   Camera setting in OpenGl
  Can any one help me with seting the camera in opengl?(most importat local rotation)How do I build a good Camera class?Doc, Ex, Class? pls. 
  There is an excellent series of tutorials on camera classes over at www.gametutorials.com, located in the OpenGL section of the Tutorials menu. Here's the source code for my camera class, which I designed using the GameTutorials examples...Camera.h:   // CCamera definition...    class CCamera{// Construction...public:CCamera();virtual ~CCamera();// Member functions...public:void SetPosition(float, float, float);void SetBounds(float, float, float);void SetView(float, float, float);void RotateCamera(float, vec3_t);void SetUp(float, float, float);void MoveCamera(float, vec3_t);void PanCamera(float, float);void TranslateCamera(float);void GetStrafeVector(void);void LoadCameraView(void);void StrafeCamera(float);void GetPosition(vec3_t);void GetStrafe(vec3_t);void GetBounds(vec3_t);void GetView(vec3_t);void GetUp(vec3_t);// Member variables...protected:vec3_t m_Position;vec3_t m_Strafe;vec3_t m_Bounds;vec3_t m_View;vec3_t m_Up;};Camera.cpp:   // CCamera implementation...    #include "stdafx.h"#include "shared.h"    #ifdef _DEBUG#undef THIS_FILEstatic char THIS_FILE[]=__FILE__;#define new DEBUG_NEW#endif    // -----------------------------------------------------------------------// CCamera constructor/destructor...// -----------------------------------------------------------------------    CCamera::CCamera(){vec3_t bounds = { MAX_BOUNDS, MAX_BOUNDS, MAX_BOUNDS };vec3_t up = { 0.0f, 1.0f, 0.0f };// Initialize the camera...memset(m_Position, 0, sizeof(vec3_t));memset(m_View, 0, sizeof(vec3_t));VectorCopy(bounds, m_Bounds);VectorCopy(up, m_Up);// Get an initial strafe vector...GetStrafeVector();}    CCamera::~CCamera() { }    // -----------------------------------------------------------------------// CCamera member functions...// -----------------------------------------------------------------------    void CCamera::GetPosition(vec3_t fPosition) { VectorCopy(m_Position, fPosition); }void CCamera::GetBounds(vec3_t fBounds) { VectorCopy(m_Bounds, fBounds); }void CCamera::GetStrafe(vec3_t fStrafe) { VectorCopy(m_Strafe, fStrafe); }void CCamera::GetView(vec3_t fView) { VectorCopy(m_View, fView); }void CCamera::GetUp(vec3_t fUp) { VectorCopy(m_Up, fUp); }    void CCamera::GetStrafeVector(void){vec3_t v1;// Get the up/down axis of rotation...VectorSubtract(m_View, m_Position, v1);MyCrossProduct(v1, m_Up, m_Strafe);Normalize(m_Strafe, m_Strafe);}    void CCamera::SetPosition(float xPos, float yPos, float zPos){// Set the camera's position...vec3_t pos = { xPos, yPos, zPos };VectorCopy(pos, m_Position);}    void CCamera::SetBounds(float xBounds, float yBounds, float zBounds){// Set the camera's bounds vector...vec3_t bounds = { xBounds, yBounds, yBounds };VectorCopy(bounds, m_Bounds);}    void CCamera::SetView(float xView, float yView, float zView){// Set the camera's view vector...vec3_t view = { xView, yView, zView };VectorCopy(view, m_View);}    void CCamera::SetUp(float xUp, float yUp, float zUp){// Set the camera's up vector...vec3_t up = { xUp, yUp, zUp };VectorCopy(up, m_Up);}    void CCamera::TranslateCamera(float fSpeed){vec3_t v1;// Get the position/view vector...VectorSubtract(m_View, m_Position, v1);Normalize(v1, v1);// Add movement on to the camera...MoveCamera(fSpeed, v1);}    void CCamera::StrafeCamera(float fSpeed){// Add movement on to the camera...MoveCamera(fSpeed, m_Strafe);}    void CCamera::PanCamera(float xSpeed, float ySpeed){// Move the camera in the x direction...StrafeCamera(xSpeed);// Move the camera in the y direction...MoveCamera(ySpeed, m_Up);}    void CCamera::MoveCamera(float fSpeed, vec3_t v1){// Modify the position and view vectors...m_Position[0] += v1[0] * fSpeed;m_Position[1] += v1[1] * fSpeed;m_Position[2] += v1[2] * fSpeed;m_View[0] += v1[0] * fSpeed;m_View[1] += v1[1] * fSpeed;m_View[2] += v1[2] * fSpeed;// Keep the camera in the map...for(int x=0;x<3;x++) {if(m_Position[x] > m_Bounds[x]) m_View[x] = m_Position[x] = m_Bounds[x];if(m_Position[x] < -m_Bounds[x]) m_View[x] = m_Position[x] = -m_Bounds[x];}// Create a new strafe vector...GetStrafeVector();}    void CCamera::RotateCamera(float fAngle, vec3_t v1){vec3_t v2, v3;// Get the position/view vector...VectorSubtract(m_View, m_Position, v2);// Get the sin and cosine of the angles...float fSinTheta = (float)sin(TORADIANS(fAngle));float fCosTheta = (float)cos(TORADIANS(fAngle));// Create the new x view position...v3[0]  = (fCosTheta + (1 - fCosTheta) * v1[0] * v1[0])   * v2[0];v3[0] += ((1 - fCosTheta) * v1[0] * v1[1] - v1[2] * fSinTheta) * v2[1];v3[0] += ((1 - fCosTheta) * v1[0] * v1[2] + v1[1] * fSinTheta) * v2[2];// ...then the new y view position...v3[1]  = ((1 - fCosTheta) * v1[0] * v1[1] + v1[2] * fSinTheta) * v2[0];v3[1] += (fCosTheta + (1 - fCosTheta) * v1[1] * v1[1])   * v2[1];v3[1] += ((1 - fCosTheta) * v1[1] * v1[2] - v1[0] * fSinTheta) * v2[2];// ...and finally, the new z view position...v3[2]  = ((1 - fCosTheta) * v1[0] * v1[2] - v1[1] * fSinTheta) * v2[0];v3[2] += ((1 - fCosTheta) * v1[1] * v1[2] + v1[0] * fSinTheta) * v2[1];v3[2] += (fCosTheta + (1 - fCosTheta) * v1[2] * v1[2])   * v2[2];// Create the new view vector by adding// the new view to the camera position...VectorAdd(m_Position, v3, m_View);// Create a new strafe vector...GetStrafeVector();}    void CCamera::LoadCameraView(void){// Load the identity matrix...glLoadIdentity();// Simply use gluLookAt to load the transforms...gluLookAt(m_Position[0], m_Position[1], m_Position[2],  m_View[0], m_View[1], m_View[2],   m_Up[0], m_Up[1], m_Up[2]);}Enjoy Coding Stuff ->  [   iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]  Fun Stuff    ->  [   Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]  [edited by - iNsAn1tY on August 3, 2003 6:14:13 AM];  search for trienco''s posts. That guy has a really good camera setup with fast frustum culling. ;  though you should mention its a rather basic matrix camera. i just uploaded a small update (draw frustum and a screen2world.. this returns a point in space, not yet a direction vector.. you get this by subtracting the position.. also it requires screenwidth and height, thats why its commented out)http://festini.device-zero.de/downloads/camera.zip 