public Particle(GraphicsDevice device, Vector3 position, Vector3 direction, Vector2 size, float speed, Texture2D particleTexture) { this.position = position; this.direction = direction; this.size = size; this.speed = speed; this.age = 0.0f; // Create billboard for this particle this.particleBillboard = new Billboard(device, this.position, this.size, particleTexture); }
private void Draw(Billboard billboard, Vector3 cameraUp, Vector3 cameraForward, string techniqueName) { Matrix worldMtx = Matrix.CreateBillboard(billboard.Position, SharedEffectParameters.xEyePosW, cameraUp, cameraForward); // Set effect variables effect.Parameters["g_World"].SetValue(worldMtx); effect.Parameters["g_BillboardTexture"].SetValue(billboard.BillboardTexture); device.RasterizerState = RasterizerState.CullNone; device.SetVertexBuffer(billboard.Vertices); // Draw billboard effect.CurrentTechnique = effect.Techniques[techniqueName]; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); } device.RasterizerState = RasterizerState.CullCounterClockwise; }
private void LoadLevel(string levelFileName) { // Load the data from the file StreamReader inFile = new StreamReader(levelFileName); while (!inFile.EndOfStream) { string line = inFile.ReadLine(); string command = line.Split(' ')[0]; string section = (command == "#") ? line.Split(' ')[1] : ""; // HEADER if (command == "LEVEL_TITLE") { title = line.Substring(command.Length + 1, line.Length - (command.Length + 1)); } else if (command == "LEVEL_TYPE") { string levelType = line.Split(' ')[1]; if (levelType == "INDOOR") { type = LevelType.Indoor; } else if (levelType == "OUTDOOR") { type = LevelType.Outdoor; } } // SOUND EFFECTS else if (command == "BACKGROUND_MUSIC") { string musicFileName = line.Remove(0, ("BACKGROUND_MUSIC").Length + 1); musicFileName = musicFileName.Remove(musicFileName.IndexOf('.')); // Remove file extension XNA backgroundMusic = content.Load <Song>(@"Music\" + musicFileName); } else if (command == "AMBIENT_SFX") { string ambientFileName = line.Split(' ')[1]; ambientFileName = ambientFileName.Remove(ambientFileName.IndexOf('.')); // Remove file extension XNA float volume = float.Parse(line.Split(' ')[2], CultureInfo.InvariantCulture); float pitch = float.Parse(line.Split(' ')[3], CultureInfo.InvariantCulture); ambientSFX = content.Load <SoundEffect>(@"SoundEffects\" + ambientFileName); ambientSFXInstance = ambientSFX.CreateInstance(); ambientSFXInstance.IsLooped = true; ambientSFXInstance.Volume = volume; ambientSFXInstance.Pitch = pitch; } else if (command == "FOOTSTEP_SFXs") { string fileName1 = line.Split(' ')[1]; string fileName2 = line.Split(' ')[2]; fileName1 = fileName1.Remove(fileName1.IndexOf('.')); // Remove file extensions XNA fileName2 = fileName2.Remove(fileName2.IndexOf('.')); footstepSFX1 = content.Load <SoundEffect>(@"SoundEffects\" + fileName1); footstepSFX2 = content.Load <SoundEffect>(@"SoundEffects\" + fileName2); } // CAMERA else if (command == "CAMERA_START_POSITION") { cameraStartPosition = new Vector3(float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[2], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[3], CultureInfo.InvariantCulture)); } else if (command == "CAMERA_START_DIRECTION") { cameraStartDirection = new Vector3(float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[2], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[3], CultureInfo.InvariantCulture)); } else if (command == "CAMERA_HEIGHT_OFFSET") { cameraHeightOffset = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); } // LIGHTING else if (command == "NUM_LIGHTS") { int numLights = int.Parse(line.Split(' ')[1]); // Create lights (ONLY ONE LIGHT FOR NOW!!!) for (int i = 0; i < numLights; i++) { // Light type line = inFile.ReadLine(); // Light position line = inFile.ReadLine(); Vector3 position = new Vector3(float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[2], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[3], CultureInfo.InvariantCulture)); // Light direction line = inFile.ReadLine(); Vector3 direction = new Vector3(float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[2], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[3], CultureInfo.InvariantCulture)); // Ambient line = inFile.ReadLine(); Vector4 ambient = new Vector4(float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[2], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[3], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[4], CultureInfo.InvariantCulture)); // Diffuse line = inFile.ReadLine(); Vector4 diffuse = new Vector4(float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[2], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[3], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[4], CultureInfo.InvariantCulture)); // Specular line = inFile.ReadLine(); Vector4 specular = new Vector4(float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[2], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[3], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[4], CultureInfo.InvariantCulture)); // Size line = inFile.ReadLine(); float lightSize = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); // Create the light light = new Light(device, content.Load <Texture2D>(@"Textures\sunFlare"), position, direction, ambient, diffuse, specular, lightSize); } } // SKY and FOG if (section == "SKY_FOG") { string skyTexture; float skyTextureScale; line = inFile.ReadLine(); skyTexture = (line.Split(' ')[1]).Split('.')[0]; // Remove file extension (XNA) line = inFile.ReadLine(); skyTextureScale = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); line = inFile.ReadLine(); skyColor = new Vector4(float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[2], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[3], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[4], CultureInfo.InvariantCulture)); line = inFile.ReadLine(); darkSkyOffset = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); line = inFile.ReadLine(); fogStart = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); line = inFile.ReadLine(); fogRange = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); // Create sky sky = new TexturedSkyDome(device, content.Load <Effect>(@"Effects\SkyDome"), content.Load <Texture2D>(@"Textures\" + skyTexture), skyTextureScale, 8000.0f); } // WATER if (section == "WATER") { line = inFile.ReadLine(); waterHeight = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); line = inFile.ReadLine(); waterColor = new Vector4(float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[2], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[3], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[4], CultureInfo.InvariantCulture)); line = inFile.ReadLine(); string waterNormalTexture = line.Split(' ')[1].Split('.')[0]; // Remove file extension (XNA) line = inFile.ReadLine(); float texScale = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); line = inFile.ReadLine(); float ratio = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); line = inFile.ReadLine(); deepWaterFogDistance = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); line = inFile.ReadLine(); float reflectionAmount = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); line = inFile.ReadLine(); float refractionAmount = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); line = inFile.ReadLine(); float waveHeight = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); line = inFile.ReadLine(); float waveSpeed = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); // Create water water = new WaterGrid(device, content.Load <Texture2D>(@"Textures\" + waterNormalTexture), texScale, ratio, reflectionAmount, refractionAmount, waveHeight, waveSpeed); } // TERRAIN if (section == "TERRAIN") { line = inFile.ReadLine(); string heightMapFileName = line.Split(' ')[1]; line = inFile.ReadLine(); string lowTex = line.Split(' ')[1].Split('.')[0]; line = inFile.ReadLine(); string highTex = line.Split(' ')[1].Split('.')[0]; // Remove file extension (XNA) line = inFile.ReadLine(); float texScale = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); line = inFile.ReadLine(); float spacing = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); line = inFile.ReadLine(); float heightScale = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); // Create terrain terrain = new TerrainFromHeightMap(device, content.Load <Texture2D>(@"Textures\" + lowTex), content.Load <Texture2D>(@"Textures\" + highTex), @"Terrain\" + heightMapFileName, texScale, spacing, heightScale); // Create terrain plane terrainPlane = new TerrainPlane(device, content.Load <Texture2D>(@"Textures\" + lowTex), content.Load <Texture2D>(@"Textures\" + highTex), texScale); } // SURFACE if (section == "SURFACE") { // Surface height line = inFile.ReadLine(); float surfaceHeight = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); // Diffuse line = inFile.ReadLine(); string diffTexFileName = line.Split(' ')[1]; diffTexFileName = diffTexFileName.Remove(diffTexFileName.IndexOf('.')); // Remove file extension XNA // Specular line = inFile.ReadLine(); string specTexFileName = line.Split(' ')[1]; specTexFileName = specTexFileName.Remove(specTexFileName.IndexOf('.')); // Remove file extension XNA // Normal line = inFile.ReadLine(); string normTexFileName = line.Split(' ')[1]; normTexFileName = normTexFileName.Remove(normTexFileName.IndexOf('.')); // Remove file extension XNA // Texture Scale line = inFile.ReadLine(); float scale = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); // Create surface surface = new SurfacePlane(device, surfaceHeight, content.Load <Texture2D>(@"Textures\" + diffTexFileName), content.Load <Texture2D>(@"Textures\" + specTexFileName), content.Load <Texture2D>(@"Textures\" + normTexFileName), scale); } // Billboard if (command == "NEW_BILLBOARD") { // Get the texture name line = inFile.ReadLine(); string billboardTex = line.Split(' ')[1]; // Get the position line = inFile.ReadLine(); Vector3 position = new Vector3(float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[2], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[3], CultureInfo.InvariantCulture)); // Get the size line = inFile.ReadLine(); Vector2 size = new Vector2(float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[2], CultureInfo.InvariantCulture)); // Load the billboard Billboard newBillboard = new Billboard(device, position, size, content.Load <Texture2D>(@"Textures\" + billboardTex)); // Add the billboard to the list billboardList.Add(newBillboard); } // MESHES if (command == "MESH_NAME") { // Preload the Mesh MeshManager.LoadMesh(line.Split(' ')[1]); } else if (command == "NEW_MESH") { // Get new mesh copy from the manager Mesh newMesh = MeshManager.LoadMesh(line.Split(' ')[1]); // POSITION line = inFile.ReadLine(); Vector3 position = new Vector3(float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[2], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[3], CultureInfo.InvariantCulture)); // ROTATION line = inFile.ReadLine(); Vector3 rotation = new Vector3(float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[2], CultureInfo.InvariantCulture), float.Parse(line.Split(' ')[3], CultureInfo.InvariantCulture)); // SCALE line = inFile.ReadLine(); float scale = float.Parse(line.Split(' ')[1], CultureInfo.InvariantCulture); newMesh.Position = position; newMesh.RotationAngles = rotation; newMesh.Scale = scale; // Add the mesh to the list meshList.Add(newMesh); } } inFile.Close(); }
public void DrawOcclusion(Billboard billboard, Vector3 cameraUp, Vector3 cameraForward) { Draw(billboard, cameraUp, cameraForward, "BillboardOcclusionTech"); }
public void DrawLighting(Billboard billboard, Vector3 cameraUp, Vector3 cameraForward) { Draw(billboard, cameraUp, cameraForward, "BillboardLightingTech"); }
public void DrawParticle(Billboard billboard, Vector3 cameraUp, Vector3 cameraForward) { Draw(billboard, cameraUp, cameraForward, "ParticleTech"); }
public void Draw(Billboard billboard, Vector3 cameraUp, Vector3 cameraForward) { Draw(billboard, cameraUp, cameraForward, "BillboardTech"); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); hudManager = new HudManager(Content, GraphicsDevice, spriteBatch, width, height); camera = new Camera(GraphicsDevice); projection = camera.Projection; world = Matrix.CreateTranslation(0.0f, 0.0f, 0.0f); skybox = new Skybox(Content); reflection = new Reflection(Content); shader = Content.Load <Effect>("Shaders/Shader"); textured = Content.Load <Effect>("Shaders/Textured"); shadertextured = Content.Load <Effect>("Shaders/ShaderTextures"); texturedAlpha = Content.Load <Effect>("Shaders/TexturedAlpha"); billboardEffect = Content.Load <Effect>("Shaders/Billboard"); bump = Content.Load <Effect>("Shaders/BumpMap"); ship = Content.Load <Model>("Models/Copy_of_evac_ship_9"); tree = Content.Load <Model>("Models/tree"); bulb = Content.Load <Model>("Models/Lightbulb"); sphere = Content.Load <Model>("Models/UntexturedSphere"); helicopter = Content.Load <Model>("Models/Helicopter"); planeModel = Content.Load <Model>("Models/plane"); locomotive = Content.Load <Model>("Models/train"); wagon1 = Content.Load <Model>("Models/wagon1"); wagon2 = Content.Load <Model>("Models/wagon2"); wagon3 = Content.Load <Model>("Models/wagon3"); heliTexture = Content.Load <Texture2D>("Models/helicopterTexture"); shipTexture = Content.Load <Texture2D>("Models/Copy_of_evac_ship_d"); asteroidTexture = Content.Load <Texture2D>("Models/asteroid"); planeBackTexture = Content.Load <Texture2D>("Models/textures/red_metal"); normalMap = Content.Load <Texture2D>("Models/HelicopterNormalMap"); planet = new Sphere(100, 64); moonbase1 = new Sphere(14, 6); moonbase2 = new Sphere(10, 12); moonbase3 = new Sphere(8, 32); moonbase1.MoveSphere(new Vector3(0, 0, 50)); moonbase2.MoveSphere(new Vector3(0, 9, 49)); moonbase3.MoveSphere(new Vector3(9, 4.5f, 49.5f)); planet.Initialize(GraphicsDevice); moonbase1.Initialize(GraphicsDevice); moonbase2.Initialize(GraphicsDevice); moonbase3.Initialize(GraphicsDevice); planeBack = new Plane(new Vector3(0.0f, 55.0f, 0.0f), 10.0f); planeBack.Initialize(GraphicsDevice); planeFront = new Plane(new Vector3(0.0f, 55.0f, 0.0f), 10.0f); planeFront.Initialize(GraphicsDevice); renderTarget = new RenderTarget2D( GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight, false, GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24); billboard = new Billboard(new Vector3(-80.0f, 10.0f, 0.0f), GraphicsDevice); billboard1 = new Billboard(new Vector3(-89.0f, 5.0f, 5.0f), GraphicsDevice); billboard2 = new Billboard(new Vector3(-51.0f, 0.0f, 10.0f), GraphicsDevice); billboard3 = new Billboard(new Vector3(-68.0f, -5.0f, 5.0f), GraphicsDevice); billboard4 = new Billboard(new Vector3(-74.0f, -10.0f, -10.0f), GraphicsDevice); billboard5 = new Billboard(new Vector3(-90.0f, -5.0f, 5.0f), GraphicsDevice); billboard6 = new Billboard(new Vector3(-100.0f, -16.0f, -7.0f), GraphicsDevice); billboard7 = new Billboard(new Vector3(-85.0f, 20.0f, 5.0f), GraphicsDevice); billboard8 = new Billboard(new Vector3(-70.0f, 15.0f, 10.0f), GraphicsDevice); billboard9 = new Billboard(new Vector3(-75.0f, -15.0f, 5.0f), GraphicsDevice); billboard10 = new Billboard(new Vector3(-54.0f, 21.0f, -100.0f), GraphicsDevice); billboard11 = new Billboard(new Vector3(-65.0f, 0.0f, 5.0f), GraphicsDevice); billboard12 = new Billboard(new Vector3(-83.0f, 0.0f, -10.0f), GraphicsDevice); billboard13 = new Billboard(new Vector3(-59.0f, 15.0f, -5.0f), GraphicsDevice); billboard14 = new Billboard(new Vector3(-64.0f, 8.0f, 10.0f), GraphicsDevice); billboard.Initialize(); billboard1.Initialize(); billboard2.Initialize(); billboard3.Initialize(); billboard4.Initialize(); billboard5.Initialize(); billboard6.Initialize(); billboard7.Initialize(); billboard8.Initialize(); billboard9.Initialize(); billboard10.Initialize(); billboard11.Initialize(); billboard12.Initialize(); billboard13.Initialize(); billboard14.Initialize(); }