Esempio n. 1
0
        private void heightmapDemo(object sender, RoutedEventArgs e)
        {
            enable3dOutput();

            var toolDiameter = 5.0;
            var margin       = toolDiameter;
            var radius       = 50.0;

            var mapResolution = 0.2;
            var center        = new Point(margin + radius, margin + radius);
            var modelShape    = new ConeShape(center, radius);

            var mapStart = new Point(0, 0);
            var mapEnd   = new Point(mapStart.X + 2 * margin + 2 * radius, mapStart.Y + 2 * margin + 2 * radius);
            var model    = HeightMap.From(modelShape, mapStart, mapEnd, mapResolution);


            //simulate parallel machining
            var blockHeight   = radius + margin;
            var stock         = HeightMap.Flat(blockHeight, mapStart, mapEnd, mapResolution);
            var machiningStep = 1.0;
            var tool          = new BallnoseEndMill(toolDiameter);

            simulateLinearMachining(stock, tool, model, toolDiameter, machiningStep, true);
            simulateLinearMachining(stock, tool, model, toolDiameter, machiningStep, false);

            output3D(stock);
        }
Esempio n. 2
0
        public IEnumerator MaterialTransitionWithParametrizableMeshes()
        {
            yield return(InitScene(reloadUnityScene: false));

            DCL.Configuration.EnvironmentSettings.DEBUG = true;
            sceneController.SetDebug();

            var entity1 = TestHelpers.CreateSceneEntity(scene);

            ParcelSettings.VISUAL_LOADING_ENABLED = true;

            DecentralandEntity entity = null;
            ConeShape          shape  = TestHelpers.InstantiateEntityWithShape <ConeShape, ConeShape.Model>
                                        (
                scene,
                DCL.Models.CLASS_ID.CONE_SHAPE,
                new Vector3(2, 1, 3),
                out entity,
                new ConeShape.Model());

            yield return(null);

            float timeout = 0f;
            float maxTime = 20f;

            while (timeout < maxTime)
            {
                timeout += Time.deltaTime;

                if (timeout > maxTime)
                {
                    timeout = maxTime;
                }

                if (entity.meshRootGameObject != null)
                {
                    var c = entity.meshRootGameObject.GetComponentInChildren <MaterialTransitionController>();

                    if (c != null) // NOTE(Brian): Wait for it
                    {
                        Assert.IsTrue(!c.useHologram, "useHologram must be false");
                        Assert.IsTrue(entity.meshRootGameObject != null, "meshGameObject is null");
                        Assert.IsTrue(c.placeholder == null,
                                      "placeholder must be null because we're not using holograms with parametric shapes.");

                        yield return(new WaitForSeconds(2f));

                        Assert.IsTrue(c == null, "MaterialTransitionController should be destroyed by now!");

                        break;
                    }
                }

                yield return(null);
            }

            Assert.Less(timeout, maxTime + 0.1f, "Timeout! MaterialTransitionController never appeared?");

            yield return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Adds the child shape.
        /// </summary>
        /// <param name="localTransform">The local transform.</param>
        /// <param name="shape">The shape.</param>
        public void AddChildShape(float4x4 localTransform, IConeShapeImp shape)
        {
            var btChildShape     = new ConeShape(shape.Radius, shape.Height);
            var btLocalTransform = Translator.Float4X4ToBtMatrix(localTransform);

            BtCompoundShape.AddChildShape(btLocalTransform, btChildShape);
        }
Esempio n. 4
0
        public override CollisionShape CopyCollisionShape()
        {
            ConeShape cs = new ConeShape(radius, height);

            cs.LocalScaling = m_localScaling.ToBullet();
            return(cs);
        }
Esempio n. 5
0
        public void GetSupportPoint()
        {
            Assert.AreEqual(new Vector3(0, 0, 0), new ConeShape().GetSupportPoint(new Vector3(1, 0, 0)));
            Assert.AreEqual(new Vector3(0, 0, 0), new ConeShape().GetSupportPoint(new Vector3(0, 1, 0)));
            Assert.AreEqual(new Vector3(0, 0, 0), new ConeShape().GetSupportPoint(new Vector3(0, 0, 1)));
            Assert.AreEqual(new Vector3(0, 0, 0), new ConeShape().GetSupportPoint(new Vector3(1, 1, 1)));

            Assert.AreEqual(new Vector3(10, 0, 0), new ConeShape(10, 30).GetSupportPoint(new Vector3(1, 0, 0)));
            Assert.AreEqual(new Vector3(0, 30, 0), new ConeShape(10, 30).GetSupportPoint(new Vector3(0, 1, 0)));
            Assert.AreEqual(new Vector3(0, 0, 10), new ConeShape(10, 30).GetSupportPoint(new Vector3(0, 0, 1)));
            Assert.AreEqual(new Vector3(-10, 0, 0), new ConeShape(10, 30).GetSupportPoint(new Vector3(-1, 0, 0)));
            Assert.AreEqual(new Vector3(10, 0, 0), new ConeShape(10, 30).GetSupportPoint(new Vector3(0, -1, 0)));
            Assert.AreEqual(new Vector3(0, 0, -10), new ConeShape(10, 30).GetSupportPoint(new Vector3(0, 0, -1)));
            Assert.AreEqual(new Vector3(0, 30, 0), new ConeShape(10, 30).GetSupportPoint(new Vector3(1, 1, 1)));
            Assert.AreEqual(10 * new Vector3(-1, 0, -1).Normalized, new ConeShape(10, 30).GetSupportPoint(new Vector3(-1, -1, -1)));

            ConeShape c = new ConeShape(10, 30);

            c.Radius = 0;
            Assert.AreEqual(new Vector3(0, 0, 0), c.GetSupportPoint(new Vector3(1, 0, 0)));
            c.Height = 0;
            Assert.AreEqual(new Vector3(0, 0, 0), c.GetSupportPoint(new Vector3(0, 1, 0)));
            c.Radius = 0;
            Assert.AreEqual(new Vector3(0, 0, 0), c.GetSupportPoint(new Vector3(0, 1, 0)));
        }
Esempio n. 6
0
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public GeneralConvexPairStressDemo(DemosGame game)
            : base(game)
        {
            Space.Remove(vehicle.Vehicle);
            //Enable simplex caching.
            ConfigurationHelper.ApplySuperSpeedySettings(Space);

            for (int i = 0; i < 2000; i++)
            {
                EntityShape shape;
                switch (i % 3)
                {
                case 0:
                    shape = new CylinderShape(0.5m + (Fix64)random.NextDouble() * 1.5m, 0.5m + (Fix64)random.NextDouble() * 1.5m);
                    break;

                case 1:
                    shape = new ConeShape(0.5m + (Fix64)random.NextDouble() * 1.5m, 0.5m + (Fix64)random.NextDouble() * 1.5m);
                    break;

                default:
                    shape = new CapsuleShape(0.5m + (Fix64)random.NextDouble() * 1.5m, 0.5m + (Fix64)random.NextDouble() * 1.5m);
                    break;
                }

                var toAdd = new Entity(shape, 2);
                //toAdd.LocalInertiaTensorInverse = new BEPUutilities.Matrix3x3();
                RandomizeEntityState(toAdd);
                Space.Add(toAdd);
            }
            Space.ForceUpdater.Gravity = new Vector3();

            game.Camera.Position = new Vector3(0, 6, 15);
        }
Esempio n. 7
0
        Mesh CreateConeShape(ConeShape shape)
        {
            Mesh mesh = Mesh.CreateCylinder(device, 0, shape.Radius, shape.Height, 16, 1);

            shapes.Add(shape, mesh);
            return(mesh);
        }
Esempio n. 8
0
 public ConeCollider()
 {
     NotifyColliderChanged(
         new Entity <ConvexCollidable <ConeShape> >(
             new ConvexCollidable <ConeShape>(
                 shape = new ConeShape(1, 1))));
 }
Esempio n. 9
0
        private CollisionShape MakeCollisionShape()
        {
            CollisionShape shape;

            switch (Shape)
            {
            case Shape.Cube:
                shape = new BoxShape(1, 1, 1);
                break;

            case Shape.Sphere:
                shape = new SphereShape(1);
                break;

            case Shape.Cylinder:
                shape = new ConeShape(1, 1);
                break;

            case Shape.Wedge:
                var wedgeGeo = Primitives.WedgeGeometry;
                shape = new ConvexTriangleMeshShape(new TriangleIndexVertexArray(wedgeGeo.Indices, wedgeGeo.Vertices.Select(v => (BulletVector3)v.Position).ToList()));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            shape.Margin      *= PhysicsSimulation.Scale;
            shape.Margin       = 0;
            shape.LocalScaling = new BulletVector3(_size.x / 2, _size.y / 2, _size.z / 2);
            return(shape);
        }
        public override void Init()
        {
            base.Init();
            Vector3 worldScale = WorldScale;

            m_scaledShape            = new ConeShape(worldScale.Y * Length, Math.Abs(Math.Max(worldScale.X, worldScale.Z)) * Radius);
            m_scaledStaticCollidable = m_scaledShape.GetCollidableInstance();
        }
Esempio n. 11
0
        public void GetMesh()
        {
            var s = new ConeShape(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.
        }
Esempio n. 12
0
 public override CollisionShape GetCollisionShape()
 {
     if (collisionShapePtr == null)
     {
         collisionShapePtr = new ConeShape(radius, height);
     }
     return(collisionShapePtr);
 }
Esempio n. 13
0
 public override CollisionShape GetCollisionShape()
 {
     if (collisionShapePtr == null)
     {
         collisionShapePtr = new ConeShape(radius, height);
         ((ConeShape)collisionShapePtr).LocalScaling = m_localScaling.ToBullet();
     }
     return(collisionShapePtr);
 }
Esempio n. 14
0
        public void GetMesh()
        {
            var s    = new ConeShape(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.
        }
            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);
                }
            }
Esempio n. 16
0
 public void Clone()
 {
     ConeShape cone = new ConeShape(1.23f, 45.6f);
       ConeShape clone = cone.Clone() as ConeShape;
       Assert.IsNotNull(clone);
       Assert.AreEqual(cone.Radius, clone.Radius);
       Assert.AreEqual(cone.Height, clone.Height);
       Assert.AreEqual(cone.GetAabb(Pose.Identity).Minimum, clone.GetAabb(Pose.Identity).Minimum);
       Assert.AreEqual(cone.GetAabb(Pose.Identity).Maximum, clone.GetAabb(Pose.Identity).Maximum);
 }
Esempio n. 17
0
        public void ConeTest()
        {
            var s  = new ConeShape(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.
        }
Esempio n. 18
0
        public void Clone()
        {
            ConeShape cone  = new ConeShape(1.23f, 45.6f);
            ConeShape clone = cone.Clone() as ConeShape;

            Assert.IsNotNull(clone);
            Assert.AreEqual(cone.Radius, clone.Radius);
            Assert.AreEqual(cone.Height, clone.Height);
            Assert.AreEqual(cone.GetAabb(Pose.Identity).Minimum, clone.GetAabb(Pose.Identity).Minimum);
            Assert.AreEqual(cone.GetAabb(Pose.Identity).Maximum, clone.GetAabb(Pose.Identity).Maximum);
        }
Esempio n. 19
0
        //ConeShape
        public IConeShapeImp AddConeShape(float radius, float height)
        {
            var btConeShape = new ConeShape(radius, height);

            BtCollisionShapes.Add(btConeShape);

            var retval = new ConeShapeImp();

            retval.BtConeShape     = btConeShape;
            btConeShape.UserObject = retval;
            return(retval);
        }
Esempio n. 20
0
 //Get Collision shape
 public override CollisionShape GetCollisionShape()
 {
     if (Shape != null)
     {
         return(Shape);
     }
     Shape = new ConeShape(_radius, _height)
     {
         LocalScaling = transform.localScale.ToBullet()
     };
     return(Shape);
 }
Esempio n. 21
0
        public static void GetShapeMeshData(EntityCollidable collidable, List <VertexPositionNormalTexture> vertices, List <ushort> indices)
        {
            ConeShape coneShape = collidable.Shape as ConeShape;

            if (coneShape == null)
            {
                throw new ArgumentException("Wrong shape type.");
            }

            float verticalOffset     = -coneShape.Height / 4;
            float angleBetweenFacets = MathHelper.TwoPi / NumSides;
            float radius             = coneShape.Radius;

            //Create the vertex list

            var topVertexPosition = new Vector3(0, coneShape.Height + verticalOffset, 0);

            for (int i = 0; i < NumSides; i++)
            {
                float   theta    = i * angleBetweenFacets;
                var     position = new Vector3((float)Math.Cos(theta) * radius, verticalOffset, (float)Math.Sin(theta) * radius);
                Vector3 offset   = topVertexPosition - position;
                Vector3 normal   = Vector3.Normalize(Vector3.Cross(Vector3.Cross(offset, Vector3.Up), offset));
                //Top vertex
                vertices.Add(new VertexPositionNormalTexture(topVertexPosition, normal, Vector2.Zero));
                //Sloped vertices
                vertices.Add(new VertexPositionNormalTexture(position, normal, Vector2.Zero));
                //Bottom vertices
                vertices.Add(new VertexPositionNormalTexture(position, Vector3.Down, Vector2.Zero));
            }


            //Create the index list
            for (ushort i = 0; i < vertices.Count; i += 3)
            {
                //Each iteration, the loop advances to the next vertex 'column.'
                //Four triangles per column (except for the four degenerate cap triangles).

                //Sloped Triangles
                indices.Add(i);
                indices.Add((ushort)(i + 1));
                indices.Add((ushort)((i + 4) % vertices.Count));

                //Bottom cap triangles.
                var nextIndex = (ushort)((i + 5) % vertices.Count);
                if (nextIndex != 2) //Don't add cap indices if it's going to be a degenerate triangle.
                {
                    indices.Add((ushort)(i + 2));
                    indices.Add(2);
                    indices.Add(nextIndex);
                }
            }
        }
        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)));
            }
        }
Esempio n. 24
0
        private static void GetMass(ConeShape cone, Vector3 scale, float densityOrMass, bool isDensity, out float mass, out Vector3 centerOfMass, out Matrix inertia)
        {
            float radiusX = cone.Radius * Math.Abs(scale.X);
            float radiusZ = cone.Radius * Math.Abs(scale.Z);
            float height  = cone.Height * Math.Abs(scale.Y);

            mass = (isDensity) ? 1.0f / 3.0f * ConstantsF.Pi * radiusX * radiusZ * height * densityOrMass : densityOrMass;

            centerOfMass = new Vector3(0, height / 4, 0) * Math.Sign(scale.Y);

            inertia     = Matrix.Zero;
            inertia.M00 = 3.0f / 20.0f * mass * (radiusZ * radiusZ + 1.0f / 4.0f * height * height);
            inertia.M11 = 3.0f / 20.0f * mass * (radiusX * radiusX + radiusZ * radiusZ);
            inertia.M22 = 3.0f / 20.0f * mass * (radiusX * radiusX + 1.0f / 4.0f * height * height);
        }
Esempio n. 25
0
        public void TestProperties()
        {
            ConeShape b = new ConeShape();

            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);
        }
Esempio n. 26
0
        /// <summary>
        /// Add shape for debug-information on the screen
        /// </summary>
        /// <param name="shape">Shape of the object</param>
        /// <param name="ori">Orientation</param>
        /// <param name="pos">Position</param>
        private void AddShapeToDrawList(Shape shape, JMatrix ori, JVector pos)
        {
            GeometricPrimitive primitive   = null;
            Matrix             scaleMatrix = Matrix.Identity;

            if (shape is BoxShape)
            {
                primitive   = _primitives[(int)PrimitiveTypes.Box];
                scaleMatrix = Matrix.CreateScale(Conversion.ToXnaVector((shape as BoxShape).Size));
            }
            else if (shape is SphereShape)
            {
                primitive   = _primitives[(int)PrimitiveTypes.Sphere];
                scaleMatrix = Matrix.CreateScale((shape as SphereShape).Radius);
            }
            else if (shape is CylinderShape)
            {
                primitive = _primitives[(int)PrimitiveTypes.Cylinder];
                CylinderShape cs = shape as CylinderShape;
                scaleMatrix = Matrix.CreateScale(cs.Radius, cs.Height, cs.Radius);
            }
            else if (shape is CapsuleShape)
            {
                primitive = _primitives[(int)PrimitiveTypes.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)PrimitiveTypes.Cone];
            }
            else if (shape is ConvexHullShape)
            {
                ConvexHullShape cs = shape as ConvexHullShape;
                primitive   = _primitives[(int)PrimitiveTypes.Box];
                scaleMatrix = Matrix.CreateScale(Conversion.ToXnaVector(cs.BoundingBox.Max - cs.BoundingBox.Min));
            }

            if (primitive != null)
            {
                primitive.AddWorldMatrix(scaleMatrix * Conversion.ToXnaMatrix(ori) *
                                         Matrix.CreateTranslation(Conversion.ToXnaVector(pos)));
            }
        }
        public void MakeNoiseScene()
        {
            Reset();

            float scale = 1.0f;

            AddFloor(30.0f * scale, 5, -0.5f);

            int      subdiv       = 3;
            Geometry coneGeometry = new RenderStack.Geometry.Shapes.Cone(
                -1.0f / 3.0f, 2.0f / 3.0f, 0.75f, 0.0f, true, false, 24 * subdiv, 10 * subdiv
                );

            coneGeometry.Transform(
                Matrix4.CreateRotation(
                    RenderStack.Math.Conversions.DegreesToRadians(90.0f),
                    Vector3.UnitZ
                    )
                );
            //coneGeometry = Mush(0.08f, coneGeometry);
            var coneMesh  = new GeometryMesh(coneGeometry, NormalStyle.CornerNormals);
            var coneShape = new ConeShape(1.0f, 0.75f);
            var gold      = materialManager["noisy"];
            var magenta   = materialManager["magenta"];

            userInterfaceManager.CurrentMaterial = "noisy";

            Geometry ellipsoidGeometry = new RenderStack.Geometry.Shapes.Ellipsoid(
                new Vector3(0.5f, 1.0f, 1.5f), 20, 12
                );

            var ellipsoidMesh  = new GeometryMesh(ellipsoidGeometry, NormalStyle.PointNormals);
            var ellipsoidShape = new EllipsoidShape(0.5f, 1.0f, 1.5f);

            for (float x = -4.0f; x <= 4.0f; x += 8.0f)
            {
                for (float z = -4.0f; z <= 4.0f; z += 8.0f)
                {
                    AddModel(new Model("cone", coneMesh, gold, x, 1.0f / 3.0f, z), coneShape).RigidBody.IsActive            = false;
                    AddModel(new Model("ellipsoid", ellipsoidMesh, magenta, x, 2.0f, z), ellipsoidShape).RigidBody.IsActive = false;
                }
            }

            AddCameras();
            AddCameraUserControls();
        }
Esempio n. 28
0
        public void SerializationBinary()
        {
            var a = new ConeShape(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            = (ConeShape)deserializer.Deserialize(stream);

            Assert.AreEqual(a.Radius, b.Radius);
            Assert.AreEqual(a.Height, b.Height);
        }
Esempio n. 29
0
        public void ConeMass()
        {
            var       s = new ConeShape(1, 2);
            float     m0;
            Vector3F  com0;
            Matrix33F i0;

            MassHelper.GetMass(s, new Vector3F(1, -2, -3), 1, true, 0.001f, 10, out m0, out com0, out i0);

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

            m.Transform(Matrix44F.CreateScale(1, -2, -3));
            float     m1;
            Vector3F  com1;
            Matrix33F i1;

            MassHelper.GetMass(m, out m1, out com1, out i1);

            const float e = 0.01f;

            Assert.IsTrue(Numeric.AreEqual(m0, m1, e * (1 + m0)));
            Assert.IsTrue(Vector3F.AreNumericallyEqual(com0, com1, e * (1 + com0.Length)));
            Assert.IsTrue(Matrix33F.AreNumericallyEqual(i0, i1, e * (1 + i0.Trace)));

            // Try other density.
            float     m2;
            Vector3F  com2;
            Matrix33F i2;

            MassHelper.GetMass(s, new Vector3F(1, -2, -3), 0.7f, true, 0.001f, 10, out m2, out com2, out i2);
            Assert.IsTrue(Numeric.AreEqual(m0 * 0.7f, m2, e * (1 + m0)));
            Assert.IsTrue(Vector3F.AreNumericallyEqual(com0, com2, e * (1 + com0.Length)));
            Assert.IsTrue(Matrix33F.AreNumericallyEqual(i0 * 0.7f, i2, e * (1 + i0.Trace)));

            // Try with target mass.
            float     m3;
            Vector3F  com3;
            Matrix33F i3;

            MassHelper.GetMass(s, new Vector3F(1, -2, -3), 23, false, 0.001f, 10, out m3, out com3, out i3);
            Assert.IsTrue(Numeric.AreEqual(23, m3, e * (1 + m0)));
            Assert.IsTrue(Vector3F.AreNumericallyEqual(com0, com3, e * (1 + com0.Length)));
            Assert.IsTrue(Matrix33F.AreNumericallyEqual(i0 * 23 / m0, i3, e * (1 + i0.Trace)));
        }
Esempio n. 30
0
        private void RenderEntity(EntityCollidable entity)
        {
            if (entity is CompoundCollidable)
            {
                CompoundCollidable compound = entity as CompoundCollidable;

                for (int i = 0; i < compound.Children.Count; i++)
                {
                    CompoundChild child = compound.Children[i];
                    Matrix4       lt    = child.Entry.LocalTransform.Matrix;
                    GL.MultMatrix(ref lt);

                    RenderEntity(child.CollisionInformation);
                }
            }
            else
            {
                EntityShape shape = entity.Shape;

                if (shape is BoxShape)
                {
                    BoxShape box = shape as BoxShape;
                    RenderCube(box.Width, box.Height, box.Length);
                }
                else if (shape is CylinderShape)
                {
                    CylinderShape cylinder = shape as CylinderShape;
                    RenderCylinder(cylinder.Radius, cylinder.Height);
                }
                else if (shape is ConeShape)
                {
                    ConeShape cone = shape as ConeShape;
                    RenderCone(cone.Radius, cone.Height);
                }
                else if (shape is SphereShape)
                {
                    SphereShape sphere = shape as SphereShape;
                    RenderSphere(sphere.Radius);
                }
            }
        }
Esempio n. 31
0
        public void SerializationXml()
        {
            var a = new ConeShape(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            = (ConeShape)deserializer.Deserialize(stream);

            Assert.AreEqual(a.Radius, b.Radius);
            Assert.AreEqual(a.Height, b.Height);
        }
        /*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;
        }
 public void AddChildShape(float4x4 localTransform, IConeShapeImp shape)
 {
     var btChildShape = new ConeShape(shape.Radius, shape.Height);
     var btLocalTransform = Translater.Float4X4ToBtMatrix(localTransform);
     BtCompoundShape.AddChildShape(btLocalTransform, btChildShape);
 }
Esempio n. 34
0
 public static void CreateConeShape(ConeShape shape, Mesh mesh)
 {
     ProceduralPrimitives.CreateMeshCone(mesh, shape.Height, shape.Radius, 0f, 10);
 }
Esempio n. 35
0
 public void RadiusException()
 {
     ConeShape b = new ConeShape();
       b.Radius = -1;
 }
Esempio n. 36
0
        public void GetSupportPoint()
        {
            Assert.AreEqual(new Vector3F(0, 0, 0), new ConeShape().GetSupportPoint(new Vector3F(1, 0, 0)));
              Assert.AreEqual(new Vector3F(0, 0, 0), new ConeShape().GetSupportPoint(new Vector3F(0, 1, 0)));
              Assert.AreEqual(new Vector3F(0, 0, 0), new ConeShape().GetSupportPoint(new Vector3F(0, 0, 1)));
              Assert.AreEqual(new Vector3F(0, 0, 0), new ConeShape().GetSupportPoint(new Vector3F(1, 1, 1)));

              Assert.AreEqual(new Vector3F(10, 0, 0), new ConeShape(10, 30).GetSupportPoint(new Vector3F(1, 0, 0)));
              Assert.AreEqual(new Vector3F(0, 30, 0), new ConeShape(10, 30).GetSupportPoint(new Vector3F(0, 1, 0)));
              Assert.AreEqual(new Vector3F(0, 0, 10), new ConeShape(10, 30).GetSupportPoint(new Vector3F(0, 0, 1)));
              Assert.AreEqual(new Vector3F(-10, 0, 0), new ConeShape(10, 30).GetSupportPoint(new Vector3F(-1, 0, 0)));
              Assert.AreEqual(new Vector3F(10, 0, 0), new ConeShape(10, 30).GetSupportPoint(new Vector3F(0, -1, 0)));
              Assert.AreEqual(new Vector3F(0, 0, -10), new ConeShape(10, 30).GetSupportPoint(new Vector3F(0, 0, -1)));
              Assert.AreEqual(new Vector3F(0, 30, 0), new ConeShape(10, 30).GetSupportPoint(new Vector3F(1, 1, 1)));
              Assert.AreEqual(10 * new Vector3F(-1, 0, -1).Normalized, new ConeShape(10, 30).GetSupportPoint(new Vector3F(-1, -1, -1)));

              ConeShape c= new ConeShape(10, 30);
              c.Radius = 0;
              Assert.AreEqual(new Vector3F(0, 0, 0), c.GetSupportPoint(new Vector3F(1, 0, 0)));
              c.Height = 0;
              Assert.AreEqual(new Vector3F(0, 0, 0), c.GetSupportPoint(new Vector3F(0, 1, 0)));
              c.Radius = 0;
              Assert.AreEqual(new Vector3F(0, 0, 0), c.GetSupportPoint(new Vector3F(0, 1, 0)));
        }
Esempio n. 37
0
        public void SerializationBinary()
        {
            var a = new ConeShape(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 = (ConeShape)deserializer.Deserialize(stream);

              Assert.AreEqual(a.Radius, b.Radius);
              Assert.AreEqual(a.Height, b.Height);
        }
Esempio n. 38
0
        public void SerializationXml()
        {
            var a = new ConeShape(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 = (ConeShape)deserializer.Deserialize(stream);

              Assert.AreEqual(a.Radius, b.Radius);
              Assert.AreEqual(a.Height, b.Height);
        }
Esempio n. 39
0
 public void HeightException()
 {
     ConeShape b = new ConeShape(3, 7);
       b.Height = -4;
 }
Esempio n. 40
0
        public void TestProperties()
        {
            ConeShape b = new ConeShape();
              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);
        }
        //ConeShape
        public IConeShapeImp AddConeShape(float radius, float height)
        {
            var btConeShape = new ConeShape(radius, height);
            BtCollisionShapes.Add(btConeShape);

            var retval = new ConeShapeImp();
            retval.BtConeShape = btConeShape;
            btConeShape.UserObject = retval;
            return retval;
        }