Hi
Test that function:
with this
hope that is what you need
(btw nice gui!, thank's)
Edit:
there are a sign error in x and y, please modify the function to:
Juan
Test that function:
Function PitchYawToVector(pitch#,yaw#,dest.Vector) dest\x = Cos(pitch) * Sin(yaw) dest\y = Sin(pitch) dest\z = Cos(pitch) * Cos(yaw) NormalizarVector(dest) End Function
with this
Type Vector Field x#, y#, z# End Type v.Vector = New vector Graphics3D 800,600,0,2 SetBuffer = BackBuffer() cam = CreateCamera() PositionEntity cam,0,0,-5 light = CreateLight() cube1 = CreateCube() ScaleEntity cube1,.1,.1,1 EntityColor cube1,255,0,0 Cube1Pitch# = 0 Cube1Yaw# = 0 Repeat If KeyDown(200) Then Cube1Pitch = Cube1Pitch + 1 If KeyDown(208) Then Cube1Pitch = Cube1Pitch - 1 If KeyDown(203) Then Cube1Yaw = Cube1Yaw + 1 If KeyDown(205) Then Cube1Yaw = Cube1Yaw - 1 RotateEntity cube1, Cube1Pitch, Cube1Yaw, 0, True PitchYawToVector(Cube1Pitch, Cube1Yaw, v) RenderWorld Text 10,10,Cube1Pitch Text 10,30,Cube1Yaw Text 100,10,v\x Text 100,30,v\y Text 100,50,v\z Text 100,70,Magnitud(v) TFormVector 0,0,1, Cube1, 0 Text 200,10,TFormedX() Text 200,30,TFormedY() Text 200,50,TFormedZ() v\x = TFormedX() v\y = TFormedY() v\z = TFormedZ() Text 200,70,Magnitud(v) Flip Until KeyHit(1) End Function PitchYawToVector(pitch#,yaw#,dest.Vector) dest\x = Cos(pitch) * Sin(yaw) dest\y = Sin(pitch) dest\z = Cos(pitch) * Cos(yaw) NormalizarVector(dest) End Function Function CuadradoVector#(v.Vector) Return v\X*v\X + v\y*v\y + v\Z*v\Z End Function Function Magnitud#(V.Vector) Return Float(Sqr(CuadradoVector(V))) End Function Function NormalizarVector(v.Vector) ; v = v(normalizado) Local Temp# Local mag# mag = Magnitud(v) If mag>0 Then Temp# = Float(1/mag) v\X = v\X * Temp v\y = v\y * Temp v\Z = v\Z * Temp Else v\x = 0 v\y = 0 v\z = 0 End If End Function
hope that is what you need
(btw nice gui!, thank's)
Edit:
there are a sign error in x and y, please modify the function to:
Function PitchYawToVector(pitch#,yaw#,dest.Vector) dest\x = -Cos(pitch) * Sin(yaw) dest\y = -Sin(pitch) dest\z = Cos(pitch) * Cos(yaw) NormalizarVector(dest) End Function
Juan