Esempio n. 1
0
        /// <summary>
        /// Adds a keyframe to the tween
        /// </summary>
        /// <param name="keyFrame">Keyframe</param>
        /// <returns>Index of the keyframe, or -1 if it could not be inserted</returns>
        public int AddKeyframe(gxtKeyframe keyFrame)
        {
            gxtDebug.Assert(keyFrame != null, "Cannot add null keyframe!");

            // greedy
            if (keyframes.Count > 0)
            {
                if (keyFrame.LocalTime > keyframes[keyframes.Count - 1].LocalTime)
                {
                    keyframes.Add(keyFrame);
                    return keyframes.Count - 1;
                }
            }

            int insertIndex = 0;
            for (int i = 0; i < keyframes.Count; ++i)
            {
                if (keyFrame.LocalTime > keyframes[i].LocalTime)
                    insertIndex = i + 1;
                else if (keyFrame.LocalTime < keyframes[i].LocalTime)
                    break;
                else
                    return -1;
            }
            keyframes.Insert(insertIndex, keyFrame);
            return insertIndex;
        }
Esempio n. 2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="pose"></param>
 /// <param name="localTime"></param>
 /// <param name="interpolationType"></param>
 /// <returns></returns>
 public int CreateKeyframe(gxtAnimationPose pose, float localTime, gxtAnimationInterpolationType interpolationType = gxtKeyframe.DEFAULT_INTERPOLATION_TYPE)
 {
     gxtKeyframe kf = new gxtKeyframe(pose, localTime, interpolationType);
     return AddKeyframe(kf);
 }
Esempio n. 3
0
 /// <summary>
 /// Removes a keyframe from the tween
 /// </summary>
 /// <param name="keyframe">Keyframe</param>
 /// <returns>If the keyframe was successfully removed</returns>
 public bool RemoveKeyframe(gxtKeyframe keyframe)
 {
     return keyframes.Remove(keyframe);
 }
