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 / dbXRotate, dbYRotate, dbZRotate problem

Author
Message
tparkin
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location:
Posted: 5th Jul 2007 18:28
These rotate functions first, do not rotate the object in an incremental way, instead they set the object's angle on the specified axis. I believe this is a misnomer and should be corrected to "dbSetXRotation".

Second, these functions seem to set the object's rotation in world coordinates. For example, rotating my object 45 degrees while facing down the positive Z axis, he rotates to the right, both his right and the world's right. Then when he is facing down the negative Z axis (the opposite direction), rotating him 45 degrees rotates him right in world space, but to his left.

I'm sure you can see how confusing this is when trying to do local transformations.

So then, my question is, how can I perform actual local rotations instead of being relative to the world axes?

Thanks.
Jna99
18
Years of Service
User Offline
Joined: 3rd Nov 2005
Location: Portugal
Posted: 5th Jul 2007 19:48
Hi tparkin try to use dbTurnObjectLeft/Right or PitchObjectUp/Down. You can also rotate an object incrementally just need to do something like ex: dbYRotateObject(dbObjectAngleY(obj)+.75f);

tparkin
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location:
Posted: 5th Jul 2007 19:52
Thanks Jna99, I understand how to rotate an object I'm just pointing out the confusing naming of the dbXRotate functions. If they are named rotate, they should..rotate..the object. If they set the angle of the object, they should be named accordingly.

I understand they wanted to make this easy to use for beginners but a heading of -90 to 90 instead of a 0-360 angle is unheard of in 3D math or the gaming industry.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 9th Jul 2007 21:08
(And a Pain to implement a compass!!)

Know way too many languages - Master of none
tparkin
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location:
Posted: 9th Jul 2007 21:12
Hey Jason,

I've written some code that can be used to do 0-360 rotations along the X, Y, Z axes. If you're interested PM me or reply here and I'd be happy to share it.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 9th Jul 2007 23:04
@Tparkin! That would be SWELL.

Personally I can get by with the turn left or right etc. But Turning to a heading and or being able to "ASK" what an Object's current heading is - That would be very useful.

I am experimenting with things that fly (maybe not physics based - but fly nonetheless) and a Compass in relation to a map "radar" or whatever would be really neat

thank you In advance: jasonpsage (at) jegas.com

Know way too many languages - Master of none
tparkin
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location:
Posted: 9th Jul 2007 23:16
Hi Jason,

One thing I should mention - my code does the rotations in local space, relative to the object. This was necessary for what I am doing and the dbXRotateObject() function only set the object's angle around the world axes.

I've attached my Object class. It's usage is pretty basic. For example:

Object ship( "ship.x" );

// Turn the ship right 45 degrees
ship.rotateY( 45 );
// "Roll" the ship 10 degrees to the right
ship.rotateZ( 10 );

// Move the ship forward in the direction it is facing
ship.move( 1 );

ship.getAngleZ( ); // Gets the ship's current Z angle (local space)

All angles are stored/returned as 0-360 values.

Also, this class uses ObjectFactory to manage the IDs of objects, which are needed for many DarkGDK functions. If you need the ID of an object, you can do ship.getID( );

If you want to get the degrees needed to turn to reach a certain angle this can be accomplished using the dot product and the dbACOS() function. If you are unfamiliar with this you can search Google for "angle between two vectors" or similar. Here's something I found that explains it better than most other sites: http://chortle.ccsu.edu/VectorLessons/vch09/vch09_1.html

Let me know what you think.

Attachments

Login to view attachments
Daggeth
17
Years of Service
User Offline
Joined: 3rd May 2007
Location:
Posted: 9th Jul 2007 23:27
I struggled with the object rotation too... try to make a an object that rotates with direction, according to speed and hugs the terrain (and shoot yourself in the face in the process).

Anyway, ascii art time.


When an object is made, its facing 0 degrees. To rotate it 35 degrees to the right, you set its Y rotation to 35. Now, this 'unit circle' is not your standard unit circle because its between -180 - 180 instead of 0 - 360. Typically, if you would want to face an object "up" or "north", you'd set its rotation to 90.. but in this case, you set its rotation to 0! These changes also make standard trigonometry a little difficult. Use the dbATANFULL function for your trig instead of the standard C++ atan. Heres a C++ function that converts db notation into standard notation

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 9th Jul 2007 23:31
The Vector Lessons - I'll have to go back and check them out again when I can concentrate - my first glace had my head hurting by page 3!

I never took the advanced math classes - and I wish I did. Good Coder - Good at implementing algorithms - terrible at making them up - and if/when I do - I know a good math person could tighten them up to more than half the size by applying algebra.

I have my strengths and weaknesses - I'm awesome with pointer math, classes, double linked lists, assembly language if need be ... but whoa!

As for your CODE - Thank You. I will peruse it now - as I have my own "OBJECT" code for DarkGDK - to generate object id's and manipulate "things". What I may do is integrate the two - namely the "maths" you have written if its all the same to you!

Thanks! Much Appreciated!
Jason P Sage

Know way too many languages - Master of none
tparkin
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location:
Posted: 9th Jul 2007 23:34
@Daggeth

Thanks for that, it may be useful when trying to get standard notation for world space rotations.

@Jason

I know what you mean about the math! Feel free to use the code in any way that it can help you.
unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 10th Jul 2007 15:37
Hey looky there, at' dem' one of em' math functions. Gives you 'a + b + c stuff...

Very nice algorithm Daggeth, maybe it's worthy of a sticky post?

Login to post a reply

Server time is: 2024-10-09 00:21:23
Your offset time is: 2024-10-09 00:21:23