Beispiel #1
0
        //VertexPositionColorTexture - 4 bytes x 3 (x,y,z) + 4 bytes x 3 (r,g,b) + 4bytes x 2 = 26 bytes
        //VertexPositionColor -  4 bytes x 3 (x,y,z) + 4 bytes x 3 (r,g,b) = 24 bytes
        private void InitHelpers()
        {
            //to do...add wireframe origin
            PrimitiveType primitiveType;
            int           primitiveCount;

            //step 1 - vertices
            VertexPositionColor[] vertices = VertexFactory.GetVerticesPositionColorOriginHelper(
                out primitiveType, out primitiveCount);

            //step 2 - make vertex data that provides Draw()
            IVertexData vertexData = new VertexData <VertexPositionColor>(vertices,
                                                                          primitiveType, primitiveCount);

            //step 3 - make the primitive object
            Transform3D transform3D = new Transform3D(new Vector3(0, 20, 0),
                                                      Vector3.Zero, new Vector3(10, 10, 10),
                                                      Vector3.UnitZ, Vector3.UnitY);

            EffectParameters effectParameters = new EffectParameters(this.unlitWireframeEffect,
                                                                     null, Color.White, 1);

            //at this point, we're ready!
            PrimitiveObject primitiveObject = new PrimitiveObject("origin helper",
                                                                  ActorType.Helper, StatusType.Drawn, transform3D, effectParameters, vertexData);

            this.objectManager.Add(primitiveObject);
        }
Beispiel #2
0
        private void InitPlayer()
        {
            //transform
            Transform3D transform3D = new Transform3D(new Vector3(0, 0, 0),
                                                      new Vector3(0, 0, 0), //rotation
                                                      new Vector3(1, 1, 1), //scale
                                                      -Vector3.UnitZ,       //look
                                                      Vector3.UnitY);       //up

            //effectparameters
            EffectParameters effectParameters = new EffectParameters(modelEffect,
                                                                     null,
                                                                     Color.White, 1);

            //model
            Model model = Content.Load <Model>("Assets/Models/wizard");

            //model object
            ModelObject playerObject = new ModelObject("Wizard", ActorType.Player,
                                                       StatusType.Drawn | StatusType.Update, transform3D,
                                                       effectParameters, model);

            ThirdPersonPlayerController controller = new ThirdPersonPlayerController(
                keyboardManager, mouseManager, cameraManager.ActiveCamera,
                GConstants.PlayerMoveSpeed,
                GConstants.PlayerStrafeSpeed,
                GConstants.PlayerRotateSpeed,
                GConstants.PlayerMoveKeysOne);

            Player player = new Player(playerObject, controller);

            this.objectManager.Add(player);
        }
Beispiel #3
0
 public CollidablePlayerObject(string id, ActorType actorType, StatusType statusType, Transform3D transform,
                               EffectParameters effectParameters, IVertexData vertexData, ICollisionPrimitive collisionPrimitive,
                               ObjectManager objectManager, Keys[] moveKeys, KeyboardManager keyboardManager)
     : base(id, actorType, statusType, transform, effectParameters, vertexData, collisionPrimitive, objectManager)
 {
     this.moveKeys        = moveKeys;
     this.keyboardManager = keyboardManager;
 }
Beispiel #4
0
        //for objects with texture and alpha but no specular or emmissive
        public EffectParameters(Effect effect, Texture2D texture, Color diffusecolor, float alpha)
        {
            Initialize(effect, texture, diffuseColor, alpha);

            //store original values in case of reset
            this.originalEffectParameters = new EffectParameters();
            this.originalEffectParameters.Initialize(effect, texture, diffuseColor, alpha);
        }
