コード例 #1
0
        private void DrawBoundingPrimitive(GameTime gameTime, ICollisionPrimitive collisionPrimitive, Color color)
        {
            if (collisionPrimitive is SphereCollisionPrimitive)
            {
                int primitiveCount = 0;
                vertexData = new VertexData <VertexPositionColor>(VertexFactory.GetSphereVertices(1, 10, out primitiveCount),
                                                                  PrimitiveType.LineStrip, primitiveCount);

                coll  = collisionPrimitive as SphereCollisionPrimitive;
                world = Matrix.Identity * Matrix.CreateScale(coll.BoundingSphere.Radius) * Matrix.CreateTranslation(coll.BoundingSphere.Center);
                wireframeEffect.World        = world;
                wireframeEffect.View         = cameraManager.ActiveCamera.View;
                wireframeEffect.Projection   = cameraManager.ActiveCamera.Projection;
                wireframeEffect.DiffuseColor = Color.White.ToVector3();
                wireframeEffect.CurrentTechnique.Passes[0].Apply();
                vertexData.Draw(gameTime, wireframeEffect);
            }
            else
            {
                BoxCollisionPrimitive coll    = collisionPrimitive as BoxCollisionPrimitive;
                BoundingBoxBuffers    buffers = BoundingBoxDrawer.CreateBoundingBoxBuffers(coll.BoundingBox, GraphicsDevice);
                BoundingBoxDrawer.DrawBoundingBox(buffers, wireframeEffect, GraphicsDevice,
                                                  cameraManager.ActiveCamera);
            }
        }
コード例 #2
0
        private DrawnActor3D getObjectFromColor(Color color, Vector3 translation)
        {
            //if the pixel is red then draw a tall (stretched collidable unlit cube)
            if (color.Equals(new Color(255, 0, 0)))
            {
                PrimitiveObject archetype
                    = archetypeDictionary["lit textured cube"] as PrimitiveObject;

                PrimitiveObject drawnActor3D = archetype.Clone() as PrimitiveObject;

                //   PrimitiveObject drawnActor3D
                //       = archetypeDictionary["lit textured pyramid"].Clone() as PrimitiveObject;

                //change it a bit
                drawnActor3D.ID = "cube " + count++;
                drawnActor3D.Transform3D.Scale             = 10 * new Vector3(2, 3, 1);
                drawnActor3D.EffectParameters.Texture      = textureDictionary["walls"];
                drawnActor3D.EffectParameters.Alpha        = 1;
                drawnActor3D.Transform3D.Translation       = translation;
                drawnActor3D.Transform3D.RotationInDegrees = new Vector3(0, 0, 0);


                BoxCollisionPrimitive collisionPrimitive = new BoxCollisionPrimitive(drawnActor3D.Transform3D);

                //make a collidable object and pass in the primitive
                CollidablePrimitiveObject collidablePrimitiveObject = new CollidablePrimitiveObject(
                    drawnActor3D.ID,
                    ActorType.CollidableDecorator,
                    StatusType.Update | StatusType.Drawn,
                    drawnActor3D.Transform3D,
                    drawnActor3D.EffectParameters,
                    drawnActor3D.IVertexData,
                    collisionPrimitive,
                    objectManager);

                return(collidablePrimitiveObject);
            }

            else if (color.Equals(new Color(0, 0, 255)))
            {
                PrimitiveObject archetype
                    = archetypeDictionary["lit textured pyramid"] as PrimitiveObject;

                PrimitiveObject drawnActor3D = archetype.Clone() as PrimitiveObject;

                //change it a bit
                drawnActor3D.ID = "Pyramid " + count++;
                drawnActor3D.Transform3D.Scale             = 10 * new Vector3(1, 1, 1);
                drawnActor3D.EffectParameters.Texture      = textureDictionary["Warning"];
                drawnActor3D.EffectParameters.Alpha        = 1;
                drawnActor3D.Transform3D.Translation       = translation;
                drawnActor3D.Transform3D.RotationInDegrees = new Vector3(0, 0, 0);


                BoxCollisionPrimitive collisionPrimitive = new BoxCollisionPrimitive(drawnActor3D.Transform3D);

                //make a collidable object and pass in the primitive
                CollidablePrimitiveObject collidablePrimitiveObject = new CollidablePrimitiveObject(
                    drawnActor3D.ID,
                    ActorType.CollidableObstacle,
                    StatusType.Update | StatusType.Drawn,
                    drawnActor3D.Transform3D,
                    drawnActor3D.EffectParameters,
                    drawnActor3D.IVertexData,
                    collisionPrimitive,
                    objectManager);

                return(collidablePrimitiveObject);
            }

            return(null);
        }