Ok, here's a question. Maybe someone can answer for me.
I am drawing a plane which will eventually be used as sky. I don't want it to be a flat plane, though, I want to 'pull' the corners down.
Here's what I'm doing to draw the sky..
C# code:
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using QuickStart;
using QuickStart.Graphics;
using QuickStart.Physics;
namespace QuickStart.Entities
{
public class SkyPlane : BaseEntity
{
public VertexBuffer VertexBuffer
{
get { return this.vertexBuffer; }
}
private VertexBuffer vertexBuffer;
public IndexBuffer IndexBuffer
{
get { return this.indexBuffer; }
}
private IndexBuffer indexBuffer;
public VertexDeclaration VertexDeclaration
{
get { return this.vertDeclaration; }
}
private VertexDeclaration vertDeclaration;
public Effect TerrainEffect
{
get { return this.terrainEffect; }
}
private Effect terrainEffect;
public Material Material
{
get { return this.material; }
}
private Material material;
private Vector3 offset;
private int squaresize = 60;
private int[] indices;
private int width = 0;
private int height = 0;
public SkyPlane(QSGame game)
: base(game)
{
this.terrainEffect = game.Content.Load<Effect>("./Effects/Terrain");
this.terrainEffect.CurrentTechnique = terrainEffect.Techniques["MultiTextured"];
this.vertDeclaration = new VertexDeclaration(this.Game.GraphicsDevice, VertexPositionTexture.VertexElements);
}
public void Initialize(Vector3 offset, float viewDistance)
{
this.width = (int) viewDistance / this.squaresize;
this.height = (int) viewDistance / this.squaresize;
this.offset = offset;
CreateVertexBuffer();
CreateIndexBuffer();
this.material = this.Game.Content.Load<Material>("Material/Terrain");
}
public void CreateVertexBuffer()
{
vertexBuffer = new VertexBuffer(this.Game.GraphicsDevice, typeof(VertexPositionTexture), width * height, BufferUsage.WriteOnly);
VertexPositionTexture[] vertices = new VertexPositionTexture[width * height];
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
vertices[x + y * width].Position = new Vector3((x * this.squaresize), 0, (y * this.squaresize)) + this.offset;
}
}
vertexBuffer.SetData(vertices);
}
public void CreateIndexBuffer()
{
int numberOfIndexes = (width - 1) * (height - 1) * 6;
indexBuffer = new IndexBuffer(this.Game.GraphicsDevice, typeof(int), numberOfIndexes, BufferUsage.WriteOnly);
int counter = 0;
indices = new int[numberOfIndexes];
for (int y = 0; y < height - 1; y++)
{
for (int x = 0; x < width - 1; x++)
{
int lowerLeft = x + y * width;
int lowerRight = (x + 1) + y * width;
int topLeft = x + (y + 1) * width;
int topRight = (x + 1) + (y + 1) * width;
indices[counter++] = topLeft;
indices[counter++] = lowerRight;
indices[counter++] = lowerLeft;
indices[counter++] = topLeft;
indices[counter++] = topRight;
indices[counter++] = lowerRight;
}
}
indexBuffer.SetData(indices);
}
public override void QueryForRenderChunks(ref RenderPassDesc desc)
{
RenderChunk chunk = this.Game.Graphics.AllocateRenderChunk();
chunk.Indices = indexBuffer;
chunk.VertexStreams.Add(vertexBuffer);
chunk.Declaration = vertDeclaration;
chunk.WorldTransform = Matrix.Identity;
chunk.VertexCount = width * height;
chunk.StartIndex = 0;
chunk.VertexStreamOffset = 0;
chunk.PrimitiveCount = indices.Length / 3;
chunk.Material = this.material;
chunk.Type = PrimitiveType.TriangleList;
base.QueryForRenderChunks(ref desc);
}
}
}
Note that QueryForRenderChunks if what the framework calls repeatedly to get a "chunk" to send to the graphics card.
So, this draws me a grid from the vector 'offset' to 'viewDistance' and the size of each square is viewDistance/sqaresize.
How could I pull the corners of the plane down? :/ |