Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

stereotypical

import multiple xfile?not sure?

This topic is 5221 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi i know how to load one xfile but im not so sure how to load multiple xfiles............. im not so sure how to do it. can someone explain to me how to do it? i have my codes below showing how i imported an xfile. please take a look thanks


#include "d3dUtility.h"
#include <vector>
#include "camera.h"

//

// Globals

//


IDirect3DDevice9* Device = 0; 

const int Width  = 640;
const int Height = 480;

Camera TheCamera(Camera::LANDOBJECT);

ID3DXMesh*                      Mesh = 0;
std::vector<D3DMATERIAL9>       Mtrls(0);
std::vector<IDirect3DTexture9*> Textures(0);

//

// Framework functions

//

bool Setup()
{
	HRESULT hr = 0;

	//

	// Load the XFile data.

	//


	ID3DXBuffer* adjBuffer  = 0;
	ID3DXBuffer* mtrlBuffer = 0;
	DWORD        numMtrls   = 0;

	hr = D3DXLoadMeshFromX(  
		"arcade.x",
		D3DXMESH_MANAGED,
		Device,
		&adjBuffer,
		&mtrlBuffer,
		0,
		&numMtrls,
		&Mesh);

	if(FAILED(hr))
	{
		::MessageBox(0, "D3DXLoadMeshFromX() - FAILED", 0, 0);
		return false;
	}

	//

	// Extract the materials, and load textures.

	//


	if( mtrlBuffer != 0 && numMtrls != 0 )
	{
		D3DXMATERIAL* mtrls = (D3DXMATERIAL*)mtrlBuffer->GetBufferPointer();

		for(int i = 0; i < numMtrls; i++)
		{
			// the MatD3D property doesn''t have an ambient value set

			// when its loaded, so set it now:

			mtrls[i].MatD3D.Ambient = mtrls[i].MatD3D.Diffuse;

			// save the ith material

			Mtrls.push_back( mtrls[i].MatD3D );

			// check if the ith material has an associative texture

			if( mtrls[i].pTextureFilename != 0 )
			{
				// yes, load the texture for the ith subset

				IDirect3DTexture9* tex = 0;
				D3DXCreateTextureFromFile(
					Device,
					mtrls[i].pTextureFilename,
					&tex);

				// save the loaded texture

				Textures.push_back( tex );
			}
			else
			{
				// no texture for the ith subset

				Textures.push_back( 0 );
			}
		}
	}
	d3d::Release<ID3DXBuffer*>(mtrlBuffer); // done w/ buffer


	//

	// Optimize the mesh.

	//


	hr = Mesh->OptimizeInplace(		
		D3DXMESHOPT_ATTRSORT |
		D3DXMESHOPT_COMPACT  |
		D3DXMESHOPT_VERTEXCACHE,
		(DWORD*)adjBuffer->GetBufferPointer(),
		0, 0, 0);

	d3d::Release<ID3DXBuffer*>(adjBuffer); // done w/ buffer


	if(FAILED(hr))
	{
		::MessageBox(0, "OptimizeInplace() - FAILED", 0, 0);
		return false;
	}

	//

	// Set texture filters.

	//


	Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);

	// 

	// Set Lights.

	//


	D3DXVECTOR3 dir(1.0f, -1.0f, 1.0f);
	D3DXCOLOR col(1.0f, 1.0f, 1.0f, 1.0f);
	D3DLIGHT9 light = d3d::InitDirectionalLight(&dir, &col);

	Device->SetLight(0, &light);
	Device->LightEnable(0, true);
	Device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
	Device->SetRenderState(D3DRS_SPECULARENABLE, true);

	//

	// Set camera.

	//


	D3DXVECTOR3 pos(4.0f, 4.0f, -13.0f);
	D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);

	D3DXMATRIX V;
	D3DXMatrixLookAtLH(
		&V,
		&pos,
		&target,
		&up);

	Device->SetTransform(D3DTS_VIEW, &V);

	//

	// Set projection matrix.

	//


	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(
			&proj,
			D3DX_PI * 0.5f, // 90 - degree

			(float)Width / (float)Height,
			1.0f,
			1000.0f);
	Device->SetTransform(D3DTS_PROJECTION, &proj);

	return true;
}

void Cleanup()
{
	d3d::Release<ID3DXMesh*>(Mesh);

	for(int i = 0; i < Textures.size(); i++)
		d3d::Release<IDirect3DTexture9*>( Textures[i] );
}

