Hello!
The animation of the translation is working right now. Thank you, also for 
the explications.
Now I'm trying to use the slerpThis-function to animate a rotation. I'm not 
sure, if I passed the values right. Probably not, because it's not working 
:-) Thus, another easy problem to solve:
I have written this function:

void rotation_x(Quaternion cube_init_qua, Quaternion cube_end_qua, int 
frame_current, int frame_total){
     Matrix cube_move;
     cube_move.setIdentity();
     Quaternion q;

     float slerp_value = frame_current/frame_total;     //to get a value 
between 0 and 1

     beginEditCP(cube_trans, Transform::MatrixFieldMask);
          q.slerpThis(cube_init_qua,cube_end_qua,slerp_value);
          cube_move.setTransform(cube_init,q);            //cube_init = 
Vec3f(0,10,0)
          cube_trans->setMatrix(cube_move);
     endEditCP(cube_trans, Transform::MatrixFieldMask);
}

And this is being called by

    rotation_x(Quaternion(Vec3f(1,0,0),0), Quaternion(Vec3f(1,0,0),30), 
frame_current, frame_total);

in the display-Function.

Thank you again!
alex


----- Original Message ----- 
From: "Carsten Neumann" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, February 21, 2008 6:56 PM
Subject: Re: [Opensg-users] Animation of a translation


> Hello Alexandra,
>
> Alexandra Wolyniec wrote:
>> Hello!
>> I'm trying to form a translation by using functions.
>> So I wrote this function to make an easy transformation along the y axis:
>>
>> void animation_vertical(Vec3f cube_init_vec, Vec3f cube_end_vec, int
>> frame_total){
>>
>>     Matrix cube_move;
>>     cube_move.setIdentity();
>>     for (frame_current=0; frame_current<=frame_total; frame_current++){
>>          beginEditCP(cube_trans, Transform::MatrixFieldMask);
>>                int cube_move_y =
>> cube_init_vec.getValues()[1]+(osgabs(cube_end_vec.getValues()[1]-cube_init_vec.getValues()[1])/frame_total*frame_current);
>>                cube_move.setTranslate(0,cube_move_y,0);
>>                cube_trans->setMatrix(cube_move);
>>        endEditCP(cube_trans, Transform::MatrixFieldMask);
>>     }
>> }
>
> you do not need a loop here. Computer animation works like stop motion
> movies: You set up the scene and take a picture of it, then modify it
> for the next picture. Whether you do the modification in many small
> steps (like in the loop above) or just use the values computed in the
> last iteration of the loop is not visible as no images are taken of the
> intermediate steps.
> So, to move an object from A to B over the course of 100 frames, you
> basically do the following:
>
> in keyboard:
> run = true;
> frame_current = 0;
> frame_total   = 100;
>
> in display:
> if run == true and frame_current <= frame_total:
>   compute a position C as the linear interpolation between A and B,
> based on the ratio of frame_current/frame_total.
>   place your object at C
>
> render the scene.
>
>> With the keyboard function I'm activating the type of the animation
>> (because there will be some more animations) and the running of the
>> animation itself. In addition I set the duration of the animation to 
>> zero:
>>
>> void keyboard(unsigned char k, int x, int y){
>>     switch (k){
>>         case '1' : run = true;
>>                         typ_animation = 1;
>>                   dauer = 0;
>>                         break;
>>         }
>> }
>>
>> After that I use the display function to let the animation go on. As I
>> have understood this method, this function is being called and called by
>> glutDisplayFunc(display);  in the SetupGlut. (Sorry, after adapting to
>> french my english gets more and more worse :-/) So, that's why I thought
>> it will redraw each new frame position of the animation.
>
> do you also have a glutIdleFunc? That should be a function that just
> calls glutPostRedisplay, because otherwise your display function will
> only be called in reaction to certain "events" that require a refresh of
> the screen content (e.g. resizing/moving the window).
> Also, when the user presses a recognized key (like '1') you probably
> also want to issue a glutPostRedisplay.
>
>> void display(void){
>>
>>     if(run==true && dauer<300){
>>          switch(typ_animation){
>>                case 1: animation_vertical(Vec3f(0,5,0), Vec3f(0,20,0),
>> dauer);
>>                break;
>>            }
>>         dauer++;
>>         }
>>        mgr->redraw();
>>     }
>> }
>>
>> All in all, it changes the positions, but it does not show the animation
>> between. Why?! What do I have to change?
>
> My guess would be the lack of a glutIdleFunction, will already display
> the animation. But please also try to understand why the loop in
> animate_vertical is not required.
>
> Hope it helps,
> Carsten
>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Opensg-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/opensg-users 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to