# OpenGL Specific matrix question

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

## 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 on other sites
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 extrudevector 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 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 on other sites
not sure what your asking here but you can nest matrix ops, perhaps what you need

pushmatrix // for base object
postion
rotation

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

popmatrix

popmatrix

##### Share on other sites
Quote:
 Original post by middySorry 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 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 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 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 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 on other sites
Quote:
 Original post by middySo something like this?//copy matrixglPushMatrix();glMultMatrix(matrix);//render bulletglPopMatrix();

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?

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

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

• Total Topics
632984
• Total Posts
3009712
• ### Who's Online (See full list)

There are no registered users currently online

×