public Sphere() { ent = new Engine.WorldRendering.Entity(); var mBuilder = new MeshBuilder(); mBuilder.AddSphere(12, 1); ent.Mesh = mBuilder.CreateMesh(); XNAGame game = new XNAGame(); var data = ent.Mesh.GetCollisionData(); var box = new MeshCollisionData.Box(); box.Dimensions = MathHelper.One.xna() * 2; box.Orientation = Matrix.Identity.xna(); data.Boxes.Add(box); var builder = new MeshPhysicsActorBuilder(new MeshPhysicsPool()); dEl = new MeshDynamicPhysicsElement(ent.Mesh, Matrix.Identity.xna(), builder); dEl.InitDynamic(TW.Physics.Scene); dEl.Actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 10; //TODO: use the MeshP //var factory = new MeshPhysicsElementFactory(engine, root); //game.AddXNAObject(factory); //TODO: this update function must be called //game.UpdateEvent += delegate //{ // dEl.Update(root, game); //}; }
private RAMMesh createTwoBoxMesh() { var mesh = new RAMMesh(); var data = mesh.GetCollisionData(); var box = new MeshCollisionData.Box(); box.Dimensions = Vector3.One * 2; box.Orientation = Matrix.Identity; data.Boxes.Add(box); box = new MeshCollisionData.Box(); box.Dimensions = Vector3.One * 4; box.Orientation = Matrix.CreateTranslation(new Vector3(2, 2, 2)); data.Boxes.Add(box); return(mesh); }
public MeshCollisionData.Box CreateCollisionBox(OBJGroup.SubObject subObj, RAMMesh mesh) { var data = mesh.GetCollisionData(); var positions = new List <Vector3>(); for (int i = 0; i < subObj.Faces.Count; i++) { var face = subObj.Faces[i]; positions.Add(importer.Vertices[face.V1.Position]); positions.Add(importer.Vertices[face.V2.Position]); positions.Add(importer.Vertices[face.V3.Position]); } var bb = BoundingBox.CreateFromPoints(positions); var box = new MeshCollisionData.Box(); box.Dimensions = bb.Max - bb.Min; box.Orientation = Matrix.CreateTranslation((bb.Max + bb.Min) * 0.5f); return(box); }
public void TestMeshPhysicsActorBuilderBoxes() { var mesh = new RAMMesh(); var data = mesh.GetCollisionData(); var box = new MeshCollisionData.Box(); box.Dimensions = Vector3.One; box.Orientation = Matrix.Identity; data.Boxes.Add(box); box = new MeshCollisionData.Box(); box.Dimensions = Vector3.One * 3; box.Orientation = Matrix.CreateTranslation(new Vector3(2, 2, 2)); data.Boxes.Add(box); testMeshPhysicsActorBuilder(mesh); }
public void TestMeshDynamicPhysicsElement() { XNAGame game = new XNAGame(); var mesh = new RAMMesh(); var data = mesh.GetCollisionData(); var box = new MeshCollisionData.Box(); box.Dimensions = Vector3.One * 2; box.Orientation = Matrix.Identity; data.Boxes.Add(box); box = new MeshCollisionData.Box(); box.Dimensions = Vector3.One * 4; box.Orientation = Matrix.CreateTranslation(new Vector3(2, 2, 2)); data.Boxes.Add(box); BoundingBox bb = new BoundingBox(); PhysicsEngine engine = new PhysicsEngine(); PhysicsDebugRendererXNA debugRenderer = null; TheWizards.Client.ClientPhysicsQuadTreeNode root; root = new ClientPhysicsQuadTreeNode( new BoundingBox( new Vector3(-16 * 16 / 2f, -100, -16 * 16 / 2f), new Vector3(16 * 16 / 2f, 100, 16 * 16 / 2f))); QuadTree.Split(root, 4); var builder = new MeshPhysicsActorBuilder(new MeshPhysicsPool()); var visualizer = new QuadTreeVisualizerXNA(); float time = 0; var spheres = new List <MeshDynamicPhysicsElement>(); var meshes = new List <MeshStaticPhysicsElement>(); var physicsElementFactoryXNA = new MeshPhysicsFactoryXNA(engine, root); var factory = physicsElementFactoryXNA.Factory; game.AddXNAObject(physicsElementFactoryXNA); game.InitializeEvent += delegate { engine.Initialize(); debugRenderer = new PhysicsDebugRendererXNA(game, engine.Scene); debugRenderer.Initialize(game); }; game.DrawEvent += delegate { debugRenderer.Render(game); visualizer.RenderNodeGroundBoundig(game, root, delegate(ClientPhysicsQuadTreeNode node, out Color col) { col = Color.Green; return(node.PhysicsObjects.Count == 0); }); visualizer.RenderNodeGroundBoundig(game, root, delegate(ClientPhysicsQuadTreeNode node, out Color col) { col = Color.Orange; return(node.PhysicsObjects.Count > 0); }); for (int i = 0; i < meshes.Count; i++) { game.LineManager3D.AddCenteredBox(meshes[i].BoundingSphere.Center, meshes[i].BoundingSphere.Radius * 2, Color.Black); } }; game.UpdateEvent += delegate { time += game.Elapsed; if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.F)) { var dEl = new MeshDynamicPhysicsElement(mesh, Matrix.CreateTranslation( game.SpectaterCamera.CameraPosition + game.SpectaterCamera.CameraDirection), builder); dEl.InitDynamic(engine.Scene); dEl.Actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 10; spheres.Add(dEl); } for (int i = 0; i < spheres.Count; i++) { spheres[i].Update(root); } engine.Update(game.Elapsed); }; game.Run(); }