Ejemplo n.º 1
0
        public BowlingPinObject(Matrix orientation, Vector3 position)
        {
            body      = new Body();
            collision = new CollisionSkin(body);

            // add a capsule for the main corpus
            Primitive capsule = new Capsule(Vector3.Zero, Matrix.Identity, 0.1f, 1.3f);
            // add a small box at the buttom
            Primitive box = new Box(new Vector3(-0.1f, -0.1f, -0.1f), Matrix.Identity, Vector3.One * 0.2f);
            // add a sphere in the middle
            Primitive sphere = new JigLibX.Geometry.Sphere(new Vector3(0.0f, 0.0f, 0.3f), 0.3f);

            collision.AddPrimitive(capsule, new MaterialProperties(0.1f, 0.5f, 0.5f));
            collision.AddPrimitive(box, new MaterialProperties(0.1f, 0.5f, 0.5f));
            collision.AddPrimitive(sphere, new MaterialProperties(0.1f, 0.5f, 0.5f));

            body.CollisionSkin = this.collision;
            Vector3 com = SetMass(0.5f);

            body.MoveTo(position, orientation);
            collision.ApplyLocalTransform(new Transform(-com, Matrix.Identity));

            body.EnableBody();
            this.scale = Vector3.One * 10.0f;
        }
Ejemplo n.º 2
0
        public BowlingPin(Game game, Model model, Matrix orientation, Vector3 position)
            : base(game, model)
        {
            body = new Body();
            collision = new CollisionSkin(body);

            // add a capsule for the main corpus
            Primitive capsule = new Capsule(Vector3.Zero, Matrix.Identity, 0.1f, 1.3f);
            // add a small box at the buttom
            Primitive box = new Box(new Vector3(-0.1f,-0.1f,-0.1f), Matrix.Identity, Vector3.One * 0.2f);
            // add a sphere in the middle
            Primitive sphere = new Sphere(new Vector3(0.0f, 0.0f, 0.3f), 0.3f);

            collision.AddPrimitive(capsule, new MaterialProperties(0.1f, 0.5f, 0.5f));
            collision.AddPrimitive(box, new MaterialProperties(0.1f, 0.5f, 0.5f));
            collision.AddPrimitive(sphere, new MaterialProperties(0.1f, 0.5f, 0.5f));

            body.CollisionSkin = this.collision;
            Vector3 com = SetMass(0.5f);

            body.MoveTo(position, orientation);
            collision.ApplyLocalTransform(new Transform(-com, Matrix.Identity));

            body.EnableBody();
            this.scale = Vector3.One * 10.0f;
        }
Ejemplo n.º 3
0
        public Gobject GetSphere(Vector3 pos, float radius, Model model, bool moveable)
        {
            Sphere spherePrimitive = new Sphere(pos, radius);
            Gobject sphere = new Gobject(
                pos,
                Vector3.One * radius,
                spherePrimitive,
                model,
                moveable,
                0);

            //newObjects.Add(sphere.ID, sphere);
            return sphere;
        }
Ejemplo n.º 4
0
        public static bool SegmentSphereIntersection(out float ts, Segment seg, Sphere sphere)
        {
            Vector3 r = seg.Delta;
            Vector3 s = seg.Origin - sphere.Position;

            float radiusSq = sphere.Radius * sphere.Radius;
            float rSq = r.LengthSquared();

            ts = 0.0f;

            if (rSq < radiusSq)
            {
                // starting inside
                return false;
            }

            float sDotr = Vector3.Dot(s, r);
            float sSq = s.LengthSquared();
            float sigma = (sDotr * sDotr) - rSq * (sSq - radiusSq);
            if (sigma < 0.0f)
                return false;
            float sigmaSqrt = (float)System.Math.Sqrt((float)sigma);
            float lambda1 = (-sDotr - sigmaSqrt) / rSq;
            float lambda2 = (-sDotr + sigmaSqrt) / rSq;
            if (lambda1 > 1.0f || lambda2 < 0.0f)
                return false;
            // intersection!
            ts = MathHelper.Max(lambda1, 0.0f);
            return true;
        }
Ejemplo n.º 5
0
        public XBoneMapObject(Vector3 position, ref XModel model)
        {
            //create a list to hold the collision primitives
            List <Primitive> prims = new List <Primitive>();

            //parse for collision bones
            foreach (ModelBone bone in model.Model.Bones)
            {
                string[] keypairs = bone.Name.ToLower().Split('_');
                //if checks for valid naming convention on collision bones
                if ((keypairs.Length == 2) && ((keypairs[0] == "sphere") || (keypairs[0] == "box") || (keypairs[0] == "capsule")))
                {
                    //determine object number
                    int objectnum;
                    if ((keypairs[1] != "") || (keypairs[1] != null))
                    {
                        objectnum = int.Parse(keypairs[1]);
                    }
                    else
                    {
                        objectnum = 0;
                    }

                    //decompose bone transforms to components
                    Vector3    pos;
                    Vector3    scale;
                    Quaternion qrot;
                    bone.Transform.Decompose(out scale, out qrot, out pos);
                    Matrix rot = Matrix.CreateFromQuaternion(qrot);

                    //create  collision primitive objects and add to list
                    switch (keypairs[0])
                    {
                    case ("sphere"):
                        JigLibX.Geometry.Sphere sph = new JigLibX.Geometry.Sphere(pos, scale.X);
                        prims.Add(sph);
                        break;

                    case ("box"):
                        Box box = new Box(pos, rot, scale);
                        prims.Add(box);
                        break;

                    case ("capsule"):
                        break;
                    }
                }
            }

            body      = new Body();
            collision = new CollisionSkin(body);

            if (prims.Count > 0)
            {
                foreach (Primitive prim in prims)
                {
                    //TODO: Add ability to specify physics material type in art editor somehow
                    collision.AddPrimitive(prim, (int)JigLibX.Collision.MaterialTable.MaterialID.NormalSmooth);
                }
            }
            else
            {//no collision prims detected from XSI so create a default one here using the mesh bounding spheres
                foreach (ModelMesh mesh in model.Model.Meshes)
                {
                    //collision.AddPrimitive(new JigLibX.Geometry.Sphere(mesh.BoundingSphere.Center, mesh.BoundingSphere.Radius), new MaterialProperties(0.8f, 0.8f, 0.7f));
                    collision.AddPrimitive(new JigLibX.Geometry.Box(position, Matrix.Identity, new Vector3(mesh.BoundingSphere.Radius / 2f)), (int)JigLibX.Collision.MaterialTable.MaterialID.NormalRough);
                }
            }

            body.CollisionSkin = this.collision;

            Vector3 com = SetMass(1.0f);

            body.MoveTo(position, Matrix.Identity);
            collision.ApplyLocalTransform(new Transform(-com, Matrix.Identity));
            body.EnableBody();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// AddSphere
        /// </summary>
        /// <param name="sphere"></param>
        /// <param name="bb"></param>
        public static void AddSphere(Sphere sphere, ref BoundingBox bb)
        {
            Vector3 radius = new Vector3(sphere.Radius);
            Vector3 minSphere = sphere.Position;
            Vector3 maxSphere = sphere.Position;

            Vector3.Subtract(ref minSphere, ref radius, out minSphere);
            Vector3.Add(ref maxSphere, ref radius, out maxSphere);

            Vector3.Min(ref bb.Min, ref minSphere, out bb.Min);
            Vector3.Max(ref bb.Max, ref maxSphere, out bb.Max);
        }