Code : Tout sélectionner
Structure World3D
x.f
y.f
z.f
EndStructure
Global Dim Point3D.World3D(8)
Global Dim Point2D.World3D(8)
Global Dim Sommet.World3D(8)
#Xoff = 512
#Yoff = 384
#Zoff = 250
Global Dim Matrice.f(3,3)
; /****************************************************************************/
; /* Rotation() : effectue la rotation des points Sommets -> Point3D */
; /****************************************************************************/
Procedure Rotation(Xa.f,Ya.f,Za.f)
matrice(0,0) = Cos(Za)*Cos(Ya)
matrice(1,0) = Sin(Za)*Cos(Ya)
matrice(2,0) = -Sin(Ya)
matrice(0,1) = Cos(Za)*Sin(Ya)*Sin(Xa) - Sin(Za)*Cos(Xa)
matrice(1,1) = Sin(Za)*Sin(Ya)*Sin(Xa) + Cos(Xa)*Cos(Za)
matrice(2,1) = Sin(Xa)*Cos(Ya)
matrice(0,2) = Cos(Za)*Sin(Ya)*Cos(Xa) + Sin(Za)*Sin(Xa)
matrice(1,2) = Sin(Za)*Sin(Ya)*Cos(Xa) - Cos(Za)*Sin(Xa)
matrice(2,2) = Cos(Xa)*Cos(Ya)
For i = 0 To 7
Point3D(i)\x = matrice(0,0)*Sommet(i)\x + matrice(1,0)*Sommet(i)\y + matrice(2,0)*Sommet(i)\z
Point3D(i)\y = matrice(0,1)*Sommet(i)\x + matrice(1,1)*Sommet(i)\y + matrice(2,1)*Sommet(i)\z
Point3D(i)\z = matrice(0,2)*Sommet(i)\x + matrice(1,2)*Sommet(i)\y + matrice(2,2)*Sommet(i)\z
Next i
EndProcedure
; /****************************************************************************/
; /* Projection() : projette en perspective les points après rotation. */
; /****************************************************************************/
Procedure Projection()
For i = 0 To 7
Point2D(i)\x=(Point3D(i)\x*256)/(Point3D(i)\z+#Zoff)+#Xoff;
Point2D(i)\y=(Point3D(i)\y*256)/(Point3D(i)\z+#Zoff)+#Yoff;
Next i
EndProcedure
; /****************************************************************************/
; /* Initialiser() : initialise les coordonnees des sommets du cube */
; /****************************************************************************/
Procedure Initialiser()
Sommet(0)\x = -100 : Sommet(0)\y = -100 : Sommet(0)\z = -100
Sommet(1)\x = 100 : Sommet(1)\y = -100 : Sommet(1)\z = -100
Sommet(2)\x = 100 : Sommet(2)\y = 100 : Sommet(2)\z = -100
Sommet(3)\x = -100 : Sommet(3)\y = 100 : Sommet(3)\z = -100
Sommet(4)\x = 100 : Sommet(4)\y = -100 : Sommet(4)\z = 100
Sommet(5)\x = -100 : Sommet(5)\y = -100 : Sommet(5)\z = 100
Sommet(6)\x = -100 : Sommet(6)\y = 100 : Sommet(6)\z = 100
Sommet(7)\x = 100 : Sommet(7)\y = 100 : Sommet(7)\z = 100
EndProcedure
Procedure ligne(a.l,b.l,couleur.l)
LineXY(Point2D(a)\x,Point2D(a)\y,Point2D(b)\x,Point2D(b)\y,couleur);
EndProcedure
Procedure Update()
Static Couleur.l
Couleur = RGB(100,100,255)
StartDrawing(ScreenOutput())
For i = 0 To 7
Circle(Point2D(i)\x,Point2D(i)\y,3,Couleur)
;
; Locate(Point2D(i)\x,Point2D(i)\y)
; DrawText(Str(i))
;
;
ligne(0,1,couleur)
ligne(1,2,couleur)
ligne(2,3,couleur)
ligne(3,0,couleur)
ligne(4,5,couleur)
ligne(5,6,couleur)
ligne(6,7,couleur)
ligne(7,4,couleur)
ligne(0,5,couleur)
ligne(1,4,couleur)
ligne(2,7,couleur)
ligne(3,6,couleur)
Next i
StopDrawing()
EndProcedure
InitSprite () : InitKeyboard () : InitMouse ()
OpenScreen (1024,768,32, "" )
Initialiser()
Repeat
ExamineKeyboard () : ExamineMouse() : ClearScreen (0)
Xangle.f + 0.01
Yangle.f + 0.03
ZAngle.f + 0.01
Rotation(Xangle,Yangle,Zangle)
Projection()
Update()
FlipBuffers ()
Until KeyboardPushed ( #PB_Key_Escape )