Skip to main content
gamedev.net
🔒 Locked

Camera

Started by SKSlayer 3 replies 450+ views
Original Post
SKSlayer
SKSlayer
I made a camera class like this
        
enum CameraState { CAM_LOOKAT, CAM_DIRECTION } ;

class CCamera
{
public:
	CCamera();
	~CCamera();
        SetCamera();
private:
	void CheckValues();
	int GetAngles();
       
	long double m_Position[3];
	double m_YLookat;
	double m_XLookat;
        long double m_Lookat[3];
	CameraState m_State;

};
        
so if m_State is CAM_DIRECTION, it will use angular values from the m_XLookat and m_Ylookat to set where to look at (like if you make a doom-like, you just rotate around the y axis with the left and right keys) ... that was easy to code But, if m_State = CAM_LOOKAT (That specifies a viewing target), the program must fill in m_YLookat and m_XLookAt so the center point of the screen is the target point .. But what are the math, I have a sight idea but dunno exactly. (Ah, yes, my camera must not spin around the Z axit) All help will be appreciated :o) (I don't want gluLookAt(...), so...) Edited by - SKSlayer on 8/25/00 8:34:01 AM
(you can find me on IRC : #opengl on undernet)
JimmyP
JimmyP
I''m not sure if I got your question right but here it goes:
you can represent the orientation of the camera at any given time with a unit vector(and of course the position with 3 floats).If you know the vector of the current orientation and can calculate the vector of the desired orientation(shouldn''t be too hard) then you can rotate the camera so that current and desired vectors overlap.This can be done using either rotation matrices or quaternion mathematics.For mor info look for a document called:"The Matrix and Quaternion FAQ" it''s great for math problems.Hope that helps you in some way...

-=Jimmy=-
-=Jimmy=-
SKSlayer
SKSlayer
Well, I am only 16 and I didn''t learn matrix yet at school ... So, what I know Is that I can get it this way

    
a=GetCamToTargetDistance();
b=GetCamToTargetDistanceOnXZPlane();
c=GetCamToTargetDistanceOnZAXIS();

LookOnYAxis=asin(c/b)
LookOnXAxis=acos(b/a);

But I am totally not sure about it ...
(you can find me on IRC : #opengl on undernet)
JimmyP
JimmyP
You don''t need to know much about matrices at this point.If you get the FAQ you''ll see exactly how to make the needed rot. matrices from Euler Angles.Euler angles ar the angles you''ll ave to rotate the initial camera vector around the x,y and z axis to overlap with the desired location.Try to read the FAQ and if you still have any questions post''em.I found the URL for you:
http://members.tripod.de/mspoerl/m_sitemap.html
There''s also an other FAQ on vectors.If you don''t know much about dot products etc, yuo might want to take a look.

-=Jimmy=-
-=Jimmy=-
SKSlayer
SKSlayer
Yeah, but I am not talking about matrix, I just need some math,
So I can have the camera following the target point..
(you can find me on IRC : #opengl on undernet)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.