Das Polygon soll rotiert werden, was es auch tut. Allerdings schrumpft es dabei auch, solange
die Rotationsgeschwindigkeit unter #PI/2 liegt, darüber wird es größer.
Mit Space rotieren lassen...
Code: Alles auswählen
Structure vertex
x.f
y.f
z.f
EndStructure
Structure polygon
color.l
x.f
y.f
z.f
List vertex.vertex()
EndStructure
Structure brush
id.l
x.f
y.f
z.f
List poly.polygon()
EndStructure
Procedure RotateMatrix(List vert.vertex(), alpha.f, beta.f, gamma.f)
;Um X-Achse rotieren
ForEach vert()
vert()\y = vert()\y*Cos(alpha) - vert()\z*Sin(alpha)
vert()\z = vert()\y*Sin(alpha) + vert()\z*Cos(alpha)
Next
;Um Y-Achse rotieren
ForEach vert()
vert()\x = vert()\x*Cos(beta) - vert()\z*Sin(beta)
vert()\z = vert()\x*Sin(beta) + vert()\z*Cos(beta)
Next
;Um Z-Achse rotieren
ForEach vert()
vert()\x = vert()\x*Cos(gamma) + vert()\y*Sin(gamma)
vert()\y = -vert()\x*Sin(gamma) + vert()\y*Cos(gamma)
Next
EndProcedure
fn.l = 20
Global Poly1.polygon
Poly1\color = RGB(255, 255, 0)
Poly1\x = 512
Poly1\y = 368
Poly1\z = 0
For i = 0 To fn - 1
AddElement(Poly1\vertex())
Poly1\vertex()\x = Round(Cos(i * 2 * #PI / fn) * 300 , 0)
Poly1\vertex()\y = Round(Sin(i * 2 * #PI / fn) * 300 , 0)
Poly1\vertex()\z = Sin(i) * 100
Next
InitSprite()
InitKeyboard()
OpenScreen(1024, 768, 32, "Screen")
Repeat
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Space) ;rotiert den Dreck
RotateMatrix(Poly1\vertex(), 0.1, 0.1, 0.1)
EndIf
; Den ganzen Müll darstellen
StartDrawing(ScreenOutput())
lsize.l = ListSize(Poly1\vertex())
SelectElement(Poly1\vertex(), 0)
t0x = Poly1\vertex()\x
t0y = Poly1\vertex()\y
t0z = Poly1\vertex()\z
For n = 0 To lsize - 1
If n + 1 < lsize
SelectElement(Poly1\vertex(), n + 1)
Else
SelectElement(Poly1\vertex(), 0)
EndIf
tx.l = Poly1\vertex()\x
ty.l = Poly1\vertex()\y
SelectElement(Poly1\vertex(), n)
LineXY(Poly1\vertex()\x + Poly1\x, Poly1\vertex()\y + Poly1\y, tx + Poly1\x, ty + Poly1\y, Poly1\color)
If n > 1 And n < lsize - 1
LineXY(Poly1\vertex()\x + Poly1\x, Poly1\vertex()\y + Poly1\y, t0x + Poly1\x, t0y + Poly1\y, Poly1\color - 100)
EndIf
Next
StopDrawing()
FlipBuffers()
ClearScreen(0)
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()
End