コード例 #1
0
ファイル: Sphere.cs プロジェクト: greencoredesign/Arrival
        public static Sphere CreateNormalTextured(GraphicsDevice device, int slices, int stacks)
        {
            var vpnt = new VertexPositionNormalTexture[(slices + 1) * (stacks + 1)];
            float phi, theta;
            float dphi = MathHelper.Pi / stacks;
            float dtheta = MathHelper.TwoPi / slices;
            float x, y, z, sc;
            int index = 0;
            for (int stack = 0; stack <= stacks; stack++)
            {
                phi = MathHelper.PiOver2 - stack * dphi;
                y = (float)Math.Sin(phi);
                sc = -(float)Math.Cos(phi);
                for (int slice = 0; slice <= slices; slice++)
                {
                    theta = slice * dtheta;
                    x = sc * (float)Math.Sin(theta);
                    z = sc * (float)Math.Cos(theta);
                    vpnt[index++] = new VertexPositionNormalTexture(new Vector3(x, y, z), new Vector3(x, y, z),
                        new Vector2((float)slice / (float)slices, (float)stack / (float)stacks));
                }
            }
            var indices = new ushort[slices * stacks * 6];
            index = 0;
            int k = slices + 1;
            for (int stack = 0; stack < stacks; stack++)
            {
                for (int slice = 0; slice < slices; slice++)
                {
                    indices[index++] = (ushort)((stack + 0) * k + slice);
                    indices[index++] = (ushort)((stack + 1) * k + slice);
                    indices[index++] = (ushort)((stack + 0) * k + slice + 1);
                    indices[index++] = (ushort)((stack + 0) * k + slice + 1);
                    indices[index++] = (ushort)((stack + 1) * k + slice);
                    indices[index++] = (ushort)((stack + 1) * k + slice + 1);
                }
            }

            var ret = new Sphere();
            ret.vertexBuffer = new VertexBuffer(device, VertexPositionNormalTexture.VertexDeclaration, vpnt.Length, BufferUsage.WriteOnly);
            ret.vertexBuffer.SetData(vpnt);
            ret.indexBuffer = new IndexBuffer(device, IndexElementSize.SixteenBits, indices.Length, BufferUsage.WriteOnly);
            ret.indexBuffer.SetData(indices);
            ret.effect = new BasicEffect(device);
            ret.effect.TextureEnabled = true;
            return ret;
        }
コード例 #2
0
ファイル: Sky.cs プロジェクト: greencoredesign/Arrival
 public Sky(GraphicsDevice device, Texture2D tex)
 {
     model = Sphere.CreateNormalTextured(device, 20, 20);
     model.effect.Texture = tex;
 }