Example #1
0
        public static void StratifiedSample4D( float[] samples,
            int offset, int nx, int ny, int nu, int nv,
            bool jitter, Random random )
        {
            float dx = 1.0f / nx;
            float dy = 1.0f / ny;
            float du = 1.0f / nu;
            float dv = 1.0f / nv;

            int k = offset;
            for( int v = 0; v < nv; ++v )
            {
                for( int u = 0; u < nu; ++u )
                {
                    for( int y = 0; y < ny; ++y )
                    {
                        for( int x = 0; x < nx; ++x )
                        {
                            float jx = jitter ? random.NextFloat() : 0.5f;
                            float jy = jitter ? random.NextFloat() : 0.5f;
                            float ju = jitter ? random.NextFloat() : 0.5f;
                            float jv = jitter ? random.NextFloat() : 0.5f;

                            samples[ k ] = ( x + jx ) * dx;
                            samples[ k + 1 ] = ( y + jy ) * dy;
                            samples[ k + 2 ] = ( u + ju ) * du;
                            samples[ k + 3 ] = ( v + jv ) * dv;

                            k += 4;
                        }
                    }
                }
            }
        }
Example #2
0
 public Plant(int id, Random random)
 {
     Id = id;
     X = random.NextFloat(0, 300f);
     Z = random.NextFloat(0, 300f);
     Species = AvailableSpecies[random.Next(0, AvailableSpecies.Length)];
 }
Example #3
0
 public AIKart(int kartNum, Level level, byte[][,] weight)
 {
     rand = new Random(kartNum);
     Level = level;
     Weight = weight;
     position = new Vector3(rand.NextFloat(-10, 11), rand.NextFloat(-10, 11), rand.NextFloat(-10, 11));
 }
 public NebulaParameters(Random rng)
 {
     Color = rng.NextRandomColor();
     Offset = new Vector2(rng.Next(-1000, 1000), rng.Next(-1000, 1000));
     Falloff = rng.NextFloat(3, 6);
     Intensity = (float)(rng.NextDouble() * 0.2 + 1.0);
     Scale = rng.NextFloat(0.01f, 4f);
 }
Example #5
0
 public Animal(int id, Random random)
 {
     Id = id;
     X = random.NextFloat(0, 300f);
     Z = random.NextFloat(0, 300f);
     Species = AvailableSpecies[random.Next(0, AvailableSpecies.Length)];
     Name = $"{Species} {Id}";
 }
Example #6
0
    public FogSphereSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      // Create a graphics screen. This screen has to call the FogSphereRenderer
      // to handle the FogSphereNode!
      _graphicsScreen = new DeferredGraphicsScreen(Services) { DrawReticle = true };
      GraphicsService.Screens.Insert(0, _graphicsScreen);
      GameObjectService.Objects.Add(new DeferredGraphicsOptionsObject(Services));

      Services.Register(typeof(DebugRenderer), null, _graphicsScreen.DebugRenderer);
      Services.Register(typeof(IScene), null, _graphicsScreen.Scene);

      // Add gravity and damping to the physics Simulation.
      Simulation.ForceEffects.Add(new Gravity());
      Simulation.ForceEffects.Add(new Damping());

      // Add a custom game object which controls the camera.
      var cameraGameObject = new CameraObject(Services);
      GameObjectService.Objects.Add(cameraGameObject);
      _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode;

      // More standard objects.
      GameObjectService.Objects.Add(new GrabObject(Services));
      GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
      GameObjectService.Objects.Add(new DynamicSkyObject(Services, true, false, true));
      GameObjectService.Objects.Add(new GroundObject(Services));
      GameObjectService.Objects.Add(new DudeObject(Services));
      GameObjectService.Objects.Add(new DynamicObject(Services, 1));
      GameObjectService.Objects.Add(new DynamicObject(Services, 2));
      GameObjectService.Objects.Add(new DynamicObject(Services, 5));
      GameObjectService.Objects.Add(new DynamicObject(Services, 6));
      GameObjectService.Objects.Add(new DynamicObject(Services, 7));
      GameObjectService.Objects.Add(new FogObject(Services));
      GameObjectService.Objects.Add(new LavaBallsObject(Services));

      // Add a few palm trees.
      Random random = new Random(12345);
      for (int i = 0; i < 10; i++)
      {
        Vector3F position = new Vector3F(random.NextFloat(-3, -8), 0, random.NextFloat(0, -5));
        Matrix33F orientation = Matrix33F.CreateRotationY(random.NextFloat(0, ConstantsF.TwoPi));
        float scale = random.NextFloat(0.5f, 1.2f);
        GameObjectService.Objects.Add(new StaticObject(Services, "PalmTree/palm_tree", scale, new Pose(position, orientation)));
      }

      // ----- Add a FogSphereNode to scene.
      var fogSphereNode = new FogSphereNode
      {
        Name = "FogSphere",
        ScaleLocal = new Vector3F(5, 3, 5),
        PoseWorld = new Pose(new Vector3F(0, 0, -3)),
      };
      _graphicsScreen.Scene.Children.Add(fogSphereNode);
    }
