/// <summary> /// Creates a new EntityModel. /// </summary> /// <param name="entity">Entity to attach the graphical representation to.</param> /// <param name="model">Graphical representation to use for the entity.</param> /// <param name="transform">Base transformation to apply to the model before moving to the entity.</param> /// <param name="game">Game to which this component will belong.</param> public EntityModel(Entity entity, Model model, BEPUutilities.Matrix transform, Game game) : base(game) { this.entity = entity; this.model = model; this.Transform = transform; /* * cModel = new CModel(model, MathConverter.Convert(entity.Position), Vector3.Zero, Vector3.One, game.GraphicsDevice); * * renderCapture = new RenderCapture(game.GraphicsDevice); * glowCapture = new RenderCapture(game.GraphicsDevice); * glowEffect = Game.Content.Load<Effect>("GlowEffect"); * glowTexture = Game.Content.Load<Texture2D>("glow_map"); * glowEffect.Parameters["GlowTexture"].SetValue(glowTexture); * blur = new GaussianBlur(game.GraphicsDevice, Game.Content, 4); */ //Collect any bone transformations in the model itself. //The default cube model doesn't have any, but this allows the EntityModel to work with more complicated shapes. boneTransforms = new Matrix[model.Bones.Count]; foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); //effect.TextureEnabled = true; //effect.Texture = glowTexture; } } }
/// <summary> /// Creates a new EntityModel. /// </summary> /// <param name="entity">Entity to attach the graphical representation to.</param> /// <param name="model">Graphical representation to use for the entity.</param> /// <param name="transform">Base transformation to apply to the model before moving to the entity.</param> /// <param name="game">Game to which this component will belong.</param> public ProjectileModel(Entity entity, Model model, BEPUutilities.Matrix transform, Game game, ParticleSystem explosionParticles, ParticleSystem explosionSmokeParticles, ParticleSystem projectileTrailParticles) : base(game) { this.entity = entity; this.model = model; this.Transform = transform; startPosition = new BEPUutilities.Vector3(entity.Position.X, entity.Position.Y, entity.Position.Z); this.explosionParticles = explosionParticles; this.explosionSmokeParticles = explosionSmokeParticles; //this.trailEmitter = new ParticleEmitter(projectileTrailParticles,trailParticlesPerSecond, MathConverter.Convert(entity.Position)); //Collect any bone transformations in the model itself. //The default cube model doesn't have any, but this allows the EntityModel to work with more complicated shapes. boneTransforms = new Matrix[model.Bones.Count]; foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); } } }
/// <summary> /// Draws the component. /// </summary> /// <param name="viewMatrix">View matrix to use when rendering the lines.</param> /// <param name="projectionMatrix">Projection matrix to use when rendering the lines.</param> public void Draw(BEPUutilities.Matrix viewMatrix, BEPUutilities.Matrix projectionMatrix) { int numElements = firstOpenIndex / 2; if (numElements > 0) { //Set state game.GraphicsDevice.BlendState = blendState; lineDrawer.LightingEnabled = false; lineDrawer.VertexColorEnabled = true; lineDrawer.World = Matrix.Identity; lineDrawer.View = MathConverter.Convert(viewMatrix); lineDrawer.Projection = MathConverter.Convert(projectionMatrix); //Draw for (int i = 0; i < lineDrawer.CurrentTechnique.Passes.Count; i++) { lineDrawer.CurrentTechnique.Passes[i].Apply(); game.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices, 0, numElements); } } }
public void Render3D(Location pos, float rot, Location size) { BEPUutilities.Matrix rot1 = BEPUutilities.Matrix.CreateFromAxisAngle(BEPUutilities.Vector3.UnitZ, rot) * BEPUutilities.Matrix.CreateFromAxisAngle(BEPUutilities.Vector3.UnitX, (float)(Math.PI * 0.25)); if (RenderedBlock != null) { TheClient.isVox = false; TheClient.SetVox(); TheClient.Rendering.SetMinimumLight(0.9f, TheClient.MainWorldView); RenderedBlock.WorldTransform = BEPUutilities.Matrix.CreateScale(size.ToBVector() * 0.70f) * rot1 * BEPUutilities.Matrix.CreateTranslation(pos.ToBVector()); RenderedBlock.Render(); TheClient.Rendering.SetMinimumLight(0f, TheClient.MainWorldView); } else if (RenderedModel != null) { TheClient.isVox = true; TheClient.SetEnts(); TheClient.Rendering.SetMinimumLight(0.9f, TheClient.MainWorldView); BEPUutilities.RigidTransform rt = BEPUutilities.RigidTransform.Identity; RenderedModel.Shape.GetBoundingBox(ref rt, out BEPUutilities.BoundingBox bb); BEPUutilities.Vector3 scale = BEPUutilities.Vector3.Max(bb.Max, -bb.Min); float len = (float)scale.Length(); RenderedModel.WorldTransform = BEPUutilities.Matrix.CreateScale(size.ToBVector() * len) * rot1 * BEPUutilities.Matrix.CreateTranslation(pos.ToBVector()); RenderedModel.RenderSimpler(); TheClient.Rendering.SetMinimumLight(0f, TheClient.MainWorldView); } }
public static Matrix Convert(BEPUutilities.Matrix matrix) { Matrix toReturn; Convert(ref matrix, out toReturn); return(toReturn); }
private Microsoft.Xna.Framework.Matrix BepuToXnaMatrix(BEPUutilities.Matrix m) { Matrix res = new Matrix(m.M11, m.M12, m.M13, m.M14, m.M21, m.M22, m.M23, m.M24, m.M31, m.M32, m.M33, m.M34, m.M41, m.M42, m.M43, m.M44); return(res); }
public static Location MatrixToAngles(BEPUutilities.Matrix WorldTransform) { Location rot; rot.X = Math.Atan2(WorldTransform.M32, WorldTransform.M33) * 180 / Math.PI; rot.Y = -Math.Asin(WorldTransform.M31) * 180 / Math.PI; rot.Z = Math.Atan2(WorldTransform.M21, WorldTransform.M11) * 180 / Math.PI; return(rot); }
public BFrustum(BEPUutilities.Matrix matrix) { Left = new Plane(new Location(-matrix.M14 - matrix.M11, -matrix.M24 - matrix.M21, -matrix.M34 - matrix.M31), -matrix.M44 - matrix.M41); Right = new Plane(new Location(matrix.M11 - matrix.M14, matrix.M21 - matrix.M24, matrix.M31 - matrix.M34), matrix.M41 - matrix.M44); Top = new Plane(new Location(matrix.M12 - matrix.M14, matrix.M22 - matrix.M24, matrix.M32 - matrix.M34), matrix.M42 - matrix.M44); Bottom = new Plane(new Location(-matrix.M14 - matrix.M12, -matrix.M24 - matrix.M22, -matrix.M34 - matrix.M32), -matrix.M44 - matrix.M42); Near = new Plane(new Location(-matrix.M13, -matrix.M23, -matrix.M33), -matrix.M43); Far = new Plane(new Location(matrix.M13 - matrix.M14, matrix.M23 - matrix.M24, matrix.M33 - matrix.M34), matrix.M43 - matrix.M44); }
public static Matrix GenerateMonoMatrixFromBepu(BEPUutilities.Matrix matrix) { Matrix world = new Matrix( matrix.M11, matrix.M12, matrix.M13, matrix.M14, matrix.M21, matrix.M22, matrix.M23, matrix.M24, matrix.M31, matrix.M32, matrix.M33, matrix.M34, matrix.M41, matrix.M42, matrix.M43, matrix.M44); return(world); }
public static BEPUutilities.Matrix GenerateBepuMatrixFromMono(Matrix matrix) { BEPUutilities.Matrix world = new BEPUutilities.Matrix( matrix.M11, matrix.M12, matrix.M13, matrix.M14, matrix.M21, matrix.M22, matrix.M23, matrix.M24, matrix.M31, matrix.M32, matrix.M33, matrix.M34, matrix.M41, matrix.M42, matrix.M43, matrix.M44); return(world); }
public override void Render() { TheClient.SetEnts(); if (TheClient.RenderTextures) { TheClient.Textures.White.Bind(); } if (model != null) { TheClient.Rendering.SetMinimumLight(0f); BEPUutilities.Matrix matang = BEPUutilities.Matrix.CreateFromQuaternion(Angles); //matang.Transpose(); Matrix4d matang4 = new Matrix4d(matang.M11, matang.M12, matang.M13, matang.M14, matang.M21, matang.M22, matang.M23, matang.M24, matang.M31, matang.M32, matang.M33, matang.M34, matang.M41, matang.M42, matang.M43, matang.M44); Matrix4d mat = matang4 * Matrix4d.CreateTranslation(ClientUtilities.ConvertD(GetPosition())); TheClient.MainWorldView.SetMatrix(2, mat); model.Draw(); // TODO: Animation? if (model.Name == "projectiles/arrow.dae") { float offs = 0.1f; BEPUutilities.Vector3 offz; BEPUutilities.Quaternion.TransformZ(offs, ref Angles, out offz); BEPUutilities.Vector3 offx; BEPUutilities.Quaternion.TransformX(offs, ref Angles, out offx); TheClient.Particles.Engine.AddEffect(ParticleEffectType.LINE, (o) => ppos + new Location(offz), (o) => Position + new Location(offz), (o) => 1f, 1f, Location.One, Location.One, true, TheClient.Textures.GetTexture("common/smoke"), 0.5f); TheClient.Particles.Engine.AddEffect(ParticleEffectType.LINE, (o) => ppos - new Location(offz), (o) => Position - new Location(offz), (o) => 1f, 1f, Location.One, Location.One, true, TheClient.Textures.GetTexture("common/smoke"), 0.5f); TheClient.Particles.Engine.AddEffect(ParticleEffectType.LINE, (o) => ppos + new Location(offx), (o) => Position + new Location(offx), (o) => 1f, 1f, Location.One, Location.One, true, TheClient.Textures.GetTexture("common/smoke"), 0.5f); TheClient.Particles.Engine.AddEffect(ParticleEffectType.LINE, (o) => ppos - new Location(offx), (o) => Position - new Location(offx), (o) => 1f, 1f, Location.One, Location.One, true, TheClient.Textures.GetTexture("common/smoke"), 0.5f); ppos = Position; } } else { TheClient.Rendering.SetMinimumLight(1f); TheClient.Rendering.SetColor(Color4.DarkRed); TheClient.Rendering.RenderCylinder(GetPosition(), GetPosition() - Velocity / 20f, 0.01f); TheClient.Particles.Engine.AddEffect(ParticleEffectType.CYLINDER, (o) => ppos, (o) => Position, (o) => 0.01f, 2f, Location.One, Location.One, true, TheClient.Textures.GetTexture("white")); ppos = Position; TheClient.Rendering.SetColor(Color4.White); } }
/// <summary> /// Draws the models managed by the drawer. /// </summary> /// <param name="viewMatrix">View matrix to use to draw the objects.</param> /// <param name="projectionMatrix">Projection matrix to use to draw the objects.</param> protected override void DrawManagedModels(Matrix viewMatrix, Matrix projectionMatrix) { viewParameter.SetValue(MathConverter.Convert(viewMatrix)); projectionParameter.SetValue(MathConverter.Convert(projectionMatrix)); for (int i = 0; i < instancingEffect.CurrentTechnique.Passes.Count; i++) { foreach (ModelDisplayObjectBatch batch in batches) { batch.Draw(instancingEffect, worldTransformsParameter, textureIndicesParameter, instancingEffect.CurrentTechnique.Passes[i]); } } }
/// <summary> /// Draws the drawer's models. /// </summary> /// <param name="viewMatrix">View matrix to use to draw the objects.</param> /// <param name="projectionMatrix">Projection matrix to use to draw the objects.</param> public void Draw(Matrix viewMatrix, Matrix projectionMatrix) { Game.GraphicsDevice.RasterizerState = IsWireframe ? wireframeState : fillState; Game.GraphicsDevice.BlendState = BlendState.Opaque; Game.GraphicsDevice.DepthStencilState = DepthStencilState.Default; foreach (SelfDrawingModelDisplayObject displayObject in selfDrawingDisplayObjects) { displayObject.Draw(viewMatrix, projectionMatrix); } DrawManagedModels(viewMatrix, projectionMatrix); }
/// <summary> /// Method for loading the ball into the game /// </summary> /// <param name="space">Space the ball will be added</param> /// <param name="game">The current game</param> public void Load(Space space, Game game) { space.Add(Form); if (Model != null) { Matrix scaling = Matrix.CreateScale(Form.Radius, Form.Radius, Form.Radius); EntityModel entityModel = new EntityModel(Form, Model, scaling, game); game.Components.Add(entityModel); } else { space.Remove(Form); throw new Exception("Load on model null"); } }
/// <summary> /// Creates a new StaticModel. /// </summary> /// <param name="model">Graphical representation to use for the entity.</param> /// <param name="transform">Base transformation to apply to the model before moving to the entity.</param> /// <param name="game">Game to which this component will belong.</param> public StaticModel(Model model, Matrix transform, Game game) : base(game) { this.model = model; this.Transform = transform; //Collect any bone transformations in the model itself. //The default cube model doesn't have any, but this allows the StaticModel to work with more complicated shapes. boneTransforms = new Microsoft.Xna.Framework.Matrix[model.Bones.Count]; foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); } } }
/// <summary> /// Creates a new StaticModel. /// </summary> /// <param name="model">Graphical representation to use for the entity.</param> /// <param name="transform">Base transformation to apply to the model before moving to the entity.</param> /// <param name="game">Game to which this component will belong.</param> public StaticModel(Model model, Matrix transform, Game game, GameManager manager) : base(game) { this.model = model; this.Transform = transform; this._manager = manager; //Collect any bone transformations in the model itself. //The default cube model doesn't have any, but this allows the StaticModel to work with more complicated shapes. boneTransforms = new Microsoft.Xna.Framework.Matrix[model.Bones.Count]; foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); } } }
/// <summary> /// Creates a new EntityModel. /// </summary> /// <param name="entity">Entity to attach the graphical representation to.</param> /// <param name="model">Graphical representation to use for the entity.</param> /// <param name="transform">Base transformation to apply to the model before moving to the entity.</param> /// <param name="game">Game to which this component will belong.</param> public EntityModel(Entity entity, Model model, BEPUutilities.Matrix transform, Game game) : base(game) { this.entity = entity; this.model = model; this.Transform = transform; //Collect any bone transformations in the model itself. //The default cube model doesn't have any, but this allows the EntityModel to work with more complicated shapes. boneTransforms = new Matrix[model.Bones.Count]; foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); } } }
public static void Convert(ref BEPUutilities.Matrix matrix, out Matrix xnaMatrix) { xnaMatrix.M11 = matrix.M11; xnaMatrix.M12 = matrix.M12; xnaMatrix.M13 = matrix.M13; xnaMatrix.M14 = matrix.M14; xnaMatrix.M21 = matrix.M21; xnaMatrix.M22 = matrix.M22; xnaMatrix.M23 = matrix.M23; xnaMatrix.M24 = matrix.M24; xnaMatrix.M31 = matrix.M31; xnaMatrix.M32 = matrix.M32; xnaMatrix.M33 = matrix.M33; xnaMatrix.M34 = matrix.M34; xnaMatrix.M41 = matrix.M41; xnaMatrix.M42 = matrix.M42; xnaMatrix.M43 = matrix.M43; xnaMatrix.M44 = matrix.M44; }
public static float TestScalarTranspose(int iterationCount) { bMatrix m = bMatrix.Identity; float accumulator = 0; for (int i = 0; i < iterationCount; ++i) { bMatrix r0, r1; bMatrix.Transpose(ref m, out r0); bMatrix.Transpose(ref r0, out r1); bMatrix.Transpose(ref r1, out r0); bMatrix.Transpose(ref r0, out r1); bMatrix.Transpose(ref r1, out r0); bMatrix.Transpose(ref r0, out r1); bMatrix.Transpose(ref r1, out r0); bMatrix.Transpose(ref r0, out r1); bMatrix.Transpose(ref r1, out r0); bMatrix.Transpose(ref r0, out r1); accumulator += r1.M11; } return(accumulator); }
public static void Convert(ref Matrix matrix, out BEPUutilities.Matrix bepuMatrix) { bepuMatrix.M11 = matrix.M11; bepuMatrix.M12 = matrix.M12; bepuMatrix.M13 = matrix.M13; bepuMatrix.M14 = matrix.M14; bepuMatrix.M21 = matrix.M21; bepuMatrix.M22 = matrix.M22; bepuMatrix.M23 = matrix.M23; bepuMatrix.M24 = matrix.M24; bepuMatrix.M31 = matrix.M31; bepuMatrix.M32 = matrix.M32; bepuMatrix.M33 = matrix.M33; bepuMatrix.M34 = matrix.M34; bepuMatrix.M41 = matrix.M41; bepuMatrix.M42 = matrix.M42; bepuMatrix.M43 = matrix.M43; bepuMatrix.M44 = matrix.M44; }
/// <summary> /// Creates a new EntityModel. /// </summary> /// <param name="entity">Entity to attach the graphical representation to.</param> /// <param name="model">Graphical representation to use for the entity.</param> /// <param name="transform">Base transformation to apply to the model before moving to the entity.</param> /// <param name="game">Game to which this component will belong.</param> public PlanetModel(Entity entity, Model model, BEPUutilities.Matrix transform, Game game) : base(game) { this.entity = entity; this.model = model; this.Transform = transform; globalAmbient = new Vector4(0.2f, 0.2f, 0.2f, 1.0f); sunlight.direction = new Vector4(Vector3.Forward, 0.0f); sunlight.color = new Vector4(1.0f, 0.941f, 0.898f, 1.0f); /// Load the assets for the Earth. model = game.Content.Load <Model>(@"Models\earth"); effect = game.Content.Load <Effect>(@"Effects\earth"); dayTexture = game.Content.Load <Texture2D>(@"Textures\earth_day_color_spec"); nightTexture = game.Content.Load <Texture2D>(@"Textures\earth_night_color"); cloudTexture = game.Content.Load <Texture2D>(@"Textures\earth_clouds_alpha"); normalMapTexture = game.Content.Load <Texture2D>(@"Textures\earth_nrm"); // Setup material settings for the Earth. ambient = new Vector4(0.3f, 0.3f, 0.3f, 1.0f); diffuse = new Vector4(0.7f, 0.7f, 0.7f, 1.0f); specular = new Vector4(0.7f, 0.7f, 0.7f, 1.0f); shininess = 20.0f; cloudStrength = 1.15f; // Calculate the bounding sphere of the Earth model and bind the // custom Earth effect file to the model. foreach (ModelMesh mesh in model.Meshes) { bounds = BoundingSphere.CreateMerged(bounds, mesh.BoundingSphere); foreach (ModelMeshPart part in mesh.MeshParts) { part.Effect = effect; } } }
public override void Render() { if (model == null) { return; } TheClient.SetEnts(); if (TheClient.RenderTextures) { TheClient.Textures.White.Bind(); } TheClient.Rendering.SetMinimumLight(0f); BEPUutilities.Matrix matang = BEPUutilities.Matrix.CreateFromQuaternion(Angles); //matang.Transpose(); Matrix4d matang4 = new Matrix4d(matang.M11, matang.M12, matang.M13, matang.M14, matang.M21, matang.M22, matang.M23, matang.M24, matang.M31, matang.M32, matang.M33, matang.M34, matang.M41, matang.M42, matang.M43, matang.M44); Matrix4d mat = matang4 * Matrix4d.CreateTranslation(ClientUtilities.ConvertD(GetPosition())); TheClient.MainWorldView.SetMatrix(2, mat); model.Draw(); // TODO: Animation? }
public static float TestScalarMultiply(int iterationCount) { bMatrix m1 = bMatrix.Identity; bMatrix m2 = bMatrix.Identity; float accumulator = 0; for (int i = 0; i < iterationCount; ++i) { bMatrix r0, r1; bMatrix.Multiply(ref m1, ref m2, out r0); bMatrix.Multiply(ref r0, ref m2, out r1); bMatrix.Multiply(ref r1, ref m2, out r0); bMatrix.Multiply(ref r0, ref m2, out r1); bMatrix.Multiply(ref r1, ref m2, out r0); bMatrix.Multiply(ref r0, ref m2, out r1); bMatrix.Multiply(ref r1, ref m2, out r0); bMatrix.Multiply(ref r0, ref m2, out r1); bMatrix.Multiply(ref r1, ref m2, out r0); bMatrix.Multiply(ref r0, ref m2, out r1); accumulator += 0.000001f * r1.M11; } return(accumulator); }
public static float TestTransformScalar(int iterationCount) { bVector4 v = new bVector4(1, 2, 3, 4); bMatrix m = bMatrix.Identity; float accumulator = 0; for (int i = 0; i < iterationCount; ++i) { bVector4 r0, r1; bMatrix.Transform(ref v, ref m, out r0); bMatrix.Transform(ref r0, ref m, out r1); bMatrix.Transform(ref r1, ref m, out r0); bMatrix.Transform(ref r0, ref m, out r1); bMatrix.Transform(ref r1, ref m, out r0); bMatrix.Transform(ref r0, ref m, out r1); bMatrix.Transform(ref r1, ref m, out r0); bMatrix.Transform(ref r0, ref m, out r1); bMatrix.Transform(ref r1, ref m, out r0); bMatrix.Transform(ref r0, ref m, out r1); accumulator += 0.000001f * r1.X; } return(accumulator); }
public static Matrix CopyFromBepuMatrix(Matrix mat, BEPUutilities.Matrix matrix) { mat.M11 = matrix.M11; mat.M12 = matrix.M12; mat.M13 = matrix.M13; mat.M14 = matrix.M14; mat.M21 = matrix.M21; mat.M22 = matrix.M22; mat.M23 = matrix.M23; mat.M24 = matrix.M24; mat.M31 = matrix.M31; mat.M32 = matrix.M32; mat.M33 = matrix.M33; mat.M34 = matrix.M34; mat.M41 = matrix.M41; mat.M42 = matrix.M42; mat.M43 = matrix.M43; mat.M44 = matrix.M44; return(mat); }
public static OpenTK.Matrix4d ConvertD(BEPUutilities.Matrix mat) { return(new OpenTK.Matrix4d(mat.M11, mat.M12, mat.M13, mat.M14, mat.M21, mat.M22, mat.M23, mat.M24, mat.M31, mat.M32, mat.M33, mat.M34, mat.M41, mat.M42, mat.M43, mat.M44)); }
public static OpenTK.Matrix4 Convert(BEPUutilities.Matrix mat) { return(new OpenTK.Matrix4((float)mat.M11, (float)mat.M12, (float)mat.M13, (float)mat.M14, (float)mat.M21, (float)mat.M22, (float)mat.M23, (float)mat.M24, (float)mat.M31, (float)mat.M32, (float)mat.M33, (float)mat.M34, (float)mat.M41, (float)mat.M42, (float)mat.M43, (float)mat.M44)); }
public static Matrix ToSharp(this BEPUutilities.Matrix m) { return(new Matrix(m.M11, m.M12, m.M13, m.M14, m.M21, m.M22, m.M23, m.M24, m.M31, m.M32, m.M33, m.M34, m.M41, m.M42, m.M43, m.M44)); }
/// <summary> /// Draws the models managed by the drawer using the appropriate technique. /// </summary> /// <param name="viewMatrix">View matrix to use to draw the objects.</param> /// <param name="projectionMatrix">Projection matrix to use to draw the objects.</param> protected abstract void DrawManagedModels(Matrix viewMatrix, Matrix projectionMatrix);
/// <summary> /// Draws the drawer's models. /// </summary> /// <param name="viewMatrix">View matrix to use to draw the objects.</param> /// <param name="projectionMatrix">Projection matrix to use to draw the objects.</param> public void Draw(Matrix viewMatrix, Matrix projectionMatrix) { Game.GraphicsDevice.RasterizerState = IsWireframe ? wireframeState : fillState; Game.GraphicsDevice.BlendState = BlendState.Opaque; Game.GraphicsDevice.DepthStencilState = DepthStencilState.Default; foreach (SelfDrawingModelDisplayObject displayObject in selfDrawingDisplayObjects) displayObject.Draw(viewMatrix, projectionMatrix); DrawManagedModels(viewMatrix, projectionMatrix); }
private void SetupVehicle() { float width = 2.5f; float height = 0.75f; float length = 4.5f; float scale = 1f; var vehicleShape = new ProceduralCuboid(width / 2 * scale, length / 2 * scale, height / 2 * scale); vehicleShape.Translate(new Vector3(0, 0.5f, 0)); vehicleShape.SetColor(Color.Red); vehicleObject = GameObjectFactory.CreateRenderableGameObjectFromShape(vehicleShape, EffectLoader.LoadSM5Effect("flatshaded")); vehicleObject.AddComponent(new ShadowCasterComponent()); SystemCore.GameObjectManager.AddAndInitialiseGameObject(vehicleObject); ProceduralSphere cyl = new ProceduralSphere(10, 10); cyl.Scale(0.375f * scale); //cyl.Transform(Matrix.CreateRotationZ(MathHelper.PiOver2)); wheel1 = GameObjectFactory.CreateRenderableGameObjectFromShape(cyl, EffectLoader.LoadSM5Effect("flatshaded")); SystemCore.GameObjectManager.AddAndInitialiseGameObject(wheel1); var bodies = new List <CompoundShapeEntry> { new CompoundShapeEntry(new BoxShape(width * scale, height * scale, length * scale), new BEPUutilities.Vector3(0, 0, 0), 60), //new CompoundShapeEntry(new BoxShape(2.5f, .3f, 2f), new BEPUutilities.Vector3(0, .75f / 2 + .3f / 2, .5f), 1) }; var body = new CompoundBody(bodies, 61); body.CollisionInformation.LocalPosition = new BEPUutilities.Vector3(0, .5f, 0); body.Position = new BEPUutilities.Vector3(10, 20, 10); testVehicle = new Vehicle(body); BEPUutilities.Quaternion localWheelRotation = BEPUutilities.Quaternion.Identity; BEPUutilities.Matrix wheelGraphicRotation = BEPUutilities.Matrix.Identity; testVehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f * scale, 0.2f * scale, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, BEPUutilities.Vector3.Down, 0.325f, new BEPUutilities.Vector3(-1.1f, -0.1f, 1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); testVehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f * scale, 0.2f * scale, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, BEPUutilities.Vector3.Down, 0.325f, new BEPUutilities.Vector3(-1.1f, -0.1f, -1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); testVehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f * scale, 0.2f * scale, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, BEPUutilities.Vector3.Down, 0.325f, new BEPUutilities.Vector3(1.1f, -0.1f, 1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); testVehicle.AddWheel(new Wheel( new CylinderCastWheelShape(.375f * scale, 0.2f * scale, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100f, BEPUutilities.Vector3.Down, 0.325f, new BEPUutilities.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 testVehicle.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; } SystemCore.PhysicsSimulation.Add(testVehicle); }
Matrix4 convert(BEPUutilities.Matrix mat) { return(ClientUtilities.Convert(mat)); }