Ejemplo n.º 1
0
        private void SetRandomColorAndIntensityOfAllLights()
        {
            foreach (var light in lights)
            {
                // Pick a random color but don't let it be too dark or else the relative intensity doesn't work well
                Sansar.Vector randomVector = new Sansar.Vector((float)rnd.NextDouble(), (float)rnd.NextDouble(), (float)rnd.NextDouble());
                if (randomVector.LengthSquared() < 0.5f)
                {
                    randomVector = randomVector.Normalized();
                }
                Sansar.Color randomColor = new Sansar.Color(randomVector.X, randomVector.Y, randomVector.Z);

                // Pick a random intensity from min to max
                float randomIntensity = randomMinIntensity + (randomMaxIntensity - randomMinIntensity) * (float)rnd.NextDouble();

                light.SetColorAndIntensity(randomColor, randomIntensity);
            }
        }
Ejemplo n.º 2
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));
     }
 }
Ejemplo n.º 3
0
        private void Subscribe(ScriptEventData sed)
        {
            if (subscriptions == null)
            {
                subscriptions = SubscribeToAll(TurnOnEvent, (data) =>
                {
                    if (TurnOnFadeTime > 0.0f)
                    {
                        previousColor         = lights[0].GetNormalizedColor();
                        previousIntensity     = lights[0].GetRelativeIntensity();
                        targetColor           = initialColor;
                        targetIntensity       = initialIntensity;
                        interpolationDuration = TurnOnFadeTime;
                        interpolationTime     = TurnOnFadeTime;
                        interpolationActive   = true;
                    }
                    else
                    {
                        interpolationActive = false;
                        SetColorAndIntensityOfAllLights(initialColor, initialIntensity);
                    }
                });

                subscriptions += SubscribeToAll(TurnOffEvent, (data) =>
                {
                    if (TurnOffFadeTime > 0.0f)
                    {
                        previousColor         = lights[0].GetNormalizedColor();
                        previousIntensity     = lights[0].GetRelativeIntensity();
                        targetColor           = Sansar.Color.Black;
                        targetIntensity       = 0.0f;
                        interpolationDuration = TurnOffFadeTime;
                        interpolationTime     = TurnOffFadeTime;
                        interpolationActive   = true;
                    }
                    else
                    {
                        interpolationActive = false;
                        SetColorAndIntensityOfAllLights(Sansar.Color.Black, 0.0f);
                    }
                });

                subscriptions += SubscribeToAll(TurnRandomEvent, (data) =>
                {
                    if (TurnRandomFadeTime > 0.0f)
                    {
                        // Pick a random color but don't let it be too dark or else the relative intensity doesn't work well
                        Sansar.Vector randomVector = new Sansar.Vector((float)rnd.NextDouble(), (float)rnd.NextDouble(), (float)rnd.NextDouble());
                        while (randomVector.LengthSquared() < 0.1f)
                        {
                            randomVector = new Sansar.Vector((float)rnd.NextDouble(), (float)rnd.NextDouble(), (float)rnd.NextDouble());
                        }
                        if (randomVector.LengthSquared() < 0.5f)
                        {
                            randomVector = randomVector.Normalized();
                        }
                        Sansar.Color randomColor = new Sansar.Color(randomVector.X, randomVector.Y, randomVector.Z);

                        // Pick a random intensity from min to max
                        float randomIntensity = randomMinIntensity + (randomMaxIntensity - randomMinIntensity) * (float)rnd.NextDouble();

                        previousColor         = lights[0].GetNormalizedColor();
                        previousIntensity     = lights[0].GetRelativeIntensity();
                        targetColor           = randomColor;
                        targetIntensity       = randomIntensity;
                        interpolationDuration = TurnRandomFadeTime;
                        interpolationTime     = TurnRandomFadeTime;
                        interpolationActive   = true;
                    }
                    else
                    {
                        interpolationActive = false;
                        SetRandomColorAndIntensityOfAllLights();
                    }
                });
            }

            if (HasFadeTime())
            {
                StartInterpolation();
            }
        }