bool Display(float timeDelta)
{
	if( Device )
	{

  // Update: Update the camera.

		//


		if( ::GetAsyncKeyState(''W'') & 0x8000f )
			TheCamera.walk(4.0f * timeDelta);

		if( ::GetAsyncKeyState(''S'') & 0x8000f )
			TheCamera.walk(-4.0f * timeDelta);

		if( ::GetAsyncKeyState(''A'') & 0x8000f )
			TheCamera.strafe(-4.0f * timeDelta);

		if( ::GetAsyncKeyState(''D'') & 0x8000f )
			TheCamera.strafe(4.0f * timeDelta);

		if( ::GetAsyncKeyState(''R'') & 0x8000f )
			TheCamera.fly(4.0f * timeDelta);

		if( ::GetAsyncKeyState(''F'') & 0x8000f )
			TheCamera.fly(-4.0f * timeDelta);

		if( ::GetAsyncKeyState(VK_UP) & 0x8000f )
			TheCamera.pitch(1.0f * timeDelta);

		if( ::GetAsyncKeyState(VK_DOWN) & 0x8000f )
			TheCamera.pitch(-1.0f * timeDelta);

		if( ::GetAsyncKeyState(VK_LEFT) & 0x8000f )
			TheCamera.yaw(-1.0f * timeDelta);
			
		if( ::GetAsyncKeyState(VK_RIGHT) & 0x8000f )
			TheCamera.yaw(1.0f * timeDelta);

		if( ::GetAsyncKeyState(''N'') & 0x8000f )
			TheCamera.roll(1.0f * timeDelta);

		if( ::GetAsyncKeyState(''M'') & 0x8000f )
			TheCamera.roll(-1.0f * timeDelta);


				// Update the view matrix representing the cameras 

        // new position/orientation.

		D3DXMATRIX V;
		TheCamera.getViewMatrix(&V);
		Device->SetTransform(D3DTS_VIEW, &V);
		//

		// Render

		//


		Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
		Device->BeginScene();

		for(int i = 0; i < Mtrls.size(); i++)
		{
			Device->SetMaterial( &Mtrls[i] );
			Device->SetTexture(0, Textures[i]);
			Mesh->DrawSubset(i);
		}	

		Device->EndScene();
		Device->Present(0, 0, 0, 0);
	}
	return true;
}

//

// WndProc

//

LRESULT CALLBACK d3d::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch( msg )
	{
	case WM_DESTROY:
		::PostQuitMessage(0);
		break;
		
	case WM_KEYDOWN:
		if( wParam == VK_ESCAPE )
			::DestroyWindow(hwnd);
		break;
	}
	return ::DefWindowProc(hwnd, msg, wParam, lParam);
}

//

// WinMain

//

int WINAPI WinMain(HINSTANCE hinstance,
				   HINSTANCE prevInstance, 
				   PSTR cmdLine,
				   int showCmd)
{
	if(!d3d::InitD3D(hinstance,
		Width, Height, true, D3DDEVTYPE_HAL, &Device))
	{
		::MessageBox(0, "InitD3D() - FAILED", 0, 0);
		return 0;
	}
		
	if(!Setup())
	{
		::MessageBox(0, "Setup() - FAILED", 0, 0);
		return 0;
	}

	d3d::EnterMsgLoop( Display );

	Cleanup();

	Device->Release();

	return 0;
}

Share this post


Link to post
Share on other sites
Advertisement
i used milkshape3d to model the objects and converted it to an xfile............. some of my xfiles display properly but some just fails to load....... ive checked everything no errors....nothing is wrong the textures i used are also very small.....y is it that some xfiles display but some fail to load once i execute??



Share this post


Link to post
Share on other sites
It looks fine to me, does it show you what part of the loading failed or it just don´t show anything, if that is the case, are you shure that all models are the same scale? with the same code some models load and others don´t?

for the multiple models question, you need a ID3DXMesh for each different model you want, and need to load it just the same way you did with the first one.

Share this post


Link to post
Share on other sites
my setup() fails it gives me back "D3DXLoadMeshFromX() - FAILED" thats how i know its from the setup().......but wat bugs me is i tried different xfiles with different sizes and shapes and textures but only some of it works i cant seem to figure out y some doesnt work. i dont think it has something to do with the sizes of the shape or the xfile cuz i tried different types of xfiles that were of the similar size and some works but some just fails to load? y? is it somethin to do with my buffer setting or somethin?

