Example #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);
        }
Example #2
0
 //used to make a collidable primitives from an existing PrimitiveObject (i.e. the type returned by the PrimitiveFactory
 public CollidablePrimitiveObject(PrimitiveObject primitiveObject, ICollisionPrimitive collisionPrimitive, ObjectManager objectManager)
     : base(primitiveObject.ID, primitiveObject.ActorType, primitiveObject.Transform, primitiveObject.EffectParameters,
            primitiveObject.StatusType, primitiveObject.VertexData)
 {
     this.collisionPrimitive = collisionPrimitive;
     //unusual to pass this in but we use it to test for collisions - see Update();
     this.objectManager = objectManager;
 }
Example #3
0
 private void InitGround()
 {
     //grass
     primitiveObject    = this.archetypalTexturedQuad.Clone() as PrimitiveObject;
     primitiveObject.ID = "grass";
     primitiveObject.EffectParameters.Texture      = this.grass;
     primitiveObject.Transform3D.Scale             = new Vector3(worldScale, worldScale, 1);
     primitiveObject.Transform3D.RotationInDegrees = new Vector3(90, 90, 0);
     this.objectManager.Add(primitiveObject);
 }
        //used to make a player collidable primitives from an existing PrimitiveObject (i.e. the type returned by the PrimitiveFactory
        public PlayerCollidablePrimitiveObject(PrimitiveObject primitiveObject, ICollisionPrimitive collisionPrimitive,
                                               ManagerParameters managerParameters, Keys[] moveKeys, float moveSpeed, float rotationSpeed)
            : base(primitiveObject, collisionPrimitive, managerParameters.ObjectManager)
        {
            this.moveKeys      = moveKeys;
            this.moveSpeed     = moveSpeed;
            this.rotationSpeed = rotationSpeed;

            //for input
            this.managerParameters = managerParameters;
        }
Example #5
0
        //draw a NON-TEXTURED primitive i.e. vertices (and possibly indices) defined by the user
        private void DrawObject(GameTime gameTime, PrimitiveObject primitiveObject, Camera3D activeCamera)
        {
            if (activeCamera.BoundingFrustum.Intersects(primitiveObject.BoundingSphere))
            {
                primitiveObject.EffectParameters.SetParameters(activeCamera);
                primitiveObject.EffectParameters.SetWorld(primitiveObject.GetWorldMatrix());
                primitiveObject.VertexData.Draw(gameTime, primitiveObject.EffectParameters.Effect);

#if DEBUG
                debugDrawCount++;
#endif
            }
        }
        //draw a NON-TEXTURED primitive i.e. vertices (and possibly indices) defined by the user
        private void DrawObject(GameTime gameTime, PrimitiveObject primitiveObject)
        {
            BasicEffect effect = primitiveObject.Effect as BasicEffect;

            //W, V, P, Apply, Draw
            effect.World      = primitiveObject.GetWorldMatrix();
            effect.View       = (this.Game as Main).CameraManager.ActiveCamera.View;
            effect.Projection = (this.Game as Main).CameraManager.ActiveCamera.ProjectionParameters.Projection;

            effect.DiffuseColor = primitiveObject.Color.ToVector3();
            effect.Alpha        = primitiveObject.Alpha;

            effect.CurrentTechnique.Passes[0].Apply();
            primitiveObject.VertexData.Draw(gameTime, effect);
        }
Example #7
0
        private void InitSkybox()
        {
            //back
            primitiveObject = this.archetypalTexturedQuad.Clone() as PrimitiveObject;
            //  primitiveObject.StatusType = StatusType.Off; //Experiment of the effect of StatusType
            primitiveObject.ID = "sky back";
            primitiveObject.EffectParameters.Texture = this.backSky;
            primitiveObject.Transform3D.Scale        = new Vector3(worldScale, worldScale, 1);
            primitiveObject.Transform3D.Translation  = new Vector3(0, 0, -worldScale / 2.0f);
            this.objectManager.Add(primitiveObject);

            //left
            primitiveObject    = this.archetypalTexturedQuad.Clone() as PrimitiveObject;
            primitiveObject.ID = "left back";
            primitiveObject.EffectParameters.Texture      = this.leftSky;
            primitiveObject.Transform3D.Scale             = new Vector3(worldScale, worldScale, 1);
            primitiveObject.Transform3D.RotationInDegrees = new Vector3(0, 90, 0);
            primitiveObject.Transform3D.Translation       = new Vector3(-worldScale / 2.0f, 0, 0);
            this.objectManager.Add(primitiveObject);

            //right
            primitiveObject    = this.archetypalTexturedQuad.Clone() as PrimitiveObject;
            primitiveObject.ID = "sky right";
            primitiveObject.EffectParameters.Texture      = this.rightSky;
            primitiveObject.Transform3D.Scale             = new Vector3(worldScale, worldScale, 20);
            primitiveObject.Transform3D.RotationInDegrees = new Vector3(0, -90, 0);
            primitiveObject.Transform3D.Translation       = new Vector3(worldScale / 2.0f, 0, 0);
            this.objectManager.Add(primitiveObject);


            //top
            primitiveObject    = this.archetypalTexturedQuad.Clone() as PrimitiveObject;
            primitiveObject.ID = "sky top";
            primitiveObject.EffectParameters.Texture      = this.topSky;
            primitiveObject.Transform3D.Scale             = new Vector3(worldScale, worldScale, 1);
            primitiveObject.Transform3D.RotationInDegrees = new Vector3(90, -90, 0);
            primitiveObject.Transform3D.Translation       = new Vector3(0, worldScale / 2.0f, 0);
            this.objectManager.Add(primitiveObject);

            //to do...front
            primitiveObject    = this.archetypalTexturedQuad.Clone() as PrimitiveObject;
            primitiveObject.ID = "sky front";
            primitiveObject.EffectParameters.Texture      = this.frontSky;
            primitiveObject.Transform3D.Scale             = new Vector3(worldScale, worldScale, 1);
            primitiveObject.Transform3D.RotationInDegrees = new Vector3(0, 180, 0);
            primitiveObject.Transform3D.Translation       = new Vector3(0, 0, worldScale / 2.0f);
            this.objectManager.Add(primitiveObject);
        }
Example #8
0
        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);
        }
Example #9
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);
        }
Example #10
0
        public new object Clone()
        {
            PrimitiveObject actor = new PrimitiveObject("clone - " + ID,                                 //deep
                                                        this.ActorType,                                  //deep
                                                        (Transform3D)this.Transform.Clone(),             //deep
                                                        (EffectParameters)this.EffectParameters.Clone(), //deep
                                                        this.StatusType,                                 //deep
                                                        this.vertexData);                                //shallow - its ok if objects refer to the same vertices

            if (this.ControllerList != null)
            {
                //clone each of the (behavioural) controllers
                foreach (IController controller in this.ControllerList)
                {
                    actor.AttachController((IController)controller.Clone());
                }
            }

            return(actor);
        }