Flying controls

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 0e73971db8
commit 4d48e2653e
  1. BIN
      C++ProjectTemplate
  2. 13
      main.cpp

Binary file not shown.

@ -138,6 +138,7 @@ private:
float fTheta=0; float fTheta=0;
float fYaw=0; float fYaw=0;
float pitch=-M_PI/6;
vec3d vec3d
Matrix_MultiplyVector(mat4x4 &m, vec3d &i) Matrix_MultiplyVector(mat4x4 &m, vec3d &i)
@ -471,16 +472,10 @@ public:
bool OnUserUpdate(float fElapsedTime) override bool OnUserUpdate(float fElapsedTime) override
{ {
if (GetKey(olc::DOWN).bHeld) { if (GetKey(olc::DOWN).bHeld) {
vCamera.y-=8*fElapsedTime; pitch-=1*fElapsedTime;
} }
if (GetKey(olc::UP).bHeld) { if (GetKey(olc::UP).bHeld) {
vCamera.y+=8*fElapsedTime; pitch+=1*fElapsedTime;
}
if (GetKey(olc::RIGHT).bHeld) {
vCamera.x+=8*fElapsedTime;
}
if (GetKey(olc::LEFT).bHeld) {
vCamera.x-=8*fElapsedTime;
} }
vec3d vForward=Vector_Mul(vLookDir,8*fElapsedTime); vec3d vForward=Vector_Mul(vLookDir,8*fElapsedTime);
if (GetKey(olc::W).bHeld) { if (GetKey(olc::W).bHeld) {
@ -508,7 +503,7 @@ public:
matWorld=Matrix_MultiplyMatrix(matWorld,matTrans); matWorld=Matrix_MultiplyMatrix(matWorld,matTrans);
vec3d vUp={0,1,0}; vec3d vUp={0,1,0};
vec3d vTarget={0,0,1}; vec3d vTarget={0,sinf(pitch),cosf(pitch)};
mat4x4 matCameraRot=Matrix_MakeRotationY(fYaw); mat4x4 matCameraRot=Matrix_MakeRotationY(fYaw);
vLookDir=Matrix_MultiplyVector(matCameraRot,vTarget); vLookDir=Matrix_MultiplyVector(matCameraRot,vTarget);
vTarget=Vector_Add(vCamera,vLookDir); vTarget=Vector_Add(vCamera,vLookDir);

Loading…
Cancel
Save