Changeset 120 in flairsrc for trunk/lib/FlairSimulator/src/FixedCamera.cpp
 Timestamp:
 Dec 1, 2016, 4:44:10 PM (5 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/lib/FlairSimulator/src/FixedCamera.cpp
r107 r120 43 43 camera>setPosition(vector3df(ToIrrlichtCoordinates(position))); 44 44 camera>setTarget(vector3df(ToIrrlichtCoordinates(lookat))); 45 target=vector3df(ToIrrlichtCoordinates(lookat)); 46 init=false; 47 rotation=camera>getRotation(); 48 printf("%f %f %f\n",rotation.X,rotation.Y,rotation.Z); 45 49 46 fov=camera>getFOV(); 50 47 } … … 52 49 FixedCamera::~FixedCamera() {} 53 50 54 float FixedCamera::sat(float value) {55 if (value >= 1)56 value = 1;57 if (value <= 179)58 value = 179;59 return value;60 }61 62 51 void FixedCamera::animateNode(ISceneNode *node, u32 timeMs) { 63 52 ICameraSceneNode *camera = static_cast<ICameraSceneNode *>(node); 64 vector3df newRotation=rotation;65 vector3df newTarget=target;66 67 if(init==false) {68 rotation=camera>getRotation();69 printf("%f %f %f\n",rotation.X,rotation.Y,rotation.Z);70 init=true;71 }72 float nRotY = 0;//rotation.Y;73 float nRotZ = rotation.Z;74 53 75 54 if (LMouseKey == true) { … … 77 56 RotateStart = MousePos; 78 57 Rotating = true; 79 //nRotY = rotation.Y; 80 //nRotZ =0;// rotation.Z; 58 target = (camera>getTarget()  camera>getAbsolutePosition()); 81 59 } else { 82 nRotY = (RotateStart.Y  MousePos.Y) * rotateSpeed; 83 nRotZ = (RotateStart.X  MousePos.X) * rotateSpeed; 84 newRotation.rotateXZBy(nRotY); 85 //nRotY = sat(nRotY); 60 float nRotY = (RotateStart.Y  MousePos.Y) * rotateSpeed; 61 float nRotZ = (RotateStart.X  MousePos.X) * rotateSpeed; 86 62 87 //newTarget.rotateXZBy(nRotY,camera>getPosition()); 88 newTarget.rotateXYBy( nRotZ,camera>getPosition()); 89 camera>setTarget(newTarget); 63 //normal between target and up vector 64 cameraAxeY=target.crossProduct(irr::core::vector3df(0,0,1)); 65 cameraAxeY.normalize(); 66 67 //rotation around z axis 68 irr::core::quaternion q1(target.X,target.Y,target.Z,0); 69 irr::core::quaternion q2; 70 q2.fromAngleAxis(nRotZ,vector3df(0,0,1)); 71 irr::core::quaternion q3=q2*q1; 72 q2.makeInverse(); 73 q3=q3*q2; 74 75 //rotation around cameraAxeY 76 q1.set(q3.X,q3.Y,q3.Z,0); 77 q2.fromAngleAxis(nRotY,cameraAxeY); 78 q3=q2*q1; 79 q2.makeInverse(); 80 q3=q3*q2; 81 82 //check angle 83 irr::core::vector3df newTarget(q3.X,q3.Y,q3.Z); 84 float angle=acos(newTarget.dotProduct(irr::core::vector3df(0,0,1))/newTarget.getLength()); 85 irr::core::vector3df cross = newTarget.crossProduct(irr::core::vector3df(0,0,1)); 86 if (cross.dotProduct(cameraAxeY) > 0) { 87 newTarget += camera>getAbsolutePosition(); 88 camera>setTarget(newTarget); 89 } 90 90 } 91 91 } else if (Rotating) { 92 //rotation.Y += (RotateStart.Y  MousePos.Y) * rotateSpeed;93 //rotation.Z += (RotateStart.X  MousePos.X) * rotateSpeed;94 //rotation.Y = sat(rotation.Y);95 //nRotY = rotation.Y;96 //nRotZ = rotation.Z;97 92 Rotating = false; 98 target=camera>getTarget();99 rotation=camera>getRotation();100 printf("%f %f %f\n",rotation.X,rotation.Y,rotation.Z);101 93 } 102 94 95 //handle zoom 103 96 float newFov=fov+currentZoom*zoomSpeed; 104 97 if(newFov>fov) { … … 110 103 currentZoom=1fov/zoomSpeed; 111 104 } 112 113 //newTarget.rotateXZBy(nRotY,camera>getPosition());114 // newTarget.rotateXYBy( nRotZ,camera>getPosition());115 116 //camera>setRotation(vector3df(rotation.X,180nRotY,nRotZ));117 //camera>setRotation(vector3df(rotation.X,nRotY,0));118 //camera>bindTargetAndRotation(true);119 // camera>setRotation(rotation);120 // camera>setTarget(newTarget);121 //rotation=camera>getRotation();122 //printf("%f %f %f\n",rotation.X,rotation.Y,rotation.Z);123 124 105 camera>setFOV(newFov); 125 106 }
Note: See TracChangeset
for help on using the changeset viewer.