I want to show draw a cylinder that starts at point a and that points to I think the key is in the first glRotated, but this is my first time working with openGL a and b are btVector3
glPushMatrix();
glTranslatef(a.x(), a.y(), a.z());
glRotated(0, b.x(), b.y(), b.z());
glutSolidCylinder(.01, .10 ,20,20);
glPopMatrix();
Any suggestions ??
According to glutsolidcylinder(3) - Linux man page:
Hence, you have to prepare the transformations respectively:
The usage of
glRotatef()seems to be mis-understood, also:This would result in:
I wrote this code out of mind (using the doc. of
btVector3which I've never used before). Thus, please, take this with a grain of salt. (Debugging might be necessary.)So, please, keep the following in mind:
The doc. does not mention whether
btVector3::angle()returns angle in degree or radians – I assumed radians.When writing such code, I often accidentally flip things (e.g. rotation into opposite direction). Such things, I usually fix in debugging, and this is probably necessary for the above sample code.
If (b - a) is already along positive or negative z-axis, then (b - a) × (0, 0, 1) will yield a 0-vector. Unfortunately, the doc. of
btVector3::normalize()does not mention what happens when applied to a 0-vector. If an exception is thrown in this case, extra checks have to be added, of course.