GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


picking ray camera.h by Pompei2
1
 
#ifndef FTS_CAMERA_H
#define FTS_CAMERA_H

#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>

/** Transforms degree into radians. */
#define RAD( deg ) (deg) / 57.295779513f

/** Transforms radians into degrees. */
#define DEG( rad ) (rad) * 57.295779513f

#define ERR_OK 0

// A 3D coordinate.
typedef struct _SPos3D_ {
    float x, y, z;
} SPos3D, *PPos3D;

// Rotate the point pos around the X axis and returns the reslut.
SPos3D rotateX( float deg, SPos3D pos );
// Rotate the point pos around the Y axis and returns the reslut.
SPos3D rotateY( float deg, SPos3D pos );
// Rotate the point pos around the Z axis and returns the reslut.
SPos3D rotateZ( float deg, SPos3D pos );
// Substract v2 from v1 . Can be used to calculate their distance.
SPos3D operator- ( SPos3D v1, SPos3D v2 );
// Normalise a vector (make it's magnitude be 1).
int v_normalize( PPos3D v );


class CCamera
{
private:
    SPos3D m_pos;
    SPos3D m_target;

    /* Maybe we fixate a special point ? */
    PPos3D m_pFixate;

    /* Just to know ... */
    float m_rX, m_rY, m_rZ;
public:
    CCamera( void );
    virtual ~CCamera( void );

    /// Doas all the glRotatef and glTranslatef stuff so the camera is placed.
    /// \note You should call glLoadIdentity before calling this function.
    void render( void );

    /// Sets the target where the camera looks at.
    void target( float x, float y, float z );
    /// Does nothing special visibly, but internally recalculates the target position.
    void recalcTarget( void );

    /* --- The lowlevel get/set functions. --- */
    /// Set the current camera's position.
    void   setPos( float x, float y, float z );
    /// Returns the x position of the camera itself.
    float  x( void ) { return m_pos.x; };
    /// Returns the y position of the camera itself.
    float  y( void ) { return m_pos.y; };
    /// Returns the z position of the camera itself.
    float  z( void ) { return m_pos.z; };

    /* --- Higher level get/sets --- */
    /// Write the modelview matrix into \a mv .
    void getModelviewMatrix( double mv[16] );
    /// Write the projection matrix into \a mp .
    void getProjectionMatrix( double mp[16] );
};

#endif /* FTS_CAMERA_H */

 /*  */