Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
349 additions
and
36 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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
BasedOnStyle: Microsoft | ||
AccessModifierOffset: -1 | ||
AlignArrayOfStructures: Left | ||
AlignConsecutiveAssignments: | ||
Enabled: true | ||
AcrossEmptyLines: true | ||
AcrossComments: true | ||
AlignCompound: true | ||
AlignConsecutiveBitFields: | ||
Enabled: true | ||
AcrossEmptyLines: true | ||
AcrossComments: true | ||
AlignCompound: true | ||
PadOperators: true | ||
AlignConsecutiveDeclarations: | ||
AcrossComments: true | ||
AlignCompound: true | ||
PadOperators: true | ||
AlignConsecutiveMacros: | ||
Enabled: true | ||
AcrossEmptyLines: true | ||
AcrossComments: true | ||
AlignCompound: true | ||
PadOperators: true | ||
AllowAllArgumentsOnNextLine: false | ||
AllowAllParametersOfDeclarationOnNextLine: false | ||
AllowShortBlocksOnASingleLine: Always | ||
AllowShortFunctionsOnASingleLine: All | ||
AlwaysBreakTemplateDeclarations: Yes | ||
BinPackArguments: false | ||
BinPackParameters: false | ||
BraceWrapping: | ||
AfterCaseLabel: true | ||
AfterUnion: true | ||
BeforeLambdaBody: true | ||
BreakBeforeBraces: Allman | ||
ColumnLimit: 80 | ||
IncludeBlocks: Regroup | ||
IncludeCategories: | ||
- Regex: DebugNew.h | ||
Priority: 4 | ||
- Regex: <([A-Za-z0-9\Q/-_\E])+> | ||
Priority: 3 | ||
- Regex: <([A-Za-z0-9.\Q/-_\E])+> | ||
Priority: 2 | ||
- Regex: '"([A-Za-z0-9.\Q/-_\E])+"' | ||
Priority: 1 | ||
IndentPPDirectives: BeforeHash | ||
IndentWidth: 2 | ||
NamespaceIndentation: All | ||
PointerAlignment: Left | ||
QualifierAlignment: Left | ||
SeparateDefinitionBlocks: Always | ||
SpaceAfterCStyleCast: true | ||
SpaceBeforeCpp11BracedList: true | ||
SpacesInContainerLiterals: false | ||
Standard: c++17 | ||
TabWidth: 1 | ||
TypenameMacros: | ||
- TKResourceType | ||
- TKComponentType | ||
- TKDeclareParam |
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,108 @@ | ||
#include "Camera.h" | ||
|
||
#include "RendererUtils.h" | ||
#include "Utils.h" | ||
#include "d3dx12.h" | ||
#include "AppWindow.h" | ||
|
||
using namespace DirectX; | ||
|
||
namespace WoohooDX12 | ||
{ | ||
Camera* m_cam = nullptr; | ||
|
||
Vec3 worldUp(0, 1, 0), reverse(-1.0f, -1.0f, -1.0f); | ||
|
||
Camera::Camera(Vec3 i_target) | ||
{ | ||
target = XMLoadFloat3(&i_target); | ||
XMFLOAT3 initPos = XMFLOAT3(0.0, 0.0, 10.0f); | ||
pos = XMLoadFloat3(&initPos); | ||
rot = XMVECTOR(); | ||
scal = XMVECTOR(); | ||
fov = 45.0f; | ||
} | ||
|
||
// Getters | ||
Mat Camera::CalculateProjMat() | ||
{ | ||
projMat = XMMatrixPerspectiveFovLH(XMConvertToRadians(float(fov)), | ||
float(viewWidth / viewHeight), | ||
nearPlane, | ||
farPlane); | ||
return projMat; | ||
} | ||
|
||
Mat Camera::CalculateViewMat() | ||
{ | ||
XMVECTOR frontVec = XMVectorMultiply(target, XMLoadFloat3(&reverse)); | ||
|
||
viewMat = XMMatrixLookAtLH(pos, | ||
XMVectorAdd(frontVec, pos), | ||
XMLoadFloat3(&worldUp)); | ||
return viewMat; | ||
} | ||
|
||
// Setters | ||
void Camera::SetProperties(unsigned short fov_in_Angle, | ||
float aspect_Width, | ||
float aspect_Height, | ||
float sensitivity) | ||
{ | ||
fov = fov_in_Angle; | ||
viewWidth = aspect_Width; | ||
viewHeight = aspect_Height; | ||
nearPlane = CONST_CAMNEAR; | ||
farPlane = CONST_CAMFAR; | ||
mouseSensitivity = sensitivity; | ||
} | ||
|
||
void Camera::TakeInputs(float mouseOffsetX, float mouseOffsetY) | ||
{ | ||
float multiplier = mouseSensitivity * frameDelta; | ||
mouseYaw += mouseOffsetX * -multiplier; | ||
mousePitch += mouseOffsetY * multiplier; | ||
|
||
// Limit Pitch direction to 90 degrees, because we don't want our camera to | ||
// upside-down! | ||
if (mousePitch > 89.0f) | ||
{ | ||
mousePitch = 89.0f; | ||
} | ||
else if (mousePitch < -89.0f) | ||
{ | ||
mousePitch = -89.0f; | ||
} | ||
|
||
// Set target direction | ||
double radPitch = XMConvertToRadians(mousePitch); | ||
double radYaw = XMConvertToRadians(mouseYaw); | ||
target = XMVectorSet(cos(radPitch) * cos(radYaw), | ||
sin(radPitch), | ||
cos(radPitch) * sin(radYaw), | ||
0.0f); | ||
|
||
XMVECTOR front, right, up; | ||
front = XMVector3Normalize(target); | ||
right = XMVector3Cross(XMVector3Normalize(target), XMLoadFloat3(&worldUp)); | ||
up = XMVectorNegate(XMVector3Normalize(XMVector3Cross(front, right))); | ||
|
||
if (buttonPressed[(int)WhButtons::W]) { | ||
pos -= front * multiplier; | ||
} | ||
if (buttonPressed[(int)WhButtons::S]) { | ||
pos += front * multiplier; | ||
} | ||
if (buttonPressed[(int)WhButtons::D]) { | ||
pos += right * multiplier; | ||
} | ||
if (buttonPressed[(int)WhButtons::A]) { | ||
pos -= right * multiplier; | ||
} | ||
XMFLOAT3 fPos; | ||
XMStoreFloat3(&fPos, pos); | ||
|
||
|
||
CalculateViewMat(); | ||
} | ||
} // namespace WoohooDX12 |
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 @@ | ||
#pragma once | ||
|
||
#include "RendererUtils.h" | ||
|
||
#include <d3d12.h> | ||
|
||
namespace WoohooDX12 | ||
{ | ||
static constexpr double CONST_CAMNEAR = 0.001, CONST_CAMFAR = 10000.0, CONST_MOUSESENSITIVITY = 0.1f; | ||
|
||
class Camera | ||
{ | ||
DirectX::XMVECTOR pos, rot, scal, target; | ||
Mat viewMat, projMat; | ||
// Fov is in angle | ||
unsigned short fov = 45.0f, viewWidth = 1920.0f, viewHeight = 1080.0f; | ||
float nearPlane = CONST_CAMNEAR, farPlane = CONST_CAMFAR, | ||
mouseSensitivity = 0.001f, mouseYaw = 90.0f, mousePitch = 0.0f; | ||
|
||
public: | ||
Camera(Vec3 target = Vec3(0, 0, 1)); | ||
|
||
// Getters | ||
Mat CalculateProjMat(); | ||
Mat CalculateViewMat(); | ||
|
||
// Setters | ||
void SetProperties(unsigned short fov_in_Angle, | ||
float aspect_Width, | ||
float aspect_Height, | ||
float sensitivity); | ||
void TakeInputs(float mouseOffsetX, float mouseOffsetY); | ||
}; | ||
|
||
extern Camera* m_cam; | ||
} // namespace WoohooDX12 |
Oops, something went wrong.