コード例 #1
0
        public static void SphereTextured(double r, int lats, int longs, Vector3 center)
        {
            for (var i = 0; i <= lats; i++)
            {
                double lat0 = Math.PI * (-0.5 + (double)(i - 1) / lats);
                double z0   = r * Math.Sin(lat0);
                double zr0  = r * Math.Cos(lat0);

                double lat1 = Math.PI * (-0.5 + (double)i / lats);
                double z1   = r * Math.Sin(lat1);
                double zr1  = r * Math.Cos(lat1);

                using (GLDraw.Begin(BeginMode.Quads))
                {
                    for (var j = 0; j <= longs; j++)
                    {
                        double lng = 2 * Math.PI * (double)(j - 1) / longs;
                        double x   = Math.Cos(lng);
                        double y   = Math.Sin(lng);

                        GL.TexCoord2((i * 2f) / (lats * 2 + 2), (j * 2f) / (longs * 2 + 2));
                        GL.Normal3(x * zr0, y * zr0, z0);
                        GL.Vertex3(x * zr0 + center.X, y * zr0 + center.Y, z0 + center.Z);
                        GL.TexCoord2((i * 2f + 1) / (lats * 2 + 2), (j * 2f) / (longs * 2 + 2));
                        GL.Normal3(x * zr1, y * zr1, z1);
                        GL.Vertex3(x * zr1 + center.X, y * zr1 + center.Y, z1 + center.Z);
                    }
                }
            }
        }
コード例 #2
0
        public static void Sphere(double r, int lats, int longs, Vector3 center)
        {
            int i, j;

            for (i = 0; i <= lats; i++)
            {
                double lat0 = Math.PI * (-0.5 + (double)(i - 1) / lats);
                double z0   = r * Math.Sin(lat0);
                double zr0  = r * Math.Cos(lat0);

                double lat1 = Math.PI * (-0.5 + (double)i / lats);
                double z1   = r * Math.Sin(lat1);
                double zr1  = r * Math.Cos(lat1);

                using (GLDraw.Begin(BeginMode.QuadStrip))
                {
                    for (j = 0; j <= longs; j++)
                    {
                        double lng = 2 * Math.PI * (double)(j - 1) / longs;
                        double x   = Math.Cos(lng);
                        double y   = Math.Sin(lng);

                        GL.Normal3(x * zr0, y * zr0, z0);
                        GL.Vertex3(x * zr0 + center.X, y * zr0 + center.Y, z0 + center.Z);
                        GL.Normal3(x * zr1, y * zr1, z1);
                        GL.Vertex3(x * zr1 + center.X, y * zr1 + center.Y, z1 + center.Z);
                    }
                }
            }
        }
コード例 #3
0
 public static void Plane(double width_2, double height_2)
 {
     using (GLDraw.Begin(BeginMode.Quads))
     {
         // front face
         GL.Normal3(0, 0, 1);
         GL.TexCoord2(1, 0); GL.Vertex3(width_2, height_2, 0);
         GL.TexCoord2(1, 1); GL.Vertex3(width_2, -height_2, 0);
         GL.TexCoord2(0, 1); GL.Vertex3(-width_2, -height_2, 0);
         GL.TexCoord2(0, 0); GL.Vertex3(-width_2, height_2, 0);
     }
 }
コード例 #4
0
        public static void Plane(double width_2, double height_2, double textureStretch)
        {
            float t = (float)textureStretch;

            using (GLDraw.Begin(BeginMode.Quads))
            {
                // front face
                GL.Normal3(0, 0, 1);
                GL.TexCoord2(1 + t, 1 + t); GL.Vertex3(width_2, height_2, 0);
                GL.TexCoord2(1 + t, -t); GL.Vertex3(width_2, -height_2, 0);
                GL.TexCoord2(-t, -t); GL.Vertex3(-width_2, -height_2, 0);
                GL.TexCoord2(-t, 1 + t); GL.Vertex3(-width_2, height_2, 0);
            }
        }
コード例 #5
0
        public static void Cube(float x1, float y1, float z1, float x2, float y2, float z2)
        {
            using (GLDraw.Begin(BeginMode.Quads))
            {
                GLHelpers.Color4(Colors.Silver);
                GL.Vertex3(x1, y1, z1);
                GL.Vertex3(x1, y2, z1);
                GL.Vertex3(x2, y2, z1);
                GL.Vertex3(x2, y1, z1);

                GLHelpers.Color4(Colors.Honeydew);
                GL.Vertex3(x1, y1, z1);
                GL.Vertex3(x2, y1, z1);
                GL.Vertex3(x2, y1, z2);
                GL.Vertex3(x1, y1, z2);

                GLHelpers.Color4(Colors.Moccasin);
                GL.Vertex3(x1, y1, z1);
                GL.Vertex3(x1, y1, z2);
                GL.Vertex3(x1, y2, z2);
                GL.Vertex3(x1, y2, z1);

                GLHelpers.Color4(Colors.SkyBlue);
                GL.Vertex3(x1, y1, z2);
                GL.Vertex3(x2, y1, z2);
                GL.Vertex3(x2, y2, z2);
                GL.Vertex3(x1, y2, z2);

                GLHelpers.Color4(Colors.PaleVioletRed);
                GL.Vertex3(x1, y2, z1);
                GL.Vertex3(x1, y2, z2);
                GL.Vertex3(x2, y2, z2);
                GL.Vertex3(x2, y2, z1);

                GLHelpers.Color4(Colors.ForestGreen);
                GL.Vertex3(x2, y1, z1);
                GL.Vertex3(x2, y2, z1);
                GL.Vertex3(x2, y2, z2);
                GL.Vertex3(x2, y1, z2);
            }
        }
