Log in or register to post comments

Object Animations

May 24, 2011 - 8:57am #1

I want my object rotate continuously when my object appear, how i can to do that??

- Gyan

Re: Object Animations

June 7, 2011 - 2:48am #20
Quote:

Transformation happens from bottom to top.

Oh thanks! It works now! :)

Re: Object Animations

June 6, 2011 - 11:23am #19

Hello.

It looks like you are performing the translate before the rotate. Transformation happens from bottom to top. Try applying the scale first, then rotation (contained in your animateBanana method), and then the translation.

I think this should do what you are looking for:

	SampleUtils::translatePoseMatrix(0.0f, -0.50f*120.0f, -1.55f*120.0f,
                                         &modelViewMatrix.data[0]);
        animateBanana(modelViewMatrix);
        SampleUtils::scalePoseMatrix(kBananaScale, kBananaScale, kBananaScale,
                                     &modelViewMatrix.data[0]);
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                    &modelViewMatrix.data[0],
                                    &modelViewProjection.data[0]

-Peter

Re: Object Animations

June 6, 2011 - 8:01am #18

I almost have the same kind of problem.

In multiTargets, I put a banana near the box, and I would like it to spin around itself. But whatever I do, it's always the same reult : the banana rotates around the y-axis of the box!

Here's my code in .cpp file (i did not use the angle based on time at the moment) :

// DRAW THE OBJECT 3 : THE BANANA
        modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());  

	// animation 
	animateBanana(modelViewMatrix);

	//size, rotation,...       
	//SampleUtils::rotatePoseMatrix(-90.0f, 0, 1.0f, 0,
                                      //&modelViewMatrix.data[0]); 
	SampleUtils::translatePoseMatrix(0.0f, -0.50f*120.0f, -1.55f*120.0f,
                                         &modelViewMatrix.data[0]);
        SampleUtils::scalePoseMatrix(kBananaScale, kBananaScale, kBananaScale,
                                     &modelViewMatrix.data[0]);
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                    &modelViewMatrix.data[0],
                                    &modelViewProjection.data[0]


/*
 * some code...
*/


void
animateBanana(QCAR::Matrix44F& modelViewMatrix)
{
	if (rotatedBanana == 360) {
		rotatedBanana = 0;
	}

	rotatedBanana = rotatedBanana + 1;

    SampleUtils::rotatePoseMatrix(rotatedBanana, 0.0f, 1.0f, 0.0f,
                                  &modelViewMatrix.data[0]);
}

Re: Object Animations

June 5, 2011 - 3:21pm #17

The transforms happen in a particular order, in this case from bottom to top. In the original code, the scale happens first, followed by the rotate, followed by the translate. With your code, you're performing the translate before the rotate. You probably want to swap the order:

translatePoseMatrix()
animateBowl()
scalePoseMatrix()

- Kim

Re: Object Animations

June 3, 2011 - 8:02am #16

here my full code:

i added this into imagetargets.cpp

double
getCurrentTime()
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
    double t = tv.tv_sec + tv.tv_usec/1000000.0;
    return t;
}

void
animateBowl(QCAR::Matrix44F& modelViewMatrix)
{
	static float angle = 0.0f;

	static double prevTime = getCurrentTime();
	double time = getCurrentTime();             // Get real time difference
	float dt = (float)(time-prevTime);          // from frame to frame

	angle += dt * 180.0f/3.1415f;

	SampleUtils::rotatePoseMatrix(angle, 0.0f, 1.0f, 0.0f,
	                                  &modelViewMatrix.data[0]);

    prevTime = time;
}

in my renderframe method :

//some codes here//

animateBowl(modelViewMatrix);
                       SampleUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale,
                                                        &modelViewMatrix.data[0]);
                       //SampleUtils::rotatePoseMatrix(90.0f, 1.0f, 0, 0,
                                                            //&modelViewMatrix.data[0]);
                       SampleUtils::scalePoseMatrix(25.f, 25.f, 25.f,
                                                    &modelViewMatrix.data[0]);
                       SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                                   &modelViewMatrix.data[0] ,
                                                   &modelViewProjection.data[0]);

//some codes here//

when is start the app, it works perfectly, my object rotate along the Y axis..

but when i change my object coordinates :

 SampleUtils::translatePoseMatrix(10.0f, 10.0f, kObjectScale,
                                                        &modelViewMatrix.data[0]);

my objects not rotate, but it moving around the Y axis..why does that happen??

Re: Object Animations

June 3, 2011 - 7:47am #15

Sorry, this isn't enough information for me to work with. That code just applies a single translation to the object, it doesn't animate it per frame.

- Kim

Re: Object Animations

June 3, 2011 - 6:36am #14

Kim, i try to translate the object :

