/
Frogush
/
LabVR
Обзор
Документация
Войти
/
Frogush
/
LabVR
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
lab_7/fсSkyBox.cpp
218 строк
8 KB
Frogush
upload files
08 дек 2025, 22:00
08 дек 2025, 22:00
fcf2512
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "f�SkyBox.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "GLS.BaseClasses" #pragma link "GLS.Scene" #pragma link "GLS.SceneViewer" #pragma link "GLS.Cadencer" #pragma link "GLS.Material" #pragma link "GLS.SimpleNavigation" #pragma link "GLS.Coordinates" #pragma link "GLS.LensFlare" #pragma link "GLS.SkyDome" #pragma link "GLS.Objects" #pragma resource "*.dfm" TForm1 *Form1; bool autoRotate = true; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { LoadTexture("Left", "../../Assets/hills_negx.bmp"); GLMaterialLibrary1->Materials->Items[0]->Material->Texture->TextureMode = tmDecal; LoadTexture("Right", "../../Assets/hills_posx.bmp"); GLMaterialLibrary1->Materials->Items[1]->Material->Texture->TextureMode = tmDecal; LoadTexture("Top", "../../Assets/hills_posy.bmp"); GLMaterialLibrary1->Materials->Items[2]->Material->Texture->TextureMode = tmDecal; LoadTexture("Bottom", "../../Assets/hills_negy.bmp"); GLMaterialLibrary1->Materials->Items[3]->Material->Texture->TextureMode = tmDecal; LoadTexture("Front", "../../Assets/hills_posz.bmp"); GLMaterialLibrary1->Materials->Items[4]->Material->Texture->TextureMode = tmDecal; LoadTexture("Back", "../../Assets/hills_negz.bmp"); GLMaterialLibrary1->Materials->Items[5]->Material->Texture->TextureMode = tmDecal; // ������ �� �����, ������ ���� ��� ������� �������� auto CloudsB = LoadTexture("Clouds_b", "../../Assets/clouds_b.jpg"); CloudsB->Material->BlendingMode = bmTransparency; CloudsB->Material->FrontProperties->Diffuse->Alpha = 0.3; CloudsB->Material->FrontProperties->Diffuse->Red = 255; CloudsB->Material->FrontProperties->Diffuse->Green = 255; CloudsB->Material->FrontProperties->Diffuse->Blue = 255; CloudsB->Material->FrontProperties->Ambient->Red = 255; CloudsB->Material->FrontProperties->Ambient->Green = 255; CloudsB->Material->FrontProperties->Ambient->Blue = 255; CloudsB->Material->FrontProperties->Emission->Red = 255; CloudsB->Material->FrontProperties->Emission->Green = 255; CloudsB->Material->FrontProperties->Emission->Blue = 255; CloudsB->TextureScale->X = 8; CloudsB->TextureScale->Y = 8; auto CloudsM = LoadTexture("Clouds_m", "../../Assets/clouds_m.jpg"); CloudsM->Material->BlendingMode = bmTransparency; CloudsM->Material->FrontProperties->Diffuse->Alpha = 0.25; CloudsM->Material->FrontProperties->Diffuse->Red = 255; CloudsM->Material->FrontProperties->Diffuse->Green = 255; CloudsM->Material->FrontProperties->Diffuse->Blue = 255; CloudsM->Material->FrontProperties->Ambient->Red = 255; CloudsM->Material->FrontProperties->Ambient->Green = 255; CloudsM->Material->FrontProperties->Ambient->Blue = 255; CloudsM->TextureScale->X = 8; CloudsM->TextureScale->Y = 8; } //--------------------------------------------------------------------------- TGLLibMaterial* __fastcall TForm1::LoadTexture(String Matname, String Filename) { // 1. ���������, ���������� �� ����, ����� ��������� �� ��������/������ if (!FileExists(Filename)) { // ����� ����������������� ��� �������: // ShowMessage("���� �� ������: " + Filename); return NULL; } // 2. �������� ����� �������� �� ����� TGLLibMaterial* LibMat = GLMaterialLibrary1->Materials->GetLibMaterialByName(Matname); if (LibMat == NULL) { // ���� ��������� ��� � ������� ����� (��� ���� ������) LibMat = GLMaterialLibrary1->AddTextureMaterial(Matname, Filename); } else { // ���� �������� ��� ���� � ������ ��������� � ���� ����� �������� LibMat->Material->Texture->Image->LoadFromFile(Filename); } // 3. ����������, ��� �������� �������� � ��������� ���������� // �����: ���������� LibMat, � �� Items[0], ����� �� ����� ��������� ������ ������� ��������� � ������ LibMat->Material->Texture->Disabled = false; LibMat->Material->Texture->TextureMode = tmDecal; return LibMat; } //--------------------------------------------------------------------------- void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double DeltaTime, const double NewTime) { // ===== ��� 3: ����������� ������ ===== if (autoRotate) { GLCamera1->MoveAroundTarget(0, DeltaTime * 2); } // ===== �������� ��������� ������� ===== auto CloudsB = GLMaterialLibrary1->Materials->GetLibMaterialByName("Clouds_b"); auto CloudsM = GLMaterialLibrary1->Materials->GetLibMaterialByName("Clouds_m"); // ===== ����� ������� �������� �� ������/�������� ===== double t = NewTime; CloudsB->TextureOffset->X = sin(t * 0.1) * 0.1; CloudsM->TextureOffset->Y = cos(t * 0.07) * 0.1; // ===== ������ �������� ������� (��������� ��� ������ � ������ �� �����) ===== CloudsB->TextureOffset->X = CloudsB->TextureOffset->X + DeltaTime * 0.02; CloudsB->TextureOffset->Y = CloudsB->TextureOffset->Y + DeltaTime * 0.03; CloudsM->TextureOffset->X = CloudsM->TextureOffset->X + DeltaTime * 0.01; CloudsM->TextureOffset->Y = CloudsM->TextureOffset->Y + DeltaTime * 0.02; // ===== ����������� ===== GLSceneViewer1->Invalidate(); // ===== ��� 4: ������������� ������ �� ESC ===== if (IsKeyDown(VK_ESCAPE)) { if (Application->MessageBox(L"�����?", L"Exit", MB_YESNO | MB_ICONQUESTION) == IDYES) Close(); } } //--------------------------------------------------------------------------- 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); } // ===== ��� 5: ����������� ���������� ������ ===== float dist = GLCamera1->DistanceToTarget(); if (dist < 3) GLCamera1->AdjustDistanceToTarget(3 - dist); if (dist > 200) GLCamera1->AdjustDistanceToTarget(200 - dist); mx = X; my = Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { Form1->Caption = "Lab7_SkyBox - " + GLSceneViewer1->FramesPerSecondText(); GLSceneViewer1->ResetPerformanceMonitor(); } //--------------------------------------------------------------------------- void __fastcall TForm1::RadioGroupPanoramsClick(TObject *Sender) { // 0 � ���� (�� ���������) // 1 � ������� ����� // 2 � ����� // 3 � ������� // 4 � ����� int id = RadioGroupPanorams->ItemIndex; // ======= ����� ======= if (id == 2) { LoadTexture("Left", "../../Assets/desert_negx.bmp"); LoadTexture("Right", "../../Assets/desert_posx.bmp"); LoadTexture("Top", "../../Assets/desert_posy.bmp"); LoadTexture("Bottom", "../../Assets/desert_negy.bmp"); LoadTexture("Front", "../../Assets/desert_posz.bmp"); LoadTexture("Back", "../../Assets/desert_negz.bmp"); GLSceneViewer1->Invalidate(); return; } // ======= ���� (������� �� ���������) ======= if (id == 0) { LoadTexture("Left", "../../Assets/hills_negx.bmp"); LoadTexture("Right", "../../Assets/hills_posx.bmp"); LoadTexture("Top", "../../Assets/hills_posy.bmp"); LoadTexture("Bottom", "../../Assets/hills_negy.bmp"); LoadTexture("Front", "../../Assets/hills_posz.bmp"); LoadTexture("Back", "../../Assets/hills_negz.bmp"); GLSceneViewer1->Invalidate(); return; } // ������ ����� �������� � ��������� �������� } //---------------------------------------------------------------------------