I have 2 objects in different coordinate systems: planet and cylinder. I have eye coordinates of both objects. I want to orient cylinder along vector that connects it and the planet.
glLoadMatrixf( PlanetTransform);
// .. draw planet
glLoadMatrixf( CylinderTransform);
glColor3f(0, 1, 0);
DrawCylinder();
// draw vector that connects cylinder and planet
glColor3f(1, 0, 0);
glLoadIdentity();
glBegin(GL_LINES);
// planet eye pos e.g. (0.045; -0.049; -0.186)
glVertex3f(point1.x, point1.y, point1.z);
// cylinder eye pos e.g. (-0.109; -0.064; -0.203)
glVertex3f(point2.x, point2.y, point2.z);
glEnd();
// orient cylinder along red vector
// TVector normal(0, 0, 1);
glLoadIdentity();
gluLookAt(point2.x, point2.y, point2.z,
point1.x, point1.y, point1.z,
normal.x, normal.y, normal.z);
DrawCylinder();
Draw cylinder code:
void DrawCylinder()
{
glPushMatrix();
glRotatef(90, 1, 0, 0);
gluCylinder(gp_quadratic, 0.01, 0, 0.03, 15, 15);
glPopMatrix();
}
I tried also to specify normal as:
TVector normal;
TVector::cross(point2 - point1, TVector(0, 0, 1), normal);
So at the end I expect to see 2 cylinders - 1 green, 1 - red. Red should be oriented along red segment. But I do not see red one. Could you please help me to find what is wrong here? Red cylinder does not appear in center of green cylinder coordinate system..
the gluCylinder(/**/)
I've quite a nightshift behind me, so my vision may be flawed, but it's cheap to try that, isn't it.
If I'm in error, try using glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) for the planet, and just look where the cylinder is.