Share this post


Link to post
Share on other sites
all i want to do is create a house and move around it.........it doesnt matter if theres no collision detection....i just want my house with all the stuff in it to appear! y is this so difficult?? i exported my house and all the items in it like the table, chair...etc together as one big xfile. then i also separated all the items and the house all as one xfiles each. it fails load the house with all the items xfile for god knows what reason.....but if i load the separate xfile like the table only........then it shows! why is this happening?

i dont know what is wrong with it i checked the xfiles and everything is there ......the textures are all in my working folder!

can someone please pleaseeeeeeee help me.......... i need to hand this assignment in by friday.
im getting desperate and i dont have much reference on xfiles..............

can someone out there please help me out??

Share this post


Link to post
Share on other sites
Since your code is the straight rip from some samplecode, cant remember which book, it is not very suited for loading several xfiles at the time. If you want to handle it like that, you need a datatype for each mesh that holds a reference to textures and materials mapped to its subsets. As it is now, it can really only hold one xfile.

Example:
struct MeshThing
{
Mesh*;
materials m[10];
textures t[10];
}

Then you have a list or something of the above, with one entry per xfile.

To draw it, loop trough the list, and for each entry do:
// drawing
for(i++)
{
settexture(mesh->t);
setmaterial(mesh->m[i]);
mesh->drawsubset(i);
}

Share this post


Link to post
Share on other sites
thanks a lot........ i used an ebook beginning of direct9 games programming...... im running out of time thats y im just trying out the codes and changing it so i wont waste too much time but now its getting difficult..... i dun have any resources elsewhere that shows me how to import multiple xfiles......if you have any maybe i could learn from there so i wont bug u guys anymore.

im xtremely new at this and im new to c++.....please bare with me i wont bug you guys anymore after this......just need to import multiple files then im done! time is not on my side......
i tried what u said but im not sure i did it the properly i dont know what else to change........... maybe u guys could take a look at my files and see where i should change it??

this is my main file called xfile.cpp



#include "d3dUtility.h"
#include <vector>
#include "camera.h"
#include <d3dx9mesh.h>

//

// Globals

//


IDirect3DDevice9* Device = 0;

const int Width = 1024;
const int Height = 800;

Camera TheCamera(Camera::LANDOBJECT);
/*
ID3DXMesh* Mesh = 0;
std::vector<D3DMATERIAL9> Mtrls(0);
std::vector<IDirect3DTexture9*> Textures(0);
*/

struct ID3DXMesh
{
Mesh*;
mtrls m[10];
Textures t[10];
}

// Framework functions

//

bool Setup()
{
HRESULT hr = 0,hr2 = 0;

//

// Load the XFile data.

//


ID3DXBuffer* adjBuffer = 0;
ID3DXBuffer* mtrlBuffer = 0;
DWORD numMtrls = 0;

hr = D3DXLoadMeshFromX(
"pls2.x",
D3DXMESH_MANAGED,
Device,
&adjBuffer,
&mtrlBuffer,
0,
&numMtrls,
&Mesh);

if(FAILED(hr))
{
::MessageBox(0, "D3DXLoadMeshFromX() - FAILED", 0, 0);
return false;
}

//

// Extract the materials, and load textures.

//


if( mtrlBuffer != 0 && numMtrls != 0 )
{
D3DXMATERIAL* mtrls = (D3DXMATERIAL*)mtrlBuffer->GetBufferPointer();

for(int i = 0; i < numMtrls; i++)
{
// the MatD3D property doesn''t have an ambient value set

// when its loaded, so set it now:

mtrls[i].MatD3D.Ambient = mtrls[i].MatD3D.Diffuse;

// save the ith material

Mtrls.push_back( mtrls[i].MatD3D );

// check if the ith material has an associative texture

if( mtrls[i].pTextureFilename != 0 )
{
// yes, load the texture for the ith subset

IDirect3DTexture9* tex = 0;
D3DXCreateTextureFromFile(
Device,
mtrls[i].pTextureFilename,
&tex);

// save the loaded texture

Textures.push_back( tex );
}
else
{
// no texture for the ith subset

Textures.push_back( 0 );
}


}
}
d3d::Release<ID3DXBuffer*>(mtrlBuffer); // done w/ buffer


//

// Optimize the mesh.

//


hr = Mesh->OptimizeInplace(
D3DXMESHOPT_ATTRSORT |
D3DXMESHOPT_COMPACT |
D3DXMESHOPT_VERTEXCACHE,
(DWORD*)adjBuffer->GetBufferPointer(),
0, 0, 0);

d3d::Release<ID3DXBuffer*>(adjBuffer); // done w/ buffer


if(FAILED(hr))
{
::MessageBox(0, "OptimizeInplace() - FAILED", 0, 0);
return false;
}
//

// Set texture filters.

//


Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);