SampleUtils::translatePoseMatrix(10.0f, 10.0f, 3.0f,
                                                        &modelViewMatrix.data[0]);

when i start the app, my object animate in different ways..it not rotate, it just moving in circle..why is that happen??i just want my object to rotate, not moving like that..

Re: Object Animations

June 2, 2011 - 11:21am #13

Animating based on time is key to game/graphics development. The problem is that the framerate isn't constant, either on a single device or across devices. You may come up with an animation that looks right on one device running at 20 frames per second, but runs too quickly on a device running at 30 fps. That's why we take the amount of time that has passed since the last frame into consideration, the passage of time at least is constant :)

In the case of an angle, think of it in terms of degrees per second.

- Kim

Re: Object Animations

June 2, 2011 - 9:00am #12
ksiva wrote:
angle += dt * 180.0f/3.1415f;               // Animate angle based on time

- Kim

I just don't get how it is possible to create an angle based on time ? :confused:

Is it not easier to put a constant, for instance
increment = 1;
and write instead
angle += increment;

:confused:

Re: Object Animations

May 30, 2011 - 6:27am #11

Ok..i'll try..thanks Kim

Regards,

Gyan

Re: Object Animations

May 30, 2011 - 5:58am #10

The .obj format does not include animation information, only the static model. You're going to want to find a rendering library for OpenGL ES that can load and render animated model formats (e.g collada, fbx). Look around for an Android game engine that you can integrate with QCAR. It isn't going to be trivial, which is why the Unity extension is a good option for getting up and running quickly.

- Kim

Re: Object Animations

May 29, 2011 - 3:51am #9

Thanks Kim, i finally made my object rotate like bowl in multitargets..

next problem i have, i make an animations on my objects in blender..i export it into .obj and include it into imagetargets.cpp..but when i start the imagetargets app in my device,,it only shows stand still object..i read the previous post which have similiar problems with me :

http://ar.qualcomm.at/node/2000327

but i dont understand about how to use the model loader ( android-gl ) ..can you help me kim??i want to use unity to load my object, but my devices not currently supported by unity..

Re: Object Animations

May 27, 2011 - 11:04am #8

1) Copy the getCurrentTime() method from the MultiTargets sample.
2) Add #include to your cpp file.
3) Use something like the following to get the angle over time:

static float angle = 0.0f;

static double prevTime = getCurrentTime();
double time = getCurrentTime();             // Get real time difference
float dt = (float)(time-prevTime);          // from frame to frame

angle += dt * 180.0f/3.1415f;               // Animate angle based on time

- Kim

Re: Object Animations

May 27, 2011 - 8:50am #7

yeah, i search about it and i finally can rotate my object in imagetargets..but i want to rotate my object continuosuly like bowl in multitargets..can you help me kim??i use animatebowl like you said, but it give me error while i build with cygwin..

Re: Object Animations

May 27, 2011 - 7:48am #6

You'll want to use glRotate:

http://www.khronos.org/opengles/sdk/1.1/docs/man/glRotate.xml

glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(modelViewMatrix.data);
glTranslatef(0.f, 0.f, kObjectScale);
glScalef(kObjectScale, kObjectScale, kObjectScale);
glRotatef(angle, 0.0f, 0.0f, 1.0f);

- Kim

Re: Object Animations

May 27, 2011 - 7:36am #5

robertross..i am using opengl_es_1_1 , the code you give to me use opengl_es_2_0 right??please can you give me sample code to rotate my object continuously use opengl_es_1_1??

regards,

Gyan

Re: Object Animations

May 27, 2011 - 1:58am #4

I would do something like at the end of your opengl render code (maybe after glDrawArrays() or glDrawElements()) put a simple angle ++ and then use that angle variable in your rotate transformation

float angle = 0.0f; //make sure its defined outside the render method

SampleUtils::rotatePoseMatrix(angle, 0.0f, 0.0f, 1.0f,
&modelViewMatrix.data[0]);)
//...
//blah
//rest of opengl code
//blah
//...
glBindTexture(GL_TEXTURE_2D, Textures[0]->mTextureID);
glDrawArrays(GL_TRIANGLES, 0, NUM_OBJECT_VERTEX);
angle ++;

Re: Object Animations

May 27, 2011 - 1:25am #3

Sorry Kim, but i dont get it..i want to develop the ImageTargets, can you show me the code to rotate my object continuously like bowl and spoon object in multitargets??

Re: Object Animations

May 24, 2011 - 10:32am #2

Take a look at the MultiTargets sample. In that sample, the bowl model rotates around the multi target. See the animateBowl() method in MultiTargets.cpp. The general idea is to find the change in time since the last frame and use that to apply a small amount of rotation to the modelview matrix.

- Kim

Log in or register to post comments