/
DmitryBar
/
computer_modeling
Обзор
Документация
Войти
/
DmitryBar
/
computer_modeling
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Lab1/source/fProjections.cpp
100 строк
3 KB
Dmitry
Выполнение первой лабораторной работы
17 окт 2024, 13:08
17 окт 2024, 13:08
569e597
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #include <vcl.h> #include <tchar.h> #pragma hdrstop #include "fProjections.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "GLS.GeomObjects" #pragma link "GLS.Graph" #pragma link "GLS.Objects" #pragma link "GLS.Scene" #pragma link "GLS.SceneViewer" #pragma link "GLScene.BaseClasses" #pragma link "GLScene.BaseClasses" #pragma resource "*.dfm" TFormProjections *FormProjections; //--------------------------------------------------------------------------- __fastcall TFormProjections::TFormProjections(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TFormProjections::FormCreate(TObject* Sender) { int i; int NStars; NStars = 10000; // ��������� ����� ���� �� ����� ����� // ��������� ��������� ��������� ���� for (i = 1; i < NStars; 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 TFormProjections::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 TFormProjections::SceneViewerMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { mx = X; my = Y; } //--------------------------------------------------------------------------- void __fastcall TFormProjections::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 TFormProjections::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta, TPoint &MousePos, bool &Handled) { GLPlane->Position->Y = GLPlane->Position->Y+WheelDelta*0.001; } //---------------------------------------------------------------------------