Here is the complete program listing.

The result is a rotating red star following the cursor. Written without OpenGl.

Explain to me a couple of points.

There is unit1.h in it there is a trace. strings, and what do they mean?

class TForm1 : public TForm { __published: TTimer *Timer1; void __fastcall FormMouseMove(TObject *Sender, TShiftState Shift, int X, int Y); void __fastcall FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta, TPoint &MousePos, bool &Handled); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); void DrawPoints(); SortTriangles(); Graphics::TBitmap*BackBuffer; }; 

PS on the form there is a timer that is responsible for the rotation of the shape.

Next, what's the z-buffer? and generally where about him read the sensible material?

Then it is not clear the last lines in the listing, namely these:

 void TForm1::DrawPoints() { TFPoint point1,point2,point3; BackBuffer->Canvas->Brush->Color=clBlack; BackBuffer->Canvas->FillRect(Form1->GetClientRect()); BackBuffer->Canvas->Brush->Color=clRed; BackBuffer->Canvas->Pen->Color=clOlive; BackBuffer->Canvas->Pen->Width=1; TPoint p[3]; SortTriangles(); for(int i=0;i<TrCol;i++) { point1=XYZtoXY(StarPoints[Triangles[i].p1].X,StarPoints[Triangles[i].p1].Y,StarPoints[Tri angles[i].p1].Z); point2=XYZtoXY(StarPoints[Triangles[i].p2].X,StarPoints[Triangles[i].p2].Y,StarPoints[Triangles[i].p2].Z); point3=XYZtoXY(StarPoints[Triangles[i].p3].X,StarPoints[Triangles[i].p3].Y,StarPoints[Triangles[i].p3].Z); p[0].x=point1.X; p[0].y=point1.Y; p[1].x=point2.X; p[1].y=point2.Y; p[2].x=point3.X; p[2].y=point3.Y; BackBuffer->Canvas->Polygon(p,2); } Canvas->Draw(0,0,BackBuffer); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { rotation-=(X-oldX)/50.0; plane-=(Y-oldY)/100.0; DrawPoints(); oldX=X; oldY=Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta, TPoint &MousePos, bool &Handled) { distance+=WheelDelta/1000.0; DrawPoints(); } 

    1 answer 1

    What exactly is this - you do not understand?

    In the .h file, the form is traditionally initialized.

    The code in the second block is responsible for drawing with the help of an "offscreen" (or dual) buffer. And the reaction to the rustle of the mouse.

    The z-buffer is a depth buffer. This is when for each point of the screen it is considered how far what is drawn on it "from the screen". Here it is not as such.

    Actually, the most interesting thing you didn’t show here:

    1. Formulas for recalculation from "3D to 2D".
    2. The method of sorting triangles so that the more distant ones were drawn earlier than the closer ones (moreover, the turd will turn out).
    • Formulas for recalculation from "3D to 2D". ? - Timi
    • XYZtoXY (x, y, z) - SilverIce