Skip to content

Instantly share code, notes, and snippets.

/Camera.cpp Secret

Created February 15, 2013 18:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/849dd50ba6dc82fc0bc9 to your computer and use it in GitHub Desktop.
#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;
}
#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