www.pudn.com > notWow.rar > Camera.h
#pragma once #include#include "Math.h" class Frustum { private: D3DXPLANE m_Planes[6]; public: bool Construct(D3DXMATRIX matProj,D3DXMATRIX matView,float Far = 0.0f ,float Near = 0.0f); bool ConstructForSky(D3DXMATRIX matProj,D3DXMATRIX matView,float Far,float Near,float BottomParam); bool CheckPoint(float XPos, float YPos, float ZPos); bool CheckCube(float XCenter, float YCenter, float ZCenter, float Size, bool *CompletelyContained = NULL); bool CheckRectangle(float XCenter, float YCenter, float ZCenter, float XSize, float YSize, float ZSize, bool *CompletelyContained = NULL); bool CheckSphere(float XCenter, float YCenter, float ZCenter, float Radius); bool CheckPlaneXZ(float XCenter,float ZCenter, float XSize,float ZSize, bool *CompletelyContained = NULL); inline bool CheckRectangle(const D3DXVECTOR3 &vMin,const D3DXVECTOR3 &vMax,bool *CompletelyContained = NULL) { return CheckRectangle((vMax.x + vMin.x) / 2 ,(vMax.y + vMin.y) / 2 ,(vMax.z + vMin.z) / 2 , (vMax.x - vMin.x) / 2 ,(vMax.y - vMin.y) / 2 ,(vMax.z - vMin.z) / 2 ,CompletelyContained); } }; class Camera { protected: float m_Height; float m_Distance; float m_Fog; float m_Background; float m_Sky; float m_SkyPlaneParam; float m_BGHeight; float m_SkyHeight; float m_BGHalfWidth; float m_SkyHalfWidth; float m_BGDir; float m_BGX,m_BGZ; float m_SkyX,m_SkyY,m_SkyZ; bool m_bFPView; float m_XPos, m_YPos, m_ZPos; float m_XRot, m_YRot, m_ZRot; float m_StartXPos, m_StartYPos, m_StartZPos; float m_StartXRot, m_StartYRot, m_StartZRot; float m_EndXPos, m_EndYPos, m_EndZPos; float m_EndXRot, m_EndYRot, m_EndZRot; D3DXMATRIX m_matProj; D3DXMATRIX m_matView; D3DXMATRIX m_matViewProj; Frustum m_VisibityFrustum; Frustum m_BackgroundFrustum; public: Camera() : m_Height(10.0),m_Distance(10.0), m_bFPView(true), m_Fog(60),m_Background(100),m_Sky(160), m_SkyPlaneParam(0.2),m_SkyHeight(10.0),m_BGHeight(10.0) { } // float GetVisibityDist() { return m_Visibity; } // float GetFogDist() { return m_Fog; } // float GetBackgroundDist() { return m_Background; } // float GetSkyDist() { return m_Sky; } int GetBGDir() { return m_BGDir; } float GetBGX() { return m_BGX; } float GetBGZ() { return m_BGZ; } float GetBGY() { return 0; } float GetSkyX() { return m_SkyX; } float GetSkyY() { return m_SkyY; } float GetSkyZ() { return m_SkyZ; } float GetSkyHeight() { return m_SkyHeight; } float GetBGHeight() { return m_BGHeight; } float GetSkyHalfWidth() { return m_SkyHalfWidth; } float GetBGHalfWidth() { return m_BGHalfWidth; } void SetFogDist(float value) { m_Fog = value; } void SetBackgroundDist(float value) { m_Background = value; } void SetSkyDist(float value) { m_Sky = value; } void SetSkyParam(float value) { m_SkyPlaneParam = value;} float GetFogStart() { return m_Fog; } float GetFogEnd() { return m_Background; } bool IsFPView() { return m_bFPView; } D3DXMATRIX *GetProj() { return &m_matProj; } D3DXMATRIX *GetView() { return &m_matView; } D3DXMATRIX *GetViewProj() { return &m_matViewProj; } // For Loot-Down Viewing Frustum *GetFrustum() { return &m_VisibityFrustum; } // For First-Peron Viewing Frustum *GetVisibityFrustum() { return &m_VisibityFrustum; } Frustum *GetBackgroundFrustum() { return &m_BackgroundFrustum;} void Init(float Fog,float BG,float Sky,float SPP,float Aspect) { m_Fog = Fog; m_Background = BG; m_Sky = Sky; m_SkyPlaneParam = SPP; Reset(Aspect); } void Update(float fTime,float X,float Y,float Z,int Dir); void Reset(float Aspect); };