/// <summary> /// Initializes the engine /// </summary> internal void Prime() { #region Initialize SDL if (Sdl.SDL_Init(Sdl.SDL_INIT_VIDEO) != 0) throw new AuraEngineException("SDL failure: " + Sdl.SDL_GetError()); Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_DOUBLEBUFFER, 1); screen = Sdl.SDL_SetVideoMode(x, y, 16, Sdl.SDL_OPENGL | Sdl.SDL_DOUBLEBUF); if (screen == IntPtr.Zero) throw new AuraEngineException("Unable to set video mode: " + Sdl.SDL_GetError()); Sdl.SDL_WM_SetCaption(windowName,windowName); #endregion #region Initialize openGL Gl.glViewport(0, 0, x, y); Gl.glClearColor(0.8f, 0.8f, 0.8f, 1.0f); Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); Sdl.SDL_GL_SetAttribute(Sdl.SDL_GL_DEPTH_SIZE, 16); Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY); Gl.glEnableClientState(Gl.GL_NORMAL_ARRAY); //Gl.glEnableClientState(Gl.GL_TEXTURE_COORD_ARRAY); Gl.glEnable(Gl.GL_DEPTH_TEST); Gl.glShadeModel(Gl.GL_SMOOTH); Gl.glEnable(Gl.GL_TEXTURE_2D); Gl.glAlphaFunc(Gl.GL_GREATER, .016f); Gl.glEnable(Gl.GL_ALPHA_TEST); #endregion #region Initialize ilut Il.ilInit(); Ilu.iluInit(); Ilut.ilutInit(); Ilu.iluImageParameter(Ilu.ILU_PLACEMENT, Ilu.ILU_UPPER_LEFT); Ilut.ilutRenderer(Ilut.ILUT_OPENGL); #endregion CameraManager.SetCamera("Default", new Camera(new Vector3(10, 10, 10), new Vector3(0, 0, 0))); #region Set up explosion mrExplody = new Explosion(new Vector3(0, 0, 0), 5.0f, 5.0f); #endregion #region DEBUG //DEBUG: LIGHTING (BROKEN) LightManager.LightingEnabled = true; Texture t = TextureImporter.Instance.ImportContent("Data/grass.jpg"); Texture leaf = TextureImporter.Instance.ImportContent("Data/leaf.png"); Material lmaterial = new Material(new Color4(.1f, .1f, .1f, .1f), new Color4(.1f,0,0), new Color4(.1f,.1f,.1f), .1f); Light l = new Light(lmaterial, false); l.position = new Vector3(0,15,5); LightManager.Lights.Add(l); m = new Model(ObjImporter.Instance.ImportContent("Data/plane.obj"), t); m.scale = 2f; Billboard particleBillboard = new Billboard(TextureImporter.Instance.ImportContent("Data/particle.png"), BillboardLockType.Spherical, 0.2f); particleBillboard.Dimention = new Vector2(.1f, .1f); /* Create the particle systems for the core of the explosion */ List<ParticleSystem> fireParticleSystems = new List<ParticleSystem>(); Flames = new ParticleSystem( 10f, // 5... um.... units. particleBillboard, //Using particle.png as the texture .5f, //scale = 1/2 new Color4InterpolationHandler(FunctionAssets.LinearInterpolation), //Linear Interpolation for color new ColorRange(new Color4(1, 1, 0, 1), new Color4(1, 0, 0, .3f)), // Yellow to Red new FloatInterpolationHandler(FunctionAssets.LinearInterpolation), //Linear Interpolation for speed new Range(1.0f, 0.0f)); Flames.Count = 500; fireParticleSystems.Add(Flames); //Speed from 1.0 to 0.0 Fire = new EmitterBase(1, //75 umm... MS? fireParticleSystems, //This should be self-explanatory DirectionalClamp.ZeroClamp, //Nothing in the Negative Y Util.r.Next(), //Seed the RNG false); //Repeat! Tree.flames = Flames; //Debug: Particles b = new Billboard(leaf, BillboardLockType.Spherical, 0.2f); b.Dimention = new Vector2(.1f, .1f); PointVisualization v = new PointVisualization(); ps = new ParticleSystem(300, b, 0.15f, FunctionAssets.LinearInterpolation, new ColorRange(new Color4(1, 1, 1)), FunctionAssets.LinearInterpolation, new Range(.1f)); ps.Count = 5; for (int i = 0; i < 20; ++i) { Vector3 rand = new Vector3((float)(Util.r.NextDouble() * Util.r.NextSign() * 8), 0, (float)(Util.r.NextDouble() * Util.r.NextSign() * 8)); tree = new Tree(rand, 3.0f, 1.5f, .3f, 3, 3, b); Forest.Add(tree); } ParticleSystem[] tps = { ps }; //e = new EmitterBase(1, tps, DirectionalClamp.ZeroClamp, null, true); #endregion }
public Explosion(Vector3 position, float radius, float velocity) { Random random = new Random(); explosionPos = position; #region Dust Billboard dustParticleBillboard = new Billboard(TextureImporter.Instance.ImportContent("Data/particle.png")); dustParticleBillboard.Dimention = new Vector2(.1f, .1f); /* Create the particle systems for the dust of the explosion */ List<ParticleSystem> dustParticleSystems = new List<ParticleSystem>(); ParticleSystem shockwave = new ParticleSystem( 20f, // 10... um.... units. dustParticleBillboard, //Using particle.png as the texture 1.0f, new Color4InterpolationHandler(FunctionAssets.LinearInterpolation), //Linear Interpolation for color new ColorRange(new Color4(0.250f, 0.135f, 0.0372f, 1), new Color4(0.543f, 0.270f, 0.0742f, 0.0f)), // Brown, removing Alpha new FloatInterpolationHandler(FunctionAssets.LinearInterpolation), //Linear Interpolation for speed new Range(0.75f, 0.0f)); shockwave.Count = 500; dustParticleSystems.Add(shockwave); //Speed from 1.0 to 0.0 /* Build the dust */ dust = new EmitterBase(75, //75 umm... MS? dustParticleSystems, //This should be self-explanatory new DirectionalClamp(ClampState.None, ClampState.Positive, ClampState.None), //Nothing in the Negative Y random.Next(), //Seed the RNG false); //Repeat! dust.Emit(); #endregion #region Core Billboard coreParticleBillboard = new Billboard(TextureImporter.Instance.ImportContent("Data/particle.png"), BillboardLockType.Spherical, 1.0f); coreParticleBillboard.Dimention = new Vector2(0.5f, .05f); /* Create the particle systems for the core of the explosion */ List<ParticleSystem> coreParticleSystems = new List<ParticleSystem>(); ParticleSystem hotcore = new ParticleSystem( 10f, // 10... um.... units. coreParticleBillboard, //Using particle.png as the texture 0.1f, new Color4InterpolationHandler(FunctionAssets.LinearInterpolation), //Linear Interpolation for color new ColorRange(new Color4(1.0f, 1.0f, 1.0f, 1.0f), new Color4(1.0f, 0.9f, 0.0f, 1.0f)), // Yellow-orange, going dark new FloatInterpolationHandler(FunctionAssets.LinearInterpolation), //Linear Interpolation for speed new Range(0.75f, 0.0f)); hotcore.Count = 100; coreParticleSystems.Add(hotcore); //Speed from 1.0 to 0.0 /* Build the core of the explosion */ core = new EmitterBase(35, //75 umm... MS? coreParticleSystems, //This should be self-explanatory new DirectionalClamp(ClampState.None, ClampState.Negative, ClampState.None), //Nothing in the Negative Y random.Next(), //Seed the RNG false); //Repeat! core.Emit(); #endregion #region Sparks Billboard sparkParticleBillboard = new Billboard(TextureImporter.Instance.ImportContent("Data/particle.png"), BillboardLockType.Spherical, 0.05f); sparkParticleBillboard.Dimention = new Vector2(0.5f, .05f); /* Create the particle systems for the sparks */ List<ParticleSystem> sparkParticleSystems = new List<ParticleSystem>(); ParticleSystem sparkles = new ParticleSystem( 17f, // 10... um.... units. sparkParticleBillboard, //Using particle.png as the texture 0.1f, new Color4InterpolationHandler(FunctionAssets.LinearInterpolation), //Linear Interpolation for color new ColorRange(new Color4(1.0f, 1.0f, 1.0f, 1.0f), new Color4(1.0f, 0.0f, 0.0f, 1.0f)), // White, going yellow new FloatInterpolationHandler(FunctionAssets.LinearInterpolation), //Linear Interpolation for speed new Range(0.85f, 0.0f)); sparkles.Count = 100; sparkParticleSystems.Add(sparkles); //Speed from 1.0 to 0.0 /* Build the sparks */ sparks = new EmitterBase(75, //75 umm... MS? sparkParticleSystems, //This should be self-explanatory new DirectionalClamp(ClampState.None, ClampState.None, ClampState.None), //Nothing in the Negative Y random.Next(), //Seed the RNG false); //Repeat! sparks.Emit(); #endregion #region Fireball Billboard fireParticleBillboard = new Billboard(TextureImporter.Instance.ImportContent("Data/dust_billboard2.png"), BillboardLockType.Spherical, 0.75f); fireParticleBillboard.Dimention = new Vector2(0.5f, .05f); /* Create the particle systems for the fire */ List<ParticleSystem> fireParticleSystems = new List<ParticleSystem>(); ParticleSystem fire = new ParticleSystem( 14f, // 10... um.... units. fireParticleBillboard, //Using particle.png as the texture 0.1f, new Color4InterpolationHandler(FunctionAssets.LinearInterpolation), //Linear Interpolation for color new ColorRange(new Color4(1.0f, 1.0f, 0.1f, 1.0f), new Color4(1.0f, 0.0f, 0.0f, 0.1f)), // White, going red new FloatInterpolationHandler(FunctionAssets.LinearInterpolation), //Linear Interpolation for speed new Range(0.65f, 0.0f)); fire.Count = 100; fireParticleSystems.Add(fire); //Speed from 1.0 to 0.0 /* Build the sparks */ fireball = new EmitterBase(75, //75 umm... MS? fireParticleSystems, //This should be self-explanatory new DirectionalClamp(ClampState.None, ClampState.Negative, ClampState.None), //Nothing in the Negative Y random.Next(), //Seed the RNG false); //Repeat! fireball.Emit(); #endregion }