How do I get a moving objects x,y,z positions, if....
Hi, I need to know if I rotate and translate a 3d Object in the ususal way, like so;
Push Matrix
// Translate the object to it's individual init position values (declared beforehand) in Scene
glTranslatef (objectPosInitX , objectPosInitY, objectPosInitZ );
//rotate automatically the object on it's Y axis
glRotatef ( rotateObject , 0.0f, 1.0f , 0.0f);
// translate the object in a circular path as it spins on its Y axis
glTranslatef (objectXMove, objectYMove, objectZmove);
// Objects model space coords go here......
PopMatrix
Then, below Swapbuffers(), I do these calculations:
rotateObject += 0.05f; This rotates object on it's own Y axis just fine
objectZMove = -10.0f; This translates it in a circular path just fine
But, How do i get this this object's x, z positions so that I can plug them into my collision checking against
the camera's x and z positions, which, I allready have tracked just fine.
Camera collision against unmovinbg objects works well. It's the check against moving objects that
I want to set up as well. But I need to know how to get the moving objects x and z positions. ...the Y position later....
Thank you in advance
If your object is spherical (for collision), you only need the center point and radius, not actual orientation.
If your object is not spherical, then you need to run each vertex of the object through a rotation matrix for the rotation you're using -- google for "rotation matrix sin cos" and you'll find it.
If your object is not spherical, then you need to run each vertex of the object through a rotation matrix for the rotation you're using -- google for "rotation matrix sin cos" and you'll find it.
enum Bool { True, False, FileNotFound };
Thank you for your reply.
But, I'm not doing any sphere or line in polygon collision checking or anything fance like that. My scene is very simple, so, I just do a distance check. It works well against unmoving objects because their init pos x,y, z don't ever change.
But, a moving object..........
thanks again
BOpenGL
Like I stated, I only need to track the moving objects x, y and z positions so I can make the comparison against the camera.
Okay, and I am testing if a center point against another center point is less than a certain circumferance, like the following:
Push Matrix
// Translate the object to it's individual init position values (declared beforehand) in Scene
glTranslatef (objectPosInitX , objectPosInitY, objectPosInitZ );
//rotate automatically the object on it's Y axis
glRotatef ( rotateObject , 0.0f, 1.0f , 0.0f);
// translate the object in a circular path as it spins on its Y axis
glTranslatef (currentObjectX, currentObjectY, currentObjectZ);
// Objects model space coords go here
PopMatrix
Ok so far, then, After Swapbuffers(), I do the following:
GLfloat previousPosX = currentObjectX; // for object's collision response
GLfloat previousPosZ = currentObjectZ;
// Other 3D Object Rotation and Translation Values
rotateObject += 0.5f ; //rotates object on it's y axis just fine
currentObjectX = objectPosInitX + 0.0f;
currentObjectY = 0.0f; // not used yet
currentObjectZ = objectPosInitZ + (-5.0f); // translates object in circular path
Then, after the user keyboard section, I check for collision like so( which works fine with the cam against stationary objects):
// Collision with object checked by calling a standard Distance function
if (Distance( xpos, zpos, currentobjectX , currentObjectZ ) < 2.0f )
{
xpos = previousXpos ; // collision response for cam so it doesnt move
zpos = previousZpos ;
currentObjectX = previousObjectPosX ; // collision response for cube so it doesnt move
currentObjectZ = previousObjectPosZ ;
}
But, still no dice...........................
Any ideas would be appreciated in advance
BOpenGL
[Edited by - BeginOpenGL on October 18, 2004 7:41:26 PM]
But, I'm not doing any sphere or line in polygon collision checking or anything fance like that. My scene is very simple, so, I just do a distance check. It works well against unmoving objects because their init pos x,y, z don't ever change.
But, a moving object..........
thanks again
BOpenGL
Like I stated, I only need to track the moving objects x, y and z positions so I can make the comparison against the camera.
Okay, and I am testing if a center point against another center point is less than a certain circumferance, like the following:
Push Matrix
// Translate the object to it's individual init position values (declared beforehand) in Scene
glTranslatef (objectPosInitX , objectPosInitY, objectPosInitZ );
//rotate automatically the object on it's Y axis
glRotatef ( rotateObject , 0.0f, 1.0f , 0.0f);
// translate the object in a circular path as it spins on its Y axis
glTranslatef (currentObjectX, currentObjectY, currentObjectZ);
// Objects model space coords go here
PopMatrix
Ok so far, then, After Swapbuffers(), I do the following:
GLfloat previousPosX = currentObjectX; // for object's collision response
GLfloat previousPosZ = currentObjectZ;
// Other 3D Object Rotation and Translation Values
rotateObject += 0.5f ; //rotates object on it's y axis just fine
currentObjectX = objectPosInitX + 0.0f;
currentObjectY = 0.0f; // not used yet
currentObjectZ = objectPosInitZ + (-5.0f); // translates object in circular path
Then, after the user keyboard section, I check for collision like so( which works fine with the cam against stationary objects):
// Collision with object checked by calling a standard Distance function
if (Distance( xpos, zpos, currentobjectX , currentObjectZ ) < 2.0f )
{
xpos = previousXpos ; // collision response for cam so it doesnt move
zpos = previousZpos ;
currentObjectX = previousObjectPosX ; // collision response for cube so it doesnt move
currentObjectZ = previousObjectPosZ ;
}
But, still no dice...........................
Any ideas would be appreciated in advance
BOpenGL
[Edited by - BeginOpenGL on October 18, 2004 7:41:26 PM]
// translate the object in a circular path as it spins on its Y axis
glTranslatef (currentObjectX, currentObjectY, currentObjectZ);
It seems that what values I put in for the variables currentObjectX , and Z, do'nt track the position of the object as it translates around the scene in a circular manner. The matrix, or whatever, just remembers the initial currentObjectX and Z and collision check and response only works for that spot even though the object may be somewhere else in its circular path. Like stated, collision detetection and response works fine for stationary objects, though.
Strange....
Anybody got any ideas on creating the necessary/correct variables to hold the real current translated coords of the object wherever it may be in it's circular treck?
Again, thank you.
BOpenGL
glTranslatef (currentObjectX, currentObjectY, currentObjectZ);
It seems that what values I put in for the variables currentObjectX , and Z, do'nt track the position of the object as it translates around the scene in a circular manner. The matrix, or whatever, just remembers the initial currentObjectX and Z and collision check and response only works for that spot even though the object may be somewhere else in its circular path. Like stated, collision detetection and response works fine for stationary objects, though.
Strange....
Anybody got any ideas on creating the necessary/correct variables to hold the real current translated coords of the object wherever it may be in it's circular treck?
Again, thank you.
BOpenGL
Hope this helps.
For moving objects I use to recalculate some vectors every time they move.
I have two vectors, position and 'foward'. The second is updated so it's easy to move the object around and keep track of its world space coordinate.
The collision however is a different kind. I use some sort of ray-triangle collision. But that's not the point I guess.
For example, the foward vector for the 'player' comes from input. For other entities I could compute this from internal variables.
Another way could be to ask the GL for the current world matrix and do the transform in CPU but separating the world matrix from the camera matrix is not an easy task in GL, and it could kill performance. I never used this method too much.
It's not a problem however to do some manual xformations. It's not really needed to have the GL do everything for you, usually you can know what xforms are getting in.
For moving objects I use to recalculate some vectors every time they move.
I have two vectors, position and 'foward'. The second is updated so it's easy to move the object around and keep track of its world space coordinate.
The collision however is a different kind. I use some sort of ray-triangle collision. But that's not the point I guess.
For example, the foward vector for the 'player' comes from input. For other entities I could compute this from internal variables.
Another way could be to ask the GL for the current world matrix and do the transform in CPU but separating the world matrix from the camera matrix is not an easy task in GL, and it could kill performance. I never used this method too much.
It's not a problem however to do some manual xformations. It's not really needed to have the GL do everything for you, usually you can know what xforms are getting in.
Previously "Krohm"
BeginOpenGL,
you really need to do all translation and rotation work BEFORE you send the object to OpenGL for rendering.
Keep in mind your program loop:
1. Gather User Input
- Change any applicable states based on Input
2. Process Living Objects
- Process AI if applicable
- Update values based on current states (physics calcs)
- Calculate new position
- Check For and Process any Collisions
3. Display Objects
If you keep things up this way, you never have to worry about extracting real position from a viewing transformation rotation or translation.
Hope this makes sense...
You are doing all of the right steps to move your object around, but you are using the OpenGL matrix stacks to do your work for you. What you really need to do is store a local translation and rotation matrix for each object at the object level. The benefit of this is that you already have the real position of the object and the rotation of your object and dont have to figure them out later. It will also simplify your OpenGL drawing routine:
PushMatrix();
GLMultMatrix(ObjectTransRotMatrix);
<---Draw Model Space stuff here--->
PopMatrix();
Anyways, thats the way I go about it.
you really need to do all translation and rotation work BEFORE you send the object to OpenGL for rendering.
Keep in mind your program loop:
1. Gather User Input
- Change any applicable states based on Input
2. Process Living Objects
- Process AI if applicable
- Update values based on current states (physics calcs)
- Calculate new position
- Check For and Process any Collisions
3. Display Objects
If you keep things up this way, you never have to worry about extracting real position from a viewing transformation rotation or translation.
Hope this makes sense...
You are doing all of the right steps to move your object around, but you are using the OpenGL matrix stacks to do your work for you. What you really need to do is store a local translation and rotation matrix for each object at the object level. The benefit of this is that you already have the real position of the object and the rotation of your object and dont have to figure them out later. It will also simplify your OpenGL drawing routine:
PushMatrix();
GLMultMatrix(ObjectTransRotMatrix);
<---Draw Model Space stuff here--->
PopMatrix();
Anyways, thats the way I go about it.
Hard work USUALLY pays off in the future, but laziness ALWAYS pays off right now.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement