secret
anonymous / Camera.cpp
Created

  • Download Gist
Camera.cpp
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
 
#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;
}
Camera.hpp
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#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;
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.