-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add move modual,can use w s a d to move the camera
- Loading branch information
Showing
15 changed files
with
230 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,54 @@ | ||
#include "ArcCamera.h" | ||
#include <algorithm> | ||
|
||
using std::max; | ||
using std::min; | ||
|
||
ArcCamera::ArcCamera() | ||
:target_(0.0f,1.0f,0.0f), | ||
distance_(5.0f), | ||
xRotation_(0.0f), | ||
yRotation_(0.0f), | ||
xlimit(XM_PIDIV2), | ||
ylimit(XM_PI) | ||
{} | ||
|
||
ArcCamera::~ArcCamera(){} | ||
|
||
void ArcCamera::SetRotation(float x, float y) | ||
{ | ||
xRotation_ = x; | ||
yRotation_ = y; | ||
xRotation_ = max(xRotation_, -xlimit); | ||
xRotation_ = min(xRotation_, xlimit); | ||
yRotation_ = max(yRotation_, -ylimit); | ||
yRotation_ = min(yRotation_, ylimit); | ||
}void ArcCamera::SetTarget(XMFLOAT3& target) | ||
{ | ||
target_ = target; | ||
} | ||
|
||
void ArcCamera::ApplyRotation(float yawDelta, float pitchDelta) | ||
{ | ||
xRotation_ += yawDelta; | ||
yRotation_ += pitchDelta; | ||
xRotation_ = max(xRotation_, -xlimit); | ||
xRotation_ = min(xRotation_, xlimit); | ||
yRotation_ = max(yRotation_, -ylimit); | ||
yRotation_ = min(yRotation_, ylimit); | ||
} | ||
|
||
XMMATRIX ArcCamera::GetViewMatrix() | ||
{ | ||
XMVECTOR zoom = XMVectorSet(0.0f, 0.0f, -distance_, 1.0f); | ||
XMMATRIX rotation = XMMatrixRotationRollPitchYaw(xRotation_, yRotation_, 0.0f); | ||
zoom = XMVector3Transform(zoom, rotation); | ||
XMVECTOR lookAt = XMLoadFloat3(&target_); | ||
XMVECTOR pos = lookAt + zoom; | ||
XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f); | ||
up = XMVector3Transform(up, rotation); | ||
XMMATRIX viewMat = XMMatrixLookAtLH(pos, lookAt, up); | ||
return viewMat; | ||
#include "ArcCamera.h" | ||
#include <algorithm> | ||
|
||
using std::max; | ||
using std::min; | ||
|
||
ArcCamera::ArcCamera() | ||
:target_(0.0f,2.0f,0.0f), | ||
distance_(5.0f), | ||
xRotation_(0.0f), | ||
yRotation_(0.0f), | ||
xlimit(XM_PIDIV2), | ||
ylimit(XM_PI) | ||
{} | ||
|
||
ArcCamera::~ArcCamera(){} | ||
|
||
void ArcCamera::SetRotation(float x, float y) | ||
{ | ||
xRotation_ = x; | ||
yRotation_ = y; | ||
xRotation_ = max(xRotation_, -xlimit); | ||
xRotation_ = min(xRotation_, xlimit); | ||
yRotation_ = max(yRotation_, -ylimit); | ||
yRotation_ = min(yRotation_, ylimit); | ||
} | ||
|
||
void ArcCamera::SetPositions(XMFLOAT3 pos, XMFLOAT3 target) | ||
{ | ||
target_ = target; | ||
} | ||
|
||
void ArcCamera::ApplyRotation(float yawDelta, float pitchDelta) | ||
{ | ||
xRotation_ += yawDelta; | ||
yRotation_ += pitchDelta; | ||
xRotation_ = max(xRotation_, -xlimit); | ||
xRotation_ = min(xRotation_, xlimit); | ||
yRotation_ = max(yRotation_, -ylimit); | ||
yRotation_ = min(yRotation_, ylimit); | ||
} | ||
|
||
XMMATRIX ArcCamera::GetViewMatrix() | ||
{ | ||
XMVECTOR zoom = XMVectorSet(0.0f, 0.0f, -distance_, 1.0f); | ||
XMMATRIX rotation = XMMatrixRotationRollPitchYaw(xRotation_, yRotation_, 0.0f); | ||
zoom = XMVector3Transform(zoom, rotation); | ||
XMVECTOR lookAt = XMLoadFloat3(&target_); | ||
XMVECTOR pos = lookAt + zoom; | ||
XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f); | ||
up = XMVector3Transform(up, rotation); | ||
XMMATRIX viewMat = XMMatrixLookAtLH(pos, lookAt, up); | ||
return viewMat; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Texture2D colorMap_ : register(t0); | ||
SamplerState colorSampler_ : register(s0); | ||
cbuffer worldCb : register(b0) | ||
{ | ||
matrix worldMatrix; | ||
}; | ||
cbuffer viewCb : register(b1) | ||
{ | ||
matrix viewMatrix; | ||
}; | ||
cbuffer projCb : register(b2) | ||
{ | ||
matrix projMatrix; | ||
}; | ||
cbuffer textureCb:register(b3) { | ||
matrix textMatirx; | ||
}; | ||
struct VS_Input | ||
{ | ||
float4 pos : POSITION; | ||
float2 tex0 : TEXCOORD0; | ||
}; | ||
struct PS_Input | ||
{ | ||
float4 pos : SV_POSITION; | ||
float2 tex0 : TEXCOORD0; | ||
}; | ||
PS_Input VS_Main(VS_Input vertex) | ||
{ | ||
PS_Input vsOut = (PS_Input)0; | ||
vsOut.pos = mul(vertex.pos, worldMatrix); | ||
vsOut.pos = mul(vsOut.pos, viewMatrix); | ||
vsOut.pos = mul(vsOut.pos, projMatrix); | ||
vsOut.tex0 = mul(textMatirx, float4(vertex.tex0, 0.0f, 1.0f)); | ||
return vsOut; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.