void GearsMeshBuilder::rotate( scalar rotX,scalar rotY,scalar rotZ ) { Matrix3 mat; mat.FromEulerAnglesXYZ(Radian(rotX),Radian(rotY),Radian(rotZ)); Quaternion quat(mat); { MeshSkeletonVector::Iterator i; for (i=mMySkeletons.Begin(); i!=mMySkeletons.End(); ++i) { MeshSkeleton *ms = (*i); for (int32 j=0; j<ms->mBoneCount; j++) { MeshBone &b = ms->mBones[j]; if ( b.mParentIndex == -1 ) { b.mPosition = quat * b.mPosition; b.mOrientation = quat * b.mOrientation; } } } } { GearMeshVector::Iterator i; for (i=mMyMeshes.Begin(); i!=mMyMeshes.End(); ++i) { GearMesh *m = (*i); uint32 vcount = m->mVertexPool.GetSize(); if ( vcount > 0 ) { MeshVertex *vb = m->mVertexPool.GetBuffer(); for (uint32 j=0; j<vcount; j++) { vb->mPos = quat * vb->mPos; vb++; } } } } { MeshAnimationVector::Iterator i; for (i=mMyAnimations.Begin(); i!=mMyAnimations.End(); ++i) { MeshAnimation *ma = (*i); for (int32 j=0; j<ma->mTrackCount && j <1; j++) { MeshAnimTrack *t = ma->mTracks[j]; for (int32 k=0; k<t->mFrameCount; k++) { MeshAnimPose &p = t->mPose[k]; p.mPos = quat * p.mPos; p.mQuat = quat * p.mQuat; } } } } }
Ogre::Quaternion VirtualModelMotionGenerator::getTargetOrientationForBody( const std::string& bodyName ) { string targetName = getTargetOrientationNameForBodyName(bodyName); Ogre::Vector3 rot = mMotions[mCurrentMotionIndex].getTargetAtTime( targetName, mPhi ); Matrix3 rotMat; rotMat.FromEulerAnglesXYZ( Radian(rot.x), Radian(rot.y), Radian(rot.z) ); return Quaternion(rotMat); }
//---------------------------------------------------------------------------- // Quaternion Quaternion StringConv::quaternionFromString(const String& _str, size_t _start, size_t& _readcount) { Vector3 vec = fromString<Vector3>(_str, _start, _readcount); if(!_readcount) return Quaternion::ZERO; Radian xAngle(Degree(vec.x)); Radian yAngle(Degree(vec.y)); Radian zAngle(Degree(vec.z)); Matrix3 mat; mat.FromEulerAnglesXYZ(xAngle, yAngle, zAngle); Quaternion q(mat); return q; }
void tyrBarrShape::chainTransformVertices(std::vector<tdio_library::Vector3> *vtx){ vtxTransform.clear(); Vector3 min = _ply.GetMin(); Vector3 max = _ply.GetMax(); Vector3 range = max - min; for(int i = 0; i < vtx->size(); i++){ Vector3 p = (*vtx)[i]; double offset = p.y - min.y; offset /= (max.y-min.y); Matrix3 mat; mat.FromEulerAnglesXYZ(0,_twistAngle * offset,0); Vector3 p2 = mat * p; vtxTransform.push_back(p2); //Vector3 P = getGlobalVertice(vtxParam[i],S,T,U); //vtxTransform.push_back(P); } }
void tyrBarrShape::transformVertices(){ vtxTransform.clear(); point3D_t *vtx = _ply.GetVertices(); int nVtx = _ply.GetNumVertices(); Vector3 min = _ply.GetMin(); Vector3 max = _ply.GetMax(); Vector3 range = max - min; for(int i = 0; i < nVtx; i++){ Vector3 p = vtx[i]; double offset = p.y - min.y; offset /= (max.y-min.y); Matrix3 mat; mat.FromEulerAnglesXYZ(0,_twistAngle * offset,0); Vector3 p2 = mat * p; vtxTransform.push_back(p2); } }
Quaternion OgreMaxUtilities::LoadRotation(const TiXmlElement* objectElement) { Quaternion rotation = Quaternion::IDENTITY; if (objectElement->Attribute("qx") != 0) { //The rotation is specified as a quaternion rotation.x = GetRealAttribute(objectElement, "qx", 0); rotation.y = GetRealAttribute(objectElement, "qy", 0); rotation.z = GetRealAttribute(objectElement, "qz", 0); rotation.w = GetRealAttribute(objectElement, "qw", 0); } else if (objectElement->Attribute("axisX") != 0) { //The rotation is specified as an axis and angle Real angle = GetRealAttribute(objectElement, "angle", 0); Vector3 axis; axis.x = GetRealAttribute(objectElement, "axisX", 0); axis.y = GetRealAttribute(objectElement, "axisY", 0); axis.z = GetRealAttribute(objectElement, "axisZ", 0); //Convert the angle and axis into the rotation quaternion rotation.FromAngleAxis(Radian(angle), axis); } else if (objectElement->Attribute("angleX") != 0) { //Assume the rotation is specified as three Euler angles Vector3 euler; euler.x = GetRealAttribute(objectElement, "angleX", 0); euler.y = GetRealAttribute(objectElement, "angleY", 0); euler.z = GetRealAttribute(objectElement, "angleZ", 0); String order = GetStringAttribute(objectElement, "order"); //Convert Euler angles to a matrix Matrix3 rotationMatrix; if (order.length() < 2) rotationMatrix.FromEulerAnglesXYZ(Radian(euler.x), Radian(euler.y), Radian(euler.z)); else { if (order[0] == 'x') { if (order[1] == 'y') rotationMatrix.FromEulerAnglesXYZ(Radian(euler.x), Radian(euler.y), Radian(euler.z)); else rotationMatrix.FromEulerAnglesXZY(Radian(euler.x), Radian(euler.y), Radian(euler.z)); } else if (order[0] == 'y') { if (order[1] == 'x') rotationMatrix.FromEulerAnglesYXZ(Radian(euler.x), Radian(euler.y), Radian(euler.z)); else rotationMatrix.FromEulerAnglesYZX(Radian(euler.x), Radian(euler.y), Radian(euler.z)); } else { if (order[1] == 'x') rotationMatrix.FromEulerAnglesZXY(Radian(euler.x), Radian(euler.y), Radian(euler.z)); else rotationMatrix.FromEulerAnglesZYX(Radian(euler.x), Radian(euler.y), Radian(euler.z)); } } //Convert the matrix into the rotation quaternion rotation.FromRotationMatrix(rotationMatrix); } return rotation; }