private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs e) { // Get the OpenGL object, just to clean up the code. PassedCount = 0; //OpenGL gl = this.openGLControl1.OpenGL; sw.Start(); gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer // Set the projection matrix. gl.MatrixMode(OpenGL.GL_PROJECTION); gl.LoadIdentity(); // Reset The View // Create a perspective transformation. gl.Perspective(60.0f, (double)openGLControl1.Width / (double)openGLControl1.Height, 0.01, 25000.0); // Use the 'look at' helper function to position and aim the camera. float vX = offsetDistance * (float)Math.Cos(angle * Vector3.Deg2Rad); float vZ = offsetDistance * (float)Math.Sin(angle * Vector3.Deg2Rad); gl.LookAt(center.x + vX, center.y, center.z + vZ, center.x, center.y, center.z, 0, 1, 0); // Set the modelview matrix. gl.MatrixMode(OpenGL.GL_MODELVIEW); //gl.Translate(-1.5f, 0.0f, -6.0f); gl.Begin(OpenGL.GL_TRIANGLES); // Start Drawing The Pyramid gl.Color(1.0f, 0.0f, 0.0f); // Red gl.Vertex(0.0f, 1.0f, 0.0f); // Top Of Triangle (Front) gl.Color(0.0f, 1.0f, 0.0f); // Green gl.Vertex(-1.0f, -1.0f, 1.0f); // Left Of Triangle (Front) gl.Color(0.0f, 0.0f, 1.0f); // Blue gl.Vertex(1.0f, -1.0f, 1.0f); // Right Of Triangle (Front) gl.Color(1.0f, 0.0f, 0.0f); // Red gl.Vertex(0.0f, 1.0f, 0.0f); // Top Of Triangle (Right) gl.Color(0.0f, 0.0f, 1.0f); // Blue gl.Vertex(1.0f, -1.0f, 1.0f); // Left Of Triangle (Right) gl.Color(0.0f, 1.0f, 0.0f); // Green gl.Vertex(1.0f, -1.0f, -1.0f); // Right Of Triangle (Right) gl.Color(1.0f, 0.0f, 0.0f); // Red gl.Vertex(0.0f, 1.0f, 0.0f); // Top Of Triangle (Back) gl.Color(0.0f, 1.0f, 0.0f); // Green gl.Vertex(1.0f, -1.0f, -1.0f); // Left Of Triangle (Back) gl.Color(0.0f, 0.0f, 1.0f); // Blue gl.Vertex(-1.0f, -1.0f, -1.0f); // Right Of Triangle (Back) gl.Color(1.0f, 0.0f, 0.0f); // Red gl.Vertex(0.0f, 1.0f, 0.0f); // Top Of Triangle (Left) gl.Color(0.0f, 0.0f, 1.0f); // Blue gl.Vertex(-1.0f, -1.0f, -1.0f); // Left Of Triangle (Left) gl.Color(0.0f, 1.0f, 0.0f); // Green gl.Vertex(-1.0f, -1.0f, 1.0f); // Right Of Triangle (Left) gl.End(); // Done Drawing The Pyramid gl.LineWidth(2f); if (OurMap != null) { gl.Color(1.0f, 1.0f, 1.0f, 1.0f); //gl.Translate((double)DistanceValX.Value, (double)DistanceValY.Value, (double)DistanceValZ.Value); gl.Begin(OpenGL.GL_LINES); for (int q = 0; q < OurMap.lineDefs.Count; q++) { Linedef ld = OurMap.lineDefs[q]; VertexDef v1 = OurMap.vertices[ld.v1], v2 = OurMap.vertices[ld.v2]; Vector3 ldFrontBottomV1 = new Vector3(v1.position.x, 0, v1.position.y); Vector3 ldBackBottomV1 = ldFrontBottomV1; Vector3 ldFrontBottomV2 = new Vector3(v2.position.x, 0, v2.position.y); Vector3 ldBackBottomV2 = ldFrontBottomV2; if (v1.floorOffset != null) { ldFrontBottomV1.y = ldBackBottomV1.y = v1.floorOffset.Value; } else { if (ld.sideBack != -1) { ldBackBottomV1.y = OurMap.sectors[OurMap.sideDefs[ld.sideBack].sector].heightFloor; } if (ld.sideFront != -1) { ldFrontBottomV1.y = OurMap.sectors[OurMap.sideDefs[ld.sideFront].sector].heightFloor; } } if (v2.floorOffset != null) { ldFrontBottomV2.y = ldBackBottomV2.y = v2.floorOffset.Value; } else { if (ld.sideBack != -1) { ldBackBottomV2.y = OurMap.sectors[OurMap.sideDefs[ld.sideBack].sector].heightFloor; } if (ld.sideFront != -1) { ldFrontBottomV2.y = OurMap.sectors[OurMap.sideDefs[ld.sideFront].sector].heightFloor; } } Vector3 ldFrontTopV1 = new Vector3(v1.position.x, 0, v1.position.y); Vector3 ldBackTopV1 = ldFrontTopV1; Vector3 ldFrontTopV2 = new Vector3(v2.position.x, 0, v2.position.y); Vector3 ldBackTopV2 = ldFrontTopV2; if (v1.ceilingOffset != null) { ldFrontTopV1.y = ldBackTopV1.y = v1.ceilingOffset.Value; } else { if (ld.sideBack != -1) { ldBackTopV1.y = OurMap.sectors[OurMap.sideDefs[ld.sideBack].sector].heightCeiling; } if (ld.sideFront != -1) { ldFrontTopV1.y = OurMap.sectors[OurMap.sideDefs[ld.sideFront].sector].heightCeiling; } } if (v2.ceilingOffset != null) { ldFrontTopV2.y = ldBackTopV2.y = v2.ceilingOffset.Value; } else { if (ld.sideBack != -1) { ldBackTopV2.y = OurMap.sectors[OurMap.sideDefs[ld.sideBack].sector].heightCeiling; } if (ld.sideFront != -1) { ldFrontTopV2.y = OurMap.sectors[OurMap.sideDefs[ld.sideFront].sector].heightCeiling; } } if (ld.sideBack != -1) { gl.Color(0.3f, 1.0f, 0.3f, 1.0f); if (RB_Copy_FtC.Checked) { ldBackTopV1.y = ldBackBottomV1.y; ldBackTopV2.y = ldBackBottomV2.y; } else if (RB_Copy_CtF.Checked) { ldBackBottomV1.y = ldBackTopV1.y; ldBackBottomV2.y = ldBackTopV2.y; } else if (RB_Swap.Checked) { float tB = ldBackBottomV1.y; ldBackBottomV1.y = ldBackTopV1.y; ldBackTopV1.y = tB; tB = ldBackBottomV2.y; ldBackBottomV2.y = ldBackTopV2.y; ldBackTopV2.y = tB; } ldBackTopV1.y = ldBackTopV1.y * ((float)CeilingMult.Value) + ((float)CeilingOffs.Value); ldBackTopV2.y = ldBackTopV2.y * ((float)CeilingMult.Value) + ((float)CeilingOffs.Value); ldBackBottomV1.y = ldBackBottomV1.y * ((float)FloorMult.Value) + ((float)FloorOffs.Value); ldBackBottomV2.y = ldBackBottomV2.y * ((float)FloorMult.Value) + ((float)FloorOffs.Value); GLVertexV3(ldBackBottomV1); GLVertexV3(ldBackBottomV2); gl.Color(.3f, .3f, 1.0f, 1.0f); GLVertexV3(ldBackTopV1); GLVertexV3(ldBackTopV2); } if (ld.sideFront != -1) { if (RB_Copy_FtC.Checked) { ldFrontTopV1.y = ldFrontBottomV1.y; ldFrontTopV2.y = ldFrontBottomV2.y; } else if (RB_Copy_CtF.Checked) { ldFrontBottomV1.y = ldFrontTopV1.y; ldFrontBottomV2.y = ldFrontTopV2.y; } else if (RB_Swap.Checked) { float tB = ldFrontBottomV1.y; ldFrontBottomV1.y = ldFrontTopV1.y; ldFrontTopV1.y = tB; tB = ldFrontBottomV2.y; ldFrontBottomV2.y = ldFrontTopV2.y; ldFrontTopV2.y = tB; } ldFrontTopV1.y = ldFrontTopV1.y * ((float)CeilingMult.Value) + ((float)CeilingOffs.Value); ldFrontTopV2.y = ldFrontTopV2.y * ((float)CeilingMult.Value) + ((float)CeilingOffs.Value); ldFrontBottomV1.y = ldFrontBottomV1.y * ((float)FloorMult.Value) + ((float)FloorOffs.Value); ldFrontBottomV2.y = ldFrontBottomV2.y * ((float)FloorMult.Value) + ((float)FloorOffs.Value); gl.Color(0.3f, 1.0f, 0.3f, 1.0f); GLVertexV3(ldFrontBottomV2); GLVertexV3(ldFrontBottomV1); gl.Color(0.3f, 0.3f, 1.0f, 1.0f); GLVertexV3(ldFrontTopV2); GLVertexV3(ldFrontTopV1); } if (q == 0 && !threw) { threw = true; Console.WriteLine(ldFrontTopV1); Console.WriteLine(ldFrontTopV2); Console.WriteLine(ldBackTopV1); Console.WriteLine(ldBackTopV2); Console.WriteLine(ldFrontBottomV1); Console.WriteLine(ldFrontBottomV2); Console.WriteLine(ldBackBottomV1); Console.WriteLine(ldBackBottomV2); } } gl.End(); } if (threw && determinePass) { Console.WriteLine("Determined?"); determinePass = false; //DistanceValY.Value =(decimal) ( min.y + (max.y - min.y) / 2f); //DistanceValX.Value = (decimal)(min.x + (max.x - min.x) / 2f); center = new Vector3( (min.x + ((max.x - min.x) / 2f)), (min.y + ((max.y - min.y) / 2f)), (min.z + ((max.z - min.z) / 2f)) ); Console.WriteLine("Min: " + min + " Max: " + max + " Center: " + center); offsetDistance = (max.x - min.x) * 1.5f; float zDistance = (max.z - min.z) * 1.5f; if (zDistance > offsetDistance) { offsetDistance = zDistance; } } gl.Flush(); ServicedVerticesLabel.Text = "Passed vertices: " + PassedCount.ToString(); sw.Stop(); deltaTime = ((float)sw.ElapsedMilliseconds) / 1000f; sw.Reset(); angle += 35f * deltaTime; if (angle > 360) { angle = 0f; } /* * // gl.Color(1.0f, 1.0f, 1.0f); * // gl.FontBitmaps.DrawText(gl, 0, 0, "Arial", "Argh"); * * * * gl.Translate(-1.5f, 0.0f, -6.0f); // Move Left And Into The Screen * * gl.Rotate(rtri, 0.0f, 1.0f, 0.0f); // Rotate The Pyramid On It's Y Axis * * gl.Begin(OpenGL.GL_TRIANGLES); // Start Drawing The Pyramid * * gl.Color(1.0f, 0.0f, 0.0f); // Red * gl.Vertex(0.0f, 1.0f, 0.0f); // Top Of Triangle (Front) * gl.Color(0.0f, 1.0f, 0.0f); // Green * gl.Vertex(-1.0f, -1.0f, 1.0f); // Left Of Triangle (Front) * gl.Color(0.0f, 0.0f, 1.0f); // Blue * gl.Vertex(1.0f, -1.0f, 1.0f); // Right Of Triangle (Front) * * gl.Color(1.0f, 0.0f, 0.0f); // Red * gl.Vertex(0.0f, 1.0f, 0.0f); // Top Of Triangle (Right) * gl.Color(0.0f, 0.0f, 1.0f); // Blue * gl.Vertex(1.0f, -1.0f, 1.0f); // Left Of Triangle (Right) * gl.Color(0.0f, 1.0f, 0.0f); // Green * gl.Vertex(1.0f, -1.0f, -1.0f); // Right Of Triangle (Right) * * gl.Color(1.0f, 0.0f, 0.0f); // Red * gl.Vertex(0.0f, 1.0f, 0.0f); // Top Of Triangle (Back) * gl.Color(0.0f, 1.0f, 0.0f); // Green * gl.Vertex(1.0f, -1.0f, -1.0f); // Left Of Triangle (Back) * gl.Color(0.0f, 0.0f, 1.0f); // Blue * gl.Vertex(-1.0f, -1.0f, -1.0f); // Right Of Triangle (Back) * * gl.Color(1.0f, 0.0f, 0.0f); // Red * gl.Vertex(0.0f, 1.0f, 0.0f); // Top Of Triangle (Left) * gl.Color(0.0f, 0.0f, 1.0f); // Blue * gl.Vertex(-1.0f, -1.0f, -1.0f); // Left Of Triangle (Left) * gl.Color(0.0f, 1.0f, 0.0f); // Green * gl.Vertex(-1.0f, -1.0f, 1.0f); // Right Of Triangle (Left) * gl.End(); // Done Drawing The Pyramid * * gl.LoadIdentity(); * gl.Translate(1.5f, 0.0f, -7.0f); // Move Right And Into The Screen * * gl.Rotate(rquad, 1.0f, 1.0f, 1.0f); // Rotate The Cube On X, Y & Z * * gl.Begin(OpenGL.GL_QUADS); // Start Drawing The Cube * * gl.Color(0.0f, 1.0f, 0.0f); // Set The Color To Green * gl.Vertex(1.0f, 1.0f, -1.0f); // Top Right Of The Quad (Top) * gl.Vertex(-1.0f, 1.0f, -1.0f); // Top Left Of The Quad (Top) * gl.Vertex(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top) * gl.Vertex(1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top) * * * gl.Color(1.0f, 0.5f, 0.0f); // Set The Color To Orange * gl.Vertex(1.0f, -1.0f, 1.0f); // Top Right Of The Quad (Bottom) * gl.Vertex(-1.0f, -1.0f, 1.0f); // Top Left Of The Quad (Bottom) * gl.Vertex(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Quad (Bottom) * gl.Vertex(1.0f, -1.0f, -1.0f); // Bottom Right Of The Quad (Bottom) * * gl.Color(1.0f, 0.0f, 0.0f); // Set The Color To Red * gl.Vertex(1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front) * gl.Vertex(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front) * gl.Vertex(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Quad (Front) * gl.Vertex(1.0f, -1.0f, 1.0f); // Bottom Right Of The Quad (Front) * * gl.Color(1.0f, 1.0f, 0.0f); // Set The Color To Yellow * gl.Vertex(1.0f, -1.0f, -1.0f); // Bottom Left Of The Quad (Back) * gl.Vertex(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Quad (Back) * gl.Vertex(-1.0f, 1.0f, -1.0f); // Top Right Of The Quad (Back) * gl.Vertex(1.0f, 1.0f, -1.0f); // Top Left Of The Quad (Back) * * gl.Color(0.0f, 0.0f, 1.0f); // Set The Color To Blue * gl.Vertex(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left) * gl.Vertex(-1.0f, 1.0f, -1.0f); // Top Left Of The Quad (Left) * gl.Vertex(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Quad (Left) * gl.Vertex(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Quad (Left) * * gl.Color(1.0f, 0.0f, 1.0f); // Set The Color To Violet * gl.Vertex(1.0f, 1.0f, -1.0f); // Top Right Of The Quad (Right) * gl.Vertex(1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right) * gl.Vertex(1.0f, -1.0f, 1.0f); // Bottom Left Of The Quad (Right) * gl.Vertex(1.0f, -1.0f, -1.0f); // Bottom Right Of The Quad (Right) * gl.End(); // Done Drawing The Q * * gl.Flush(); * * rtri += 3.0f;// 0.2f; // Increase The Rotation Variable For The Triangle * rquad -= 3.0f;// 0.15f; // Decrease The Rotation Variable For The Quad */ }
public static UDMFConverted ReadFile(List <string> file) { /*foreach(string m in file) * { * Debug.Log(m); * } * return new UDMFConverted();*/ if (file.Count > 0) { UDMFConverted dConv = new UDMFConverted(); List <VertexDef> vertices = new List <VertexDef>(); List <Sector> sectors = new List <Sector>(); List <SideDef> sideDefs = new List <SideDef>(); List <Linedef> lineDefs = new List <Linedef>(); List <Thing> things = new List <Thing>(); // CRd current= CRd.core; for (int ln = 0; ln < file.Count; ln++) { //int ePos=ln; if (Regex.IsMatch(file[ln], @"thing.*\n{", RegexOptions.IgnoreCase)) { //Debug.Log("thing:"+file[ln]); Thing tn = new Thing(); tn.FormFromList(file[ln].Split(new char[] { '\n' }, StringSplitOptions.None)); things.Add(tn); } else if (Regex.IsMatch(file[ln], @"vertex.*\n{", RegexOptions.IgnoreCase)) { //Debug.Log("vertex:"+file[ln]); VertexDef vect = new VertexDef(); vect.FormFromList(file[ln].Split(new char[] { '\n' }, StringSplitOptions.None)); //Vector2 vect = StrUtils.FormVector2FromList(file[ln].Split(new char[] { '\n' }, StringSplitOptions.None)); vertices.Add(vect); } else if (Regex.IsMatch(file[ln], @"linedef.*\n{", RegexOptions.IgnoreCase)) { //Debug.Log("linedef:"+file[ln]); Linedef ld = new Linedef(); ld.FormFromList(file[ln].Split(new char[] { '\n' }, StringSplitOptions.None)); lineDefs.Add(ld); } else if (Regex.IsMatch(file[ln], @"sidedef.*\n{", RegexOptions.IgnoreCase)) { //Debug.Log("sidedef:"+file[ln]); SideDef sd = new SideDef(); sd.FormFromList(file[ln].Split(new char[] { '\n' }, StringSplitOptions.None)); sideDefs.Add(sd); } else if (Regex.IsMatch(file[ln], @"sector.*\n{", RegexOptions.IgnoreCase)) { //Debug.Log("sector:"+file[ln]); Sector sec = new Sector(); sec.FormFromList(file[ln].Split(new char[] { '\n' }, StringSplitOptions.None)); sectors.Add(sec); } //if(ePos!=ln) ln=ePos; } dConv.things = things; dConv.vertices = vertices; dConv.sectors = sectors; dConv.sideDefs = sideDefs; dConv.lineDefs = lineDefs; return(dConv); } return(null); }