コード例 #6
0
        /// <summary>Make a cube with normals and 2D texture coordinates</summary>
        /// <param name="width"></param>
        public static void Cube2D(double width)
        {
            var w = width / 2;

            using (GLDraw.Begin(BeginMode.Quads))
            {
                // back face
                GL.Normal3(0, 0, -w); GL.TexCoord2(1, 1); GL.Vertex3(w, w, -w);
                GL.Normal3(0, 0, -w); GL.TexCoord2(1, 0); GL.Vertex3(w, -w, -w);
                GL.Normal3(0, 0, -w); GL.TexCoord2(0, 0); GL.Vertex3(-w, -w, -w);
                GL.Normal3(0, 0, -w); GL.TexCoord2(0, 1); GL.Vertex3(-w, w, -w);
                // bottom face
                GL.Normal3(0, -w, 0); GL.TexCoord2(1, 1); GL.Vertex3(w, -w, w);
                GL.Normal3(0, -w, 0); GL.TexCoord2(1, 0); GL.Vertex3(-w, -w, w);
                GL.Normal3(0, -w, 0); GL.TexCoord2(0, 0); GL.Vertex3(-w, -w, -w);
                GL.Normal3(0, -w, 0); GL.TexCoord2(0, 1); GL.Vertex3(w, -w, -w);
                // top face
                GL.Normal3(0, w, 0); GL.TexCoord2(1, 1); GL.Vertex3(w, w, w);
                GL.Normal3(0, w, 0); GL.TexCoord2(1, 0); GL.Vertex3(-w, w, w);
                GL.Normal3(0, w, 0); GL.TexCoord2(0, 0); GL.Vertex3(-w, w, -w);
                GL.Normal3(0, w, 0); GL.TexCoord2(0, 1); GL.Vertex3(w, w, -w);
                // left face
                GL.Normal3(-w, 0, 0); GL.TexCoord2(1, 1); GL.Vertex3(-w, w, w);
                GL.Normal3(-w, 0, 0); GL.TexCoord2(1, 0); GL.Vertex3(-w, w, -w);
                GL.Normal3(-w, 0, 0); GL.TexCoord2(0, 0); GL.Vertex3(-w, -w, -w);
                GL.Normal3(-w, 0, 0); GL.TexCoord2(0, 1); GL.Vertex3(-w, -w, w);
                // right face
                GL.Normal3(w, 0, 0); GL.TexCoord2(1, 1); GL.Vertex3(w, w, w);
                GL.Normal3(w, 0, 0); GL.TexCoord2(1, 0); GL.Vertex3(w, w, -w);
                GL.Normal3(w, 0, 0); GL.TexCoord2(0, 0); GL.Vertex3(w, -w, -w);
                GL.Normal3(w, 0, 0); GL.TexCoord2(0, 1); GL.Vertex3(w, -w, w);
                // front face
                GL.Normal3(0, 0, w); GL.TexCoord2(1, 1); GL.Vertex3(w, w, w);
                GL.Normal3(0, 0, w); GL.TexCoord2(1, 0); GL.Vertex3(w, -w, w);
                GL.Normal3(0, 0, w); GL.TexCoord2(0, 0); GL.Vertex3(-w, -w, w);
                GL.Normal3(0, 0, w); GL.TexCoord2(0, 1); GL.Vertex3(-w, w, w);
            }
        }
コード例 #7
0
        public static void PlaneMesh(float width, float height, int meshSize, float z)
        {
            float x  = -width;
            float y  = height;
            float dX = width * 2f / meshSize;
            float dY = -height * 2f / meshSize;

            GL.Normal3(0, 0, 1);
            for (int i = 0; i < meshSize; i++)
            {
                y = height;
                using (GLDraw.Begin(BeginMode.QuadStrip))
                {
                    for (int j = 0; j < meshSize + 1; j++)
                    {
                        GL.TexCoord2(i / (float)meshSize, j / (float)meshSize); GL.Vertex3(x, y, z);
                        GL.TexCoord2((i + 1) / (float)meshSize, j / (float)meshSize); GL.Vertex3(x + dX, y, z);
                        y += dY;
                    }
                }
                x += dX;
            }
        }