| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include <tchar.h>
- #pragma hdrstop
- #include "fcProjection.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "GLS.BaseClasses"
- #pragma link "GLS.Coordinates"
- #pragma link "GLS.GeomObjects"
- #pragma link "GLS.Graph"
- #pragma link "GLS.Objects"
- #pragma link "GLS.Scene"
- #pragma link "GLS.SceneViewer"
- #pragma link "GLS.BaseClasses"
- #pragma resource "*.dfm"
- TFormProjection *FormProjection;
- //---------------------------------------------------------------------------
- __fastcall TFormProjection::TFormProjection(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TFormProjection::FormCreate(TObject* Sender)
- {
- int i;
- // generate a bunch of random points
- for (i = 1; i < 1000; i++) {
- GLPoints->Positions->Add((float)(Random() - 0.5) * 5,
- (float)(Random() - 0.5) * 5, (float)(Random() - 0.5) * 5);
- GLPoints->Colors->Add(Random(), Random(), Random(), 0.8);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TFormProjection::DirectOpenGLRender(TObject *Sender, TGLRenderContextInfo &rci)
- {
- int i;
- TGLMatrix mat;
- TGLVector p, pProj;
- TGLVector planePoint, planeNormal;
- THmgPlane plane;
- // Here we recover our plane point and normal...
- planePoint = GLPlane->Position->AsVector;
- planeNormal = GLPlane->Direction->AsVector;
- // ...which we use to create a plane (equation)
- plane = PlaneMake(planePoint, planeNormal);
- // from that plane equation and our pojection direction
- // (which is here the plane normal)
- mat = MakeParallelProjectionMatrix(plane, planeNormal);
- // save state, turn off lighting and specify the lines color
- rci.GLStates->Disable(stLighting);
- glColor3f(1, 1, 0);
- // we'll be drawing a bunch of lines, to specify a line in OpenGL,
- // you only need to specify the line start and end vertices
- glBegin(GL_LINES);
- for (i=0; i < GLPoints->Positions->Count-1; i++) {
- // read the point coordinates, directly from the TGLPoints list
- MakePoint(p, GLPoints->Positions->Items[i]);
- // project this point on the plane with the matrix
- pProj = VectorTransform(p, mat);
- // specify the two vertices
- glVertex3fv(p.V);
- glVertex3fv(pProj.V);
- }
- glEnd();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFormProjection::SceneViewerMouseDown(TObject *Sender, TMouseButton Button,
- TShiftState Shift, int X, int Y)
- {
- mx = X; my = Y;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFormProjection::SceneViewerMouseMove(TObject *Sender, TShiftState Shift, int X,
- int Y)
- {
- if (Shift.Contains(ssLeft))
- GLCamera->MoveAroundTarget(my-Y, mx-X);
- else if (Shift.Contains(ssRight))
- GLCamera->RotateObject(GLPlane, my-Y, mx-X);
- mx = X; my = Y;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFormProjection::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
- TPoint &MousePos, bool &Handled)
- {
- GLPlane->Position->Y = GLPlane->Position->Y+WheelDelta*0.001;
- }
- //---------------------------------------------------------------------------
|