Skip to content

anonymous /Camera.cpp secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#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
Something went wrong with that request. Please try again.