Esempio n. 4
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            IsMouseVisible = true;
            camera = new gxtCamera(Vector2.Zero, 0.0f, 0.0f, false);
            gxtDisplayManager.Singleton.WindowTitle = "Animation Scene Graph Test";
            sceneGraph = new gxtSceneGraph();
            sceneGraph.Initialize();

            Texture2D grassTexture, metalTexture;
            bool textureLoaded = gxtResourceManager.Singleton.LoadTexture("Textures\\grass", out grassTexture);
            gxtDebug.Assert(textureLoaded, "Texture load failed!");
            textureLoaded = gxtResourceManager.Singleton.LoadTexture("Textures\\scratched_metal", out metalTexture);
            gxtDebug.Assert(textureLoaded, "Texture load failed!");

            parent = new gxtSceneNode();
            Vector2[] rectangleVertices = gxtGeometry.CreateRectangleVertices(150, 100);
            gxtDynamicMesh rectangle = new gxtDynamicMesh(rectangleVertices);
            gxtIMaterial rectangleMaterial = new gxtMaterial(true, Color.Yellow, 0.5f);
            rectangle.Material = rectangleMaterial;
            rectangle.ApplyTexture(grassTexture, gxtTextureCoordinateType.WRAP);
            parent.AttachDrawable(rectangle);

            child = new gxtSceneNode();
            child.Position = new Vector2(37.5f, 55.5f);
            Vector2[] rectangleVertices2 = gxtGeometry.CreateRectangleVertices(75, 175);
            gxtIMaterial rectangleMaterial2 = new gxtMaterial(true, Color.Blue, 1.0f);
            gxtDynamicMesh rectangle2 = new gxtDynamicMesh(rectangleVertices2);
            rectangle2.Material = rectangleMaterial2;
            rectangle2.ApplyTexture(metalTexture, gxtTextureCoordinateType.WRAP);
            child.AttachDrawable(rectangle2);
            parent.AddChild(child);

            sceneGraph.AddNode(parent);

            gxtAnimationPose a0 = new gxtAnimationPose();
            a0.InterpolateUVCoords = true;
            a0.InterpolateColorOverlay = true;
            a0.UVCoordinates = rectangle.GetTextureCoordinates();

            gxtAnimationPose a1 = new gxtAnimationPose();
            a1.InterpolateUVCoords = false;
            a1.InterpolateColorOverlay = true;
            a1.ColorOverlay = Color.Red;
            a1.Translation = new Vector2(-150, -200);

            Vector2[] uvCoordsCopy = rectangle.GetTextureCoordinates();
            for (int i = 0; i < uvCoordsCopy.Length; ++i)
            {
                uvCoordsCopy[i] += new Vector2(-0.75f);
            }
            a1.UVCoordinates = uvCoordsCopy;

            gxtAnimationPose a2 = new gxtAnimationPose();
            a2.Translation = new Vector2(200, -225);
            a2.Rotation = gxtMath.PI_OVER_FOUR;
            a2.InterpolateUVCoords = false;
            Vector2[] uvCoordsCopy2 = rectangle.GetTextureCoordinates();
            for (int i = 0; i < uvCoordsCopy2.Length; ++i)
            {
                uvCoordsCopy2[i] *= (1.0f / 1.5f);
                //uvCoordsCopy2[i] += new Vector2(-3.75f, 0.0f);
            }
            a2.UVCoordinates = uvCoordsCopy2;


            gxtAnimationPose a3 = new gxtAnimationPose();
            a3.Translation = new Vector2(50, 200);
            a3.Rotation = gxtMath.DegreesToRadians(-235);
            a3.Scale = new Vector2(1.85f, 1.75f);

            gxtKeyframe k0 = new gxtKeyframe(a0, 0.0f);
            gxtKeyframe k1 = new gxtKeyframe(a1, 0.4f);
            gxtKeyframe k2 = new gxtKeyframe(a2, 0.65f);
            gxtKeyframe k3 = new gxtKeyframe(a3, 1.0f);


            gxtAnimationClip clip = new gxtAnimationClip(parent, rectangle);
            clip.AddKeyframe(k0);
            clip.AddKeyframe(k1);
            clip.AddKeyframe(k2);
            clip.AddKeyframe(k3);

            animClip = new gxtAnimation(TimeSpan.FromSeconds(5.0), true, true, 1.0f);
            animClip.AddClip(clip);

            animController = new gxtAnimationController();
            animController.AddAnimation("default", animClip);
            //animClip.AddTween();
            /*
            gxtAnimationKeyFrame k3 = new gxtAnimationKeyFrame();
            */

            /*
            parent = new gxtSceneNode();
            //gxtIDrawable rectangleDrawable = new gxtDrawable(Color.Yellow, true, 0.5f);
            gxtRectangle rectangle = new gxtRectangle(150, 100);
            gxtIMaterial rectangleMaterial = new gxtMaterial(true, Color.Yellow, 0.2f);
            rectangle.Material = rectangleMaterial;
            parent.AttachDrawable(rectangle);

            child = new gxtSceneNode();
            //gxtIDrawable childRectDrawable = new gxtDrawable(Color.Blue, true, 0.0f);
            gxtRectangle childRect = new gxtRectangle(75, 175);
            gxtIMaterial childRectangleMaterial = new gxtMaterial(true, new Color(0, 0, 255, 100), 0.0f);
            childRect.Material = childRectangleMaterial;
            child.AttachDrawable(childRect);
            child.Position = new Vector2(37.5f, 55.5f);

            parent.AddChild(child);

            sceneGraph.AddNode(parent);

            initKeyframe = new gxtKeyframe(gxtNodeTransform.Identity, 0.0f);

            gxtNodeTransform midTransform = new gxtNodeTransform();
            midTransform.Translation = new Vector2(-185, -100);
            midTransform.Scale = new Vector2(-1.5f, 1.5f);
            midTransform.Rotation = gxtMath.DegreesToRadians(-25.0f);
            gxtKeyframe midKeyFrame = new gxtKeyframe(midTransform, 0.235f);

            gxtNodeTransform finalPose = new gxtNodeTransform();
            finalPose.Translation = new Vector2(100.0f, -200.0f);
            finalPose.Rotation = gxtMath.DegreesToRadians(90.0f);
            finalKeyframe = new gxtKeyframe(finalPose, 0.6f);

            gxtNodeTransform lastXform = new gxtNodeTransform();
            lastXform.Translation = new Vector2(100.0f, -200.0f);
            lastXform.Rotation = -6.0f * gxtMath.PI;
            lastXform.Scale = new Vector2(0.25f, 1.45f);
            gxtKeyframe lastKeyframe = new gxtKeyframe(lastXform, 0.85f);


            gxtTween tween = new gxtTween(parent);
            tween.AddKeyframe(initKeyframe);
            tween.AddKeyframe(finalKeyframe);
            tween.AddKeyframe(midKeyFrame);
            tween.AddKeyframe(lastKeyframe);


            animClip = new gxtAnimationClip(TimeSpan.FromSeconds(10.0));
            animClip.AddTween(tween);
            animClip.Loop = false;
            animClip.PlaybackRate = 1.0f;

            animController = new gxtAnimationController();
            animController.AddClip("default", animClip);
            animController.Stop("default");
            */

            gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, "Window Width: {0}", gxtDisplayManager.Singleton.ResolutionWidth);
            gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, "Window Height: {0}", gxtDisplayManager.Singleton.ResolutionHeight);
            //gxtSprite sprite = new gxtSprite(texture);
            //sprite.Depth = 0.0f;
            //sprite.Alpha = 100;
            //manager.Add(sprite);
        }