Beispiel #5
0
        public ModelObject(string id, ActorType actorType, StatusType statusType,
                           Transform3D transform, EffectParameters effectParameters, Model model)
            : base(id, actorType, statusType, transform, effectParameters)
        {
            this.model = model;

            InitializeBoneTransforms();
        }
 public BillboardPrimitiveObject(string id, ActorType actorType, Transform3D transform,
                                 EffectParameters effectParameters, StatusType statusType, IVertexData vertexData, BillboardType billboardType)
     : base(id, actorType, transform, effectParameters, statusType, vertexData)
 {
     //create blank set of parameters and set type to be Normal - developer can change after instanciation - see Main::InitializeBillboards()
     this.billboardOrientationParameters = new BillboardOrientationParameters();
     this.BillboardType = billboardType;
 }
        public new object Clone()
        {
            CollidableProjectile projectile = new CollidableProjectile(ID, ActorType, StatusType, Transform3D.Clone() as Transform3D,
                                                                       EffectParameters.Clone() as EffectParameters, IVertexData.Clone() as IVertexData, CollisionPrimitive.Clone() as ICollisionPrimitive,
                                                                       ObjectManager);

            projectile.ControllerList.AddRange(GetControllerListClone());
            return(projectile);
        }
 //used to draw collidable primitives that have a texture i.e. use VertexPositionColor vertex types only
 public CollidablePrimitiveObject(string id, ActorType actorType, Transform3D transform,
                                  EffectParameters effectParameters, StatusType statusType, IVertexData vertexData,
                                  ICollisionPrimitive collisionPrimitive, ObjectManager objectManager)
     : base(id, actorType, transform, effectParameters, statusType, vertexData)
 {
     this.collisionPrimitive = collisionPrimitive;
     //unusual to pass this in but we use it to test for collisions - see Update();
     this.objectManager = objectManager;
 }
Beispiel #9
0
        public new object Clone()
        {
            CollidablePlayerObject player = new CollidablePlayerObject(ID, ActorType, StatusType, Transform3D.Clone() as Transform3D,
                                                                       EffectParameters.Clone() as EffectParameters, IVertexData.Clone() as IVertexData, CollisionPrimitive.Clone() as ICollisionPrimitive,
                                                                       ObjectManager, moveKeys, keyboardManager);

            player.ControllerList.AddRange(GetControllerListClone());
            return(player);
        }
Beispiel #10
0
 public MoveableObject(string id,
                       ActorType actorType,
                       StatusType statusType,
                       Transform3D transform,
                       EffectParameters effectParameters,
                       Model model,
                       IController controller) :
     base(id, actorType, statusType, transform, effectParameters, model)
 {
     ControllerList.Add(controller);
 }
 public PlayerObject(string id, ActorType actorType, Transform3D transform,
                     EffectParameters effectParameters, Model model,
                     Keys[] moveKeys, float radius, float height, float accelerationRate, float decelerationRate, float jumpHeight,
                     Vector3 translationOffset, KeyboardManager keyboardManager)
     : base(id, actorType, transform, effectParameters, model, radius, height, accelerationRate, decelerationRate)
 {
     this.moveKeys          = moveKeys;
     this.translationOffset = translationOffset;
     this.keyboardManager   = keyboardManager;
     this.jumpHeight        = jumpHeight;
 }
 public AnimatedPlayerObject(string id, ActorType actorType, Transform3D transform,
                             EffectParameters effectParameters,
                             Keys[] moveKeys, float radius, float height,
                             float accelerationRate, float decelerationRate, float jumpHeight,
                             Vector3 translationOffset, KeyboardManager keyboardManager)
     : base(id, actorType, transform, effectParameters, null, moveKeys, radius, height, accelerationRate, decelerationRate, jumpHeight, translationOffset, keyboardManager)
 {
     //initialize dictionaries
     this.modelDictionary           = new Dictionary <AnimationDictionaryKey, Model>();
     this.animationPlayerDictionary = new Dictionary <AnimationDictionaryKey, AnimationPlayer>();
     this.skinningDataDictionary    = new Dictionary <AnimationDictionaryKey, SkinningData>();
 }
        public CharacterObject(string id, ActorType actorType, Transform3D transform,
                               EffectParameters effectParameters, Model model,
                               float radius, float height, float accelerationRate, float decelerationRate)
            : base(id, actorType, transform, effectParameters, model)
        {
            this.Body               = new Character(accelerationRate, decelerationRate);
            this.Collision          = new CollisionSkin(Body);
            this.Body.ExternalData  = this;
            this.Body.CollisionSkin = this.Collision;
            Capsule capsule = new Capsule(Vector3.Zero, Matrix.CreateRotationX(MathHelper.PiOver2), radius, height);

            this.Collision.AddPrimitive(capsule, (int)MaterialTable.MaterialID.NormalSmooth);
        }