Example #7
0
 public PointerData(SharpDX.Direct2D1.DeviceContext context, uint id, PointerDeviceType type, Point p)
 {
     this.PointerId = id;
     this.DeviceType = type;
     this.Pointers = new List<Point>();
     this.Pointers.Add(p);
     Random rnd = new Random();
     // Colors of lines. presents in RGBA (a random value between 0.5 ~ 1.0)
     color = new Color4(rnd.NextFloat(0.5f, 1), rnd.NextFloat(0.5f, 1), rnd.NextFloat(0.5f, 1), 1);
 }
Example #8
0
 public static string[] generate_input_file_content(int seed)
 {
     string[] data = new string[2];
     Random rand = new Random(seed);
     string operation = rand.Next(0, 4).ToString();
     string num0 = rand.NextFloat().ToString();
     string num1 = rand.NextFloat().ToString();
     data[0] = operation;
     data[1] = num0 + " " + num1;
     return data;
 }
Example #9
0
    public SpatialPartitionSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      GraphicsScreen.ClearBackground = true;
      GraphicsScreen.BackgroundColor = Color.Gray;
      GraphicsScreen.DrawReticle = true;
      SetCamera(new Vector3F(0, 1, 10), 0, 0);

      // Create a spatial partition. DigitalRune Geometry supports several types, see also
      // http://digitalrune.github.io/DigitalRune-Documentation/html/e32cab3b-cc7c-42ee-8ec9-23dd4467edd0.htm#WhichPartition
      // An AabbTree is useful for static objects. A DynamicAabbTree is good for moving objects.
      // The spatial partition can manage different types of items. In this case it manages
      // GeometricObjects. A delegate has to inform the spatial partition how to get the AABB
      // of an object.
      //_spatialPartition = new DynamicAabbTree<GeometricObject>
      _spatialPartition = new AabbTree<GeometricObject>
      {
        GetAabbForItem = geometricObject => geometricObject.Aabb,

        // Optional: The tree is automatically built using a mixed top-down/bottom-up approach. 
        // Bottom-up building is slower but produces better trees. If the tree building takes too 
        // long, we can lower the BottomUpBuildThreshold (default is 128).
        //BottomUpBuildThreshold = 0,

        // Optional: A filter can be set to disable certain kind of overlaps.
        //Filter = ...
      };

      // Create a triangle mesh.
      var triangleMesh = new SphereShape(1).GetMesh(0.01f, 4);
      var triangleMeshShape = new TriangleMeshShape(triangleMesh)
      {
        // TriangleMeshShapes can also use a spatial partition to manage triangle.
        // The items in the spatial partition are the triangle indices. The GetAabbForItem
        // delegate is set automatically.
        Partition = new AabbTree<int>(),
      };

      // Spatial partitions are built automatically when needed. However, it is still recommended
      // to call Update to initialize the spatial partition explicitly.
      triangleMeshShape.Partition.Update(false);

      // Add a lot of triangle mesh objects to _spatialPartition.
      var random = new Random();
      for (int i = 0; i < 50; i++)
      {
        var randomPosition = new Vector3F(random.NextFloat(-6, 6), random.NextFloat(-3, 3), random.NextFloat(-10, 0));
        var geometricObject = new GeometricObject(triangleMeshShape, new Pose(randomPosition));
        _spatialPartition.Add(geometricObject);
      }

      _spatialPartition.Update(false);
    }
