Nick Nougat
09-27-2003, 08:25 AM
I'm having some problems concerning the exact way of realising cameras:
I'll list the facts I know and hope, that someone can tell me where I made a mistake:
In my 'engine', the location of each entity is described by a position vector and a quaternion for its rotation. Entity position is interpreted as relative to a fixed coordinate system.
My facts:
1) It is agreed that it should be possible to render the world from the point of view of any entity (i.e. making the entity the camera) simply by applying the translation and rotation of this entity differently (see below).
2) To render an entity at its position one first rotates, then translates the entity.
3) The view transformation (i.e. the camera transform) is the last transformation applied to the modelview matrix.
4) The camera transformation is different from normal translations: we rotate first, then translate by the negative position.
5) In the code, since I use the model of a fixed coordinate system, the order of the translations is reversed:
1. camera rotation
2. camera translation with negative position
3. push matrix
4. Entity_1 translation
5. Entity_1 rotation
6. pop matrix
7. ...and so on up to Entity_n
Problem:
--------
When I render, it seems as though the z-axis were inverted, moving forward moves backward, objects behind me are in front etc.
I calculated some simple examples of translations by hand and my method seems correct.
Do I have to invert the z-coordinates? If so, why? Or could my implementation of quaternions be wrong? (shouldn't be though).
Thanks in advance for your replies
Nick
I'll list the facts I know and hope, that someone can tell me where I made a mistake:
In my 'engine', the location of each entity is described by a position vector and a quaternion for its rotation. Entity position is interpreted as relative to a fixed coordinate system.
My facts:
1) It is agreed that it should be possible to render the world from the point of view of any entity (i.e. making the entity the camera) simply by applying the translation and rotation of this entity differently (see below).
2) To render an entity at its position one first rotates, then translates the entity.
3) The view transformation (i.e. the camera transform) is the last transformation applied to the modelview matrix.
4) The camera transformation is different from normal translations: we rotate first, then translate by the negative position.
5) In the code, since I use the model of a fixed coordinate system, the order of the translations is reversed:
1. camera rotation
2. camera translation with negative position
3. push matrix
4. Entity_1 translation
5. Entity_1 rotation
6. pop matrix
7. ...and so on up to Entity_n
Problem:
--------
When I render, it seems as though the z-axis were inverted, moving forward moves backward, objects behind me are in front etc.
I calculated some simple examples of translations by hand and my method seems correct.
Do I have to invert the z-coordinates? If so, why? Or could my implementation of quaternions be wrong? (shouldn't be though).
Thanks in advance for your replies
Nick