void App_DoUpdate(object sender, EventArgs e) { PhysicsEngine.Update(); List <BaseGameObject> worldSpaces = WorldData.GetObjectsByType(typeof(WorldSpace)); foreach (WorldSpace ws in worldSpaces) { ws.Update(); } ObjectPicker.Update(); DeferredRenderer.Update(); SkyDome.Update(); string s = string.Empty; s = "TotalGameTime: " + App.gameTime.TotalGameTime.ToString() + "\t"; s += "TotalRealTime: " + App.gameTime.TotalRealTime.ToString() + "\t"; s += "FramesPerSecond: " + App.gameTime.FramesPerSecond.ToString() + "\t"; s += "ElapsedGameTime: " + App.gameTime.ElapsedGameTime.ToString() + "\t"; s += "ElapsedRealTime: " + App.gameTime.ElapsedRealTime.ToString() + "\n"; //s += "Cc pos: " + PlayerInput.characterController.Body.Position.ToString(); }
private void Window_Closing(object sender, CancelEventArgs e) { try { Game.Device.ClearState(); } catch { } Rendering.Grid.Dispose(); KeyboardInput.ReleaseDevice(); MouseInput.ReleaseDevice(); SpriteDrawer.Dispose(); DeferredRenderer.Dispose(); SkyDome.Dispose(); TextureLoader.Dispose(); PhysicsEngine.Dispose(); GameData.Dispose(); WorldData.Dispose(); if (view1.D3DScene != null) { view1.D3DScene.Dispose(); } view1.Dispose(); ShaderHelper.Dispose(); }
public void FillSkyIndexBuffer(SkyDome skyDome) { int num = 0; for (int i = 0; i < 7; i++) { for (int j = 0; j < 10; j++) { int num2 = j; int num3 = (j + 1) % 10; int num4 = i; int num5 = i + 1; skyDome.Indices[num++] = (ushort)(num2 + num4 * 10); skyDome.Indices[num++] = (ushort)(num3 + num4 * 10); skyDome.Indices[num++] = (ushort)(num3 + num5 * 10); skyDome.Indices[num++] = (ushort)(num3 + num5 * 10); skyDome.Indices[num++] = (ushort)(num2 + num5 * 10); skyDome.Indices[num++] = (ushort)(num2 + num4 * 10); } } for (int k = 2; k < 10; k++) { skyDome.Indices[num++] = 0; skyDome.Indices[num++] = (ushort)(k - 1); skyDome.Indices[num++] = (ushort)k; } skyDome.IndexBuffer.SetData(skyDome.Indices, 0, skyDome.Indices.Length); }
public void Shutdown() { // Release the position object. Position = null; // Release the light object. Light = null; // Release the fps object. FPS = null; // Release the camera object. Camera = null; // Release the text object. Text?.Shutdown(); Text = null; // Release the cpu object. CPU?.Shutdown(); CPU = null; // Release the water shader object. WaterShader?.ShutDown(); WaterShader = null; // Release the water object. WaterModel?.ShutDown(); WaterModel = null; // Release the reflection shader object. ReflectionShader?.ShutDown(); ReflectionShader = null; // Release the reflection render to texture object. ReflectionTexture?.Shutdown(); ReflectionTexture = null; // Release the refraction render to texture object. RefractionTexture?.Shutdown(); RefractionTexture = null; // Release the sky plane shader object. SkyPlaneShader?.ShutDown(); SkyPlaneShader = null; // Release the sky plane object. SkyPlane?.ShurDown(); SkyPlane = null; // Release the sky dome shader object. SkyDomeShader?.ShutDown(); SkyDomeShader = null; // Release the sky dome object. SkyDome?.ShutDown(); SkyDome = null; // Release the terrain shader object. TerrainShader?.ShutDown(); TerrainShader = null; // Release the tree object. TerrainModel?.ShutDown(); TerrainModel = null; // Release the input object. Input?.Shutdown(); Input = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
protected override void LoadContent() { device = GraphicsDevice; this._spriteBatch = new SpriteBatch(device); this._spriteLargeFont = Content.Load <SpriteFont>("FONT\\LargeGameFont"); this._spriteRegularFont = Content.Load <SpriteFont>("FONT\\GameFont"); _soundManager.AddSound("Neutral", Content.Load <SoundEffect>("SOUND//Gear1")); _soundManager.AddSound("First", Content.Load <SoundEffect>("SOUND//Gear1")); _soundManager.AddSound("Second", Content.Load <SoundEffect>("SOUND//Gear2")); _soundManager.AddSound("Third", Content.Load <SoundEffect>("SOUND//Gear3")); _soundManager.AddSound("Fourth", Content.Load <SoundEffect>("SOUND//Gear4")); _soundManager.AddSound("Fifth", Content.Load <SoundEffect>("SOUND//Gear5")); _soundManager.AddSound("Reverse", Content.Load <SoundEffect>("SOUND//Gear2")); _soundManager.AddSound("GearChange", Content.Load <SoundEffect>("SOUND//Gear1ToGear2")); _soundManager.AddSound("BrakeMajor", Content.Load <SoundEffect>("SOUND//BrakeMajor")); _soundManager.AddSound("BrakeCurveMajor", Content.Load <SoundEffect>("SOUND//BrakeCurveMajor")); _gears = new Dictionary <string, Texture2D>(); _gears.Add("Neutral", Content.Load <Texture2D>("SPRITES//Gear_Neutral")); _gears.Add("First", Content.Load <Texture2D>("SPRITES//Gear_First")); _gears.Add("Second", Content.Load <Texture2D>("SPRITES//Gear_Second")); _gears.Add("Third", Content.Load <Texture2D>("SPRITES//Gear_Third")); _gears.Add("Fourth", Content.Load <Texture2D>("SPRITES//Gear_Fourth")); _gears.Add("Fifth", Content.Load <Texture2D>("SPRITES//Gear_Fifth")); _gears.Add("Sixth", Content.Load <Texture2D>("SPRITES//Gear_Neutral")); _gears.Add("Reverse", Content.Load <Texture2D>("SPRITES//Gear_Reverse")); _revBG = Content.Load <Texture2D>("SPRITES//RevBG"); _revCount = Content.Load <Texture2D>("SPRITES//RevCount"); _effect = Content.Load <Effect>("EFFECT//m_effects"); _skyDome = new SkyDome(Content.Load <Model>("MODEL//DOME//dome"), Content.Load <Texture2D>("MODEL//DOME//cloudMap"), _effect.Clone(device)); _terrain = new ColoredTerrain(_effect.Clone(device), new Vector2(500, 500), Content.Load <Texture2D>("TEXTURE//heightmap6")); //_terrain = new ColoredTerrain(_effect.Clone(device), new Vector2(500, 500), Content.Load<Texture2D>("TEXTURE//flatheightmap")); _car = new CarObject(Content.Load <Model>("MODEL//SL500//SL500"), CreateSL500Spec(), _steeringWheelDevice); _car.initialise(); _camera = new Camera[3]; _camera[0] = new ChaseCamera(_car, new Vector3(-0.35f * 2.8f, 1.0f * 2.8f, 0.3f * 2.8f), device.Viewport, new Vector2(MathHelper.TwoPi, MathHelper.TwoPi), true); _camera[1] = new ChaseCamera(_car, new Vector3(0f * 2.8f, 2f * 2.8f, 7f * 2.8f), device.Viewport, new Vector2(MathHelper.TwoPi, MathHelper.TwoPi), false); _camera[2] = new StationaryCamera(new Vector3(1000, 150, 500), device.Viewport, new Vector2(MathHelper.PiOver2, -MathHelper.Pi / 10f)); _camera[0].initialise(); _camera[1].initialise(); _camera[2].initialise(); _currentCam = _camera[0]; _terrain.intialize(device); }
//draw the reflectionMap onto the plane public void DrawReflectionMap(Matrix viewMatrix, Matrix projectionMatrix, SkyDome skyDome) { Plane reflectionPlane = CreatePlane(heightOfWater - 0.5f, new Vector3(0, -1, 0), reflectionMatrix, projectionMatrix, true); device.ClipPlanes[0].Plane = reflectionPlane; device.ClipPlanes[0].IsEnabled = true; device.SetRenderTarget(0, reflection); device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.CornflowerBlue, 1.0f, 0); drawEnviroment(reflectionMatrix, projectionMatrix); skyDome.DrawSkyDome(reflectionMatrix, projectionMatrix, domeRotation); device.ClipPlanes[0].IsEnabled = false; device.SetRenderTarget(0, null); reflectionMap = reflection.GetTexture(); }
//constructor public RaceMarker(ref GraphicsDeviceManager newGraphics, ref GameStateManager state, ref Model newModel, Vector3 newPosition, ref Effect newEffect, ref Texture2D newMap, ref Texture2D newMapCollision, ref SkyDome dome, ref Texture2D newMapAI) { graphics = newGraphics; device = graphics.GraphicsDevice; currentState = state; raceMarkerModel = newModel; position = newPosition; map = newMap; mapCollision = newMapCollision; mapAI = newMapAI; effect = newEffect; skyDome = dome; collisionSphere = new BoundingSphere(position, 0.2f); }
public void FillSkyVertexBuffer(SkyDome skyDome, float timeOfDay, float precipitationIntensity, int temperature) { for (int i = 0; i < 8; i++) { float x = (float)Math.PI / 2f * MathUtils.Sqr((float)i / 7f); for (int j = 0; j < 10; j++) { int num = j + i * 10; float x2 = (float)Math.PI * 2f * (float)j / 10f; float num2 = 1800f * MathUtils.Cos(x); skyDome.Vertices[num].Position.X = num2 * MathUtils.Sin(x2); skyDome.Vertices[num].Position.Z = num2 * MathUtils.Cos(x2); skyDome.Vertices[num].Position.Y = 1800f * MathUtils.Sin(x) - ((i == 0) ? 450f : 0f); skyDome.Vertices[num].Color = CalculateSkyColor(skyDome.Vertices[num].Position, timeOfDay, precipitationIntensity, temperature); } } skyDome.VertexBuffer.SetData(skyDome.Vertices, 0, skyDome.Vertices.Length); }
protected override void Dispose(bool disposing) { //GameWorld.Dispose(disposing); try { Game.Device.ClearState(); } catch { } KeyboardInput.ReleaseDevice(); MouseInput.ReleaseDevice(); PrintText.Dispose(); EffectManager.Dispose(); SpriteDrawer.Dispose(); DeferredRenderer.Dispose(); SkyDome.Dispose(); TextureLoader.Dispose(); PhysicsEngine.Dispose(); }
private void Window_Initialized(object sender, EventArgs e) { MainPlayer.Initialize(); float aspectRatio = (float)view1.Width / (float)view1.Height; Camera.CurrentBehavior = Behavior.Spectator; //Camera.Perspective((float)Math.PI / 4.0f, aspectRatio, 1.0f, 1000000.0f); Camera.Perspective((float)Math.PI / 4.0f, aspectRatio, 1.0f, 4000.0f); Camera.Position = new Vector3(0, 0, 0); Camera.Velocity = new Vector3(40.0f, 40.0f, 40.0f); Camera.RotationSpeed = 0.25f; WorldTime.Speed = 0; //compile shaders List <BaseGameObject> shaders = WorldData.GetObjectsByType(typeof(Shader)); foreach (Shader s in shaders) { s.Recompile(); } SpriteDrawer.Initialize(); DeferredRenderer.Initialize((int)view1.Width, (int)view1.Height); DeferredRenderer.RenderHeight = (int)view1.Height; DeferredRenderer.RenderWidth = (int)view1.Width; SkyDome.Initialize(); Rendering.Grid.Initialize(); view1.OnRenderView += new EventHandler(view1_OnRender); view1.D3DScene = new CellViewer((int)view1.Width, (int)view1.Height); view1.OnRenderView += new EventHandler(view1_OnRender); this.WindowState = System.Windows.WindowState.Maximized; GameData.LoadGameData(); PhysicsEngine.Initialize(); ScriptManager.Initialize(); }
//Constructor public Race(ref GraphicsDeviceManager newGraphics, ref HeightMapGenerator Generator, ref SkyDome dome, ref Effect neweffect, float newTexture0Height, float newTexture1Height, float newTexture2Height, float newTexture3Height, bool addAIBots) { graphics = newGraphics; generator = Generator; this.dome = dome; this.effect = neweffect; point = 0; ppoint = 0; finished = false; leader = null; finishers = 0; angle = 0; texture0Height = newTexture0Height; texture1Height = newTexture1Height; texture2Height = newTexture2Height; texture3Height = newTexture3Height; addBots = addAIBots; }
public void Dispose() { _player = null; _frameCounter = null; _camera = null; _frustrum = null; _skyPlane.ShurDown(); _skyPlane = null; _skyDome.ShutDown(); _skyDome = null; _quadTree?.Shutdown(); _quadTree = null; _foliage?.Dispose(); _foliage = null; _groundModel?.Dispose(); _groundModel = null; _terrain?.Dispose(); _terrain = null; _userInterface?.Dispose(); _userInterface = null; _shaderManager?.Dispose(); _shaderManager = null; _input?.Dispose(); _input = null; _directX?.Dispose(); _directX = null; }
public void DrawSkydome(Camera camera) { if (!m_skyDomes.TryGetValue(camera.GameWidget, out SkyDome value)) { value = new SkyDome(); m_skyDomes.Add(camera.GameWidget, value); } if (value.VertexBuffer == null || value.IndexBuffer == null) { Utilities.Dispose(ref value.VertexBuffer); Utilities.Dispose(ref value.IndexBuffer); value.VertexBuffer = new VertexBuffer(m_skyVertexDeclaration, value.Vertices.Length); value.IndexBuffer = new IndexBuffer(IndexFormat.SixteenBits, value.Indices.Length); FillSkyIndexBuffer(value); value.LastUpdateTimeOfDay = null; } int x = Terrain.ToCell(camera.ViewPosition.X); int z = Terrain.ToCell(camera.ViewPosition.Z); float globalPrecipitationIntensity = m_subsystemWeather.GlobalPrecipitationIntensity; float timeOfDay = m_subsystemTimeOfDay.TimeOfDay; int seasonalTemperature = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z); if (!value.LastUpdateTimeOfDay.HasValue || MathUtils.Abs(timeOfDay - value.LastUpdateTimeOfDay.Value) > 0.001f || !value.LastUpdatePrecipitationIntensity.HasValue || MathUtils.Abs(globalPrecipitationIntensity - value.LastUpdatePrecipitationIntensity.Value) > 0.02f || ((globalPrecipitationIntensity == 0f || globalPrecipitationIntensity == 1f) && value.LastUpdatePrecipitationIntensity.Value != globalPrecipitationIntensity) || m_lightningStrikeBrightness != value.LastUpdateLightningStrikeBrightness || !value.LastUpdateTemperature.HasValue || seasonalTemperature != value.LastUpdateTemperature) { value.LastUpdateTimeOfDay = timeOfDay; value.LastUpdatePrecipitationIntensity = globalPrecipitationIntensity; value.LastUpdateLightningStrikeBrightness = m_lightningStrikeBrightness; value.LastUpdateTemperature = seasonalTemperature; FillSkyVertexBuffer(value, timeOfDay, globalPrecipitationIntensity, seasonalTemperature); } Display.DepthStencilState = DepthStencilState.DepthRead; Display.RasterizerState = RasterizerState.CullNoneScissor; Display.BlendState = BlendState.Opaque; m_shaderFlat.Transforms.World[0] = Matrix.CreateTranslation(camera.ViewPosition) * camera.ViewProjectionMatrix; m_shaderFlat.Color = Vector4.One; Display.DrawIndexed(PrimitiveType.TriangleList, m_shaderFlat, value.VertexBuffer, value.IndexBuffer, 0, value.IndexBuffer.IndicesCount); }
public void Shutdown() { // Release the position object. Position = null; // Release the light object. Light = null; // Release the fps object. FPS = null; // Release the camera object. Camera = null; // Release the sky dome shader object. SkyDomeShader?.ShutDown(); SkyDomeShader = null; // Release the sky dome object. SkyDome?.ShutDown(); SkyDome = null; // Release the text object. Text?.Shutdown(); Text = null; // Release the cpu object. CPU?.Shutdown(); CPU = null; // Release the terrain shader object. TerrainShader?.ShutDown(); TerrainShader = null; // Release the tree object. TerrainModel?.ShutDown(); TerrainModel = null; // Release the input object. Input?.Shutdown(); Input = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
public void Draw(GameTime gameTime, ChaseCamera camera, City cityToRender, SkyDome skyDome, Viewport view, bool enableWater) { domeRotation += 0.01f; if (domeRotation > 360) { domeRotation = 0; } graphics.GraphicsDevice.Viewport = view; float time = (float)gameTime.TotalGameTime.TotalMilliseconds / 100.0f; //device.RenderState.FillMode = FillMode.WireFrame; if (enableWater) { UpdateRefelectionMatrix(camera); DrawRefractionMap(camera.view, camera.projection); DrawReflectionMap(camera.view, camera.projection, skyDome); device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.CornflowerBlue, 1.0f, 0); } drawEnviroment(camera.view, camera.projection); if (cityToRender != null) { cityToRender.Draw(gameTime, camera.view, camera.projection); } skyDome.DrawSkyDome(camera.view, camera.projection, domeRotation); if (enableWater) { drawWater(camera.view, camera.projection, camera.Position, time); } //create tree billboards DrawBillboards(camera.view, camera.projection, camera.Position); }
protected override void Initialize() { //GameWorld.Initialize(this.Window, GraphicsDeviceManager.ScreenWidth, GraphicsDeviceManager.ScreenHeight); //GameWorld.DeSerializeWorld(@"..\..\Content\export\World\physicsTest.world"); PlayerInput.Initialize(); float aspectRatio = (float)GraphicsDeviceManager.ScreenWidth / (float)GraphicsDeviceManager.ScreenHeight; Camera.CurrentBehavior = Behavior.Spectator; Camera.Perspective((float)Math.PI / 4.0f, aspectRatio, 1.0f, 1000000.0f); Camera.Position = new Vector3(0.0f, 10.0f, 0.0f); Camera.Velocity = new Vector3(40.0f, 40.0f, 40.0f); KeyboardInput.CreateDevice(this.Window); MouseInput.CreateDevice(this.Window); PrintText.Initialize(); EffectManager.Initialize(); SpriteDrawer.Initialize(); DeferredRenderer.Initialize(GraphicsDeviceManager.ScreenWidth, GraphicsDeviceManager.ScreenHeight); SkyDome.Initialize(); PhysicsEngine.Initialize(); }
protected override void SolveInstance(IGH_DataAccess DA) { int year = 2017; //int tasks = 1; //if (this.mt) tasks = Environment.ProcessorCount; int tasks = Environment.ProcessorCount; ParallelOptions paropts = new ParallelOptions { MaxDegreeOfParallelism = tasks }; //ParallelOptions paropts_1cpu = new ParallelOptions { MaxDegreeOfParallelism = 1 }; ////////////////////////////////////////////////////////////////////////////////////////// /// INPUTS int reclvl = 0; if (!DA.GetData(0, ref reclvl)) { return; } bool drawviewfactors = false; if (!DA.GetData(1, ref drawviewfactors)) { drawviewfactors = false; } bool drawcumskymatrix = false; if (!DA.GetData(2, ref drawcumskymatrix)) { drawcumskymatrix = false; } bool draw_sunpath = true; if (!DA.GetData(3, ref draw_sunpath)) { draw_sunpath = true; } bool draw_solarvec = true; if (!DA.GetData(4, ref draw_solarvec)) { draw_solarvec = true; } List <int> hoy = new List <int>(); if (!DA.GetDataList(5, hoy)) { return; } List <double> loc = new List <double>(); if (!DA.GetDataList(6, loc)) { return; } double longitude = loc[0]; double latitude = loc[1]; List <double> dni = new List <double>(); List <double> dhi = new List <double>(); DA.GetDataList(7, dni); DA.GetDataList(8, dhi); double domesize = 1.2; if (!DA.GetData(9, ref domesize)) { domesize = 1.2; } List <Mesh> context = new List <Mesh>(); DA.GetDataList(10, context); Point3d sp = new Point3d(); if (!DA.GetData(11, ref sp)) { return; } ////////////////////////////////////////////////////////////////////////////////////////// /// size of skydome Point3d anchor = sp; Point3d bb_furthest_point; // max distance to furthest corner of context double bb_max_distance = double.MinValue; if (context.Count > 0) { Mesh context_joined = new Mesh(); foreach (Mesh msh in context) { context_joined.Append(msh); } BoundingBox bb_context = context_joined.GetBoundingBox(false); if (bb_context.IsDegenerate(-1.0) == 4) { bb_furthest_point = new Point3d(sp.X + 1.0, sp.Y + 1.0, sp.Z + 1.0); } else { Point3d[] _pts = bb_context.GetCorners(); int _p_index = 0; for (int i = 0; i < _pts.Length; i++) { double _d = sp.DistanceTo(_pts[i]); if (_d > bb_max_distance) { bb_max_distance = _d; _p_index = i; } } bb_furthest_point = _pts[_p_index]; } } else { bb_furthest_point = new Point3d(sp.X + 1.0, sp.Y + 1.0, sp.Z + 1.0); } Vector3d vec_sp = bb_furthest_point - sp; vec_sp = Vector3d.Multiply(vec_sp, domesize); double vec_sp_len = vec_sp.Length; ////////////////////////////////////////////////////////////////////////////////////////// /// SKYDOME /// View factors and/or Cumulative SkyMatrix SkyDome dome = new SkyDome(reclvl); // create 2 meshes, one with obstructed views (make it black transparent), and one unobstructed (regular GH_Mesh color) Mesh meshObstructed = new Mesh(); foreach (double[] p in dome.VertexVectorsSphere) { Vector3d vec = new Vector3d(p[0], p[1], p[2]); vec = Vector3d.Multiply(vec_sp_len, vec); meshObstructed.Vertices.Add(vec + sp); } foreach (int[] f in dome.Faces) { meshObstructed.Faces.AddFace(f[0], f[1], f[2]); } meshObstructed.UnifyNormals(); if (drawviewfactors) { List <Vector3d> vec_sky_list = new List <Vector3d>(); List <int> vec_int = new List <int>(); for (int i = 0; i < meshObstructed.Vertices.Count; i++) { Vector3d testvec = meshObstructed.Vertices[i] - sp; if (testvec.Z >= 0.0) { vec_sky_list.Add(testvec); vec_int.Add(i); } } Color[] colors = new Color[meshObstructed.Vertices.Count]; for (int i = 0; i < meshObstructed.Vertices.Count; i++) { colors[i] = Color.FromArgb(100, 255, 255, 255); //alpha not working } meshObstructed.VertexColors.SetColors(colors); Vector3d[] vec_sky = vec_sky_list.ToArray(); bool[] shadow = new bool[vec_sky_list.Count]; if (context.Count > 0) { CShadow.CalcShadowMT(sp, new Vector3d(0, 0, 1), 0.001, vec_sky, context.ToArray(), ref shadow, paropts); } int j = 0; foreach (int i in vec_int) { Color c = new Color(); if (shadow[j]) { // Custom material, DisplayMaterial (rhinostyle) rendering material. and make in override DrawViewportMesh c = Color.FromArgb(100, 0, 0, 0); //alpha not working meshObstructed.VertexColors.SetColor(i, c); _vectorsObstructed.Add(i); } j++; } } else if (drawcumskymatrix) { // https://www.sciencedirect.com/science/article/pii/S0038092X04001161 // http://alexandria.tue.nl/openaccess/635611/p1153final.pdf // Solarmodel.dll needs new function to compute cumulative sky view matrix (requires obstruction check from drawviewfactors // 1. calc perez diffuse for each hour. use that value (hor, circum, dome) and assign it to each mesh face // 2. DNI is computed directly onto SP // 3. visualize colored dome for diff only. // 4. add text to sensorpoint, stating annual irradiation (DNI plus diff) // // cumskymatrix seperate component!! coz it can be re-used for several sensor points // matrix inversion as in robinson stone to compute irradiation on all sensor points with refl.? // // needs a separate component that uses cumskymatrix on a number of SPs and visualizes that analysis surface. //... or use this component, output the sensorpoints, give it to a surface and make surface evaluate with the points, and recolor that surface if (dni.Count == 8760 && dhi.Count == 8760) // only continue, if solar irradiance time series are provided { //Rhino.RhinoApp.WriteLine("Leggo!"); //Context.cWeatherdata weather; //weather.DHI = dhi; //weather.DNI = dni; //weather.Snow = new List<double>(); //double[] beta = new double[1] { beta_in }; //double[] psi = new double[1] { psi_in }; //Sensorpoints.p3d[] coord = new Sensorpoints.p3d[1]; //dummy variables. will not be used in this simplified simulation //coord[0].X = 0; //coord[0].Y = 0; //coord[0].Z = 0; //Sensorpoints.v3d[] normal = new Sensorpoints.v3d[1]; //dummy variables. will not be used in this simplified simulation //normal[0].X = 0; //normal[0].Y = 1; //normal[0].Z = 0; //double[] albedo = new double[8760]; //for (int t = 0; t < 8760; t++) //{ // albedo[t] = albedo1; //} //Console.WriteLine("Calculating irradiation..."); //Sensorpoints p = new Sensorpoints(beta, psi, coord, normal, reclvl); //p.SetSimpleSkyMT(beta, paropts); //p.SetSimpleGroundReflectionMT(beta, albedo, weather, sunvectors.ToArray(), paropts); //p.CalcIrradiationMT(weather, sunvectors.ToArray(), paropts); // hold on... i need a new function in SolarModel for CumSkyMatrix } else { Rhino.RhinoApp.WriteLine("No data for Direct Normal Irradiance and Diffuse Horizontal Irradiance provided... Please provide 8760 time series for each."); } } if (drawviewfactors || drawcumskymatrix) { //_colouredMesh.Add(meshObstructed); _viewFactors = meshObstructed; } ////////////////////////////////////////////////////////////////////////////////////////// /// Solar Vectors List <Sphere> spheres = new List <Sphere>(); double fontsize = vec_sp_len / 50.0; List <SunVector> sunvectors_list; SunVector.Create8760SunVectors(out sunvectors_list, longitude, latitude, year); int count = 0; if (draw_solarvec) { foreach (int h in hoy) { Vector3d vec = new Vector3d(sunvectors_list[h].udtCoordXYZ.x, sunvectors_list[h].udtCoordXYZ.y, sunvectors_list[h].udtCoordXYZ.z); vec = Vector3d.Multiply(vec_sp_len, vec); Point3d solarpoint = new Point3d(Point3d.Add(sp, vec)); Line ln = new Line(sp, solarpoint); ln.Flip(); _solar_vectors.Add(ln); if (sunvectors_list[h].udtCoordXYZ.z < 0) { _night_time.Add(true); } else { _night_time.Add(false); } int year_now = sunvectors_list[h].udtTime.iYear; int month_now = sunvectors_list[h].udtTime.iMonth; int day_now = sunvectors_list[h].udtTime.iDay; double hour_now = sunvectors_list[h].udtTime.dHours; string hour_now2 = Convert.ToString(hour_now); if (hour_now < 10) { hour_now2 = "0" + Convert.ToString(hour_now); } string strval = Convert.ToString(year_now) + "/ " + Convert.ToString(month_now) + "/ " + Convert.ToString(day_now) + "/ " + hour_now2 + ":00"; Plane pl = new Plane(ln.From, new Vector3d(-1, 0, 0)); //Plane pl = new Plane(ln.From, vec); var te = Rhino.RhinoDoc.ActiveDoc.Objects.AddText(strval, pl, fontsize, "Baskerville", false, false); Rhino.DocObjects.TextObject txt = Rhino.RhinoDoc.ActiveDoc.Objects.Find(te) as Rhino.DocObjects.TextObject; _txt.Add(new List <Curve>()); if (txt != null) { var tt = txt.Geometry as Rhino.Geometry.TextEntity; Curve[] A = tt.Explode(); foreach (Curve crv in A) { _txt[count].Add(crv); } } count++; Rhino.RhinoDoc.ActiveDoc.Objects.Delete(te, true); Sphere sph = new Sphere(ln.From, vec_sp_len / 30.0); spheres.Add(sph); } } ////////////////////////////////////////////////////////////////////////////////////////// /// SUN PATH /// !!! wierd sun paths at extreme longitudes -> time shift... +/- UCT // draw solar paths: curves that connect each month, but for the same hour if (draw_sunpath) { for (int hod = 0; hod < 24; hod++) { List <Point3d> pts = new List <Point3d>(); for (int d = 0; d < 365; d++) { int h = hod + 24 * d; Vector3d vec = new Vector3d(sunvectors_list[h].udtCoordXYZ.x, sunvectors_list[h].udtCoordXYZ.y, sunvectors_list[h].udtCoordXYZ.z); vec = Vector3d.Multiply(vec_sp_len, vec); if (vec.Z > 0) { Point3d solarpoint = new Point3d(Point3d.Add(sp, vec)); pts.Add(solarpoint); } } if (pts.Count > 0) { PolylineCurve crv = new PolylineCurve(pts); _sun_paths.Add(crv); } } // draw solar paths; curves that connects each hour, but for the same month int interv = 365 / 12; for (int m = 0; m < 12; m++) { List <Point3d> pts = new List <Point3d>(); for (int hod = 0; hod < 24; hod++) { int h = hod + ((m * interv + interv / 2) * 24); Vector3d vec = new Vector3d(sunvectors_list[h].udtCoordXYZ.x, sunvectors_list[h].udtCoordXYZ.y, sunvectors_list[h].udtCoordXYZ.z); vec = Vector3d.Multiply(vec_sp_len, vec); if (vec.Z > 0) { Point3d solarpoint = new Point3d(Point3d.Add(sp, vec)); pts.Add(solarpoint); } } if (pts.Count > 0) { PolylineCurve crv = new PolylineCurve(pts); _sun_paths.Add(crv); } } } ////////////////////////////////////////////////////////////////////////////////////////// /// OUTPUT DA.SetData(0, _viewFactors); // this mesh needs to be colored according to view factor or cumulative sky matrix DA.SetDataList(1, _solar_vectors); DA.SetDataList(2, _sun_paths); DA.SetDataList(3, spheres); }
public bool Initialise(Dimension size, IntPtr windowHandle) { var result = true; try { _directX = new DirectX(); result &= _directX.Initialise(size, windowHandle); _input = new Input(); result &= _input.Initialise(size, windowHandle); _shaderManager = new ShaderManager(); result &= _shaderManager.Initialise(_directX, windowHandle); _player = new Player { Position = new Coordinate3D <float>(31.0f, 18.0f, 7.0f), Rotation = new Coordinate3D <float>(11.0f, 23.0f, 0.0f) }; _camera = new Camera(); _camera.SetPosition(new Coordinate3D <float>(0, 0, -10)); _camera.Render(); _camera.RenderBaseViewMatrix(); _frameCounter = new FrameCounter(); _frameCounter.Initialise(); _userInterface = new UserInterface(); result &= _userInterface.Initialise(_directX, size); _terrain = new Terrain(); result &= _terrain.Initialise(_directX.Device, "heightmap01.bmp", "dirt03.bmp"); _groundModel = new Object(); result &= _groundModel.Initialise(_directX.Device, "plane01.txt", "rock015.bmp"); _quadTree = new QuadTree(); result &= _quadTree.Initialise(_terrain, _directX.Device); _foliage = new Foliage(); result &= _foliage.Initialise(_directX.Device, _quadTree, "grass01.bmp", 2500); _frustrum = new Frustrum(); _skyDome = new SkyDome(); result &= _skyDome.Initialise(_directX.Device); _skyPlane = new SkyPlane(); result &= _skyPlane.Initialze(_directX.Device, "cloud001.bmp", "perturb001.bmp"); return(result); } catch (Exception ex) { //Log.WriteToFile(ErrorLevel.Error, "Window.Initialise", ex, true); return(false); } }
private bool RenderGraphics() { // Clear the scene. D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, projection, and ortho matrices from the camera and Direct3D objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix cameraViewMatrix = Camera.ViewMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; Matrix orthoD3DMatrix = D3D.OrthoMatrix; // Get the position of the camera. Vector3 cameraPostion = Camera.GetPosition(); // Translate the sky dome to be centered around the camera position. Matrix.Translation(cameraPostion.X, cameraPostion.Y, cameraPostion.Z, out worldMatrix); // Turn off back face culling. D3D.TurnOffCulling(); // Turn off the Z buffer. D3D.TurnZBufferOff(); // Render the sky dome using the sky dome shader. SkyDome.Render(D3D.DeviceContext); if (!SkyDomeShader.Render(D3D.DeviceContext, SkyDome.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, SkyDome.ApexColour, SkyDome.CenterColour)) { return(false); } // Turn back face culling back on. D3D.TurnOnCulling(); // Enable additive blending so the clouds blend with the sky dome color. D3D.EnableSecondBlendState(); // Render the sky plane using the sky plane shader. SkyPlane.Render(D3D.DeviceContext); if (!SkyPlaneShader.Render(D3D.DeviceContext, SkyPlane.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, SkyPlane.CloudTexture.TextureResource, SkyPlane.PerturbTexture.TextureResource, SkyPlane.m_Translation, SkyPlane.m_Scale, SkyPlane.m_Brightness)) { return(false); } // Turn off blending D3D.TurnOffAlphaBlending(); // Turn the Z buffer back on. D3D.TurnZBufferOn(); // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Render the terrain buffers. TerrainModel.Render(D3D.DeviceContext); // Render the model using the color shader. if (!TerrainShader.Render(D3D.DeviceContext, TerrainModel.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, Light.AmbientColor, Light.DiffuseColour, Light.Direction, TerrainModel.Texture.TextureResource)) { return(false); } //// Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); //// Turn on the alpha blending before rendering the text. D3D.TurnOnAlphaBlending(); // Render the text user interface elements. if (!Text.Render(D3D.DeviceContext, worldMatrix, orthoD3DMatrix)) { return(false); } //// Turn off alpha blending after rendering the text. D3D.TurnOffAlphaBlending(); //// Turn the Z buffer back on now that all 2D rendering has completed. D3D.TurnZBufferOn(); // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); Services.AddService(typeof(SpriteBatch), spriteBatch); font = Content.Load<SpriteFont>("Sprites/arial"); bigFont = Content.Load<SpriteFont>("Sprites/big"); box = Content.Load<Model>("Models/box"); (box.Meshes[0].Effects[0] as BasicEffect).EnableDefaultLighting(); treeModel = Content.Load<Model>("Models/tree"); (treeModel.Meshes[0].MeshParts[0].Effect as BasicEffect).EnableDefaultLighting(); textureBuilding = Content.Load<Texture2D>("Texture/Building_texture3"); /*effect.TextureEnabled = true; effect.Texture = textureBuilding;*/ ElevatortMusic = Content.Load<Song>("Audio\\elevatorMusic"); ElevatorBell = Content.Load<Song>("Audio\\ElevatorBell"); #region Player player = new Entity(this, box); player.Position = new Vector3(0, 120, 0); player.Controller = new KeyboardController(player); player.Scale = new Vector3(0.01f, 0.02f, 0.01f); player.Gravity = true; player.Color = Color.Purple; #endregion #region floor floor = new Entity(this, box); floor.Scale = new Vector3(0.99f, 0.5f, 0.99f); floor.Position = new Vector3(0, -50, 0); #endregion #region walls Entity wall = new Entity(this, box); wall.Position = new Vector3(100, 450, 0); wall.Scale = new Vector3(0.02f, 5, 1); wall.Texture = textureBuilding; Entity wall2 = new Entity(this, box); wall2.Position = new Vector3(0, 450, 100); wall2.Scale = new Vector3(1, 5, 0.02f); wall2.Texture = textureBuilding; Entity wall3 = new Entity(this, box); wall3.Position = new Vector3(0, 450, -100); wall3.Scale = new Vector3(1, 5, 0.02f); wall3.Texture = textureBuilding; Entity wall4 = new Entity(this, box); wall4.Position = new Vector3(-100, 500, 20); wall4.Scale = new Vector3(0.02f, 4.5f, 0.8f); wall4.Texture = textureBuilding; #endregion #region elevator elevator = new Entity(this, box); elevator.Color = Color.LimeGreen; elevator.Scale = new Vector3(0.2f, 0.02f, 0.2f); elevator.Position = new Vector3(-120, 0, -80); #endregion #region Tree model Entity tree = new Entity(this, treeModel); tree.Scale = new Vector3(0.15f); tree.Position = new Vector3(50, 10, 50); Entity tree2 = new Entity(this, treeModel); tree2.Scale = new Vector3(0.17f); tree2.Position = new Vector3(30, 5, 40); Entity tree3 = new Entity(this, treeModel); tree3.Scale = new Vector3(0.2f); tree3.Position = new Vector3(40, 5, 10); #endregion #region Skydome and Terrain Terrain terrain = new Terrain(this); terrain.Initialize(); SkyDome skyDome = new SkyDome(this); skyDome.Initialize(); #endregion #region ShaftWall(elevator shaft) Entity shaftWall1 = new Entity(this, box); shaftWall1.Position = new Vector3(-121, 450, -100); shaftWall1.Scale = new Vector3(0.21f, 5, 0.02f); //shaftWall1.Texture = Content.Load<Texture2D>("trans"); Entity shaftWall2 = new Entity(this, box); shaftWall2.Position = new Vector3(-121, 450, -60); shaftWall2.Scale = new Vector3(0.21f, 5, 0.02f); //shaftWall2.Texture = Content.Load<Texture2D>("trans"); shaftWall1.Alpha = 0.5f; shaftWall2.Alpha = 0.5f; #endregion staticEntities.Add(shaftWall1); staticEntities.Add(shaftWall2); floors = new Entity[20]; doors = new ElevatorDoors[20]; floorNumbers = new BoundingBox[20]; elevatorFronts = new BoundingBox[20]; for (int i = 0; i < floors.Length; i++) { floors[i] = new Entity(this, box); floors[i].Position = new Vector3(0, i * 50, 0); floors[i].Scale = new Vector3(0.99f, 0.02f, 0.99f); doors[i] = new ElevatorDoors(this, i, box); BoundingBox bb = floors[i].BB; bb.Min.X -= 45; bb.Max.Y += 40; floorNumbers[i] = bb; bb.Min.X += 45; bb.Max.X -= 175; bb.Max.Z -= 150; elevatorFronts[i] = bb; } #region add component staticEntities.Add(wall); staticEntities.Add(wall2); staticEntities.Add(wall3); staticEntities.Add(wall4); staticEntities.Add(elevator); movingEntities.Add(player); Components.Add(terrain); Components.Add(skyDome); #endregion #region elevatorButtons elevatorButtons = new TextButton[20]; for (int i = 0; i < elevatorButtons.Length; i++) { elevatorButtons[i] = new TextButton(this, new Vector2(50 + i * 60, 650), (i+1)+"", bigFont); elevatorButtons[i].Click += (o, e) => { int targetFloor = int.Parse((o as TextButton).Text); TrySelectFloor(targetFloor); }; //elevatorButtons[i].Visible = true; elevatorButtons[i].Enabled = false; elevatorButtons[i].DrawOrder = 10; } #endregion #region AddDoors staticEntities.Add(floor); for (int i = 0; i < floors.Length; i++) { staticEntities.Add(floors[i]); staticEntities.Add(doors[i].LeftDoor); staticEntities.Add(doors[i].RightDoor); //staticEntities.Add(doors[i * 2]); //staticEntities.Add(doors[i * 2 + 1]); } #endregion Camera = new Camera(this, player); Camera.Initialize(); ParticleEmitter emitter = new ParticleEmitter(this); emitter.Initialize(); Components.Add(emitter); }
//constructor public Alpine(ref GraphicsDeviceManager newGraphics, ref HeightMapGenerator Generator, ref Texture2D newmap, ref SkyDome dome, ref Effect neweffect, bool addBots, ref Texture2D treeMap) : base(ref newGraphics, ref Generator, ref dome, ref neweffect, 0, 7, 16, 35, addBots) { this.Map = newmap; this.treeMap = treeMap; graphics = newGraphics; device = graphics.GraphicsDevice; //set the starting points for the track startingpoints[0] = new Vector3(300f, 0f, -1880f); startingpoints[1] = new Vector3(289f, 0f, -1905f); startingpoints[2] = new Vector3(323f, 0f, -1916f); startingpoints[3] = new Vector3(327f, 0f, -1887f); this.StartPoints = startingpoints; LoadContent(); heightCollision = 44; }
private bool RenderReflectionToTexture() { // Setup a clipping plane based on the height of the water to clip everything below it. Vector4 clipPlane = new Vector4(0.0f, 1.0f, 0.0f, -WaterModel.WaterHeight); // Set the render target to be the reflection render to texture. ReflectionTexture.SetRenderTarget(D3D.DeviceContext); // Clear the reflection render to texture. ReflectionTexture.ClearRenderTarget(D3D.DeviceContext, 0.0f, 0.0f, 0.0f, 1.0f); // Use the camera to render the reflection and create a reflection view matrix. Camera.RenderReflection(WaterModel.WaterHeight); // Get the camera reflection view matrix instead of the normal view matrix. Matrix reflectionViewMatrix = Camera.ReflectionViewMatrix; // Get the world and projection matrices from the d3d object. Matrix worldMatrix = D3D.WorldMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; // Get the position of the camera. Vector3 cameraPosition = Camera.GetPosition(); // Invert the Y coordinate of the camera around the water plane height for the reflected camera position. cameraPosition.Y = -cameraPosition.Y + (WaterModel.WaterHeight * 2.0f); // Translate the sky dome and sky plane to be centered around the reflected camera position. Matrix.Translation(cameraPosition.X, cameraPosition.Y, cameraPosition.Z, out worldMatrix); // Turn off back face culling and the Z buffer. D3D.TurnOffCulling(); D3D.TurnZBufferOff(); // Render the sky dome using the reflection view matrix. SkyDome.Render(D3D.DeviceContext); if (!SkyDomeShader.Render(D3D.DeviceContext, SkyDome.IndexCount, worldMatrix, reflectionViewMatrix, projectionMatrix, SkyDome.ApexColour, SkyDome.CenterColour)) { return(false); } // Enable back face culling. D3D.TurnOnCulling(); // Enable additive blending so the clouds blend with the sky dome color. D3D.EnableSecondBlendState(); // Render the sky plane using the sky plane shader. SkyPlane.Render(D3D.DeviceContext); if (!SkyPlaneShader.Render(D3D.DeviceContext, SkyPlane.IndexCount, worldMatrix, reflectionViewMatrix, projectionMatrix, SkyPlane.CloudTexture.TextureResource, SkyPlane.PerturbTexture.TextureResource, SkyPlane.m_Translation, SkyPlane.m_Scale, SkyPlane.m_Brightness)) { return(false); } // Turn off blending and enable the Z buffer again. D3D.TurnOffAlphaBlending(); D3D.TurnZBufferOn(); // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Render the terrain using the reflection view matrix and reflection clip plane. TerrainModel.Render(D3D.DeviceContext); if (!ReflectionShader.Render(D3D.DeviceContext, TerrainModel.IndexCount, worldMatrix, reflectionViewMatrix, projectionMatrix, TerrainModel.ColorTexture.TextureResource, TerrainModel.NormalMapTexture.TextureResource, Light.DiffuseColour, Light.Direction, 2.0f, clipPlane)) { return(false); } // Reset the render target back to the original back buffer and not the render to texture anymore. D3D.SetBackBufferRenderTarget(); // Reset the viewport back to the original. D3D.ResetViewPort(); return(true); }
private bool Render() { // Clear the scene. D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, projection, ortho, base view and reflection matrices from the camera and Direct3D objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix viewCameraMatrix = Camera.ViewMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; Matrix orthoMatrix = D3D.OrthoMatrix; Matrix baseViewMatrix = Camera.BaseViewMatrix; Matrix reflectionMatrix = Camera.ReflectionViewMatrix; // Get the position of the camera. Vector3 cameraPosition = Camera.GetPosition(); // Translate the sky dome to be centered around the camera position. Matrix.Translation(cameraPosition.X, cameraPosition.Y, cameraPosition.Z, out worldMatrix); // Turn off back face culling and the Z buffer. D3D.TurnOffCulling(); D3D.TurnZBufferOff(); // Render the sky dome using the sky dome shader. SkyDome.Render(D3D.DeviceContext); if (!SkyDomeShader.Render(D3D.DeviceContext, SkyDome.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, SkyDome.ApexColour, SkyDome.CenterColour)) { return(false); } // Turn back face culling back on. D3D.TurnOnCulling(); // Enable additive blending so the clouds blend with the sky dome color. D3D.EnableSecondBlendState(); // Render the sky plane using the sky plane shader. SkyPlane.Render(D3D.DeviceContext); if (!SkyPlaneShader.Render(D3D.DeviceContext, SkyPlane.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, SkyPlane.CloudTexture.TextureResource, SkyPlane.PerturbTexture.TextureResource, SkyPlane.m_Translation, SkyPlane.m_Scale, SkyPlane.m_Brightness)) { return(false); } // Turn off blending. D3D.TurnOffAlphaBlending(); // Turn the Z buffer back on. D3D.TurnZBufferOn(); // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Render the terrain using the terrain shader. TerrainModel.Render(D3D.DeviceContext); if (!TerrainShader.Render(D3D.DeviceContext, TerrainModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, TerrainModel.ColorTexture.TextureResource, TerrainModel.NormalMapTexture.TextureResource, Light.DiffuseColour, Light.Direction, 2.0f)) { return(false); } // Translate to the location of the water and render it. Matrix.Translation(240.0f, WaterModel.WaterHeight, 250.0f, out worldMatrix); WaterModel.Render(D3D.DeviceContext); if (!WaterShader.Render(D3D.DeviceContext, WaterModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, reflectionMatrix, ReflectionTexture.ShaderResourceView, RefractionTexture.ShaderResourceView, WaterModel.Texture.TextureResource, Camera.GetPosition(), WaterModel.NormalMapTiling, WaterModel.WaterTranslation, WaterModel.ReflectRefractScale, WaterModel.RefractionTint, Light.Direction, WaterModel.SpecularShininess)) { return(false); } // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); // Turn on the alpha blending before rendering the text. D3D.TurnOnAlphaBlending(); // Render the text user interface elements. Text.Render(D3D.DeviceContext, worldMatrix, orthoMatrix); // Turn off alpha blending after rendering the text. D3D.TurnOffAlphaBlending(); // Turn the Z buffer back on now that all 2D rendering has completed. D3D.TurnZBufferOn(); // Present the rendered scene to the screen. D3D.EndScene(); return(true); }
private void ddlSetWeather_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBoxItem cbItemWeather = ddlSetWeather.SelectedItem as ComboBoxItem; SkyDome.SetSettings(WorldData.GetObject(cbItemWeather.Name.ToString()) as WeatherSetting); }