# render object on vertices

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

## 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 on other sites
You have to get the direction, thats easy : (if you know your vectoriel maths)

// Create the directionVECTOR Direction = Vertex2 - Vertex1;// Normalize it to get a vector of size of 1Direction.Normalize();// Get the center pointVECTOR Center = (Vertex2 + Vertex1) / 2;// Set the size of your lineglLineWidth(5); // In pixel// Now draw your lineglBegin(GL_LINES);    glVertex3f( /* Center + Direction * (LineHeight / 2) */ );    glVertex3f( /* Center - Direction * (LineHeight / 2) */ );glEnd();

##### 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 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 thedistance between these two vertices (and so it would change - what Idon'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 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 on other sites
perhaps glulookat(..)

##### 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.

1. 1
2. 2
Rutin
25
3. 3
4. 4
5. 5

• 10
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632942
• Total Posts
3009342
• ### Who's Online (See full list)

There are no registered users currently online

×