Changeset 120 in flair-src for trunk/lib


Ignore:
Timestamp:
Dec 1, 2016, 4:44:10 PM (8 years ago)
Author:
Sanahuja Guillaume
Message:

working fixed cameras

Location:
trunk/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/CMakeLists.txt

    r45 r120  
    1919
    2020FILE(GLOB FLAIRCORE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
    21 message(${CMAKE_C_COMPILER})
     21
    2222INCLUDE_DIRECTORIES(
    2323        ${LIBXML2_INCLUDE_DIR}
  • trunk/lib/FlairSimulator/src/FixedCamera.cpp

    r107 r120  
    4343  camera->setPosition(vector3df(ToIrrlichtCoordinates(position)));
    4444  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
    4946  fov=camera->getFOV();
    5047}
     
    5249FixedCamera::~FixedCamera() {}
    5350
    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 
    6251void FixedCamera::animateNode(ISceneNode *node, u32 timeMs) {
    6352  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;
    7453
    7554  if (LMouseKey == true) {
     
    7756      RotateStart = MousePos;
    7857      Rotating = true;
    79       //nRotY = rotation.Y;
    80       //nRotZ =0;// rotation.Z;
     58      target = (camera->getTarget() - camera->getAbsolutePosition());
    8159    } 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;
    8662
    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      }
    9090    }
    9191  } 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;
    9792    Rotating = false;
    98     target=camera->getTarget();
    99     rotation=camera->getRotation();
    100   printf("%f %f %f\n",rotation.X,rotation.Y,rotation.Z);
    10193  }
    10294
     95  //handle zoom
    10396  float newFov=fov+currentZoom*zoomSpeed;
    10497  if(newFov>fov) {
     
    110103    currentZoom=1-fov/zoomSpeed;
    111104  }
    112 
    113 //newTarget.rotateXZBy(-nRotY,camera->getPosition());
    114 //  newTarget.rotateXYBy( nRotZ,camera->getPosition());
    115 
    116   //camera->setRotation(vector3df(rotation.X,-180-nRotY,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 
    124105  camera->setFOV(newFov);
    125106}
  • trunk/lib/FlairSimulator/src/FixedCamera.h

    r107 r120  
    2626class FixedCamera : public VisualizationCamera {
    2727public:
    28   FixedCamera(std::string name,core::Vector3D position,core::Vector3D lookat=core::Vector3D(0,0,0),float rotateSpeed = -500.0f, float zoomSpeed = .05f);
     28  FixedCamera(std::string name,core::Vector3D position,core::Vector3D lookat=core::Vector3D(0,0,0),float rotateSpeed = -3.0f, float zoomSpeed = .05f);
    2929  ~FixedCamera();
    3030
     
    3232
    3333private:
    34   float sat(float value);
    3534  irr::core::position2df RotateStart;
    36   irr::core::vector3df rotation,target;
    3735  bool Rotating;
    3836  float rotateSpeed;
    3937  float zoomSpeed;
    4038  float fov;
    41   bool init;
     39  irr::core::vector3df target,cameraAxeY;
    4240};
    4341
Note: See TracChangeset for help on using the changeset viewer.