Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I want to make a game that has spheres going around the screen. They will be moving only horizontal and vertical but I'm thinking it might look better if they were 3D spheres.

 

I also have anothere question how do we use meshes and .X files?

Posted

Code to load and draw a DirectX .X model

 

The following code is from book source MDX Kick Start to load a .X mesh file:

 

======================================

private void LoadMesh(string file)

{

ExtendedMaterial[] mtrl;

 

// Load our mesh

mesh = Mesh.FromFile(file, MeshFlags.Managed, device, out mtrl);

 

// If we have any materials, store them

if ((mtrl != null) && (mtrl.Length > 0))

{

meshMaterials = new Material[mtrl.Length];

meshTextures = new Texture[mtrl.Length];

 

// Store each material and texture

for (int i = 0; i < mtrl.Length; i++)

{

meshMaterials = mtrl.Material3D;

if ((mtrl.TextureFilename != null) && (mtrl.TextureFilename != string.Empty))

{

// We have a texture, try to load it

meshTextures = TextureLoader.FromFile(device, @"..\..\" + mtrl.TextureFilename);

}

}

}

}

============================================

 

You also need to have declared the following:

 

Mesh mesh = null;

Material[] meshMaterials;

Texture[] meshTextures;

 

The 'mesh' can be drawn using the following code:

 

============================================

for (int i = 0; i < meshMaterials.Length; i++)

{

device.Material = meshMaterials;

device.SetTexture(0, meshTextures);

mesh.DrawSubset(i);

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...