Stranded - Snippet 2


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. void UpdateCamera()
  2. {
  3. // set next camera mode when Tab pressed
  4. if(Kb.bp(KB_TAB))
  5. {
  6. View=(View+1)%VIEW_NUM;
  7. }
  8.  
  9.  
  10. // setup the camera
  11. if(Players.elms()) // if we have at least one player
  12. {
  13. // set camera depending on current view mode
  14. switch(View)
  15. {
  16. case VIEW_FPP:
  17. {
  18. OrientP &head=Players[0].cskel.getPoint("head"); // obtain player "head" skeleton point (this was created in Mesh Editor)
  19. Cam.setPosDir(head.pos,head.dir,head.perp); // set camera from 'head' position, direction and perpendicular to direction
  20. }break;
  21.  
  22. default: // VIEW_TPP
  23. {
  24.  
  25.  
  26. if(Ms.b(0)) {
  27. desired_camera.yaw -=Ms.ds.x*3; // update camera yaw angle according to mouse smooth delta x
  28. desired_camera.pitch+=Ms.ds.y*3*Ms.inv(); // update camera pitch angle according to mouse smooth delta y
  29. Clamp(desired_camera.pitch,-PI_2,0); // clamp to possible camera pitch angle
  30. desired_camera.dist=Max(1.0f,desired_camera.dist*ScaleFactor(Ms.wheel()*-0.2)); // update camera distance according to mouse wheel
  31. desired_camera.setSpherical();
  32.  
  33. Ball ball(0.1f, desired_camera.at);
  34.  
  35. Physics.move(ball, desired_camera.matrix.pos-ball.pos);
  36.  
  37. Cam.setPosDir(ball.pos, desired_camera.matrix.z, desired_camera.matrix.y);
  38. //Cam.setSpherical(ball.pos, desired_camera.yaw, desired_camera.pitch, 0, desired_camera.dist); // set spherical camera looking at player using camera angles
  39. }
  40. else {
  41. desired_camera.yaw =Players[0].angle.x; // update camera yaw angle according to mouse smooth delta x
  42. desired_camera.pitch=Players[0].angle.y; // update camera pitch angle according to mouse smooth delta y
  43. Clamp(desired_camera.pitch,-PI_2,PI_4); // clamp to possible camera pitch angle
  44. desired_camera.dist=Max(1.0f,desired_camera.dist*ScaleFactor(Ms.wheel()*-0.2)); // update camera distance according to mouse wheel
  45. //Cam.dist=Max(1.0f,Cam.dist*ScaleFactor(Ms.wheel()*-0.1)); // update camera distance according to mouse wheel
  46. desired_camera.at =Players[0].pos();
  47. desired_camera.setSpherical();
  48.  
  49. Ball ball(0.1f, desired_camera.at);
  50.  
  51. Physics.move(ball, desired_camera.matrix.pos-ball.pos);
  52.  
  53. Cam.setPosDir(ball.pos, desired_camera.matrix.z, desired_camera.matrix.y);
  54. //Cam.setSpherical(Players[0].ctrl_pos+Vec(0,0.5,0), Players[0].angle.x, Players[0].angle.y, 0, desired_camera.matrix.z); // set spherical camera looking at player position with given player angles
  55. //Cam.matrix.setRotateZ(Players[0].angle.);
  56. }
  57.  
  58. }break;
  59. }
  60.  
  61. // after setting camera position and angles:
  62. Cam.updateVelocities().set(); // update camera velocities and activate it
  63. }
  64. else // when no player on the scene
  65. {
  66. CamHandle(0.1,100,CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT)); // default camera handling actions
  67. }
  68.  
  69.  
  70. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.