/
SergeyGerasimov
/
VRLabs
Обзор
Документация
Войти
/
SergeyGerasimov
/
VRLabs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Lab2_ViewPoints/fcViewPoints.cpp
121 строка
3 KB
SergeyGerasimov
Загрузка всех лабораторных работ
01 май 2026, 15:32
01 май 2026, 15:32
83d1a16
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #include <vcl.h> #include <tchar.h> #include <stdlib.h> #include <random> #include <math.h> #pragma hdrstop #include "fcViewPoints.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 link "GLS.SimpleNavigation" #pragma link "GLS.GeomObjects" #pragma link "GLS.Material" #pragma resource "*.dfm" TForm1* Form1; std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<> dis(-1.0, 1.0); std::uniform_real_distribution<> disColor(0.0, 1.0); //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {} //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { GLCube1->Visible = true; GLSphere1->Visible = false; GLCylinder1->Visible = false; RadioGroup1->ItemIndex = 0; } void __fastcall TForm1::RadioGroup1Click(TObject *Sender) { int idx = RadioGroup1->ItemIndex; GLCube1->Visible = (idx == 0); GLSphere1->Visible = (idx == 1); GLCylinder1->Visible = (idx == 2); } void __fastcall TForm1::ButtonClearClick(TObject *Sender) { GLPoints1->Positions->Clear(); GLPoints1->Colors->Clear(); GLSceneViewer1->Refresh(); } //--------------------------------------------------------------------------- void __fastcall TForm1::ButtonGenClick(TObject *Sender) { int numPoints = SpinEdit1->Value; int shape = RadioGroup1->ItemIndex; GLPoints1->Positions->Clear(); GLPoints1->Colors->Clear(); float cubeSize = 1.0f; float sphereRadius = 1.0f; float cylinderRadius = 1.0f; float cylinderHeight = 1.0f; for (int i = 0; i < numPoints; i++) { float x = 0, y = 0, z = 0; bool ok = false; switch (shape) { case 0: x = dis(gen) * cubeSize; y = dis(gen) * cubeSize; z = dis(gen) * cubeSize; ok = true; break; case 1: do { x = dis(gen) * sphereRadius; y = dis(gen) * sphereRadius; z = dis(gen) * sphereRadius; } while (x*x + y*y + z*z > sphereRadius*sphereRadius); ok = true; break; case 2: do { x = dis(gen) * cylinderRadius; y = dis(gen) * cylinderRadius; } while (x*x + y*y > cylinderRadius*cylinderRadius); z = dis(gen) * cylinderHeight; ok = true; break; } if (ok) { TAffineVector point; point.X = x; point.Y = y; point.Z = z; GLPoints1->Positions->Add(point); TVector3f color; color.X = (float)(rand() % 256) / 255.0f; color.Y = (float)(rand() % 256) / 255.0f; color.Z = (float)(rand() % 256) / 255.0f; GLPoints1->Colors->Add(color, 1); } } GLSceneViewer1->Refresh(); } //--------------------------------------------------------------------------- //---------------------------------------------------------------------------