c++ - Camera/View matrix -
after reading through article (http://3dgep.com/?p=1700) seems imply got view matrix wrong. here's how compute view matrix;
mat4 camera::orientation() const { quaternion rotation; rotation = glm::angleaxis(mverticalangle, vec3(1.0f, 0.0f, 0.0f)); rotation = rotation * glm::angleaxis(mhorizontalangle, vec3(0.0f, 1.0f, 0.0f)); return glm::tomat4(rotation); } mat4 camera::getviewmatrix() const { return orientation() * glm::translate(mat4(1.0f), -mtranslation); }
supposedly, invert resulting matrix, have not far , has work excellently far, , i'm not doing inverting down pipeline either. there missing here?
you did inversion. view matrix inverse of model transformation positions camera. is:
modelcamera = translation(position) * rotation
so inverse is:
viewmatrix = (translation(position) * rotation)^-1 = rotation^-1 * translation(position)^-1
the translation inverted negating offset:
= rotation^-1 * translation(-position)
this leaves inverting rotation. can assume rotation inverted. thus, original rotation of camera model is
rotation^-1 = rotationx(verticalangle) * rotationy(horizontalangle) rotation = (rotationx(verticalangle) * rotationy(horizontalangle))^-1 = rotationy(horizontalangle)^-1 * rotationx(verticalangle)^-1 = rotationy(-horizontalangle) * rotationx(-verticalangle)
so angles specify inverted angles rotate camera. if increase horizontalangle
, camera should turn right (assuming right-handed coordinate system). that's matter of definitions.
Comments
Post a Comment