Animation.cs :  » Game » RealmForge » Axiom » Animating » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » RealmForge 
RealmForge » Axiom » Animating » Animation.cs
#region LGPL License
/*
Axiom Game Engine Library
Copyright (C) 2003  Axiom Project Team

The overall design, and a majority of the core engine and rendering code 
contained within this library is a derivative of the open source Object Oriented 
Graphics Engine OGRE, which can be found at http://ogre.sourceforge.net.  
Many thanks to the OGRE team for maintaining such a high quality project.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#endregion
using System;
using Axiom.Collections;
using Axiom.Core;


namespace Axiom.Animating{
    /// <summary>
    ///    An animation sequence. 
    /// </summary>
    /// <remarks>
    ///    This class defines the interface for a sequence of animation, whether that
    ///    be animation of a mesh, a path along a spline, or possibly more than one
    ///    type of animation in one. An animation is made up of many 'tracks', which are
    ///    the more specific types of animation.
    ///    <p/>
    ///    You should not create these animations directly. They will be created via a parent
    ///    object which owns the animation, e.g. Skeleton, SceneManager, etc.
    /// </remarks>
    public class Animation {
        #region Member variables
    
        /// <summary>Name of this animation.</summary>
        protected string name;
        /// <summary>The total length of this animation (sum of the tracks).</summary>
        protected float length;
        /// <summary>Collection of AnimationTracks.</summary>
        protected AnimationTrackCollection trackList;
        /// <summary>Interpolation mode of this animation.</summary>
        protected InterpolationMode interpolationMode;
        /// <summary>Default interpolation mode of any animations.</summary>
        static protected InterpolationMode defaultInterpolationMode;

        #endregion

        #region Constructors

        /// <summary>Static constructor.</summary>
        static Animation() {
            // set default interpolation mode to Spline (mmm....spline)
            defaultInterpolationMode = InterpolationMode.Spline;
        }

        /// <summary>
        ///    Internal constructor, to prevent from using new outside of the engine.
        ///    <p/>
        ///    Animations should be created within objects that can own them (skeletons, scene managers, etc).
        /// </summary>
        internal Animation(string name, float length) {
            this.name = name;
            this.length = length;

            // use the default interpolation mode
            this.interpolationMode = Animation.DefaultInterpolationMode;

            // initialize the collection
            this.trackList = new AnimationTrackCollection();
        }

        #endregion

        #region Properties


        /// <summary>
        ///    Gets the name of this animation.
        /// </summary>
        public string Name {
            get { return name; }
        }

        /// <summary>
        ///    Gets the total length of this animation.
        /// </summary>
        public float Length {
            get { return length; }
        }

        /// <summary>
        ///    Gets/Sets the current interpolation mode for this animation.
        /// </summary>
        public InterpolationMode InterpolationMode {
            get { return interpolationMode; }
            set { interpolationMode = value; }
        }

        /// <summary>
        ///    A collection of the tracks in this animation.
        /// </summary>
        // TODO: See if we can ensure that the track list is not modified somehow.
        public AnimationTrackCollection Tracks {
            get { return trackList; }
        }

        /// <summary>
        ///    Gets/Sets the default interpolation mode to be used for all animations.
        /// </summary>
        public static InterpolationMode DefaultInterpolationMode {
            get { return defaultInterpolationMode; }
            set { defaultInterpolationMode = value; }
        }

        #endregion

        #region Public methods

        /// <summary>
        ///    Creates an AnimationTrack. 
        /// </summary>
        /// <param name="handle">Numeric handle to give the track, used for accessing the track later.</param>
        /// <returns></returns>
        public AnimationTrack CreateTrack(short handle) {
            AnimationTrack track = new AnimationTrack(this);
            track.Handle = handle;

            // add the track to the list
            trackList.Add(track);

            return track;
        }

        /// <summary>
        ///    Creates a new AnimationTrack automatically associated with a Node. 
        /// </summary>
        /// <param name="index">Numeric handle to give the track, used for accessing the track later.</param>
        /// <param name="target">Node object which will be affected by this track.</param>
        /// <returns></returns>
        public AnimationTrack CreateTrack(short handle, Node target) {
            // create a new track and set it's target
            AnimationTrack track = CreateTrack(handle);
            track.TargetNode = target;
            track.Handle = handle;

            return track;
        }

    /// <summary>
    ///    Applies an animation given a specific time point and weight.
    /// </summary>
    /// <remarks>
    ///    Where you have associated animation tracks with Node objects, you can eaily apply
    ///    an animation to those nodes by calling this method.
    /// </remarks>
    /// <param name="time">The time position in the animation to apply.</param>
    /// <param name="weight">The influence to give to this track, 1.0 for full influence, less to blend with
    ///    other animations.</param>
    /// <param name="accumulate"></param>
    public void Apply(float time, float weight, bool accumulate) {
      Apply(time, weight, accumulate, false);
    }


        /// <summary>
        ///    Applies an animation given a specific time point and weight.
        /// </summary>
        /// <remarks>
        ///    Where you have associated animation tracks with Node objects, you can eaily apply
        ///    an animation to those nodes by calling this method.
        /// </remarks>
        /// <param name="time">The time position in the animation to apply.</param>
        /// <param name="weight">The influence to give to this track, 1.0 for full influence, less to blend with
        ///    other animations.</param>
        /// <param name="accumulate"></param>
        public void Apply(float time, float weight, bool accumulate, bool lookInDirectionOfTranslation) {
            // loop through tracks and update them all with current time
      for(int i = 0; i < trackList.Count; i++) {
        trackList[i].Apply(time, weight, accumulate, lookInDirectionOfTranslation);
      }
        }

    public void Apply(Skeleton skeleton, float time, float weight, bool accumulate) {
      // loop through tracks and update them all with current time
      for(int i = 0; i < trackList.Count; i++) {
        AnimationTrack track = trackList[i];
        Bone bone = skeleton.GetBone((ushort)track.Handle);
        track.ApplyToNode(bone, time, weight, accumulate, false );
      }
    }

        #endregion

        #region Event handlers

        private void TrackAdded(object source, System.EventArgs e) {
      
        }

        private void TracksCleared(object source, System.EventArgs e) {
            // clear the tangents list when the points are cleared
            //tangentList.Clear();
        }

        #endregion
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.