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.

Dark GDK / How to interpret dbObjectAngleX ?

Author
Message
Richaldo
15
Years of Service
User Offline
Joined: 12th Nov 2009
Location: Hertfordshire, England
Posted: 17th Mar 2010 22:25
I'm having trouble interpreting the values returned by dbObjectAngleX and dbObjectAngleZ. They seem to return a number from -180 to +180 in curves - not evenly spaced out.

Therefore if I wanted to store the dbObjectAngleX in degrees (0 to 360), how would I do this and how could I convert it back again? I have a feeling I would need to use sin cos or tan, but I'm not sure!

After a bit of work I can convert dbObjectAngleY to degrees because I understand the values it returns, but for X and Z I'm a bit lost.

Any advice greatly received!
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 17th Mar 2010 23:38
The angles work the same way in all three directions. If you use dbWrapValue(dbObjectAngleX()), it will give you an angle around the X axis between 0-359, but you will probably receive the same result if you deduct the negative values from 360. If you want to set an object angle (for example with dbRotateObject), you don't need to convert it back.

What do you mean by "not evenly spaced"?
Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 18th Mar 2010 00:09
Sounds like you are using the free rotation commands to rotate your object (dbTurnObjectLeft etc..), these dont work in euler angles which is what you want.

You need to use dbRotateObject() to keep the angles euler(0 - 360), the problem may be if you need to use the free rotation commands, if you have to use these then you I think you may need to keep track of the angles yourself.

I have not tried this but declare your own angle variables x,y,z; then when you use dbTurnObjectLeft(id, 10) then you also do y = y - 10.
Like I said, this is just a theory.

Richaldo
15
Years of Service
User Offline
Joined: 12th Nov 2009
Location: Hertfordshire, England
Posted: 18th Mar 2010 00:39
Thanks for the responses, I'll try a few of these suggestions out and let you know how I get on. In the meantime I'll give you a bit of background on what I'm trying to achieve...

I'm storing the position and rotation of objects every frame so I can replay them back as an action replay feature. In order to support slow motion I need to be able to interpolate these keyframe values.
Doing this with a 3D position works perfectly by storing the dbObjectPosition values every frame.
Take these two positions:

frame[0].x = 100, frame[0].y = -200, frame[0].z = 150;
frame[1].x = 200, frame[1].y = -400, frame[1].z = 300;

If I wanted to run the replay at half speed I would increment the frame counter by 0.5 and work out the position of the object from the two keyframes by getting the mid value from each axis which would be easy to calculate as follows:

x = 150, y = -300, z = 225;

So by rendering this intermediate frame inbetween they key frames I would get a smooth slow motion replay.

This works great, but applying the same logic to rotation doesn't work. Take this real data I got from an object by storing dbObjectAngle values:

frame[0].x = -15.98, frame[0].y = 88.88, frame[0].z = -15.79;
frame[1].x = -177.23, frame[1].y = 86.55, frame[1].z = 179.78;

The intermediate rotation values for frame 0.5 are therefore calculated as

x = -96.61, y = 87.72, z = 66.20;

because those values are in the middle of the keyframes, but that rotation is not physically inbetween the two keyframes when rendered to screen and the object appears to rotate all over the place when the calculated frames are drawn.
The y value is fine, it's just the x and z that I can't figure out how to interpolate.

I think you are right though, its all about how I'm setting the angles. I don't think the simple divide by two logic can be applied to euler angles in the same way as simple position vectors

I'll let you know how I get on, but please keep the suggestions coming if you have any. Has anyone implemented a similar thing before?
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 18th Mar 2010 03:50
Quote: "I don't think the simple divide by two logic can be applied to euler angles in the same way as simple position vectors"


Indeed it cannot under a lot of circumstances, the easiest way is to look at how various animation systems handle this interpolation. The DirectX SDK comes with an example that uses quaternions to interpolate bones between frames, this is probably what you want because they easily allow you to spherically interpolate, of course GDK doesn't use them so it may be a bit annoying to implement.

Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 18th Mar 2010 15:41 Edited at: 18th Mar 2010 15:42
Have you looked at this command?

Quote: "dbCurveAngle
This command will return an auto-interpolated angle based on a given speed. This command will gradually move a number from its current value to a destination value at a certain speed. This command can be used to create the technique of a camera swinging into position from another location by curving the value of the camera angles.

Syntax
float dbCurveValue ( float fDestination, float fCurve, float fSpeed )"


Richaldo
15
Years of Service
User Offline
Joined: 12th Nov 2009
Location: Hertfordshire, England
Posted: 27th Mar 2010 22:14
The solution I went with was to convert the Euler angles stored by the object into degrees using EZRotate and store my keyframes in degrees.

I could then do the interpolation using fairly simple maths before converting the result back into Euler and applying to the object.

The only thing to remember was to make sure I interpolated the angles correctly, by always going the shortest route. For example, if keyframe A has an angle of 350 degrees and keyframe B has the same angle at 30 degrees the middle interpolation should be 10 degrees and not ( (350 - 30) / 2 ) = 160, which it would be for positions coords.

Login to post a reply

Server time is: 2024-11-20 03:47:39
Your offset time is: 2024-11-20 03:47:39