/** Create or adjust "rot" parameter for a component * Assumed that name either equals "rotx", "roty" or "rotz" otherwise this * method will not add/modify "rot" parameter * @param comp :: Component * @param name :: Parameter name * @param deg :: Parameter value in degrees * @param pDescription :: a pointer (may be NULL) to a string, containing * parameter's * description. If provided, the contents of the string is copied to the * parameter's * memory */ void ParameterMap::addRotationParam(const IComponent *comp, const std::string &name, const double deg, const std::string *const pDescription) { Parameter_sptr paramRotX = get(comp, rotx()); Parameter_sptr paramRotY = get(comp, roty()); Parameter_sptr paramRotZ = get(comp, rotz()); double rotX, rotY, rotZ; if (paramRotX) rotX = paramRotX->value<double>(); else rotX = 0.0; if (paramRotY) rotY = paramRotY->value<double>(); else rotY = 0.0; if (paramRotZ) rotZ = paramRotZ->value<double>(); else rotZ = 0.0; // adjust rotation Quat quat; if (name.compare(rotx()) == 0) { addDouble(comp, rotx(), deg); quat = Quat(deg, V3D(1, 0, 0)) * Quat(rotY, V3D(0, 1, 0)) * Quat(rotZ, V3D(0, 0, 1)); } else if (name.compare(roty()) == 0) { addDouble(comp, roty(), deg); quat = Quat(rotX, V3D(1, 0, 0)) * Quat(deg, V3D(0, 1, 0)) * Quat(rotZ, V3D(0, 0, 1)); } else if (name.compare(rotz()) == 0) { addDouble(comp, rotz(), deg); quat = Quat(rotX, V3D(1, 0, 0)) * Quat(rotY, V3D(0, 1, 0)) * Quat(deg, V3D(0, 0, 1)); } else { g_log.warning() << "addRotationParam() called with unrecognized coordinate symbol: " << name; return; } // clear the position cache clearPositionSensitiveCaches(); // finally add or update "pos" parameter addQuat(comp, rot(), quat, pDescription); }
void ArcBall::setView( int view ) { m_zoom = 1.0; m_moveX = 0; m_moveY = 0; m_oldMoveX = 0; m_oldMoveY = 0; m_currentRot.setToIdentity(); m_lastRot.setToIdentity(); QQuaternion rotx( sqrt(0.5), 0, 0, sqrt(0.5) ); QQuaternion rot_x( -sqrt(0.5), 0, 0, sqrt(0.5) ); QQuaternion roty( 0, sqrt(0.5), 0, sqrt(0.5) ); QQuaternion rot_y( 0, -sqrt(0.5), 0, sqrt(0.5) ); QQuaternion rotz( 0, 0, sqrt(0.5), sqrt(0.5) ); if ( view == 2 ) { m_currentRot.rotate( rotz ); m_currentRot.rotate( rotx ); m_currentRot.rotate( rotx ); } if ( view == 3 ) { m_currentRot.rotate( rot_x ); m_currentRot.rotate( rot_y ); } }
//rotate void rotate(float rx, float ry, float rz){ Matrix4f rotx, roty, rotz; rotx = Matrix4f::Identity(); roty = Matrix4f::Identity(); rotz = Matrix4f::Identity(); float cosrx, sinrx, cosry, sinry, cosrz, sinrz; cosrx = cosf(rx); sinrx = sinf(rx); cosry = cosf(ry); sinry = sinf(ry); cosrz = cosf(rz); sinrz = sinf(rz); rotx(1,1) = cosrx; rotx(1,2) = -sinrx; rotx(2,1) = sinrx; rotx(2,2) = cosrx; roty(0,0) = cosry; roty(2,0) = -sinry; roty(0,2) = sinry; roty(2,2) = cosry; rotz(0,0) = cosrz; rotz(0,1) = -sinrz; rotz(1,0) = sinrz; rotz(1,1) = cosrz; model_view.top() *= (rotx * roty * rotz); }
void wxOgre::OnMouseMotion(wxMouseEvent& event) { static float speed = 0.0f; static bool dragStart = true; static const wxString posInfo(wxT("Pos:X:%03d, Y:%03d Change X:%03d Y:%03d")); static Ogre::Quaternion startRot(Ogre::Quaternion::IDENTITY); Ogre::LogManager* logMgr = Ogre::LogManager::getSingletonPtr(); Ogre::Log* log(logMgr->getDefaultLog()); int left, top, width, height; mCamera->getViewport()->getActualDimensions(left, top, width, height); wxPoint pos = event.GetPosition(); wxPoint change = pos - mPrevPos; Ogre::Vector2 changeNorm((Ogre::Real) change.x / (Ogre::Real) width, (Ogre::Real) -change.y / (Ogre::Real) height); if ((!dragStart) && ((!event.Dragging()) || (!event.LeftIsDown()))) { wxString msg(wxT("Drag End")); log->logMessage(Ogre::String(msg.mb_str(wxConvUTF8))); dragStart = true; } if(event.Dragging()) { if (event.LeftIsDown()) { if (mTarget) { Ogre::Vector3 objectCentre(mTarget == NULL ? Ogre::Vector3::ZERO : mTarget->getPosition()); if (dragStart) { Ogre::Vector3 cam2Object(mCameraNode->getPosition() - objectCentre); mDirection = cam2Object.normalisedCopy(); mRadius = cam2Object.length(); mChangePos = Ogre::Vector2::ZERO; dragStart = false; wxString msg(wxT("Drag Start")); log->logMessage(Ogre::String(msg.mb_str(wxConvUTF8))); } else { Ogre::Vector3 across; Ogre::Vector3 up; Ogre::Vector3 forward; mCamera->getRealOrientation().ToAxes(across, up, forward); mChangePos += changeNorm; Ogre::Quaternion roty(Ogre::Radian(mChangePos.y * Ogre::Math::PI / 12.0f), across); Ogre::Quaternion rotx(Ogre::Radian(mChangePos.x * Ogre::Math::PI / 12.0f), up); Ogre::Quaternion rot(roty * rotx); rot.normalise(); mCameraNode->setPosition(objectCentre + ((rot * mDirection) * mRadius)); mCamera->lookAt(objectCentre); } } } else if(event.MiddleIsDown()) { int left, top, width, height; mCamera->getViewport()->getActualDimensions(left, top, width, height); float speed = 1.0f; if (event.ShiftDown()) speed = 0.1f; if (event.ControlDown()) speed = 10.0f; float moveX = ((float)-change.x / (float)width) * mZoomScale * speed; float moveY = ((float)change.y / (float)height) * mZoomScale * speed; Ogre::Vector3 delta(mCamera->getRealOrientation().xAxis() * moveX); delta += mCamera->getRealOrientation().yAxis() * moveY; mCamera->setPosition(mCamera->getRealPosition() + delta); } } mPrevPos = pos; }
Matrix4D RotateY(float theta) { Matrix4D roty(cos(theta), 0, sin(theta), 0, 0, 1, 0, 0, -sin(theta),0, cos(theta), 0, 0, 0, 0, 1); return roty; }
void GsMat::roty ( float radians, char fmt ) { roty ( sinf(radians), cosf(radians), fmt ); }