/
Pyatigor_Yaroslav
/
KMiVVR
Обзор
Документация
Войти
/
Pyatigor_Yaroslav
/
KMiVVR
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Lab5/fBrownianMotion.cpp
130 строк
4 KB
Пятигор2302
upload files
01 дек 2025, 19:39
01 дек 2025, 19:39
95606b0
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "fBrownianMotion.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "GLS.BaseClasses" #pragma link "GLS.Cadencer" #pragma link "GLS.Scene" #pragma link "GLS.SceneViewer" #pragma link "GLS.Coordinates" #pragma link "GLS.Graph" #pragma link "GLS.Objects" #pragma link "GLS.SimpleNavigation" #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::GLDummyCube1Progress(TObject *Sender, const double DeltaTime, const double NewTime) { xst++; yst++; zst++; if(xst > xdl) { xx=rand() % 2; xdl = rand() % 1000 + 100; xst = 0; } if(yst > ydl) { yy = rand() % 2; ydl = rand() % 1000 + 100; yst = 0; } if(zst > zdl) { zz = rand() % 2; zdl = rand() % 1000 + 100; zst = 0; } if(xx == 0) { GLSphere1->TurnAngle = GLSphere1->TurnAngle + DeltaTime * 50; } else { GLSphere1->TurnAngle = GLSphere1->TurnAngle - DeltaTime * 50; } if(yy == 0) { GLSphere1->RollAngle = GLSphere1->RollAngle + DeltaTime * 50; } else { GLSphere1->RollAngle = GLSphere1->RollAngle - DeltaTime * 50; } if(zz == 0) { GLSphere1->PitchAngle = GLSphere1->PitchAngle + DeltaTime * 50; }else { GLSphere1->PitchAngle = GLSphere1->PitchAngle - DeltaTime * 50; } d = (double)TrackBar1->Position / 10; double speedFactor = d; GLSphere1->Position->X = GLSphere1->Position->X + dx * DeltaTime * speedFactor; GLSphere1->Position->Y = GLSphere1->Position->Y + dy * DeltaTime * speedFactor; GLSphere1->Position->Z = GLSphere1->Position->Z + dz * DeltaTime * speedFactor; double radius = 0.445; double distance = sqrt( GLSphere1->Position->X * GLSphere1->Position->X + GLSphere1->Position->Y * GLSphere1->Position->Y + GLSphere1->Position->Z * GLSphere1->Position->Z ); if(distance > radius) { double normalX = GLSphere1->Position->X / distance; double normalY = GLSphere1->Position->Y / distance; double normalZ = GLSphere1->Position->Z / distance; double dotProduct = dx * normalX + dy * normalY + dz * normalZ; dx = (dx - 2 * dotProduct * normalX) * 0.999; dy = (dy - 2 * dotProduct * normalY) * 0.998; dz = (dz - 2 * dotProduct * normalZ) * 0.997; double overlap = distance - radius; GLSphere1->Position->X -= overlap * normalX; GLSphere1->Position->Y -= overlap * normalY; GLSphere1->Position->Z -= overlap * normalZ; } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { xst = 0; yst = 0; zst = 0; xdl = rand() % 1000 + 100; ydl = rand() % 1000 + 100; zdl = rand() % 1000 + 100; xx = rand() % 2; yy = rand() % 2; zz = rand() % 2; m = 1.0; d = (double)TrackBar1->Position / 100; // Начальная скорость dx = (m * rand() / RAND_MAX / d) * 0.1; dy = (m * rand() / RAND_MAX / d) * 0.1; dz = (m * rand() / RAND_MAX / d) * 0.1; } //---------------------------------------------------------------------------