Пример #1
0
float MotionGraphController::getValue(CHANNEL_ID _channel, float _time){
	//if it is not transitioning and its time to loop
	if (!status.isTransitioning &&  timeToTransition(_time))
	{
		//iterateStatus();
		int frame3 = computeCurrentFrame(_time);
		MotionSequence *motion_sequence = returnMotionSequenceContainerFromID(status.SeqID).MS;
		if (motion_sequence == NULL)
			throw AnimationException("MotionSequenceController has no attached MotionSequence");

		if (!isValidChannel(_channel, _time))
		{
			string s = string("MotionSequenceController received request for invalid channel ")
				+ " bone: " + toString(_channel.bone_id) + " dof: " + toString(_channel.channel_type);
			throw AnimationException(s.c_str());
		}

//		int frame3 = computeCurrentFrame(_time);
		//set this for currentFrameCalculations
		last_transition_time = _time;
		last_transition_frame = status.FrameNumberTransitionTo;
		// set the frame number to the frame we transition to.
		status.FrameNumber = status.FrameNumberTransitionTo;

	//	int frame3 = computeCurrentFrame(_time);
		float value = motion_sequence->getValue(_channel, computeCurrentFrame(_time));

		//transition the graph using status information
		// only use when we have matching names of Motion sequences are the same as the filenames of the frames on the graph
		// in this case we need to put the vertex descriptor back to its original spot
		//transitionGraph();
		printStatus();
		//update the status
		iterateStatus();
		printStatus();
		return(value);

	}
	else if (status.isTransitioning &&  timeToTransition(_time))
	{
		MotionSequence *motion_sequence = returnMotionSequenceContainerFromID(status.TransitionToSeqId).MS;
		if (motion_sequence == NULL)
			throw AnimationException("MotionSequenceController has no attached MotionSequence");

		if (!isValidChannel(_channel, _time))
		{
			string s = string("MotionSequenceController received request for invalid channel ")
				+ " bone: " + toString(_channel.bone_id) + " dof: " + toString(_channel.channel_type);
			throw AnimationException(s.c_str());
		}
		//set this for currentFrameCalculations
		last_transition_time = _time;
		last_transition_frame = status.FrameNumberTransitionTo;
		// set the frame number to the frame we transition to.
		status.FrameNumber = status.FrameNumberTransitionTo;

		int frame3 = computeCurrentFrame(_time);
		float value = motion_sequence->getValue(_channel, computeCurrentFrame(_time));

		//transition the graph using status information
		// only use when we have matching names of Motion sequences are the same as the filenames of the frames on the graph
		//transitionGraph();
		printStatus();
		//update the status
		iterateStatus();
		printStatus();
		return(value);
	}
	//not at right time to transition
	else{
		MotionSequence *motion_sequence = returnMotionSequenceContainerFromID(status.SeqID).MS;

		if (motion_sequence == NULL)
			throw AnimationException("MotionSequenceController has no attached MotionSequence");

		if (!isValidChannel(_channel, _time))
		{
			string s = string("MotionSequenceController received request for invalid channel ")
				+ " bone: " + toString(_channel.bone_id) + " dof: " + toString(_channel.channel_type);
			throw AnimationException(s.c_str());
		}
		int frame3 = computeCurrentFrame(_time);
		float value = motion_sequence->getValue(_channel, computeCurrentFrame(_time));
		if (frame3 > status.FrameNumber)
		{

			//printStatus();
		}

		//update status
		status.FrameNumber = frame3;

		// only use when we have matching names of Motion sequences are the same as the filenames of the frames on the graph
		//iterate graph
		//iterateMotionGraph();
	
		return(value);
	}
}
Пример #2
0
float MotionSequenceController::getValue(CHANNEL_ID _channel, float _time)
{
	if (motion_sequence == NULL) 
		throw AnimationException("MotionSequenceController has no attached MotionSequence");

	if (!isValidChannel(_channel, _time)) 
	{
		string s = string("MotionSequenceController received request for invalid channel ") 
			+ " bone: " + toString(_channel.bone_id) + " dof: " + toString(_channel.channel_type);
		throw AnimationException(s.c_str());
	}

	float duration = motion_sequence->getDuration();
	long cycles = long(_time / duration);
	
	sequence_time = _time - duration*cycles;
	if (sequence_time > duration) sequence_time = 0.0f;

	int frame = int(motion_sequence->numFrames()*sequence_time/duration);

	float value = motion_sequence->getValue(_channel, frame);

	if (apply_start_offset)
	{
		// modify root based on offsets.
		if (_channel.bone_id == 0)
		{
			if (!frame_is_cached[frame])
			{
				Vector3D frame_position(
					motion_sequence->getValue(CHANNEL_ID(0,CT_TX), frame),
					motion_sequence->getValue(CHANNEL_ID(0,CT_TY), frame),
					motion_sequence->getValue(CHANNEL_ID(0,CT_TZ), frame));
				Vector3D frame_orientation(
					motion_sequence->getValue(CHANNEL_ID(0,CT_RX), frame),
					motion_sequence->getValue(CHANNEL_ID(0,CT_RY), frame),
					motion_sequence->getValue(CHANNEL_ID(0,CT_RZ), frame));

				frame_position = start_offset_combined_transform * frame_position;

				Matrix4x4 orig_orientation_transform = 
					Matrix4x4::rotationRPY(frame_orientation.roll, frame_orientation.pitch, frame_orientation.yaw);
				Matrix4x4 new_orientation_transform = start_offset_rotation_transform*orig_orientation_transform;
				
				float p, y, r;
				// invalid rotation concatenation, Euler angles don't add properly
				p = frame_orientation.pitch + start_offset_rotation.pitch;
				y = frame_orientation.yaw + start_offset_rotation.yaw;
				r = frame_orientation.roll + start_offset_rotation.roll;
				//logout << "Frame " << frame << endl;
				//logout << "\tframe orientation: " << frame_orientation << endl;
				//logout << "\toffset rotation: " << start_offset_rotation << endl;
				frame_orientation = Vector3D(p,y,r);
				//logout << "\tnew orientation: " << frame_orientation << endl;
				
				root_cache.set(frame,0,frame_position.x);
				root_cache.set(frame,1,frame_position.y);
				root_cache.set(frame,2,frame_position.z);
				root_cache.set(frame,3,frame_orientation.pitch);
				root_cache.set(frame,4,frame_orientation.yaw);
				root_cache.set(frame,5,frame_orientation.roll);
				frame_is_cached[frame] = true;
			}
			switch(_channel.channel_type)
			{
			case CT_TX:
				value = root_cache.get(frame,0); break;
			case CT_TY:
				value = root_cache.get(frame,1); break;
			case CT_TZ:
				value = root_cache.get(frame,2); break;
			case CT_RX:
				value = root_cache.get(frame,3); break;
			case CT_RY:
				value = root_cache.get(frame,4); break;
			case CT_RZ:
				value = root_cache.get(frame,5); break;
			default:
				value = 0.0f; break;
			}
		}
	}

	return value;
}