//

// Set Lights.

//


D3DXVECTOR3 dir(1.0f, -1.0f, 1.0f);
D3DXCOLOR col(1.0f, 1.0f, 1.0f, 1.0f);
D3DLIGHT9 light = d3d::InitDirectionalLight(&dir, &col);

Device->SetLight(0, &light);
Device->LightEnable(0, true);
Device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
Device->SetRenderState(D3DRS_SPECULARENABLE, true);
// Set camera.

//


D3DXVECTOR3 pos(4.0f, 4.0f, -13.0f);
D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);

D3DXMATRIX V;
D3DXMatrixLookAtLH(
&V,
&pos,
&target,
&up);

Device->SetTransform(D3DTS_VIEW, &V);

//

// Set projection matrix.

//


D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(
&proj,
D3DX_PI * 0.5f, // 90 - degree

(float)Width / (float)Height,
1.0f,
1000.0f);
Device->SetTransform(D3DTS_PROJECTION, &proj);

return true;


}

void Cleanup()
{
d3d::Release<ID3DXMesh*>(Mesh);

for(int i = 0; i < Textures.size(); i++)
d3d::Release<IDirect3DTexture9*>( Textures[i] );

}

bool Display(float timeDelta)
{
if( Device )
{


// Update: Update the camera.

//


if( ::GetAsyncKeyState(''W'') & 0x8000f )
TheCamera.walk(40.0f * timeDelta);

if( ::GetAsyncKeyState(''S'') & 0x8000f )
TheCamera.walk(-40.0f * timeDelta);

if( ::GetAsyncKeyState(''A'') & 0x8000f )
TheCamera.strafe(-40.0f * timeDelta);

if( ::GetAsyncKeyState(''D'') & 0x8000f )
TheCamera.strafe(40.0f * timeDelta);

if( ::GetAsyncKeyState(''R'') & 0x8000f )
TheCamera.fly(40.0f * timeDelta);

if( ::GetAsyncKeyState(''F'') & 0x8000f )
TheCamera.fly(-40.0f * timeDelta);

if( ::GetAsyncKeyState(VK_UP) & 0x8000f )
TheCamera.pitch(3.0f * timeDelta);

if( ::GetAsyncKeyState(VK_DOWN) & 0x8000f )
TheCamera.pitch(-3.0f * timeDelta);

if( ::GetAsyncKeyState(VK_LEFT) & 0x8000f )
TheCamera.yaw(-3.0f * timeDelta);

if( ::GetAsyncKeyState(VK_RIGHT) & 0x8000f )
TheCamera.yaw(3.0f * timeDelta);

if( ::GetAsyncKeyState(''N'') & 0x8000f )
TheCamera.roll(3.0f * timeDelta);

if( ::GetAsyncKeyState(''M'') & 0x8000f )
TheCamera.roll(-3.0f * timeDelta);


// Update the view matrix representing the cameras

// new position/orientation.

D3DXMATRIX V;
TheCamera.getViewMatrix(&V);
Device->SetTransform(D3DTS_VIEW, &V);
//

// Render

//


Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
Device->BeginScene();
//I added yours here

for(i++)
{
setTexture(mesh->t);
setMaterial(mesh->m[i]);
mesh->Drawsubset(i);
}

Device->EndScene();
Device->Present(0, 0, 0, 0);
}
return true;
}

//

// WndProc

//

LRESULT CALLBACK d3d::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch( msg )
{
case WM_DESTROY:
::PostQuitMessage(0);
break;

case WM_KEYDOWN:
if( wParam == VK_ESCAPE )
::DestroyWindow(hwnd);
break;
}
return ::DefWindowProc(hwnd, msg, wParam, lParam);
}

//

// WinMain

//

int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE prevInstance,
PSTR cmdLine,
int showCmd)
{
if(!d3d::InitD3D(hinstance,
Width, Height, true, D3DDEVTYPE_HAL, &Device))
{
::MessageBox(0, "InitD3D() - FAILED", 0, 0);
return 0;
}

if(!Setup())
{
::MessageBox(0, "Setup() - FAILED", 0, 0);
return 0;
}

d3d::EnterMsgLoop( Display );

Cleanup();

Device->Release();

return 0;
}




