/
Frogush
/
LabVR
Обзор
Документация
Войти
/
Frogush
/
LabVR
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Lab_8/fEffectsFLAG.cpp
333 строки
11 KB
Frogush
upload files
08 дек 2025, 22:59
08 дек 2025, 22:59
134371b
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "fEffectsFLAG.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "GLS.BaseClasses" #pragma link "GLS.Scene" #pragma link "GLS.SceneViewer" #pragma link "GLS.Cadencer" #pragma link "GLS.FireFX" #pragma link "GLS.Coordinates" #pragma link "GLS.Objects" #pragma link "GLS.Tree" #pragma link "GLS.Material" #pragma link "GLS.FileTGA" #pragma link "GLS.BitmapFont" #pragma link "GLS.HUDObjects" #pragma link "GLS.WindowsFont" #pragma link "GLS.ThorFX" #pragma link "GLS.Graph" #pragma link "GLS.SkyDome" #pragma link "GLS.LensFlare" #pragma link "GLS.Atmosphere" #pragma resource "*.dfm" TfrmMain *frmMain; //--------------------------------------------------------------------------- __fastcall TfrmMain::TfrmMain(TComponent* Owner) : TForm(Owner) { Randomize(); String pathL1 = "../../Assets/leaf.png"; String pathL2 = "../../Assets/leaf2.png"; String pathL3 = "../../Assets/leaf3.png"; if (!FileExists(pathL1)) pathL1 = "leaf.png"; if (!FileExists(pathL2)) pathL2 = pathL1; if (!FileExists(pathL3)) pathL3 = pathL1; if (FileExists("../../Assets/ground.jpg")) GLHeightField1->Material->Texture->Image->LoadFromFile("../../Assets/ground.jpg"); GLMaterialLibrary1->AddTextureMaterial("Leaf1", pathL1); TGLLibMaterial *mat1 = GLMaterialLibrary1->Materials->GetLibMaterialByName("Leaf1"); mat1->Material->BlendingMode = bmAlphaTest50; mat1->Material->Texture->TextureMode = tmModulate; mat1->Material->Texture->TextureFormat = tfRGBA; GLMaterialLibrary1->AddTextureMaterial("Leaf2", pathL2); TGLLibMaterial *mat2 = GLMaterialLibrary1->Materials->GetLibMaterialByName("Leaf2"); mat2->Material->BlendingMode = bmAlphaTest50; mat2->Material->Texture->TextureMode = tmModulate; mat2->Material->Texture->TextureFormat = tfRGBA; GLMaterialLibrary1->AddTextureMaterial("Leaf3", pathL3); TGLLibMaterial *mat3 = GLMaterialLibrary1->Materials->GetLibMaterialByName("Leaf3"); mat3->Material->BlendingMode = bmAlphaTest50; mat3->Material->Texture->TextureMode = tmModulate; mat3->Material->Texture->TextureFormat = tfRGBA; GLMaterialLibrary1->AddTextureMaterial("Branch", "../../Assets/zbark.jpg"); GLMaterialLibrary1->Materials->GetLibMaterialByName("Branch")->Material->Texture->TextureMode = tmModulate; GLTree1->LeafMaterialName = "Leaf1"; GLTree1->BranchMaterialName = "Branch"; GLTree1->StructureChanged(); for (int i = 0; i < GLTree1->Count; i++) { TGLSceneObject *Obj = dynamic_cast<TGLSceneObject*>(GLTree1->Children[i]); if (Obj) { if (Obj->Material->LibMaterialName != "Branch") { int r = Random(3); if (r == 0) Obj->Material->LibMaterialName = "Leaf1"; if (r == 1) Obj->Material->LibMaterialName = "Leaf2"; if (r == 2) Obj->Material->LibMaterialName = "Leaf3"; } Obj->Visible = false; } } if (FileExists("../../Assets/marbletiles.jpg")) GLHeightField2->Material->Texture->Image->LoadFromFile("../../Assets/marbletiles.jpg"); if (FileExists("../../Assets/earth_4096.jpg")) GLSphere1->Material->Texture->Image->LoadFromFile("../../Assets/earth_4096.jpg"); GLSkyDome3->Bands->Clear(); GLSkyDome3->Stars->AddRandomStars(5000, ConvertColorVector(clrWhite)); GLAtmosphere1->TogleBlendingMode(); GLHUDText1->Text = " Press \"w\" - up, \"s\" - down, \"a, q\" - left, \"d, e\" - right."; GLFireFXManager1->InnerColor->AsWinColor = clLime; GLFireFXManager1->OuterColor->AsWinColor = clGreen; GLFireFXManager1->MaxParticles = 5000; i_f = 0; } //--------------------------------------------------------------------------- void __fastcall TfrmMain::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { mx = X; my = Y; } //--------------------------------------------------------------------------- void __fastcall TfrmMain::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 TfrmMain::GLSceneViewer1MouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta, TPoint &MousePos, bool &Handled) { GLCamera1->AdjustDistanceToTarget(Power(1.1, -WheelDelta / 120)); } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TfrmMain::GLCadencer1Progress(TObject *Sender, const double DeltaTime, const double NewTime) { // 1. �������� ��������� (��� ����) if (RadioButton3->Checked) { GLSphere1->Turn(DeltaTime * 20); } // 2. ������ ���� if (RadioButton1->Checked) { // --- ���������� ����� (WASD + QE) --- // ���������� ���� ������ ��� � ���� � ��������� if(IsKeyDown(87)) GLDummyCube4->Position->Y += DeltaTime; // W if(IsKeyDown(83)) GLDummyCube4->Position->Y -= DeltaTime; // S if(IsKeyDown(65)) GLDummyCube4->Position->X += DeltaTime; // A if(IsKeyDown(68)) GLDummyCube4->Position->X -= DeltaTime; // D if(IsKeyDown(81)) GLDummyCube4->Position->Z += DeltaTime; // Q if(IsKeyDown(69)) GLDummyCube4->Position->Z -= DeltaTime; // E // --- ����� �����: �������� ������ ���� --- // ������� ������ "�������" ���� � ������� ������ �� ������� float pulse = sin(NewTime * 4.0) * 0.15; // ������� ��������� �������� (����� ����� �� ��� ������������) // rand() % 50 ���� ����� �� 0 �� 49, ����� �� 200.0 ��� ������ ����� float flicker = (rand() % 50) / 200.0; // ������ "�������� ����" (���������� ������) ����������� // ���� 1.2 + ��������� + ����������� GLFireFXManager1->FireBurst = 1.2 + pulse + flicker; // ������� ������ ������ ������ � ���� (� ������ ��������) GLFireFXManager1->ParticleSize = 0.5 + (cos(NewTime * 6.0) * 0.05); } // 3. ����� �� Esc if(IsKeyDown(27)) { Close(); } } //--------------------------------------------------------------------------- void __fastcall TfrmMain::TrackBar1Change(TObject *Sender) { // ����� ���� (Wind) if (RadioButton1->Checked) { // 1. ������ ���� (��� ����) GLFireFXManager1->FireDir->X = TrackBar1->Position * 0.1; // 2. �����: ���� ����� ������ �� ����� ���� // abs() ����� ������ ����� (����� �������� � �����, � ������) // ��� ������� �����, ��� ������ ����� ������� (ParticleLife) float windPower = abs(TrackBar1->Position); // ������� ����� 1.0 ��� + ������� �� ����� GLFireFXManager1->ParticleLife = 1.0 + (windPower / 10.0); } // ����� ������ (Glow Size) if (RadioButton2->Checked) { GLThorFXManager1->GlowSize = (float)TrackBar1->Position / 50; } } //--------------------------------------------------------------------------- void __fastcall TfrmMain::Timer1Timer(TObject *Sender) { frmMain->Caption = "Lab8 Fire, lightning and atmosphere glow effects - " + GLSceneViewer1->FramesPerSecondText(); if (i_f < GLTree1->Count && RadioButton1->Checked) { GLTree1->Children[i_f]->Visible = true; i_f++; } } //--------------------------------------------------------------------------- void __fastcall TfrmMain::RadioButton1Click(TObject *Sender) { GLDummyCube1->Visible = false; GLDummyCube2->Visible = false; GLDummyCube3->Visible = false; Label2->Visible = false; Label3->Visible = false; Label4->Visible = false; Label5->Visible = false; TrackBar1->Visible = false; TrackBar2->Visible = false; TrackBar3->Visible = false; TrackBar4->Visible = false; CheckBox1->Visible = false; CheckBox2->Visible = false; CheckBox3->Visible = false; GLFireFXManager1->Disabled = true; GLThorFXManager1->Disabled = true; GLHUDText1->Visible = false; GLLightSource1->Position->X = 0; if (RadioButton1->Checked) { GLCamera1->TargetObject = GLDummyCube1; GLDummyCube1->Visible = true; Label2->Visible = true; Label2->Caption = "Wind:"; TrackBar1->Visible = true; TrackBar1->Max = 20; TrackBar1->Min = -20; TrackBar1->Position = 0; GLFireFXManager1->Disabled = false; GLHUDText1->Visible = true; } if (RadioButton2->Checked) { GLCamera1->TargetObject = GLDummyCube2; GLDummyCube2->Visible = true; Label2->Visible = true; Label2->Caption = "Glow Size:"; TrackBar1->Visible = true; TrackBar1->Max = 50; TrackBar1->Min = 0; TrackBar1->Position = 10; Label2->Visible = true; Label3->Visible = true; Label4->Visible = true; Label5->Visible = true; TrackBar1->Visible = true; TrackBar2->Visible = true; TrackBar3->Visible = true; TrackBar4->Visible = true; CheckBox1->Visible = true; CheckBox2->Visible = true; CheckBox3->Visible = true; GLThorFXManager1->Disabled = false; CheckBox2Click(Sender); } if (RadioButton3->Checked) { GLLightSource1->Position->X = 30; GLCamera1->TargetObject = GLDummyCube3; GLDummyCube3->Visible = true; } } //--------------------------------------------------------------------------- void __fastcall TfrmMain::TrackBar2Change(TObject *Sender) { GLThorFXManager1->InnerColor->Alpha = (float)TrackBar2->Position / 50; } //--------------------------------------------------------------------------- void __fastcall TfrmMain::TrackBar3Change(TObject *Sender) { GLThorFXManager1->Wildness = (float)TrackBar3->Position / 5; } //--------------------------------------------------------------------------- void __fastcall TfrmMain::TrackBar4Change(TObject *Sender) { GLThorFXManager1->Vibrate = (float)TrackBar4->Position / 10; } //--------------------------------------------------------------------------- void __fastcall TfrmMain::CheckBox1Click(TObject *Sender) { GLThorFXManager1->Core = CheckBox1->Checked; } //--------------------------------------------------------------------------- void __fastcall TfrmMain::CheckBox2Click(TObject *Sender) { GLThorFXManager1->Disabled = CheckBox2->Checked; } //--------------------------------------------------------------------------- void __fastcall TfrmMain::GLThorFXManager1CalcPoint(TObject *Sender, int PointNo, float &x, float &y, float &z) { if (CheckBox3->Checked) { float Place = (float)PointNo / GLThorFXManager1->Maxpoints; float Spin = (Place * M_PI) * 10 + (GLCadencer1->CurrentTime * 20); float Scale = (float)Sin(Place * M_PI) / 2; y = y + Sin(Spin) * Scale; x = x + Cos(Spin) * Scale; } } //--------------------------------------------------------------------------- void __fastcall TfrmMain::GLHeightField2GetHeight(const float x, const float y, float &z, TGLColorVector &Color, TTexPoint &TexPoint) { z = 2; } //---------------------------------------------------------------------------