Sign in to follow this  

render object on vertices

This topic is 4712 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, I have two vertices whose distance to each other changes over time. Now I want to connect these two vertices. The easiest way would be to use GL_LINES. But first the the line would be everytime as long as the distance between these two vertices (and so it would change - what I don't want) and second it looks bad so I would like to render an object (e.g. primitive pencil or ruler object consisting of some polygons and textures) which has then everytime the same length, independent of the distances of the vertices. So the two vertices would only show the direction. How is that possible? Thanks for any help... record [Edited by - record on January 18, 2005 1:12:32 PM]

Share this post


Link to post
Share on other sites
You have to get the direction, thats easy : (if you know your vectoriel maths)


// Create the direction
VECTOR Direction = Vertex2 - Vertex1;
// Normalize it to get a vector of size of 1
Direction.Normalize();
// Get the center point
VECTOR Center = (Vertex2 + Vertex1) / 2;
// Set the size of your line
glLineWidth(5); // In pixel
// Now draw your line
glBegin(GL_LINES);
glVertex3f( /* Center + Direction * (LineHeight / 2) */ );
glVertex3f( /* Center - Direction * (LineHeight / 2) */ );
glEnd();


Share this post


Link to post
Share on other sites
Hi,

but now I have a connection between these two vertices with just a line.
That's exactly what I didn't want.

The two vertices should act like a grid. They only should show the direction of the object I want to render on top of these two vertices.


record

[Edited by - record on January 19, 2005 5:15:57 PM]

Share this post


Link to post
Share on other sites
The important part of his code is this line:

Direction.Normalize();

This ensures that the "line" is of unit length no matter how far apart your verts are. This solves the first problem you had:

Quote:

But first the the line would be everytime as long as the
distance between these two vertices (and so it would change - what I
don't want)


The second part you asked for, drawing an object aligned to this direction vector, is a little bit more work. Probably you'll want to create a rotation matrix to line up your object with the direction vector and draw the object with that transform applied.

Share this post


Link to post
Share on other sites
Hi,

To normalize this vector was actually not my problem. Maybe my question was a little bit unprecise. The different length issue should only just be a sort of introduction to my main problem which you understand correct.


I would render my object at the location of the first vertex (with an orientation of e.g. 0/1/0). And then rotate my object with the same angle I need to rotate my line (from the two vertices) from (0/1/0) to the current direction.

But how would I get such a rotation matrix?



Record

Share this post


Link to post
Share on other sites
OK,

So instead of changing the line I keep the line static and turn the viewpoint with gluLookat such that I can render s.th else just a pure line.
Right?

But how does the transformation matrix looks like?
For example I want to render the line along the x-axes (from (0,0,0) to (10,0,0). Before I just did that.
Now the line is everytime e.g. on the y-axes and I have to transform my viewpoint such that the line on the y-axes look like a line on the x-axes.
How do I do that?


Thanks,

Record.

Share this post


Link to post
Share on other sites

This topic is 4712 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this