Beispiel #14
0
        private void InitPrimitiveArchetypes() //formerly InitTexturedQuad
        {
            Transform3D transform3D = new Transform3D(Vector3.Zero, Vector3.Zero,
                                                      Vector3.One, Vector3.UnitZ, Vector3.UnitY);

            EffectParameters effectParameters = new EffectParameters(this.unlitTexturedEffect,
                                                                     this.grass, /*bug*/ Color.White, 1);

            IVertexData vertexData = new VertexData <VertexPositionColorTexture>(
                this.vertices, PrimitiveType.TriangleStrip, 2);

            this.archetypalTexturedQuad = new PrimitiveObject("original texture quad",
                                                              ActorType.Decorator,
                                                              StatusType.Update | StatusType.Drawn,
                                                              transform3D, effectParameters, vertexData);
        }
Beispiel #15
0
        public ModelObject(string id, ActorType actorType,
                           Transform3D transform, EffectParameters effectParameters, Model model, StatusType statusType)
            : base(id, actorType, transform, effectParameters, statusType)
        {
            this.model = model;

            /* 3DS Max models contain meshes (e.g. a table might have 5 meshes i.e. a top and 4 legs) and each mesh contains a bone.
             *  A bone holds the transform that says "move this mesh to this position". Without 5 bones in a table all the meshes would collapse down to be centred on the origin.
             *  Our table, wouldnt look very much like a table!
             *
             *  Take a look at the ObjectManager::DrawObject(GameTime gameTime, ModelObject modelObject) method and see if you can figure out what the line below is doing:
             *
             *  effect.World = modelObject.BoneTransforms[mesh.ParentBone.Index] * modelObject.GetWorldMatrix();
             */
            InitializeBoneTransforms();
        }
Beispiel #16
0
        private void InitStaticModels()
        {
            //transform
            Transform3D transform3D = new Transform3D(new Vector3(0, 5, 0),
                                                      new Vector3(0, 0, 45), //rotation
                                                      new Vector3(1, 1, 1),  //scale
                                                      -Vector3.UnitZ,        //look
                                                      Vector3.UnitY);        //up

            //effectparameters
            EffectParameters effectParameters = new EffectParameters(modelEffect,
                                                                     Content.Load <Texture2D>("Assets/Textures/Props/Crates/crate1"),
                                                                     Color.White, 1);

            //model
            Model model = Content.Load <Model>("Assets/Models/box2");
        }
        //allows us to specify a lowPoly collision skin model
        public TriangleMeshObject(string id, ActorType actorType, Transform3D transform,
                                  EffectParameters effectParameters, Model model, Model lowPolygonModel, MaterialProperties materialProperties)
            : base(id, actorType, transform, effectParameters, model)
        {
            //get the primitive mesh which forms the skin - use low poly if it has been provided in the constructor
            TriangleMesh triangleMesh = null;

            if (lowPolygonModel != null)
            {
                triangleMesh = GetTriangleMesh(lowPolygonModel, this.Transform);
            }
            else
            {
                triangleMesh = GetTriangleMesh(model, this.Transform);
            }

            //add the primitive mesh to the collision skin
            this.Body.CollisionSkin.AddPrimitive(triangleMesh, materialProperties);
        }
