private void customGLControl_Paint(object sender, PaintEventArgs e) { if (!ready) return; try { fpsMonitor.Update(); RenderInit(((GLControl)sender).ClientRectangle, Color.LightBlue); if (rom != null && rom.Loaded) { /* Scene/rooms */ RenderScene(); /* Prepare for actors */ GL.PushAttrib(AttribMask.AllAttribBits); GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.Lighting); if (supportsGenProgramsARB) GL.Disable((EnableCap)All.FragmentProgram); if (supportsCreateShader) GL.UseProgram(0); { /* Room actors */ if (Configuration.RenderRoomActors && currentRoom != null && currentRoom.ActiveRoomActorData != null) foreach (HeaderCommands.Actors.Entry ac in currentRoom.ActiveRoomActorData.ActorList) ac.Render(ac == (cbActors.SelectedItem as HeaderCommands.Actors.Entry) && cbActors.Visible ? HeaderCommands.PickableObjectRenderType.Selected : HeaderCommands.PickableObjectRenderType.Normal); /* Spawn points */ if (Configuration.RenderSpawnPoints && currentScene != null && currentScene.GetActiveSpawnPointData() != null) foreach (HeaderCommands.Actors.Entry ac in currentScene.GetActiveSpawnPointData().ActorList) ac.Render(ac == (cbSpawnPoints.SelectedItem as HeaderCommands.Actors.Entry) && cbSpawnPoints.Visible ? HeaderCommands.PickableObjectRenderType.Selected : HeaderCommands.PickableObjectRenderType.Normal); /* Transitions */ if (Configuration.RenderTransitions && currentScene != null && currentScene.GetActiveTransitionData() != null) foreach (HeaderCommands.Actors.Entry ac in currentScene.GetActiveTransitionData().ActorList) ac.Render(ac == (cbTransitions.SelectedItem as HeaderCommands.Actors.Entry) && cbTransitions.Visible ? HeaderCommands.PickableObjectRenderType.Selected : HeaderCommands.PickableObjectRenderType.Normal); /* Path waypoints */ if (Configuration.RenderPathWaypoints && activePathHeader != null && activePathHeader.Points != null) { /* Link waypoints? */ if (Configuration.LinkAllWPinPath) { GL.LineWidth(4.0f); GL.Color3(0.25, 0.5, 1.0); GL.Begin(PrimitiveType.LineStrip); foreach (HeaderCommands.Waypoints.Waypoint wp in activePathHeader.Points) GL.Vertex3(wp.X, wp.Y, wp.Z); GL.End(); } HeaderCommands.Waypoints.Waypoint selwp = (dgvPathWaypoints.SelectedCells.Count != 0 ? dgvPathWaypoints.SelectedCells[0].OwningRow.DataBoundItem as HeaderCommands.Waypoints.Waypoint : null); foreach (HeaderCommands.Waypoints.Waypoint wp in activePathHeader.Points) wp.Render(wp == selwp && cbPathHeaders.Visible ? HeaderCommands.PickableObjectRenderType.Selected : HeaderCommands.PickableObjectRenderType.Normal); } } GL.PopAttrib(); /* Collision */ if (Configuration.RenderCollision && currentScene != null && currentScene.GetActiveCollision() != null) { if (!collisionDirty && collisionDL != null) { collisionDL.Render(); } else { collisionDirty = false; if (collisionDL != null) collisionDL.Dispose(); collisionDL = new DisplayList(ListMode.CompileAndExecute); GL.PushAttrib(AttribMask.AllAttribBits); GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.Lighting); if (supportsGenProgramsARB) GL.Disable((EnableCap)All.FragmentProgram); if (supportsCreateShader) GL.UseProgram(0); GL.DepthRange(0.0, 0.99999); if (Configuration.RenderCollisionAsWhite) GL.Color4(1.0, 1.0, 1.0, 0.5); GL.Begin(PrimitiveType.Triangles); foreach (HeaderCommands.Collision.Polygon poly in currentScene.GetActiveCollision().Polygons) { if (poly == currentCollisionPolygon && cbCollisionPolys.Visible) { GL.Color4(0.5, 0.5, 1.0, 0.5); poly.Render(HeaderCommands.PickableObjectRenderType.NoColor); if (Configuration.RenderCollisionAsWhite) GL.Color4(1.0, 1.0, 1.0, 0.5); } else { if (Configuration.RenderCollisionAsWhite) poly.Render(HeaderCommands.PickableObjectRenderType.NoColor); else poly.Render(HeaderCommands.PickableObjectRenderType.Normal); } } GL.End(); GL.DepthRange(0.0, 0.99998); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); GL.LineWidth(2.0f); GL.Color3(Color.Black); GL.Begin(PrimitiveType.Triangles); foreach (HeaderCommands.Collision.Polygon poly in currentScene.GetActiveCollision().Polygons) poly.Render(HeaderCommands.PickableObjectRenderType.NoColor); GL.End(); GL.PopAttrib(); collisionDL.End(); } } /* Waterboxes */ if (Configuration.RenderWaterboxes && currentScene != null && currentScene.GetActiveCollision() != null) { if (!waterboxesDirty && waterboxDL != null) { waterboxDL.Render(); } else { waterboxesDirty = false; if (waterboxDL != null) waterboxDL.Dispose(); waterboxDL = new DisplayList(ListMode.CompileAndExecute); GL.PushAttrib(AttribMask.AllAttribBits); GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.Lighting); if (supportsGenProgramsARB) GL.Disable((EnableCap)All.FragmentProgram); if (supportsCreateShader) GL.UseProgram(0); GL.Disable(EnableCap.CullFace); GL.Begin(PrimitiveType.Quads); foreach (HeaderCommands.Collision.Waterbox wb in currentScene.GetActiveCollision().Waterboxes) { double alpha = ((Configuration.ShowWaterboxesPerRoom && currentRoom != null && (wb.RoomNumber != currentRoom.Number && wb.RoomNumber != 0x3F)) ? 0.1 : 0.5); if (wb == currentWaterbox && cbWaterboxes.Visible) GL.Color4(0.5, 1.0, 0.5, alpha); else GL.Color4(0.0, 0.5, 1.0, alpha); wb.Render(HeaderCommands.PickableObjectRenderType.Normal); } GL.End(); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); GL.LineWidth(2.0f); GL.Begin(PrimitiveType.Quads); foreach (HeaderCommands.Collision.Waterbox wb in currentScene.GetActiveCollision().Waterboxes) { double alpha = ((Configuration.ShowWaterboxesPerRoom && currentRoom != null && (wb.RoomNumber != currentRoom.Number && wb.RoomNumber != 0x3F)) ? 0.1 : 0.5); GL.Color4(0.0, 0.0, 0.0, alpha); wb.Render(HeaderCommands.PickableObjectRenderType.Normal); } GL.End(); GL.Enable(EnableCap.CullFace); GL.PopAttrib(); GL.Color4(Color.White); waterboxDL.End(); } } /* Render selected room triangle overlay */ if (currentRoomTriangle != null && !Configuration.RenderCollision) { currentRoomTriangle.Render(HeaderCommands.PickableObjectRenderType.Normal); } /* 2D text overlay */ RenderTextOverlay(); } ((GLControl)sender).SwapBuffers(); } catch (EntryPointNotFoundException) { // } }
static StockObjects() { /* Axis marker */ AxisMarker = new DisplayList(ListMode.Compile); GL.LineWidth(4.0f); GL.DepthRange(0.0, 0.99999); double radius = 12.0; GL.LineWidth(4.0f); GL.Begin(PrimitiveType.Lines); GL.Color3(1.0, 0.0, 0.0); GL.Vertex3(radius, 0.0, 0.0); GL.Vertex3(-radius, 0.0, 0.0); GL.Color3(0.0, 1.0, 0.0); GL.Vertex3(0.0, radius, 0.0); GL.Vertex3(0.0, -radius, 0.0); GL.End(); GL.PushMatrix(); GL.Rotate(90.0, 1.0, 0.0, 0.0); GL.Color3(0.0, 0.0, 1.0); MiscDrawingHelpers.RenderNotchCircle(radius / 2.0, 48); GL.PopMatrix(); GL.DepthRange(0.0, 1.0); GL.LineWidth(1.0f); AxisMarker.End(); /* Simple axis marker */ SimpleAxisMarker = new DisplayList(ListMode.Compile); GL.LineWidth(4.0f); GL.DepthRange(0.0, 0.99999); GL.LineWidth(4.0f); GL.Begin(PrimitiveType.Lines); GL.Color3(1.0, 0.0, 0.0); GL.Vertex3(radius, 0.0, 0.0); GL.Vertex3(-radius, 0.0, 0.0); GL.Color3(0.0, 1.0, 0.0); GL.Vertex3(0.0, radius, 0.0); GL.Vertex3(0.0, -radius, 0.0); GL.Color3(0.0, 0.0, 1.0); GL.Vertex3(0.0, 0.0, radius); GL.Vertex3(0.0, 0.0, -radius); GL.End(); GL.DepthRange(0.0, 1.0); GL.LineWidth(1.0f); SimpleAxisMarker.End(); /* Simple cube */ Cube = new DisplayList(ListMode.Compile); MiscDrawingHelpers.RenderCube(false); Cube.End(); /* Colored cube */ ColoredCube = new DisplayList(ListMode.Compile); MiscDrawingHelpers.RenderCube(true); ColoredCube.End(); /* Sphere */ Sphere = new DisplayList(ListMode.Compile); MiscDrawingHelpers.RenderSphere(Vector3d.Zero, 3.0, 12); Sphere.End(); /* Down arrow */ DownArrow = new DisplayList(ListMode.Compile); // Top GL.Begin(PrimitiveType.Quads); GL.Vertex3(1.0, 2.0, -1.0); GL.Vertex3(-1.0, 2.0, -1.0); GL.Vertex3(-1.0, 2.0, 1.0); GL.Vertex3(1.0, 2.0, 1.0); GL.End(); GL.Begin(PrimitiveType.Triangles); // Left GL.Vertex3(-1.0, 2.0, 1.0); GL.Vertex3(-1.0, 2.0, -1.0); GL.Vertex3(0.0, 0.0, 0.0); // Right GL.Vertex3(1.0, 2.0, -1.0); GL.Vertex3(1.0, 2.0, 1.0); GL.Vertex3(0.0, 0.0, 0.0); // Front GL.Vertex3(1.0, 2.0, 1.0); GL.Vertex3(-1.0, 2.0, 1.0); GL.Vertex3(0.0, 0.0, 0.0); // Back GL.Vertex3(0.0, 0.0, 0.0); GL.Vertex3(-1.0, 2.0, -1.0); GL.Vertex3(1.0, 2.0, -1.0); GL.End(); DownArrow.End(); /* Simple slab (ex. boxes, chests) */ Slab = new DisplayList(ListMode.Compile); MiscDrawingHelpers.RenderCube(new Vector3d(3.0, 2.0, 2.0), false); Slab.End(); /* Colored slab */ ColoredSlab = new DisplayList(ListMode.Compile); MiscDrawingHelpers.RenderCube(new Vector3d(3.0, 2.0, 2.0), true); ColoredSlab.End(); /* Door */ Door = new DisplayList(ListMode.Compile); MiscDrawingHelpers.RenderCube(new Vector3d(2.5, 4.5, 0.5), new Vector3d(0.0, 4.0, 0.0), false); Door.End(); /* Colored door */ ColoredDoor = new DisplayList(ListMode.Compile); MiscDrawingHelpers.RenderCube(new Vector3d(2.5, 4.5, 0.5), new Vector3d(0.0, 4.0, 0.0), true); ColoredDoor.End(); }
public XMLActorDefinitionReader(string defdir) { Definitions = new List <Definition>(); string path = Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), defdir); if (Directory.Exists(path) == false) { return; } ProgramVersion = new Version(); List <string> XmlFiles = Directory.EnumerateFiles(path, "*.xml").ToList(); foreach (string fn in XmlFiles) { Definition ndef = null; Definition.Item nitem = null; Definition.Item.Option nopt = null; OpenGLHelpers.DisplayList displaydl = null; OpenGLHelpers.DisplayList pickdl = null; XmlTextReader xml = new XmlTextReader(fn); while (xml.Read()) { if (xml.NodeType == XmlNodeType.Element) { if (xml.Name == "ActorDatabase") { while (xml.MoveToNextAttribute()) { if (xml.Name == "ProgramVersion") { ProgramVersion = Version.Parse(xml.Value); if (ProgramVersion != Version.Parse(Application.ProductVersion)) { ThrowVersionError(); } } } } else if (xml.Name == "Definition") { if (ProgramVersion == new Version()) { ThrowVersionError(); } ndef = new Definition(); ndef.Items = new List <Definition.Item>(); while (xml.MoveToNextAttribute()) { switch (xml.Name) { case "Number": if (xml.Value.StartsWith("0x") == true) { ndef.Number = ushort.Parse(xml.Value.Substring(2), System.Globalization.NumberStyles.HexNumber); } else { ndef.Number = ushort.Parse(xml.Value); } break; case "IsDefault": ndef.IsDefault = (Definition.DefaultTypes)Enum.Parse(typeof(Definition.DefaultTypes), xml.Value); break; case "DisplayModel": displaydl = OpenGLHelpers.StockObjects.GetDisplayList(xml.Value); if (displaydl != null) { ndef.DisplayModel = displaydl; } break; case "PickModel": pickdl = OpenGLHelpers.StockObjects.GetDisplayList(xml.Value); if (pickdl != null) { ndef.PickModel = pickdl; } break; case "FrontOffset": ndef.FrontOffset = double.Parse(xml.Value, System.Globalization.CultureInfo.InvariantCulture); break; } } } else if (xml.Name == "Item") { nitem = new Definition.Item(); while (xml.MoveToNextAttribute()) { switch (xml.Name) { case "Index": nitem.Index = int.Parse(xml.Value); break; case "ValueType": nitem.ValueType = FindTypeInCurrentAssemblies(xml.Value); break; case "DisplayStyle": nitem.DisplayStyle = (Definition.Item.DisplayStyles)Enum.Parse(typeof(Definition.Item.DisplayStyles), xml.Value); break; case "Usage": nitem.Usage = (Definition.Item.Usages)Enum.Parse(typeof(Definition.Item.Usages), xml.Value); break; case "Description": nitem.Description = xml.Value; break; case "Mask": if (xml.Value.StartsWith("0x") == true) { nitem.Mask = UInt64.Parse(xml.Value.Substring(2), System.Globalization.NumberStyles.HexNumber); } else { nitem.Mask = UInt64.Parse(xml.Value); } break; case "ControlType": nitem.ControlType = FindTypeInCurrentAssemblies(xml.Value); break; } } ndef.Items.Add(nitem); } else if (xml.Name == "Option") { nopt = new Definition.Item.Option(); while (xml.MoveToNextAttribute()) { switch (xml.Name) { case "Value": if (xml.Value.StartsWith("0x") == true) { nopt.Value = UInt64.Parse(xml.Value.Substring(2), System.Globalization.NumberStyles.HexNumber); } else { nopt.Value = UInt64.Parse(xml.Value); } break; case "Description": nopt.Description = xml.Value; break; } } nitem.Options.Add(nopt); } } else if (xml.NodeType == XmlNodeType.EndElement) { if (xml.Name == "Definition") { if (displaydl != null && pickdl == null) { ndef.PickModel = displaydl; } Definitions.Add(ndef); } } } } }