camera model/representation

Started by
3 comments, last by JimmyP 22 years, 11 months ago
Does anyone know of any good camera model tutorials.I just want a good way of implemnting a generic camera model,nothing fancy(yet),just something basic I can build on later.Any suggestions?Thanx in advance. Edited by - JimmyP on April 27, 2001 10:57:10 AM
-=Jimmy=-
Advertisement
Maybe I didn''t explain myself very well above...
What I want to find out about are ways of representing the camera,so that simple roations around the local x,y,z axes and translations along them are possible.That should be generic enough to implement various types of cameras later...
-=Jimmy=-
This is my base camera class that I am using in my 3D engine Rastagon 3. If you just need a basic representation this should help you. I''m pretty sure I don''t use all the member variables, anymore but I never removed the old ones.
This is just the base class. I built a 3rd Person Follow Cam on top of this, and am now working on a GameCamera that allows scripted camera events.

The way the basicamera is built makes it more suitable for a FPS.
Hope this is what you wanted.

class basicamera{    public:        basicamera(int sw = 640, int sh = 480, float = 0.0,                   float = 0.0, float = 0.0, float = 0.0,                   float = ANG_90, float = 0.0);        ~basicamera();	virtual void Update() { SetViewMatrix(); }        void RotYaw(float amount);        void RotRoll(float amount);        void RotPitch(float amount);	float GetPitch() { return view.x; }	float GetYaw()   { return view.y; }	float GetRoll()  { return view.z; }	float GetX() { return pos.x; }	float GetY() { return pos.y; }	float GetZ() { return pos.z; }        void SetX(float n) { pos.x = n; }	void SetY(float n) { pos.y = n; }	void SetZ(float n) { pos.z = n; }        virtual void Move(float amount);        void SetView(D3DXVECTOR3 nview) { view = nview; }        void SetPos(D3DXVECTOR3 npos) { pos = npos; }	void ZoomIn(float amount);	void ZoomOut(float amount);    protected:	void SetViewMatrix();        D3DXVECTOR3 pos;  // pEye,        D3DXVECTOR3 at;   // pAt, calculated by SetViewMatrix        D3DXVECTOR3 view; // pAt, cam rotation	D3DXVECTOR3 Up;   // not needed here, only used once        D3DXMATRIX projmat;        D3DXMATRIX viewmat;        float zoomfactor;}; 
Thanx for posting.I''m now using the same(almost) representation.Instead of using the three right,up and viewing vectors I just use a 3x3 matrix representing camera rotation and a 3 vector for camera position/translation.Does this look ok?
Btw how do you compose the camera matrix out of the right,up and viewing vectors and position vector?
Also if I use a rotation matrix for the y-axis like this one:
/cos(A) 0 -sin(A) 0\
|0 1 0 0|
|sin(A) 0 cos(A) 0|
\0 0 0 1/

and multiply it using glMultMatrixf(),shouldn''t it have the same effect as glRotatef(A,.0,1.0,.0)?Asuming that A has been converted to radians in cos(A) and sin(A) since cos and sin uses radians and glRotatef uses degrees and that I''m using column major format.Using the same matrices for x and z rotation I get identical results with glRotatef(or so it seems) but in the y axis the results are reversed,i.e. to get the same result I''d have to use glRotatef(-A,.0,1.0,.0).
-=Jimmy=-
I''m a big on whatever works, works. So if it works for you, go for it.

I have no real knowledge of OpenGL, interface is pretty standard, but the actual implementation for my camera was based on Direct X 8 d3dxmatrix commands. "pos" is the location of the camera. "view" is the camera rotation. the sw and sh in the constructor are for finding the screens aspect ratio. All the other parameters to the constructor are for initializeing "pos" & "view"

I had started writing a very general camera tutorial, but work, school, and Rastagon 3 Programming cut that short. When R3 is finished, I may create a detail tutorial on creating a similar system, or atleast release that portion of the design. I have yet to decide.



Domini
Rastagon 2 Engine

This topic is closed to new replies.

Advertisement