Jump to content
  • Advertisement
Sign in to follow this  
akademiksqc

basic problem for world space to object space

This topic is 2808 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

Hi there!

I have a simple 2D problem.

- In my game i have a visual grid of variable size.
- I have objects represented by points in the grid cells.
- The grid can be rotated clockwise or anti clockwise with variable rotation.

My goal is to determine the position(row,col) of a given point in the grid.
Here is how i achieve it when their is no rotation (using world space only):

row_number = ((myPoint.y - myGridMinX) / cellSize).ceiling
col_number = ((myPoint.x - myGridMinY) / cellSize).ceiling

Its easy but as soon as its rotated the above code is not working anymore.
I can't figure out how to convert my calculation in the grid's space.

Now, let say i have a grid of 4 x 3 rotated 45 degrees anti clockwise, how should i calculate my point position?
Thank you.

Share this post


Link to post
Share on other sites
Advertisement
You don't mention what API* you're using (if that's important), but you can use vector-matrix multiplication. I.e., google for "vector matrix multiplication." You'll need to construct a matrix representing the translation/rotation of your grid and multiply each of the coordinates by that matrix.

*Many APIs provide functions to do what you want. E.g., in DirectX, there's a D3DXVec3TransformCoord function that would serve.

Share this post


Link to post
Share on other sites
Hi, thx for the quick reply,

"You'll need to construct a matrix representing the translation/rotation of your grid"

This is exactly what i can't figure out, i understand the matrix multiplication with each of my coordinates concept, but how to construct them?
Could you give me an example if i have a 2x2 grid rotated a 45 degree and where the lower left corner is at (2,1) in world space?
I am using Irrlicht, but its not an API concern...

You don't mention what API* you're using (if that's important), but you can use vector-matrix multiplication. I.e., google for "vector matrix multiplication." You'll need to construct a matrix representing the translation/rotation of your grid and multiply each of the coordinates by that matrix.

*Many APIs provide functions to do what you want. E.g., in DirectX, there's a D3DXVec3TransformCoord function that would serve.

Share this post


Link to post
Share on other sites
Just to elaborate a bit, if you have a point in world space and want to use the equations you posted to compute the corresponding grid point, you'll first want to transform the world-space point by the inverse of the world transform for the grid.

As for how to build these various transforms, that's just basic 3-d math, so any good reference on that topic should be able to help you with that.

What math library are you using?

Share this post


Link to post
Share on other sites
Ok...
I am not using any right now.
Thx.

Just to elaborate a bit, if you have a point in world space and want to use the equations you posted to compute the corresponding grid point, you'll first want to transform the world-space point by the inverse of the world transform for the grid.

As for how to build these various transforms, that's just basic 3-d math, so any good reference on that topic should be able to help you with that.

What math library are you using?

Share this post


Link to post
Share on other sites

Hi, thx for the quick reply,

"You'll need to construct a matrix representing the translation/rotation of your grid"

This is exactly what i can't figure out, i understand the matrix multiplication with each of my coordinates concept, but how to construct them?
Could you give me an example if i have a 2x2 grid rotated a 45 degree and where the lower left corner is at (2,1) in world space?
I am using Irrlicht, but its not an API concern...


It's definitely an API concern. I'm not an Irrlicht person, but I'm quite certain it has the functions you need - matrix::setRotation, etc. Take a look at the API documentation and google a bit for irrlicht info, tutorials, etc.

You're eventually going to need a lot of vector and matrix manipulation and you should familiarize yourself with the capabilities of your API.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!