3D-Punkt
Verfasst: 22.02.2006 22:18
Wie kann ich am einfachsten und
schnellsten einen Punkt in einer 3D Umgebung darstellen?
Stehend!
schnellsten einen Punkt in einer 3D Umgebung darstellen?
Stehend!
Code: Alles auswählen
Global d_scrw2.f,d_scrh2.f ;(ScreenWidth/2;ScreenHeight/2)
#zoom2 = 300
Dim _sin.f(360)
Dim _cos.f(360)
For x = 0 To 360
_sin(x) = Sin(x/(180/3.141))
_cos(x) = Cos(x/(180/3.141))
Next x
Procedure d_point3d(x1.f,y1.f,z1.f,wx.l,wy.l,wz.l,color.l) ;wx;wy;wz -> KameraPosition
Protected draw
Protected xx.f,yy.f,zz.f
; Drehung berechnen
xx.f = _cos(wy) * _cos(wz) * x1 - _cos(wy) * _sin(wz) * y1 + _sin(wy) * z1
yy.f = (_cos(wx) * _sin(wz) + _sin(wx) * _sin(wy) * _cos(wz)) * x1 + (_cos(wx) * _cos(wz) - _sin(wx) * _sin(wy) * _sin(wz)) * y1 - _sin(wx) * _cos(wy) * z1
zz.f = (_sin(wx) * _sin(wz) - _cos(wx) * _sin(wy) * _cos(wz)) * x1 + (_sin(wx) * _cos(wz) + _cos(wx) * _sin(wy) * _sin(wz)) * y1 + _cos(wx) * _cos(wy) * z1
yy = -yy
;Testen ob die Linie hinter der Camera ist
draw = 1
If zz >= 0
; 1. In 2D-Coordianten umwandeln 2. Malen
; "normale" Perspektive
Debug Round(xx*#zoom2/(zz+1),0)+d_scrw2
Debug Round(yy*#zoom2/(zz+1),0)+d_scrh2
Plot(Round(xx*#zoom2/(zz+1),0)+d_scrw2,Round(yy*#zoom2/(zz+1),0)+d_scrh2,color)
; Kavalierperspektive
;LineXY(Round(xx-zz/2.828,0)+scrw2,Round(yy-zz/2.828,0)+scrh2,Round(xx2-zz2/2.828,0)+scrw2,Round(yy2-zz2/2.828,0)+scrh2)
EndIf
EndProcedure
OpenWindow(0,0,0,400,400,#PB_Window_ScreenCentered|#PB_Window_SystemMenu,"")
d_scrw2 = 200
d_scrh2 = 200
Repeat
StartDrawing(WindowOutput())
z = Random(1000)
d_point3d(Random(400)-200,Random(400)-200,z,0.0,0.0,0.0,255<<16+z)
StopDrawing()
Repeat
WE = WindowEvent()
Select WE
Case #PB_Event_CloseWindow
quit = 1
EndSelect
Until WE = 0
Until quit