OpenGL Transforming coordinate frames

M

matt.casella

Hi,

I've having a *small* problem with a small simulation/game I'm trying
to write in C++ using OpenGL. I'm not sure if I need to include code
yet, as it might just make things more complicated, but I can do so if
necessary.

Basically what I'm writing involves a simple sprite fielder trying to
catch a thrown ball. The ball and the fielder are each in their
respective coordinate frames, and I'm using the matrix stack to keep
track of these. I'm also using a camera with gluLookAt(). The user
picks some initial settings like power and release angle, and the balls
trajectory and landing position is calculated. I can plot this landing
spot correctly as long as I stay within the ball's coordinate frame.

What I would like to do is have my fielder go to the position that the
ball will land to catch it. However, I can't seem to get this to work
right. I have the coordinates that the ball is going to land, and I
need to somehow transform them into coordinates that the fielder "can
understand". I would like the fielder to be able to calculate a path
to the ball using several different algorithms. So basically I just
want to make sense of the ball's landings coordinates. I try saving
the model_view matrix of the ball and then loading it back, but somehow
when I plot the point it's not int he right location. It seems to me
to be just simple matrix multiplication, but I'm having a problem
somewhere. Does the camera need to be considered in these
calculations? I've also had a couple of futile efforts at using
gluUnproject + project, but to no avail. Can anyone give me any info,
or refer me some where where I can see some examples? Any help or
advice is welcomed. Thanks.

-Matt
 
S

Salt_Peter

Hi,

I've having a *small* problem with a small simulation/game I'm trying
to write in C++ using OpenGL. I'm not sure if I need to include code
yet, as it might just make things more complicated, but I can do so if
necessary.

Basically what I'm writing involves a simple sprite fielder trying to
catch a thrown ball. The ball and the fielder are each in their
respective coordinate frames, and I'm using the matrix stack to keep
track of these. I'm also using a camera with gluLookAt(). The user
picks some initial settings like power and release angle, and the balls
trajectory and landing position is calculated. I can plot this landing
spot correctly as long as I stay within the ball's coordinate frame.

What I would like to do is have my fielder go to the position that the
ball will land to catch it. However, I can't seem to get this to work
right. I have the coordinates that the ball is going to land, and I
need to somehow transform them into coordinates that the fielder "can
understand". I would like the fielder to be able to calculate a path
to the ball using several different algorithms. So basically I just
want to make sense of the ball's landings coordinates. I try saving
the model_view matrix of the ball and then loading it back, but somehow
when I plot the point it's not int he right location. It seems to me
to be just simple matrix multiplication, but I'm having a problem
somewhere. Does the camera need to be considered in these
calculations? I've also had a couple of futile efforts at using
gluUnproject + project, but to no avail. Can anyone give me any info,
or refer me some where where I can see some examples? Any help or
advice is welcomed. Thanks.

-Matt

You should ask in a relevent news group.
Are you sure you are reversing the projection coordinates? as in z = -z
axis?
 
G

Gianni Mariani

Hi,

I've having a *small* problem with a small simulation/game I'm trying
to write in C++ using OpenGL.

It's really hard to help much here except to tell you how I would do it.

To go from one co-ordinate space to another you need to peform the
reverse which usually means multiplication by the inverse matrix. I you
have an unit orthonormal 3x3 matrix, this is just the matrix transpose.
If you have a homogenous 4x4 matrix then I would do a real matrix
invert (which can be quite efficiently done in for a 4x4).

It's mean many many years since I did much opengl so I don't know what
the latest API advances look like but if I were on the opengl committee
I would have added some apis like a 4x4 invert for example.

G
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top