eGamer 101 Report post Posted March 6, 2010 when i ran this code i get the camera flipping, any help please ? float DegToRad = 3.1415f / 180.0f; float x = 0; float y = 0; float z = 6; void render() { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLoadIdentity(); gluLookAt(x, y, z, 0, 0, 0, 0, 1, 0); static float Q = 0; x = 0; y = 6*sinf(Q*Math::Deg2Rad); z = 6*cosf(Q*Math::Deg2Rad); Q += 1.0f; glColor3ub(100,255,255); glutSolidCone(1,2,8,8); } [Edited by - eGamer on March 6, 2010 9:41:33 AM] 0 Share this post Link to post Share on other sites
jyk 2095 Report post Posted March 6, 2010 It looks like you've specified the negative y axis as the 'reference up' axis when building the view transform. This may be why the camera appears to be flipped relative to what you're expecting (although there's not really enough information given to say for sure). 0 Share this post Link to post Share on other sites
eGamer 101 Report post Posted March 6, 2010 ok i changed the up axis [see above].I want to rotate the camera as above but i am getting the flipping problem.what other info you want me to add ? 0 Share this post Link to post Share on other sites
jyk 2095 Report post Posted March 6, 2010 Ok, I see. The camera is orbiting the origin in the yz plane, which means that it will flip periodically regardless of what you use for the up vector.I'm not sure what behavior you're after exactly, but if you want the camera to orbit without flipping, try using either (0, -z, y) or (0, z, -y) for the up axis. 0 Share this post Link to post Share on other sites
eGamer 101 Report post Posted March 6, 2010 ok, i did your changes and the flipping has gone, now the camera orbits without flipping.can you explain how you concluded this change?i want to know the math behind it.Thanks. 0 Share this post Link to post Share on other sites
jyk 2095 Report post Posted March 6, 2010 Quote:Original post by eGamerok, i did your changes and the flipping has gone, now the camera orbits without flipping.can you explain how you concluded this change?i want to know the math behind it.Thanks.Short answer:In general, the vectors (-y, x) and (y, -x) are perpendicular to the vector (x, y). Similarly, the vectors (0, -z, y) and (0, z, y) are perpendicular to the vector (0, y, z). Note that these vectors are also the result of taking the cross product of the vector (0, y, z) and the positive or negative cardinal x axis.The 'up' axis argument to a look-at function provides a reference so that a unique orientation can (in most cases) be constructed. This is necessary because, given only a position and a target point, there is an infinite number of orientations that will 'look at' the target (that is, the camera object can 'roll' about its local forward axis while still meeting the requirement of 'looking at' the target).By using a reference up vector that is a 90-degree rotation of the 'look' vector in the orbiting plane, we ensure that the orientation of the camera object will remain consistent even as it orbits.That's not a very good explanation, I'm afraid, but despite the relative simplicity of the problem, a full explanation would actually be fairly lengthy. Anyway, feel free to ask if you have further questions. 0 Share this post Link to post Share on other sites
eGamer 101 Report post Posted March 6, 2010 ok, i have written the function and it gives "unique orientation", but still causesthe flipping problem.void Camera::Redefine(Vector_4Df& pos, Vector_4Df& TargetPoint){ // we want to build a right-handed // system view frame so z = x ^ y m_P = pos; Vector_3Df z = TargetPoint - pos; z.Normalize(); if( fabs(1-z.DotProduct(Vector_3Df::Y_AXIS)) <= FLT_Epsilon ) ) Vector_3Df y = Vector_3Df::Z_AXIS - z*(Vector_3Df::Z_AXIS*z); else Vector_3Df y = Vector_3Df::Y_AXIS - z*(Vector_3Df::Y_AXIS*z); y.Normalize(); Vector_3Df x = z ^ y; x.Normalize(); Matrix_44f Orientation( x[0], x[1], x[2],0, y[0], y[1], y[2],0, z[0], z[1], z[2],0, 0, 0, 0,1); m_Orientation.From(Orientation);}the previous function didn't show anything unless i multiply z by -1.though the previous calculations (without multiplying).if it is too much detail,i don't want to waste your time, can you pleaseadvice me with a book that explains this, i already read the book "Essential Mathematics for Games and Interactive Applications", but it seemednot enough. 0 Share this post Link to post Share on other sites