public void Update(TimeSpan elapsed)
		{
			if (Nebula.Zone.Shape.ContainsPoint(camera.Position))
			{
				UpdateBackgroundLightning(elapsed);
				UpdateDynamicLightning(elapsed);
				UpdateCloudLightning(elapsed);
				if (Nebula.HasInteriorClouds)
				{
					for (int i = 0; i < Nebula.InteriorCloudCount; i++)
					{
						if (!puffsinterior[i].Spawned ||
							VectorMath.Distance(puffsinterior[i].Position, camera.Position) > Nebula.InteriorCloudMaxDistance)
						{
							puffsinterior[i].Color = GetPuffColor();
							puffsinterior[i].Shape = Nebula.InteriorCloudShapes.GetNext();
							puffsinterior[i].Position = camera.Position + RandomPointSphere(Nebula.InteriorCloudMaxDistance);
							puffsinterior[i].Spawned = true;
							puffsinterior[i].Velocity = RandomDirection() * Nebula.InteriorCloudDrift;
						}
						puffsinterior[i].Position += puffsinterior[i].Velocity * (float)elapsed.TotalSeconds;
					}
				}
			}
		}
 public void Update()
 {
     if (manager == null)
     {
         return;
     }
     if (Entry == null)
     {
         Entry = manager.GetEntry(Sound);
     }
     if (Active)
     {
         if (Entry.Range.Y > 0 && (VectorMath.Distance(manager.ListenerPosition, Position) > Entry.Range.Y))
         {
             EnsureStopped();
         }
         else
         {
             TryMakeActive();
         }
     }
     else
     {
         EnsureStopped();
     }
     //Update properties
     if (Instance != null)
     {
         Instance.SetPosition(Position);
         Instance.SetPitch(Pitch);
     }
 }
Beispiel #3
0
 public Vector3 GetPosition(float t)
 {
     if (t >= 1)
     {
         return(endPoint);
     }
     if (t <= 0)
     {
         return(startPoint);
     }
     if (!curve)
     {
         float dist      = VectorMath.Distance(startPoint, endPoint);
         var   direction = (endPoint - startPoint).Normalized();
         return(startPoint + (direction * (dist * t)));
     }
     else
     {
         float seg0 = 0;
         for (int i = 0; i < segments.Length; i++)
         {
             if (t < seg0 + lengthPercents[i])
             {
                 var t2 = (t - seg0) / lengthPercents[i];
                 return(segments[i].ValueAt(t2));
             }
             else
             {
                 seg0 += lengthPercents[i];
             }
         }
         throw new Exception("Something has gone horribly wrong in MotionPath");
     }
 }
        /*
         * public bool Intersects(BoundingFrustum frustum)
         * {
         *  if (frustum == null)
         *      throw new NullReferenceException();
         *
         *  throw new NotImplementedException();
         * }
         */

        public bool Intersects(BoundingSphere sphere)
        {
            float val = VectorMath.Distance(sphere.Center, Center);

            if (val > sphere.Radius + Radius)
            {
                return(false);
            }
            return(true);
        }
        public static BoundingSphere CreateFromBoundingBox(BoundingBox box)
        {
            // Find the center of the box.
            Vector3 center = new Vector3((box.Min.X + box.Max.X) / 2.0f,
                                         (box.Min.Y + box.Max.Y) / 2.0f,
                                         (box.Min.Z + box.Max.Z) / 2.0f);

            // Find the distance between the center and one of the corners of the box.
            float radius = VectorMath.Distance(center, box.Max);

            return(new BoundingSphere(center, radius));
        }
