Exemplo n.º 1
0
        public CylinderCollider(RigidBody body)
        {
            var shape = (CylinderShape)body.CollisionShape;

            if (shape == null)
            {
                throw new ArgumentException("The body shape does not match the collider!", "body.CollisionShape");
            }

            Model = new Model(new Mesh[]
            {
                Primitives.Cylinder(shape.Radius, shape.HalfExtentsWithMargin.Y, shape.HalfExtentsWithMargin.Y, 20, MeshMaterial.Green)
            });
            Body = body;

            _radius     = shape.Radius;
            _halfLength = shape.HalfExtentsWithMargin.Y;
        }
Exemplo n.º 2
0
            public Model CreateModel(Vector3 origin, Vector3 direction, Vector4 color)
            {
                // TODO: create Align method for matrices, the same as for quaternions
                Matrix4 align = Matrix4.CreateTranslation(origin);

                if (direction != Vector3.UnitY)
                {
                    align *= Matrix4.CreateFromAxisAngle(Vector3.Cross(Vector3.UnitY, direction), (float)Math.Acos(Vector3.Dot(Vector3.UnitY, direction)));
                }

                return(new Model(new Mesh[]
                {
                    Primitives.Cylinder(0.01f, 0, 1f, 20, new MeshMaterial
                    {
                        Diffuse = color
                    }),
                    Primitives.Cone(0.05f, 0.2f, 20, new MeshMaterial
                    {
                        Diffuse = color
                    }, Vector3.UnitY)
                }, align * Matrix4.CreateScale(_scale)));
            }