# 3D coordinates transformation

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

## 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 on other sites
Yes, perhaps you can post your formulas so we can see what you might be doing wrong.

##### Share on other sites
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 on other sites

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

tempy = Altitude;

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

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 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 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 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 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 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 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

1. 1
2. 2
Rutin
21
3. 3
4. 4
5. 5
A4L
14

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013602
×