Esempio n. 1
0
 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);
         GL.BindBuffer(BufferTarget.ElementArrayBuffer, l.ibo);
         if (!Globals.doWireframe)
         {
             GL.DrawElements(PrimitiveType.Triangles, l.indices.Length,
                             DrawElementsType.UnsignedInt, IntPtr.Zero);
         }
         else
         {
             GL.DrawElements(PrimitiveType.Lines, l.indices.Length,
                             DrawElementsType.UnsignedInt, IntPtr.Zero);
         }
     }
     if (drawAsBlack)
     {
         GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
     }
     GL.DisableClientState(ArrayCap.VertexArray);
     GL.PopMatrix();
 }
Esempio n. 2
0
        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;
                    int          index1      = (int)list.indices[j + 0];
                    int          index2      = (int)list.indices[j + 1];
                    int          index3      = (int)list.indices[j + 2];
                    int          numVertices = vertices.Count;
                    if (index1 >= numVertices || index2 >= numVertices || index3 >= numVertices)
                    {
                        continue;
                    }
                    temp.a = new Vector3(vertices[index1]);
                    temp.b = new Vector3(vertices[index2]);
                    temp.c = new Vector3(vertices[index3]);
                    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);
            }

            int   closest_index = 0;
            float closest_abs   = 9999999.0f;

            // Console.WriteLine("Found " + found.Count + " triangles under position");
            for (int i = 0; i < found.Count; i++)
            {
                float abs = Math.Abs(pos.Y - found[i]);
                if (abs < closest_abs)
                {
                    closest_abs   = abs;
                    closest_index = i;
                }
            }
            return((short)found[closest_index]);
        }
Esempio n. 3
0
 public void drawCollisionMapOutline()
 {
     GL.PushMatrix();
     GL.EnableClientState(ArrayCap.VertexArray);
     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);
         GL.BindBuffer(BufferTarget.ElementArrayBuffer, l.ibo);
         GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
         GL.BindBuffer(BufferTarget.ElementArrayBuffer, l.ibo);
         GL.DrawElements(PrimitiveType.Triangles, l.indices.Length,
                         DrawElementsType.UnsignedInt, IntPtr.Zero);
         GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
     }
     GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
     GL.DisableClientState(ArrayCap.VertexArray);
     GL.PopMatrix();
 }
Esempio n. 4
0
        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);
        }