Archived

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

Camera rotation

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Lets say I have a camera struct given by
  
typedef struct cam_type{
  vec3_t pos;
  vec3_t orig_pos;
} cam_t;

typedef struct vec3_type{
  float x, y, z;
} vec3_t;
  
The position of the cam is relative to the world''s origin. If I was to rotate this camera around the world''s y-axis, would its distance from the origin always be the same? Also, isn''t the length of this vector then its distance from the origin? I am doing the rotation by the following code and this doesn''t seem to be happening. Its position is (2.0,3.0,4.0).
  
cam_t *cam = Cam_Init(2.0,3.0,4.0); /* pos and orig_pos setup */
mat4x4_t *rot;
float a;
float rot_step = PI / 36.0;

for(a = 0.0; a <= (PI * 2); a += rot_step){
  rot = Mat4x4_YRotation(a);
  Vec3_Transform(&(cam->pos), rot); /* transforms the vec3_t by rot */
  printf("length = %f\n", Vec3_Length(&(cam->pos));
  Vec3_Copy(&(cam->orig_pos), &(cam->pos)); /* copy original position back */
}
  
Every 2PI it is back to its original position and length but in between it isn''t working. Thanks.

Share this post


Link to post
Share on other sites
world.OM; //worldspace rotation matrix
world.TM; //worldSpace Translation ma.
world.EM //eye matrix

camera.OM; //camera rotation Matrix
camera.TM; //camera translation matrix


world.EM.unit();
world.TM.unit();
world.OM.unit();

world.OM.setRot(x,y,z); //rotate
world.TM.setTans(x0,y0,z0); //than translate

world.EM.mul(OM); //rotate
world.EM.mul(TM); //than translate

//now the camera stuff
camera.OM.unit();
camrea.TM.unit();

camrea.OM.setRot(cxDir, cyDir, czDir);
camera.TM.setTrans(-cx, -cy, -cz);


//everything depends on the order of multiplication
world.EM.mul(camera.OM);
world.EM.mul(camera.TM);


transform(nvert, world.EM);


this should give u a feeling for what has to happen while calculation all the matr. stuff.

learn to use u''re finger and u''re position in a room as the orignin of the 3d-space. when doing a rotation just rotate about the depending axis represented by u''re finger and look to than direction, when translating, walk throug the room.

have phun:

-thanks to bush for destroying my childrens futur; stop that madness-

Share this post


Link to post
Share on other sites
unit() i assume normalizes the vector to unit length 1 (one).
However these are matricies...
Maybe it clears the matricies to all 1''s or an identity matrix? Just ideas, lol

||--------------------------||
Black Hole Productions
http://bhp.e-chrono.net/
Resident expert on stuff
max621@barrysworld.com
||--------------------------||

Share this post


Link to post
Share on other sites
stoip wasting oure time by asking stupendous questions, go on read tut. if u wanna really know. this all is basic stuff.
go on and read, there are hundrets of good tut. on 3d-math.
when not understanding something come back and ask...

bybylamer

Share this post


Link to post
Share on other sites
quote:
Original post by bloemschneif
stoip wasting oure time by asking stupendous questions, go on read tut.


the only one wasting your time is yourself.
he has every right to ask any question he likes, and
you have every right to ignore it.
nobody forced you to read this thread.. so stop wasting your
time and find something productive to do.

Share this post


Link to post
Share on other sites