hi.
i have creat a flat earth by below code.
but it s withe.
i wan t to texture it by a bmp file.
i don t khow how i can do it.
please help me.
thanks.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Drawing;
namespace Directx1
{
class GameEngine
{
private GraphicInitiator graphicInit;
private Device device3d;
private Form1 form;
private VertexBuffer
vb;
private short[] indices;//andis ha ra neshan midahad
private IndexBuffer ib;
private int WIDTH = 100;//arz
private int HEIGHT = 100;
private int[,] heightData;//ertefa
private CustomVertex.PositionColored[] vertices;//noghat ra neshan khahad dad
private void IndicesDeclaration()
{//dar index bafeer andis haman ra set khahim kard
ib = new IndexBuffer(typeof(short), (WIDTH - 1) * (HEIGHT - 1) * 6, device3d, Usage.WriteOnly, Pool.Default);
indices = new short[(WIDTH - 1) * (HEIGHT - 1) * 6];
for (int x = 0; x < WIDTH - 1; x++)
{
for (int y = 0; y < HEIGHT - 1; y++)
{
indices[(x + y * (WIDTH - 1)) * 6] = (short)((x + 1) + (y + 1) * WIDTH);
indices[(x + y * (WIDTH - 1)) * 6 + 1] = (short)((x + 1) + y * WIDTH);
indices[(x + y * (WIDTH - 1)) * 6 + 2] = (short)(x + y * WIDTH);
indices[(x + y * (WIDTH - 1)) * 6 + 3] = (short)((x + 1) + (y + 1) * WIDTH);
indices[(x + y * (WIDTH - 1)) * 6 + 4] = (short)(x + y * WIDTH);
indices[(x + y * (WIDTH - 1)) * 6 + 5] = (short)(x + (y + 1) * WIDTH);
}
}
ib.SetData(indices, 0, LockFlags.None);
}
private void LoadHeightData()
//heath data z ra bara ma moshakhas mikonad
{
heightData = new int[WIDTH, HEIGHT];
for (int x = 0; x < WIDTH; x++)
{
for (int y = 0; y < HEIGHT; y++)
{
heightData[x ,y]=0;
heightData[x ,y]=0;
heightData[x, y] = 0;
}
}
//heightData[WIDTH / 2, HEIGHT / 2] = 5;
}
public GameEngine(Form1 Frm)
{
form = Frm;
graphicInit = new GraphicInitiator();//peykar bandi device
graphicInit.initDevice(ref device3d, form);
LoadHeightData();//hamashon sefran
VertexDeclaration();
IndicesDeclaration();
CameraPositioning();
}
public void clear()
{
device3d.Clear(ClearFlags.Target, Color.DarkSlateBlue, 1.0f, 0);
}
private void CameraPositioning()
{
device3d.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, form.Width / form.Height, 1f, 300f);
device3d.Transform.View = Matrix.LookAtLH(new Vector3(0, -50, 15), new Vector3(0, 0, 0), new Vector3(0, 0, 1));
device3d.RenderState.Lighting = false;
device3d.RenderState.CullMode = Cull.None;
}
private void VertexDeclaration()
{//be andaze tool * arze zamin noghte tarif kardim
vb = new VertexBuffer(typeof(CustomVertex.PositionColored), WIDTH*HEIGHT, device3d, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default);
vertices = new CustomVertex.PositionColored[WIDTH*HEIGHT];
for (int x=0;x< WIDTH;x++)
{
for (int y=0; y< HEIGHT;y++)
{
vertices[x+y*WIDTH].Position = new Vector3(x, y, 0);
vertices[x+y*WIDTH].Color = Color.White.ToArgb();
vertices[x + y * WIDTH].Position = new Vector3(x, y, heightData[x, y]);
}
}
vb.SetData(vertices, 0 ,LockFlags.None);
}
public void drawWorld()
{
CameraPositioning();
device3d.BeginScene();
device3d.Transform.World=Matrix.Translation(new Vector3(-50,5,-20));
device3d.VertexFormat = CustomVertex.PositionColored.Format;
device3d.SetStreamSource(0,
vb, 0);
device3d.Indices = ib;
device3d.DrawIndexedPrimitives(PrimitiveType.Trian gleList, 0, 0, WIDTH * HEIGHT, 0, indices.Length / 3);
device3d.EndScene();
device3d.Present();
}
}
}
Report to moderator