-
-
Save anonymous/849dd50ba6dc82fc0bc9 to your computer and use it in GitHub Desktop.
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
#include "pch.h" | |
#include "Camera.h" | |
using namespace DirectX; | |
Camera::Camera( ) | |
{ | |
Position( 0.0f, 0.0f, 0.0f ); | |
Direction( 0.0f, 0.0f, 1.0f ); | |
Up( 0.0f, 1.0f, 0.0f ); | |
} | |
void Camera::Position( float x, float y, float z ) | |
{ | |
position = XMVectorSet( x, y, z, 0.0f ); | |
update = true; | |
} | |
void Camera::Translate( float x, float y, float z ) | |
{ | |
XMFLOAT3 p; XMStoreFloat3( &p, position ); | |
Position( p.x + x, p.y + y, p.z + z ); | |
} | |
void Camera::Direction( float x, float y, float z ) | |
{ | |
direction = XMVectorSet( x, y, z, 0.0f ); | |
update = true; | |
} | |
void Camera::Up( float x, float y, float z ) | |
{ | |
up = XMVectorSet( x, y, z, 0.0f ); | |
update = true; | |
} | |
DirectX::XMVECTOR Camera::Position( void ) | |
{ | |
return position; | |
} | |
DirectX::XMVECTOR Camera::Direction( void ) | |
{ | |
return direction; | |
} | |
DirectX::XMVECTOR Camera::Up( void ) | |
{ | |
return up; | |
} | |
DirectX::XMMATRIX Camera::Matrix( void ) | |
{ | |
if ( update ) | |
{ | |
matrix = XMMatrixLookAtLH( position, position + direction, up ); | |
update = false; | |
} | |
return matrix; | |
} |
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
#pragma once | |
class Camera | |
{ | |
public: | |
Camera( ); | |
void Position( float x, float y, float z ); | |
void Translate( float x, float y, float z ); | |
void Direction( float x, float y, float z ); | |
void Rotate( float pitch, float yaw ); | |
void Up( float x, float y, float z ); | |
DirectX::XMVECTOR Position( void ); | |
DirectX::XMVECTOR Direction( void ); | |
DirectX::XMVECTOR Up( void ); | |
DirectX::XMMATRIX Matrix( void ); | |
operator DirectX::XMMATRIX() | |
{ return Matrix(); } | |
protected: | |
DirectX::XMVECTOR position, direction, up; | |
DirectX::XMMATRIX matrix; | |
bool update; | |
float pitch, yaw, roll; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment