public void AddChildShape(float4x4 localTransform, ICylinderShapeImp shape)
 {
     var btHalfExtents = Translater.Float3ToBtVector3(shape.HalfExtents);
     var btChildShape = new CylinderShape(btHalfExtents);
     var btLocalTransform = Translater.Float4X4ToBtMatrix(localTransform);
     BtCompoundShape.AddChildShape(btLocalTransform, btChildShape);
 }
        public override CollisionShape CopyCollisionShape()
        {
            CylinderShape cs = new CylinderShape(halfExtent.ToBullet());

            cs.LocalScaling = m_localScaling.ToBullet();

            return(cs);
        }
Example #3
0
    public void TestCylinderCylinder(float x, float y, float z, float height, float radius, bool expected)
    {
        var cylinder1 = new CylinderShape(Vector3.Zero, 1, 1);

        var cylinder2 = new CylinderShape(new Vector3(x, y, z), height, radius);

        Assert.Equal(expected, CollisionDetection.IntersectCylinderCylinder(cylinder1, cylinder2));
    }
Example #4
0
 public override CollisionShape GetCollisionShape()
 {
     if (collisionShapePtr == null)
     {
         collisionShapePtr = new CylinderShape(halfExtent.ToBullet());
     }
     return(collisionShapePtr);
 }
Example #5
0
 /// <summary>
 /// Creates a new cylinder cast based wheel shape.
 /// </summary>
 /// <param name="radius">Radius of the wheel.</param>
 /// <param name="width">Width of the wheel.</param>
 /// <param name="localWheelOrientation">Unsteered orientation of the wheel in the vehicle's local space.</param>
 /// <param name="localGraphicTransform">Local graphic transform of the wheel shape.
 /// This transform is applied first when creating the shape's worldTransform.</param>
 /// <param name="includeSteeringTransformInCast">Whether or not to include the steering transform in the wheel shape cast. If false, the casted wheel shape will always point straight forward.
 /// If true, it will rotate with steering. Sometimes, setting this to false is helpful when the cast shape would otherwise become exposed when steering.</param>
 public CylinderCastWheelShape(float radius, float width, Quaternion localWheelOrientation,
                               Matrix localGraphicTransform, bool includeSteeringTransformInCast)
 {
     shape = new CylinderShape(width, radius);
     LocalWheelOrientation          = localWheelOrientation;
     LocalGraphicTransform          = localGraphicTransform;
     IncludeSteeringTransformInCast = includeSteeringTransformInCast;
 }
Example #6
0
        public void GetMesh()
        {
            var s = new CylinderShape(3, 10);
              var mesh = s.GetMesh(0.05f, 3);
              Assert.Greater(mesh.NumberOfTriangles, 1);

              // No more tests necessary because we see the result in the samples.
        }
Example #7
0
        public void AddChildShape(float4x4 localTransform, ICylinderShapeImp shape)
        {
            var btHalfExtents    = Translater.Float3ToBtVector3(shape.HalfExtents);
            var btChildShape     = new CylinderShape(btHalfExtents);
            var btLocalTransform = Translater.Float4X4ToBtMatrix(localTransform);

            BtCompoundShape.AddChildShape(btLocalTransform, btChildShape);
        }
Example #8
0
 public override CollisionShape GetCollisionShape()
 {
     if (collisionShapePtr == null)
     {
         collisionShapePtr = new CylinderShape(halfExtent.ToBullet());
         ((CylinderShape)collisionShapePtr).LocalScaling = m_localScaling.ToBullet();
     }
     return(collisionShapePtr);
 }
        public void GetMesh()
        {
            var s    = new CylinderShape(3, 10);
            var mesh = s.GetMesh(0.05f, 3);

            Assert.Greater(mesh.NumberOfTriangles, 1);

            // No more tests necessary because we see the result in the samples.
        }
Example #10
0
 public GrenadeEntity(Region tregion, bool shadows)
     : base(tregion, true, shadows)
 {
     model      = TheClient.Models.Sphere;
     GColor     = new Color4(0f, 0f, 0f, 1f);
     Shape      = new CylinderShape(0.2f, 0.05f);
     Bounciness = 0.95f;
     SetMass(1);
 }