Example #10
0
    public SkySample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      _graphicsScreen = new DeferredGraphicsScreen(Services);
      _graphicsScreen.DrawReticle = true;
      GraphicsService.Screens.Insert(0, _graphicsScreen);
      GameObjectService.Objects.Add(new DeferredGraphicsOptionsObject(Services));

      Services.Register(typeof(DebugRenderer), null, _graphicsScreen.DebugRenderer);
      Services.Register(typeof(IScene), null, _graphicsScreen.Scene);

      // Add gravity and damping to the physics Simulation.
      Simulation.ForceEffects.Add(new Gravity());
      Simulation.ForceEffects.Add(new Damping());

      // Add a custom game object which controls the camera.
      var cameraGameObject = new CameraObject(Services);
      GameObjectService.Objects.Add(cameraGameObject);
      _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode;

      GameObjectService.Objects.Add(new GrabObject(Services));
      GameObjectService.Objects.Add(new GroundObject(Services));
      GameObjectService.Objects.Add(new DudeObject(Services));
      GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
      GameObjectService.Objects.Add(new LavaBallsObject(Services));
      GameObjectService.Objects.Add(new FogObject(Services));
      GameObjectService.Objects.Add(new StaticObject(Services, "Barrier/Barrier", 0.9f, new Pose(new Vector3F(0, 0, -2))));
      GameObjectService.Objects.Add(new StaticObject(Services, "Barrier/Cylinder", 0.9f, new Pose(new Vector3F(3, 0, 0), QuaternionF.CreateRotationY(MathHelper.ToRadians(-20)))));

      // The DynamicSkyObject creates the dynamic sky and lights.
      GameObjectService.Objects.Add(new DynamicSkyObject(Services));

      // Add a few palm trees.
      Random random = new Random(12345);
      for (int i = 0; i < 10; i++)
      {
        Vector3F position = new Vector3F(random.NextFloat(-3, -8), 0, random.NextFloat(0, -5));
        Matrix33F orientation = Matrix33F.CreateRotationY(random.NextFloat(0, ConstantsF.TwoPi));
        float scale = random.NextFloat(0.5f, 1.2f);
        GameObjectService.Objects.Add(new StaticObject(Services, "PalmTree/palm_tree", scale, new Pose(position, orientation)));
      }

      // Add a grain filter to add some noise in the night.
      _graphicsScreen.PostProcessors.Add(new GrainFilter(GraphicsService)
      {
        IsAnimated = true,
        LuminanceThreshold = 0.3f,
        ScaleWithLuminance = true,
        Strength = 0.04f,
        GrainScale = 1.5f,
      });
    }
Example #11
0
    public SplitScreenSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      _graphicsScreen = new SplitScreen(Services);
      _graphicsScreen.DrawReticle = true;
      GraphicsService.Screens.Insert(0, _graphicsScreen);

      Services.Register(typeof(DebugRenderer), null, _graphicsScreen.DebugRenderer);
      Services.Register(typeof(IScene), null, _graphicsScreen.Scene);

      // Add gravity and damping to the physics Simulation.
      Simulation.ForceEffects.Add(new Gravity());
      Simulation.ForceEffects.Add(new Damping());

      // Add a custom game object which controls the camera of player A.
      var cameraGameObject = new CameraObject(Services);
      GameObjectService.Objects.Add(cameraGameObject);
      _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode;

      var projection = (PerspectiveProjection)cameraGameObject.CameraNode.Camera.Projection;
      projection.SetFieldOfView(
        projection.FieldOfViewY,
        GraphicsService.GraphicsDevice.Viewport.AspectRatio / 2,
        projection.Near,
        projection.Far);
      cameraGameObject.CameraNode.Camera = new Camera(projection);

      // A second camera for player B.
      _cameraNodeB = new CameraNode(cameraGameObject.CameraNode.Camera);
      _graphicsScreen.ActiveCameraNodeB = _cameraNodeB;

      GameObjectService.Objects.Add(new GrabObject(Services));
      GameObjectService.Objects.Add(new GroundObject(Services));
      GameObjectService.Objects.Add(new DudeObject(Services));
      GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
      GameObjectService.Objects.Add(new LavaBallsObject(Services));
      GameObjectService.Objects.Add(new FogObject(Services));
      GameObjectService.Objects.Add(new StaticObject(Services, "Barrier/Barrier", 0.9f, new Pose(new Vector3F(0, 0, -2))));
      GameObjectService.Objects.Add(new StaticObject(Services, "Barrier/Cylinder", 0.9f, new Pose(new Vector3F(3, 0, 0), QuaternionF.CreateRotationY(MathHelper.ToRadians(-20)))));
      GameObjectService.Objects.Add(new StaticSkyObject(Services));

      // Add a few palm trees.
      Random random = new Random(12345);
      for (int i = 0; i < 10; i++)
      {
        Vector3F position = new Vector3F(random.NextFloat(-3, -8), 0, random.NextFloat(0, -5));
        Matrix33F orientation = Matrix33F.CreateRotationY(random.NextFloat(0, ConstantsF.TwoPi));
        float scale = random.NextFloat(0.5f, 1.2f);
        GameObjectService.Objects.Add(new StaticObject(Services, "PalmTree/palm_tree", scale, new Pose(position, orientation)));
      }
    }
