Hey guys,
I'm having trouble understanding rotation after using FixObjectToObject().
In the following example, Earth rotates around the Sun.
I also attached the complete project with the media files as .zip.
There's no copyright issue with the .png files!
#option_explicit
type ObjectType
gfx as integer
ID as integer
x as float
y as float
z as float
endtype
global sun as ObjectType
global earth as ObjectType
SetWindowSize ( 0, 0, 1 )
SetSyncRate ( 144, 1 )
SetDisplayAspect ( GetMaxDeviceWidth() * 1.0 / GetMaxDeviceHeight() )
SetRawMouseVisible ( 0 )
SetCameraPosition ( 1, 0, 0, -100 )
SetCameraRange ( 1, 1, 1000 )
SetCameraLookAt ( 1, 0, 0, 0, 0 )
SetRawMouseVisible ( 0 )
// sun
sun.gfx = LoadImage ( "sun.png" )
sun.ID = CreateObjectSphere ( 5.0 , 64, 64 )
sun.x = 0.0
sun.y = 0.0
sun.z = 0.0
SetObjectPosition ( sun.ID, sun.x, sun.y, sun.z )
SetObjectImage ( sun.ID, sun.gfx, 0 )
SetObjectColorEmissive ( sun.ID, 155, 155, 0 )
// earth
earth.y = 20.0
earth.gfx = LoadImage ( "earth_day.png" )
earth.ID = CreateObjectSphere ( 10.0, 64, 64 )
SetObjectImage ( earth.ID, earth.gfx, 0 )
SetObjectPosition ( earth.ID, earth.x, earth.y, earth.z )
// create pivot
FixObjectToObject ( earth.ID, sun.ID )
repeat
RotateObjectlocalZ ( sun.ID, 0.5 )
SetObjectRotationQuat ( earth.ID, 0, 0, 0, 0 )
RotateObjectlocalY ( earth.ID, 5.0 )
Sync()
until GetRawKeyPressed ( 27 )
END
I used
SetObjectRotationQuat ( earth.ID, 0, 0, 0, 0 )
to rotate Earth back to its default angle.
That worked, but after using the Quat command I'm unable to rotate Earth using
RotateObjectlocalY ( earth.ID, 5.0 )
If I comment the Quat command,
RotateObjectlocalY ( earth.ID, 5.0 )
works, but Earth angles are useless due to the Sun - Earth pivot.
Can anybody explain why the Euler rotation doesn't work anymore after setting the Quat rotation?
I can fix the problem by calculating the Earth orbit with sin and cos, but I want to understand what's going on.
Thanks!
PSY