/
Frogush
/
LabVR
Обзор
Документация
Войти
/
Frogush
/
LabVR
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
lab_10/fBoxedin.cpp
239 строк
8 KB
Frogush
upload files
10 дек 2025, 02:21
10 дек 2025, 02:21
c076793
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #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" TfrmMain *frmMain; float random() { return (float)(rand() & 0x1FFF) / (float)0x1FFF; } //--------------------------------------------------------------------------- __fastcall TfrmMain::TfrmMain(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 TfrmMain::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { mx = X; my = Y; } //--------------------------------------------------------------------------- void __fastcall TfrmMain::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 TfrmMain::GLSceneViewer1MouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta, TPoint &MousePos, bool &Handled) { GLCamera1->AdjustDistanceToTarget(Power(1.1, -WheelDelta / 120)); } //--------------------------------------------------------------------------- void __fastcall TfrmMain::GLCadencer1Progress(TObject *Sender, const double DeltaTime, const double NewTime) { // ����������� ���������� ��������� �������� ����� ������� static bool isWireframe = false; // ������� ����� ������� static float slowMoFactor = 1.0; // ������� �������� ������� (1.0 = �����) TGLVector rayStart, rayVector; float velocity; TGLVector pPoint; TGLVector pNormal; __int64 t; if(IsKeyDown(VK_ESCAPE)) Close(); // --- 1. �������� ������ (Sphere1) --- // ������� ��������� ���� ��������� (0.05), ����� ����� ��� ����� ������ if (Sphere1->Visible) { Sphere1->Scale->Scale(1.05); // ������ TVector4f col = Sphere1->Material->FrontProperties->Diffuse->Color; if (col.W > 0.05) Sphere1->Material->FrontProperties->Diffuse->SetColor(col.X, col.Y, col.Z, col.W - 0.05); else Sphere1->Visible = false; } // --- 2. ������ SLOW MOTION --- // ������ ���������� �������� � ����� (1.0) // ���� ������ 0.1, �� �� ���������� �������� � 1.0 if (slowMoFactor < 1.0) { slowMoFactor += DeltaTime * 1.5; if (slowMoFactor > 1.0) slowMoFactor = 1.0; } // ��������� ���������� � �������� velocity = TrackBar1->Position * DeltaTime * 50 * slowMoFactor; t = StartPrecisionTimer(); SetVector(rayStart, Sphere2->AbsolutePosition); SetVector(rayVector, Sphere2->AbsoluteDirection); NormalizeVector(rayVector); // --- 3. ������ � ������������ ������� --- if(FreeForm1->OctreeSphereSweepIntersect(rayStart, rayVector, velocity, Sphere2->Radius, &pPoint, &pNormal)) { NormalizeVector(pNormal); // === ������ ����� === // �) ����������� ����� (����� / �����) isWireframe = !isWireframe; // ����������� ���� if (isWireframe) { // �������� "�������" FreeForm1->Material->PolygonMode = pmLines; // ������ ����� FreeForm1->Material->FrontProperties->Diffuse->SetColor(0.0, 1.0, 0.0, 1.0); // ����-������� // ����������� ������� �����, ���� ���������� ��������� (�����������) FreeForm1->Material->FrontProperties->Emission->SetColor(0.0, 0.5, 0.0, 1.0); // ��������� } else { // ���������, ���������� ��� ���� FreeForm1->Material->PolygonMode = pmFill; // �������� ������� FreeForm1->Material->FrontProperties->Diffuse->SetColor(0.7, 0.7, 0.8, 1.0); // ����������� ����-������� FreeForm1->Material->FrontProperties->Emission->SetColor(0.0, 0.0, 0.0, 1.0); // ��� ��������� } // �) �������� ���������� ������� slowMoFactor = 0.05; // �������� ������ �� 5% �� ��������! (����� ��������) // �) ������ ������ Sphere1->Position->AsVector = pPoint; Sphere1->Direction->AsVector = pNormal; Sphere1->Visible = true; Sphere1->Scale->SetVector(0.5, 0.5, 0.5); Sphere1->Material->FrontProperties->Diffuse->SetColor(1.0, 1.0, 1.0, 1.0); Sphere1->Material->FrontProperties->Emission->SetColor(1.0, 0.6, 0.0, 1.0); // ��������� // �) ������ float shake = 0.8; GLCamera1->MoveAroundTarget((random() - 0.5) * shake, (random() - 0.5) * shake); // �) ��������� 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); } if (Lines1->Nodes->Count > 0) Lines1->Nodes->Last()->AsVector = Sphere2->Position->AsVector; colTotalTime = colTotalTime + StopPrecisionTimer(t); colCount++; } //--------------------------------------------------------------------------- void TfrmMain::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); // --- ��������� ����� (����������: ���������� SetColor) --- for(i = 0; i < Lines1->Nodes->Count; i++) { TGLLinesNode* node = (TGLLinesNode*)Lines1->Nodes->Items[i]; float freshness = (float)i / (float)Lines1->Nodes->Count; // ���������� ����� SetColor(Red, Green, Blue, Alpha) if (freshness > 0.8) { // ������ (Hot) node->Color->SetColor(1.0, 1.0, 0.0, 1.0); } else if (freshness > 0.4) { // ������� (Warm) node->Color->SetColor(1.0, 0.0, 0.0, 0.8); } else { // ����� (Cold/Smoke) node->Color->SetColor(0.5, 0.5, 0.5, freshness); } } } //--------------------------------------------------------------------------- void __fastcall TfrmMain::Timer1Timer(TObject *Sender) { float t; String s; if(colCount > 0) t = colTotalTime * 1000 / colCount; else t = 0; frmMain->Caption = "Lab10 Boxedin - " + GLSceneViewer1->FramesPerSecondText(); GLSceneViewer1->ResetPerformanceMonitor(); colTotalTime = 0; colCount = 0; } //--------------------------------------------------------------------------- void __fastcall TfrmMain::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; } //---------------------------------------------------------------------------