Log in or register to post comments

Add Motion Path

March 16, 2012 - 7:51am #1

Hi,
I just got the rotating on my cube to work. Now I want to add a motion path to my cube. For example, move down from the top to the bottom, then do a curve to the left. Has anyone done something similar or has some tips how to do this?

Then I have a question about starting and stopping animations. I implemented two different UIs to my Android project. One UI with one button appears if an image is tracked. Now I want to add a start animation method to this button. To send the state of my Ui-button to the c++-script is no problem but how can I change the state of the animation of an object. Any Ideas?

Re: Add Motion Path

March 19, 2012 - 7:55am #3

Hi,
finally I made a little motion path.

void
animatePath(QCAR::Matrix44F& modelViewMatrix)
{
//while(checkMovement){
	switch(checkMovementState){
	case moveXAxe:
		if(translateCubeX < 150.0f)
		{
			translateCubeX = translateCubeX + 1.0f;
			SampleUtils::translatePoseMatrix(translateCubeX, -50.0f, 50.0f,&modelViewMatrix.data[0]);
		}else
		{
			winkelX = (CurveX);
			winkelY = (CurveY);
			radX = winkelX * PI / 180;
			radY = winkelY * PI / 180;
		
			CurveYHolder = (float)(1.0f * (sin(radX)));
			CurveXHolder =(float)(1.0f*(1 - (cos(radY))));
		
			translateCubeY = translateCubeY + CurveYHolder;
			translateCubeX = translateCubeX - CurveXHolder;
			LOG("CurveXHolder: %f, CurveYHolder: %f",CurveXHolder, CurveYHolder);
			SampleUtils::translatePoseMatrix(translateCubeX, translateCubeY, 50.0f,&modelViewMatrix.data[0]);
				
			checkMovementState = 2;		
		}
	break;
	case moveCurve:
		if(winkelX < 360)
		{
			winkelX = (CurveX);
			winkelY = (CurveY);
			radX = winkelX * PI / 180;
			radY = winkelY * PI / 180;
		
			CurveYHolder = (float)(1.0f * (sin(radX)));
			CurveXHolder =(float)(1.0f*(1 - (cos(radY))));
		
			translateCubeY = translateCubeY + CurveYHolder;
			translateCubeX = translateCubeX - CurveXHolder;
			LOG("CurveXHolder: %f, CurveYHolder: %f",CurveXHolder, CurveYHolder);
			SampleUtils::translatePoseMatrix(translateCubeX, translateCubeY, 50.0f,&modelViewMatrix.data[0]);
			
			CurveX = CurveX +1.0f;
			CurveY = CurveY +1.0f;	
		}else
		{
			CurveX = 1.0f;
			CurveY = 1.0f;
			winkelX = 0.0f;
				
			winkelX = (CurveX*2);
			winkelY = (CurveY*2);
			radX = winkelX * PI / 180;
			radY = winkelY * PI / 180;
		
			CurveYHolder = (float)(sin(radY) * 2);
			CurveXHolder = (float) (2*cos(radX));
			CurveXHolder = (float) CurveXHolder -2;
		
			translateCubeY = translateCubeY + CurveYHolder;
			translateCubeX = translateCubeX - CurveXHolder;
			LOG("CurveXHolder: %f, CurveYHolder: %f",CurveXHolder, CurveYHolder);
			SampleUtils::translatePoseMatrix(translateCubeX, translateCubeY, 50.0f,&modelViewMatrix.data[0]);
			
			CurveX = CurveX +1.0f;
			CurveY = CurveY +1.0f;
			
			checkMovementState = 3;
			}
	break;
	case moveCurveExperiment:
		if(winkelX < 180)
		{
			winkelX = (CurveX*2);
			winkelY = (CurveY*2);
			radX = winkelX * PI / 180;
			radY = winkelY * PI / 180;
		
			CurveYHolder = (float)(sin(radY) * 2);
			CurveXHolder = (float) (2*cos(radX));
			CurveXHolder = CurveXHolder -2;
		
			translateCubeY = translateCubeY + CurveYHolder;
			translateCubeX = translateCubeX - CurveXHolder;
			LOG("CurveXHolder: %f, CurveYHolder: %f",CurveXHolder, CurveYHolder);
			SampleUtils::translatePoseMatrix(translateCubeX, translateCubeY, 50.0f,&modelViewMatrix.data[0]);
				
			CurveX = CurveX +1.0f;
			CurveY = CurveY +1.0f;
		}else
		{
			translateCubeX = 50.0f;
			translateCubeY = -50.0f;
			
			translateCubeX = translateCubeX + 1.0f;
			SampleUtils::translatePoseMatrix(translateCubeX, -50.0f, 50.0f,&modelViewMatrix.data[0]);
			
			checkMovementState = 1;
			CurveX = 1.0f;
			CurveY = 1.0f;
			}	
	break;
	}	
	//}
}

There are a few things which I don't understand.
The first and second formula are very similar. The first one is from a book and the second one is from me.

One problem are both if-statements. For winkelX I have also no idea where the origin is and what the value of the radius means "((2*cos(radX));". I tested a lot to find a value which fits my screen size.

Greetz

Robert

Re: Add Motion Path

March 17, 2012 - 5:13am #2

Hey guys,
I have now a first result.

void
animatePath(QCAR::Matrix44F& modelViewMatrix)
{
static float translateCubeX = 50.0f;
static float translateCubeY = 0.0f;

//boolean checkMovement = true
//while(checkMovement){

	//static double prevTimeMovement = getCurrentTime();
	//double timeMovement = getCurrentTime();
	//float dtMovement = (float)(timeMovement-prevTimeMovement);
		if(translateCubeX < 150.0f){
			translateCubeX = translateCubeX + 0.1f;
			SampleUtils::translatePoseMatrix(translateCubeX, -50.0f, 50.0f,&modelViewMatrix.data[0]);
			//prevTimeMovement = timeMovement;
		}else{
			translateCubeX = 50.0f;
			//dtMovement = 0.0f;
			checkMovement = false;
		}
	//}
}

With "while(checkMovement){" I want to check if i pressed my start/stop Animation UI Button on top of the AR-View, but at the moment i have not tested this function.

To update the screen-coordinate calculation of my cube i did the following changes to the calculation process

from:
QCAR::Vec2F object = QCAR::Tool::projectPoint(cameraCalibration, trackable->getPose(), QCAR::Vec3F(50, -50, 50));
to:
QCAR::Vec2F object = QCAR::Tool::projectPoint(cameraCalibration, trackable->getPose(), QCAR::Vec3F(translateCubeX, -50, 50));

Maybe it is useful for someone. Anywhere I'm looking forward for other solutions or more complex animations!

Log in or register to post comments