예제 #1
0
        bool ResetToInitialPosition(RigidBodyComponent rigidBody)
        {
            ObjectPrivate objectPrivate = ScenePrivate.FindObject(rigidBody.ComponentId.ObjectId);

            if (objectPrivate != null && objectPrivate.IsValid)
            {
                try
                {
                    var motionType = rigidBody.GetMotionType();
                    WaitFor(rigidBody.SetMotionType, RigidBodyMotionType.MotionTypeKeyframed);
                    rigidBody.SetAngularVelocity(Vector.Zero);
                    rigidBody.SetLinearVelocity(Vector.Zero);
                    rigidBody.SetOrientation(objectPrivate.InitialRotation);
                    rigidBody.SetPosition(objectPrivate.InitialPosition);
                    rigidBody.SetMotionType(motionType);
                    return(true);
                }
                catch
                {
                    Log.Write(LogLevel.Error, __SimpleTag, "Position Reset: error resetting object position.");
                }
            }

            return(false);
        }
예제 #2
0
        void ResetToInitialPosition()
        {
            var motionType = RigidBody.GetMotionType();

            WaitFor(RigidBody.SetMotionType, RigidBodyMotionType.MotionTypeKeyframed);
            RigidBody.SetAngularVelocity(Vector.Zero);
            RigidBody.SetLinearVelocity(Vector.Zero);
            RigidBody.SetOrientation(ObjectPrivate.InitialRotation);
            RigidBody.SetPosition(ObjectPrivate.InitialPosition);
            RigidBody.SetMotionType(motionType);
        }
예제 #3
0
    void ResetAfterTimeout()
    {
        Wait(ResetTimeout);

        _rb.SetMotionType(RigidBodyMotionType.MotionTypeKeyframed);
        _rb.SetAngularVelocity(Vector.Zero);
        _rb.SetLinearVelocity(Vector.Zero);
        _rb.SetPosition(ObjectPrivate.InitialPosition);
        _rb.SetOrientation(ObjectPrivate.InitialRotation);
        _rb.SetMotionType(RigidBodyMotionType.MotionTypeDynamic);
    }
예제 #4
0
 private void UpdateLoop()
 {
     while (true)
     {
         //this is only one object, so we have it hard coded in to only follow the first agent., you could split this up later
         Boolean got1 = false;
         foreach (AgentPrivate agent in ScenePrivate.GetAgents())
         {
             if (got1 == false)
             {
                 ObjectPrivate      agentObejct = ScenePrivate.FindObject(agent.AgentInfo.ObjectId);
                 AnimationComponent anim;
                 if (agentObejct.TryGetFirstComponent(out anim))
                 {
                     Sansar.Vector fwd = anim.GetVectorAnimationVariable("LLCameraForward");
                     //Builds a rotation from the fwd vector
                     Quaternion newRot = Quaternion.FromLook(fwd, Sansar.Vector.Up);
                     //This is a basic check to make sure the camera rotation isnt all 0s
                     if (fwd.LengthSquared() > 0)
                     {
                         try
                         {
                             RigidBody.SetAngularVelocity(Vector.Zero);
                             RigidBody.SetLinearVelocity(Vector.Zero);
                             RigidBody.SetPosition(agentObejct.Position + lightPositionOffset);
                             //Order of multiplication matters here I think, start with the base rotation,
                             //multiply by and base offset rotation for the light, then multiply by the rotation of the fwd
                             //Keep in mind that multiplying quad A by quad b will rotate quad A by quad b
                             RigidBody.SetOrientation(QuaternionToVector(startRot * lightOnObjectDirection * newRot).Normalized());
                         }
                         catch
                         {
                         }
                     }
                 }
                 got1 = true;
             }
         }
         Wait(TimeSpan.FromSeconds(.05));
     }
 }
