Jump to content
  • Advertisement
Sign in to follow this  
middy

OpenGL Specific matrix question

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

Well I am going to be very specific. I am probably having trouble due to me not understanding OpenGl correctly. But here I go. I have a model. Its position and rotation in world coordinate system are represented by 4 vectors vector Position vector Dof vector up vector side I can use this to create a rotationTranslation matrix and this works great. What I want to is to make a new object go from a point on the model and forward into space into a direction. The point is in model coordinates. vector extrude vector object direction So how do I do this.

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure I understand this:
Quote:
What I want to is to make a new object go from a point on the model and forward into space into a direction. The point is in model coordinates.

vector extrude
vector object direction

Do you want to extrude an object? What's the vector "object direction"? Is the vector extrude the direction and scale you want to use for the extrusion?

To begin with, you can apply your matrix to the point to get it in world coordinates.
Um.. Well, before I continue I'd like confirmation that extrusion of an object is what you want [wink]

Share this post


Link to post
Share on other sites
Sorry wrong word for it ... I want to the smaller object to fly "out" from a point on first model.

The vector extrude, is the point where the smaller object starts

Share this post


Link to post
Share on other sites
not sure what your asking here but you can nest matrix ops, perhaps what you need

pushmatrix // for base object
loadidentity
postion
rotation

pushmatrix // for object 2 (smaller one i guess)
loadidentity
position(extrude + movement)
rotation

popmatrix

popmatrix

Share this post


Link to post
Share on other sites
Quote:
Original post by middy
Sorry wrong word for it ... I want to the smaller object to fly "out" from a point on first model.

The vector extrude, is the point where the smaller object starts

So the smaller object should start at point A, and fly in direction B over time ? Well, that would be:

P(t) = A + B * t

where P is the new position at time t. Then you just multiply P(t) by the same matrix you use to transform your model with, and you'll get it in world space.

Is it this what you meant ?

Share this post


Link to post
Share on other sites
Well the movement part I have sorted out. My problem is rendering the damn thing.

The smaller object is a bullet stream, coming from a gun. When I rotate the gun the bullets (even though they have left the gun) rotates with it.

So I figured I constructed the bullet rotationTranslation matrix wrong. Or had misunderstood something

I included a picture

Share this post


Link to post
Share on other sites
Ok, if you do something like this:
* When a shot is fired, make a copy of the "rotationTranslation matrix" of the ship. Each bullet should have it's own copy.
* To render a bullet you should start with a clean modelview matrix (i.e. the ships transformation should not be on there.) Apply the bullet's rotationTranslation matrix to it.
* Calculate the bullet's position as Yann showed. Then draw the bullet at that position. The bullet should now be transformed to the correct position in space.

An alternative would be to transform starting position and direction to world space directly when a bullet is fired.

Share this post


Link to post
Share on other sites
So something like this?


//copy matrix

glPushMatrix();
glMultMatrix(matrix);
//render bullet

glPopMatrix();


How would I translate starting position and direction on ship to world coordinates?

Share this post


Link to post
Share on other sites
Why don't you just give the bullet object 2 vector properties:position and velocity.When you fire a bullet,you initially set its position using the extrude or whatever,and set also the initial velocity from the direction of the gun.After that,you just calculate the orbit of the bullet using any physics equations you desire,and draw the bullet by just translating using the "bullet.position" vector.

Share this post


Link to post
Share on other sites
Quote:
Original post by middy
So something like this?


//copy matrix

glPushMatrix();
glMultMatrix(matrix);
//render bullet

glPopMatrix();

Yes, something like that, but with lots of code between "copy matrix" and glPushMatrix()... :)

Quote:
How would I translate starting position and direction on ship to world coordinates?

Using the matrix you've copied..!

Say, why don't you post the code you have now and we'll try to tell you how to change it so it works?

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!