Exemplo n.º 1
0
 public CameraScene(List <CirclePrimitive> circles, List <BoxPrimitive> boxes, BoxPrimitive room_bounds)
 {
     m_room_bounds = room_bounds;
     m_circles     = circles;
     m_boxes       = boxes;
 }
Exemplo n.º 2
0
        /// <inheritdoc />
        protected override void LoadContent()
        {
            Random = new Random(5);

            SpriteFont = Game.Content.Load <SpriteFont>(ContentFolderSpriteFonts + "Arial");

            //The buffer pool is a source of raw memory blobs for the engine to use.
            BufferPool = new BufferPool();

            Radii  = new List <float>();
            Camera = new SimpleCamera(GraphicsDevice.Viewport.AspectRatio, new Vector3(40, 60, 150), 55, 0.4f);

            var boxTexture = Game.Content.Load <Texture2D>(ContentFolderTextures + "wood/caja-madera-3");

            Box = new BoxPrimitive(GraphicsDevice, Vector3.One * 10, boxTexture);

            Sphere = new SpherePrimitive(GraphicsDevice);

            SphereHandles = new List <BodyHandle>();
            BoxHandles    = new List <BodyHandle>();

            var targetThreadCount = Math.Max(1,
                                             Environment.ProcessorCount > 4 ? Environment.ProcessorCount - 2 : Environment.ProcessorCount - 1);

            ThreadDispatcher = new SimpleThreadDispatcher(targetThreadCount);

            // This are meshes/model/primitives collections to render
            // The PositionFirstTimestepper is the simplest timestepping mode, but since it integrates velocity into position at the start of the frame, directly modified velocities outside of the timestep
            // will be integrated before collision detection or the solver has a chance to intervene. That's fine in this demo. Other built-in options include the PositionLastTimestepper and the SubsteppingTimestepper.
            // Note that the timestepper also has callbacks that you can use for executing logic between processing stages, like BeforeCollisionDetection.
            Simulation = Simulation.Create(BufferPool, new NarrowPhaseCallbacks(),
                                           new PoseIntegratorCallbacks(new NumericVector3(0, -100, 0)), new PositionFirstTimestepper());

            // Creates a floor
            var floorTexture = Game.Content.Load <Texture2D>(ContentFolderTextures + "floor/adoquin-2");

            //Floor = new QuadPrimitive(GraphicsDevice);

            TilingEffect = Game.Content.Load <Effect>(ContentFolderEffects + "TextureTiling");
            TilingEffect.Parameters["Texture"].SetValue(floorTexture);
            TilingEffect.Parameters["Tiling"].SetValue(Vector2.One * 50f);

            FloorWorld = Matrix.CreateScale(400f) * Matrix.CreateTranslation(new Vector3(75, 0, -150));
            Simulation.Statics.Add(new StaticDescription(new NumericVector3(0, -0.5f, 0),
                                                         new CollidableDescription(Simulation.Shapes.Add(new Box(2000, 1, 2000)), 0.1f)));

            BoxesWorld   = new List <Matrix>();
            SpheresWorld = new List <Matrix>();

            // Single Box
            var radius = 10;

            for (var j = 0; j < 5; j++)
            {
                for (var i = 0; i < 20; i++)
                {
                    var boxShape = new Box(radius, radius, radius);
                    boxShape.ComputeInertia(0.4f, out var boxInertia);
                    var boxIndex = Simulation.Shapes.Add(boxShape);
                    var position = new NumericVector3(-30 + i * 10 + 1, j * 10 + 1, -40);

                    var bodyDescription = BodyDescription.CreateDynamic(position, boxInertia,
                                                                        new CollidableDescription(boxIndex, 0.1f), new BodyActivityDescription(0.01f));

                    var bodyHandle = Simulation.Bodies.Add(bodyDescription);

                    BoxHandles.Add(bodyHandle);
                }
            }

            base.LoadContent();
        }
Exemplo n.º 3
0
 public CsgObject DoCopyAndFlatten(BoxPrimitive objectToProcess)
 {
     return(new BoxPrimitive(objectToProcess));
 }
Exemplo n.º 4
0
 public IRayTraceable GetIRayTraceableRecursive(BoxPrimitive objectToProcess)
 {
     return(new BoxShape(Vector3.Zero, objectToProcess.Size, DefaultMaterial));
 }
Exemplo n.º 5
0
        /// <inheritdoc />
        public override void Draw(GameTime gameTime)
        {
            // Calculate the ViewProjection matrix
            var viewProjection = Camera.View * Camera.Projection;

            // Robot drawing
            Robot.Draw(RobotWorld, Camera.View, Camera.Projection);

            // Floor drawing

            // Set the Technique inside the TilingEffect to "BaseTiling", we want to control the tiling on the floor
            // Using its original Texture Coordinates
            TilingEffect.CurrentTechnique = TilingEffect.Techniques["BaseTiling"];
            // Set the Tiling value
            TilingEffect.Parameters["Tiling"].SetValue(new Vector2(10f, 10f));
            // Set the WorldViewProjection matrix
            TilingEffect.Parameters["WorldViewProjection"].SetValue(FloorWorld * viewProjection);
            // Set the Texture that the Floor will use
            TilingEffect.Parameters["Texture"].SetValue(StonesTexture);
            Quad.Draw(TilingEffect);


            // Steps drawing

            // Set the Technique inside the TilingEffect to "WorldTiling"
            // We want to use the world position of the steps to define how to sample the Texture
            TilingEffect.CurrentTechnique = TilingEffect.Techniques["WorldTiling"];
            // Set the Texture that the Steps will use
            TilingEffect.Parameters["Texture"].SetValue(CobbleTexture);
            // Set the Tiling value
            TilingEffect.Parameters["Tiling"].SetValue(Vector2.One * 0.05f);

            // Draw every Step
            for (int index = 0; index < StairsWorld.Length; index++)
            {
                // Get the World Matrix
                var matrix = StairsWorld[index];
                // Set the World Matrix
                TilingEffect.Parameters["World"].SetValue(matrix);
                // Set the WorldViewProjection Matrix
                TilingEffect.Parameters["WorldViewProjection"].SetValue(matrix * viewProjection);
                BoxPrimitive.Draw(TilingEffect);
            }


            // Draw the Box, setting every matrix and its Texture
            BoxesEffect.World      = BoxWorld;
            BoxesEffect.View       = Camera.View;
            BoxesEffect.Projection = Camera.Projection;

            BoxesEffect.Texture = WoodenTexture;
            BoxPrimitive.Draw(BoxesEffect);


            // Gizmos Drawing
            for (int index = 0; index < Colliders.Length; index++)
            {
                var box     = Colliders[index];
                var center  = BoundingVolumesExtensions.GetCenter(box);
                var extents = BoundingVolumesExtensions.GetExtents(box);
                Game.Gizmos.DrawCube(center, extents * 2f, Color.Red);
            }

            Game.Gizmos.DrawCylinder(RobotCylinder.Transform, Color.Yellow);

            base.Draw(gameTime);
        }