OpenGl GluLookAt. Cannot orient object -
i have 2 objects in different coordinate systems: planet , cylinder. have eye coordinates of both objects. want orient cylinder along vector connects , planet.

glloadmatrixf( planettransform); // .. draw planet glloadmatrixf( cylindertransform); glcolor3f(0, 1, 0); drawcylinder(); // draw vector connects cylinder , 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 specify normal as:
tvector normal; tvector::cross(point2 - point1, tvector(0, 0, 1), normal); so @ end expect see 2 cylinders - 1 green, 1 - red. red should oriented along red segment. not see red one. please me find wrong here? red cylinder not appear in center of green cylinder coordinate system..
the glucylinder(/**/)
- is built along local z-axis, pointing outwards along red line
- the local y-axis global z_axis (pointing viewer), projected onto viewing plane of planet
- thus local x-axis poiting along viewing plane of planet
- thus after glrotatef(90, 1, 0, 0); cylinder points away user depth of picture , hidden behind planet
- thus if instead glrotatef(180, 1, 0 ,0 ); used, should fine afais.
i've quite nightshift behind me, vision may flawed, it's cheap try that, isn't it.
if i'm in error, try using glpolygonmode(gl_front_and_back, gl_line) planet, , cylinder is.
Comments
Post a Comment