コード例 #1
0
        protected override void LoadContent()
        {
            boxModel = Content.Load<Model>("box");
            torusModel = Content.Load<Model>("torus");

            // Get the vertex information out of the model
            List<JVector> positions = new List<JVector>();
            List<JOctree.TriangleVertexIndices> indices = new List<JOctree.TriangleVertexIndices>();
            ExtractData(positions, indices, torusModel);

            // Build an octree of it
            JOctree octree = new JOctree(positions, indices);
            octree.BuildOctree();

            // Pass it to a new instance of the triangleMeshShape
            TriangleMeshShape triangleMeshShape = new TriangleMeshShape(octree);

            // Create a body, using the triangleMeshShape
            RigidBody triangleBody = new RigidBody(triangleMeshShape);
            triangleBody.Tag = Color.LightGray;
            triangleBody.Position = new JVector(0, 3, 0);
            
            // Add the mesh to the world.
            world.AddBody(triangleBody);

            base.LoadContent();
        }
コード例 #2
0
        protected override void LoadContent()
        {
            boxModel   = Content.Load <Model>("box");
            torusModel = Content.Load <Model>("torus");

            // Get the vertex information out of the model
            List <JVector> positions = new List <JVector>();
            List <JOctree.TriangleVertexIndices> indices = new List <JOctree.TriangleVertexIndices>();

            ExtractData(positions, indices, torusModel);

            // Build an octree of it
            JOctree octree = new JOctree(positions, indices);

            octree.BuildOctree();

            // Pass it to a new instance of the triangleMeshShape
            TriangleMeshShape triangleMeshShape = new TriangleMeshShape(octree);

            // Create a body, using the triangleMeshShape
            RigidBody triangleBody = new RigidBody(triangleMeshShape);

            triangleBody.Tag      = Color.LightGray;
            triangleBody.Position = new JVector(0, 3, 0);

            // Add the mesh to the world.
            world.AddBody(triangleBody);

            base.LoadContent();
        }
コード例 #3
0
        private void SetHeightmap(float[,] heightValues)
        {
            // Remove any previous heightmaps
            if (_terrainBody != null)
            {
                World.RemoveBody(_terrainBody);
            }

            _heightValues = heightValues;

            if (heightValues != null)
            {
                //            new TerrainShape()
                JOctree terrainOctree = HeightmapToOctree(heightValues);
                var     terrainShape  = new TriangleMeshShape(terrainOctree);

                _terrainBody          = new RigidBody(terrainShape);
                _terrainBody.IsStatic = true;
                _terrainBody.Friction = 0.5f;

                World.AddBody(_terrainBody);
            }
        }
コード例 #4
0
        protected override void LoadContent()
        {
            models[(int)Models.box]      = Content.Load <Model>("box");
            models[(int)Models.sphere]   = Content.Load <Model>("sphere");
            models[(int)Models.cylinder] = Content.Load <Model>("cylinder");
            models[(int)Models.cone]     = Content.Load <Model>("cone");
            models[(int)Models.capsule]  = Content.Load <Model>("capsule");
            models[(int)Models.triangle] = Content.Load <Model>("staticmesh");

            List <JVector> vertices = new List <JVector>();
            List <JOctree.TriangleVertexIndices> indices =
                new List <JOctree.TriangleVertexIndices>();

            ExtractData(vertices, indices, models[(int)Models.triangle]);
            JOctree octree = new JOctree(vertices, indices);

            TriangleMeshShape triangleShape = new TriangleMeshShape(octree);
            RigidBody         triangleBody  = new RigidBody(triangleShape);

            triangleBody.IsStatic = true; triangleBody.Tag = false;
            triangleBody.Position = new JVector(-20, 10, -10);
            world.AddBody(triangleBody);
        }
コード例 #5
0
 public void CalculatePhysicsHull()
 {
     JMeshData meshData = model.ModelData.ExtractData();
     JOctree collisionVerts = new JOctree(meshData.Vertices, meshData.Indices);
     TriangleMeshShape shape = new TriangleMeshShape(collisionVerts);
     RigidBody = new RigidBody(shape);
     RigidBody.IsStatic = true; // terrain is immovable
 }
コード例 #6
0
        protected override void LoadContent()
        {
            models[(int)Models.box] = Content.Load<Model>("box");
            models[(int)Models.sphere] = Content.Load<Model>("sphere");
            models[(int)Models.cylinder] = Content.Load<Model>("cylinder");
            models[(int)Models.cone] = Content.Load<Model>("cone");
            models[(int)Models.capsule] = Content.Load<Model>("capsule");
            models[(int)Models.triangle] = Content.Load<Model>("staticmesh");

            List<JVector> vertices = new List<JVector>();
            List<JOctree.TriangleVertexIndices> indices =
                new List<JOctree.TriangleVertexIndices>();

            ExtractData(vertices, indices, models[(int)Models.triangle]);
            JOctree octree = new JOctree(vertices, indices);

            TriangleMeshShape triangleShape = new TriangleMeshShape(octree);
            RigidBody triangleBody = new RigidBody(triangleShape);
            triangleBody.IsStatic = true; triangleBody.Tag = false;
            triangleBody.Position = new JVector(-20, 10, -10);
            world.AddBody(triangleBody);
        }
コード例 #7
0
        public void CalculatePhysicsHull()
        {
            List<JOctree.TriangleVertexIndices> collisionIndices = new List<JOctree.TriangleVertexIndices>();
            var indices = surface.getIndices();
            for (int i = 0; i < indices.Count / 3; i++)
            {
                collisionIndices.Add(new JOctree.TriangleVertexIndices((int)indices[i*3], (int)indices[i*3 + 1], (int)indices[i*3 + 2]));
            }

            PositionMaterialNormalVector verts = surface.getVertices();
            List<JVector> collisionVertPositions = verts.Select<PositionMaterialNormal, JVector>(v => v.position.ToJVector()).ToList();

            JOctree collisionVerts = new JOctree(collisionVertPositions, collisionIndices);
            TriangleMeshShape shape = new TriangleMeshShape(collisionVerts);
            RigidBody = new RigidBody(shape);
            RigidBody.IsStatic = true; // terrain is immovable
        }