Jump to content
  • Advertisement
Sign in to follow this  
fs1

3D coordinates transformation

This topic is 1347 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Dear All

I have captured the camera's coordinates in a game SDK which is measured in meters relative to north/south/altitude.

I need to transform them nto coordinates relative to the sprite, regardless of its pitch, bank and heading.

I have tried the several 3D transfoms and rotations without success (I can't get the camera's fixed position if the sprite changes its pitch/bank for example)

http://planning.cs.uiuc.edu/node102.html

I even tried to transform sequentially, first the heading, then the bank and last the pitch.

How can I approach this problem?

I can post my formulas if helps.

Thanks!

Share this post


Link to post
Share on other sites
Advertisement
You want the camera's world position transformed into the sprite's local space, right?

My wild guess is that you might just not be inverting your sprite's world matrix.

So:

Matrix = Build a matrix representing the sprite's orientation (and position!!)
Matrix = Invert the matrix.
Multiply your camera's position vector by the matrix.


If you're already doing all of that, then it's probably just a typo somewhere. Edited by Nypyren

Share this post


Link to post
Share on other sites

Thanks for your reply.

 

I have the following variables:

 

distanceN, distanceE, Altitude which are the camera distances in meters to the North, East and Vertical.

 

Then, the planes' Pitch, Bank and Heading are the values of these variables in radians.

 

Then I do it sequentially to see how each transfrom behaves.

 

EDIT: corrected signed in Formulas

 

For Heading transform:

 

tempx = distanceE * cos (Heading) - distanceN * sin(Heading);
tempz = distanceN * cos (Heading) + distanceE * sin(Heading);
tempy = Altitude;

 

tempx, tempy, tempz are the transformed coordinates for the transversal, vertical and longitudal axis respectively

 

Heading seems to work perfect.

 

then for Bank transform:

 

temp1x = tempy * sin(Bank) + tempx * cos(Bank);
temp1y = tempy * cos (Bank) - tempx * sin(Bank);
temp1z = tempz;

 

again temp1x, temp1y, temp1z are the transformed coordinates for the transversal, vertical and longitudal axis respectively

 

and finally for Pitch transform

 

z = -temp1y * sin(Pitch) + temp1z* cos(Pitch);
y = temp1y *  cos(Pitch) + temp1z * sin(Pitch);
x = temp1x;

 

where x, y, z are the final transformed coordinates for the transversal, vertical and longitudal axis respectively.

 

Something is off with the Pitch and Bank piece.

 

Any hints?

 

Thanks !

Edited by fs1

Share this post


Link to post
Share on other sites

The problem I am having is that when you combine Pitch and Bank rotations the above breakdown doesn't seem to work.

 

Any ideas?

 

Thanks

Share this post


Link to post
Share on other sites

It appears that the order of your transformations may be the problem. Applying roll, pitch and yaw is commonly done in just that order, not yaw-roll-pitch as you have it.

Share this post


Link to post
Share on other sites

It appears that the order of your transformations may be the problem. Applying roll, pitch and yaw is commonly done in just that order, not yaw-roll-pitch as you have it.

Thanks Buckeye. Just a question, most probably I may have to apply the inverse of the roll, pitch and yaw - as I want to go back to the relative position to the sprite. Is my reading correct? If so, what order should I do?

Share this post


Link to post
Share on other sites


Is my reading correct? If so, what order should I do?

 

I was still working on my first pot of coffee when I posted previously so I'd have to take a closer look. Since it's been almost an hour, I'm guessing you've already tried it. How did it work out?

Share this post


Link to post
Share on other sites

I was still working on my first pot of coffee when I posted previously so I'd have to take a closer look. Since it's been almost an hour, I'm guessing you've already tried it. How did it work out?

 

I doesn't work on this side. I am checking the signs in the above formula I posted. I will revert back as soon as I assure they have the right signs.

Edited by fs1

Share this post


Link to post
Share on other sites

It appears that the order of your transformations may be the problem. Applying roll, pitch and yaw is commonly done in just that order, not yaw-roll-pitch as you have it.

 

Buckeye, your suggestion helped to figure out the order. The game does roll, pitch and draw as you mentioned. So to go back to the original coordinates, I applied the inverse of that - draw, pitch and woll. It works ! Thanks all for the help!

Edited by fs1

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!