public void Begin() { guiModule = new GuiModule(Main.GraphicsDevice, Main.Input); inputModule = new InputModule(Main.Input); simulation = new Simulation(Main.Content, new MISP.GenericScriptObject( "episode-name", "main-menu", "server", null)); simulation.debugOutput += (s) => { Main.Write(s); }; simulation.Content.FrontLoadTextures(); Main.Write("Started menu simulation\n"); Main.ScriptEngine.PrepareEnvironment(simulation.scriptEngine); Main.ScriptEngine.AddEnvironment("menu", simulation.scriptEngine, simulation.scriptContext); renderModule = new RenderModule(Main.GraphicsDevice, simulation.Content); simulation.modules.Add(renderModule); octTreeModule = new OctTreeModule(new BoundingBox(new Vector3(-100, -100, -100), new Vector3(100, 100, 100)), 5.0f); simulation.modules.Add(octTreeModule); simulation.modules.Add(inputModule); simulation.modules.Add(guiModule); simulation.beginSimulation(); //var labelString = "Jemgine"; //var label = new UIItem(Layout.CenterItem(new Rectangle(0, 0, 10 * labelString.Length, 16), // Main.GraphicsDevice.Viewport.Bounds)); //label.settings = new MISP.GenericScriptObject( // "bg-color", new Vector3(0, 0, 0), // "text-color", new Vector3(1,1,1), // "label", labelString); //guiModule.uiRoot.AddChild(label); }
public void Draw(OctTreeModule octTreeModule) { var frustum = Camera.GetFrustum(); var nodes = octTreeModule.Query(frustum).Distinct() .Select(id => renderables.ContainsKey(id) ? renderables[id] : null); foreach (var node in nodes) { if (node != null) (node as IRenderable).PreDraw(device, renderContext); } device.SetRenderTarget(null); device.Clear(ClearOptions.DepthBuffer, Color.Black, 1.0f, 0); //device.Clear(Color.Black); device.BlendState = BlendState.AlphaBlend; device.DepthStencilState = DepthStencilState.Default; drawEffect.Parameters["World"].SetValue(Matrix.Identity); drawEffect.Parameters["View"].SetValue(Camera.View); drawEffect.Parameters["Projection"].SetValue(Camera.Projection); drawEffect.Parameters["WorldInverseTranspose"].SetValue(Matrix.Transpose(Matrix.Invert(Matrix.Identity))); //drawEffect.Parameters["DiffuseColor"].SetValue(new Vector4(1, 1, 1, 1)); //drawEffect.Parameters["DiffuseLightDirection"].SetValue(Vector3.Normalize(new Vector3(1, 0, -1))); //drawEffect.Parameters["FillColor"].SetValue(new Vector4(0.5f, 0.5f, 1, 1)); //drawEffect.Parameters["FillLightDirection"].SetValue(Vector3.Normalize(new Vector3(0, 1, 1))); drawEffect.Parameters["FogColor"].SetValue(Color.Black.ToVector4()); drawEffect.CurrentTechnique = drawEffect.Techniques[0]; renderContext.BeginScene(drawEffect, device); foreach (var node in nodes) { if (node != null) (node as IRenderable).DrawEx(renderContext); } debug.Begin(Matrix.Identity, Camera.View, Camera.Projection); foreach (var line in debugLines) debug.Line(line.Item1, line.Item2); debug.Flush(); debugLines.Clear(); }
public UInt32 MousePick(OctTreeModule octTreeModule, Vector2 mouseCoordinates) { AddDebugLine(new VertexPositionColor(Vector3.Zero, Color.Red), new VertexPositionColor(Camera.Unproject(new Vector3(mouseCoordinates, 0)), Color.Blue)); device.SetRenderTarget(mousePickTarget); device.Clear(ClearOptions.Target, Vector4.Zero, 0xFFFFFF, 0); device.BlendState = BlendState.Opaque; drawIDEffect.Parameters["World"].SetValue(Matrix.Identity); drawIDEffect.Parameters["View"].SetValue(Camera.View); var projection = Camera.GetSinglePixelProjection(mouseCoordinates); drawIDEffect.Parameters["Projection"].SetValue(projection); var frustum = new BoundingFrustum(Camera.View * projection); var nodes = octTreeModule.Query(frustum).Distinct() .Select(id => renderables.ContainsKey(id) ? renderables[id] : null); drawIDEffect.CurrentTechnique = drawIDEffect.Techniques[0]; var context = new RenderIDContext(); context.BeginScene(drawIDEffect, device); foreach (var node in nodes) if (node != null) { //drawIDEffect.Parameters["World"].SetValue(node.World); //drawIDEffect.Parameters["WorldInverseTranspose"].SetValue(Matrix.Transpose(Matrix.Invert(node.World))); var idBytes = BitConverter.GetBytes((node as Component).EntityID); drawIDEffect.Parameters["ID"].SetValue( new Vector4(idBytes[0] / 255.0f, idBytes[1] / 255.0f, idBytes[2] / 255.0f, idBytes[3] / 255.0f)); //drawIDEffect.CurrentTechnique.Passes[0].Apply(); (node as IRenderable).DrawEx(context); //(node as IRenderable).Draw(device); } device.SetRenderTarget(null); var data = new Color[1]; mousePickTarget.GetData(data); var result = data[0].PackedValue; if (renderables.ContainsKey(result)) { var mouseRay = new Ray(Camera.GetPosition(), Camera.Unproject(new Vector3(mouseCoordinates, 0)) - Camera.GetPosition()); mouseRay.Direction = Vector3.Normalize(mouseRay.Direction); renderables[result].CalculateLocalMouse(mouseRay, AddDebugLine); } return result; }
internal void StartSimulation(String episodeName, uint version) { //System.Threading.Thread.Sleep(10000); if (simulation != null) throw new InvalidProgramException(); simulation = new Simulation(Main.Content, new MISP.GenericScriptObject( "episode-name", episodeName, "server", null)); simulation.Content.FrontLoadTextures(); Main.Write("Started client simulation with episode " + episodeName + "\n"); Main.ScriptEngine.PrepareEnvironment(simulation.scriptEngine); Main.ScriptEngine.AddEnvironment("client", simulation.scriptEngine, simulation.scriptContext); //simulation.scriptEngine.AddGlobalVariable("ui", (context) => { return uiRoot; }); //uiRoot.children.Clear(); renderModule = new RenderModule(Main.GraphicsDevice, simulation.Content); simulation.modules.Add(renderModule); octTreeModule = new OctTreeModule(new BoundingBox(new Vector3(-100, -100, -100), new Vector3(100, 100, 100)), 5.0f); simulation.modules.Add(octTreeModule); simulation.modules.Add(clientModule); simulation.modules.Add(inputModule); simulation.modules.Add(guiModule); simulation.beginSimulation(); mouseLabel = new UIItem(new Rectangle(0, 0, 128, 64)); mouseLabel.settings = new MISP.GenericScriptObject("bg-color", new Vector3(1, 1, 1)); //guiModule.uiRoot.AddChild(mouseLabel); }