Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. void IrrSetCamera (irr::scene::ICameraSceneNode* camera,
  2.                               float rotx, float roty, float rotz,
  3.                               float x, float y , float z) {
  4.  
  5.  quaternion tempQuaternion;
  6.  
  7.  // Work out the 3 axes for the camera:
  8.  // Forward = target (0,0,0) - position -- the position at (x=0, y=0) is (0,0,1).
  9.  // Right = -1 * cross-product of up.
  10.  // Pos = -forward + x * right + y * up.
  11.  vector3df up(0,1,0);
  12.  vector3df forward(0,0,-1);
  13.  vector3df pos(x,y,1);
  14.  
  15.  tempQuaternion.fromAngleAxis(rotz, forward);
  16.  tempQuaternion.getMatrix().rotateVect(up);
  17.  
  18.  tempQuaternion.fromAngleAxis(rotx, up);
  19.  tempQuaternion.getMatrix().rotateVect(forward);
  20.  
  21.  vector3df right = forward.crossProduct (up);
  22.  tempQuaternion.fromAngleAxis(roty, right);
  23.  tempQuaternion.getMatrix().rotateVect(forward);
  24.  tempQuaternion.getMatrix().rotateVect(up);
  25.  
  26.  pos = pos + z * forward;
  27.  camera->setUpVector (up);
  28.  camera->setTarget (pos + forward);
  29.  camera->setPosition (pos);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement