public void drawCollisionMap(bool drawAsBlack) { GL.PushMatrix(); GL.EnableClientState(ArrayCap.VertexArray); if (drawAsBlack) // Used as part of color picking { GL.BlendFunc(BlendingFactorSrc.Zero, BlendingFactorDest.Zero); } for (int i = 0; i < triangles.Count; i++) { CollisionTriangleList l = triangles[i]; //if (m.vertices == null || m.indices == null) return; GL.BindTexture(TextureTarget.Texture2D, l.texture.ID); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo); GL.VertexPointer(3, VertexPointerType.Float, 0, IntPtr.Zero); if (Globals.doWireframe) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); } else { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); } GL.BindBuffer(BufferTarget.ElementArrayBuffer, l.ibo); GL.DrawElements(BeginMode.Triangles, l.indices.Length, DrawElementsType.UnsignedInt, IntPtr.Zero); if (Globals.doWireframe) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); } } if (drawAsBlack) { GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); } GL.DisableClientState(ArrayCap.VertexArray); GL.PopMatrix(); if (!drawAsBlack && !Globals.doWireframe) { drawCollisionMapOutline(); } }
public short dropToGround(Vector3 pos) { List <float> found = new List <float>(); for (int i = 0; i < triangles.Count; i++) { CollisionTriangleList list = triangles[i]; for (int j = 0; j < list.indices.Length; j += 3) { tempTriangle temp; temp.a = new Vector3(vertices[(int)list.indices[j + 0]]); temp.b = new Vector3(vertices[(int)list.indices[j + 1]]); temp.c = new Vector3(vertices[(int)list.indices[j + 2]]); if (PointInTriangle(pos.Xz(), temp.a.Xz(), temp.b.Xz(), temp.c.Xz())) { found.Add(barryCentric(temp.a, temp.b, temp.c, pos)); } } } if (found.Count == 0) { return((short)pos.Y); } float highestY = -0x2000; // Console.WriteLine("Found " + found.Count + " triangles under position"); for (int i = 0; i < found.Count; i++) { if (found[i] > highestY) { highestY = found[i]; } } return((short)highestY); }