/
Pyatigor_Yaroslav
/
KMiVVR
Обзор
Документация
Войти
/
Pyatigor_Yaroslav
/
KMiVVR
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Lab10/fBoxedin.cpp
164 строки
5 KB
Пятигор2302
upload files
21 дек 2025, 16:21
21 дек 2025, 16:21
3aa09b0
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "fBoxedin.h" #include "GLS.Color.hpp" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "GLS.BaseClasses" #pragma link "GLS.Cadencer" #pragma link "GLS.Coordinates" #pragma link "GLS.GeomObjects" #pragma link "GLS.Objects" #pragma link "GLS.Scene" #pragma link "GLS.SceneViewer" #pragma link "GLS.VectorFileObjects" #pragma link "GLS.File3DS" #pragma link "Stage.Keyboard" #pragma resource "*.dfm" TForm1 *Form1; float random() { return (float)(rand() & 0x1FFF) / (float)0x1FFF; } //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { SetCurrentDir("..\\..\\Assets"); FreeForm1->LoadFromFile("BoxedIn.3ds"); FreeForm1->BuildOctree(3); Label1->Caption = "Octree Nodes: " + IntToStr(FreeForm1->Octree->NodeCount); Label2->Caption = "Tri Count Octree: " + IntToStr(FreeForm1->Octree->TriCountOctree); Label3->Caption = "Tri Count Mesh: " + IntToStr(FreeForm1->Octree->TriCountMesh); Lines1->AddNode(0, 0, 0); Lines1->ObjectStyle = Lines1->ObjectStyle << osDirectDraw; Lines1->LineWidth = 2.0; } //--------------------------------------------------------------------------- void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { mx = X; my = Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (Shift.Contains(ssRight) && Shift.Contains(ssLeft)) GLCamera1->AdjustDistanceToTarget(Power(1.01, Y - my)); else if (Shift.Contains(ssRight) || Shift.Contains(ssLeft)) GLCamera1->MoveAroundTarget(my - Y, mx - X); mx = X; my = Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::GLSceneViewer1MouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta, TPoint &MousePos, bool &Handled) { GLCamera1->AdjustDistanceToTarget(Power(1.1, -WheelDelta / 120)); } //--------------------------------------------------------------------------- void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double DeltaTime, const double NewTime) { TGLVector rayStart, rayVector; float velocity; TGLVector pPoint; TGLVector pNormal; __int64 t; if(IsKeyDown(VK_ESCAPE)) Close(); velocity = TrackBar1->Position * DeltaTime * 50; t = StartPrecisionTimer(); SetVector(rayStart, Sphere2->AbsolutePosition); SetVector(rayVector, Sphere2->AbsoluteDirection); NormalizeVector(rayVector); if(FreeForm1->OctreeSphereSweepIntersect(rayStart, rayVector, velocity, Sphere2->Radius, &pPoint, &pNormal)) { NormalizeVector(pNormal); Sphere1->Position->AsVector = pPoint; Sphere1->Direction->AsVector = pNormal; Sphere2->Direction->AsAffineVector = VectorReflect(Sphere2->Direction->AsAffineVector, AffineVectorMake(pNormal)); Sphere2->Direction->X = Sphere2->Direction->X * 0.9 + random() * 0.2 - 0.1; Sphere2->Direction->Y = Sphere2->Direction->Y * 0.9 + random() * 0.2 - 0.1; Sphere2->Direction->Z = Sphere2->Direction->Z * 0.9 + random() * 0.2 - 0.1; AddToTrail(pPoint); } else { Sphere2->Move(velocity); } Lines1->Nodes->Last()->AsVector = Sphere2->Position->AsVector; colTotalTime = colTotalTime + StopPrecisionTimer(t); colCount++; } //--------------------------------------------------------------------------- void TForm1::AddToTrail(const TGLVector & p) { int i, k; Lines1->Nodes->Last()->AsVector = p; Lines1->AddNode(0, 0, 0); if(Lines1->Nodes->Count > 30) Lines1->Nodes->Delete(0); // �������� ����� � ������������ for(i = 0; i < Lines1->Nodes->Count; i++) { k = Lines1->Nodes->Count - i - 1; if(k >= 0) { TGLLinesNode* node = (TGLLinesNode*)Lines1->Nodes->Items[k]; float ratio = (float)i / Lines1->Nodes->Count; node->Color->Red = 1.0f; node->Color->Green = ratio; node->Color->Blue = 0.0f; node->Color->Alpha = 0.8 - i * 0.8 / Lines1->Nodes->Count; } } } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { float t; String s; if(colCount > 0) t = colTotalTime * 1000 / colCount; else t = 0; Form1->Caption = "Lab10 Boxedin Andrusenko - " + GLSceneViewer1->FramesPerSecondText(); GLSceneViewer1->ResetPerformanceMonitor(); colTotalTime = 0; colCount = 0; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Sphere2->Position->X = random(); Sphere2->Position->Y = random(); Sphere2->Position->Z = random(); Sphere2->Direction->X = random(); if(random() > 0.5) Sphere2->Direction->X = -Sphere2->Direction->X; Sphere2->Direction->Y = random(); if(random() > 0.5) Sphere2->Direction->Y = -Sphere2->Direction->Y; Sphere2->Direction->Z = random(); if(random() > 0.5) Sphere2->Direction->Z = -Sphere2->Direction->Z; Lines1->Nodes->Clear(); Lines1->AddNode(0, 0, 0); } //---------------------------------------------------------------------------