Skip to main content
GameDev.net gamedev.net
🔒 Locked

Odd camera behavior

Started by Sovereign Mar 3, 2000 at 5:55 AM 1 replies 400+ views
Original Post
Sovereign
Sovereign
Heres my problem. I rotate the camera up and down, left and right using large angles many times, but when I return my camera back to my original angles the test entity is tilted or distorted. The problem is I did not tilt the camera. I also notice that when I when I move the test entity to the center of my screen the rotation angles appear to be off. That is the rotation angles don''t return to my original values. Is there a way to do some kind of maintenace on the matrix to correct this proplem. Anybody have a solution to this problem. Here are some sample code of the camera setup: void PlayerCamera(PR_REAL xm, PR_REAL ym, PR_REAL zm, PR_REAL pitch_angle , PR_REAL yaw_angle, PR_REAL roll_angle, PR_REAL frx, PR_REAL fry, PR_DWORD move_count) { PR_REAL txm, tym, tzm; PR_REAL tcx, tcy, tcz; PR_REAL tfrx, tfry; PR_REAL vx1, vx2, vx3; PR_REAL vy1, vy2, vy3; PR_REAL vz1, vz2, vz3; txm = xm * move_count; tym = ym * move_count; tzm = zm * move_count; tcx = pitch_angle * move_count; tcy = yaw_angle * move_count; tcz = roll_angle * move_count; tfrx = frx * move_count; tfry = fry * move_count; PR_RotateEntity(camera_pointer, tcx, tcy, tcz); tvector[0] = txm;tvector[1] = 0;tvector[2] = 0; PR_Transform(camera_pointer->orientation.rot_mat); vx1 = tvector[0];vx2 = tvector[1];vx3 = tvector[2]; tvector[0] = 0;tvector[1] = tym;tvector[2] = 0; PR_Transform(camera_pointer->orientation.rot_mat); vy1 = tvector[0];vy2 = tvector[1];vy3 = tvector[2]; tvector[0] = 0;tvector[1] = 0;tvector[2] = tzm; PR_Transform(camera_pointer->orientation.rot_mat); vz1 = tvector[0];vz2 = tvector[1];vz3 = tvector[2]; // Used for the free camera mode PR_MoveEntity(camera_pointer, vx1 + vy1 + vz1, vx2 + vy2 + vz2, vx3 + vy3 + vz3); tvector[0]=0;tvector[1]=0;tvector[2] = (PR_REAL) 10.0; PR_RotateSegment(camera_pointer, 0, tfrx, tfry, 0); PR_Transform(camera_pointer->segment_orientation->rot_mat); PR_Transform(camera_pointer->orientation.rot_mat); tvector[0] += camera_pointer->orientation.location.x; tvector[1] += camera_pointer->orientation.location.y; tvector[2] += camera_pointer->orientation.location.z; PR_PositionCameraTarget (camera, tvector[0], tvector[1], tvector[2]); // Set Camera Up Y vector only works when CAMFLAG_AIM_TARGET mode is enabled tvector[0] = 0; tvector[1] = 1; tvector[2] = 0; PR_Transform(camera_pointer->segment_orientation->rot_mat); PR_Transform(camera_pointer->orientation.rot_mat); camera->up.x=tvector[0]; camera->up.y=tvector[1]; camera->up.z=tvector[2]; PR_PositionCameraSource(camera, camera_pointer->orientation.location.x, camera_pointer->orientation.location.y,camera_pointer->orientation.location.z); //PR_CameraDirection (camera); PR_SetActiveCamera(camera); //TODO: Need to setup routine for third player person //PR_TransformEntity (player); /* Transform the entity */ //PR_RenderEntity (player); /* Render the entity */ } Doug
Sovereign
Sovereign
Hi again

OK the real reason for the original post is that I have
developed some code to compute the Pitch bearing and Yaw bearing based on knowing the object location. The problem is I need accuracy in a matrix opperation for this to work properly. I am using a 0 to 360 for both bearings. This
in theory allow me to steer my camera so I can line up with
the object based on it''s two bearings(angles).

Here''s a clip from an article on quaternions by Nick Bobick from gamasutra via link from flipcode that explains my problem well:

"Rotations involve only three degrees of freedom (DOF), around the x, y, and z coordinate axes. However, nine DOF (assuming 3x3 matrices) are required to constrain the rotation - clearly more than we need. Additionally, matrices are prone to "drifting," a situation that arises when one of the six constraints is violated and the matrix introduces rotations around an arbitrary axis. Combatting this problem requires keeping a matrix orthonormalized - making sure that it obeys constraints. However, doing so is not computationally cheap. A common way of solving matrix drift relies on the Gram-Schmidt algorithm for conversion of an arbitrary basis into an orthogonal basis. Using the Gram-Schmidt algorithm or calculating a correction matrix to solve matrix drifting can take a lot of CPU cycles, and it has to be done very often, even when using floating point math. "

Although I not througly knowledable on the use of quaternions in 3 axis rotations, but the full article indicated they can solve a lot of proplems involving my particular problem.

Where can I find information on this Gram-Schmidt algorithm
that maybe will solve my current problem.

Doug



Oofnish
Oofnish
Gram-Schmidt process takes a any set of vectors that form a "basis" for a vector space. (meaning: any other vector in that space can be made up by a linear combination of the vectors in the basis) The output of the process is completely different set of vectors that are Orthonormal to each other and to the original set. Orthonormal meaning "unit vector perpindicular to".

The process is a fairly mindless algorithm (not easy, but just plugging things into the formula.) The formula is as follows :

For a set of vectors v1,v2,and v3; get another set of vectors u1,u2,u3 which are orthonormal to the given basis.

step 1)
set u1 = v1//v1/ (/v1/ == the magnitude of v1.)
You should recognize this equation as the unit vector in the direction of v1.

step 2)
set u2 = v2''//v2''/
where v2'' = v2 - dot(v2,u1) * u1

step 3)
set u3 = v3''//v3''/
where v3'' = v3 - (dot(v3,u1) * u1) - (dot(v3,u2) * u2)

u1,u2, and u3 will be orthogonal unit vectors to the basis v1,v2, and v3.

I think, however, the article mentioned that this algorithm is NOT cheap, and there might be better ways of actually accomplishing this task. However, the above method will indeed orhthonormalize any matrix ( since a matrix can be thought of as a combination of vectors )

Anyway. just my input. hope it helped. More info on the gram-schmidt process can be found in any elementary linear algebra or matrix algebra textbook.

good luck!



*oof*
oof

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.