Exemplo n.º 1
0
        /// <summary>
        /// Draw wireframe/solid of any of the RigidBody.Shape primitives, except
        /// TerrainShape... for now.
        /// </summary>
        /// <param name="body">body to draw</param>
        /// <param name="color">Color to bias wireframe/solid towards</param>
        /// <param name="drawSolid">True: draw solid, False: draw wireframe</param>
        /// <param name="enableLightning">enable the default lightning</param>
        public void DrawBody(RigidBody body, Color color, bool drawSolid, bool enableLightning)
        {
            GeometricPrimitive primitive = null;
            Matrix scaleMatrix;

            #region decide scale and shape
            Shape shape = body.Shape;
            if (shape is BoxShape)
            {
                primitive = Primitives.Box;
                scaleMatrix = Matrix.CreateScale(Conversion.ToXNAVector((shape as BoxShape).Size));
            }
            else if (shape is SphereShape)
            {
                primitive = Primitives.Sphere;
                scaleMatrix = Matrix.CreateScale((shape as SphereShape).Radius);
            }
            else if (shape is CylinderShape)
            {
                primitive = Primitives.Cylinder;
                CylinderShape cs = shape as CylinderShape;
                scaleMatrix = Matrix.CreateScale(cs.Radius, cs.Height, cs.Radius);
            }
            else if (shape is CapsuleShape)
            {
                CapsuleShape cs = shape as CapsuleShape;
                primitive = CapsulePrimitive.GetCapsulePrimitive(
                    BasicEffect.GraphicsDevice, cs.Radius * 2, cs.Length, 6);
                scaleMatrix = Matrix.Identity;

            }
            else if (shape is ConeShape)
            {
                primitive = Primitives.Cone;
                ConeShape cs = shape as ConeShape;
                scaleMatrix = Matrix.CreateScale(cs.Radius, cs.Height, cs.Radius);
            }
            else
            {
                throw new ArgumentException("Unable to draw given body (is it a TerrainShape?");
            }
            #endregion

            BasicEffect.World = scaleMatrix * body.GetWorldMatrix();
            BasicEffect.DiffuseColor = color.ToVector3();

            BasicEffect.LightingEnabled = enableLightning;
            if (drawSolid)
            {
                primitive.DrawSolid(BasicEffect);
            }
            else
            {
                primitive.DrawWireFrame(BasicEffect);
            }
        }
Exemplo n.º 2
0
        public void DrawModel(Model model, RigidBody body, Matrix scale)
        {
            engine.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    //effect.DiffuseColor = color.ToVector3();
                    setupLightning(effect);
                    effect.World = mesh.ParentBone.Transform*scale*body.GetWorldMatrix();

                    effect.View = engine.Camera.View;
                    effect.Projection = engine.Camera.Projection;
                }
                mesh.Draw();
            }
        }