/
ArtemSls
/
O3DM
Обзор
Документация
Войти
/
ArtemSls
/
O3DM
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
patch
Lab11/OdeSimple/fOdeSimple.cpp
214 строк
8 KB
ArtemSls
upload files
24 янв 2025, 03:52
24 янв 2025, 03:52
88b5564
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "fOdeSimple.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "GLS.SceneViewer" #pragma link "GLS.BaseClasses" #pragma link "GLS.Scene" #pragma link "GLS.Cadencer" #pragma link "GLS.ODEManager" #pragma link "GLS.Coordinates" #pragma link "GLS.Objects" #pragma link "GLS.Graph" #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- 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::ComboBox1Change(TObject *Sender) { if (ComboBox1->ItemIndex == 0) { GLPlane1->Visible = true; GetOdeStatic(GLPlane1)->Manager = GLODEManager1; CheckBox2->Enabled = false; Label3->Enabled = false; TrackBar1->Enabled = false; } else { GLPlane1->Visible = false; CheckBox2->Enabled = true; Label3->Enabled = true; TrackBar1->Enabled = true; GetOdeStatic(GLPlane1)->Manager = NULL; } if (ComboBox1->ItemIndex == 1) { GLHeightField1->Visible = true; CheckBox2->Enabled = true; Label3->Enabled = true; TrackBar1->Enabled = true; GetODEHeightField(GLHeightField1)->Manager = GLODEManager1; } else { GLHeightField1->Visible = false; CheckBox2->Enabled = false; Label3->Enabled = false; TrackBar1->Enabled = false; GetODEHeightField(GLHeightField1)->Manager = NULL; } } //--------------------------------------------------------------------------- void __fastcall TForm1::TrackBar1Change(TObject *Sender) { ((TGLODEHeightField*)(GLHeightField1->Behaviours->Behaviour[0]))->ContactResolution = 0.25 + (float)(10 - TrackBar1->Position) / 20; } //--------------------------------------------------------------------------- void __fastcall TForm1::GLHeightField1GetHeight(const float x, const float y, float &z, TGLColorVector &Color, TTexPoint &TexPoint) { z = 0.5 * cos(x) * sin(y); } //--------------------------------------------------------------------------- void __fastcall TForm1::CheckBox1Click(TObject *Sender) { GLODEManager1->Visible = CheckBox1->Checked; } //--------------------------------------------------------------------------- void __fastcall TForm1::CheckBox2Click(TObject *Sender) { ((TGLODEHeightField*)(GLHeightField1->Behaviours->Behaviour[0]))->RenderContacts = CheckBox2->Checked; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { switch (ComboBox2->ItemIndex) { case 0: DoSphere(); break; case 1: DoBox(); break; case 2: DoCapsule(); break; case 3: DoCylinder(); break; } } //--------------------------------------------------------------------------- void TForm1::DoSphere(void) { TGLSphere *sphere; TGLODEDynamic *dyn; sphere = (TGLSphere*)(GLDummyCube2->AddNewChild(__classid(TGLSphere))); sphere->Position->SetPoint(5 * Random() - 2.5, 2, 5 * Random() - 2.5); sphere->Radius = 0.3 * (Random() + 1); sphere->Material->FrontProperties->Ambient->RandomColor(); sphere->Material->FrontProperties->Diffuse->RandomColor(); dyn = new TGLODEDynamic(sphere->Behaviours); dyn->Manager = GLODEManager1; ((TGLODEElementSphere*)(dyn->AddNewElement(__classid(TGLODEElementSphere))))->Radius = sphere->Radius; } //--------------------------------------------------------------------------- void TForm1::DoBox(void) { TGLCube *cube; TGLODEDynamic *dyn; TGLODEElementBox *elem; cube = (TGLCube*)(GLDummyCube2->AddNewChild(__classid(TGLCube))); cube->Position->SetPoint(5 * Random() - 2.5, 2, 5 * Random() - 2.5); cube->CubeWidth = 0.5 * (Random() + 1); cube->CubeHeight = 0.5 * (Random() + 1); cube->CubeDepth = 0.5 * (Random() + 1); cube->Material->FrontProperties->Ambient->RandomColor(); cube->Material->FrontProperties->Diffuse->RandomColor(); dyn = new TGLODEDynamic(cube->Behaviours); dyn->Manager = GLODEManager1; elem = (TGLODEElementBox*)dyn->AddNewElement(__classid(TGLODEElementBox)); elem->BoxWidth = cube->CubeWidth; elem->BoxHeight = cube->CubeHeight; elem->BoxDepth = cube->CubeDepth; } //--------------------------------------------------------------------------- void TForm1::DoCapsule(void) { TGLCylinder *capsule; TGLODEDynamic *dyn; TGLSphere *sphere; TGLODEElementCapsule *elem; capsule = (TGLCylinder*)(GLDummyCube2->AddNewChild(__classid(TGLCylinder))); capsule->Position->SetPoint(5 * Random() - 2.5, 2, 5 * Random() - 2.5); capsule->BottomRadius = 0.25 * (Random() + 1); capsule->TopRadius = capsule->BottomRadius; capsule->Height = Random() + 1; capsule->Parts << cySides; capsule->Material->FrontProperties->Ambient->RandomColor(); capsule->Material->FrontProperties->Diffuse->RandomColor(); sphere = (TGLSphere*)capsule->AddNewChild(__classid(TGLSphere)); sphere->Position->Y = 0.5 * capsule->Height; sphere->Radius = capsule->BottomRadius; sphere->Bottom = 0; sphere = (TGLSphere*)capsule->AddNewChild(__classid(TGLSphere)); sphere->Position->Y = -0.5 * capsule->Height; sphere->Radius = capsule->BottomRadius; sphere->Top = 0; dyn = new TGLODEDynamic(capsule->Behaviours); dyn->Manager = GLODEManager1; elem = (TGLODEElementCapsule*)dyn->AddNewElement(__classid(TGLODEElementCapsule)); elem->Radius = capsule->BottomRadius; elem->Length = capsule->Height; elem->Direction->SetVector(0, 1, 0); elem->Up->SetVector(0, 0, 1); } //--------------------------------------------------------------------------- void TForm1::DoCylinder(void) { TGLCylinder *cylinder; TGLODEDynamic *dyn; TGLODEElementCylinder *elem; cylinder = (TGLCylinder*)(GLDummyCube2->AddNewChild(__classid(TGLCylinder))); cylinder->Position->SetPoint(5 * Random() - 2.5, 2, 5 * Random() - 2.5); cylinder->BottomRadius = 0.25 * (Random() + 1); cylinder->TopRadius = cylinder->BottomRadius; cylinder->Height = Random() + 1; cylinder->Material->FrontProperties->Ambient->RandomColor(); cylinder->Material->FrontProperties->Diffuse->RandomColor(); dyn = new TGLODEDynamic(cylinder->Behaviours); dyn->Manager = GLODEManager1; elem = (TGLODEElementCylinder*)dyn->AddNewElement(__classid(TGLODEElementCylinder)); elem->Radius = cylinder->BottomRadius; elem->Length = cylinder->Height; } //--------------------------------------------------------------------------- void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double DeltaTime, const double NewTime) { GLSceneViewer1->Invalidate(); GLODEManager1->Step(DeltaTime); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { GLDummyCube2->DeleteChildren(); } //---------------------------------------------------------------------------