/
Frogush
/
LabVR
Обзор
Документация
Войти
/
Frogush
/
LabVR
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
lab_13/fxVR.cpp
130 строк
5 KB
Frogush
upload files
10 дек 2025, 02:22
10 дек 2025, 02:22
136fdb9
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #include <fmx.h> #include <math.h> #pragma hdrstop #include "fxVR.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.fmx" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { mx = my = 0; orbitAngle = 0; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { Viewport3D1->Expand = 0.25; Viewport3D1->Stereo = true; Viewport3D1->Color = TAlphaColorRec::Black; Timer1->Interval = 16; Timer1->Enabled = true; // Начальный набор кубов Cubes.clear(); Cubes.push_back(Cube1); Cubes.push_back(Cube2); // Позиции кубов по кругу float r = 5.0f; Cube1->Position->Point = TPoint3D::Create(-r, 0, 0); Cube2->Position->Point = TPoint3D::Create(r, 0, 0); } //--------------------------------------------------------------------------- //══════════════════════════════════════════════════ // ПКМ — поменять цвет всем кубам + создать новый //══════════════════════════════════════════════════ void __fastcall TForm1::Viewport3D1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, float X, float Y) { if (Button == TMouseButton::mbRight) { // Меняем цвет всем кубам for (auto c : Cubes) { if (c->MaterialSource && c->MaterialSource->InheritsFrom(__classid(TLightMaterialSource))) { TLightMaterialSource* mat = static_cast<TLightMaterialSource*>(c->MaterialSource); TAlphaColor newColor = ((rand() & 255) << 24) | ((rand() & 255) << 16) | ((rand() & 255) << 8) | (rand() & 255); mat->Diffuse = newColor; } } // Создаём новый куб TCube *newCube = new TCube(this); newCube->Parent = Dummy4; // вращение вокруг стола newCube->Width = 3; newCube->Height = 3; newCube->Depth = 3; // Цвет newCube->MaterialSource = LightMaterialSource4; // Ставим по кругу float radius = 5.0f; float angle = Cubes.size() * 45; // каждый новый куб = +45° float rad = angle * M_PI / 180.0f; newCube->Position->X = cos(rad) * radius; newCube->Position->Z = sin(rad) * radius; Cubes.push_back(newCube); } mx = X; my = Y; } //--------------------------------------------------------------------------- // Заглушка — мышь не управляет камерой void __fastcall TForm1::Viewport3D1MouseMove(TObject *Sender, TShiftState Shift, float X, float Y) { mx = X; my = Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::Viewport3D1MouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta, bool &Handled) { // заглушка } //--------------------------------------------------------------------------- //══════════════════════════════════════════════════ // MAIN LOOP (вращение вокруг стола + своя ось) //══════════════════════════════════════════════════ void __fastcall TForm1::Timer1Timer(TObject *Sender) { orbitAngle += 0.5f; if (orbitAngle > 360) orbitAngle -= 360; float radius = 5.0f; float rad = orbitAngle * M_PI / 180.0f; // Вращаем таблицу (Dummy4) → все кубы двигаются по кругу Dummy4->RotationAngle->Y = orbitAngle; // Каждый куб крутится вокруг своей оси for (auto c : Cubes) { c->RotationAngle->Y += 2.0f; if (c->RotationAngle->Y > 360) c->RotationAngle->Y -= 360; } } //---------------------------------------------------------------------------