Exemplo n.º 1
0
        /*
         * // Remove linkage between myself and any possible children I might have.
         * // Called at taint time!
         * private void PhysicallyUnlinkAllChildrenFromRoot(BSPhysObject rootPrim)
         * {
         *  DetailLog("{0},PhysicallyUnlinkAllChildren,taint", rootPrim.LocalID);
         *
         *  PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.BSBody);
         * }
         */

        // Call each of the constraints that make up this linkset and recompute the
        //    various transforms and variables. Used when objects are added or removed
        //    from a linkset to make sure the constraints know about the new mass and
        //    geometry.
        // Must only be called at taint time!!
        private void RecomputeLinksetConstraintVariables()
        {
            float linksetMass = LinksetMass;

            foreach (BSPhysObject child in m_taintChildren)
            {
                BSConstraint constrain;
                if (PhysicsScene.Constraints.TryGetConstraint(LinksetRoot.BSBody, child.BSBody, out constrain))
                {
                    // DetailLog("{0},BSLinkset.RecomputeLinksetConstraintVariables,taint,child={1},mass={2},A={3},B={4}",
                    //         LinksetRoot.LocalID, child.LocalID, linksetMass, constrain.Body1.ID, constrain.Body2.ID);
                    constrain.RecomputeConstraintVariables(linksetMass);
                }
                else
                {
                    // Non-fatal error that happens when children are being added to the linkset but
                    //    their constraints have not been created yet.
                    break;
                }
            }

            // If the whole linkset is not here, doesn't make sense to recompute linkset wide values
            if (m_children.Count == m_taintChildren.Count)
            {
                // If this is a multiple object linkset, set everybody's center of mass to the set's center of mass
                OMV.Vector3 centerOfMass = ComputeLinksetCenterOfMass();
                BulletSimAPI.SetCenterOfMassByPosRot2(LinksetRoot.BSBody.ptr, centerOfMass, OMV.Quaternion.Identity);
                foreach (BSPhysObject child in m_taintChildren)
                {
                    BulletSimAPI.SetCenterOfMassByPosRot2(child.BSBody.ptr, centerOfMass, OMV.Quaternion.Identity);
                }
            }
            return;
        }