//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "GLWin32Viewer"
#pragma link "GLMisc"
#pragma link "GLScene"
#pragma link "GLCadencer"
#pragma link "GLMirror"
#pragma link "GLObjects"
#pragma link "GLGeomObjects"
#pragma link "GLExtrusion"
#pragma link "GLMultiPolygon"
#pragma link "GLTeapot"
#pragma resource "*.dfm"
TForm1 *Form1;
int mx, my;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent * Owner):TForm(Owner)
{
}

//---------------------------------------------------------------------------

void __fastcall TForm1::CBOpaqueClick(TObject * Sender)
{
  if(CBOpaque->Checked)
    GLMirror1->MirrorOptions << moOpaque;
  else
    GLMirror1->MirrorOptions >> moOpaque;
}

//---------------------------------------------------------------------------

void __fastcall TForm1::CBStencilClick(TObject * Sender)
{
  if(CBStencil->Checked)
    GLMirror1->MirrorOptions << moUseStencil;
  else
    GLMirror1->MirrorOptions >> moUseStencil;
}

//---------------------------------------------------------------------------

void __fastcall TForm1::CBClearZClick(TObject * Sender)
{
  if(CBClearZ->Checked)
    GLMirror1->MirrorOptions << moClearZBuffer;
  else
    GLMirror1->MirrorOptions >> moClearZBuffer;
}

//---------------------------------------------------------------------------

void __fastcall TForm1::CBPlaneClipClick(TObject * Sender)
{
  if(CBPlaneClip->Checked)
    GLMirror1->MirrorOptions << moMirrorPlaneClip;
  else
    GLMirror1->MirrorOptions >> moMirrorPlaneClip;
}

//---------------------------------------------------------------------------

void __fastcall TForm1::Timer1Timer(TObject * Sender)
{
  Caption = GLSceneViewer1->FramesPerSecondText(1);
  //String(GLSceneViewer1->FramesPerSecond()) + " FPS";
  GLSceneViewer1->ResetPerformanceMonitor();
}

//---------------------------------------------------------------------------

void __fastcall TForm1::GLCadencer1Progress(TObject * Sender,
                                            const double deltaTime,
                                            const double newTime)
{
  GLSceneViewer1->Invalidate();
}

//---------------------------------------------------------------------------

void __fastcall TForm1::FormResize(TObject * Sender)
{
  if(GLSceneViewer1->Width > GLSceneViewer1->Height)
    GLCamera1->SceneScale = (float)GLSceneViewer1->Height / 300;
  else
    GLCamera1->SceneScale = (float)GLSceneViewer1->Width / 360;
}

//---------------------------------------------------------------------------

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(ssShift))
  {
    GLCamera1->MoveAroundTarget(my - Y, mx - X);
    mx = X;
    my = Y;
  }
}

//---------------------------------------------------------------------------