Beispiel #6
0
 public Vector3 GetPosition(float t)
 {
     t = MathHelper.Clamp(t, 0, 1);
     if (curve)
     {
         t = t * ((DEGREE + 1) * 2 + points.Count);
         return(new Vector3(getInterpol(seqX, t), getInterpol(seqY, t), getInterpol(seqZ, t)));
     }
     else
     {
         float dist      = VectorMath.Distance(points[0], points[1]);
         var   direction = (points[1] - points[0]).Normalized();
         return(points[0] + (direction * (dist * t)));
     }
 }
        public ContainmentType Contains(Vector3 point)
        {
            float distance = VectorMath.Distance(point, Center);

            if (distance > this.Radius)
            {
                return(ContainmentType.Disjoint);
            }

            else if (distance < this.Radius)
            {
                return(ContainmentType.Contains);
            }

            return(ContainmentType.Intersects);
        }
Beispiel #8
0
            public float ApproximateLength(float distance, float sampleRate = 10f)
            {
                // we do 100 samples per unit of straight line distance:
                float   detail    = distance * sampleRate;
                float   increment = 1.0f / detail;
                float   dist      = 0f;
                Vector3 prev      = ValueAt(0);
                float   t         = 0.0f;

                for (int i = 0; i < detail; i++)
                {
                    t += increment;
                    Vector3 to = ValueAt(t);
                    dist += VectorMath.Distance(prev, to);
                    prev  = to;
                }
                return(dist);
            }
Beispiel #9
0
 void RenderInteriorPuffs()
 {
     if (Nebula.HasInteriorClouds)
     {
         for (int i = 0; i < Nebula.InteriorCloudCount; i++)
         {
             if (!puffsinterior[i].Spawned)
             {
                 continue;
             }
             var distance = VectorMath.Distance(puffsinterior[i].Position, camera.Position);
             var alpha    = Nebula.InteriorCloudMaxAlpha;
             if (distance > Nebula.InteriorCloudFadeDistance.X && distance < Nebula.InteriorCloudFadeDistance.Y)
             {
                 var distance_difference = Nebula.InteriorCloudFadeDistance.Y - Nebula.InteriorCloudFadeDistance.X;
                 var current             = distance - Nebula.InteriorCloudFadeDistance.X;
                 alpha -= (alpha * (distance_difference - current) / distance_difference);
             }
             if (distance < Nebula.InteriorCloudFadeDistance.X)
             {
                 alpha = 0;
             }
             var    shape = puffsinterior[i].Shape;
             Color4 c     = new Color4(puffsinterior[i].Color, alpha);
             if (cldLightningActive)
             {
                 c *= Nebula.CloudLightningColor;
             }
             game.Billboards.Draw(
                 (Texture2D)game.ResourceManager.FindTexture(shape.Texture),
                 puffsinterior[i].Position,
                 new Vector2(Nebula.InteriorCloudRadius),
                 c,
                 new Vector2(shape.Dimensions.X, shape.Dimensions.Y),
                 new Vector2(shape.Dimensions.X + shape.Dimensions.Width, shape.Dimensions.Y),
                 new Vector2(shape.Dimensions.X, shape.Dimensions.Y + shape.Dimensions.Height),
                 new Vector2(shape.Dimensions.X + shape.Dimensions.Width, shape.Dimensions.Y + shape.Dimensions.Height),
                 0,
                 SortLayers.OBJECT
                 );
         }
     }
 }
        public ContainmentType Contains(BoundingSphere sphere)
        {
            float val = VectorMath.Distance(sphere.Center, Center);

            if (val > sphere.Radius + Radius)
            {
                return(ContainmentType.Disjoint);
            }

            else if (val <= Radius - sphere.Radius)
            {
                return(ContainmentType.Contains);
            }

            else
            {
                return(ContainmentType.Intersects);
            }
        }
Beispiel #11
0
 public Vector3 GetPosition(float t)
 {
     if (t >= 1)
     {
         return(points[points.Count - 1]);
     }
     if (t <= 0)
     {
         return(points[0]);
     }
     if (curve)
     {
         return(interpolate(t));
     }
     else
     {
         float dist      = VectorMath.Distance(points[0], points[1]);
         var   direction = (points[1] - points[0]).Normalized();
         return(points[0] + (direction * (dist * t)));
     }
 }