Don't like ads? PRO users don't see any ads ;-)
Guest

gluLookAt

By: spacechase0 on Nov 6th, 2011  |  syntax: C++  |  size: 0.82 KB  |  hits: 36  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class Camera
  2. {
  3.         public:
  4.                 Camera()
  5.                    : pos( 0, 0, 5 ),
  6.                      dir( 0, 0, -1 ),
  7.                      up( 0, 1, 0 )
  8.                 {
  9.                 }
  10.                
  11.                 sf::Vector3f pos;
  12.                 sf::Vector3f dir;
  13.                 sf::Vector3f up;
  14.                
  15.                 void Display()
  16.                 {
  17.                         gluLookAt( pos.x, pos.y, pos.z,
  18.                                            pos.x + dir.x, pos.y + dir.y, pos.z + dir.z,
  19.                                            up.x, up.y, up.z );
  20.                 }
  21. };
  22.  
  23. // Update
  24. {
  25.         // I know this should be a seperate function, but it was easier to just put it here. :P
  26.         #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 ) )
  27.        
  28.         float speed = 1;
  29.         sf::Vector3f amount( cam.dir.x * speed, cam.dir.y * speed, cam.dir.z * speed );
  30.        
  31.         if ( sf::Keyboard::IsKeyPressed( sf::Keyboard::W ) )
  32.         {
  33.                 cam.pos += amount;
  34.         }
  35.         if ( sf::Keyboard::IsKeyPressed( sf::Keyboard::S ) )
  36.         {
  37.                 cam.pos -= amount;
  38.         }
  39. }
  40.