/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
void UpdateCamera() { // set next camera mode when Tab pressed if(Kb.bp(KB_TAB)) { View=(View+1)%VIEW_NUM; } // setup the camera if(Players.elms()) // if we have at least one player { // set camera depending on current view mode switch(View) { case VIEW_FPP: { OrientP &head=Players[0].cskel.getPoint("head"); // obtain player "head" skeleton point (this was created in Mesh Editor) Cam.setPosDir(head.pos,head.dir,head.perp); // set camera from 'head' position, direction and perpendicular to direction }break; default: // VIEW_TPP { if(Ms.b(0)) { desired_camera.yaw -=Ms.ds.x*3; // update camera yaw angle according to mouse smooth delta x desired_camera.pitch+=Ms.ds.y*3*Ms.inv(); // update camera pitch angle according to mouse smooth delta y Clamp(desired_camera.pitch,-PI_2,0); // clamp to possible camera pitch angle desired_camera.dist=Max(1.0f,desired_camera.dist*ScaleFactor(Ms.wheel()*-0.2)); // update camera distance according to mouse wheel desired_camera.setSpherical(); Ball ball(0.1f, desired_camera.at); Physics.move(ball, desired_camera.matrix.pos-ball.pos); Cam.setPosDir(ball.pos, desired_camera.matrix.z, desired_camera.matrix.y); //Cam.setSpherical(ball.pos, desired_camera.yaw, desired_camera.pitch, 0, desired_camera.dist); // set spherical camera looking at player using camera angles } else { desired_camera.yaw =Players[0].angle.x; // update camera yaw angle according to mouse smooth delta x desired_camera.pitch=Players[0].angle.y; // update camera pitch angle according to mouse smooth delta y Clamp(desired_camera.pitch,-PI_2,PI_4); // clamp to possible camera pitch angle desired_camera.dist=Max(1.0f,desired_camera.dist*ScaleFactor(Ms.wheel()*-0.2)); // update camera distance according to mouse wheel //Cam.dist=Max(1.0f,Cam.dist*ScaleFactor(Ms.wheel()*-0.1)); // update camera distance according to mouse wheel desired_camera.at =Players[0].pos(); desired_camera.setSpherical(); Ball ball(0.1f, desired_camera.at); Physics.move(ball, desired_camera.matrix.pos-ball.pos); Cam.setPosDir(ball.pos, desired_camera.matrix.z, desired_camera.matrix.y); //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 //Cam.matrix.setRotateZ(Players[0].angle.); } }break; } // after setting camera position and angles: Cam.updateVelocities().set(); // update camera velocities and activate it } else // when no player on the scene { CamHandle(0.1,100,CAMH_ZOOM|(Ms.b(1)?CAMH_MOVE:CAMH_ROT)); // default camera handling actions } }