Animations

All about the core api and animation, input, sound, effect, collision and physics engines.
You can also post here your feature requests.

Moderator: Brume Dev Team

Animations

Postby Gero on Mon Dec 31, 2007 4:10 pm

Hi,

I just wanted to create a simple rotation animation...
I thought I could do it myself with the Orient() function but I don't find any function to get the current rotation.
Now here is my code:
Code: Select all
        public void CreatePaketAnimation()
        {

            int nbFrames = 5;
            float totalTime = 1f;

            BrumeAnimation Animation = new BrumeAnimation();
            Animation.Name = "packet_rotate";
            Animation.TotalTime = totalTime;
            Animation.AnimatedElements = new BrumeAnimatedElement[1];

            Animation.AnimatedElements[0].Name = Animation.Name + " Rotate";
            Animation.AnimatedElements[0].RotationKeys = new BrumeRotationKey[nbFrames];

            Animation.AnimatedElements[0].RotationKeys[0].Time = 0.0f;
            Animation.AnimatedElements[0].RotationKeys[0].Rotation = BrumeQuaternion.RotationAxis(BrumeVector.XAXIS, BrumeAngle.ToRadian(0f));

            for (int i = 1; i < nbFrames - 1; i++)
            {
                Animation.AnimatedElements[0].RotationKeys[i].Time = (float)((totalTime * i) / nbFrames);
                Animation.AnimatedElements[0].RotationKeys[i].Rotation = BrumeQuaternion.RotationAxis(BrumeVector.XAXIS, BrumeAngle.ToRadian(360f * i / nbFrames));
            }

            Animation.AnimatedElements[0].RotationKeys[nbFrames - 1].Time = totalTime;
            Animation.AnimatedElements[0].RotationKeys[nbFrames - 1].Rotation = BrumeQuaternion.RotationAxis(BrumeVector.XAXIS, BrumeAngle.ToRadian(360f));

            BrumeAnimationManager.AddAnimation(Animation);
             
        }
and later in the objects Init() function:
Code: Select all
            AnimationStates.CurrentTime = 0.0f;
            AnimationStates.Speed = 1f;
            AnimationStates.Duration = 1f;
            Animation = BrumeAnimationManager.GetAnimation("packet_rotate");
            AnimationStates.TargetAnimation = Animation;
            AnimationStates.CurrentTime = 0.0f;
            AnimationStates.PlayMode = BrumeAnimationParams.PLAY_LOOP;

The code is from the IceCube project. There it works.
I've played with the parameters but I didn't see any animation there. :(
Is there any "start" function I haven't seen?
User avatar
Gero
Brume user
 
Posts: 27
Joined: Thu Dec 06, 2007 10:11 pm

Re: Animations

Postby Gero on Mon Dec 31, 2007 9:00 pm

I found a solution for the animation:
Just comment out the line in the CreatePacketAnimation() function.
Code: Select all
            //Animation.AnimatedElements[0].Name = Animation.Name + " Rotate";

Now the objects are rotating.. BUT the position is always 0... :( It gets overwritten every
animationframe :(
I track the position myself now.
This code solves it for objects without animation:
Code: Select all
        private BrumeVector slidePos = new BrumeVector();

        public BrumeVector SlidePos
        {
            get { return slidePos; }
            set
            {
                slidePos = value;
                this.Pos.X = slidePos.X;
                this.Pos.Y = slidePos.Y;
                this.Pos.Z = slidePos.Z;
            }
        }

To use it simply set the SlidePos member instead of Pos. You can name it whatever you want.
Use this code for animated objects:
Code: Select all
        public override void OnAfterAnimationKeyFrame()
        {
            base.OnAfterAnimationKeyFrame();
            this.Pos.X = slidePos.X;
            this.Pos.Y = slidePos.Y;
            this.Pos.Z = slidePos.Z;
        }
User avatar
Gero
Brume user
 
Posts: 27
Joined: Thu Dec 06, 2007 10:11 pm

Re: Animations

Postby Silmaryls on Tue Jan 08, 2008 8:56 pm

Hi Gero !

In order to keep object's position when playing an anim, just change the anim type :

{code]
myObject.Animation = ...
myObject.AnimationStates.TransformationType = BrumeAnimationParams.TYPE_RST_LTMTranslation;
[/code]

This should work.

For the Orient method I am effectively using vectors for orientation. Maybe you can keep the orientation value by overriding BrumeObject class ?
Otherwise I may create a UserData field typed Object if you think it's a better solution (this may be usefull).
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France


Return to Technical discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron