public MovementPlanner(Player player, float distanceScalar) { _player = player; _intersectionDetector = new IntersectionDetector(); _obstaclePathFinder = new ObstaclePathFinder(); _distanceScalar = distanceScalar; }
static void Main(string[] args) { // Initialize GLFW int result = Glfw.Init(); if (result == 0) { Console.WriteLine("Failed to initialize GLFW"); return; } // Display GLFW version initialized Console.WriteLine("GLFW Version: " + Marshal.PtrToStringAnsi(Glfw.GetVersionString())); // Set window creation hints Glfw.WindowHint((int)GlfwWindowHint.ContextVersionMajor, 3); Glfw.WindowHint((int)GlfwWindowHint.ContextVersionMinor, 2); // Create window IntPtr windowHandle = Glfw.CreateWindow(800, 600, "Seacow Engine", IntPtr.Zero, IntPtr.Zero); // Make the window's context current Glfw.MakeContextCurrent(windowHandle); // Display context information int majorVersion = Glfw.GetWindowAttrib(windowHandle, (int)GlfwWindowHint.ContextVersionMajor); int minorVersion = Glfw.GetWindowAttrib(windowHandle, (int)GlfwWindowHint.ContextVersionMinor); Console.WriteLine("OpenGL Major Version: " + majorVersion); Console.WriteLine("OpenGL Minor Version: " + minorVersion); // Set GLFW input callback Glfw.SetKeyCallback(windowHandle, Marshal.GetFunctionPointerForDelegate(callback)); // Own init stuff Renderer myRenderer = new Renderer(); Shader myVertexShader = new Shader("Data/Shaders/Vertex.Shader", ShaderType.VertexShader); Shader myFragmentShader = new Shader("Data/Shaders/Fragment.Shader", ShaderType.FragmentShader); Material mySimpleMaterial = new Material(new List <Shader>() { myVertexShader, myFragmentShader }); // Load texture Texture dirtTexture = new Texture("Data/Textures/simpleTex.bmp"); // Load sphere ObjLoader experimentalLoader = new ObjLoader("Data/Models/sphere/textureSphere.obj"); ModelData experimentalModelData = experimentalLoader.LoadModel(); ObjWeaver objWeave = new ObjWeaver(); var weavedModelData = objWeave.WeaveModelData(experimentalModelData); // Load box ObjLoader boxLoader = new ObjLoader("Data/Models/Box/simpleBox.obj"); ModelData boxModelData = boxLoader.LoadModel(); ObjWeaver boxModelDataWeaver = new ObjWeaver(); var weavedBoxModelData = boxModelDataWeaver.WeaveModelData(boxModelData); // Create sphere mySphere = new Mesh( weavedModelData.weavedVertexData, weavedModelData.indexes.Select(i => (uint)i).ToList(), mySimpleMaterial, dirtTexture); mySphere.Scale = 0.1f; mySphere.Position = new vec3(0.3f, 1.0f, 0.0f); mySimpleMaterial.Activate(); // Create box Mesh myBox = new Mesh( weavedBoxModelData.weavedVertexData, weavedBoxModelData.indexes.Select(i => (uint)i).ToList(), mySimpleMaterial ); myBox.Position = vec3.UnitX * 1; myBox.Scale = 0.5f; myBox.UserColor = new Vector3(0.0f, 0.0f, 1.0f); // Create indicator sphere indicatorSphere = new Mesh( weavedModelData.weavedVertexData, weavedModelData.indexes.Select(i => (uint)i).ToList(), mySimpleMaterial ); indicatorSphere.UserColor = new Vector3(1.0f, 0.0f, 0.0f); indicatorSphere.Scale = 0.1f; // Add objects to world myRenderer.WorldMeshes.Add(mySphere); myRenderer.WorldMeshes.Add(myBox); //myRenderer.WorldMeshes.Add(indicatorSphere); // ** Do all sorts of fun collision stuff! :D :D ** Aabb colBox = new Aabb(new Vector3(0.5f, -0.5f, -0.5f), new Vector3(1.5f, 0.5f, 0.5f)); Vector3 circlePoint = new Vector3(mySphere.Position.x, mySphere.Position.y, mySphere.Position.z); // Enable depth testing Gl.Enable((uint)Capability.DepthTest); Gl.CheckForError(); const double dt = 0.01; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); double currentTime = stopwatch.ElapsedMilliseconds / 1000.0f; double accumulator = 0.0; while (Glfw.WindowShouldClose(windowHandle) == 0) { // Timer stuff double newTime = stopwatch.ElapsedMilliseconds / 1000.0f; double frameTime = newTime - currentTime; currentTime = newTime; accumulator += frameTime; int counter = 0; // Fixed timestep while (accumulator >= dt) { Sphere theSphere = new Sphere(new Vector3(mySphere.Position.x, mySphere.Position.y, mySphere.Position.z), 0.1f); var colResult = IntersectionDetector.TestSphereAgainstAabb(theSphere, colBox); if (colResult) { Console.WriteLine("COLLISION"); } //Integrate(dt); accumulator -= dt; } // Rendering Gl.ClearColor(0.39f, 0.58f, 0.92f, 0.0f); Gl.CheckForError(); Gl.Clear((int)ColorBit.ColorBuffer | (int)ColorBit.DepthBuffer); Gl.CheckForError(); myRenderer.Render((float)(accumulator / dt)); Glfw.SwapBuffers(windowHandle); Glfw.PollEvents(); } Glfw.Terminate(); }
public override UIElement[] RenderUIElements() { UIElement[] uiElements; if (!NodeSettings.IsFocused) { ILineSegment arrowLineSegment = new LineSegment(new Point(NodeUIElementLocation.X + 25, NodeUIElementLocation.Y + 23), new Point(NodeUIElementLocation.X + 130, NodeUIElementLocation.Y + 27)); Point A = new Point(NodeUIElementLocation.X + 5, NodeUIElementLocation.Y + 5); Point B = new Point(NodeUIElementLocation.X + 5, NodeUIElementLocation.Y + 22); Point C = new Point(NodeUIElementLocation.X + 5, NodeUIElementLocation.Y + 45); Point D = new Point(NodeUIElementLocation.X + 89, NodeUIElementLocation.Y + 45); Point E = new Point(NodeUIElementLocation.X + 174, NodeUIElementLocation.Y + 45); Point F = new Point(NodeUIElementLocation.X + 174, NodeUIElementLocation.Y + 22); Point G = new Point(NodeUIElementLocation.X + 174, NodeUIElementLocation.Y + 5); Point H = new Point(NodeUIElementLocation.X + 89, NodeUIElementLocation.Y + 5); Point arrowEnd = new Point(NodeSettings.CentreX, NodeSettings.CentreY); List <Point> elements = new List <Point>(); elements.Add(A); elements.Add(B); elements.Add(C); elements.Add(D); elements.Add(E); elements.Add(F); elements.Add(G); elements.Add(H); Point arrowStart = elements.FindClosestPoint(arrowEnd); ILineSegment arrowCoordinates = new LineSegment(arrowStart, arrowEnd); Point cornerA = new Point(NodeUIElementLocation.X, NodeUIElementLocation.Y); Point cornerB = new Point(NodeUIElementLocation.X + 5, NodeUIElementLocation.Y + 55); Point cornerC = new Point(NodeUIElementLocation.X + 179, NodeUIElementLocation.Y + 50); Point cornerD = new Point(NodeUIElementLocation.X + 184, NodeUIElementLocation.Y + 5); Point triangulationPoint = new Point(NodeUIElementLocation.X + 90, NodeUIElementLocation.Y + 25); double mainTopLeftX = NodeSettings.CentreX - 90; double mainTopLeftY = NodeSettings.CentreY - 125; Point mainCornerA = new Point(mainTopLeftX - 5, mainTopLeftY - 6); Point mainCornerB = new Point(mainTopLeftX - 6, mainTopLeftY + 255); Point mainCornerC = new Point(mainTopLeftX + 185, mainTopLeftY + 256); Point mainCornerD = new Point(mainTopLeftX + 186, mainTopLeftY - 5); Point mainTriangulationPoint = new Point(NodeSettings.CentreX, NodeSettings.CentreY); IntersectionDetector detector = new IntersectionDetector(); detector.Add(new LineSegment(cornerA, cornerB, mainTriangulationPoint)); detector.Add(new LineSegment(cornerB, cornerC, mainTriangulationPoint)); detector.Add(new LineSegment(cornerC, cornerD, mainTriangulationPoint)); detector.Add(new LineSegment(cornerD, cornerA, mainTriangulationPoint)); IntersectionDetector detector2 = new IntersectionDetector(); detector2.Add(new LineSegment(mainCornerA, mainCornerB, triangulationPoint)); detector2.Add(new LineSegment(mainCornerB, mainCornerC, triangulationPoint)); detector2.Add(new LineSegment(mainCornerC, mainCornerD, triangulationPoint)); detector2.Add(new LineSegment(mainCornerD, mainCornerA, triangulationPoint)); arrowCoordinates = arrowCoordinates.Resize(detector); arrowCoordinates = arrowCoordinates.Resize(detector2); Arrow arrow = new Arrow(arrowCoordinates); List <UIElement> newElements = new List <UIElement>(base.RenderUIElements()); newElements.Add(arrow.Sprite); uiElements = newElements.ToArray(); } else { uiElements = base.RenderUIElements(); } return(uiElements); }
public override UIElement[] RenderUIElements() { UIElement[] uiElements; if (!NodeSettings.IsFocused) { ILineSegment arrowLineSegment = new LineSegment(new Point(NodeUIElementLocation.X + 25, NodeUIElementLocation.Y + 23), new Point(NodeUIElementLocation.X + 130, NodeUIElementLocation.Y + 27)); Point A = new Point(NodeUIElementLocation.X + 5, NodeUIElementLocation.Y + 5); Point B = new Point(NodeUIElementLocation.X + 5, NodeUIElementLocation.Y + 22); Point C = new Point(NodeUIElementLocation.X + 5, NodeUIElementLocation.Y + 45); Point D = new Point(NodeUIElementLocation.X + 89, NodeUIElementLocation.Y + 45); Point E = new Point(NodeUIElementLocation.X + 174, NodeUIElementLocation.Y + 45); Point F = new Point(NodeUIElementLocation.X + 174, NodeUIElementLocation.Y + 22); Point G = new Point(NodeUIElementLocation.X + 174, NodeUIElementLocation.Y + 5); Point H = new Point(NodeUIElementLocation.X + 89, NodeUIElementLocation.Y + 5); Point arrowEnd = new Point(NodeSettings.CentreX, NodeSettings.CentreY); List<Point> elements = new List<Point>(); elements.Add(A); elements.Add(B); elements.Add(C); elements.Add(D); elements.Add(E); elements.Add(F); elements.Add(G); elements.Add(H); Point arrowStart = elements.FindClosestPoint(arrowEnd); ILineSegment arrowCoordinates = new LineSegment(arrowStart, arrowEnd); Point cornerA = new Point(NodeUIElementLocation.X, NodeUIElementLocation.Y); Point cornerB = new Point(NodeUIElementLocation.X + 5, NodeUIElementLocation.Y + 55); Point cornerC = new Point(NodeUIElementLocation.X + 179, NodeUIElementLocation.Y + 50); Point cornerD = new Point(NodeUIElementLocation.X + 184, NodeUIElementLocation.Y + 5); Point triangulationPoint = new Point(NodeUIElementLocation.X + 90, NodeUIElementLocation.Y + 25); double mainTopLeftX = NodeSettings.CentreX - 90; double mainTopLeftY = NodeSettings.CentreY - 125; Point mainCornerA = new Point(mainTopLeftX - 5, mainTopLeftY - 6); Point mainCornerB = new Point(mainTopLeftX - 6, mainTopLeftY + 255); Point mainCornerC = new Point(mainTopLeftX + 185, mainTopLeftY + 256); Point mainCornerD = new Point(mainTopLeftX + 186, mainTopLeftY - 5); Point mainTriangulationPoint = new Point(NodeSettings.CentreX, NodeSettings.CentreY); IntersectionDetector detector = new IntersectionDetector(); detector.Add(new LineSegment(cornerA, cornerB, mainTriangulationPoint)); detector.Add(new LineSegment(cornerB, cornerC, mainTriangulationPoint)); detector.Add(new LineSegment(cornerC, cornerD, mainTriangulationPoint)); detector.Add(new LineSegment(cornerD, cornerA, mainTriangulationPoint)); IntersectionDetector detector2 = new IntersectionDetector(); detector2.Add(new LineSegment(mainCornerA, mainCornerB, triangulationPoint)); detector2.Add(new LineSegment(mainCornerB, mainCornerC, triangulationPoint)); detector2.Add(new LineSegment(mainCornerC, mainCornerD, triangulationPoint)); detector2.Add(new LineSegment(mainCornerD, mainCornerA, triangulationPoint)); arrowCoordinates = arrowCoordinates.Resize(detector); arrowCoordinates = arrowCoordinates.Resize(detector2); Arrow arrow = new Arrow(arrowCoordinates); List<UIElement> newElements = new List<UIElement>(base.RenderUIElements()); newElements.Add(arrow.Sprite); uiElements = newElements.ToArray(); } else { uiElements = base.RenderUIElements(); } return uiElements; }