Beispiel #18
0
        private void InitStaticModels()
        {
            //transform
            Transform3D transform3D = new Transform3D(new Vector3(0, 5, 0),
                                                      new Vector3(0, 0, 45), //rotation
                                                      new Vector3(1, 1, 1),  //scale
                                                      -Vector3.UnitZ,        //look
                                                      Vector3.UnitY);        //up

            //effectparameters
            EffectParameters effectParameters = new EffectParameters(modelEffect,
                                                                     Content.Load <Texture2D>("Assets/Textures/Props/Crates/crate1"),
                                                                     Color.White, 1);

            //model
            Model model = Content.Load <Model>("Assets/Models/box2");

            //model object
            ModelObject archetypalBoxObject = new ModelObject("car", ActorType.Player,
                                                              StatusType.Drawn | StatusType.Update, transform3D,
                                                              effectParameters, model);

            this.objectManager.Add(archetypalBoxObject);
        }
 public CollidableProjectile(string id, ActorType actorType, StatusType statusType, Transform3D transform3D, EffectParameters effectParameters, IVertexData vertexData, ICollisionPrimitive collisionPrimitive, ObjectManager objectManager) : base(id, actorType, statusType, transform3D, effectParameters, vertexData, collisionPrimitive, objectManager)
 {
 }
        public PlayerCollidablePrimitiveObject(string id, ActorType actorType, Transform3D transform, EffectParameters effectParameters,
                                               StatusType statusType, IVertexData vertexData, ICollisionPrimitive collisionPrimitive,
                                               ManagerParameters managerParameters,
                                               Keys[] moveKeys, float moveSpeed, float rotationSpeed)
            : base(id, actorType, transform, effectParameters, statusType, vertexData, collisionPrimitive, managerParameters.ObjectManager)
        {
            this.moveKeys      = moveKeys;
            this.moveSpeed     = moveSpeed;
            this.rotationSpeed = rotationSpeed;

            //for input
            this.managerParameters = managerParameters;
        }
 public TriangleMeshObject(string id, ActorType actorType, Transform3D transform,
                           EffectParameters effectParameters, Model model, MaterialProperties materialProperties)
     : this(id, actorType, transform, effectParameters, model, null, materialProperties)
 {
 }
        protected PrimitiveObject GetTexturedBillboard(GraphicsDevice graphics, ShapeType shapeType, EffectParameters effectParameters)
        {
            PrimitiveType primitiveType;
            int           primitiveCount;
            IVertexData   vertexData;

            //get the vertices
            VertexBillboard[] vertices = PrimitiveUtility.GetBillboard(out primitiveType, out primitiveCount);

            //create the buffered data
            vertexData = new BufferedVertexData <VertexBillboard>(graphics, vertices, primitiveType, primitiveCount);

            //instanciate the object and return a reference
            return(GetPrimitiveObjectFromVertexData(vertexData, shapeType, effectParameters));
        }
        protected PrimitiveObject GetPrimitiveObjectFromVertexData(IVertexData vertexData, ShapeType shapeType, EffectParameters effectParameters)
        {
            //instanicate the object
            PrimitiveObject primitiveObject = new PrimitiveObject("Archetype - " + shapeType.ToString(),
                                                                  ActorType.NotYetAssigned,
                                                                  Transform3D.Zero,
                                                                  effectParameters.Clone() as EffectParameters,
                                                                  StatusType.Update | StatusType.Drawn,
                                                                  vertexData);

            //add to the dictionary for re-use in any subsequent call to this method
            primitiveDictionary.Add(shapeType, primitiveObject);

            //return a reference to a CLONE of our original object - remember we always clone the dictionary object, rather than modify the archetype in the dictionary
            return(primitiveObject.Clone() as PrimitiveObject);
        }
        public CollidableObject(string id, ActorType actorType, Transform3D transform, EffectParameters effectParameters, Model model)
            : base(id, actorType, transform, effectParameters, model)
        {
            this.body = new Body();
            this.body.ExternalData  = this;
            this.collision          = new CollisionSkin(this.body);
            this.body.CollisionSkin = this.collision;

            //we will only add this event handling in a class that sub-classes CollidableObject e.g. PickupCollidableObject or PlayerCollidableObject
            //this.body.CollisionSkin.callbackFn += CollisionSkin_callbackFn;
        }
Beispiel #25
0
 //used when we don't want to specify status type
 public DrawnActor3D(string id, ActorType actorType, Transform3D transform, EffectParameters effectParameters)
     : this(id, actorType, transform, effectParameters, StatusType.Drawn | StatusType.Update)
 {
 }
Beispiel #26
0
 //default draw and update settings for statusType
 public ModelObject(string id, ActorType actorType,
                    Transform3D transform, EffectParameters effectParameters, Model model)
     : this(id, actorType, transform, effectParameters, model, StatusType.Update | StatusType.Drawn)
 {
 }
Beispiel #27
0
 public override bool Remove()
 {
     this.effectParameters = null;
     return(base.Remove());
 }
Beispiel #28
0
 public PrimitiveObject(string id, ActorType actorType, Transform3D transform,
                        EffectParameters effectParameters, StatusType statusType, IVertexData vertexData)
     : base(id, actorType, transform, effectParameters, statusType)
 {
     this.vertexData = vertexData;
 }
        public MoveablePickupObject(string id, ActorType actorType, Transform3D transform, EffectParameters effectParameters,
                                    Model model, PickupParameters pickupParameters)
            : base(id, actorType, transform, effectParameters, model)
        {
            this.pickupParameters = pickupParameters;

            //register for callback on CDCR
            this.Body.CollisionSkin.callbackFn += CollisionSkin_callbackFn;
        }
Beispiel #30
0
 public DrawnActor3D(string id, ActorType actorType, Transform3D transform, EffectParameters effectParameters, StatusType statusType)
     : base(id, actorType, transform, statusType)
 {
     this.effectParameters = effectParameters;
 }