Making a world

Started by
10 comments, last by Roble 21 years, 2 months ago
Say I wanted to make a world (like in any RPG), and load it into DirectX, how would I go about doing this?
I M Teh n00B11!!!1
Advertisement
you could make a world in a 3d modelling program
and then export as a .x file
then load and render it in direct3d
How would I make the .x file load?
You would probably want to arrange it into an octree or something.
Where can I get a good 3D world making program
In the DX SDK there is built in support for .x files, Milkshape is a good program for working with models and it has a .x file exporter. In order to get it to work though, you will need to know more about directx, I suggest finding a book on it, on half.com you usually can find a good deal on used DirectX books.

Lata,
Ben
This is what it says in the DX SDK help:

<b>Loading an X File</b>

<i>Use the following procedure to load an .x file.

Use the DirectXFileCreate function to create an IDirectXFile object.

If templates are present in the Microsoft® DirectX® file that you will load, use the IDirectXFile::RegisterTemplates method to register those templates.

Use the IDirectXFile::CreateEnumObject method to create an IDirectXFileEnumObject enumerator object.

Loop through the objects in the file. For each object, perform the following steps.

Use the IDirectXFileEnumObject::GetNextDataObject method to retrieve each IDirectXFileData object.

Use the IDirectXFileData::GetType method to retrieve the data''s type.

Load the data using the IDirectXFileData::GetData method.

If the object has optional members, retrieve the optional members by calling the IDirectXFileData::GetNextObject method.

Release the IDirectXFileData object.

Release the IDirectXFileEnumObject object.

Release the IDirectXFile object. </i>

One word "?" =P anyone have any actual CODE?
// -------------------------------------------------------------
// mesh.h

class CMesh_X{protected:	IDirect3DDevice9*   m_pd3dDevice;	ID3DXMesh*          m_pMesh;	D3DMATERIAL9*       m_pMaterials;	IDirect3DTexture9** m_pTextures;	DWORD               m_dwNumMaterials;public:	CMesh_X();	~CMesh_X() { Destroy(); }	bool Create(IDirect3DDevice9* pd3dDevice, LPCTSTR pFilename);	void Destroy();	bool Render();}; 


// -------------------------------------------------------------

// -------------------------------------------------------------
// mesh.cpp

#include <d3dx9.h>#include "mesh.h"CMesh_X::CMesh_X(){	m_pd3dDevice     = NULL;	m_pMesh          = NULL;	m_pMaterials     = NULL;	m_pTextures      = NULL;	m_dwNumMaterials = 0L;}bool CMesh_X::Create(IDirect3DDevice9* pd3dDevice, LPCTSTR pFilename){	m_pd3dDevice = pd3dDevice;	ID3DXBuffer* pAdjacencyBuffer = NULL;	ID3DXBuffer* pMtrlBuffer      = NULL;	// Load the mesh from the specified file	if( FAILED( D3DXLoadMeshFromX(pFilename, D3DXMESH_SYSTEMMEM, pd3dDevice, &pAdjacencyBuffer, &pMtrlBuffer, NULL, &m_dwNumMaterials, &m_pMesh) ) )		return false;	// Allocate memory for the materials and textures	m_pMaterials = new D3DMATERIAL9[m_dwNumMaterials];	m_pTextures  = new LPDIRECT3DTEXTURE9[m_dwNumMaterials];	// Optimize the mesh	if( FAILED( m_pMesh->OptimizeInplace(D3DXMESHOPT_COMPACT|D3DXMESHOPT_ATTRSORT|D3DXMESHOPT_VERTEXCACHE, (DWORD*)pAdjacencyBuffer->GetBufferPointer(), NULL, NULL, NULL) ) )		return false;	// Get the materials and texture names from the material buffer	D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pMtrlBuffer->GetBufferPointer();	// Copy each material and create its texture	for( DWORD i=0; i<m_dwNumMaterials; i++ )	{		// Copy the material		m_pMaterials = d3dxMaterials.MatD3D;<br>		m_pTextures  = NULL;<br><br>		// Set the ambient color for the material (D3DX does not do this)<br>		m_pMaterials.Ambient = m_pMaterials.Diffuse;<br><br>		// Create texture<br>		if( d3dxMaterials.pTextureFilename != NULL &amp;&amp; lstrlen(d3dxMaterials.pTextureFilename) &gt; 0 )<br>			D3DXCreateTextureFromFile(pd3dDevice, d3dxMaterials.pTextureFilename, &amp;m_pTextures);<br>	}<br><br>	// Release the adjacency buffer<br>	if( pAdjacencyBuffer )<br>		pAdjacencyBuffer-&gt;Release();<br><br>	// Release the material buffer<br>	if( pMtrlBuffer )<br>		pMtrlBuffer-&gt;Release();<br><br>	return true;<br>}<br><br>void CMesh_X::Destroy()<br>{<br>	if( m_pMaterials )<br>	{<br>		delete[] m_pMaterials;<br>		m_pMaterials = NULL;<br>	}<br><br>	if( m_pTextures )<br>	{<br>		for( DWORD i=0; i &lt; m_dwNumMaterials; i++ )<br>		{<br>			if( m_pTextures )<br>			{<br>				m_pTextures-&gt;Release();<br>				m_pTextures = NULL;<br>			}<br>		}<br>		delete[] m_pTextures;<br>		m_pTextures = NULL;<br>	}<br><br>	if( m_pMesh )<br>	{<br>		m_pMesh-&gt;Release();<br>		m_pMesh = NULL;<br>	}<br>}<br><br>bool CMesh_X::Render()<br>{<br><br>	// Meshes are divided into subsets, &#111;ne for each material. Render them in a loop<br>	for( DWORD i=0; i&lt;m_dwNumMaterials; i++ )<br>	{<br>		// Set the material and texture for this subset<br>		m_pd3dDevice-&gt;SetMaterial(&amp;m_pMaterials);<br>		m_pd3dDevice-&gt;SetTexture(0, m_pTextures);<br>        <br>		// Draw the mesh subset<br>		m_pMesh-&gt;DrawSubset(i);<br>	}<br><br>	return true;<br>}<br> </pre>   </i>   
YOu could alsi try the Hugo Elias method of fault line simulation
I don''t know if tha will work with my SDK (DX 8.1) because that''s for DX 9 SDK? BTW, Where would I paste the name of my .x file in that code? =)
I M Teh n00B11!!!1

This topic is closed to new replies.

Advertisement