Пример #1
0
        public Block(Model model, Vector3 position, Type type)
            : base(model, position)
        {
            CurrentState = State.UnTouched;
            Demolished = false;
            BlockType = type;
            switch (BlockType)
            {
                case Type.Glass:
                    Mass = 5.0f; // default
                    Life = 1;
                    break;
                case Type.Wood:
                    Mass = 10.0f; // heavier than glass
                    Life = 2;
                    break;
                case Type.Stone:
                    Mass = 20.0f; // heavier than wood
                    Life = 3;
                    break;
                default:
                    break;
            }

            // create the cube
            box = new Cube(position, new Vector3(1.0f, 1.0f, 1.0f));
            triangles = new Triangle[12];
            // top of the cube
            triangles[0] = new Triangle(box.vertices[0], box.vertices[1], box.vertices[2]);
            triangles[1] = new Triangle(box.vertices[0], box.vertices[2], box.vertices[3]);
            // bottom of the cube
            triangles[2] = new Triangle(box.vertices[4], box.vertices[6], box.vertices[5]);
            triangles[3] = new Triangle(box.vertices[4], box.vertices[7], box.vertices[6]);
            // left of the cube
            triangles[4] = new Triangle(box.vertices[4], box.vertices[7], box.vertices[3]);
            triangles[5] = new Triangle(box.vertices[4], box.vertices[3], box.vertices[0]);
            // right of the cube
            triangles[6] = new Triangle(box.vertices[5], box.vertices[6], box.vertices[2]);
            triangles[7] = new Triangle(box.vertices[5], box.vertices[2], box.vertices[1]);
            // front of the cube
            triangles[8] = new Triangle(box.vertices[2], box.vertices[6], box.vertices[7]);
            triangles[9] = new Triangle(box.vertices[2], box.vertices[7], box.vertices[3]);
            // back of the cube
            triangles[10] = new Triangle(box.vertices[5], box.vertices[1], box.vertices[0]);
            triangles[11] = new Triangle(box.vertices[5], box.vertices[0], box.vertices[4]);

            // define normals
            normals = new Vector3[6];
            normals[0] = Vector3.Down; // top of cube
            normals[1] = Vector3.Up; // bottom of cube
            normals[2] = Vector3.Right; // left of cube
            normals[3] = Vector3.Left; // right of cube
            normals[4] = Vector3.Forward; // front of cube
            normals[5] = Vector3.Backward; // back of cube
        }
Пример #2
0
 // test collision between a sphere and a triangle
 public static bool TestSphereTriangle(Transform sphere, Triangle triangle)
 {
     return TestSphereTriangle(sphere, triangle.a, triangle.b, triangle.c);
 }