Example #11
0
    protected override void OnPositionChanged(Quat rotation, float angle,
                                              Vector3 membraneCoords)
    {
        organelle.OrganelleGraphics.Transform = new Transform(rotation, membraneCoords);

        Vector3 middle = Hex.AxialToCartesian(new Hex(0, 0));
        Vector3 membranePointDirection = (membraneCoords - middle).Normalized();

        membraneCoords += membranePointDirection * Constants.DEFAULT_HEX_SIZE * 2;

        if (organelle.ParentMicrobe.Species.IsBacteria)
        {
            membraneCoords *= 0.5f;
        }

        float pilusSize = 4.6f;

        // Scale the size down for bacteria
        if (organelle.ParentMicrobe.Species.IsBacteria)
        {
            pilusSize *= 0.5f;
        }

        var physicsRotation = MathUtils.CreateRotationForPhysicsOrganelle(angle);

        // Need to remove the old copy first
        DestroyShape();

        // TODO: Godot doesn't have Cone shape.
        // https://github.com/godotengine/godot-proposals/issues/610
        // So this uses a cylinder for now

        // @pilusShape = organelle.world.GetPhysicalWorld().CreateCone(pilusSize / 10.f,
        //     pilusSize);

        var shape = new CylinderShape();

        shape.Radius = pilusSize / 10.0f;
        shape.Height = pilusSize;

        var parentMicrobe = organelle.ParentMicrobe;

        var ownerId = parentMicrobe.CreateShapeOwner(shape);

        parentMicrobe.ShapeOwnerAddShape(ownerId, shape);

        // TODO: find a way to pass the information to the shape /
        // parentMicrobe what is a pilus part of the collision
        // pilusShape.SetCustomTag(PHYSICS_PILUS_TAG);

        var transform = new Transform(physicsRotation, membraneCoords);

        parentMicrobe.ShapeOwnerSetTransform(ownerId, transform);

        parentMicrobe.AddPilus(ownerId);
        addedChildShapes.Add(ownerId);
    }
            public TreeTemplate(
                int sliceCount,
                int stackDivision,
                int coneCount,
                float height,
                float radius,
                float radAdd
                )
            {
                var          attributePosition = new Attribute(VertexUsage.Position, VertexAttribPointerType.Float, 0, 3);
                var          attributeNormal   = new Attribute(VertexUsage.Normal, VertexAttribPointerType.Float, 0, 3); /*  content normals     */
                VertexFormat vertexFormat      = new VertexFormat();

                vertexFormat.Add(attributePosition);
                vertexFormat.Add(attributeNormal);

                this.sliceCount    = sliceCount;
                this.stackDivision = stackDivision;
                this.coneCount     = coneCount;
                this.height        = height;
                this.radius        = radius;
                this.radAdd        = radAdd;
                float   coneHeight = height / (float)coneCount;
                Matrix4 rotZ       = Matrix4.CreateRotation(
                    RenderStack.Math.Conversions.DegreesToRadians(90.0f),
                    Vector3.UnitZ
                    );
                float    cylHeight        = coneHeight;
                float    cylRadius        = height / 20.0f;
                Geometry cylinderGeometry = new RenderStack.Geometry.Shapes.Cylinder(-cylHeight, cylHeight, cylRadius, sliceCount);

                cylinderGeometry.Transform(rotZ);
                GeometryMesh cylinderMesh  = new GeometryMesh(cylinderGeometry, NormalStyle.CornerNormals, vertexFormat);
                Shape        cylinderShape = new CylinderShape(cylHeight, cylRadius);

                cylinderMesh.GetMesh.Name = "cylinder";
                meshes.Add(cylinderMesh);
                shapes.Add(cylinderShape);
                for (int c = 0; c < coneCount; c++)
                {
                    float    topRadius      = (coneCount - 1 - c) * radius / (float)coneCount;
                    float    bottomRadius   = topRadius + radAdd;
                    float    R              = bottomRadius;
                    float    r              = topRadius;
                    float    fullConeHeight = (R * coneHeight) / (R - r);
                    float    minX           = -fullConeHeight / 3.0f;
                    float    maxX           = 2.0f * fullConeHeight / 3.0f;
                    float    offset         = -minX;
                    Geometry coneGeometry   = new RenderStack.Geometry.Shapes.Cone(minX, maxX, bottomRadius, 0.0f, true, true, sliceCount, stackDivision);
                    coneGeometry.Transform(rotZ);
                    GeometryMesh coneMesh  = new GeometryMesh(coneGeometry, NormalStyle.CornerNormals, vertexFormat);
                    Shape        coneShape = new ConeShape(fullConeHeight, R);
                    coneMesh.GetMesh.Name = "cone" + c.ToString();
                    meshes.Add(coneMesh);
                    shapes.Add(coneShape);
                }
            }
Example #13
0
            protected new void Start()
            {
                base.Start();

                mShape = new CylinderShape(radius, halfHeight);

                var args = new CollisionEvents.DynamicColliderCreationEventArgs(this);

                CollisionEvents.FireEvent(CollisionEvents.EventType.DynamicColliderCreation, gameObject, args);
            }
Example #14
0
        public void ScaledConvexShape()
        {
            var s  = new CylinderShape(1, 2);
            var v0 = s.GetVolume(0.001f, 10);

            var s1 = new ScaledConvexShape(new CylinderShape(10, 10), new Vector3(0.1f, 0.2f, 0.1f));
            var v1 = s1.GetVolume(0.0001f, 10);

            Assert.IsTrue(Numeric.AreEqual(v0, v1, 0.01f * (1 + v0))); // 1% error is allowed.
        }
Example #15
0
 public void Clone()
 {
     CylinderShape cylinder = new CylinderShape(1.23f, 45.6f);
       CylinderShape clone = cylinder.Clone() as CylinderShape;
       Assert.IsNotNull(clone);
       Assert.AreEqual(cylinder.Radius, clone.Radius);
       Assert.AreEqual(cylinder.Height, clone.Height);
       Assert.AreEqual(cylinder.GetAabb(Pose.Identity).Minimum, clone.GetAabb(Pose.Identity).Minimum);
       Assert.AreEqual(cylinder.GetAabb(Pose.Identity).Maximum, clone.GetAabb(Pose.Identity).Maximum);
 }
Example #16
0
        public void CylinderTest()
        {
            var s  = new CylinderShape(1, 2);
            var v0 = s.GetVolume(0.001f, 10);

            var m  = s.GetMesh(0.001f, 10);
            var v1 = m.GetVolume();

            Assert.IsTrue(Numeric.AreEqual(v0, v1, 0.01f * (1 + v0))); // 1% error is allowed.
        }
 public override CollisionShape GetCollisionShape()
 {
     if (collisionShapePtr == null)
     {
         collisionShapePtr = new CylinderShape(new Vector3(HalfExtent.x, HalfExtent.y, HalfExtent.x).ToBullet());
         ((CylinderShape)collisionShapePtr).LocalScaling = m_localScaling.ToBullet();
         collisionShapePtr.Margin = m_Margin;
     }
     return(collisionShapePtr);
 }
Example #18
0
    public void TestCylinderBox(
        float cylinderX, float cylinderY, float cylinderZ, float cylinderRadius, float cylinderHeight,
        float boxX, float boxY, float boxZ, float boxAngle, float boxHalfSizeX, float boxHalfSizeY, float boxHeight,
        bool expected)
    {
        var cylinder = new CylinderShape(new Vector3(cylinderX, cylinderY, cylinderZ), cylinderHeight, cylinderRadius);

        var box = new BoxShape(new Vector3(boxX, boxY, boxZ), boxAngle, boxHalfSizeX, boxHalfSizeY, boxHeight);

        Assert.Equal(expected, CollisionDetection.IntersectCylinderBox(cylinder, box));
    }
        public void Clone()
        {
            CylinderShape cylinder = new CylinderShape(1.23f, 45.6f);
            CylinderShape clone    = cylinder.Clone() as CylinderShape;

            Assert.IsNotNull(clone);
            Assert.AreEqual(cylinder.Radius, clone.Radius);
            Assert.AreEqual(cylinder.Height, clone.Height);
            Assert.AreEqual(cylinder.GetAabb(Pose.Identity).Minimum, clone.GetAabb(Pose.Identity).Minimum);
            Assert.AreEqual(cylinder.GetAabb(Pose.Identity).Maximum, clone.GetAabb(Pose.Identity).Maximum);
        }
Example #20
0
    public void TestSphereCylinder(
        float sphereX, float sphereY, float sphereZ, float sphereRadius,
        float cylinderX, float cylinderY, float cylinderZ, float cylinderRadius, float cylinderHeight,
        bool expected)
    {
        var sphere = new SphereShape(new Vector3(sphereX, sphereY, sphereZ), sphereRadius);

        var cylinder = new CylinderShape(new Vector3(cylinderX, cylinderY, cylinderZ), cylinderHeight, cylinderRadius);

        Assert.Equal(expected, CollisionDetection.IntersectSphereCylinder(sphere, cylinder));
    }
Example #21
0
    // Handle player crouch
    private void crouch(float delta)
    {
        if (!headRay.IsColliding())
        {
            CollisionShape shape   = (CollisionShape)GetNode("body");
            CylinderShape  capsule = ((CylinderShape)shape.Shape);

            // Height of collision shape
            float newCollisionHeight = Mathf.Lerp(capsule.Height, 2 - (input["crouch"] * 1.5f), crouchSpeed * delta);
            capsule.Height = newCollisionHeight;
        }
    }
Example #22
0
        public ICylinderShapeImp AddCylinderShape(float3 halfExtents)
        {
            var btCylinderShape = new CylinderShape(Translater.Float3ToBtVector3(halfExtents));

            BtCollisionShapes.Add(btCylinderShape);

            var retval = new CylinderShapeImp();

            retval.BtCylinderShape     = btCylinderShape;
            btCylinderShape.UserObject = retval;
            return(retval);
        }
 //Get Collision shape
 public override CollisionShape GetCollisionShape()
 {
     if (Shape != null)
     {
         return(Shape);
     }
     Shape = new CylinderShape(_halfExtents.ToBullet())
     {
         LocalScaling = transform.localScale.ToBullet()
     };
     return(Shape);
 }
Example #24
0
        public ICylinderShapeImp AddCylinderShape(float halfExtentsX, float halfExtentsY, float halfExtentsZ)
        {
            var btCylinderShape = new CylinderShape(halfExtentsX, halfExtentsY, halfExtentsZ);

            BtCollisionShapes.Add(btCylinderShape);

            var retval = new CylinderShapeImp();

            retval.BtCylinderShape     = btCylinderShape;
            btCylinderShape.UserObject = retval;
            return(retval);
        }
Example #25
0
 public CharacterControllerConvexCast()
 {
     Body = new Capsule(Vector3.Zero, 1.7f, .3f, 10);
     //Making the character a continuous object prevents it from flying through walls which would be pretty jarring from a player's perspective.
     Body.PositionUpdateMode        = PositionUpdateMode.Continuous;
     Body.LocalInertiaTensorInverse = new Matrix3X3();
     Body.CollisionInformation.Events.CreatingPair += RemoveFriction;
     GlueSpeed  = 20;
     StepHeight = 1;
     //construct the casting shape.  It should be a little smaller than the character's radius.
     castShape = new CylinderShape(0, Body.Radius * .8f);
     castShape.CollisionMargin = 0;
 }
        public void Wall()
        {
            Shape shape = new CylinderShape(0.5f, 0.5f);

            for (int i = 0; i < WallSize; i++)
            {
                for (int e = 0; e < WallSize; e++)
                {
                    RigidBody body = new RigidBody(shape);
                    body.Position = new JVector((i % 2 == 0) ? e : e + 0.5f, i + 0.5f, 0);
                    world.AddBody(body);
                }
            }
        }
        private static void GetMass(CylinderShape cylinder, Vector3 scale, float densityOrMass, bool isDensity, out float mass, out Matrix inertia)
        {
            scale = Vector3.Absolute(scale);
            float radiusX = cylinder.Radius * scale.X;
            float heightY = cylinder.Height * scale.Y;
            float radiusZ = cylinder.Radius * scale.Z;

            mass = (isDensity) ? ConstantsF.Pi * radiusX * radiusZ * heightY * densityOrMass : densityOrMass;

            inertia     = Matrix.Zero;
            inertia.M00 = 1.0f / 4.0f * mass * radiusZ * radiusZ + 1.0f / 12.0f * mass * heightY * heightY;
            inertia.M11 = 1.0f / 4.0f * mass * radiusX * radiusX + 1.0f / 4.0f * mass * radiusZ * radiusZ;
            inertia.M22 = 1.0f / 4.0f * mass * radiusX * radiusX + 1.0f / 12.0f * mass * heightY * heightY;
        }
        private void DrawShape(Shape shape, JMatrix ori, JVector pos)
        {
            Model  model       = null;
            Matrix scaleMatrix = Matrix.Identity;

            if (shape is TriangleMeshShape)
            {
                model = models[(int)Models.triangle];
            }
            else if (shape is BoxShape)
            {
                model       = models[(int)Models.box];
                scaleMatrix = Matrix.CreateScale(Conversion.ToXNAVector((shape as BoxShape).Size));
            }
            else if (shape is SphereShape)
            {
                model       = models[(int)Models.sphere];
                scaleMatrix = Matrix.CreateScale((shape as SphereShape).Radius);
            }
            else if (shape is CylinderShape)
            {
                model = models[(int)Models.cylinder];
                CylinderShape cs = shape as CylinderShape;
                scaleMatrix = Matrix.CreateScale(cs.Radius, cs.Height, cs.Radius);
            }
            else if (shape is CapsuleShape)
            {
                model = models[(int)Models.capsule];
            }
            else if (shape is ConeShape)
            {
                ConeShape cs = shape as ConeShape;
                scaleMatrix = Matrix.CreateScale(cs.Radius * 2.0f, cs.Height, cs.Radius * 2.0f);
                model       = models[(int)Models.cone];
            }

            Matrix[] transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World = transforms[mesh.ParentBone.Index] * scaleMatrix *Conversion.ToXNAMatrix(ori) *
                                   Matrix.CreateTranslation(Conversion.ToXNAVector(pos));
                }
                mesh.Draw();
            }
        }
        private void AddShapeToDrawList(Shape shape, JMatrix ori, JVector pos)
        {
            Primitives3D.GeometricPrimitive primitive = null;
            Matrix scaleMatrix = Matrix.Identity;

            if (shape is BoxShape)
            {
                primitive   = primitives[(int)Primitives.box];
                scaleMatrix = Matrix.CreateScale(Conversion.ToXNAVector((shape as BoxShape).Size));
            }
            else if (shape is SphereShape)
            {
                primitive   = primitives[(int)Primitives.sphere];
                scaleMatrix = Matrix.CreateScale((shape as SphereShape).Radius);
            }
            else if (shape is CylinderShape)
            {
                primitive = primitives[(int)Primitives.cylinder];
                CylinderShape cs = shape as CylinderShape;
                scaleMatrix = Matrix.CreateScale(cs.Radius, cs.Height, cs.Radius);
            }
            else if (shape is CapsuleShape)
            {
                primitive = primitives[(int)Primitives.capsule];
                CapsuleShape cs = shape as CapsuleShape;
                scaleMatrix = Matrix.CreateScale(cs.Radius * 2, cs.Length, cs.Radius * 2);
            }
            else if (shape is ConeShape)
            {
                ConeShape cs = shape as ConeShape;
                scaleMatrix = Matrix.CreateScale(cs.Radius, cs.Height, cs.Radius);
                primitive   = primitives[(int)Primitives.cone];
            }

            /*else if (shape is ConvexHullShape)
             * {
             *  Console.WriteLine("convex");
             *  ConvexHullShape cs = shape as ConvexHullShape;
             *  //scaleMatrix = Matrix.CreateScale(cs.Radius, cs.Height, cs.Radius);
             *  //scaleMatrix = Matrix.CreateScale(Conversion.ToXNAVector((shape as BoxShape).Size));
             *  primitive = primitives[(int)Primitives.convexHull];
             *
             * }*/

            if (primitive != null)
            {
                primitive.AddWorldMatrix(scaleMatrix * Conversion.ToXNAMatrix(ori) * Matrix.CreateTranslation(Conversion.ToXNAVector(pos)));
            }
        }
        public void TestProperties()
        {
            CylinderShape b = new CylinderShape();

            Assert.AreEqual(0, b.Radius);
            Assert.AreEqual(0, b.Height);

            b.Height = 10;
            Assert.AreEqual(10, b.Height);
            Assert.AreEqual(0, b.Radius);

            b.Radius = 4;
            Assert.AreEqual(10, b.Height);
            Assert.AreEqual(4, b.Radius);
        }
        protected override void OnInitializePhysics()
        {
            // collision configuration contains default setup for memory, collision setup
            CollisionConf = new DefaultCollisionConfiguration();
            Dispatcher    = new CollisionDispatcher(CollisionConf);

            Broadphase = new AxisSweep3(new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000));

            World         = new DiscreteDynamicsWorld(Dispatcher, Broadphase, null, CollisionConf);
            World.Gravity = new Vector3(0, -10, 0);

            var groundShape = new BoxShape(30, 1, 30);
            var ground      = LocalCreateRigidBody(0, Matrix.Translation(0, -5, 0), groundShape);

            ground.UserObject = "metal.wav";
            ground            = LocalCreateRigidBody(0, Matrix.Translation(0, 0, 0) * Matrix.RotationZ((float)-Math.PI / 4), groundShape);
            ground.UserObject = "metal.wav";
            var groundShape2 = new BoxShape(5, 1, 30);

            ground            = LocalCreateRigidBody(0, Matrix.Translation(25, -3, 0), groundShape2);
            ground.UserObject = "metal.wav";

            var boxShape = new BoxShape(1, 0.5f, 2);

            for (int i = 0; i < 4; i++)
            {
                var box = LocalCreateRigidBody(1, Matrix.Translation(i * 1.5f, i * 3 + 10, i * 3), boxShape);
                box.UserObject = "metal.wav";
            }

            var sphereShape = new SphereShape(1);

            for (int i = 0; i < 4; i++)
            {
                var sphere = LocalCreateRigidBody(1, Matrix.Translation(i, i * 3 + 20, 0), sphereShape);
                sphere.UserObject = "rubber.wav";
            }

            var cylinderShape = new CylinderShape(0.5f, 1, 0.5f);

            for (int i = 0; i < 4; i++)
            {
                var cylinder = LocalCreateRigidBody(1, Matrix.Translation(i, i * 3 + 20, 3), cylinderShape);
                cylinder.UserObject = "can.wav";
            }

            ManifoldPoint.ContactAdded += ContactAdded;
        }
Example #32
0
        public CharacterBase(int x, int y, Level level)
            : this()
        {
            if (level != null)
            {
                Level = level;

                Location = new Point2(x, y);

                Type = (CharacterType)level.Map.Planes[(int)Level.Planes.Objects][y, x];

                SetAxisLock(PhysicsServer.BodyAxis.AngularX, true);
                SetAxisLock(PhysicsServer.BodyAxis.AngularY, true);
                SetAxisLock(PhysicsServer.BodyAxis.AngularZ, true);

                MoveLockY = true;

                CollisionShape colShape = new CollisionShape();
                CylinderShape  cylShape = new CylinderShape();

                cylShape.Height = Level.CellSize;
                cylShape.Radius = Level.CellSize * 0.25f;

                colShape.Shape = cylShape;

                AddChild(colShape);

                CollisionLayer = (uint)Level.CollisionLayers.Characters;
                CollisionMask  = (uint)(
                    Level.CollisionLayers.Characters |
                    Level.CollisionLayers.Static |
                    Level.CollisionLayers.Doors |
                    Level.CollisionLayers.Walls |
                    Level.CollisionLayers.Floor |
                    Level.CollisionLayers.Pickups |
                    Level.CollisionLayers.Projectiles);

                Level.AddChild(this);

                Transform tform = this.Transform;

                tform.origin = level.MapToWorld(x, y);

                this.Transform = tform;

                SetPhysicsProcess(true);
            }
        }
Example #33
0
        private RigidBody CreateGear(float radius, Matrix transform)
        {
            const float mass = 6.28f;

            var shape = new CompoundShape();
            var axle  = new CylinderShape(0.2f, 0.25f, 0.2f);
            var wheel = new CylinderShape(radius, 0.025f, radius);

            shape.AddChildShape(Matrix.Identity, axle);
            shape.AddChildShape(Matrix.Identity, wheel);

            RigidBody body = LocalCreateRigidBody(mass, transform, shape);

            body.LinearFactor = Vector3.Zero;
            return(body);
        }
Example #34
0
 public void HeightException()
 {
     CylinderShape b = new CylinderShape(3, 7);
       b.Height = -4;
 }
Example #35
0
        public void SerializationXml()
        {
            var a = new CylinderShape(11, 22);

              // Serialize object.
              var stream = new MemoryStream();
              var serializer = new XmlSerializer(typeof(Shape));
              serializer.Serialize(stream, a);

              // Output generated xml. Can be manually checked in output window.
              stream.Position = 0;
              var xml = new StreamReader(stream).ReadToEnd();
              Trace.WriteLine("Serialized Object:\n" + xml);

              // Deserialize object.
              stream.Position = 0;
              var deserializer = new XmlSerializer(typeof(Shape));
              var b = (CylinderShape)deserializer.Deserialize(stream);

              Assert.AreEqual(a.Radius, b.Radius);
              Assert.AreEqual(a.Height, b.Height);
        }
        public ICylinderShapeImp AddCylinderShape(float3 halfExtents)
        {
            var btCylinderShape = new CylinderShape(Translater.Float3ToBtVector3(halfExtents));
            BtCollisionShapes.Add(btCylinderShape);

            var retval = new CylinderShapeImp();
            retval.BtCylinderShape = btCylinderShape;
            btCylinderShape.UserObject = retval;
            return retval;
        }
Example #37
0
 public void RadiusException()
 {
     CylinderShape b = new CylinderShape();
       b.Radius = -1;
 }
        public ICylinderShapeImp AddCylinderShape(float halfExtentsX, float halfExtentsY, float halfExtentsZ)
        {
            var btCylinderShape = new CylinderShape(halfExtentsX, halfExtentsY, halfExtentsZ);
            BtCollisionShapes.Add(btCylinderShape);

            var retval = new CylinderShapeImp();
            retval.BtCylinderShape = btCylinderShape;
            btCylinderShape.UserObject = retval;
            return retval;
        }
        /*private void MyTickCallBack(ManifoldPoint cp, CollisionObjectWrapper colobj0wrap, int partid0, int index0, CollisionObjectWrapper colobj1wrap, int partid1, int index1)
        {
            Debug.WriteLine("MyTickCallBack");
            int numManifolds = BtWorld.Dispatcher.NumManifolds;
            RigidBodyImp myRb;
            //Debug.WriteLine("numManifolds: " + numManifolds);
            for (int i = 0; i < numManifolds; i++)
            {
                PersistentManifold contactManifold = BtWorld.Dispatcher.GetManifoldByIndexInternal(i);
                int numContacts = contactManifold.NumContacts;
                if (numContacts > 0)
                {
                    CollisionObject obA = (CollisionObject) contactManifold.Body0;
                    CollisionObject obB = (CollisionObject) contactManifold.Body1;

                   // Debug.WriteLine(numContacts);
                    var pnA = obA.UserObject;

                    for (int j = 0; j < numContacts; j++)
                    {
                        ManifoldPoint pt = contactManifold.GetContactPoint(j);

                    }
                }
            }
        }*/
        public IRigidBodyImp AddRigidBody(float mass, float3 worldTransform, float3 orientation, ICollisionShapeImp colShape/*, float3 intertia*/)
        {
            // Use bullet to do what needs to be done:

             var btMatrix = Matrix.RotationX(orientation.x)
                                    * Matrix.RotationY(orientation.y)
                                    * Matrix.RotationZ(orientation.z)
                                    * Matrix.Translation(worldTransform.x, worldTransform.y, worldTransform.z);

             var btMotionState = new DefaultMotionState(btMatrix);

            var shapeType = colShape.GetType().ToString();

            CollisionShape btColShape;

            var isStatic = false;
            switch (shapeType)
            {
                //Primitives
                case "Fusee.Engine.BoxShapeImp":
                    var box = (BoxShapeImp) colShape;
                    var btBoxHalfExtents = Translater.Float3ToBtVector3(box.HalfExtents);
                    btColShape = new BoxShape(btBoxHalfExtents);
                    break;
                case "Fusee.Engine.CapsuleShapeImp":
                    var capsule = (CapsuleShapeImp) colShape;
                    btColShape = new CapsuleShape(capsule.Radius, capsule.HalfHeight);
                    break;
                case "Fusee.Engine.ConeShapeImp":
                    var cone = (ConeShapeImp) colShape;
                    btColShape = new ConeShape(cone.Radius, cone.Height);
                    break;
                case "Fusee.Engine.CylinderShapeImp":
                    var cylinider = (CylinderShapeImp) colShape;
                    var btCylinderHalfExtents = Translater.Float3ToBtVector3(cylinider.HalfExtents);
                    btColShape = new CylinderShape(btCylinderHalfExtents);
                    break;
                case "Fusee.Engine.MultiSphereShapeImp":
                    var multiSphere = (MultiSphereShapeImp) colShape;
                    var btPositions = new Vector3[multiSphere.SphereCount];
                    var btRadi = new float[multiSphere.SphereCount];
                    for (int i = 0; i < multiSphere.SphereCount; i++)
                    {
                        var pos = Translater.Float3ToBtVector3(multiSphere.GetSpherePosition(i));
                        btPositions[i] = pos;
                        btRadi[i] = multiSphere.GetSphereRadius(i);
                    }
                    btColShape = new MultiSphereShape(btPositions, btRadi);
                    break;
                case "Fusee.Engine.SphereShapeImp":
                    var sphere = (SphereShapeImp) colShape;
                    var btRadius = sphere.Radius;
                    btColShape = new SphereShape(btRadius);
                    break;

                //Misc
                case "Fusee.Engine.CompoundShapeImp":
                    var compShape = (CompoundShapeImp) colShape;
                    btColShape = new CompoundShape(true);
                    btColShape = compShape.BtCompoundShape;
                    break;
                case "Fusee.Engine.EmptyShapeImp":
                    btColShape = new EmptyShape();
                    break;

                //Meshes
                case "Fusee.Engine.ConvexHullShapeImp":
                    var convHull = (ConvexHullShapeImp) colShape;
                    var btPoints= new Vector3[convHull.GetNumPoints()];
                    for (int i = 0; i < convHull.GetNumPoints(); i++)
                    {
                        var point = convHull.GetScaledPoint(i);
                        btPoints[i] = Translater.Float3ToBtVector3(point);
                    }
                    btColShape = new ConvexHullShape(btPoints);
                    //btColShape.LocalScaling = new Vector3(3,3,3);
                    break;
                case "Fusee.Engine.StaticPlaneShapeImp":
                    var staticPlane = (StaticPlaneShapeImp) colShape;
                    Debug.WriteLine("staticplane: " + staticPlane.Margin);
                    var btNormal = Translater.Float3ToBtVector3(staticPlane.PlaneNormal);
                    btColShape = new StaticPlaneShape(btNormal, staticPlane.PlaneConstant);
                    isStatic = true;
                    //btColShape.Margin = 0.04f;
                    //Debug.WriteLine("btColshape" + btColShape.Margin);
                    break;
                case "Fusee.Engine.GImpactMeshShapeImp":
                    var gImpMesh = (GImpactMeshShapeImp)colShape;
                    gImpMesh.BtGImpactMeshShape.UpdateBound();
                    var btGimp = new GImpactMeshShape(gImpMesh.BtGImpactMeshShape.MeshInterface);

                    btGimp.UpdateBound();
                    btColShape = btGimp;

                    break;
                //Default
                default:
                    Debug.WriteLine("defaultImp");
                    btColShape = new EmptyShape();
                    break;
            }

            var btLocalInertia = btColShape.CalculateLocalInertia(mass);
               // btLocalInertia *= (10.0f*10);
            RigidBodyConstructionInfo btRbcInfo = new RigidBodyConstructionInfo(mass, btMotionState, btColShape,
                btLocalInertia);

            var btRigidBody = new RigidBody(btRbcInfo);
            btRigidBody.Restitution = 0.2f;
            btRigidBody.Friction = 0.2f;
            btRigidBody.CollisionFlags = CollisionFlags.CustomMaterialCallback;

            BtWorld.AddRigidBody(btRigidBody);
            btRbcInfo.Dispose();
            var retval = new RigidBodyImp();
            retval._rbi = btRigidBody;
            btRigidBody.UserObject = retval;
            return retval;
        }
Example #40
0
        public void TestProperties()
        {
            CylinderShape b = new CylinderShape();
              Assert.AreEqual(0, b.Radius);
              Assert.AreEqual(0, b.Height);

              b.Height = 10;
              Assert.AreEqual(10, b.Height);
              Assert.AreEqual(0, b.Radius);

              b.Radius = 4;
              Assert.AreEqual(10, b.Height);
              Assert.AreEqual(4, b.Radius);
        }
Example #41
0
        public void SerializationBinary()
        {
            var a = new CylinderShape(11, 22);

              // Serialize object.
              var stream = new MemoryStream();
              var formatter = new BinaryFormatter();
              formatter.Serialize(stream, a);

              // Deserialize object.
              stream.Position = 0;
              var deserializer = new BinaryFormatter();
              var b = (CylinderShape)deserializer.Deserialize(stream);

              Assert.AreEqual(a.Radius, b.Radius);
              Assert.AreEqual(a.Height, b.Height);
        }