Example #12
0
        public void FloorTest()
        {
            const int max = 1000;

            var r = new Random(102);

            for (var i = 0; i < 30; i++)
            {
                var v = new Vector2(r.NextFloat() * max, r.NextFloat() * max);
                var c = v.Floor();
                Assert.AreEqual(Math.Floor(v.X), c.X);
                Assert.AreEqual(Math.Floor(v.Y), c.Y);
            }
        }
Example #13
0
        public void CeilingTest()
        {
            const int max = 1000;

            var r = new Random(987);

            for (var i = 0; i < 30; i++)
            {
                var v = new Vector2(r.NextFloat() * max, r.NextFloat() * max);
                var c = v.Ceiling();
                Assert.AreEqual(Math.Ceiling(v.X), c.X);
                Assert.AreEqual(Math.Ceiling(v.Y), c.Y);
            }
        }
Example #14
0
        public void ResultContentTest()
        {
            List<float> data = new List<float>();
            Random rand = new Random();
            data.Add(rand.NextFloat());
            data.Add(rand.NextFloat());
            string[] time = new string[2];
            time[0] = "00:00:02";
            time[1] = "00:00:02";
            Writer.create_result_file(ContentGenerator.generate_result_file_content(data,time));
            string[] testdata = File.ReadAllLines(Path.Combine(Directory.GetCurrentDirectory(), "Data//Result//Result.dat"));
            for (int i = 0; i < testdata.Length; i++)
            {
                Debug.WriteLine(testdata[i]);
            }

            Assert.IsTrue(testdata.Length == 6);
        }
        public DNA Initialize( Random rand, TaskState task )
        {
            DNA dna = new DNA {
                Shapes = new Shape[task.Shapes]
            };
            int shapesPerSegment = task.Shapes / 9;
            int shapeCounter = 0;

            for( int i = 0; i < task.Shapes - shapesPerSegment * 9; i++ ) {
                Shape shape = new Shape {
                    Color = Color.FromArgb( StartingAlpha, Color.R, Color.G, Color.B ),
                    Points = new PointF[task.Vertices]
                };
                for( int j = 0; j < shape.Points.Length; j++ ) {
                    shape.Points[j] = new PointF( rand.NextFloat( -MaxOverlap, task.ImageWidth + MaxOverlap ),
                                                  rand.NextFloat( -MaxOverlap, task.ImageHeight + MaxOverlap ) );
                }
                dna.Shapes[i] = shape;
                shapeCounter++;
            }

            for( int x = 0; x < 3; x++ ) {
                for( int y = 0; y < 3; y++ ) {
                    for( int i = 0; i < shapesPerSegment; i++ ) {
                        Shape shape = new Shape {
                            Color = Color.FromArgb( StartingAlpha, Color.R, Color.G, Color.B ),
                            Points = new PointF[task.Vertices]
                        };
                        for( int j = 0; j < shape.Points.Length; j++ ) {
                            shape.Points[j] =
                                new PointF(
                                    rand.NextFloat( task.ImageWidth / 3f * x - MaxOverlap,
                                                    task.ImageWidth / 3f * ( x + 1 ) + MaxOverlap ),
                                    rand.NextFloat( task.ImageHeight / 3f * y - MaxOverlap,
                                                    task.ImageHeight / 3f * ( y + 1 ) + MaxOverlap ) );
                        }
                        dna.Shapes[shapeCounter] = shape;
                        shapeCounter++;
                    }
                }
            }
            return dna;
        }
