資源簡介
opengl完美天空盒 天空盒無縫連接 有CS模仿和背景音效!!絢麗

代碼片段和文件信息
#include?“Camera.h“
#include?
#include?
#include?
//?默認初始化Camera屬性
CCamera::CCamera()
{
//?初始化Camera為OpenGL的默認方向
CVector3?vPos(0.0?0.0?0.0);
CVector3?vView(0.0?0.0-1.0);
CVector3?vUp(0.0?1.0?0.0);
m_vPosition =?vPos;
m_vView =?vView;
m_vUpVector =?vUp;
SetCursorPos(Window_Width?>>?1?Window_Height?>>?1);
ShowCursor(FALSE);
}
//?設置Camera位置
void?CCamera::PositionCamera(float?posX?float?posY?float?posZ
?float?viewX?float?viewY?float?viewZ
?float?upX?float?upY?float?upZ)
{
//?初始化Camera
CVector3?vPos =?CVector3(posX?posY?posZ);
CVector3?vView =?CVector3(viewX?viewY?viewZ);
CVector3?vUp =?CVector3(upX?upY?upZ);
m_vPosition?=?vPos;
m_vView?????=?vView;
m_vUpVector?=?vUp;
//?將m_vView到m_vPosition的向量單位化
m_vView?=?m_vPosition?+?(m_vView-m_vPosition).GetNormalized();
SetCursorPos(Window_Width?>>?1?Window_Height?>>?1);
}
//?設置Camera位置
void?CCamera::PositionCamera(const?CVector3?&pos?const?CVector3?&view?const?CVector3?&up)
{
//?初始化Camera
m_vPosition?=?pos;
m_vView?=?view;
m_vUpVector?=?up;
//?將m_vView到m_vPosition的矢量單位化
m_vView?=?m_vPosition?+?(m_vView-m_vPosition).GetNormalized();
SetCursorPos(Window_Width?>>?1?Window_Height?>>?1);
}
//?通過移動鼠標移動Camera的方向(第一人稱)
void?CCamera::SetViewByMouse(void)
{
POINT?mousePos; //?存儲鼠標位置的結構體
//int?middleX?=?Window_Width??>>?1; //?窗口寬度的一半
// int?middleY?=?Window_Height?>>?1; //?窗口高度的一半
int?middleX?=?Window_Width>>1?; //?窗口寬度的一半
int?middleY?=?Window_Height>>1; //?窗口高度的一半
float?angleY?=?0.0f; //?存儲向上看、向下看的角度
float?angleZ?=?0.0f; //?存儲向左看、向右看的角度
static?float?currentRotX?=?0.0f; //?存儲總的向上、向下的旋轉角度
//?獲得當前鼠標位置
GetCursorPos(&mousePos);
//?如果鼠標仍然在正中間,不更新場景
if?((mousePos.x?==?middleX)?&&?(mousePos.y?==?middleY))
{
return;
}
//?將鼠標置回屏幕的中央
SetCursorPos(middleX?middleY);
//?獲得鼠標移動的方向
angleY?=?(float)((middleX?-?mousePos.x))?/?100.0f;
angleZ?=?(float)((middleY?-?mousePos.y))?/?100.0f;
//?保存一個當前向上或向下旋轉過的角度,可以限制Camera上下做360度旋轉
currentRotX?-=?angleZ;??
//?如果當前的旋轉弧度大于1.3,不讓Camera繼續向上旋轉
if?(currentRotX?>?1.3f)
{
currentRotX?=?1.3f;
}
//?如果當前的旋轉弧度小于1.3,不讓Camera繼續向下旋轉
else?if?(currentRotX?-1.3f)
{
currentRotX?=?-1.3f;
}
//?否則繞所處位置旋轉視線
else
{
//?繞Camera的水平向量旋轉Camera(上下)
RotateView(angleZ?m_vStrafe);
}
//?繞Camera的向上向量旋轉Camera(左右)
RotateView(angleY?CVector3(010));
}
//?繞給出的軸旋轉Camera的方向
void?CCamera::RotateView(float?angle?const?CVector3?&vAxis)
{
CVector3?vNewView;
CVector3?vView?=?m_vView?-?m_vPosition;
vNewView?=?vView.GetRotatedAxis(angle?vAxis);
m_vView?=?m_vPosition?+?vNewView;
}
//?確認鍵盤控制的移動
void?CCamera::CheckForMovement()
{
//?判斷是否按下向上鍵或‘W‘鍵
if?(GetKeyState(VK_UP)?&?0x80?||?GetKeyState(‘W‘)?&?0x80)
{
MoveCamera(MOVESPEED); //?向前移動Camera
}
//?判斷是否按下向下鍵或‘S‘鍵
if?(GetKeyState(VK_DOWN)?&?0x80?||?GetKeyState(‘S‘)?&?0x80)
{
M
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2011-11-08?22:24??天空盒\
?????文件????????4724??2011-04-13?13:53??天空盒\Camera.cpp
?????文件????????1345??2011-04-13?13:50??天空盒\Camera.h
?????文件????????4937??2004-11-28?19:33??天空盒\CDSound.cpp
?????文件?????????918??2004-12-01?18:34??天空盒\CDSound.h
?????文件?????????766??2011-04-12?11:34??天空盒\crosshair.cur
?????目錄???????????0??2011-11-08?22:23??天空盒\Data\
?????文件??????786486??2011-04-12?19:00??天空盒\Data\5Back.bmp
?????文件??????786486??2011-04-12?19:00??天空盒\Data\5Bottom.bmp
?????文件??????786486??2011-04-12?19:00??天空盒\Data\5Front.bmp
?????文件??????103885??2009-03-19?20:07??天空盒\Data\5Front.jpg
?????文件??????786486??2011-04-12?19:00??天空盒\Data\5Left.bmp
?????文件??????786486??2011-04-12?19:00??天空盒\Data\5Right.bmp
?????文件??????786486??2011-04-12?19:00??天空盒\Data\5Top.bmp
?????文件??????786486??2011-04-12?19:00??天空盒\Data\7back.bmp
?????文件??????786486??2011-04-12?19:00??天空盒\Data\7bottom.bmp
?????文件??????786486??2011-04-12?19:00??天空盒\Data\7front.bmp
?????文件??????786486??2011-04-12?19:00??天空盒\Data\7left.bmp
?????文件??????786486??2011-04-12?19:00??天空盒\Data\7right.bmp
?????文件??????786486??2011-04-12?19:00??天空盒\Data\7top.bmp
?????目錄???????????0??2011-11-08?22:24??天空盒\Debug\
?????文件???????30187??2011-04-13?22:25??天空盒\Debug\Camera.obj
?????文件???????17630??2011-04-13?22:25??天空盒\Debug\CDSound.obj
?????文件?????????766??2005-05-27?23:59??天空盒\Debug\crosshair.cur
?????文件??????137216??2009-04-14?13:32??天空盒\Debug\Fmod.dll
?????文件??????155352??2009-04-14?13:32??天空盒\Debug\Fmodvc.lib
?????文件???????16224??2011-04-13?22:50??天空盒\Debug\Font.obj
?????文件?????2049024??2008-12-11?13:07??天空盒\Debug\Hang.bsc
?????文件?????1145588??2011-04-14?10:04??天空盒\Debug\Hang.ilk
?????文件?????4074336??2011-04-13?22:52??天空盒\Debug\Hang.pch
?????文件??????844800??2011-04-14?10:04??天空盒\Debug\Hang.pdb
............此處省略31個文件信息
- 上一篇:小煩通用內存修改器源碼
- 下一篇:ForceAtlas2圖布局算法
評論
共有 條評論