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

📄 camera.h

📁 使用shader语言在vs阶段编写光照效果的演示程序及全部源代码
💻 H
字号:
#ifndef _CAMERA_H_
#define _CAMERA_H_

#include <d3d9.h>
#include <d3dx9.h>

class XCamera
{
public:
	//Projection Type
	enum PROJECT_T
	{
		PT_PROJECT = 0, 
		PT_ORTHO   = 1, 
		PT_FRUSTUM = 2  // Not implemented
	};

	//Define the view rect
	class XViewRect
	{
	public:
		float m_left;
		float m_right;
		float m_top;
		float m_bottom;
	};
public:
	//define the eye infomation
	class XEye
	{
		friend class XCamera;
	public:
		D3DXVECTOR3 m_Up;
		D3DXVECTOR3 m_EyePos;
		D3DXVECTOR3 m_EyeTarget;
	public:
		XEye(D3DXVECTOR3& EyeTarget,D3DXVECTOR3& EyePos,D3DXVECTOR3& Up)
			:m_Up(Up),m_EyePos(EyePos),m_EyeTarget(EyeTarget)
		{

		}
		XEye();
		/*no destructor*/
		~XEye(){};
	};
public:

	/*****************************************************************
	yaw.
	pitch.
	roll
	circle.
	*****************************************************************/
	void yaw(float angle);
	void pitch(float angle);
	void roll(float angle);
	void circle(float angle);


	/*****************************************************************
	change the camera's position
	*****************************************************************/
	void toward(float dist);
	void upDown(float dist);
	void shift(float  dist);

	/*****************************************************************
	rotate the camera
	*****************************************************************/
	void rotate(D3DXVECTOR3& axis,float angle);

	void focus(float dist,float factor = 0.1);


	/*****************************************************************
	set / get the property
	*****************************************************************/
	void   setEye(XCamera::XEye& eye){m_Eye = eye;};



	/*****************************************************************
	//set the projectino's informatino。
	*****************************************************************/
	void   setFOV(float fov)                    {m_fFov   = fov;         }
	void   setNearPlan(float near_plan)         {m_fNear  = near_plan;   }
	void   setFarPlan(float  far_plan)          {m_fFar   = far_plan;    }
	void   setAspect(float   aspect )           {m_fAspect= aspect;      }


	/*****************************************************************
	//set the viewport's size 。only effect the ortho .
	*****************************************************************/
	void   setViewRect(XViewRect& rect)         {m_ViewRect=rect;        }


	/*****************************************************************
	//set the projectiv mode。
	*****************************************************************/
	void   setProjectType(PROJECT_T type)       {m_ProjectType = type  ; }
	//get the projectiv mode。
	PROJECT_T getProjectType()                  {return m_ProjectType  ; }


	void   setViewRect(float  l,float r,float t,float b)
	{
		m_ViewRect.m_left = l;
		m_ViewRect.m_right = r;
		m_ViewRect.m_top = t;
		m_ViewRect.m_bottom =b;
	}

	/*****************************************************************
	得到摄影机的参数
	*****************************************************************/

	XEye&  getEye()                             {return     m_Eye;       }
	float  getFOV()                             {return     m_fFov;      }
	float  getNearPlan()                        {return     m_fNear;     }
	float  getFarPlan()                         {return     m_fFar;      }
	float  getAspect()                          {return     m_fAspect;    }

	XViewRect* getViewRect()                    {return    &m_ViewRect;  }



public:
	//you need to overload this function to apply your camera
	void applyCamera();
	void applyProjection();
	XEye m_Eye;
private:


	/*
	Project Matrix  information。
	*/
	float m_fFov;
	float m_fNear;
	float m_fFar;
	float m_fAspect;

	XViewRect   m_ViewRect;
	PROJECT_T   m_ProjectType;

};

#endif

⌨️ 快捷键说明

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