⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mgccamera.h

📁 《3D游戏引擎设计》的源码
💻 H
字号:
// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement.  The various license agreements may be found at
// the Magic Software web site.  This file is subject to the license
//
// RESTRICTED USE SOURCE CODE
// http://www.magic-software.com/License/restricted.pdf

#ifndef MGCCAMERA_H
#define MGCCAMERA_H

#include "MgcMatrix3.h"
#include "MgcObject.h"
#include "MgcPlane.h"
class MgcBound;


class MgcCamera : public MgcObject
{
    MgcDeclareRTTI;
    MgcDeclareStream;

public:
    // construction and destruction
    MgcCamera ();
    virtual ~MgcCamera ();

    // view frustum
    void SetFrustum (MgcReal fNear, MgcReal fFar, MgcReal fLeft,
        MgcReal fRight, MgcReal fTop, MgcReal fBottom);
    void SetFrustumNear (MgcReal fNear);
    void SetFrustumFar (MgcReal fFar);
    void GetFrustum (MgcReal& rfNear, MgcReal& rfFar, MgcReal& rfLeft,
        MgcReal& rfRight, MgcReal& rfTop, MgcReal& rfBottom) const;
    MgcReal GetFrustumNear () const;
    MgcReal GetFrustumFar () const;
    MgcReal GetFrustumLeft () const;
    MgcReal GetFrustumRight () const;
    MgcReal GetFrustumTop () const;
    MgcReal GetFrustumBottom () const;
    MgcReal GetMaxCosSqrFrustumAngle () const;

    // view port (contained in [0,1]^2)
    void SetViewPort (MgcReal fLeft, MgcReal fRight, MgcReal fTop,
        MgcReal fBottom);
    void GetViewPort (MgcReal& rfLeft, MgcReal& rfRight, MgcReal& rfTop,
        MgcReal& rfBottom);
    MgcReal GetViewPortLeft () const;
    MgcReal GetViewPortRight () const;
    MgcReal GetViewPortTop () const;
    MgcReal GetViewPortBottom () const;

    // camera frame (world coordinates)
    //   default location = (0,0,0)
    //   default left = (1,0,0)
    //   default up = (0,1,0)
    //   default direction = (0,0,1)
    void SetFrame (const MgcVector3& rkLocation, const MgcVector3& rkLeft,
        const MgcVector3& rkUp, const MgcVector3& rkDirection);
    void SetFrame (const MgcVector3& rkLocation, const MgcMatrix3& rkAxes);
    void SetLocation (const MgcVector3& rkLocation);
    void SetAxes (const MgcVector3& rkLeft, const MgcVector3& rkUp,
        const MgcVector3& rkDirection);
    void SetAxes (const MgcMatrix3& rkAxes);
    const MgcVector3& GetLocation () const;
    const MgcVector3& GetLeft () const;
    const MgcVector3& GetUp () const;
    const MgcVector3& GetDirection () const;

    // update callbacks
    void Update ();
    virtual void OnFrustumChange ();
    virtual void OnViewPortChange ();
    virtual void OnFrameChange ();

    // culling support
    void SetPlaneState (unsigned int uiPlaneState);
    unsigned int GetPlaneState () const;
    bool Culled (const MgcBound& kWorldBound);

protected:
    // view frustum
    MgcReal m_fFrustumN, m_fFrustumF;
    MgcReal m_fFrustumL, m_fFrustumR, m_fFrustumT, m_fFrustumB;

    // view port
    MgcReal m_fPortL, m_fPortR, m_fPortT, m_fPortB;

    // camera frame (world location and coordinate axes)
    MgcVector3 m_kLocation, m_kLeft, m_kUp, m_kDirection;

    // culling support
    enum
    {
        // plane indices (store only frustum planes for now)
        PI_NEAR,
        PI_FAR,
        PI_LEFT,
        PI_RIGHT,
        PI_BOTTOM,
        PI_TOP,
        PI_QUANTITY
    };

    enum
    {
        // plane bit masks for m_uiPlaneState;
        PBM_NEAR   =  1,
        PBM_FAR    =  2,
        PBM_LEFT   =  4,
        PBM_RIGHT  =  8,
        PBM_BOTTOM = 16,
        PBM_TOP    = 32
    };

    unsigned int m_uiPlaneState;  // bit = 1 -> active, bit = 0 -> inactive
    MgcPlane m_akWorldPlane[PI_QUANTITY];
    MgcReal m_afCoeffL[2], m_afCoeffR[2], m_afCoeffB[2], m_afCoeffT[2];

    void UpdateWorldPlanes ();
};

MgcSmartPointer(MgcCamera);
MgcRegisterStream(MgcCamera);
#include "MgcCamera.inl"

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -