Manages and draws models.
 /// <summary>
 /// Constructs a new display model.
 /// </summary>
 /// <param name="entity">Entity to follow.</param>
 /// <param name="model">Model to draw on the entity.</param>
 /// <param name="modelDrawer">Model drawer to use.</param>
 public Model3D(Entity entity, Model model, ModelDrawer modelDrawer)
 {
     Drawer         = modelDrawer;
     LocalTransform = Matrix.Identity;
     Entity         = entity;
     Model          = model;
 }
 /// <summary>
 /// Constructs a new display model.
 /// </summary>
 /// <param name="entity">Entity to follow.</param>
 /// <param name="model">Model to draw on the entity.</param>
 /// <param name="modelDrawer">Model drawer to use.</param>
 public DisplayEntityModel(Entity entity, Model model, ModelDrawer modelDrawer)
     : base(modelDrawer)
 {
     LocalTransform = Matrix.Identity;
     Entity         = entity;
     Model          = model;
 }
Beispiel #3
0
 /// <summary>
 /// Constructs a new display model.
 /// </summary>
 /// <param name="entity">Entity to follow.</param>
 /// <param name="model">Model to draw on the entity.</param>
 /// <param name="modelDrawer">Model drawer to use.</param>
 public DisplayEntityModelTest(Entity entity, Model model, ModelDrawer modelDrawer)
     : base(modelDrawer)
 {
     OffsetTransform = Matrix.Identity;
     Entity          = entity;
     Model           = model;
 }
Beispiel #4
0
 /// <summary>
 /// Constructs a new display model.
 /// </summary>
 /// <param name="entity">Entity to follow.</param>
 /// <param name="model">Model to draw on the entity.</param>
 /// <param name="modelDrawer">Model drawer to use.</param>
 public DisplayEntityModel(Entity entity, Model model, ModelDrawer modelDrawer)
     : base(modelDrawer)
 {
     OffsetTransform = Matrix.Identity;
     Entity = entity;
     Model = model;
 }
Beispiel #5
0
 public ActorContainer(Space space, ModelDrawer modelDrawer, LineDrawer constraintDrawer, LightDrawer lightDrawer)
 {
     _space = space;
     _meshes = new List<LPPMesh>();
     _deleteList = new List<Actor>();
     _actors = new List<Actor>();
     _components = new List<Component>();
     _modelDrawer = modelDrawer;
     _constraintDrawer = constraintDrawer;
     _lightDrawer = lightDrawer;
     _actorDictionary = new Dictionary<string, Actor>();
     Content = Game1.thegame.Content;
 }
Beispiel #6
0
        public World(ModelDrawer debugModelDrawer)
        {
            mDebugModelDrawer = debugModelDrawer;
            mGameObjects = new List<IGameObject>();
            mActors = new List<IActor>();
            Space = new Space();

            // Add the optimal number of threads for physics.
            // TODO: Add correct cores for Xbox.
            for (int i = 0; i < System.Environment.ProcessorCount; i++)
            {
                Space.ThreadManager.AddThread();
            }

            mUncommittedGameObjectAdditions = new List<IGameObject>();
            mUncommittedGameObjectRemovals = new List<IGameObject>();

            Space.ForceUpdater.Gravity = new Vector3(0, -9.81f * 3.0f, 0);
        }
Beispiel #7
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            Manager = new Manager(this, graphics, "Default");
            Manager.AutoCreateRenderTarget = true;
            Manager.Initialize();

            ModelDrawer = new BruteModelDrawer(this);
            ConstraintDrawer = new LineDrawer(this);
            LightDrawer = new LightDrawer(this);
            space = new Space();
            space.ForceUpdater.Gravity = new Vector3(0.0f, -10.0f, 0.0f);
            Actors = new ActorContainer(space, ModelDrawer, ConstraintDrawer, LightDrawer);

            base.Initialize();
        }
 protected CustomMesh(ModelDrawer drawer, T displayedObject)
     : base(drawer)
 {
     DisplayedObject = displayedObject;
 }
Beispiel #9
0
 /// <summary>
 /// Creates the display object for the entity.
 /// </summary>
 /// <param name="drawer">Drawer managing this display object.</param>
 /// <param name="displayedObject">Entity to draw.</param>
 public DisplayInstancedMesh(ModelDrawer drawer, InstancedMesh displayedObject)
     : base(drawer, displayedObject)
 {
 }
 /// <summary>
 /// Constructs a new display model.
 /// </summary>
 /// <param name="model">Model to draw on the entity.</param>
 /// <param name="modelDrawer">Model drawer to use.</param>
 public Model3D(Model model, ModelDrawer modelDrawer)
 {
     Drawer         = modelDrawer;
     Model          = model;
     LocalTransform = Matrix.Identity;
 }
Beispiel #11
0
 /// <summary>
 /// Creates the display object for the entity.
 /// </summary>
 /// <param name="drawer">Drawer managing this display object.</param>
 /// <param name="displayedObject">Entity to draw.</param>
 public DisplayMinkowskiSumTest(ModelDrawer drawer, MinkowskiSum displayedObject)
     : base(drawer, displayedObject)
 {
 }
Beispiel #12
0
 protected SelfDrawingModelDisplayObject(ModelDrawer modelDrawer)
 {
     ModelDrawer = modelDrawer;
 }
 /// <summary>
 /// Constructs a new display model.
 /// </summary>
 /// <param name="model">Model to draw on the entity.</param>
 /// <param name="modelDrawer">Model drawer to use.</param>
 public DisplayModel(Model model, ModelDrawer modelDrawer)
     : base(modelDrawer)
 {
     Model = model;
 }
 protected SelfDrawingModelDisplayObject(ModelDrawer modelDrawer)
 {
     ModelDrawer = modelDrawer;
 }
Beispiel #15
0
 /// <summary>
 /// Constructs a new
 /// </summary>
 /// <param name="drawer">Drawer to use.</param>
 /// <param name="entity">Entity to draw.</param>
 public DisplayEntity(ModelDrawer drawer, Entity entity)
     : base(drawer, entity)
 {
 }
Beispiel #16
0
 /// <summary>
 /// Creates the display object for the entity.
 /// </summary>
 /// <param name="drawer">Drawer managing this display object.</param>
 /// <param name="displayedObject">Entity to draw.</param>
 public DisplayWrappedBodyTest(ModelDrawer drawer, WrappedBody displayedObject)
     : base(drawer, displayedObject)
 {
 }
Beispiel #17
0
 /// <summary>
 /// Creates the display object for the entity.
 /// </summary>
 /// <param name="drawer">Drawer managing this display object.</param>
 /// <param name="displayedObject">Entity to draw.</param>
 public DisplayCylinderTest(ModelDrawer drawer, Cylinder displayedObject)
     : base(drawer, displayedObject)
 {
 }
Beispiel #18
0
        private void LoadLevel(List<string> parameters)
        {
            if (parameters.Count == 0 || !File.Exists(parameters[0]))
            {
                return;
            }

            if (mGameStates[mGameStates.Count - 1] is World)
            {
                DebugModelDrawer = null;
                DebugModelDrawer = new InstancedModelDrawer(this);
                DebugModelDrawer.IsWireframe = true;

                (mGameStates[mGameStates.Count - 1] as GameWorld).Clear();
                mGameStates[mGameStates.Count - 1] = null;
                mGameStates[mGameStates.Count - 1] = new GameWorld(DebugModelDrawer);
                (mGameStates[mGameStates.Count - 1] as GameWorld).AddLevelFromFile(parameters[0], Vector3.Zero, Quaternion.Identity, Vector3.One);
            }
        }
Beispiel #19
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            DebugModelDrawer = new InstancedModelDrawer(this);
            DebugModelDrawer.IsWireframe = true;
            spriteBatch = new SpriteBatch(GraphicsDevice);

            try
            {
                GraphicsManager.Initialize(GraphicsDevice, spriteBatch);
                AssetLibrary.LoadContent(Content);
                CollisionMeshManager.LoadContent(Content);
                SoundManager.LoadContent(Content);
                ExitToMenu();
            }
            catch (Exception e)
            {
                TextWriter tw = new StreamWriter("log.txt");
                tw.WriteLine(e.Message);
                tw.WriteLine(e.StackTrace);
                tw.Close();
                throw e;
            }
        }
 /// <summary>
 /// Creates the display object for the object.
 /// </summary>
 /// <param name="drawer">Drawer managing this display object.</param>
 /// <param name="displayedObject">Object to draw.</param>
 public DisplayStaticMesh(ModelDrawer drawer, StaticMesh displayedObject)
     : base(drawer, displayedObject)
 {
 }
Beispiel #21
0
 /// <summary>
 /// Creates the display object for the entity.
 /// </summary>
 /// <param name="drawer">Drawer managing this display object.</param>
 /// <param name="displayedObject">Entity to draw.</param>
 public DisplayBoxTest(ModelDrawer drawer, Box displayedObject)
     : base(drawer, displayedObject)
 {
 }
Beispiel #22
0
 /// <summary>
 /// Creates the display object for the entity.
 /// </summary>
 /// <param name="drawer">Drawer managing this display object.</param>
 /// <param name="displayedObject">Entity to draw.</param>
 public DisplaySphereTest(ModelDrawer drawer, Sphere displayedObject)
     : base(drawer, displayedObject)
 {
 }
Beispiel #23
0
 /// <summary>
 /// Creates the display object for the entity.
 /// </summary>
 /// <param name="drawer">Drawer managing this display object.</param>
 /// <param name="displayedObject">Entity to draw.</param>
 public DisplayCompoundBodyTest(ModelDrawer drawer, CompoundBody displayedObject)
     : base(drawer, displayedObject)
 {
 }
Beispiel #24
0
 /// <summary>
 /// Constructs a new display model.
 /// </summary>
 /// <param name="model">Model to draw on the entity.</param>
 /// <param name="modelDrawer">Model drawer to use.</param>
 public DisplayModel(Model model, ModelDrawer modelDrawer)
     : base(modelDrawer)
 {
     Model = model;
 }
Beispiel #25
0
 /// <summary>
 /// Creates the display object for the entity.
 /// </summary>
 /// <param name="drawer">Drawer managing this display object.</param>
 /// <param name="displayedObject">Entity to draw.</param>
 public DisplayTriangleMesh(ModelDrawer drawer, TriangleMesh displayedObject)
     : base(drawer, displayedObject)
 {
 }
Beispiel #26
0
 protected ModelDisplayObjectBase(ModelDrawer drawer)
 {
     Drawer           = drawer;
     BatchInformation = new BatchInformation();
     TextureIndex     = Random.Next(8);
 }
        /// <summary>
        /// Constructs the front end and the internal physics representation of the vehicle.
        /// </summary>
        /// <param name="position">Position of the tank.</param>
        /// <param name="owningSpace">Space to add the vehicle to.</param>
        /// <param name="camera">Camera to attach to the vehicle.</param>
        /// <param name="game">Running game.</param>
        /// <param name="drawer">Drawer used to draw the tank.</param>
        /// <param name="wheelModel">Model to use for the 'wheels' of the tank.</param>
        /// <param name="wheelTexture">Texture of the wheels on the tank.</param>
        public TankInput(Vector3 position, Space owningSpace, Camera camera, DemosGame game, ModelDrawer drawer, Model wheelModel, Texture2D wheelTexture)
        {
            var bodies = new List<CompoundShapeEntry>()
            {
                new CompoundShapeEntry(new BoxShape(4f, 1, 8), new Vector3(0, 0, 0), 500),
                new CompoundShapeEntry(new BoxShape(3, .7f, 4f), new Vector3(0, .5f + .35f, .5f), 1)
            };
            var body = new CompoundBody(bodies, 501);
            body.CollisionInformation.LocalPosition = new Vector3(0, .5f, 0);
            body.Position = (position); //At first, just keep it out of the way.
            Vehicle = new Vehicle(body);

            #region RaycastWheelShapes

            //The wheel model used is not aligned initially with how a wheel would normally look, so rotate them.
            MaximumDriveForce = 1800;
            BaseSlidingFriction = 3;

            Matrix wheelGraphicRotation = Matrix.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2);
            for (int i = 0; i < 6; i++)
            {
                var toAdd = new Wheel(
                    new RaycastWheelShape(.375f, wheelGraphicRotation),
                    new WheelSuspension(2000, 300f, Vector3.Down, 1.3f, new Vector3(-1.9f, 0, -2.9f + i * 1.15f)),
                    new WheelDrivingMotor(10, MaximumDriveForce, MaximumDriveForce),
                    new WheelBrake(7, 7, 1.0f),
                    new WheelSlidingFriction(BaseSlidingFriction, BaseSlidingFriction));
                toAdd.DrivingMotor.GripFrictionBlender = FrictionBlender;
                toAdd.Brake.FrictionBlender = FrictionBlender;
                toAdd.SlidingFriction.FrictionBlender = FrictionBlender;
                Vehicle.AddWheel(toAdd);
                leftTrack.Add(toAdd);
            }
            for (int i = 0; i < 6; i++)
            {
                var toAdd = new Wheel(
                    new RaycastWheelShape(.375f, wheelGraphicRotation),
                    new WheelSuspension(2000, 300f, Vector3.Down, 1.3f, new Vector3(1.9f, 0, -2.9f + i * 1.15f)),
                    new WheelDrivingMotor(10, 2000, 1000),
                    new WheelBrake(7, 7, 1.0f),
                    new WheelSlidingFriction(BaseSlidingFriction, BaseSlidingFriction));
                toAdd.DrivingMotor.GripFrictionBlender = FrictionBlender;
                toAdd.Brake.FrictionBlender = FrictionBlender;
                toAdd.SlidingFriction.FrictionBlender = FrictionBlender;
                Vehicle.AddWheel(toAdd);
                rightTrack.Add(toAdd);
            }

            #endregion

            foreach (Wheel wheel in Vehicle.Wheels)
            {
                //This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes.
                wheel.Shape.FreezeWheelsWhileBraking = true;

                //By default, wheels use as many iterations as the space.  By lowering it,
                //performance can be improved at the cost of a little accuracy.
                wheel.Suspension.SolverSettings.MaximumIterationCount = 1;
                wheel.Brake.SolverSettings.MaximumIterationCount = 1;
                wheel.SlidingFriction.SolverSettings.MaximumIterationCount = 1;
                wheel.DrivingMotor.SolverSettings.MaximumIterationCount = 1;
            }

            Space = owningSpace;

            Space.Add(Vehicle);
            ModelDrawer = drawer;
            DisplayModel model;
            WheelModels = new List<DisplayModel>();
            for (int k = 0; k < Vehicle.Wheels.Count; k++)
            {
                Vehicle.Wheels[k].Shape.Detector.Tag = "noDisplayObject";
                model = new DisplayModel(wheelModel, ModelDrawer);
                ModelDrawer.Add(model);
                WheelModels.Add(model);
                model.Texture = wheelTexture;
            }



            CameraControlScheme = new ChaseCameraControlScheme(Vehicle.Body, new Vector3(0, 0.6f, 0), true, 10, camera, game);

        }
 protected ModelDisplayObjectBase(ModelDrawer drawer)
 {
     Drawer = drawer;
     BatchInformation = new BatchInformation();
     TextureIndex = Random.Next(8);
 }
 /// <summary>
 /// Constructs a new display entity.
 /// </summary>
 /// <param name="drawer">Drawer to use.</param>
 /// <param name="entityCollidable">EntityCollidable to draw.</param>
 public DisplayEntityCollidable(ModelDrawer drawer, EntityCollidable entityCollidable)
     : base(drawer, entityCollidable)
 {
 }
