void AnimalThirdPersonControler::orient(int i_xRel, int i_yRel, double i_timeSinceLastFrame) { if (!(m_pAnimal != nullptr && m_pCamera != nullptr)) return; Ogre::Vector3 camPos = m_pCamera->getPosition(); Ogre::Radian angleX(i_xRel * -m_camAngularSpeed); Ogre::Radian angleY(i_yRel * -m_camAngularSpeed); Ogre::Vector3 avatarToCamera = m_pCamera->getPosition() - m_pAnimal->m_pNode->getPosition(); // restore lenght if (avatarToCamera.length() != m_camDistance) avatarToCamera = avatarToCamera.normalisedCopy() * m_camDistance; // Do not go to the poles Ogre::Radian latitude = m_pAnimal->m_pNode->getOrientation().zAxis().angleBetween(avatarToCamera); if (latitude < Ogre::Radian(Ogre::Math::DegreesToRadians(10.f)) && angleY < Ogre::Radian(0.f)) angleY = Ogre::Radian(0.f); else if (latitude > Ogre::Radian(Ogre::Math::DegreesToRadians(170.f)) && angleY > Ogre::Radian(0.f)) angleY = Ogre::Radian(0.f); Ogre::Quaternion orient = Ogre::Quaternion(angleY, m_pCamera->getOrientation().xAxis()) * Ogre::Quaternion(angleX, m_pCamera->getOrientation().yAxis()); Ogre::Vector3 newAvatarToCamera = orient * avatarToCamera; // Move camera closer if collides with terrain m_collideCamWithTerrain(newAvatarToCamera); }
void AsemanSensors::refresh() { p->r_vector.x = p->pr_vector.x; p->r_vector.y = p->pr_vector.y; p->r_vector.z = p->pr_vector.z; p->a_vector = rebase(p->pa_vector); p->g_vector = rebase(p->pg_vector); return; const AsemanSensorsResItem & resX0 = analizeItem(p->a_vector.x,p->a_vector.y,p->a_vector.z,false); const AsemanSensorsResItem & resY0 = analizeItem(p->a_vector.y,p->a_vector.x,p->a_vector.z,false); const AsemanSensorsResItem & resX1 = analizeItem(p->a_vector.x,p->a_vector.y,p->a_vector.z,true); const AsemanSensorsResItem & resY1 = analizeItem(p->a_vector.y,p->a_vector.x,p->a_vector.z,true); AsemanSensorsResItem resX; if( qAbs(qAbs(90-resX0.beta*180/M_PI)-qAbs(angleY())) < qAbs(qAbs(90-resX1.beta*180/M_PI)-qAbs(angleY())) ) resX = resX0; else resX = resX1; AsemanSensorsResItem resY; if( qAbs(qAbs(90-resY0.beta*180/M_PI)-qAbs(angleX())) < qAbs(qAbs(90-resY1.beta*180/M_PI)-qAbs(angleX())) ) resY = resY0; else resY = resY1; int rvector_x_sign = angleX()<0? -1 : 1; int rvector_y_sign = angleY()<0? -1 : 1; p->r_vector.x = rvector_x_sign*(M_PI/2-resY.beta)*180/M_PI + p->zeroX*M_PI/180; p->r_vector.y = rvector_y_sign*(M_PI/2-resX.beta)*180/M_PI + p->zeroY*M_PI/180; p->a_vector.x = resX.newX; p->a_vector.y = resY.newX; }