Example #16
0
        public static void GenerateHomePositions(int n)
        {
            Random rand = new Random();
            bool passed = false;
            Vector2 randPosition = new Vector2(0, 0);

            int i = 0;
            foreach(Team team in TeamManager.teams)
            {
                passed = false;
                while (!passed)
                {
                    randPosition = new Vector2(rand.NextFloat(LevelSpawner.BorderMargin.X + radius, GameRoot.ScreenSize.X - LevelSpawner.BorderMargin.X - 2 * radius), rand.NextFloat(LevelSpawner.BorderMargin.Y + radius, GameRoot.ScreenSize.Y - LevelSpawner.BorderMargin.Y - 2 * radius));
                    if (i == 0)
                    {
                        float distance = Vector2.DistanceSquared(randPosition, GameRoot.ScreenSize * 0.5f);
                        if(distance < (0.5f * GameRoot.ScreenSize.Y * 0.5f * GameRoot.ScreenSize.Y))
                            passed = false;
                        else
                            passed = true;
                    }

                    else
                    {
                        for (int j = 0; j < i; j++)
                        {
                            float distance = Vector2.DistanceSquared(randPosition, TeamManager.teams[j].homePlanet.Position);
                            if (distance < (1.5f * GameRoot.ScreenSize.X / n) * (1.5f * GameRoot.ScreenSize.X / n))
                            {
                                passed = false;
                                break;
                            }
                            else
                                passed = true;
                        }
                    }
                }

                team.homePlanet = new Planet(randPosition, team.Color, 1.0f, i, team);
                team.planetsColonized.Add(team.homePlanet);
                i++;
            }
        }
 static void MutateShape( Random rand, DNA dna, Shape shape, TaskState task )
 {
     int maxOverlap = task.ProjectOptions.MaxOverlap;
     shape.PreviousState = shape.Clone() as Shape;
     switch( rand.Next( 9 ) ) {
         case 0:
             shape.Color = Color.FromArgb( (byte)rand.Next( task.ProjectOptions.MinAlpha, 256 ), shape.Color.R,
                                           shape.Color.G, shape.Color.B );
             dna.LastMutation = MutationType.ReplaceColor;
             break;
         case 1:
             shape.Color = Color.FromArgb( shape.Color.A, (byte)rand.Next( 256 ), shape.Color.G, shape.Color.B );
             dna.LastMutation = MutationType.ReplaceColor;
             break;
         case 2:
             shape.Color = Color.FromArgb( shape.Color.A, shape.Color.R, (byte)rand.Next( 256 ), shape.Color.B );
             dna.LastMutation = MutationType.ReplaceColor;
             break;
         case 3:
             shape.Color = Color.FromArgb( shape.Color.A, shape.Color.R, shape.Color.G, (byte)rand.Next( 256 ) );
             dna.LastMutation = MutationType.ReplaceColor;
             break;
         case 4:
         case 5:
             shape.Points[rand.Next( shape.Points.Length )].X = rand.NextFloat( -maxOverlap,
                                                                                task.ImageWidth + maxOverlap );
             dna.LastMutation = MutationType.ReplacePoint;
             break;
         case 6:
         case 7:
             shape.Points[rand.Next( shape.Points.Length )].Y = rand.NextFloat( -maxOverlap,
                                                                                task.ImageHeight + maxOverlap );
             dna.LastMutation = MutationType.ReplacePoint;
             break;
         case 8:
             shape.Points[rand.Next( shape.Points.Length )].X = rand.NextFloat( -maxOverlap,
                                                                                task.ImageWidth + maxOverlap );
             shape.Points[rand.Next( shape.Points.Length )].Y = rand.NextFloat( -maxOverlap,
                                                                                task.ImageHeight + maxOverlap );
             dna.LastMutation = MutationType.ReplacePoints;
             break;
     }
 }
Example #18
0
        public Box(int _screenW, int _screenH, Random _rndRandom)
            : base()
        {
            screenW = _screenW;
              screenH = _screenH;

              rnd = _rndRandom;

              x = randomBetween(0, screenW);
              y = randomBetween(0, screenH);
              width = randomBetween(10, 50);
              height = randomBetween(10, 50);
              speed = randomBetween(50, 250);
              dirX = rnd.NextFloat() < 0.5d ? -1 : 1;
              dirY = rnd.NextFloat() < 0.5d ? -1 : 1;

              aabb = new AABB();
              updateAABB();
        }
