public MainWindow() { InitializeComponent(); _timer.reset(); _world1.getParticles().Add(_particle1); _world1.getParticles().Add(_particle2); _world1.getParticles().Add(_particle3); _world1.getParticles().Add(_particle4); _world1.getParticles().Add(_particleUser); _groundContactGenerator.init(_world1.getParticles()); _sphereContactGenerator.init(_world1.getParticles()); _world1.getForceRegistry().add(_particle1, _g); _world1.getForceRegistry().add(_particle2, _g); _world1.getForceRegistry().add(_particle3, _g); _world1.getForceRegistry().add(_particle4, _g); _world1.getForceRegistry().add(_particleUser, _g); _world1.getForceRegistry().add(_particleUser, _u); _world1.getContactGenerators().Add(_groundContactGenerator); _world1.getContactGenerators().Add(_sphereContactGenerator); _timer.start(); CompositionTarget.Rendering += UpdateChildren; }
public GameApplication(GameConfig game_cfg, GameWindow gameWindow) { Config = game_cfg; _gameWindow = gameWindow; Width = Config.WindowConfig.ScreenWidth; Height = Config.WindowConfig.ScreenHeight; _timer = new GameTimer(); world1 = new ParticleWorld(300, 16); respawn = new ParticleRespawn(1, 3); //radialWind = new ParticleWind(new ge.Vec3(100.0f, 100.0f, 0.0f), 10000.0f, 10.0f); //radialWind2 = new ParticleWind(new ge.Vec3(500.0f, 300.0f, 0.0f), 6000.0f, 15.0f); particleArray = new Particle[particleCount + freeParticles]; for (int i = 0; i < (particleCount + freeParticles); ++i) { particleArray[i] = new Particle(); } particleGravityArray = new ParticleGravity[(particleCount + freeParticles)]; //particleGravityArray2 = new ParticleGravity[(particleCount + freeParticles)]; for (int i = 0; i < (particleCount + freeParticles); i++) { world1.getParticles().Add(particleArray[i]); } groundContactGenerator = new GroundContact(); groundContactGenerator.init(world1.getParticles()); particleRods = new ParticleRod[cablesCount]; sphereContactGenerator = new SphereContact(); sphereContactGenerator.init(world1.getParticles()); world1.getContactGenerators().Add(groundContactGenerator); world1.getContactGenerators().Add(sphereContactGenerator); }
private void Window_Initialized(object sender, EventArgs e) { _timer.reset(); _timer.start(); _pixelWidth = (int)img.Width; _pixelHeight = (int)img.Height; int stride = (_pixelWidth * 32) / 8; lineTos = new lineToRender[] { new lineToRender() { from = 0, to = 16, buf = new byte[stride * 16] }, new lineToRender() { from = 16, to = 32, buf = new byte[stride * 16] }, new lineToRender() { from = 32, to = 48, buf = new byte[stride * 16] }, new lineToRender() { from = 48, to = 64, buf = new byte[stride * 16] }, new lineToRender() { from = 64, to = 80, buf = new byte[stride * 16] }, new lineToRender() { from = 80, to = 96, buf = new byte[stride * 16] }, new lineToRender() { from = 96, to = 112, buf = new byte[stride * 16] }, new lineToRender() { from = 112, to = 128, buf = new byte[stride * 16] }, new lineToRender() { from = 128, to = 144, buf = new byte[stride * 16] }, new lineToRender() { from = 144, to = 160, buf = new byte[stride * 16] }, new lineToRender() { from = 160, to = 176, buf = new byte[stride * 16] }, new lineToRender() { from = 176, to = 192, buf = new byte[stride * 16] }, new lineToRender() { from = 192, to = 200, buf = new byte[stride * 8] } }; _wb = new WriteableBitmap(_pixelWidth, _pixelHeight, 96, 96, PixelFormats.Bgra32, null); _rect = new Int32Rect(0, 0, _pixelWidth, _pixelHeight); _pixels = new byte[_pixelWidth * _pixelHeight * _wb.Format.BitsPerPixel / 8]; fillScreen(_pixels, new pBGRA(128, 128, 128, 255), _pixelWidth); printLine(_pixels, new pLine(0, 0, 64, 56), new pBGRA(195, 94, 65, 255), _pixelWidth); _stride = (_wb.PixelWidth * _wb.Format.BitsPerPixel) / 8; _wb.WritePixels(_rect, _pixels, _stride, 0); img.Source = _wb; // position, radius, surface color, reflectivity, transparency, emission color Sphere sphere1 = new Sphere(new Vec3f(0.0f, -10005, -20), 10000, new Vec3f(0.20f, 0.20f, 0.20f), 0, 0.0f); _spheres.Add(sphere1); _particle1 = new Particlef(sphere1, new Vec3f(0.0f), INFINITY); //красная Sphere sphere2 = new Sphere(new Vec3f(0.0f, 20, -20), 4.0f, new Vec3f(1.00f, 0.32f, 0.36f), 1, 0.9f); _spheres.Add(sphere2); _particle2 = new Particlef(sphere2, new Vec3f(0.0f), 10.0f); //желтая Sphere sphere3 = new Sphere(new Vec3f(5.0f, 10, -15), 2, new Vec3f(0.90f, 0.76f, 0.46f), 1, 0.9f); _spheres.Add(sphere3); _particle3 = new Particlef(sphere3, new Vec3f(0.0f), 10.0f); Sphere sphere4 = new Sphere(new Vec3f(5.0f, 10, -25), 3, new Vec3f(0.65f, 0.77f, 0.97f), 1, 0.9f); _spheres.Add(sphere4); _particle4 = new Particlef(sphere4, new Vec3f(0.0f), 10.0f); Sphere sphere5 = new Sphere(new Vec3f(-5.5f, 10, -15), 3, new Vec3f(0.90f, 0.90f, 0.90f), 1, 0.0f); _spheres.Add(sphere5); _particle5 = new Particlef(sphere5, new Vec3f(0.0f), 10.0f); //красная Sphere sphere6 = new Sphere(new Vec3f(0.0f, 40, -21), 6.0f, new Vec3f(0.92f, 0.36f, 0.26f), 1, 0.9f); _spheres.Add(sphere6); _particle6 = new Particlef(sphere6, new Vec3f(0.0f), 10.0f); //желтая Sphere sphere7 = new Sphere(new Vec3f(5.0f, 30, -15), 2, new Vec3f(0.76f, 0.72f, 0.36f), 1, 0.9f); _spheres.Add(sphere7); _particle7 = new Particlef(sphere7, new Vec3f(0.0f), 10.0f); Sphere sphere8 = new Sphere(new Vec3f(5.0f, 30, -25), 3, new Vec3f(0.65f, 0.77f, 0.97f), 1, 0.9f); _spheres.Add(sphere8); _particle8 = new Particlef(sphere8, new Vec3f(0.0f), 10.0f); Sphere sphere9 = new Sphere(new Vec3f(-5.5f, 30, -15), 3, new Vec3f(0.60f, 0.60f, 0.60f), 1, 0.9f); _spheres.Add(sphere9); _particle9 = new Particlef(sphere9, new Vec3f(0.0f), 10.0f); // light _spheres.Add(new Sphere(new Vec3f(20.0f, 30, -40), 3, new Vec3f(0.00f, 0.00f, 0.00f), 0, 0.0f, new Vec3f(3.0f, 3.0f, 3.0f))); _world1.getParticles().Add(_particle1); _world1.getParticles().Add(_particle2); _world1.getParticles().Add(_particle3); _world1.getParticles().Add(_particle4); _world1.getParticles().Add(_particle5); _world1.getParticles().Add(_particle6); _world1.getParticles().Add(_particle7); _world1.getParticles().Add(_particle8); _world1.getParticles().Add(_particle9); _sphereContactGenerator.init(_world1.getParticles()); _world1.getForceRegistry().add(_particle1, _g); _world1.getForceRegistry().add(_particle2, _g); _world1.getForceRegistry().add(_particle3, _g); _world1.getForceRegistry().add(_particle4, _g); _world1.getForceRegistry().add(_particle5, _g); _world1.getForceRegistry().add(_particle6, _g); _world1.getForceRegistry().add(_particle7, _g); _world1.getForceRegistry().add(_particle8, _g); _world1.getForceRegistry().add(_particle9, _g); _world1.getContactGenerators().Add(_sphereContactGenerator); InitializeStats(); CompositionTarget.Rendering += UpdateChildren; }