コード例 #1
0
ファイル: SphereBuilder.cs プロジェクト: geoffreylhart/Zenith
        internal static VertexIndiceBuffer MakeSphereSegExplicit(GraphicsDevice graphicsDevice, ISector root, double diameter, double minX, double minY, double maxX, double maxY, EditorCamera camera)
        {
            Vector3d cameraVector = new LongLat(camera.cameraRotX, camera.cameraRotY).ToSphereVector(); // TODO: this is hacky

            VertexIndiceBuffer buffer = new VertexIndiceBuffer();
            List <VertexPositionNormalTexture> vertices = new List <VertexPositionNormalTexture>();

            double radius             = diameter / 2;
            int    verticalSegments   = Math.Max((int)((maxY - minY) * 50), 1);
            int    horizontalSegments = Math.Max((int)((maxX - minX) * 50), 1);

            for (int i = 0; i <= verticalSegments; i++)
            {
                double y = (minY + (maxY - minY) * i / (double)verticalSegments);
                for (int j = 0; j <= horizontalSegments; j++)
                {
                    double x = (minX + (maxX - minX) * j / (double)horizontalSegments);

                    double tx = j / (double)horizontalSegments;
                    double ty = i / (double)verticalSegments;
                    // stole this equation
                    Vector3d normal     = root.ProjectToSphereCoordinates(new Vector2d(x, y));
                    Vector3d position   = normal * (float)radius; // switched dy and dz here to align the poles from how we had them
                    Vector2d texturepos = new Vector2d((float)tx, (float)ty);
                    vertices.Add(new VertexPositionNormalTexture((position - cameraVector).ToVector3(), normal.ToVector3(), texturepos));
                }
            }
            List <int> indices = MakeIndices(horizontalSegments, verticalSegments);

            buffer.vertices = new VertexBuffer(graphicsDevice, VertexPositionNormalTexture.VertexDeclaration, vertices.Count, BufferUsage.WriteOnly);
            buffer.vertices.SetData(vertices.ToArray());
            buffer.indices = new IndexBuffer(graphicsDevice, IndexElementSize.ThirtyTwoBits, indices.Count, BufferUsage.WriteOnly);
            buffer.indices.SetData(indices.ToArray());
            return(buffer);
        }
コード例 #2
0
        internal static VertexIndiceBuffer MakeBasicCube(GraphicsDevice graphicsDevice, Vector3 corner, Vector3 offx, Vector3 offy, Vector3 offz)
        {
            VertexIndiceBuffer buffer = new VertexIndiceBuffer();
            List <VertexPositionNormalTexture> vertices = new List <VertexPositionNormalTexture>();
            List <int> indices = new List <int>();
            Vector3    corner2 = corner + offx + offy + offz;

            AddQuad(vertices, indices, corner, offz, offx);    // front
            AddQuad(vertices, indices, corner, offy, offz);    // left
            AddQuad(vertices, indices, corner, offx, offy);    // bottom
            // clearly reverse the direction and rotationness to do the opposite corner
            AddQuad(vertices, indices, corner2, -offx, -offz); // back
            AddQuad(vertices, indices, corner2, -offz, -offy); // right
            AddQuad(vertices, indices, corner2, -offy, -offx); // top
            // TODO: change back to BufferUsage.WriteOnly if applicable
            buffer.vertices = new VertexBuffer(graphicsDevice, VertexPositionNormalTexture.VertexDeclaration, vertices.Count, BufferUsage.None);
            buffer.vertices.SetData(vertices.ToArray());
            buffer.indices = new IndexBuffer(graphicsDevice, IndexElementSize.ThirtyTwoBits, indices.Count, BufferUsage.None);
            buffer.indices.SetData(indices.ToArray());
            return(buffer);
        }