Beispiel #30
0
 public GameWorld(ModelDrawer debugModelDrawer)
     : base(debugModelDrawer)
 {
 }
Beispiel #31
0
 /// <summary>
 /// Creates the display object for the entity.
 /// </summary>
 /// <param name="drawer">Drawer managing this display object.</param>
 /// <param name="displayedObject">Entity to draw.</param>
 public DisplayConeTest(ModelDrawer drawer, Cone displayedObject)
     : base(drawer, displayedObject)
 {
 }
Beispiel #32
0
 /// <summary>
 /// Creates the display object for the entity.
 /// </summary>
 /// <param name="drawer">Drawer managing this display object.</param>
 /// <param name="displayedObject">Entity to draw.</param>
 public DisplayTerrain(ModelDrawer drawer, Terrain displayedObject)
     : base(drawer, displayedObject)
 {
 }
Beispiel #33
0
 /// <summary>
 /// Creates the display object for the entity.
 /// </summary>
 /// <param name="drawer">Drawer managing this display object.</param>
 /// <param name="displayedObject">Entity to draw.</param>
 public DisplayFluid(ModelDrawer drawer, FluidVolume displayedObject)
     : base(drawer, displayedObject)
 {
 }
Beispiel #34
0
 /// <summary>
 /// Constructs a new
 /// </summary>
 /// <param name="drawer">Drawer to use.</param>
 /// <param name="entity">Entity to draw.</param>
 protected DisplayEntity(ModelDrawer drawer, T entity)
     : base(drawer, entity)
 {
 }
Beispiel #35
0
 /// <summary>
 /// Creates the display object for the entity.
 /// </summary>
 /// <param name="drawer">Drawer managing this display object.</param>
 /// <param name="displayedObject">Entity to draw.</param>
 public DisplayTriangleTest(ModelDrawer drawer, Triangle displayedObject)
     : base(drawer, displayedObject)
 {
 }
        protected override void Initialize()
        {
            ModelDrawer = new InstancedModelDrawer(this);

            ConstraintDrawer = new LineDrawer(this);
            ConstraintDrawer.DisplayTypes.Add(typeof(GrabSpring), typeof(DisplayGrabSpring));
            ConstraintDrawer.DisplayTypes.Add(typeof(MotorizedGrabSpring), typeof(DisplayMotorizedGrabSpring));

            ContactDrawer = new ContactDrawer(this);
            BoundingBoxDrawer = new BoundingBoxDrawer(this);
            SimulationIslandDrawer = new SimulationIslandDrawer(this);

            base.Initialize();
        }
