Reputation: 57
Do I need to look for a formula to get the midpoint? Or there is already a function in openGL that allows me to do so.
I thought up a code that some I think that is close:
if(num1 % 2 == 0)
{
}
What I mean is for the line to get the midpoint (openGL)
glVertex3f(-3,0.0,0.0);
glVertex3f(3,0.0,0.0);
Upvotes: 0
Views: 899
Reputation: 162309
Or there is already a function in openGL that allows me to do so.
OpenGL is not a math library! It just draws things, and that's how it should be.
Upvotes: 0
Reputation: 22366
If you want the midpoint of a line segment (as your edit implies), it's simple linear algebra:
// Where p1 and p2 are your line end points.
midpoint = p1 + ( ( p2 - p1 ) * 0.5 )
// Or...
midpoint = ( p1 + p2 ) * 0.5;
Upvotes: 1