this is my utility.cpp file



#include "d3dUtility.h"

bool d3d::InitD3D(
HINSTANCE hInstance,
int width, int height,
bool windowed,
D3DDEVTYPE deviceType,
IDirect3DDevice9** device)
{
//

// Create the main application window.

//


WNDCLASS wc;

wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)d3d::WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(0, IDI_APPLICATION);
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = "Direct3D9App";

if( !RegisterClass(&wc) )
{
::MessageBox(0, "RegisterClass() - FAILED", 0, 0);
return false;
}

HWND hwnd = 0;
hwnd = ::CreateWindow("Direct3D9App", "Direct3D9App",
WS_EX_TOPMOST,
0, 0, width, height,
0 /*parent hwnd*/, 0 /* menu */, hInstance, 0 /*extra*/);

if( !hwnd )
{
::MessageBox(0, "CreateWindow() - FAILED", 0, 0);
return false;
}

::ShowWindow(hwnd, SW_SHOW);
::UpdateWindow(hwnd);

//

// Init D3D:

//


HRESULT hr = 0, hr2 = 0;

// Step 1: Create the IDirect3D9 object.


IDirect3D9* d3d9 = 0;
d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
if( !d3d9 )
{
::MessageBox(0, "Direct3DCreate9() - FAILED", 0, 0);
return false;
}

// Step 2: Check for hardware vp.


D3DCAPS9 caps;
d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, deviceType, &caps);

int vp = 0;
if( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
else
vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;

// Step 3: Fill out the D3DPRESENT_PARAMETERS structure.


D3DPRESENT_PARAMETERS d3dpp;
d3dpp.BackBufferWidth = width;
d3dpp.BackBufferHeight = height;
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hwnd;
d3dpp.Windowed = windowed;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.Flags = 0;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

// Step 4: Create the device.


hr = d3d9->CreateDevice(
D3DADAPTER_DEFAULT, // primary adapter

deviceType, // device type

hwnd, // window associated with device

vp, // vertex processing

&d3dpp, // present parameters

device); // return created device


if( FAILED(hr) )
{
// try again using a 16-bit depth buffer

d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

hr = d3d9->CreateDevice(
D3DADAPTER_DEFAULT,
deviceType,
hwnd,
vp,
&d3dpp,
device);

if( FAILED(hr) )
{
d3d9->Release(); // done with d3d9 object

::MessageBox(0, "CreateDevice() - FAILED", 0, 0);
return false;
}
}

d3d9->Release(); // done with d3d9 object


return true;
}

int d3d::EnterMsgLoop( bool (*ptr_display)(float timeDelta) )
{
MSG msg;
::ZeroMemory(&msg, sizeof(MSG));

static float lastTime = (float)timeGetTime();

while(msg.message != WM_QUIT)
{
if(::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
else
{
float currTime = (float)timeGetTime();
float timeDelta = (currTime - lastTime)*0.001f;

ptr_display(timeDelta);

lastTime = currTime;
}
}
return msg.wParam;
}

D3DLIGHT9 d3d::InitDirectionalLight(D3DXVECTOR3* direction, D3DXCOLOR* color)
{
D3DLIGHT9 light;
::ZeroMemory(&light, sizeof(light));

light.Type = D3DLIGHT_DIRECTIONAL;
light.Ambient = *color * 0.4f;
light.Diffuse = *color;
light.Specular = *color * 0.6f;
light.Direction = *direction;

return light;
}

D3DLIGHT9 d3d::InitPointLight(D3DXVECTOR3* position, D3DXCOLOR* color)
{
D3DLIGHT9 light;
::ZeroMemory(&light, sizeof(light));

light.Type = D3DLIGHT_POINT;
light.Ambient = *color * 0.4f;
light.Diffuse = *color;
light.Specular = *color * 0.6f;
light.Position = *position;
light.Range = 1000.0f;
light.Falloff = 1.0f;
light.Attenuation0 = 1.0f;
light.Attenuation1 = 0.0f;
light.Attenuation2 = 0.0f;

return light;
}

D3DLIGHT9 d3d::InitSpotLight(D3DXVECTOR3* position, D3DXVECTOR3* direction, D3DXCOLOR* color)
{
D3DLIGHT9 light;
::ZeroMemory(&light, sizeof(light));

light.Type = D3DLIGHT_SPOT;
light.Ambient = *color * 0.4f;
light.Diffuse = *color;
light.Specular = *color * 0.6f;
light.Position = *position;
light.Direction = *direction;
light.Range = 1000.0f;
light.Falloff = 1.0f;
light.Attenuation0 = 1.0f;
light.Attenuation1 = 0.0f;
light.Attenuation2 = 0.0f;
light.Theta = 0.5f;
light.Phi = 0.7f;

return light;
}

D3DMATERIAL9 d3d::InitMtrl(D3DXCOLOR a, D3DXCOLOR d, D3DXCOLOR s, D3DXCOLOR e, float p)
{
D3DMATERIAL9 mtrl;
mtrl.Ambient = a;
mtrl.Diffuse = d;
mtrl.Specular = s;
mtrl.Emissive = e;
mtrl.Power = p;
return mtrl;
}



and this is my d3dutility.h header file....... maybe u guys could take a look and explain to me where should i change so i can load multiple xfiles.....i added the stuff u said but i dunno what else that i should change........




#ifndef __d3dUtilityH__
#define __d3dUtilityH__

#include <d3dx9.h>
#include <string>
#include <d3dx9mesh.h>

namespace d3d
{
bool InitD3D(
HINSTANCE hInstance, // [in] Application instance.

int width, int height, // [in] Backbuffer dimensions.

bool windowed, // [in] Windowed (true)or full screen (false).

D3DDEVTYPE deviceType, // [in] HAL or REF

IDirect3DDevice9** device);// [out]The created device.


int EnterMsgLoop(
bool (*ptr_display)(float timeDelta));

LRESULT CALLBACK WndProc(
HWND *hwnd,
UINT *msg,
WPARAM *wParam,
LPARAM *lParam);

template<class T> void Release(T t)
{
if( t )
{
t->Release();
t = 0;
}
}

template<class T> void Delete(T t)
{
if( t )
{
delete t;
t = 0;
}
}

const D3DXCOLOR WHITE( D3DCOLOR_XRGB(255, 255, 255) );
const D3DXCOLOR BLACK( D3DCOLOR_XRGB( 0, 0, 0) );
const D3DXCOLOR RED( D3DCOLOR_XRGB(255, 0, 0) );
const D3DXCOLOR GREEN( D3DCOLOR_XRGB( 0, 255, 0) );
const D3DXCOLOR BLUE( D3DCOLOR_XRGB( 0, 0, 255) );
const D3DXCOLOR YELLOW( D3DCOLOR_XRGB(255, 255, 0) );
const D3DXCOLOR CYAN( D3DCOLOR_XRGB( 0, 255, 255) );
const D3DXCOLOR MAGENTA( D3DCOLOR_XRGB(255, 0, 255) );

//

// Lights

//


D3DLIGHT9 InitDirectionalLight(D3DXVECTOR3* direction, D3DXCOLOR* color);
D3DLIGHT9 InitPointLight(D3DXVECTOR3* position, D3DXCOLOR* color);
D3DLIGHT9 InitSpotLight(D3DXVECTOR3* position, D3DXVECTOR3* direction, D3DXCOLOR* color);

//

// Materials

//


D3DMATERIAL9 InitMtrl(D3DXCOLOR a, D3DXCOLOR d, D3DXCOLOR s, D3DXCOLOR e, float p);

const D3DMATERIAL9 WHITE_MTRL = InitMtrl(WHITE, WHITE, WHITE, BLACK, 2.0f);
const D3DMATERIAL9 RED_MTRL = InitMtrl(RED, RED, RED, BLACK, 2.0f);
const D3DMATERIAL9 GREEN_MTRL = InitMtrl(GREEN, GREEN, GREEN, BLACK, 2.0f);
const D3DMATERIAL9 BLUE_MTRL = InitMtrl(BLUE, BLUE, BLUE, BLACK, 2.0f);
const D3DMATERIAL9 YELLOW_MTRL = InitMtrl(YELLOW, YELLOW, YELLOW, BLACK, 2.0f);
}

#endif // __d3dUtilityH__




im so so sorry that im asking you guys for so much.....i know this is wrong but im xtremely desperate and running out of time........and i cant seem to understand the sdk tutorials and this ebook only xplains importing one xfile......please understand......i am extremely grateful to everyone. thanks again

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!