public static MaterialPrimitivePair CreatePair(ref Primitive primitive, ref int materialID, ref MaterialProperties materialProperties)
        {
            MaterialPrimitivePair newPair = new MaterialPrimitivePair();
            newPair.Primitive = primitive;
            newPair.MaterialProperties = materialProperties;

            return newPair;
        }
        /// <summary>
        /// Adds a primitive to this collision skin - the primitive is
        /// copied (so you can pass in something on the stack, or delete
        /// the original) - perhaps using reference counting.  Returns the
        /// primitive index, or -1 if failure Also takes that material ID
        /// and the properties used when a collision ID is USER_DEFINED
        /// </summary>
        private int AddPrimitive(Primitive prim, int matID, MaterialProperties matProps)
        {
            Primitive newPrim = prim.Clone();

            if (newPrim == null)
                throw new ArgumentException("Not able to clone primitive!");

            materialIDs.Add(matID);
            materialProperties.Add(matProps);

            primitivesOldWorld.Add(prim.Clone());
            primitivesNewWorld.Add(prim.Clone());
            primitivesLocal.Add(newPrim);

            UpdateWorldBoundingBox();

            return materialIDs.Count - 1;
        }
 /// <summary>
 /// Sets the material properties for a primitive. In this case the
 /// material ID will be automatically set to USER_DEFINED
 /// </summary>
 /// <param name="prim"></param>
 /// <param name="matProperties"></param>
 public void SetMaterialProperties(int prim, MaterialProperties matProperties)
 {
     materialProperties[prim] = matProperties;
     materialIDs[prim] = (int)MaterialTable.MaterialID.UserDefined;
 }
 public int AddPrimitive(Primitive prim, MaterialProperties matProps)
 {
     return AddPrimitive(prim, (int)MaterialTable.MaterialID.UserDefined, matProps);
 }
 public static MaterialPrimitivePair CreatePair(Primitive primitive, int materialID, ref MaterialProperties materialProperties)
 {
     return CreatePair(ref primitive, ref materialID, ref materialProperties);
 }
 public void Add(Primitive primitive, MaterialProperties materialProperties)
 {
     _materialPrimitivePairs.Add(MaterialPrimitivePair.CreatePair(primitive, (int)MaterialTable.MaterialID.UserDefined, ref materialProperties));
 }
 public void Add(Primitive primitive, int materialID, MaterialProperties materialProperties)
 {
     _materialPrimitivePairs.Add(MaterialPrimitivePair.CreatePair(primitive, materialID, ref materialProperties));
 }
        private void Initialize(Primitive primitive, MaterialProperties materialProperties, PrimitiveProperties primitiveProperties, bool enableBody)
        {
            float mass;
            Vector3 centerOfMass;
            Matrix inertiaTensor;
            Matrix inertiaTensorCoM;

            // Set variables ...
            _primitive = primitive;
            _primitiveProperties = primitiveProperties;
            _materialProperties = materialProperties;

            // Create and link Body and CollisionSkin.
            _body = new Body();
            _skin = new CollisionSkin(_body);
            _body.CollisionSkin = _skin;

            // Add primitive to CollisionSkin.
            _skin.AddPrimitive(primitive, materialProperties);

            // Set body properties.
            _skin.GetMassProperties(primitiveProperties, out mass, out centerOfMass, out inertiaTensor, out inertiaTensorCoM);

            _body.BodyInertia = inertiaTensorCoM;
            _body.Mass = mass;

            // Sync CollisionSkin and Body.
            _body.MoveTo(Vector3.Zero, Matrix.Identity);
            _skin.ApplyLocalTransform(new Transform(-centerOfMass, Matrix.Identity));

            // Enable Body.
            if (enableBody)
            {
                _body.EnableBody();
            }
            else
            {
                _body.DisableBody();
            }
        }
        /// <summary>
        /// This adds/overrides a material, and sets all the pairs for
        /// existing materials using some sensible heuristic
        /// </summary>
        /// <param name="id"></param>
        /// <param name="properties"></param>
        public void SetMaterialProperties(int id, MaterialProperties properties)
        {
            materials[id] = properties;

            foreach (KeyValuePair<int, MaterialProperties> it in materials)
            {
                int otherID = it.Key;
                MaterialProperties mat = it.Value;

                int key01 = otherID << 16 | id;
                int key10 = id << 16 | otherID;
                materialPairs[key01] = materialPairs[key10] =
                    new MaterialPairProperties(properties.Elasticity * mat.Elasticity,
                        properties.StaticRoughness * mat.StaticRoughness,
                        properties.DynamicRoughness * mat.DynamicRoughness);
            }
        }
 /// <summary>
 /// Initializes a new BasicObject.
 /// </summary>
 /// <param name="primitive">Primitive that will define the CollisionSkin.</param>
 /// <param name="materialProperties"></param>
 /// <param name="primitiveProperties"></param>
 /// <param name="enableBody"></param>
 public BasicObject(Primitive primitive, MaterialProperties materialProperties, PrimitiveProperties primitiveProperties, bool enableBody)
 {
     Initialize(primitive, materialProperties, primitiveProperties, enableBody);
 }
 /// <summary>
 /// Initializes a new BasicObject. Body is enabled by default.
 /// </summary>
 /// <param name="primitive">Primitive that will define the CollisionSkin.</param>
 /// <param name="materialProperties"></param>
 /// <param name="primitiveProperties"></param>
 public BasicObject(Primitive primitive, MaterialProperties materialProperties, PrimitiveProperties primitiveProperties)
 {
     Initialize(primitive, materialProperties, primitiveProperties, true);
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="type">Only AABox, Box, Capsule & Sphere will be accepted.</param>
 /// <param name="color"></param>
 public CollisionPrimitiveInfo(PrimitiveType type, MaterialProperties materialProperties, Color4 color)
 {
     Initialize(type, materialProperties, color);
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="type">Only AABox, Box, Capsule & Sphere will be accepted.</param>
        public CollisionPrimitiveInfo(PrimitiveType type, MaterialProperties materialProperties)
        {
            Random random = new Random();

            Initialize(type, materialProperties, new Color4((float)random.NextDouble() * 0.5f + 0.5f, (float)random.NextDouble() * 0.5f + 0.5f, (float)random.NextDouble() * 0.5f + 0.5f));
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="type">Only AABox, Box, Capsule & Sphere will be accepted.</param>
        /// <param name="color"></param>
        private void Initialize(PrimitiveType type, MaterialProperties materialProperties, Color4 color)
        {
            switch(type)
            {
                case PrimitiveType.AABox:
                    _primitive = new AABox(new Vector3(-0.5f), new Vector3(0.5f));
                    break;

                case PrimitiveType.Box:
                    _primitive = new Box(Vector3.Zero, Matrix.Identity, new Vector3(1f));
                    break;

                case PrimitiveType.Capsule:
                    _primitive = new Capsule(Vector3.Zero, Matrix.Identity, 1f, 1f);
                    break;

                case PrimitiveType.Sphere:
                    _primitive = new Sphere(Vector3.Zero, 1f);
                    break;

                default:
                    goto case PrimitiveType.Box;
            }

            _materialProperties = materialProperties;
            _color = color;
        }