/** * @brief * Returns position, rotation and scale from a matrix */ void PLTools::GetPosRotScale(const GMatrix &mTransform, Point3 &vPos, Quat &qRot, Point3 &vScale, bool bFlip) { // Get the position vPos = mTransform.Translation(); // Get the rotation of the node as quaternion qRot = mTransform.Rotation(); // Flip 180 degree around the y-axis? (true for camera and spot lights) if (bFlip) { Quat qRotationOffset; // We have to add a rotation about the x-axis of -90 degree... is this a IGame transform bug or something other odd?? float fAngles[] = {static_cast<float>(HALFPI), 0.0f, 0.0f}; EulerToQuat(fAngles, qRotationOffset); qRot = qRotationOffset*qRot; // We have to 'invert the z-axis', this is no PixelLight bug or so, we decided to do so to make things more universal fAngles[0] = 0.0f; fAngles[2] = static_cast<float>(PI); EulerToQuat(fAngles, qRotationOffset); qRot = qRotationOffset*qRot; } // Look out! We REALLY need to take the parity of the transform matrix into account! vScale = mTransform.Scaling()*static_cast<float>(mTransform.Parity()); }
void MeshExporter::_dumpJoint(IGameNode * node) { IGameObject * obj = node->GetIGameObject(); IGameObject::MaxType T = obj->GetMaxType(); IGameObject::ObjectTypes type = obj->GetIGameType(); const char * name = node->GetName(); switch(type) { case IGameObject::IGAME_BONE: case IGameObject::IGAME_HELPER: { joint * bone = mMeshSource->NewJoint(node->GetName()); int parent = -1; if (node->GetNodeParent()) { parent = _getJointId(node->GetNodeParent()->GetName()); mMeshSource->SetJointLink(parent, mMeshSource->GetJointCount() - 1); } else { INode* pNode = node->GetMaxNode()->GetParentNode(); if (pNode) parent = _getJointId(pNode->GetName()); } IGameControl * pGameControl = node->GetIGameControl(); // base matrix { GMatrix matWorld = node->GetLocalTM(); bone->position = Utility::ToFloat3(matWorld.Translation()); bone->rotation = Utility::ToQuat(matWorld.Rotation()); bone->scale = Utility::ToFloat3(matWorld.Scaling()); /* if (node->GetNodeParent()) { int parentId = _getBoneId(node->GetNodeParent()->GetName()); if (parentId != -1) { xBone * parentBn = GetBone(parentId); bone->position = bone->position - parentBn->position; bone->orientation = parentBn->orientation.Inverse() * bone->orientation; bone->scale = bone->scale / parentBn->scale; } } */ } _dumpAnimation(pGameControl, mMeshSource->GetJointCount() - 1); } break; } }
void Unreal3DExport::WriteTracking() { Tab<Point3> Loc; Tab<Quat> Quat; Tab<Point3> Euler; Loc.SetCount(FrameCount); Quat.SetCount(FrameCount); Euler.SetCount(FrameCount); for( int n=0; n<TrackedNodes.Count(); ++n ) { IGameNode* node = TrackedNodes[n]; for( int t=0; t<FrameCount; ++t ) { // Progress CheckCancel(); // Set frame int curframe = FrameStart + t; pScene->SetStaticFrame(curframe); // Write tracking GMatrix objTM = node->GetWorldTM(); Loc[t] = objTM.Translation(); Quat[t] = objTM.Rotation(); float eu[3]; QuatToEuler(Quat[t],eu); Euler[t]=Point3(eu[0],eu[1],eu[2]); Euler[t] *= 180.0f/pi; eu[1] *= -1; EulerToQuat(eu,Quat[t],EULERTYPE_YXZ); } for( int t=0; t<FrameCount; ++t ) { _ftprintf( fLog, _T("%sLoc[%d]=(X=%f,Y=%f,Z=%f)\n"), node->GetName(), t, Loc[t].x, Loc[t].y, Loc[t].z ); } for( int t=0; t<FrameCount; ++t ) { _ftprintf( fLog, _T("%sQuat[%d]=(W=%f,X=%f,Y=%f,Z=%f)\n"), node->GetName(), t, Quat[t].w, Quat[t].x, Quat[t].y, Quat[t].z ); } for( int t=0; t<FrameCount; ++t ) { _ftprintf( fLog, _T("%sEuler[%d]=(X=%f,Y=%f,Z=%f)\n"), node->GetName(), t, Euler[t].x, Euler[t].y, Euler[t].z ); } } }
void SGMExporter::ExportStaticRot(IGameNode *gNode, BinaryWriter *bw) { /*INode *node = gNode ->GetMaxNode(); assert(node != NULL); Control *tmCtrl = node ->GetTMController(); assert(tmCtrl != NULL); Control *ctrl = tmCtrl ->GetRotationController(); assert(ctrl != NULL); Interval i(0, 0); Quat q; ctrl ->GetValue(0, &q, i, CTRL_ABSOLUTE);*/ GMatrix m = gNode ->GetLocalTM(); AngAxis angAxis(m.Rotation()); bw ->Write(angAxis.angle); bw ->Write(angAxis.axis.x); bw ->Write(angAxis.axis.y); bw ->Write(angAxis.axis.z); }