예제 #5
0
 void OnDrop(HeldObjectData data)
 {
     try {
         unsubscribe?.Invoke();
         if (ResetPositionOnDrop)
         {
             RigidBody.SetPosition(OriginalPosition);
             RigidBody.SetOrientation(OriginalOrientation);
             RigidBody.SetLinearVelocity(Sansar.Vector.Zero);
             RigidBody.SetAngularVelocity(Sansar.Vector.Zero);
         }
     }
     catch (NullReferenceException nre) { if (DebugSpam)
                                          {
                                              Log.Write("OnDrop", nre.Message);
                                          }
     }                                                                                       // ignore exceptions for not found agents.
     catch (Exception e) { if (DebugSpam)
                           {
                               Log.Write("OnDrop", e.ToString());
                           }
     }
 }
        void ApplyRotation(float startAngle, float targetAngle, Quaternion targetRotation, float speed, ref bool isComplete, ref bool willComplete)
        {
            float totalAngle = targetAngle - startAngle;

            if (Math.Abs(totalAngle) < anglePrecision)
            {
                isComplete = true;
                return;
            }

            int sign = Math.Sign(totalAngle);

            Quaternion currentRotation = RigidBody.GetOrientation();

            float angleNoTurn = GetAngleFromZero(currentRotation);
            float angle       = angleNoTurn + turnDirection * turnCount * TwoPI;

            float angleOffset = sign * (targetAngle - angle);

            if (willComplete || Math.Abs(angleOffset) < anglePrecision)
            {
                RigidBody.SetAngularVelocity(Vector.Zero);
                RigidBody.SetOrientation(targetRotation);
                isComplete = true;
                return;
            }

            if (angleOffset < 0) // overshot
            {
                RigidBody.SetAngularVelocity(Vector.Zero);
                RigidBody.SetOrientation(targetRotation);
                isComplete = true;
                return;
            }

            if (EaseInOut > 0 && MoveDuration > 4f * timestep)
            {
                float speedMod = SpeedCurve(Math.Abs(angle), Math.Abs(GetAngleFromZero(movedRotation) + turnDirection * numTurns * TwoPI));
                speed = speed * speedMod;
            }

            if (angleOffset < speed * timestep)
            {
                speed        = angleOffset / timestep;
                willComplete = true;
            }

            Vector velocity = sign * speed * worldRotationAxis;

            RigidBody.SetAngularVelocity(velocity);

            if (willComplete)
            {
                return;
            }

            float prediction = Math.Abs(angleNoTurn + sign * timestep * speed);

            if (prediction >= PI || Math.Abs(angleNoTurn) > PI && prediction < PI)
            {
                turnCount += sign;
            }
        }
예제 #7
0
    private void UpdateLoop()
    {
        float Tick      = 0.01f;
        float AngleStep = 5 * OpenAngle * Tick / SecondsToOpen;

        TimeSpan Moment = TimeSpan.FromSeconds(Tick);

        float Angle = 0.0f;

        while (true)
        {
            Wait(Moment);

            // If we're in the process of opening or closing, we'll adjust the angle a little toward the target
            if (Opening)
            {
                if (OpenOut)
                {
                    Angle -= AngleStep;
                    if (Angle < -OpenAngle)
                    {
                        Angle = -OpenAngle;
                    }
                }
                else
                {
                    Angle += AngleStep;
                    if (Angle > OpenAngle)
                    {
                        Angle = OpenAngle;
                    }
                }

                // If it's been a while since we've heard an open signal, let's start closing the door
                if (DateTime.Now.Subtract(LatestOpenSignal).TotalSeconds >= SecondsBeforeClose)
                {
                    Opening = false;
                    if (CloseSound != null)
                    {
                        ScenePrivate.PlaySound(CloseSound, PlaySettings.PlayOnce);
                    }
                }
            }
            else
            {
                if (OpenOut)
                {
                    Angle += AngleStep;
                    if (Angle > 0f)
                    {
                        Angle = 0f;
                    }
                }
                else
                {
                    Angle -= AngleStep;
                    if (Angle < 0f)
                    {
                        Angle = 0f;
                    }
                }
            }

            // Compute the new position and rotation of the door
            Quaternion Rotation = Quaternion.FromEulerAngles(new Vector(0, 0, Angle, 0));
            Quaternion NewOri   = ClosedOrientation * Rotation;
            Vector     NewPos   = ClosedPosition - HingeOffset.Rotate(ref Rotation);

            // Update the door's position and orientation
            DoorBody.SetAngularVelocity(Vector.Zero);
            DoorBody.SetLinearVelocity(Vector.Zero);
            DoorBody.SetPosition(NewPos);
            DoorBody.SetOrientation(QuaternionToVector(NewOri));
        }
    }