/
daryadevx
/
KMiVVR
Обзор
Документация
Войти
/
daryadevx
/
KMiVVR
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Lab10/fCollisions.cpp
119 строк
4 KB
daryadevx
fix
24 дек 2024, 21:14
24 дек 2024, 21:14
5d0eeb2
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "fCollisions.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "GLS.GeomObjects" #pragma link "GLS.Cadencer" #pragma link "GLS.SceneViewer" #pragma link "GLS.Objects" #pragma link "GLS.VectorFileObjects" #pragma link "GLS.Scene" #pragma link "GLS.File3DS" #pragma link "GLS.BaseClasses" #pragma link "GLS.Coordinates" #pragma link "GLS.Scene" #pragma link "GLS.SimpleNavigation" #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent * Owner):TForm(Owner) { __int64 t; TFileName Path = GetCurrentAssetPath(); // Load high poly mesh (10 000 triangles). SetCurrentDir(Path + "\\model"); FreeForm1->LoadFromFile("HighPolyObject.3ds"); t = StartPrecisionTimer(); FreeForm1->BuildOctree(3); LABuild->Caption = Format("Время сборки: %.3f ms", ARRAYOFCONST((StopPrecisionTimer(t) * 1000))); Label1->Caption = "Узлы octree: " + IntToStr(FreeForm1->Octree->NodeCount); Label2->Caption = "Расчет Octree: " + IntToStr(FreeForm1->Octree->TriCountOctree); Label3->Caption = "Расчет сетки: " + IntToStr(FreeForm1->Octree->TriCountMesh); mousex = -1; mousey = -1; } //--------------------------------------------------------------------------- void __fastcall TForm1::GLSceneViewer2MouseDown(TObject * Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TGLVector rayStart, rayVector, iPoint, iNormal; __int64 t; SetVector(rayStart, GLCamera2->AbsolutePosition); SetVector(rayVector, GLSceneViewer2->Buffer-> ScreenToVector(AffineVectorMake(X, GLSceneViewer2->Height - Y, 0)),0); NormalizeVector(rayVector); t = StartPrecisionTimer(); if(CBOctree->Checked) { // Octree method (fast) if(FreeForm1-> OctreeRayCastIntersect(rayStart, rayVector, &iPoint, &iNormal)) { Sphere1->Visible = True; Sphere1->Position->AsVector = iPoint; Sphere1->Direction->AsVector = VectorNormalize(iNormal); } else Sphere1->Visible = False; Label4->Hint = "# Узлы: " + IntToStr(FreeForm1->Octree->ResultArray.Length); } else { // Brute-Force method (slow) if(FreeForm1->RayCastIntersect(rayStart, rayVector, &iPoint, &iNormal)) { Sphere1->Visible = True; Sphere1->Position->AsVector = iPoint; Sphere1->Direction->AsVector = VectorNormalize(iNormal); } else Sphere1->Visible = False; } Label5->Hint = Format("Время пересечения: %.3f ms", ARRAYOFCONST((StopPrecisionTimer(t) * 1000))); } //--------------------------------------------------------------------------- void __fastcall TForm1::GLSceneViewer2MouseMove(TObject * Sender, TShiftState Shift, int X, int Y) { mousex = X; mousey = Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::GLCadencer1Progress(TObject * Sender, const double deltaTime, const double newTime) { TShiftState ss; ss << ssShift; if(CheckBox1->Checked) GLSceneViewer2MouseDown(Sender, Controls::mbLeft, ss, mousex, mousey); FreeForm1->RollAngle = 5.0 * newTime; // 45 per second } //---------------------------------------------------------------------------//---------------------------------------------------------------------------