/
Fuv
/
KMiVVR
Обзор
Документация
Войти
/
Fuv
/
KMiVVR
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
L7/Panorama.cpp
358 строк
12 KB
Fuv
upload files
05 дек 2025, 22:52
05 дек 2025, 22:52
a9bf86d
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Panorama.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "GLS.BaseClasses" #pragma link "GLS.Cadencer" #pragma link "GLS.Coordinates" #pragma link "GLS.LensFlare" #pragma link "GLS.Material" #pragma link "GLS.Navigator" #pragma link "GLS.Objects" #pragma link "GLS.Scene" #pragma link "GLS.SimpleNavigation" #pragma link "GLS.SkyDome" #pragma link "GLS.SceneViewer" #pragma link "GLS.GeomObjects" #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- TGLLibMaterial* __fastcall TForm1::LoadTexture(String Matname, String Filename) { // Проверяем, существует ли уже материал с таким именем TGLLibMaterial* existingMat = GLMaterialLibrary1->Materials->GetLibMaterialByName(Matname); if (existingMat) { // Если материал существует, обновляем его текстуру try { existingMat->Material->Texture->Image->LoadFromFile(Filename); existingMat->Material->Texture->Enabled = true; existingMat->Material->Texture->Disabled = false; return existingMat; } catch (...) { return NULL; } } else { // Если материала нет, создаем новый try { TGLLibMaterial* newMat = GLMaterialLibrary1->AddTextureMaterial(Matname, Filename); if (newMat) { newMat->Material->Texture->Enabled = true; newMat->Material->Texture->Disabled = false; } return newMat; } catch (...) { return NULL; } } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { // Объявляем переменные для материалов TGLLibMaterial* matBack; TGLLibMaterial* matFront; TGLLibMaterial* matTop; TGLLibMaterial* matBottom; TGLLibMaterial* matLeft; TGLLibMaterial* matRight; TGLLibMaterial* matClouds; TGLLibMaterial* matBricks; TGLLibMaterial* matBricks2; TGLLibMaterial* matMoon1; // Для сферы1 TGLLibMaterial* matMoon2; // Для сферы2 TGLLibMaterial* matMoon3; // Для сферы3 TGLLibMaterial* matRing; String assetsPath = ExtractFilePath(Application->ExeName) + "\\Assets"; String cubemapsPath = ExtractFilePath(Application->ExeName) + "\\Cubemaps"; // -------------- // Load graphics // -------------- // Skybox textures - новые имена файлов SetCurrentDir(cubemapsPath); // ИЗМЕНЕНО: новые имена файлов (nx, ny, nz, px, py, pz) matBack = LoadTexture("Back","nz.jpg"); // nz = зад if (matBack) matBack->Material->Texture->TextureMode = tmDecal; matFront = LoadTexture("Front","pz.jpg"); // pz = перед if (matFront) matFront->Material->Texture->TextureMode = tmDecal; matTop = LoadTexture("Top","py.jpg"); // py = верх if (matTop) matTop->Material->Texture->TextureMode = tmDecal; matBottom = LoadTexture("Bottom","ny.jpg"); // ny = низ if (matBottom) matBottom->Material->Texture->TextureMode = tmDecal; matLeft = LoadTexture("Left","nx.jpg"); // nx = лево if (matLeft) matLeft->Material->Texture->TextureMode = tmDecal; matRight = LoadTexture("Right","px.jpg"); // px = право if (matRight) matRight->Material->Texture->TextureMode = tmDecal; // Загружаем текстуры из папки Assets SetCurrentDir(assetsPath); // Проверяем существование файла ring.jpg String ringFile = "ring.jpg"; if (!FileExists(ringFile)) { ringFile = "ring.png"; // Пробуем png if (!FileExists(ringFile)) { return; } } // Cloud texture matClouds = LoadTexture("Clouds","Clouds.jpg"); if (matClouds) { matClouds->Material->BlendingMode = bmTransparency; matClouds->Material->FrontProperties->Diffuse->Alpha = 0.3; // scale the clouds texture matClouds->TextureScale->X = 9; matClouds->TextureScale->Y = 9; } // bricks matBricks = LoadTexture("Bricks","rawwall.jpg"); if (matBricks) { matBricks->TextureScale->X = 1; matBricks->TextureScale->Y = 32; matBricks->Material->Texture->TextureMode = tmModulate; } // bricks2 matBricks2 = LoadTexture("Bricks2","marbletiles.jpg"); if (matBricks2) { matBricks2->TextureScale->X = 6; matBricks2->TextureScale->Y = 1; matBricks2->Material->Texture->TextureMode = tmModulate; } // Moon1 - текстура для сферы1 matMoon1 = LoadTexture("Moon1","unwrapped moon.jpg"); if (matMoon1) { matMoon1->Material->Texture->TextureMode = tmModulate; matMoon1->Material->BlendingMode = bmOpaque; matMoon1->Material->FrontProperties->Diffuse->Alpha = 1.0; } // Moon2 - текстура для сферы2 String moon2File = "moon2.jpg"; if (!FileExists(moon2File)) { moon2File = "moon2.png"; if (!FileExists(moon2File)) { moon2File = "unwrapped moon.jpg"; } } matMoon2 = LoadTexture("Moon2", moon2File); if (matMoon2) { matMoon2->Material->Texture->TextureMode = tmModulate; matMoon2->Material->BlendingMode = bmOpaque; matMoon2->Material->FrontProperties->Diffuse->Alpha = 1.0; matMoon2->Material->FrontProperties->Diffuse->Red = 0.8; matMoon2->Material->FrontProperties->Diffuse->Green = 0.8; matMoon2->Material->FrontProperties->Diffuse->Blue = 0.8; } // Moon3 - текстура для сферы3 String moon3File = "moon3.jpg"; if (!FileExists(moon3File)) { moon3File = "moon3.png"; if (!FileExists(moon3File)) { moon3File = "unwrapped moon.jpg"; } } matMoon3 = LoadTexture("Moon3", moon3File); if (matMoon3) { matMoon3->Material->Texture->TextureMode = tmModulate; matMoon3->Material->BlendingMode = bmOpaque; matMoon3->Material->FrontProperties->Diffuse->Alpha = 1.0; } else { matMoon3 = GLMaterialLibrary1->AddTextureMaterial("Moon3", ""); if (matMoon3) { matMoon3->Material->BlendingMode = bmOpaque; matMoon3->Material->FrontProperties->Diffuse->Red = 0.6; matMoon3->Material->FrontProperties->Diffuse->Green = 0.7; matMoon3->Material->FrontProperties->Diffuse->Blue = 1.0; matMoon3->Material->FrontProperties->Diffuse->Alpha = 1.0; } } // Ring (Сатурна) matRing = LoadTexture("Ring", ringFile); if (matRing) { matRing->Material->Texture->TextureMode = tmModulate; matRing->Material->BlendingMode = bmTransparency; matRing->Material->FrontProperties->Diffuse->Alpha = 1.0; matRing->TextureScale->X = 8.0; matRing->TextureScale->Y = 1.0; matRing->Material->Texture->Enabled = true; matRing->Material->Texture->TextureWrap = twBoth; matRing->Material->FaceCulling = fcCull; matRing->Material->Texture->MinFilter = miLinear; matRing->Material->Texture->MagFilter = maLinear; } // ========== НАСТРОЙКА ДИСКА ========== GLDisk1->Parent = GLSphere1; GLDisk1->Position->X = 0; GLDisk1->Position->Y = 0; GLDisk1->Position->Z = 0; GLDisk1->PitchAngle = 90; GLDisk1->OuterRadius = 1.5; GLDisk1->InnerRadius = 1.2; GLDisk1->Slices = 64; GLDisk1->Loops = 4; GLDisk1->Material->MaterialLibrary = GLMaterialLibrary1; GLDisk1->Material->LibMaterialName = "Ring"; GLDisk1->Material->BlendingMode = bmTransparency; GLDisk1->Material->FaceCulling = fcCull; GLDisk1->Visible = true; //----------------------------------------- // Настройка размера и положения сфер //----------------------------------------- // Сфера1 (центральная) - оставляем как есть // Сфера2 - БОЛЬШАЯ и ДАЛЬШЕ от сферы1 GLSphere2->Position->X = -3.0; // Дальше от центра (левее) GLSphere2->Position->Y = 0; GLSphere2->Position->Z = 0; GLSphere2->Radius = 0.5; // Большой размер // Сфера3 - МЕНЬШЕ сферы2 и БЛИЖЕ к сфере1 GLSphere3->Position->X = 2.0; // Ближе к центру (правее) GLSphere3->Position->Y = 0; GLSphere3->Position->Z = 0; GLSphere3->Radius = 0.3; // Меньше чем сфера2 //----------------------------------------- // Assign materials to objects //----------------------------------------- if (matBricks) { GLCube1->Material->LibMaterialName = "Bricks"; GLCube11->Material->LibMaterialName = "Bricks"; GLCube111->Material->LibMaterialName = "Bricks"; GLCube112->Material->LibMaterialName = "Bricks"; } if (matBricks2) { GLCube2->Material->LibMaterialName = "Bricks2"; GLCube21->Material->LibMaterialName = "Bricks2"; GLCube211->Material->LibMaterialName = "Bricks2"; GLCube212->Material->LibMaterialName = "Bricks2"; } // Назначаем РАЗНЫЕ текстуры для сфер if (matMoon1) { GLSphere1->Material->LibMaterialName = "Moon1"; GLSphere1->Material->MaterialLibrary = GLMaterialLibrary1; } if (matMoon2) { GLSphere2->Material->LibMaterialName = "Moon2"; GLSphere2->Material->MaterialLibrary = GLMaterialLibrary1; } else if (matMoon1) { GLSphere2->Material->LibMaterialName = "Moon1"; GLSphere2->Material->MaterialLibrary = GLMaterialLibrary1; GLSphere2->Material->FrontProperties->Diffuse->Red = 0.7; GLSphere2->Material->FrontProperties->Diffuse->Green = 0.7; GLSphere2->Material->FrontProperties->Diffuse->Blue = 0.7; } // Назначаем материал для сферы3 if (matMoon3) { GLSphere3->Material->LibMaterialName = "Moon3"; GLSphere3->Material->MaterialLibrary = GLMaterialLibrary1; } else if (matMoon1) { GLSphere3->Material->LibMaterialName = "Moon1"; GLSphere3->Material->MaterialLibrary = GLMaterialLibrary1; GLSphere3->Material->FrontProperties->Diffuse->Red = 0.6; GLSphere3->Material->FrontProperties->Diffuse->Green = 0.7; GLSphere3->Material->FrontProperties->Diffuse->Blue = 1.0; } // Устанавливаем камеру в начальную позицию GLCamera1->Position->X = 0; GLCamera1->Position->Y = 0; GLCamera1->Position->Z = 5; // Настройка GLSceneViewer GLSceneViewer1->Buffer->BackgroundColor = clBlack; GLSceneViewer1->Buffer->AntiAliasing = aaNone; GLSceneViewer1->Buffer->DepthTest = true; GLUserInterface1->MouseLookActive = true; // Включаем кэденсер GLCadencer1->Enabled = true; } //--------------------------------------------------------------------------- void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime, const double newTime) { // Make clouds Texture slide TGLLibMaterial* cloudsMat = GLMaterialLibrary1->Materials->GetLibMaterialByName("Clouds"); if (cloudsMat) { cloudsMat->TextureOffset->X = cloudsMat->TextureOffset->X + deltaTime * 0.02; cloudsMat->TextureOffset->Y = cloudsMat->TextureOffset->Y + deltaTime * 0.03; } // Rotate spheres and disk GLSphere1->Turn(deltaTime * 7); // Сфера1: нормальная скорость GLSphere2->Turn(deltaTime * 18); // Сфера2: быстрая (в ~2.5 раза быстрее сферы1) GLSphere3->Turn(deltaTime * 12); // Сфера3: средняя скорость HandleKeys(deltaTime); GLUserInterface1->MouseLook(); GLUserInterface1->MouseUpdate(); GLSceneViewer1->Invalidate(); } //--------------------------------------------------------------------------- void __fastcall TForm1::HandleKeys(double d) { if (IsKeyDown('W')||IsKeyDown('Z')) GLCamera1->Move(d); if (IsKeyDown('S')) GLCamera1->Move(-d); if (IsKeyDown('A')) GLCamera1->Slide(-d); if (IsKeyDown('D')) GLCamera1->Slide(d); if (IsKeyDown(VK_SPACE)) Castle->Visible = !Castle->Visible; if (IsKeyDown(VK_ESCAPE)) Close(); } //---------------------------------------------------------------------------