View Full Version : Need help for animation

jenny_wui

01-10-2013, 06:23 PM

I have somehow managed to find out the medial axis path of my tubular intestine model. Now I want to create animation so that the camera moves from the start of the medial path to the end of it. The path is a set of points. Could somebody give me some guideline about constantly moving from one medial axis point to another to create animation? Thanks.

thokra

01-11-2013, 01:34 AM

A one second Google search immediately brought me to this (http://www.cs.ncl.ac.uk/publications/articles/papers/870.pdf) exhaustive paper. You may also check out various books on computer animation, my reference being Computer Animation by Rick Parent. Also, for an essential tool regarding this topic, i.e. arc-length parameterization, you may check this (https://www.cs.uiowa.edu/~kearney/pubs/CurvesAndSurfacesArcLength.pdf) paper out. Knowing arc lengths of motion curve segments helps you keep the camera speed constant while moving along a curve with differently spaced control points.

jenny_wui

01-11-2013, 08:50 AM

Thanks for the paper which is quite exhausetive. I think my work is much simpler as I already have the points along which the camera will traverse. I would like to proceed step by step. I place the camera at the beginning of the tube i.e. beginning point. I think I just need to place the camera from previous to the next point. Do I need to consider anything more?As I have never worked on camera manipulation, I need some more input to work on it. I think I only need to deal with gluLookAt function and camera position i.e. cameraX, cameraY, cameraZ. In the following equation,

gluLookAt( cameraX, cameraY, cameraZ, centerX, centerY, centerZ, upX, upY, upZ);

Do I need to consider other gluLookAt parameters?

Please help me clarify it.

tonyo_au

01-11-2013, 07:26 PM

gluLooatAt will work find but you have to conside how smoothly you want to move the camera (ie how far you move the camera along your path in a second) and what you do when you reach a corner.

As you a approach a corner you have 3 options -

you center can remain along the vector you are currently travelling and you jerk around the corner as you swap vectors when the camera reaches the cornder - this is the easiest to do

you stop the camera at the corner and smoothly rotate the center around the corner vertex to the new align along the new vector before continusing along the new vector

you have your center go around the corner onto the new vector before the camera has arrived at the corner - this may look better but you have to consider how far ahead of the camera the center is so you don't try to look through the wall of the intestine.

jenny_wui

01-11-2013, 11:08 PM

Suppose I have first two points in my path: v1 and v2. I set camera at v1 and center at v2. Next point is v3. I put camera at v2 and center at v3. Now do I need to check everytime the alignment between vector v1v2 and v2v3 before moving the camera? Please clarify a bit.

tonyo_au

01-12-2013, 08:47 PM

What you are describing is not a true animation you need to move the camera along the path; the path is not discret points but a continuous function. If your camera has a velocity of v then your camera will travel d = vt in time t. If you camera is at point p on the path your camera need to be placed at the point d units along the path from p. Note this new position need not be exactly at a vertex defining the path (in fact it almost certainly won't be). To understand how to do this you need some basic understanding of vectors. What background do you have on vector maths?

jenny_wui

01-12-2013, 10:49 PM

942

Actually I don't understand how to proceed. I have attached the picture of my model and the path which consists of a number of points. Now I have shown camera position and the center and I have put those values in gluLookAt function. But I can't view any thing. This is my starting point. I know about vectors. What I am trying now is to press a key and the camera will move along different points on the path, my center point will be new camera point and next vertex point will be new center. But I can't make it work. I need help. I may have some basic problem in understanding. After I finish this basic step by step key pressing movement, I shall implement the animation. I think any example code may be helpful to understand.

tonyo_au

01-13-2013, 05:13 AM

Can you post the code where you setup the first gluLookAt and the render of a frame.

jenny_wui

01-13-2013, 08:13 AM

I don't understand why I can't see anything for the following position of camera.Here is some part of the code:

voidglutReshape(int width, intheight)

{

static const double kPI =3.1415926535897932384626433832795;

static const double kFovY =40;

doublenearDist, farDist, aspect;

glViewport(0, 0, width, height);

// Compute theviewing parameters based on a fixed fov and viewing

// a canonicalbox centered at the origin.

nearDist = 2.0 / tan((kFovY / 2.0) * kPI /180.0);

farDist = nearDist + 50.0;

aspect = (double)width / height;

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(kFovY, aspect, nearDist,farDist);

// first point of the path

camera[0] = (*path)[0].vert[0];

camera[1] = (*path)[0].vert[1];

camera[2] = (*path)[0].vert[2];

// second point of the path

center[0] = (*path)[1].vert[0];

center[1] = (*path)[1].vert[1];

center[2] = (*path)[1].vert[2];

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

updateCamera();

}

voidupdateCamera()

{

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(camera[0], camera[1],camera[2], center[0], center[1],

center[2], 0, 1, 0);

glTranslatef(gCameraTranslationX,gCameraTranslatio nY, 0);

glMultMatrixd(gCameraRotation);

glScaled(gCameraScale, gCameraScale,gCameraScale);

glutPostRedisplay();

}

jenny_wui

01-13-2013, 12:43 PM

I had someproblem in my previous code with culling. After fixing it I can view some thing like this:

943

But output is not correct as I am not able to find correct view from camera to center. Do I need to do any thing with the up vector. I have another question, why the point where camera is set is shown in the output? It is not supposed to be visible from my understanding. Please help me clarify the thing. Thanks.

tonyo_au

01-13-2013, 05:12 PM

Why are you doing this?

glTranslatef(gCameraTranslationX,gCameraTranslatio nY, 0);

glMultMatrixd(gCameraRotation);

glScaled(gCameraScale, gCameraScale,gCameraScale);

You have already placed your camera in the world with the gluLookAt, now you are moving the world.

jenny_wui

01-13-2013, 10:19 PM

Now I am getting some output by setting camera at v0 and center at v2 by adjusting near and far plane in gluPerspective (last time it was too away from camera). I have attached the output. The matrix transformation is unit. So it is actually not making any change in the output. I kept it for mouse based interaction.

949

But the result is not ok, I want to see the image centered, but I am getting it partially. As I keep on moving by pressing a key making the center point as camera and center as the next vertex, the output is worse. sometimes ou of the model. I understand I need to finetune the alignment between v0v1 and v1v2 and so on. Please give me some suggestion. Thank you for cooperation from the beginning.

tonyo_au

01-14-2013, 12:13 AM

Your probelms now are probably fine tuning. If is possible that the direct line from the camera vertex to the center vertex is actually cutting through the model. Also you image on the screen will not be square if the window is not square - that is a circle will look like an oval. This can be fixed but I would ignore it for the moment and just make the window square. Try adjusting the FOV in the perspective camera .

jenny_wui

01-14-2013, 05:07 PM

I have made the window square. Now when I move, I find the camera in the middle of the screen, by adjusting fovY and near plane. But most of time I could see side, roof or floor of the tunnel as shown in my first picture, very few times, I can see the whole boundary as shown in the second picture. How can that be adjusted?

950 951

jenny_wui

01-15-2013, 03:49 PM

I have managed to get better output by adjusting the FOV. Thanks for the suggestion.

jenny_wui

01-15-2013, 05:26 PM

I need some suggestion about creating animation. i.e. how to process camera with time, and how to modify the path if necessary when the camera traverses a particular distance. Thanks in advance.

tonyo_au

01-16-2013, 02:41 AM

Ok to move the camera for an animation you need to know the scale of your model; that is, is 1 unit on mesh equal to 1 cm, or 1 m etc. Once you know that you have to think about how far you want the camera to move in 1 second - say 1cm (might be too slow) or 1m (probably to fast).

Lets say we have a scale of 1 mesh unit = 1 cm. and we want to move the camera 5 cm in a second; then the new camera = old camera + 5 * ||direction||. See my earlier post on how to choose a direction.

jenny_wui

01-16-2013, 01:26 PM

Hi,

In previous posting, there were following three options:

1.center can remain along the vector you are currently travelling and you jerk around the corner as you swap vectors when the camera reaches the cornder - this is the easiest to do

2.stop the camera at the corner and smoothly rotate the center around the corner vertex to the new align along the new vector before continusing along the new vector

3. have your center go around the corner onto the new vector before the camera has arrived at the corner - this may look better but you have to consider how far ahead of the camera the center is so you don't try to look through the wall of the intestine.

I think the third option is the best one. Suppose each secnd I travel 5 unit along the look at vector. Now my new point is:

new_point = camera + lookatvector*5;

This new point is supposed be the next camera point and is most likely not on the path; Then my question is :

how can I choose next camera and center? How can the new vector be found?

I think I can go around the corner by checking the next vector and the angle between two consecutive vectors. But again my new point may not on the line. Then how to keep on proceeding along the path?

Now this way my original path lmay not be maintained. Then what would be the end condition of traversal?

Help me clarify the above issues.

tonyo_au

01-16-2013, 02:41 PM

Thw third option is clearly the hardest. You have to choose a distance the center point is ahead of the camera. If you make it too far you will try to look through the sides of your model. You also have to follow that path across a vertex. If you path is simple set of lines this is quite straight forward.

Here is the pseudo code

assume path is V1,V2,V3; camera is at E and center is at C both somewhere along V1-V2

the distance to move of D = time * velocity.

new center is

if D > ( V2-C)

C = ||V3-V2|| * (D - (V2-C))

else

C = ||V2-V1|| * D

new camera is

if D > (V2-E)

E = ||V3-V2|| * (D - (V2-E))

else

E = ||V2-V1|| * D

Note that you should allow for D > (V2-C)+(V3-V2) etc

If you are using a curved path you approximate it with a set of line vectors

jenny_wui

01-16-2013, 09:21 PM

Thanks. At first I need to find the whole path length and the traversal time which I need to fix by myself. Then traverse the path at a const. velocity. And for each pair of vertices, I need to check the above algorithm. But I didn't understand why I need to have D > (V2 - C) + (V3 - V2). Could you clarify a bit.

tonyo_au

01-16-2013, 10:28 PM

Lets say V1-V2 is 1 unit long and V2-V3 is 1 unit long, if D is say 4; then the new location for the camera starting in line V1-V2 is past V3; so you have to place in on the line V3-V4 - but it might also be past V4 - understand.

jenny_wui

01-21-2013, 09:57 PM

Thanks. I have implemented as per your suggestion. At each frame equal amount of distance v*t is travelled. Checking each time among which vertices pair the center and cameral position lie and giving new positions for each. I think this makes travel same amount of distance and result is more uniform.

tonyo_au

01-22-2013, 05:12 AM

Glad to hear you are making progress.:)

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.