Beispiel #37
0
        /// <summary>
        /// Constructs the front end and the internal physics representation of the Vehicle.
        /// </summary>
        /// <param name="position">Position of the Vehicle.</param>
        /// <param name="space">Space to add the Vehicle to.</param>
        /// <param name="camera">Camera to attach to the Vehicle.</param>
        /// <param name="game">The running game.</param>
        /// <param name="drawer">Drawer used to draw the Vehicle.</param>
        /// <param name="wheelModel">Model of the wheels.</param>
        /// <param name="wheelTexture">Texture to use for the wheels.</param>
        public VehicleInput(Vector3 position, Space space, Camera camera, DemosGame game, ModelDrawer drawer, Model wheelModel, Texture2D wheelTexture)
        {
            var bodies = new List<CompoundShapeEntry>
                {
                    new CompoundShapeEntry(new BoxShape(2.5f, .75f, 4.5f), new Vector3(0, 0, 0), 60),
                    new CompoundShapeEntry(new BoxShape(2.5f, .3f, 2f), new Vector3(0, .75f / 2 + .3f / 2, .5f), 1)
                };
            var body = new CompoundBody(bodies, 61);
            body.CollisionInformation.LocalPosition = new Vector3(0, .5f, 0);
            body.Position = position; //At first, just keep it out of the way.
            Vehicle = new Vehicle(body);

            var localWheelRotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), MathHelper.PiOver2);

            //The wheel model used is not aligned initially with how a wheel would normally look, so rotate them.
            Matrix wheelGraphicRotation = Matrix.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2);
            Vehicle.AddWheel(new Wheel(
                                 new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false),
                                 new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(-1.1f, -0.1f, 1.8f)),
                                 new WheelDrivingMotor(2.5f, 30000, 10000),
                                 new WheelBrake(1.5f, 2, .02f),
                                 new WheelSlidingFriction(4, 5)));
            Vehicle.AddWheel(new Wheel(
                                 new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false),
                                 new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(-1.1f, -0.1f, -1.8f)),
                                 new WheelDrivingMotor(2.5f, 30000, 10000),
                                 new WheelBrake(1.5f, 2, .02f),
                                 new WheelSlidingFriction(4, 5)));
            Vehicle.AddWheel(new Wheel(
                                 new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false),
                                 new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(1.1f, -0.1f, 1.8f)),
                                 new WheelDrivingMotor(2.5f, 30000, 10000),
                                 new WheelBrake(1.5f, 2, .02f),
                                 new WheelSlidingFriction(4, 5)));
            Vehicle.AddWheel(new Wheel(
                                 new CylinderCastWheelShape(.375f, 0.2f, localWheelRotation, wheelGraphicRotation, false),
                                 new WheelSuspension(2000, 100f, Vector3.Down, 0.325f, new Vector3(1.1f, -0.1f, -1.8f)),
                                 new WheelDrivingMotor(2.5f, 30000, 10000),
                                 new WheelBrake(1.5f, 2, .02f),
                                 new WheelSlidingFriction(4, 5)));

            foreach (Wheel wheel in Vehicle.Wheels)
            {
                //This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes.
                wheel.Shape.FreezeWheelsWhileBraking = true;

                //By default, wheels use as many iterations as the space.  By lowering it,
                //performance can be improved at the cost of a little accuracy.
                //However, because the suspension and friction are not really rigid,
                //the lowered accuracy is not so much of a problem.
                wheel.Suspension.SolverSettings.MaximumIterationCount = 1;
                wheel.Brake.SolverSettings.MaximumIterationCount = 1;
                wheel.SlidingFriction.SolverSettings.MaximumIterationCount = 1;
                wheel.DrivingMotor.SolverSettings.MaximumIterationCount = 1;
            }

            Space = space;

            Space.Add(Vehicle);
            ModelDrawer = drawer;
            DisplayModel model;
            WheelModels = new List<DisplayModel>();
            for (int k = 0; k < 4; k++)
            {
                Vehicle.Wheels[k].Shape.Detector.Tag = "noDisplayObject";
                model = new DisplayModel(wheelModel, ModelDrawer);
                ModelDrawer.Add(model);
                WheelModels.Add(model);
                model.Texture = wheelTexture;
            }

            CameraControlScheme = new ChaseCameraControlScheme(Vehicle.Body, new Vector3(0, 0.6f, 0), true, 10, camera, game);
        }
Beispiel #38
0
 /// <summary>
 /// Creates the display object for the entity.
 /// </summary>
 /// <param name="drawer">Drawer managing this display object.</param>
 /// <param name="displayedObject">Entity to draw.</param>
 public DisplayCapsuleTest(ModelDrawer drawer, Capsule displayedObject)
     : base(drawer, displayedObject)
 {
 }
Beispiel #39
0
 /// <summary>
 /// Creates the display object for the entity.
 /// </summary>
 /// <param name="drawer">Drawer managing this display object.</param>
 /// <param name="displayedObject">Entity to draw.</param>
 public DisplayConvexHullTest(ModelDrawer drawer, ConvexHull displayedObject)
     : base(drawer, displayedObject)
 {
 }