2011年3月4日 星期五

BoneEdit-Camera

我們需要一個攝影機的功能,方便視角轉來轉去,像下面的影片

class CCamera
{
public:
    CCamera();
    virtual ~CCamera();
    void UpData();//更新
    void Move(float vec);//前後移動
    void Strafe(float vec);//左右平移
    void SetPosition(Vector pos);//設定位置(觀看點隨位罝移動)
    Vector Position;//位置
    Vector ViewPoint;//觀看的目標
    Vector UpVector;//頭頂的位置
};

Vector是個向量的類別,包含了xyz的值.
最重要的Updata為
void CCamera::UpData()
{
    gluLookAt(  (GLfloat)Position[0], (GLfloat)Position[1], (GLfloat)Position[2],
                (GLfloat)ViewPoint[0], (GLfloat)ViewPoint[1], (GLfloat)ViewPoint[2],
                (GLfloat)UpVector[0], (GLfloat)UpVector[1], (GLfloat)UpVector[2] );
}
直接使用gluLookAt設定攝影機的參數,其它的函式都是一些數學運算,像是
void CCamera::SetPosition(Vector pos)//設定位置
{
    Vector v;
    v = pos - Position;
    ViewPoint += v;
    Position = pos;
}
其它的函式就不貼程式碼了.

沒有留言:

張貼留言