- Main Page
- Packages
- Classes
- Files

- File List
- File Members

# D:/guillaume/guillara/3D/DXGfx/DXGfxLib/Avatar.cs

Go to the documentation of this file.

    00001 using System;
    00002 using System.Collections.Generic;
    00003 using System.Text;
    00004 using Microsoft.DirectX;
    00005 using Microsoft.DirectX.Direct3D;
    00006
    00007 namespace DXGfxLib
    00008 {
    00009     // States
    00010     public enum AvatarState { Moving, Resting };
    00011
    00019     public class Avatar
    00020     {
    00026         public float speed = 1.0f;
    00027
    00031         public Vector3 destination;
    00032
    00037         public AvatarState currentState = AvatarState.Resting;
    00038
    00042         public SceneObject associatedSceneObject = null;
    00043
    00047         private Avatar()
    00048         {
    00049         }
    00050
    00055         private Avatar(SceneNode node)
    00056         {
    00057         }
    00058
    00063         public Avatar(SceneObject sceneObj)
    00064         {
    00065             associatedSceneObject = sceneObj;
    00066         }
    00067
    00072         public void MoveTo(Vector3 desiredDestination)
    00073         {
    00074             destination = desiredDestination;
    00075             currentState = AvatarState.Moving;
    00076         }
    00077
    00081         public void StopMoving()
    00082         {
    00083             currentState = AvatarState.Resting;
    00084         }
    00085
    00099         public void FrameMove(float elapsedTime)
    00100         {
    00101             if (currentState == AvatarState.Moving)
    00102             {
    00103
    00104                 Vector3 diff = Vector3.Subtract(destination, associatedSceneObject.Position);
    00105
    00106                 if (diff.Length() < 0.5f)
    00107                 {
    00108                     currentState = AvatarState.Resting;
    00109                 }
    00110                 else
    00111                 {
    00112                     diff.Normalize();
    00113
    00114                     Matrix translation = Matrix.Translation(speed * diff);
    00115
    00116                     associatedSceneObject.ApplyWorldTransform(translation);
    00117
    00118                     // Now if a class implementing IPositionConstraint has been set for this scene node
    00119                     // let's use it.
    00120                     if (associatedSceneObject.positionConstraint != null)
    00121                     {
    00122                         Matrix transf = associatedSceneObject.positionConstraint.ValidateOrMove(associatedSceneObject.Position, associatedSceneObject.localBoundingBox);
    00123                         associatedSceneObject.ApplyWorldTransform(transf);
    00124                     }
    00125                 }
    00126
    00127             }
    00128         }
    00129     }
    00130 }