123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include <tchar.h>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "GLS.BaseClasses"
- #pragma link "GLS.Cadencer"
- #pragma link "GLS.Coordinates"
- #pragma link "GLS.Objects"
- #pragma link "GLS.Scene"
- #pragma link "GLS.SkyDome"
- #pragma link "GLS.GeomObjects"
- #pragma link "GLS.SceneViewer"
- #pragma link "GLS.Imposter"
- #pragma resource "*.dfm"
- TForm1 *Form1;
- TGLRenderPoint *renderPoint;
- //TGLStaticImposterBuilder impBuilder;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- renderPoint = (TGLRenderPoint *) GLDummyCube1->AddNewChild(__classid(TGLRenderPoint));
- /* to do
- impBuilder = TGLStaticImposterBuilder.Create(Self);
- impBuilder->SampleSize = 64;
- impBuilder->SamplingRatioBias = 1.3;
- impBuilder->Coronas->Items[0].Samples = 32;
- impBuilder->Coronas->Add(15, 24);
- impBuilder->Coronas->Add(30, 24);
- impBuilder->Coronas->Add(45, 16);
- impBuilder->Coronas->Add(60, 16);
- impBuilder->Coronas->Add(85, 16);
- impBuilder->RenderPoint = renderPoint;
- impBuilder->RequestImposterFor(GLTeapot1);
- */
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
- const double newTime)
- {
- GLSceneViewer1->Invalidate();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Timer1Timer(TObject *Sender)
- {
- LabelFPS->Caption = GLSceneViewer1->FramesPerSecondText();
- if (CBShowImposter->Checked)
- LabelFPS->Caption = LabelFPS->Caption +" - 3721 imposters";
- /*
- LabelTexSize->Caption = Format("%d x %d - %.1f%%",
- ARRAYOFCONST((impBuilder->TextureSize->X, impBuilder->TextureSize->Y,
- impBuilder->TextureFillRatio*100)));
- */
- GLSceneViewer1->ResetPerformanceMonitor();
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::CBShowTeapotClick(TObject *Sender)
- {
- GLTeapot1->Visible = CBShowTeapot->Checked;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::CBShowImposterClick(TObject *Sender)
- {
- GLDirectOpenGL1->Visible = CBShowImposter->Checked;
- }
- //---------------------------------------------------------------------------
- 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::GLDirectOpenGL1Render(TObject *Sender, TGLRenderContextInfo &rci)
- {
- int x, y;
- Gls::Vectorgeometry::TVector camPos;
- Gls::Vectorgeometry::TVector pos;
- /* to do
- TImposter *imp;
- imp = impBuilder->ImposterFor(GLTeapot1);
- if ((imp=nil) or (imp->Texture->Handle=0)) Exit;
- imp->BeginRender(rci);
- for (x=-30; x<30; x++) do
- for (y=-30;y<30; y++) do {
- MakePoint(pos, x*5, 0, y*4);
- camPos = VectorSubtract(rci->cameraPosition, pos);
- imp->Render(rci, pos, camPos, 1);
- }
- imp->EndRender(rci);
- */
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
- TShiftState Shift, int X, int Y)
- {
- mx = X;
- my = Y;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
- TPoint &MousePos, bool &Handled)
- {
- GLCamera1->
- AdjustDistanceToTarget(Power(1.1, (WheelDelta / 120.0)));
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormResize(TObject *Sender)
- {
- if(GLSceneViewer1->Width > GLSceneViewer1->Height)
- GLCamera1->SceneScale = (float)GLSceneViewer1->Height / 300;
- else
- GLCamera1->SceneScale = (float)GLSceneViewer1->Width / 360;
- }
- //---------------------------------------------------------------------------
|