#### Archived

This topic is now archived and is closed to further replies.

# Camera rotation

This topic is 5860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m having problems with my camera rotation, when I try to rotate it just jumps to a centered position to the scene. Am I doing this completely wrong? Probably obvious but here are what the functions do: P3D_t is my vector structure(3 points) mat_ident resets a matrix of type float matrix_t[4][4] mat_rotate rotates using matrices mat_mult multiplies two matrices together mat_vecmult multiplies a matrix by a vector c_matrix is my camera matrix I know the rotation function works, because I can rotate objects themselves just fine. I''m thinking I''m not creating this function correctly.

void mc_rotate(camera_t *cam, float ax, float ay, float az) {
matrix_t temp;
P3D_t tvec = vec_sub(&cam->view, &cam->position);

mat_ident(temp);
mat_rotate(temp, ax, ay, az);
mat_mult(cam->c_matrix, temp);

cam->view = mat_vecmult(temp, &tvec);
}


##### Share on other sites

hmm.

interesting

I''m thinking that mat_mult or mat_rotate may have problems, they should be taking in references or pointers to the matricies you want to rotate (they may be taking straight objects) - in which case things will fall apart fast.

anyway... onto a more personal, biased view :-)

It''s always difficult when you use C functions and structures to maintain consistency (imo) and making sure everything is right... (while this is only my personaly opinion) I believe that matrices and vectors should always be represented by classes... I''m concerned at how you have to set the temp matrix to identity, the problems that could cause if you forgot... yikes.. (a constructor should do this)

I can just imagine that code being replaced by:

cam.rotate(...);
cam.view=cam.position*cam;

(I think thats what you are trying to do)

but as I say, just personal preference and what I''m used to (I''m always screwing with my matrix/vector objects )...

##### Share on other sites
I said screw it to my own functions for now and switched over to use glRotate and glTranslate. Probably more efficient anyway and lets me get on with learning. I''ll venture back to my math lib when I better understand.

Thanks for the response though. I don''t know C++ well enough right now, I''m more familiar and comfortable with C.

##### Share on other sites
good good.

but don''t underestimate the huge power of doing your own 3d maths. The things you can pull off can''t be toutched by glRotate, etc.

##### Share on other sites
aehm... i might misunderstand something but i think there is only a little mistake:

what exactly does mat_ident? does it just set all values to 0?
(because mat_mult(cam->c_matrix, temp) would cause that cam->c_matrix would be 0,too).

but perhaps i just misunderstood your problem.

##### Share on other sites
mat_ident sets temp to an identity matrix, then mat_rotate does the rotation stuff. I think my problem is that I was using glLoadMatrix instead of glMultMatrix.

But I will venture back to my mathlib to clean it up a bit later on. I wrote the thing in ''99 and just got around to compiling it for VS 6. :D

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
18
5. 5

• 9
• 9
• 33
• 13
• 13
• ### Forum Statistics

• Total Topics
632584
• Total Posts
3007218

×