Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Rotate object around some point in space

Author
Message
Beavis
23
Years of Service
User Offline
Joined: 15th May 2003
Location: Czech Republic
Posted: 14th Aug 2003 14:34
Hello,
I need rotate some object around Y axis but rotation centre must be in some variable.

For example I have box somewhere in position 10,0,0
a need turn this box at 90 angle around point 0,0,0
Can someone help me with this?
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 14th Aug 2003 20:38 Edited at: 14th Aug 2003 20:39
Ok, something like this should work when you're rotating around the y-axis:

`Work out distance away from rotation point on x and z axis
xdistance# = object position x(objectnumber) - rotate.pos.x
zdistance# = object position z(objectnumber) - rotate.pos.z
`Work out distance from rotation point
TotalDistance# = sqrt(xdistance#^2+zdistance^2)
`Work out angle of object from rotation point
angle# = atanfull(xdistance#,zdistance#)
`Work out angle of new position from rotation point
newangle# = wrapvalue(angle# + AmountToRotateBy#)
`Work out new x and z positions for object
newxpos# = rotate.pos.x + sin(newangle#)*TotalDistance#
newzpos# = rotate.pos.z + cos(newangle#)*TotalDistance#
`Position the object
Position object objectnumber,newxpos#,object position y(objectnumber),newzpos#
`Rotate the object
yrotate object objectnumber,wrapvalue(object angle y(objectnumber)+AmountToRotateBy#)


None of that's tested, I just wrote it out here, but it should work.
Hope it helps.

Insiiiiiiiiiiiiiiiiiiiiiiiide!
Beavis
23
Years of Service
User Offline
Joined: 15th May 2003
Location: Czech Republic
Posted: 15th Aug 2003 10:15
Thank you for help. It works fine.

Login to post a reply

Server time is: 2026-07-23 02:29:32
Your offset time is: 2026-07-23 02:29:32