
gluLookAt
By:
spacechase0 on
Nov 6th, 2011 | syntax:
C++ | size: 0.82 KB | hits: 36 | expires: Never
class Camera
{
public:
Camera()
: pos( 0, 0, 5 ),
dir( 0, 0, -1 ),
up( 0, 1, 0 )
{
}
sf::Vector3f pos;
sf::Vector3f dir;
sf::Vector3f up;
void Display()
{
gluLookAt( pos.x, pos.y, pos.z,
pos.x + dir.x, pos.y + dir.y, pos.z + dir.z,
up.x, up.y, up.z );
}
};
// Update
{
// I know this should be a seperate function, but it was easier to just put it here. :P
#define Distance(a,b) std::sqrt( std::pow( b.x - a.x, 2 ) + std::pow( b.y - a.y, 2 ) + std::pow( b.z - a.z, 2 ) )
float speed = 1;
sf::Vector3f amount( cam.dir.x * speed, cam.dir.y * speed, cam.dir.z * speed );
if ( sf::Keyboard::IsKeyPressed( sf::Keyboard::W ) )
{
cam.pos += amount;
}
if ( sf::Keyboard::IsKeyPressed( sf::Keyboard::S ) )
{
cam.pos -= amount;
}
}