Example #19
0
 /// <summary>
 /// Given nx strata in [0,1],
 /// Place a sample in each one,
 /// starting from samples[ offset ]
 /// and ending at samples[ offset + nx - 1 ]
 /// </summary>
 /// <param name="samples"></param>
 /// <param name="jitter"></param>
 public static void StratifiedSample1D( float[] samples,
     int offset, int nx,
     bool jitter, Random random )
 {
     float invTot = 1.0f / nx;
     for( int i = 0; i < nx; ++i )
     {
         float j = jitter ? random.NextFloat() : 0.5f;
         samples[ offset + i ] = ( i + j ) * invTot;
     }
 }
Example #20
0
        public void Load()
        {
            _program = _assets.Fetch<ShaderProgram>("Main");
            _vbo = new VBO();
            _tex = _assets.Fetch<Texture>("star.png");
            data = new List<Vertex>();
            var rnd = new Random();
            for (var i = 0; i < 150; i++)
            {
                //rnd.NextDouble()

                var x = rnd.NextFloat(-80f, 80f);
                var y = rnd.NextFloat(-80f, 80f);

                var z = rnd.NextFloat(0f, 10f) - 60.0f;
                AddStar((float)rnd.NextDouble() + 0.1f, new Vector3(x, y,z));
            }

            _vbo.Buffer(data.ToArray());
            _vao = new VAO(_program, _vbo);
            Loaded = true;
        }
Example #21
0
        /// <summary>
        /// Given nx x ny strata in [0,1]^2
        /// Place a sample in each one,
        /// starting at samples[ offset ],
        /// and ending at samples[ offset + nx * ny - 1 ]
        /// </summary>
        /// <param name="samples"></param>
        /// <param name="jitter"></param>
        public static void StratifiedSample2D( float[] samples,
            int offset, int nx, int ny,
            bool jitter, Random random )
        {
            float dx = 1.0f / nx;
            float dy = 1.0f / ny;

            int k = offset;
            for( int y = 0; y < ny; ++y )
            {
                for( int x = 0; x < nx; ++x )
                {
                    float jx = jitter ? random.NextFloat() : 0.5f;
                    float jy = jitter ? random.NextFloat() : 0.5f;

                    samples[ k ] = ( x + jx ) * dx;
                    samples[ k + 1 ] = ( y + jy ) * dy;

                    k += 2;
                }
            }
        }
Example #22
0
        public void NextFloatTest()
        {
            var r = new Random(555);
            var last = 0f;

            for (var i = 0; i < 20; i++)
            {
                var f = r.NextFloat();
                Assert.AreNotEqual(last, f);
                Assert.Less(f, 1f);
                Assert.GreaterOrEqual(f, 0f);
                last = f;
            }
        }
Example #23
0
        public UpdateOutcome Update(Random random)
        {
            if (random.NextDouble() < 0.05)
            {
                Health = Math.Max(0f, Math.Min(Health + random.NextFloat(-0.1f, 0.1f), 1f)); // chance of varying up to 10% of our health

                // Dead?
                if (Health <= 0f)
                    return UpdateOutcome.Removed;

                return UpdateOutcome.Changed;
            }

            return UpdateOutcome.None;
        }
Example #24
0
        public StratifiedND( Random random, params int[] nSamples )
        {
            nDimensions = nSamples.Length;

            this.nSamples = new int[ nDimensions ];
            Array.Copy( nSamples, this.nSamples, nSamples.Length );

            int nSamplesTotal = NumSamplesTotal;
            int nFloatsTotal = nSamplesTotal * nDimensions;
            values = new float[ nFloatsTotal ];
            for( int i = 0; i < nFloatsTotal; ++i )
            {
                values[ i ] = random.NextFloat();
            }
        }
