je ne trouve pas l'erreur de ce code
Publié : sam. 26/nov./2005 20:24
ce code est sencé afficher un cube bleu au mileu de l'ecran
mais sa marche pas
au lancement le cube est de face donc on devrai voir un carre !
le cube tourne quan on appuie sur haut / bas / droite / gauche
voila ...
mais sa marche pas
au lancement le cube est de face donc on devrai voir un carre !
le cube tourne quan on appuie sur haut / bas / droite / gauche
voila ...
Code : Tout sélectionner
Resultat = InitSprite()
EcranX = GetSystemMetrics_(#SM_CXSCREEN) : ; =largeur de l'ecran
EcranY = GetSystemMetrics_(#SM_CYSCREEN) : ; =hauteur de l'ecran
WindowID = OpenWindow(1, 100, 100, 800, 600, #PB_Window_SystemMenu | #PB_Window_BorderLess, "hello")
WindowID = WindowID(1)
Result = OpenWindowedScreen(WindowID, 0, 0, 800, 600, 1, 0, 0)
InitKeyboard()
#pi = 3.1415
Structure 3d
x.l
y.l
z.l
EndStructure
DataSection
point :
Data.l 8
Data.l -100, 100, 100, -100, -100, 100, 100, -100 ; coordonée x des points
Data.l 100, 100, 100, 100, -100, -100, -100, -100 ; coordonée y des points
Data.l -100, -100, 100, 100, 100, 100, -100, -100 ; coordonée z des points
ligne :
Data.l 12
Data.l 4, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 1, 8, 5, 3, 6, 2, 7 ; couples de point qui forme une ligne
EndDataSection
Global Dimentionp, Dimentionl
Restore point
Read z
Dimentionp = z
Dim Poin.3d(z)
Dim angle.l(z)
For ligne = 1 To 3
For colonne = 1 To z
If ligne = 1
Read z1
Poin(colonne)\x = z1
ElseIf ligne = 2
Read z2
Poin(colonne)\y = z2
ElseIf ligne = 3
Read z3
Poin(colonne)\z = z3
EndIf
Next
Next
Restore ligne
Read z
Dimentionl = z
Dim ligne.Point(2 * z)
For colonne = 1 To z Step 2
Read z1
ligne(colonne)\x = z1
Read z1
ligne(colonne)\y = z1
Next
Procedure Display3d(coorx, coory, rotationz.f, rotationy.f, rotationx.f, color)
; rotation autour de z
For curseur = 1 To Dimentionp
If poin(curseur)\x <> 0
angle(curseur) = rotationz + ATan(poin(curseur)\y / poin(curseur)\x)
If poin(curseur)\x <= 0
angle(curseur) = 180 + angle(curseur)
EndIf
ElseIf poin(curseur)\y > 0
angle(curseur) = 90 + rotationz
ElseIf poin(curseur)\y <= 0
angle(curseur) = 180 + rotationz
EndIf
distance.f = Sqr(poin(curseur)\x * poin(curseur)\x + poin(curseur)\y * poin(curseur)\y)
poin(curseur)\x = distance * Cos(angle(curseur))
poin(curseur)\y = distance * Sin(angle(curseur))
Next
;rotation autour de y
For curseur = 1 To Dimentionp
If poin(curseur)\x <> 0
angle(curseur) = rotationy + ATan(poin(curseur)\z / poin(curseur)\x)
If poin(curseur)\x <= 0
angle(curseur) = 180 + angle(curseur)
EndIf
ElseIf poin(curseur)\y > 0
angle(curseur) = 90 + rotationy
ElseIf poin(curseur)\y <= 0
angle(curseur) = 180 + rotationy
EndIf
distance.f = Sqr(poin(curseur)\x * poin(curseur)\x + poin(curseur)\z * poin(curseur)\z)
poin(curseur)\x = distance * Cos(angle(curseur))
poin(curseur)\z = distance * Sin(angle(curseur))
Next
;rotation autour de x
For curseur = 1 To Dimentionp
If poin(curseur)\z <> 0
angle(curseur) = rotationx + ATan(poin(curseur)\y / poin(curseur)\z)
If poin(curseur)\z <= 0
angle(curseur) = 180 + angle(curseur)
EndIf
ElseIf poin(curseur)\y > 0
angle(curseur) = 90 + rotationx
ElseIf poin(curseur)\y <= 0
angle(curseur) = 180 + rotationx
EndIf
distance.f = Sqr(poin(curseur)\z * poin(curseur)\z + poin(curseur)\y * poin(curseur)\y)
poin(curseur)\z = distance * Cos(angle(curseur))
poin(curseur)\y = distance * Sin(angle(curseur))
Next
; dessin de cote
For curseur = 1 To Dimentionl
point1 = ligne(curseur)\x
point2 = ligne(curseur)\y
pointx1 = poin(point1)\x + coorx
pointy1 = poin(point1)\y + coory
pointx2 = poin(point2)\x + coorx
pointy2 = poin(point2)\y + coory
Debug "point 1 ( " + Str(pointx1) + " , " + Str(pointy1)
Debug "point 2 ( " + Str(pointx2) + " , " + Str(pointy2)
LineXY(pointx1, pointy1, pointx2, pointy2, color)
Next
EndProcedure
coorx = 400
coory = 300
Repeat
Delay(10)
rotz.f = 0
roty.f = 0
rotx.f = 0
ExamineKeyboard()
If KeyboardPushed(#pb_key_up) : rotx = #pi / 10
ElseIf KeyboardPushed(#pb_key_down) : rotx = -#pi / 10
ElseIf KeyboardPushed(#pb_key_right) : roty = #pi / 10
ElseIf KeyboardPushed(#pb_key_left) : roty = -#pi / 10
EndIf
ClearScreen(0, 0, 0)
StartDrawing(ScreenOutput())
Display3d(coorx, coory, rotz, roty, rotx, RGB(0, 0, 255))
StopDrawing()
FlipBuffers()
Until KeyboardPushed(#pb_key_escape)