Rotation around a point on a virtual sphere...
Blitz3D Forums/Blitz3D Programming/Rotation around a point on a virtual sphere...
| ||
Hey, I need help with this, I can’t get it to work correctly, if I disable 2 axes, then its working but I am really looking to have the 3 axes… My goal is to rotate around a point on a virtual sphere; the cone should point at the cube or at least move symmetric with it. Here the code: Graphics3D 800,600, 16,2 Cam = CreateCamera() : PositionEntity Cam,0,0,-20 : ;RotateEntity Cam,50,0,0 Light = CreateLight() : PositionEntity Light,20,30,-20 CenterMesh = CreateCone() CenterPitchAdd# = 1 ; Can be changed CenterYawAdd# = 1 ; Can be changed CenterRollAdd# = 1 ; Can be changed AwayMesh = CreateCube() PxR# = 0 ; Can be changed PyR# = 5 ; Can be changed PzR# = 0 ; Can be changed Repeat TurnEntity CenterMesh,CenterPitchAdd#, CenterYawAdd#, CenterRollAdd# ;pitch# = EntityPitch#(CenterMesh) ;Yaw# = EntityYaw#(CenterMesh) ;roll# = EntityRoll#(CenterMesh) pitch# = pitch# + CenterPitchAdd# Yaw# = Yaw# + CenterYawAdd# roll# = roll# + CenterRollAdd# ;------------ CODE -------------- Px# = PxR# Py# = PyR#*Cos(pitch#) - PzR#*Sin(pitch#) Pz# = PyR#*Sin(pitch#) + PzR#*Cos(pitch#) Px# = Px#*Cos(roll#) - Py#*Sin(roll#) Py# = Px#*Sin(roll#) + Py#*Cos(roll#) Pz# = Pz# Px# = Px#*Cos(Yaw#) - Pz#*Sin(Yaw#) Py# = Py# Pz# = Px#*Sin(Yaw#) + Pz#*Cos(Yaw#) ;------------ CODE -------------- PositionEntity AwayMesh, Px#, Py#, Pz# ; <----- TEST RenderWorld Text 0,10, Px# Text 0,20, Py# Text 0,30, Pz# Text 0,40, "---------" Text 0,50, pitch# Text 0,60, Yaw# Text 0,70, roll# Flip Until KeyHit(1) |
| ||
Why not use PointEntity? Unless there is a reason against it, try this (note the RotateMesh command):Graphics3D 800,600, 16,2 Cam = CreateCamera() : PositionEntity Cam,0,0,-20 : ;RotateEntity Cam,50,0,0 Light = CreateLight() : PositionEntity Light,20,30,-20 CenterMesh = CreateCone() CenterPitchAdd# = 1 ; Can be changed CenterYawAdd# = 1 ; Can be changed CenterRollAdd# = 1 ; Can be changed RotateMesh CenterMesh,90,0,0 ; make the cone point forward, since that is the direction that PointEntity points from. AwayMesh = CreateCube() PxR# = 0 ; Can be changed PyR# = 5 ; Can be changed PzR# = 0 ; Can be changed Repeat ; TurnEntity CenterMesh,CenterPitchAdd#, CenterYawAdd#, CenterRollAdd# ;pitch# = EntityPitch#(CenterMesh) ;Yaw# = EntityYaw#(CenterMesh) ;roll# = EntityRoll#(CenterMesh) pitch# = pitch# + CenterPitchAdd# Yaw# = Yaw# + CenterYawAdd# roll# = roll# + CenterRollAdd# ;------------ CODE -------------- Px# = PxR# Py# = PyR#*Cos(pitch#) - PzR#*Sin(pitch#) Pz# = PyR#*Sin(pitch#) + PzR#*Cos(pitch#) Px# = Px#*Cos(roll#) - Py#*Sin(roll#) Py# = Px#*Sin(roll#) + Py#*Cos(roll#) Pz# = Pz# Px# = Px#*Cos(Yaw#) - Pz#*Sin(Yaw#) Py# = Py# Pz# = Px#*Sin(Yaw#) + Pz#*Cos(Yaw#) ;------------ CODE -------------- PositionEntity AwayMesh, Px#, Py#, Pz# ; <----- TEST PointEntity CenterMesh,AwayMesh ; simply point at the cube RenderWorld Text 0,10, Px# Text 0,20, Py# Text 0,30, Pz# Text 0,40, "---------" Text 0,50, pitch# Text 0,60, Yaw# Text 0,70, roll# Flip Until KeyHit(1) End |
| ||
^^ naa, the cone is here as a test to be sure the cube is moving correctly... Also, I want to avoid doing stuff like: Awaymesh pos 0,0,0 Awaymesh rot pitch,yaw,roll Awaymesh move 4 .... I need to have it as a code. |
| ||
I also tried something like that: x = x0 + r.(cos(theta) * sin(phi) * 1); y = y0 + r.(sin(theta) * 1 * cos(psi)); z = z0 + r.(1 * cos(phi) * sin(psi)); .... with no success sources: http://www.gamedev.net/community/forums/topic.asp?topic_id=413692 Any help is more than welcome ! ^^ |
| ||
Is this what you want or am I wrong? Graphics3D 800,600, 16,2 Cam = CreateCamera() : PositionEntity Cam,0,0,-20 Light = CreateLight() : PositionEntity Light,20,30,-20 CenterMesh = CreateCone() CenterPitchAdd# = 1 ; Can be changed CenterYawAdd# = 1 ; Can be changed CenterRollAdd# = 1 ; Can be changed AwayMesh = CreateCube(CenterMesh) PxR# = 0 ; Can be changed PyR# = 5 ; Can be changed PzR# = 0 ; Can be changed MoveEntity AwayMesh, PxR, PyR, PzR Repeat Px# = EntityX(AwayMesh, True) Py# = EntityY(AwayMesh, True) Pz# = EntityZ(AwayMesh, True) pitch% = EntityPitch(CenterMesh) yaw% = EntityYaw(CenterMesh) roll% = EntityRoll(CenterMesh) TurnEntity CenterMesh, CenterPitchAdd#, CenterYawAdd#, CenterRollAdd# RenderWorld Text 0, 0, "Px=" + Px Text 0, 10, "Py=" + Py Text 0, 20, "Pz=" + Pz Text 0, 40, "pitch=" + pitch Text 0, 50, "yaw =" + Yaw Text 0, 60, "roll =" + roll Flip Until KeyHit(1) |