Example #25
0
		/// <summary>
		/// Initialize services :
		/// </summary>
		protected override void Initialize ()
		{
			base.Initialize();

			LoadContent();
			Reloading += (s,e) => LoadContent();

			CreateTargets();
			GraphicsDevice.DisplayBoundsChanged += (s,e) => CreateTargets();


			var lr = GetService<LightRenderer>();
			var rand = new Random(542);
			
			for (int i=0; i<1024; i++) {
				var light = new OmniLight();
				light.RadiusOuter	=	rand.NextFloat(3, 4);
				light.RadiusInner	=	light.RadiusOuter * 0.5f;
				light.Position		=	rand.NextVector3( new Vector3(-50,3,-50), new Vector3(50,6,50) );
				//light.Position		=	Vector3.Up * 3; //new Vector3(10,2,20);
				//light.Position		=	new Vector3( (i/32)*3-48, 2.5f, (i%32)*3-48 );
				light.Intensity		=	rand.NextColor4()*50;// new Color4(10,10,5,0);
				lr.OmniLights.Add( light );
			}

			var names = spotAtlas.SubImageNames;

			lr.MaskAtlas	=	spotAtlas;

			for (int i=0; i<16; i++) {
				var light = new SpotLight();

				var position		=	rand.NextVector3( new Vector3(-30,20,-30), new Vector3(30,20,30) );
				var target			=	position + rand.NextVector3( new Vector3(-10, -35,-10), new Vector3(10, -35,10) );

				//position			=	rand.NextVector3( new Vector3(-50,50,-50), new Vector3(50,50,50) );
				//target				=	Vector3.Down * 20;

				light.Intensity		=	rand.NextColor4()*100;// new Color4(10,10,5,0);
				light.SpotView		=	Matrix.LookAtRH( position, target, Vector3.Up );
				light.RadiusOuter	=	(target - position).Length() * 1.5f;
				light.RadiusInner	=	light.RadiusOuter * 0.5f;
				light.MaskName		=	names[ rand.Next(0, names.Length) ];
				light.Projection	=	Matrix.PerspectiveFovRH( MathUtil.DegreesToRadians(45), 1, 1f, light.RadiusOuter );

				lr.SpotLights.Add( light );
			}
		}
Example #26
0
		/// <summary>
		/// Add services :
		/// </summary>
		protected override void Initialize ()
		{
			
			//	initialize services :
			base.Initialize();

			//	create structured buffers and shaders :
			buffer1		=	new StructuredBuffer( GraphicsDevice, typeof(Vector2), NumberOfElements  , StructuredBufferFlags.None );
			buffer2		=	new StructuredBuffer( GraphicsDevice, typeof(Vector2), NumberOfElements  , StructuredBufferFlags.None );
			paramsCB	=	new ConstantBuffer( GraphicsDevice, typeof(Params) );
			shader		=	Content.Load<Ubershader>("test");
			factory		=	new StateFactory( shader, typeof(ShaderFlags), Primitive.TriangleList, VertexInputElement.Empty );

			//
			//	Create and write data :
			//
			var	rand	=	new Random();
			var	input	=	Enumerable.Range(0, NumberOfElements).Select( i => new Vector2( rand.NextFloat(0,100), i ) ).ToArray();
			buffer1.SetData( input );
			
			//	add keyboard handler :
			InputDevice.KeyDown += InputDevice_KeyDown;
		}
Example #27
0
        /// <summary>
        /// Occurs during the randomizing process
        /// </summary>
        /// <param name="generator"></param>
        protected override void OnRandomize(Random generator)
        {
            _color = generator.NextColor();
            Opacity = generator.NextFloat();
            _pointShape = generator.NextEnum<PointShape>();

            base.OnRandomize(generator);
        }
Example #28
0
        ///// <summary>
        ///// Adds SimpleStroke copy content
        ///// </summary>
        ///// <param name="copy"></param>
        //protected override void OnCopy(Descriptor copy)
        //{
        //    base.OnCopy(copy);
        //    ISimpleStroke ss = copy as ISimpleStroke;
        //    ss.Color = Color;
        //    ss.Width = Width;
        //    ss.DashStyle = this.DashStyle;
        //}

        /// <summary>
        /// Handles randomization of simple stroke content
        /// </summary>
        /// <param name="generator">The random generator to use for randomizing characteristics.</param>
        protected override void OnRandomize(Random generator)
        {
            _color = generator.NextColor();
            Opacity = generator.NextFloat();
            _width = generator.NextFloat(10);
            _dashStyle = generator.NextEnum<DashStyle>();
            base.OnRandomize(generator);
        }
Example #29
0
 public static Vector2 GenerateRandomVector2(Random random, Range horizontalRange, Range verticalRange)
 {
     return new Vector2(random.NextFloat(horizontalRange.Min, horizontalRange.Max), random.NextFloat(verticalRange.Min, verticalRange.Max));
 }
Example #30
0
 public static Vector2 GenerateRandomUnitVector2(Random random)
 {
     float radians = random.NextFloat(-FlaiMath.Pi, FlaiMath.Pi);
     return FlaiMath.GetAngleVector(radians);
 }