資源簡介
DX圖形設計的期末大項目,給各位參考一下。應有的功能都有了。
代碼片段和文件信息
#include?“Camera.h“
Camera::Camera()??//構造函數,初始化Camera類的成員變量
{
flag?=?Rotate?|?Translate;????//指定標識符
rotateX?=?0.0f;???????????????//繞X軸旋轉的角度
rotateY?=?0.0f;????????????????//繞Y軸旋轉的角度
rotateZ?=?0.0f;????????????????//繞Z軸旋轉的角度
move?=?XMVectorSet(0.0f?0.0f?0.0f?1.0f);??//初始化移動位置
eye?=?XMVectorSet(0.0f?0.0f?0.0f?1.0f);???//初始化視點位置
//初始化相機的旋轉矩陣
//這里需要將XMMATRIX對象轉變成XMStoreFloat4x4對象
XMMATRIX?cameraRotationMATRIX?=?XMMatrixIdentity();
XMStoreFloat4x4(&cameraRotation?cameraRotationMATRIX);
//初始化相機的觀察矩陣
//同樣需要將XMMATRIX對象轉變成XMStoreFloat4x4對象
XMMATRIX?viewMATRIX?=?XMMatrixIdentity();
XMStoreFloat4x4(&view?viewMATRIX);
}
//仰俯
void?Camera::Pitch(float?angle)
{
rotateX?+=?angle;
flag?|=?Rotate;
}
//偏轉
void?Camera::Yaw(float?angle)
{
rotateY?+=?angle;
flag?|=?Rotate;
}
//設置視點位置
void?Camera::SetEye(const?XMVECTOR&?position)
{
eye?=?position;
flag?|=?Translate;
}
//獲得當前視點位置
const?XMVECTOR&?Camera::GetEye()
{
return?eye;
}
//獲得當前攝像機的觀察點
const?XMVECTOR&?Camera::GetAt()
{
return?at;
}
//獲得當前攝像機的正方向
const?XMVECTOR&?Camera::GetUp()
{
return?up;
}
//向前移動攝像機,value取負值則向后移動
void?Camera::MoveForwardBy(float?value)
{
move?=?XMVectorSetZ(move?value);
flag?|=?Translate;
}
//向右移動攝像機,value取負值則向左旋轉
void?Camera::MoveRightBy(float?value)
{
move?=?XMVectorSetX(move?value);
flag?|=?Translate;
}
//向上移動攝像機,value取負值則向下移動
void?Camera::MoveUpBy(float?value)
{
move?=?XMVectorSetY(move?value);
flag?|=?Translate;
}
//應用當前設置生成觀察變換矩陣
void?Camera::Apply()
{
XMMATRIX?cameraRotationMATRIX;????//聲明XMMATRIX一個對象用于矩陣變換
if?(flag?!=?None)
{
if?((flag?&?Rotate)?!=?0)??//如果包含旋轉標識
{
//將Rotate取否,即1110,再和flag進行與運算
//如果flag=0011則運算結果為0010
flag?&=?~Rotate;
//在三個坐標系上進行旋轉變換
cameraRotationMATRIX?=?XMMatrixRotationX(rotateX)?*?XMMatrixRotationY(rotateY)?*?XMMatrixRotationZ(rotateZ);
XMStoreFloat4x4(&cameraRotation?cameraRotationMATRIX);?//將生成的XMMATRIX存放到成員cameraRotation
}
if?((flag?&?Translate)?!=?0)//如果包含平移標識
{
//將Translate取否,即1110,再和flag進行與運算
//如果flag=0010則運算結果為0000
flag?&=?~Translate;
//從成員cameraRotation獲得旋轉矩陣
cameraRotationMATRIX?=?xmloadFloat4x4(&cameraRotation);
//重新計算視點位置
eye?+=?XMVector4Transform(move?cameraRotationMATRIX);
move?=?XMVectorZero();?//重置移動向量
}
//從成員cameraRotation獲得旋轉矩陣
cameraRotationMATRIX?=?xmloadFloat4x4(&cameraRotation);
//重新計算觀察點
at?=?eye?+?XMVector4Transform(XMVectorSet(0.0f?0.0f?1.0f?1.0f)?cameraRotationMATRIX);
//重新計算攝像機正方向
up?=?XMVector4Transform(XMVectorSet(0.0f?1.0f?0.0f?1.0f)?cameraRotationMATRIX);
//重新計算觀察矩陣
XMMATRIX?viewMATRIX?=?XMMatrixLookAtLH(eye?at?up);
//將新生成的觀察矩陣存入成員view中
XMStoreFloat4x4(&view?viewMATRIX);
}
}
//獲得觀察坐標系變換矩陣
const?XMFLOAT4X4&?Camera::GetView()
{
return?view;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-01-03?11:37??D3Djumpganme\
?????目錄???????????0??2018-01-03?11:37??D3Djumpganme\D3DTexture\
?????文件????44171264??2018-01-03?11:37??D3Djumpganme\D3DTexture.sdf
?????文件?????????976??2017-12-20?10:25??D3Djumpganme\D3DTexture.sln
?????文件???????31232??2018-01-03?11:37??D3Djumpganme\D3DTexture.v12.suo
?????文件???????20753??2018-01-02?19:54??D3Djumpganme\D3DTexture\0.png
?????文件???????18986??2018-01-02?19:55??D3Djumpganme\D3DTexture\1.png
?????文件???????20400??2018-01-02?19:55??D3Djumpganme\D3DTexture\2.png
?????文件???????20726??2018-01-02?19:55??D3Djumpganme\D3DTexture\3.png
?????文件???????19637??2018-01-02?19:56??D3Djumpganme\D3DTexture\4.png
?????文件???????20143??2018-01-02?19:56??D3Djumpganme\D3DTexture\5.png
?????文件???????21233??2018-01-02?19:56??D3Djumpganme\D3DTexture\6.png
?????文件???????19803??2018-01-02?19:57??D3Djumpganme\D3DTexture\7.png
?????文件???????21392??2018-01-02?19:57??D3Djumpganme\D3DTexture\8.png
?????文件???????21175??2018-01-02?19:58??D3Djumpganme\D3DTexture\9.png
?????文件??????592776??2018-01-02?19:59??D3Djumpganme\D3DTexture\bg14.jpg
?????文件???????66614??1999-09-25?20:19??D3Djumpganme\D3DTexture\BOX.bmp
?????文件????????3242??2018-01-01?16:34??D3Djumpganme\D3DTexture\Camera.cpp
?????文件????????1433??2018-01-03?11:34??D3Djumpganme\D3DTexture\Camera.h
?????文件???????69410??2018-01-03?11:37??D3Djumpganme\D3DTexture\d3dTexture.cpp
?????文件????????4816??2018-01-01?16:34??D3Djumpganme\D3DTexture\D3DTexture.vcxproj
?????文件????????1642??2018-01-01?16:34??D3Djumpganme\D3DTexture\D3DTexture.vcxproj.filters
?????文件????????3267??2017-12-20?10:31??D3Djumpganme\D3DTexture\d3dUtility.cpp
?????文件????????1259??2017-12-20?10:31??D3Djumpganme\D3DTexture\d3dUtility.h
?????目錄???????????0??2018-01-03?11:36??D3Djumpganme\D3DTexture\Debug\
?????文件??????228424??2018-01-03?11:34??D3Djumpganme\D3DTexture\Debug\Camera.obj
?????文件???????10661??2018-01-03?11:36??D3Djumpganme\D3DTexture\Debug\D3DTexture.log
?????文件??????510358??2018-01-03?11:36??D3Djumpganme\D3DTexture\Debug\d3dTexture.obj
?????目錄???????????0??2018-01-03?11:36??D3Djumpganme\D3DTexture\Debug\D3DTexture.tlog\
?????文件????????3326??2018-01-03?11:36??D3Djumpganme\D3DTexture\Debug\D3DTexture.tlog\cl.command.1.tlog
?????文件???????62976??2018-01-03?11:36??D3Djumpganme\D3DTexture\Debug\D3DTexture.tlog\CL.read.1.tlog
............此處省略28個文件信息
評論
共有 條評論