void OrientConstRotation::GetValue(TimeValue t, void *val, Interval &valid, GetSetMethod method)
{
	if (firstTimeFlag) {
		Point3 trans, scaleP;
		Quat quat;
		Matrix3 tempMat(1);
		// CAL-9/26/2002: in absolute mode the value could be un-initialized (random value).
		if (method == CTRL_RELATIVE) tempMat = *(Matrix3*)val;
		DecomposeMatrix(tempMat, trans, quat, scaleP);
		baseRotQuatWorld = baseRotQuatLocal * quat;
		baseRotQuatWorld.Normalize();
		firstTimeFlag = 0;
	}
	if (!ivalid.InInterval(t)) {
		DbgAssert(val != NULL);
		Update(t);
	}
	valid &= ivalid;

			 
	if (method==CTRL_RELATIVE) {
		Interval iv;

		if (IsLocal()){			// From Update, I'm getting target_local_TM in curRot
			Matrix3 *mat = (Matrix3*)val; // this is source_Parent_TM
			Quat q = curRot;			// this is target_local_TM
			PreRotateMatrix(*mat, q);	// source_world_TM = source_Parent_TM * target_local_TM 
		}
		
		else { 		// i.e., WorldToWorld: from Update, I'm getting target_world_TM in curRot
			int ct = pblock->Count(orientation_target_list);;
			if (ct < 1){
				Matrix3 *mat = (Matrix3*)val;
				Quat q = curRot;
				PreRotateMatrix(*mat, q);
			}
			else{
				Matrix3 *mat = (Matrix3*)val; // this is source_Parent_TM
				// CAL-06/24/02: preserve all components and replace with the new orientation.
				AffineParts ap;
				decomp_affine( *mat, &ap );
				ap.q = curRot;				// target world rotation
				comp_affine( ap, *mat );
				// CAL-06/24/02: this only preserve the translation component
				// Point3 tr;
				// tr = mat->GetTrans();
				// mat->IdentityMatrix();
				// Quat q = curRot;			// this is target_world_TM
				// q.MakeMatrix(*mat);
				// mat->SetTrans(tr);
			}
		}
	} 
	else {
		*((Quat*)val) = curRot;
	}
//		RedrawListbox(GetCOREInterface()->GetTime());
}
Пример #2
0
 void Node::SetTransform(const Matrix4& transform)
 {
     DecomposeMatrix(transform, position_, q_, scale_);
     MarkAsDirty(true, true);
 }
Пример #3
0
bool MeshExpUtility::SaveSkinKeys(const char* n){
	CFS_Memory F;

	int FramesPerSecond = GetFrameRate();
	int TicksPerFrame	= GetTicksPerFrame();
	int FirstTick		= ip->GetAnimRange().Start();
	int LastTick		= ip->GetAnimRange().End();

	Point3 v;
	Matrix3 tm;

	// Write signature and version
	char S[MAX_PATH];
	sprintf(S, "KEYEXP 3.0");
	F.Wstring(S);

	INode *node;
	ObjectEntry *Current;

	//-----------------------------------------------------------------------
	// Count bones and report

	int NumBones = 0;
	Current = theObjects->head;
	while(Current)
	{
		/*
		if(Current->entry->type != OBTYPE_BONE)
		{
			Current = Current->next;
			continue;
		}
		*/

		NumBones++;

		Current = Current->next;
	}

	sprintf(S, "Number of Bones = %d", NumBones);
	F.Wstring(S);
	ELog.Msg(mtInformation,S);

	//-----------------------------------------------------------------------
	// Write out necessary data for motion keys

	sprintf(S, "Key Data");
	F.Wstring(S);

	TimeValue t;
	Quat qq;
	Point3 tp, sp;
	INode* parent;
	Matrix3 tmp;

	sprintf(S, "%d %d %d", FirstTick / TicksPerFrame, LastTick / TicksPerFrame, FramesPerSecond);
	F.Wstring(S);

	Current = theObjects->head;
	while(Current){
		/*
		if(Current->entry->type != OBTYPE_BONE)
		{
			Current = Current->next;
			continue;
		}
		*/

		Matrix3 tm;

		node = Current->entry->node;

		sprintf(S, "Node: %s", node->GetName());
		F.Wstring(S);
		ELog.Msg(mtInformation,S);

		// Print notetrack info
		{
			int NumNT, n, i, j, NumNotes;
			NoteTrack* pNT;
			DefNoteTrack* pDNT;
			NoteKey* pNK;

			NumNT = node->NumNoteTracks();

			// count all of the notes on all of the notetracks
			NumNotes = 0;
			for(n=0;n<NumNT;n++){
				pNT = node->GetNoteTrack(n);
				if(pNT->ClassID() == Class_ID(NOTETRACK_CLASS_ID, 0)){
					pDNT = (DefNoteTrack*)pNT;
					j = pDNT->NumKeys();
					for(i=0;i<j;i++){
						pNK = pDNT->keys[i];
						if( (pNK->time >= FirstTick) && (pNK->time <= LastTick) )
							NumNotes++;
					}
				}
			}

			sprintf(S, "Number of Notes = %d", NumNotes);
			F.Wstring(S);

			for(n=0;n<NumNT;n++){
				pNT = node->GetNoteTrack(n);
				if(pNT->ClassID() == Class_ID(NOTETRACK_CLASS_ID, 0)){
					pDNT = (DefNoteTrack*)pNT;
					j = pDNT->NumKeys();
					for(i=0;i<j;i++){
						pNK = pDNT->keys[i];
						if( (pNK->time >= FirstTick) && (pNK->time <= LastTick) ){
							sprintf(S, "%d: %s", (pNK->time - FirstTick) / TicksPerFrame, pNK->note);
							F.Wstring(S);
						}
					}
				}
			}
		}

		for(t=FirstTick;t<=LastTick;t+=TicksPerFrame){
			tm = node->GetNodeTM(t);
			DecomposeMatrix(tm, tp, qq, sp);
			qq.MakeMatrix	(tm);
			tm.SetTrans		(tp);

			parent = node->GetParentNode();
			if(parent){
				tmp = parent->GetNodeTM(t);
				DecomposeMatrix(tmp, tp, qq, sp);
				qq.MakeMatrix(tmp);
				tmp.SetTrans(tp);
				tmp = Inverse(tmp);
				tm *= tmp;
			}

			DecomposeMatrix(tm, tp, qq, sp);
			sprintf(S,"%f %f %f %f",qq.x, qq.y, qq.z, qq.w);
			F.Wstring(S);
			sprintf(S,"%f %f %f",tp.x,tp.y,tp.z);
			F.Wstring(S);

			/*
			// Euler angles
			Point3			E;
			QuatToEuler		(Quat(tm), E);
			fprintf			(f,"%f %f %f",E.x,E.y,E.z);

			// Translate
			DecomposeMatrix	(tm, tp, qq, sp);
			fprintf			(f,"%f %f %f",tp.x,tp.y,tp.z);
			*/

//			Matrix3fprint(f, tm);
		}
		Current = Current->next;
	}

	sprintf(S, "Key Data Complete");
	F.Wstring(S);
	ELog.Msg(mtInformation,S);

	F.SaveTo(n,0);

	return true;
}