public void Draw_Empty() { SceneGraph graph = BuildSceneGraph(); graph.Update(); graph.Draw(null); }
public void Collision_InjectObject() { SceneGraph graph = BuildSceneGraph(); GameObjectCollisionSpawn obj1 = new GameObjectCollisionSpawn(graph) { NoClip = false, SceneGraph = graph }; obj1.SetCollisionSize(32, 32); graph.Add(obj1); GameObjectCollisionSpawn obj2 = new GameObjectCollisionSpawn(graph) { NoClip = false, SceneGraph = graph }; obj2.SetCollisionSize(32, 32); graph.Add(obj2); graph.Update(); graph.Draw(null); Assert.That(graph.RootGraph.Count, Is.EqualTo(4)); Assert.That(GetObjectTotals(graph).CollisionTestCount, Is.EqualTo(2)); Assert.That(GetObjectTotals(graph).CollisionCount, Is.EqualTo(2)); Assert.That(GetObjectTotals(graph).UpdateCount, Is.EqualTo(2)); Assert.That(GetObjectTotals(graph).DrawCount, Is.EqualTo(4)); }
/// <summary> /// Update framebuffer. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ObjectsControl_Render(object sender, GlControlEventArgs e) { GlControl senderControl = (GlControl)sender; float senderAspectRatio = (float)senderControl.Width / senderControl.Height; // Clear Gl.Viewport(0, 0, senderControl.Width, senderControl.Height); Gl.ClearColor(1.0f, 0.0f, 0.0f, 1.0f); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _CubeScene.CurrentView.ProjectionMatrix = Matrix4x4f.Perspective(45.0f, senderAspectRatio, 0.1f, 100.0f); // _CubeScene.CurrentView.LocalModelView = Matrix4x4f.Translated(0.0f, 0.0f, 10.0f); //_CubeScene.CurrentView.LocalModelView = // Matrix4x4f.Translated(_ViewStrideLat, _ViewStrideAlt, 0.0f) * // Matrix4x4f.RotatedY(_ViewAzimuth) * // Matrix4x4f.RotatedX(_ViewElevation) * // Matrix4x4f.Translated(0.0f, 0.0f, _ViewLever); //_CubeScene.CurrentView.LocalModelView = // Matrix4x4f.Translated(0.0f, 0.0f, _ViewLever) * // Matrix4x4f.RotatedX(_ViewElevation) * // Matrix4x4f.RotatedY(_ViewAzimuth) * // Matrix4x4f.Translated(_ViewStrideLat, _ViewStrideAlt, 0.0f); _CubeScene.UpdateViewMatrix(); _CubeScene.Draw(_Context); }
public void Draw_SkipOffScreen() { SceneGraph graph = BuildSceneGraph(); GameObject obj = new GameObjectCounter(); obj.Position = new Vector2(-33f, -33f); graph.Add(obj); graph.Update(); graph.Draw(null); Assert.That(GetObjectTotals(graph).DrawCount, Is.EqualTo(0)); Assert.That(graph.NodesCulled, Is.EqualTo(1)); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { if (GameStateManager.CurrentGameState == GameStateManager.GameState.Game) { // Since we're drawing in order from back to front, depth buffer is disabled graphics.GraphicsDevice.RenderState.DepthBufferEnable = false; graphics.GraphicsDevice.Clear(Color.Black); // Prepare scene sceneGraph.NewScene(); CurrentLevel.ResetCollisionDebugInfo(); spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState); // AddToScene the background CurrentLevel.Draw(sceneGraph, spriteBatch, Color.Black); // AddToScene the player sceneGraph.AddToScene(playerSprite.ToSceneGraphNode()); // AddToScene the enemies sceneGraph.AddToScene(CurrentLevel.NpcContainer.AddToScene()); // Write debug info sceneGraph.AddText("Player position: " + playerSprite.Position + " Player destination: " + playerSprite.Destination); sceneGraph.AddText("Tile position:" + CurrentLevel.ToTileCoordinate(playerSprite.Position)); sceneGraph.AddText("Player is dead:" + playerIsDead); sceneGraph.AddText("Player keypress: " + playerSprite.currentMovement.XDirection + " " + playerSprite.currentMovement.YDirection); sceneGraph.AddText(collisionDebugString); sceneGraph.AddText("Cam position:" + camera.Position); sceneGraph.Draw(); gameHUD.Draw(bigFont, HUDPosition); //base.Draw(gameTime); spriteBatch.End(); } else { if (GameStateManager.CurrentGameState == GameStateManager.GameState.Menu) { IsMouseVisible = true; } GraphicsDevice.Clear(Color.Black); base.Draw(gameTime); } }
public void Draw_InjectObject() { SceneGraph graph = BuildSceneGraph(); graph.Add(new GameObjectInjector() { SceneGraph = graph }); graph.Update(); graph.Draw(null); Assert.That(graph.RootGraph.Count, Is.EqualTo(3)); Assert.That(GetObjectTotals(graph).DrawCount, Is.EqualTo(3)); }
/// <summary> /// Update framebuffer. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ObjectsControl_Render(object sender, GlControlEventArgs e) { Control senderControl = (Control)sender; float senderAspectRatio = (float)senderControl.Width / senderControl.Height; // Clear Gl.Viewport(0, 0, senderControl.Width, senderControl.Height); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _CubeScene.CurrentView.LocalModel.SetIdentity(); _CubeScene.CurrentView.LocalModel.Translate(_ViewStrideLat, _ViewStrideAlt, 0.0f); _CubeScene.CurrentView.LocalModel.RotateY(_ViewAzimuth); _CubeScene.CurrentView.LocalModel.RotateX(_ViewElevation); _CubeScene.CurrentView.LocalModel.Translate(0.0f, 0.0f, _ViewLever); _CubeScene.CurrentView.ProjectionMatrix = new PerspectiveProjectionMatrix(45.0f, senderAspectRatio, 0.5f, 10000.0f); _CubeScene.Draw(_Context); }
private void Visual_Paint_1(object sender, PaintEventArgs e) { // Console.WriteLine("Drawn."); render = true; ResizeUI(); Visual.Clear(); Render.To2D(); EditGraph.Draw(); if (ShowIcons || IconsAlpha > 0.0f) { Render.Col = new OpenTK.Vector4(1, 1, 1, IconsAlpha); Render.SetBlend(BlendMode.Alpha); if (MoveOn) { Render.Col = new OpenTK.Vector4(0.5f, 0.5f, 0.5f, 0.5f * IconsAlpha); Render.Rect(20, 20, 32, 32); } Render.Col = new OpenTK.Vector4(1, 1, 1, IconsAlpha); Render.Image(20, 20, 32, 32, MoveIcon); if (RotateOn) { Render.Col = new OpenTK.Vector4(0.5f, 0.5f, 0.5f, 0.5f * IconsAlpha); Render.Rect(65, 20, 32, 32); } Render.Col = new OpenTK.Vector4(1, 1, 1, IconsAlpha); Render.Image(65, 20, 32, 32, RotateIcon); if (ScaleOn) { Render.Col = new OpenTK.Vector4(0.5f, 0.5f, 0.5f, 0.5f * IconsAlpha); Render.Rect(110, 20, 32, 32); } Render.Col = new OpenTK.Vector4(1, 1, 1, IconsAlpha); Render.Image(110, 20, 32, 32, ScaleIcon); } Render.Col = new OpenTK.Vector4(1, 1, 1, 1); switch (EditMode) { case 1: Render.Image(20, Visual.Height - 40, 32, 32, MoveIcon); break; case 2: Render.Image(20, Visual.Height - 40, 32, 32, RotateIcon); break; case 3: Render.Image(20, Visual.Height - 40, 32, 32, ScaleIcon); break; } Visual.Swap(); render = false; }
/// <summary> /// Update framebuffer. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ObjectsControl_Render(object sender, GlControlEventArgs e) { GlControl senderControl = (GlControl)sender; float senderAspectRatio = (float)senderControl.Width / senderControl.Height; // Clear Gl.Viewport(0, 0, senderControl.Width, senderControl.Height); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _CubeScene.CurrentView.LocalModel.SetIdentity(); _CubeScene.CurrentView.LocalModel.Translate(_ViewStrideLat, _ViewStrideAlt, 0.0f); _CubeScene.CurrentView.LocalModel.RotateY(_ViewAzimuth); _CubeScene.CurrentView.LocalModel.RotateX(_ViewElevation); _CubeScene.CurrentView.LocalModel.Translate(0.0f, 0.0f, _ViewLever); _CubeScene.CurrentView.ProjectionMatrix = new PerspectiveProjectionMatrix(45.0f, senderAspectRatio, 0.5f, 10000.0f); _CubeScene.Draw(_Context); // Overlay ProjectionMatrix overlayProjection = new OrthoProjectionMatrix(0.0f, ClientSize.Width, 0.0f, ClientSize.Height); ModelMatrix overlayModel = new ModelMatrix(); overlayModel.Translate(0.375f, 0.375f); Gl.Clear(ClearBufferMask.DepthBufferBit); ColorRGBAF fpsColor = ColorRGBAF.ColorGreen; int fps = senderControl.Fps; if (fps >= 59) { fpsColor = ColorRGBAF.ColorGreen; } else if (fps >= 29) { fpsColor = ColorRGBAF.ColorBlue; } else if (fps >= 24) { fpsColor = ColorRGBAF.ColorYellow; } else { fpsColor = ColorRGBAF.ColorRed; } fontPatch.DrawString( _Context, overlayProjection * overlayModel, fpsColor, String.Format("FPS: {0}", senderControl.Fps) ); overlayModel.SetIdentity(); overlayModel.Translate(0.375f, ClientSize.Height - 64 + 0.375f); fontTitle.DrawString( _Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen, "Hello Objects example ~(^.^)~" ); overlayModel.SetIdentity(); overlayModel.Translate(0.375f, ClientSize.Height - 128 + 0.375f); fontTitleV.DrawString(_Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen, "Hello Objects example ~(^.^)~" ); }
/// <summary> /// Update framebuffer. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ObjectsControl_Render(object sender, GlControlEventArgs e) { GlControl senderControl = (GlControl)sender; float senderAspectRatio = (float)senderControl.Width / senderControl.Height; KhronosApi.LogEnabled = false; KhronosApi.LogComment("--------------------------------------------------"); KhronosApi.LogComment("*** Draw"); // Clear Gl.Viewport(0, 0, senderControl.Width, senderControl.Height); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _CubeScene.CurrentView.ProjectionMatrix = new PerspectiveProjectionMatrix(45.0f, senderAspectRatio, 0.1f, 100.0f); _CubeScene.CurrentView.LocalModel.SetIdentity(); _CubeScene.CurrentView.LocalModel.Translate(_ViewStrideLat, _ViewStrideAlt, 0.0f); _CubeScene.CurrentView.LocalModel.RotateY(_ViewAzimuth); _CubeScene.CurrentView.LocalModel.RotateX(_ViewElevation); _CubeScene.CurrentView.LocalModel.Translate(0.0f, 0.0f, _ViewLever); _CubeScene.UpdateViewMatrix(); _CubeScene.Draw(_Context); KhronosApi.LogEnabled = false; return; // Overlay ProjectionMatrix overlayProjection = new OrthoProjectionMatrix(0.0f, ClientSize.Width, 0.0f, ClientSize.Height); ModelMatrix overlayModel = new ModelMatrix(); overlayModel.Translate(0.375f, 0.375f); Gl.Clear(ClearBufferMask.DepthBufferBit); ColorRGBAF fpsColor = ColorRGBAF.ColorGreen; int fps = (int)Math.Floor(1000.0 / senderControl.FrameSwapTime.TotalMilliseconds); if (fps >= 59) { fpsColor = ColorRGBAF.ColorGreen; } else if (fps >= 29) { fpsColor = ColorRGBAF.ColorBlue; } else if (fps >= 24) { fpsColor = ColorRGBAF.ColorYellow; } else { fpsColor = ColorRGBAF.ColorRed; } fontPatch.DrawString( _Context, overlayProjection * overlayModel, fpsColor, String.Format("FPS: {0}", fps) ); overlayModel.SetIdentity(); overlayModel.Translate(0.375f, ClientSize.Height - 64 + 0.375f); fontTitle.DrawString( _Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen, "Hello Objects example ~(^.^)~" ); overlayModel.SetIdentity(); overlayModel.Translate(0.375f, ClientSize.Height - 128 + 0.375f); fontTitleV.DrawString(_Context, overlayProjection * overlayModel, ColorRGBAF.ColorGreen, "Hello Objects example ~(^.^)~" ); // Release resources _Context.DisposeResources(); }
public void Draw() { SceneGraph.Draw(); }