/
ArtemSls
/
O3DM
Обзор
Документация
Войти
/
ArtemSls
/
O3DM
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
patch
Lab10/Collisions/fBoxedin.cpp
146 строк
5 KB
ArtemSls
upload files
24 янв 2025, 03:48
24 янв 2025, 03:48
7355a2c
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "fBoxedin.h" //--------------------------------------------------------------------------- #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; } //--------------------------------------------------------------------------- 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 + random() / 10; Sphere2->Direction->Y = Sphere2->Direction->Y + random() / 10; Sphere2->Direction->Z = Sphere2->Direction->Z + random() / 10; 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 > 20) Lines1->Nodes->Delete(0); for(i = 0; i <= 19; i++) { k = Lines1->Nodes->Count - i - 1; if(k >= 0) ((TGLLinesNode *) Lines1->Nodes->Items[k])->Color->Alpha = 0.95 - i * 0.05; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { float t; String s; if(colCount > 0) t = colTotalTime * 1000 / colCount; else t = 0; Form1->Caption = "Lab10 Boxedin Slesarev - " + 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; } //---------------------------------------------------------------------------