Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* [1] YOU HAVE THE FOLLOWING LINE ON YOUR AXISROTATION FUNCTION:
- axis = NormalizeVector( &axis );
- AND YOUR COMMENT ABOUT MAKING SURE NOT TO CHANGE THE ORIGINAL CONFUSED ME A
- LITTLE BIT. MY NORMALIZE VECTOR FUNCTION ACCEPTS A VECTOR BY VALUE AND IT
- CREATES AND RETURNS A NEW ONE (SEE BELOW). WHICH MEANS I HAD TO CHANGE THE
- ABOVE LINE TO THIS:
- axis = NormalizeVector(axis);
- NOW, YOU SAID TO MAKE SURE I WASN'T CHANGING THE ORIGINAL (WHICH IS RIGHTVECTOR
- OR SKYVECTOR, DEPENDING ON THE FUNCTION THAT CALLED AXISROTATION). THE ORIGINAL
- WILL BE PASSED BY VALUE TO AXISROTATION, THAN IT WILL BE PASSED AGAIN BY VALUE
- TO NORMALIZEVECTOR. I ASSUME I'M NOT DOING ANYTHING WRONG TO MESS UP THE
- ROTATIONS? */
- /*I just mentioned that in passing since I wasn't sure what your convention was for passing by value/by pointer/by c++-style reference. I usually pass vectors by value since there's not much overhead in duplicating three floats. No problem here, just my limited knowledge of your code.*/
- Vector3D NormalizeVector(Vector3D v) {
- GLfloat length = (GLfloat)sqrt((v.x * v.x) + (v.y * v.y) + (v.z * v.z));
- if(length == 0.0f) return NULLVECTOR;
- Vector3D result;
- result.x = v.x / length;
- result.y = v.y / length;
- result.z = v.z / length;
- return result;
- }
- /* [2] YOUR CODE INTRODUCED A LITTLE SIDE EFFECT. WHEN I CALL PITCH/YAW USING
- THE KEYBOARD, I CAN ROTATE ONE THOSE AXIS FREELY (COMPLETING 360º). WHEN
- USING THE MOUSE, I CAN ROTATE FREELY WITH YAW BUT NOT WITH PITCHING, IT
- SEEMS LIMITED AT [-90º, 90º]. I DON'T UNDERSTAND HOW IS THE MOUSE CAUSING
- THIS, THE FUNCTION CALLS ARE THE SAME
- EDIT: ACTUALLY THE ABOVE IS NOT 100% TRUE, IT SEEMS THERE IS SOME WEIRD
- BEHAVIOR WHEN THE ANGLE GOES ABOVE BELOW/ABOVE -90º/90º AND THEN I
- YAW LEFT OR RIGHT. IT'S LIKE, IF I GO BELOW -90º AND THEN YAW, IT
- SEEMS THE ORIENTATION CHANGES, IS THIS WHAT YOU MEAN BY THE FOLLOWING?
- "When you look straight up, you can still yaw gracefully, but the
- horizon won't stay level. It's one or the other."
- I WOULD ASSUME THE ONLY WAY TO PREVENT THIS STRANGE BEHAVIOR (THE
- MOUSE IS JUMPY WHEN IT REACHES SUCH HIGH ANGLES) IS TO LIMIT THE
- ANGLE TO BE CONFINED BETWEEN [-90º, 90º] AND DON'T LET IT ROTATE
- BELOW/ABOVE THOSE LIMITS?*/
- /* Yes. The real problem is that you need to consider what you're trying to do. When I implemented this, I just used spherical coordinates to store an azimuth and an elevation. Only thing is, looking straight up results in a singularity. i.e. UpVector will be in the horizontal plane, but which direction will it point? The only advice I can give is to consider carefully which behavior you want for your application, work out the vectors with arms, fingers, and the right hand rule, and implement it. I limited mine to [-90+epsilonº, 90-epsilonº].*/
- void Camera::Yaw(GLfloat angleX) {
- Reference = AxisRotation(Reference, SkyVector, angleX );
- RightVector = NormalizeVector(CrossProduct(Reference, SkyVector));
- UpVector = NormalizeVector(CrossProduct(RightVector, Reference));
- }
- void Camera::Pitch(GLfloat angleY) {
- Reference = AxisRotation(Reference, RightVector, angleY);
- UpVector = NormalizeVector(CrossProduct(RightVector, Reference));
- }
- /* [3] I TRIED TO ADAPT YOUR AXISROTATION FUNCTION FOR THE ROLL(), JUST SO I
- COULD KEEP THE CODE IMPLEMETANTIONS CONSISTENT, BUT I CAN'T MAKE IT WORK.
- LOOKING AT MY CURRENT ROLL FUNCTION, THIS WAS MY ATTEMPT WHICH DOESN'T
- SEEM TO WORK, WHATEVER I'M LOOKING AT JUST GOES OFF VIEW
- WHAT AM I MISSING? */
- /* The problem is that 'Yaw' is not a true yaw. It looks like roll rotates the camera so the horizon is not level, then yaw restores it to level. Strictly speaking, if you pitch up by 45 degrees, then yaw right by 90 degrees, the horizion will show up on camera at a 45 degree angle. Try it. If you want the horizion to stay level, then you can just rotate everything around the vertical axis like I suggested. To be precise though, it's not really a yaw then. It's more of a 'swivel.' */
- void Camera::Roll(GLfloat angle) {
- RightVector = AxisRotation(Reference, RightVector, angle);
- UpVector = NormalizeVector(CrossProduct(RightVector, Reference));
- }
- /* [4] YOU CAN SEE ABOVE THAT CROSSPRODUCT NO LONGER TAKES ADDRESSES TO THE
- VECTORS. THIS WAS THE ONLY VECTOR FUNCTION I HAD WHICH ACCEPTED VECTORS
- BY REFERENCE AND I CHANGED IT FOR CONSISTENCY. BELOW YOU CAN SEE HOW I
- HAD THE ORIGINAL (TOP) AGAINST THE NEW ONE (BOTTOM). ALL MY VECTOR FUNCTIONS
- ACCEPT VECTORS BY VALUE AND NOT BY REFERENCE, DO YOU THINK THERE'S ANYTHING
- WRONG DOING IT LIKE THIS, OR IT'S GOOD ENOUGH? */
- Again, I always pass vectors by value. There's not usually a good reason to modify the operands in a mathematical expression and this ensures that you can't.
- Vector3D CrossProduct(Vector3D *v, Vector3D *u) {
- Vector3D result;
- result.x = v->y * u->z - v->z * u->y;
- result.y = v->z * u->x - v->x * u->z;
- result.z = v->x * u->y - v->y * u->x;
- return result;
- }
- Vector3D CrossProduct(Vector3D v, Vector3D u) {
- Vector3D result;
- result.x = v.y * u.z - v.z * u.y;
- result.y = v.z * u.x - v.x * u.z;
- result.z = v.x * u.y - v.y * u.x;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement