OpenSim.Region.Framework.Scenes.SceneObjectPart.DoPhysicsPropertyUpdate C# (CSharp) Method

DoPhysicsPropertyUpdate() public method

public DoPhysicsPropertyUpdate ( bool UsePhysics, bool isNew ) : void
UsePhysics bool
isNew bool
return void
        public void DoPhysicsPropertyUpdate(bool UsePhysics, bool isNew)
        {
            if (IsJoint())
            {
                if (UsePhysics)
                {
                    // by turning a joint proxy object physical, we cause creation of a joint in the ODE scene.
                    // note that, as a special case, joints have no bodies or geoms in the physics scene, even though they are physical.

                    PhysicsJointType jointType;
                    if (IsHingeJoint())
                    {
                        jointType = PhysicsJointType.Hinge;
                    }
                    else if (IsBallJoint())
                    {
                        jointType = PhysicsJointType.Ball;
                    }
                    else
                    {
                        jointType = PhysicsJointType.Ball;
                    }

                    List<string> bodyNames = new List<string>();
                    string RawParams = Description;
                    string[] jointParams = RawParams.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
                    string trackedBodyName = null;
                    if (jointParams.Length >= 2)
                    {
                        for (int iBodyName = 0; iBodyName < 2; iBodyName++)
                        {
                            string bodyName = jointParams[iBodyName];
                            bodyNames.Add(bodyName);
                            if (bodyName != "NULL")
                            {
                                if (trackedBodyName == null)
                                {
                                    trackedBodyName = bodyName;
                                }
                            }
                        }
                    }

                    SceneObjectPart trackedBody = m_parentGroup.Scene.GetSceneObjectPart(trackedBodyName); // FIXME: causes a sequential lookup
                    Quaternion localRotation = Quaternion.Identity;
                    if (trackedBody != null)
                    {
                        localRotation = Quaternion.Inverse(trackedBody.RotationOffset) * this.RotationOffset;
                    }
                    else
                    {
                        // error, output it below
                    }

                    PhysicsJoint joint;

                    joint = m_parentGroup.Scene.PhysicsScene.RequestJointCreation(Name, jointType,
                        AbsolutePosition,
                        this.RotationOffset,
                        Description,
                        bodyNames,
                        trackedBodyName,
                        localRotation);

                    if (trackedBody == null)
                    {
                        ParentGroup.Scene.jointErrorMessage(joint, "warning: tracked body name not found! joint location will not be updated properly. joint: " + Name);
                    }

                }
                else
                {
                    if (isNew)
                    {
                        // if the joint proxy is new, and it is not physical, do nothing. There is no joint in ODE to
                        // delete, and if we try to delete it, due to asynchronous processing, the deletion request
                        // will get processed later at an indeterminate time, which could cancel a later-arriving
                        // joint creation request.
                    }
                    else
                    {
                        // here we turn off the joint object, so remove the joint from the physics scene
                        m_parentGroup.Scene.PhysicsScene.RequestJointDeletion(Name); // FIXME: what if the name changed?

                        // make sure client isn't interpolating the joint proxy object
                        Velocity = Vector3.Zero;
                        AngularVelocity = Vector3.Zero;
                        Acceleration = Vector3.Zero;
                    }
                }
            }
            else
            {
                if (PhysActor != null)
                {
                    if (UsePhysics != PhysActor.IsPhysical || isNew)
                    {
                        if (PhysActor.IsPhysical) // implies UsePhysics==false for this block
                        {
                            if (!isNew)
                                ParentGroup.Scene.RemovePhysicalPrim(1);

                            PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
                            PhysActor.OnOutOfBounds -= PhysicsOutOfBounds;
                            PhysActor.delink();

                            if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints && (!isNew))
                            {
                                // destroy all joints connected to this now deactivated body
                                m_parentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(PhysActor);
                            }

                            // stop client-side interpolation of all joint proxy objects that have just been deleted
                            // this is done because RemoveAllJointsConnectedToActor invokes the OnJointDeactivated callback,
                            // which stops client-side interpolation of deactivated joint proxy objects.
                        }

                        if (!UsePhysics && !isNew)
                        {
                            // reset velocity to 0 on physics switch-off. Without that, the client thinks the
                            // prim still has velocity and continues to interpolate its position along the old
                            // velocity-vector.
                            Velocity = new Vector3(0, 0, 0);
                            Acceleration = new Vector3(0, 0, 0);
                            AngularVelocity = new Vector3(0, 0, 0);
                            //RotationalVelocity = new Vector3(0, 0, 0);
                        }

                        PhysActor.IsPhysical = UsePhysics;


                        // If we're not what we're supposed to be in the physics scene, recreate ourselves.
                        //m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor);
                        /// that's not wholesome.  Had to make Scene public
                        //PhysActor = null;

                        if ((Flags & PrimFlags.Phantom) == 0)
                        {
                            if (UsePhysics)
                            {
                                ParentGroup.Scene.AddPhysicalPrim(1);

                                PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
                                PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
                                if (_parentID != 0 && _parentID != LocalId)
                                {
                                    if (ParentGroup.RootPart.PhysActor != null)
                                    {
                                        PhysActor.link(ParentGroup.RootPart.PhysActor);
                                    }
                                }
                            }
                        }
                    }
                    m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
                }
            }
        }
SceneObjectPart