/
fozery
/
L2_Tagiev
Обзор
Документация
Войти
/
fozery
/
L2_Tagiev
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
fViewPoints.cpp
156 строк
5 KB
fozery
реализовал код лабораторной работы
09 ноя 2025, 20:04
09 ноя 2025, 20:04
4a27a99
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #include <vcl.h> #include <tchar.h> #include <stdlib.h> #pragma hdrstop #include "fViewPoints.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "GLS.SceneViewer" #pragma link "GLS.Coordinates" #pragma link "GLS.Objects" #pragma link "GLS.SceneViewer" #pragma link "GLS.Scene" #pragma link "GLS.Cadencer" #pragma resource "*.dfm" TForm1* Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {} //--------------------------------------------------------------------------- void __fastcall TForm1::FormMouseWheel(TObject* Sender, TShiftState Shift, int WheelDelta, TPoint &MousePos, bool &Handled) { if (GLSceneViewer1->MouseInControl == true) { GLCamera1->AdjustDistanceToTarget(Power(1.1, -WheelDelta / 120)); } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject* Sender) { for (int i = 0; i < 100; i++) { P[i] = new TGLPoints(GLDummyCube1); P[i]->Colors->Add(((float)(rand() % 256)) / 256.0, ((float)(rand() % 256)) / 256.0, ((float)(rand() % 256)) / 256.0, 0.5); P[i]->Size = 5; P[i]->Position->X = 1.0 * rand() / RAND_MAX - 0.5; P[i]->Position->Y = 1.0 * rand() / RAND_MAX - 0.5; P[i]->Position->Z = 1.0 * rand() / RAND_MAX - 0.5; P[i]->Style = psSmooth; } float sphereRadius = GLSphere1->Radius; for (int i = 0; i < 100; i++) { P_s[i] = new TGLPoints(GLSphere1); P_s[i]->Colors->Add(((float)(rand() % 256)) / 256.0, ((float)(rand() % 256)) / 256.0, ((float)(rand() % 256)) / 256.0, 0.5); P_s[i]->Size = 5; P_s[i]->Style = psSmooth; float x, y, z, distance; do { x = (2.0 * rand() / RAND_MAX - 1.0) * sphereRadius; y = (2.0 * rand() / RAND_MAX - 1.0) * sphereRadius; z = (2.0 * rand() / RAND_MAX - 1.0) * sphereRadius; distance = sqrt(x*x + y*y + z*z); } while (distance > sphereRadius); P_s[i]->Position->X = x; P_s[i]->Position->Y = y; P_s[i]->Position->Z = z; } } //--------------------------------------------------------------------------- void __fastcall TForm1::TrackBar1Change(TObject* Sender) { GLDummyCube1->PitchAngle = TrackBar1->Position; GLSphere1->PitchAngle = TrackBar1->Position; } //--------------------------------------------------------------------------- void __fastcall TForm1::TrackBar2Change(TObject* Sender) { GLDummyCube1->RollAngle = TrackBar2->Position; GLSphere1->RollAngle = TrackBar2->Position; } //--------------------------------------------------------------------------- void __fastcall TForm1::TrackBar3Change(TObject* Sender) { GLDummyCube1->TurnAngle = TrackBar3->Position; GLSphere1->TurnAngle = TrackBar3->Position; } //--------------------------------------------------------------------------- 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(ssLeft)) GLCamera1->MoveAroundTarget(my - Y, mx - X); else if (Shift.Contains(ssRight)) GLCamera1->RotateTarget(my - Y, mx - X, 0); mx = X; my = Y; } void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double DeltaTime, const double NewTime) { bool currentLeft = GetAsyncKeyState(VK_LEFT) & 0x8000; bool currentRight = GetAsyncKeyState(VK_RIGHT) & 0x8000; if (currentRight && !FKeyRightPressed) { if (GLSceneViewer1->Camera == GLCamera1) GLSceneViewer1->Camera = GLCamera2; else if (GLSceneViewer1->Camera == GLCamera2) GLSceneViewer1->Camera = GLCamera3; else GLSceneViewer1->Camera = GLCamera1; } if (currentLeft && !FKeyLeftPressed) { if (GLSceneViewer1->Camera == GLCamera1) GLSceneViewer1->Camera = GLCamera3; else if (GLSceneViewer1->Camera == GLCamera2) GLSceneViewer1->Camera = GLCamera1; else GLSceneViewer1->Camera = GLCamera2; } FKeyLeftPressed = currentLeft; FKeyRightPressed = currentRight; } //--------------------------------------------------------------------------- void __fastcall TForm1::TrackBar3KeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { Key = 0; } //--------------------------------------------------------------------------- void __fastcall TForm1::TrackBar2KeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { Key = 0; } //--------------------------------------------------------------------------- void __fastcall TForm1::TrackBar1KeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { Key = 0; } //---------------------------------------------------------------------------