Esempio n. 1
0
Scene * D3D::BuildScene(IDirect3DDevice9 *d3dDevice)
 {
	 // Setup some materials - we'll use these for 
	 // making the same mesh appear in multiple
	 // colors

	 D3DMATERIAL9 colors[8];
	 D3DUtil_InitMaterial( colors[0], 1.0f, 1.0f, 1.0f, 1.0f );	// white
	 D3DUtil_InitMaterial( colors[1], 0.0f, 1.0f, 1.0f, 1.0f );	// cyan
	 D3DUtil_InitMaterial( colors[2], 1.0f, 0.0f, 0.0f, 1.0f );	// red
	 D3DUtil_InitMaterial( colors[3], 0.0f, 1.0f, 0.0f, 1.0f );	// green
	 D3DUtil_InitMaterial( colors[4], 0.0f, 0.0f, 1.0f, 1.0f );	// blue
	 D3DUtil_InitMaterial( colors[5], 0.4f, 0.4f, 0.4f, 0.4f );	// 40% grey
	 D3DUtil_InitMaterial( colors[6], 0.25f, 0.25f, 0.25f, 0.25f );	// 25% grey
	 D3DUtil_InitMaterial( colors[7], 0.65f, 0.65f, 0.65f, 0.65f );	// 65% grey

	 // The identity matrix is always useful
	 D3DXMATRIX ident;
	 D3DXMatrixIdentity(&ident);

	 // We'll use these rotations for some teapots and grid objects
	 D3DXMATRIX rotateX, rotateY, rotateZ;

	 // Create the root, and the camera.
	 // Remeber how to use smart pointers?? I hope so!

	 boost::shared_ptr<TransformNode> root(new TransformNode(&ident));

	 boost::shared_ptr<CameraNode> camera(new CameraNode(&ident));
	 root->m_children.push_back(camera);



	 // We'll put the camera in the scene at (20,20,20) looking back at the Origin

	 D3DXMATRIX rotOnly, result, inverse;
	 float cameraYaw = - (3.0f * D3DX_PI) / 4.0f;
	 float cameraPitch = D3DX_PI / 4.0f;
	 D3DXQUATERNION q;
	 D3DXQuaternionIdentity(&q);
	 D3DXQuaternionRotationYawPitchRoll(&q, cameraYaw, cameraPitch, 0.0);
	 D3DXMatrixRotationQuaternion(&rotOnly, &q);

	 D3DXMATRIX trans;
	 D3DXMatrixTranslation(&trans, 15.0f, 15.0f, 15.0f);

	 D3DXMatrixMultiply(&result, &rotOnly, &trans);

	 D3DXMatrixInverse(&inverse, NULL, &result);
	 camera->VSetTransform(&result, &inverse);

	 D3DXMatrixRotationZ(&rotateZ, D3DX_PI / 2.0f);
	 D3DXMatrixRotationX(&rotateX, -D3DX_PI / 2.0f);
	 D3DXVECTOR3 target(30, 2, 15);

	 //

	

	 ID3DXMesh *teapot;
	 if( SUCCEEDED( D3DXCreateTeapot( d3dDevice, &teapot, NULL ) ) )
	 {
		 // Teapot #1 - a white one at (x=6,y=2,z=4)
		 D3DXMatrixTranslation(&trans,6,2,4);

		 boost::shared_ptr<SceneNode> mesh1(new MeshNode(teapot, &trans, colors[2]));
		 root->m_children.push_back(mesh1);

		 // Teapot #2 - a cyan one at (x=3,y=2,z=1)
		 //   with a 
		 D3DXMatrixTranslation(&trans, 3,2,1);
		 D3DXMATRIX result;
		 D3DXMatrixMultiply(&result, &rotateZ, &trans);

		 boost::shared_ptr<SceneNode> mesh2(new MeshNode(teapot, &result, colors[1]));
		 root->m_children.push_back(mesh2);

		 // Teapot #3 - another white one at (x=30, y=2, z=15)
		 D3DXMATRIX rotateY90;
		 D3DXMatrixRotationY(&rotateY90, D3DX_PI / 2.0f);
		 D3DXMatrixTranslation(&trans, target.x, target.y, target.z);
		 D3DXMatrixMultiply(&result, &rotateY90, &trans);
		 boost::shared_ptr<SceneNode> mesh3(new MeshNode(teapot, &result, colors[0]));
		 root->m_children.push_back(mesh3);

		 // We can release the teapot now, mesh1 and mesh2 AddRef'd it.
		 SAFE_RELEASE(teapot);
	 }

	 ID3DXMesh *sphere;
	 if ( SUCCEEDED( 
		 D3DXCreateSphere( 
		 d3dDevice, .25, 16, 16, &sphere, NULL) ) )
	 {
		 // We're going to create a spiral of spheres...
		 // starting at (x=3, y=0, z=3), and spiraling
		 // upward about a local Y axis.

		 D3DXMatrixTranslation(&trans, 3,0,3);

		 boost::shared_ptr<SceneNode> sphere1(new MeshNode(sphere, &trans, colors[4]) );
		 root->m_children.push_back(sphere1);

		 // Here's the local rotation and translation.
		 // We'll rotate about Y, and then translate
		 // up (along Y) and forward (along Z).
		 D3DXMatrixRotationY(&rotateY, D3DX_PI / 8.0f);
		 D3DXMATRIX trans2;
		 D3DXMatrixTranslation(&trans2, 0, 0.5, 0.5);
		 D3DXMatrixMultiply(&result, &trans2, &rotateY);

		 for (int i=0; i<25; i++)
		 {
			 // If you didn't think smart pointers were cool - 
			 // watch this! No leaked memory....

			 // Notice this is a heirarchy....
			 boost::shared_ptr<SceneNode> sphere2(new MeshNode(sphere, &result, colors[i%5]) );
			 sphere1->m_children.push_back(sphere2);
			 sphere1 = sphere2;
		 }

		 // We can release the sphere now, all the cylinders AddRef'd it.
		 SAFE_RELEASE(sphere);
	 }
	 

	 //
	 D3DXMatrixTranslation(&trans,-25,20,20);
	 //D3DXMatrixScaling(&trans, -10, -10, -10);
	 ScaleMtrl scale;
	 scale.x = -50.0f;
	 scale.y = -50.0f;
	 scale.z = -50.0f;
	 boost::shared_ptr<SceneNode> xmesh1(new XMeshNode(L"gf3.x", d3dDevice, &trans, &scale));
	 root->m_children.push_back(xmesh1);

	 
	  root->m_children.push_back(xmesh1);

	 /*D3DXMatrixTranslation(&trans,-45,20,20);
	 boost::shared_ptr<SceneNode> xmesh11(new XMeshNode(L"gf3.x", d3dDevice, &trans, &scale));
	 root->m_children.push_back(xmesh11);*/


	  XMeshNode *mm = new XMeshNode(L"gow_m1.x", d3dDevice, &trans, &scale);

	 D3DXMatrixTranslation(&trans,10,10,10);
	 //D3DXMatrixScaling(&trans, -10, -10, -10);
	 //ScaleMtrl scale;
	 scale.x = 100.0f;
	 scale.y = 100.0f;
	 scale.z = 100.0f;
	 boost::shared_ptr<SceneNode> xmesh2( new XMeshNode(L"gow_m1.x", d3dDevice, &trans, &scale));
	 root->m_children.push_back(xmesh2);

	 
	 
	 /*D3DXMatrixTranslation(&trans,20,20,20);
	 boost::shared_ptr<SceneNode> xmesh3(new XMeshNode(mm->m_mesh, mm->Mtrls, mm->Textures, &trans, 0));
	 root->m_children.push_back(xmesh3);*/

	 int col = 10;
	 int row= 10;
	 int zoom = 10;
	 const int COUNT = 13;
	 for(int i = 0; i < COUNT; i++)
	 {
		 for (int j = 0; j< COUNT; j++)
		 {
			 for(int z = 0; z< COUNT; z++)
			 {
				 D3DXMatrixTranslation(&trans, col + i, row + j , zoom + z);
				 boost::shared_ptr<SceneNode> xmeshNew(new XMeshNode(mm->m_mesh, mm->Mtrls, mm->Textures, &trans, 0));
				 root->m_children.push_back(xmeshNew);
			 }
		 }
	 }


	 //D3DXMatrixScaling(&trans, 10, 10, 10);

	 // Here are the grids...they make it easy for us to 
	 // see where the coordinates are in 3D space.
	 boost::shared_ptr<SceneNode> grid1(new Grid(40, 0x00404040, L"Textures\\grid.dds", &ident));
	 root->m_children.push_back(grid1);
	 boost::shared_ptr<SceneNode> grid2(new Grid(40, 0x00004000, L"Textures\\grid.dds", &rotateX));
	 root->m_children.push_back(grid2);
	 boost::shared_ptr<SceneNode> grid3(new Grid(40, 0x00000040, L"Textures\\grid.dds", &rotateZ));
	 root->m_children.push_back(grid3);

	 //  Here's the sky node that never worked!!!!
	 boost::shared_ptr<SkyNode> sky(new SkyNode(_T("Sky2"), camera));
	 root->m_children.push_back(sky);

	 D3DXMatrixTranslation(&trans,15,2,15);
	 D3DXMatrixRotationY(&rotateY, D3DX_PI / 4.0f);
	 D3DXMatrixMultiply(&result, &rotateY, &trans);

	 boost::shared_ptr<SceneNode> arrow1(new ArrowNode(2, &result, colors[0], d3dDevice));
	 root->m_children.push_back(arrow1);

	 D3DXMatrixRotationY(&rotateY, D3DX_PI / 2.0f);
	 D3DXMatrixMultiply(&result, &rotateY, &trans);
	 boost::shared_ptr<SceneNode> arrow2(new ArrowNode(2, &result, colors[5], d3dDevice));
	 root->m_children.push_back(arrow2);

	 D3DXMatrixMultiply(&result, &rotateX, &trans);
	 boost::shared_ptr<SceneNode> arrow3(new ArrowNode(2, &result, colors[0], d3dDevice));
	 root->m_children.push_back(arrow3);


	 // Everything has been attached to the root. Now
	 // we attach the root to the scene.

	 Scene *scene = new Scene(d3dDevice, root);
	 scene->Restore();

	 // A movement controller is going to control the camera, 
	 // but it could be constructed with any of the objects you see in this
	 // function. You can have your very own remote controlled sphere. What fun...
	 boost::shared_ptr<MovementController> m_pMovementController(new MovementController(camera, cameraYaw, cameraPitch));

	 scene->m_pMovementController = m_pMovementController;
	 return scene;
 }
Esempio n. 2
0
//
// Framework Functions
//
bool Setup()
{
	//
	// Create the objects.
	//

	D3DXCreateTeapot(
		Device,
		&Objects[0],
		0);

	D3DXCreateBox(
		Device,
		2.0f, // width
		2.0f, // height
		2.0f, // depth
		&Objects[1],
		0);

	// cylinder is built aligned on z-axis
	D3DXCreateCylinder(
		Device,
		1.0f, // radius at negative z end
		1.0f, // radius at positive z end
		3.0f, // length of cylinder
		10,   // slices
		10,   // stacks
		&Objects[2],
		0);

	D3DXCreateTorus(
		Device,
		1.0f, // inner radius
		3.0f, // outer radius
		10,   // sides
		10,   // rings
		&Objects[3],
		0);

	D3DXCreateSphere(
		Device,
		1.0f, // radius
		10,   // slices
		10,   // stacks
		&Objects[4],
		0);

	//
	// Build world matrices - position the objects in world space.
	// For example, ObjWorldMatrices[1] will position Objects[1] at
	// (-5, 0, 5).  Likewise, ObjWorldMatrices[2] will position
	// Objects[2] at (5, 0, 5).
	//

	D3DXMatrixTranslation(&ObjWorldMatrices[0],  0.0f, 0.0f,  0.0f);
	D3DXMatrixTranslation(&ObjWorldMatrices[1], -5.0f, 0.0f,  5.0f);
	D3DXMatrixTranslation(&ObjWorldMatrices[2],  5.0f, 0.0f,  5.0f);
	D3DXMatrixTranslation(&ObjWorldMatrices[3], -5.0f, 0.0f, -5.0f);
	D3DXMatrixTranslation(&ObjWorldMatrices[4],  5.0f, 0.0f, -5.0f);

	//
	// Set the 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);

	//
	// Switch to wireframe mode.
	//

	Device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);

	return true;
}
Esempio n. 3
0
//
// Framework functions
//
bool Setup()
{
	//
	// Create the teapot.
	//

	D3DXCreateTeapot(Device, &Teapot, 0);

	//
	// Compute the bounding sphere.
	//

	BYTE* v = 0;
	Teapot->LockVertexBuffer(0, (void**)&v);

	D3DXComputeBoundingSphere(
		(D3DXVECTOR3*)v,
		Teapot->GetNumVertices(),
		D3DXGetFVFVertexSize(Teapot->GetFVF()),
		&BSphere._center,
		&BSphere._radius);

	Teapot->UnlockVertexBuffer();

	//
	// Build a sphere mesh that describes the teapot's bounding sphere.
	//

	D3DXCreateSphere(Device, BSphere._radius, 20, 20, &Sphere, 0);

	//
	// Set light.
	//

	D3DXVECTOR3 dir(0.707f, -0.0f, 0.707f);
	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, false);	

	//
	// Set view matrix.
	//

	D3DXVECTOR3 pos(0.0f, 0.0f, -10.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.25f, // 45 - degree
			(float)Width / (float)Height,
			1.0f,
			1000.0f);
	Device->SetTransform(D3DTS_PROJECTION, &proj);

	return true;
}
Esempio n. 4
0
void cASEObject::setup(stASENode& nodeinfo, D3DXMATRIXA16* pmatParentWorld/* = NULL*/){
	m_stNodeInfo = nodeinfo;		
	m_matWorldTM = nodeinfo.LocalMat;
	m_matOriginalWorld = nodeinfo.LocalMat;
	m_stNodeAni = nodeinfo.AnimationInfo;
	
	if (pmatParentWorld){
		D3DXMATRIXA16 mtPrnI;
		D3DXMatrixInverse(&mtPrnI, NULL, pmatParentWorld);
		m_matLocalMat = m_matWorldTM * mtPrnI;
	}
	else {
		D3DXMatrixIdentity(&m_matLocalMat);
	}	
	
	D3DXMATRIXA16 matInverse;
	D3DXMatrixInverse(&matInverse, NULL, &m_matWorldTM);

	for (size_t i = 0; i < m_stNodeInfo.vecVertex.size(); i++){
		D3DXVec3TransformCoord(
			&m_stNodeInfo.vecVertex[i].p,
			&m_stNodeInfo.vecVertex[i].p,
			&matInverse);
		D3DXVec3TransformNormal(
			&m_stNodeInfo.vecVertex[i].n,
			&m_stNodeInfo.vecVertex[i].n,
			&matInverse
			);
	}

	D3DXCreateSphere(g_pD3DDevice, 0.025f, 10, 10, &m_pNodeMesh, NULL);

	if (m_stNodeInfo.nRef != INT_MAX){
		m_pMesh = NULL;
		HRESULT hr = D3DXCreateMeshFVF(m_stNodeInfo.vecVertex.size() / 3,
			m_stNodeInfo.vecVertex.size(),
			D3DXMESH_MANAGED,
			ST_PNT_VERTEX::FVF,
			g_pD3DDevice,
			&m_pMesh);

#ifdef _DEBUG
		_ASSERT(hr == S_OK && "Mesh Not Created");
#endif

		ST_PNT_VERTEX* pV = NULL;
		m_pMesh->LockVertexBuffer(0, (LPVOID*)&pV);
		memcpy(pV, &m_stNodeInfo.vecVertex[0], m_stNodeInfo.vecVertex.size() * sizeof(ST_PNT_VERTEX));
		m_pMesh->UnlockVertexBuffer();

		WORD* pI = NULL;
		m_pMesh->LockIndexBuffer(0, (LPVOID*)&pI);
		for (size_t j = 0; j < m_pMesh->GetNumVertices(); ++j)
		{
			pI[j] = j;
		}
		m_pMesh->UnlockIndexBuffer();

		DWORD* pA = NULL;
		m_pMesh->LockAttributeBuffer(0, &pA);
		for (size_t j = 0; j < m_pMesh->GetNumFaces(); j++){
			pA[j] = m_stNodeInfo.nRef;
		}
		m_pMesh->UnlockAttributeBuffer();

		std::vector<DWORD> vecAdjBuffer(m_stNodeInfo.vecVertex.size());
		m_pMesh->GenerateAdjacency(0.0f, &vecAdjBuffer[0]);

		m_pMesh->OptimizeInplace(
			D3DXMESHOPT_ATTRSORT |
			D3DXMESHOPT_COMPACT |
			D3DXMESHOPT_VERTEXCACHE,
			&vecAdjBuffer[0], 0, 0, 0);
	}
}
Esempio n. 5
0
BOOL initD3dStuff(HWND hWnd) {
    void *tempVoid;
    LPD3DXBUFFER shipMB;
    D3DXMATERIAL *tempMaterials;
    int transparency = 127;

    CUSTOMVERTEX customVertex1[] = {
        //	triangle
        {0.8f, -0.8f, 0.0f, 0, 0, 1, D3DCOLOR_ARGB(255, 255, 255, 255), 0, 0},
        {0.0f, 0.8f, 0.0f, 0, 0, 1, D3DCOLOR_ARGB(255, 255, 255, 255), 1, 0},
        {-0.8f, -0.8f, 0.0f, 0, 0, 1, D3DCOLOR_ARGB(255, 255, 255, 255), 1, 1}
    };
    CUSTOMVERTEX customVertex2[] = {
        //	side 1
        {-3.0f, 3.0f, -3.0f, 0, 0, -1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 0},
        {3.0f, 3.0f, -3.0f, 0, 0, -1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 1},
        {-3.0f, -3.0f, -3.0f, 0, 0, -1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 0},
        {3.0f, -3.0f, -3.0f, 0, 0, -1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 1},

        //	side 2
        {-3.0f, 3.0f, 3.0f, 0, 0, 1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 0},
        {-3.0f, -3.0f, 3.0f, 0, 0, 1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 1},
        {3.0f, 3.0f, 3.0f, 0, 0, 1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 0},
        {3.0f, -3.0f, 3.0f, 0, 0, 1, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 1},

        //	side 3
        {-3.0f, 3.0f, 3.0f, 0, 1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 0},
        {3.0f, 3.0f, 3.0f, 0, 1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 1},
        {-3.0f, 3.0f, -3.0f, 0, 1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 0},
        {3.0f, 3.0f, -3.0f, 0, 1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 1},

        //	side 4
        {-3.0f, -3.0f, 3.0f, 0, -1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 0},
        {-3.0f, -3.0f, -3.0f, 0, -1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 1},
        {3.0f, -3.0f, 3.0f, 0, -1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 0},
        {3.0f, -3.0f, -3.0f, 0, -1, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 1},

        //	side 5
        {3.0f, 3.0f, -3.0f, 1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 0},
        {3.0f, 3.0f, 3.0f, 1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 1},
        {3.0f, -3.0f, -3.0f, 1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 0},
        {3.0f, -3.0f, 3.0f, 1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 1},

        //	side 6
        //	I inverted the texture coords to get my image right
        {-3.0f, 3.0f, -3.0f, -1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 0},
        {-3.0f, -3.0f, -3.0f, -1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 0, 1},
        {-3.0f, 3.0f, 3.0f, -1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 0},
        {-3.0f, -3.0f, 3.0f, -1, 0, 0, D3DCOLOR_ARGB(transparency, 255, 255, 255), 1, 1}
    };

    //	predefined simple D3DX mesh objects
    D3DXCreateBox(d3d9dev, 7.0f, 3.0f, 3.0f, &mesh1, NULL);
    D3DXCreateSphere(d3d9dev, 0.3f, 20, 10, &mesh2, NULL);

    //	one complete mesh loading (vertices, materials and textures)
    if (D3DXLoadMeshFromXResource(NULL, (LPCSTR)MAKEINTRESOURCE(IDR_MESHX1), "meshx", D3DXMESH_MANAGED, d3d9dev, NULL, &shipMB, NULL, &numMaterials, &mesh3) != D3D_OK) {
        MessageBox(hWnd, "craft.x could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }
    /*	load from file
    if (D3DXLoadMeshFromX("craft.x", D3DXMESH_MANAGED, d3d9dev, NULL, &shipMB, NULL, &numMaterials, &mesh3) != D3D_OK) {
    	MessageBox(hWnd, "craft.x file not found", "Error", MB_ICONERROR);
    	PostQuitMessage(0);
    }
    */
    tempMaterials = (D3DXMATERIAL *)shipMB->GetBufferPointer();
    materialX = new D3DMATERIAL9[numMaterials];
    planeTexture = new LPDIRECT3DTEXTURE9[numMaterials];
    for (DWORD i = 0; i < numMaterials; i++) {
        materialX[i] = tempMaterials[i].MatD3D;
        materialX[i].Ambient = materialX[i].Diffuse;
        /*	dont need the following cause I use resources
        		USES_CONVERSION;    // allows certain string conversions
        		// if there is a texture to load, load it
        		if(FAILED(D3DXCreateTextureFromFile(d3d9dev, CA2W(tempMaterials[i].pTextureFilename), &planeTexture[i])))
        */			planeTexture[i] = NULL;	// if there is no texture, set the texture to NULL

    }

    // load the textures (embedded in the executable) we will use
    if (D3DXCreateTextureFromResource(d3d9dev, NULL, (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP1), &planeTexture[2]) != D3D_OK) {
        MessageBox(hWnd, "wings.bmp could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }
    if (D3DXCreateTextureFromResource(d3d9dev, NULL, (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP2), &planeTexture[6]) != D3D_OK) {
        MessageBox(hWnd, "bihull.bmp could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }
    planeTexture[0] = planeTexture[1] = planeTexture[3] = planeTexture[4] = planeTexture[6];

    if (D3DXCreateTextureFromResourceEx(d3d9dev,	//	the device pointer
                                        NULL,	//	module (executable containing the resource)
                                        (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP3),	//	resource
                                        //"logo1.bmp",	//	the file name
                                        D3DX_DEFAULT,	//	default width
                                        D3DX_DEFAULT,	//	default height
                                        D3DX_DEFAULT,	//	no mip mapping
                                        NULL,	//	regular usage
                                        D3DFMT_A8R8G8B8,	//	32-bit pixels with alpha
                                        D3DPOOL_MANAGED,	//	typical memory handling
                                        D3DX_DEFAULT,	//	no filtering
                                        D3DX_DEFAULT,	//	no mip filtering
                                        D3DCOLOR_ARGB(127, 255, 0, 255),	//	the hot-pink color key
                                        NULL,	//	no image info struct
                                        NULL,	//	not using 256 colors
                                        &texture1) != D3D_OK) {
        MessageBox(hWnd, "logo1.bmp could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }
    /*	if (D3DXCreateTextureFromResource(d3d9dev, NULL, (LPCSTR)MAKEINTRESOURCE(IDB_BITMAP3), &texture1) != D3D_OK) {
    		MessageBox(hWnd, "logo1.bmp could not be loaded", "Error", MB_ICONERROR);
    		PostQuitMessage(0);
    		return FALSE;
    	}
    */

    if (D3DXCreateTextureFromResourceEx(d3d9dev,	//	the device pointer
                                        NULL,	//	module (executable containing the resource)
                                        (LPCSTR)MAKEINTRESOURCE(IDR_LOGO2PNG),	//	resource
                                        //"logo2.png",	//	the file name
                                        D3DX_DEFAULT,	//	default width
                                        D3DX_DEFAULT,	//	default height
                                        D3DX_DEFAULT,	//	no mip mapping
                                        NULL,	//	regular usage
                                        D3DFMT_A8R8G8B8,	//	32-bit pixels with alpha
                                        D3DPOOL_MANAGED,	//	typical memory handling
                                        D3DX_DEFAULT,	//	no filtering
                                        D3DX_DEFAULT,	//	no mip filtering
                                        D3DCOLOR_ARGB(127, 255, 0, 255),	//	the hot-pink color key
                                        NULL,	//	no image info struct
                                        NULL,	//	not using 256 colors
                                        &texture2) != D3D_OK) {
        MessageBox(hWnd, "logo2.png could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }
    /*
    	if (D3DXCreateTextureFromResource(d3d9dev, NULL, (LPCSTR)MAKEINTRESOURCE(IDR_LOGO2PNG), &texture2) != D3D_OK) {
    		MessageBox(hWnd, "logo2.png could not be loaded", "Error", MB_ICONERROR);
    		PostQuitMessage(0);
    		return FALSE;
    	}
    */
    if (D3DXCreateTextureFromResourceEx(d3d9dev,	//	the device pointer
                                        NULL,	//	module (executable containing the resource)
                                        (LPCSTR)MAKEINTRESOURCE(IDR_LOGO3PNG),	//	resource
                                        //"logo3.png",	//	the file name
                                        D3DX_DEFAULT,	//	default width
                                        D3DX_DEFAULT,	//	default height
                                        D3DX_DEFAULT,	//	no mip mapping
                                        NULL,	//	regular usage
                                        D3DFMT_A8R8G8B8,	//	32-bit pixels with alpha
                                        D3DPOOL_MANAGED,	//	typical memory handling
                                        D3DX_DEFAULT,	//	no filtering
                                        D3DX_DEFAULT,	//	no mip filtering
                                        D3DCOLOR_ARGB(127, 255, 0, 255),	//	the hot-pink color key
                                        NULL,	//	no image info struct
                                        NULL,	//	not using 256 colors
                                        &texture3) != D3D_OK) {
        MessageBox(hWnd, "logo3.png could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }
    /*	if (D3DXCreateTextureFromResource(d3d9dev, NULL, (LPCSTR)MAKEINTRESOURCE(IDR_LOGO3PNG), &texture3) != D3D_OK) {
    		MessageBox(hWnd, "logo3.png could not be loaded", "Error", MB_ICONERROR);
    		PostQuitMessage(0);
    		return FALSE;
    	}
    */

    //	sprite
    D3DXCreateSprite(d3d9dev, &sprite);
    // sprite texture
    if (D3DXCreateTextureFromResourceEx(d3d9dev,	//	the device pointer
                                        NULL,	//	module (executable containing the resource)
                                        (LPCSTR)MAKEINTRESOURCE(IDR_LEGENDPNG),	//	resource
                                        //"legend.png",	//	the file name
                                        D3DX_DEFAULT,	//	default width
                                        D3DX_DEFAULT,	//	default height
                                        D3DX_DEFAULT,	//	no mip mapping
                                        NULL,	//	regular usage
                                        D3DFMT_A8R8G8B8,	//	32-bit pixels with alpha
                                        D3DPOOL_MANAGED,	//	typical memory handling
                                        D3DX_DEFAULT,	//	no filtering
                                        D3DX_DEFAULT,	//	no mip filtering
                                        D3DCOLOR_XRGB(255, 0, 255),	//	the hot-pink color key
                                        NULL,	//	no image info struct
                                        NULL,	//	not using 256 colors
                                        &legendTexture) != D3D_OK) {
        MessageBox(hWnd, "legend.png could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }

    //	sprite legend
    D3DXCreateSprite(d3d9dev, &legendSprite);
    //	its texture
    if (D3DXCreateTextureFromResourceEx(d3d9dev,	//	the device pointer
                                        NULL,
                                        (LPCSTR)MAKEINTRESOURCE(IDR_SPRITEPNG),
                                        //"sprite.png",	//	the file name
                                        D3DX_DEFAULT,	//	default width
                                        D3DX_DEFAULT,	//	default height
                                        D3DX_DEFAULT,	//	no mip mapping
                                        NULL,	//	regular usage
                                        D3DFMT_A8R8G8B8,	//	32-bit pixels with alpha
                                        D3DPOOL_MANAGED,	//	typical memory handling
                                        D3DX_DEFAULT,	//	no filtering
                                        D3DX_DEFAULT,	//	no mip filtering
                                        D3DCOLOR_XRGB(255, 0, 255),	//	the hot-pink color key
                                        NULL,	//	no image info struct
                                        NULL,	//	not using 256 colors
                                        &spriteTexture) != D3D_OK) {
        MessageBox(hWnd, "panel.png could not be loaded", "Error", MB_ICONERROR);
        PostQuitMessage(0);
        return FALSE;
    }

    //	triangle
    d3d9dev->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &d3d9VertexBuffer1, NULL);
    d3d9VertexBuffer1->Lock(0, 0, &tempVoid, 0);
    if (memcpy(tempVoid, customVertex1, sizeof(customVertex1)) == NULL) MessageBox(NULL, "Error", "error", MB_OK);
    d3d9VertexBuffer1->Unlock();

    //	cube
    d3d9dev->CreateVertexBuffer(24*sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &d3d9VertexBuffer2, NULL);
    d3d9VertexBuffer2->Lock(0, 0, &tempVoid, 0);
    memcpy(tempVoid, customVertex2, sizeof(customVertex2));
    d3d9VertexBuffer2->Unlock();

    return TRUE;
}
//
// Framework functions
//
bool Setup()
{
	HRESULT hr = 0;

	//
	// Load the XFile data.
	//
	ID3DXBuffer* adjBuffer  = 0;
	ID3DXBuffer* mtrlBuffer = 0;
	DWORD        numMtrls   = 0;

	hr = D3DXLoadMeshFromX(  
		"../media/object/bigship1.x",
		D3DXMESH_MANAGED,
		Device,
		&adjBuffer,
		&mtrlBuffer,
		0,
		&numMtrls,
		&Mesh);

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

	//
	// Extract the materials, 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 );
			}
		}
	}
	byhj::Release<ID3DXBuffer*>(mtrlBuffer); // done w/ buffer

	//
	// Optimize the mesh.
	//

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

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

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

	//
	// Compute Bounding Sphere and Bounding Box.
	//

	byhj::BoundingSphere boundingSphere;
	byhj::BoundingBox    boundingBox;

	ComputeBoundingSphere(Mesh, &boundingSphere);
	ComputeBoundingBox(Mesh, &boundingBox);

	D3DXCreateSphere(
		Device,
		boundingSphere._radius,
		20,
		20,
		&SphereMesh,
		0);

	D3DXCreateBox(
		Device,
		boundingBox._max.x - boundingBox._min.x,
		boundingBox._max.y - boundingBox._min.y,
		boundingBox._max.z - boundingBox._min.z,
		&BoxMesh,
		0);

	//
	// 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 = byhj::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, 12.0f, -20.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;
}
Esempio n. 7
0
//-------------------------------------------------------------------------
bool CMeshLoadX::Setup(IDirect3DDevice9* pDevice,int nWidth,int nHeight)
{
	if (0 == pDevice)
	{
		return false;
	}
	m_Device = pDevice;
	m_nHeight = nHeight;
	m_nWidth = nWidth;

	// 读取X文件并解析
	{
		HRESULT hr = 0;
		ID3DXBuffer* adjBuffer = 0;
		ID3DXBuffer* mtrlBuffer = 0;
		DWORD	numMtrls = 0;
		hr = D3DXLoadMeshFromX(
			s_szMeshFilePath,
			D3DXMESH_MANAGED,
			m_Device,
			&adjBuffer,
			&mtrlBuffer,
			0,
			&numMtrls,
			&m_SourceMesh);

		if (FAILED(hr))
		{
			::MessageBox(0,"CMeshLoadX::Setup hr is failed",0,0);
			return false;
		}

		if (mtrlBuffer != 0 && numMtrls != 0)
		{
			D3DXMATERIAL* mtrls = (D3DXMATERIAL*)mtrlBuffer->GetBufferPointer();
			for (int nIndex = 0; nIndex < numMtrls; ++nIndex)
			{
				mtrls[nIndex].MatD3D.Ambient = mtrls[nIndex].MatD3D.Diffuse;
				m_vecMtrls.push_back(mtrls[nIndex].MatD3D);
				if (mtrls[nIndex].pTextureFilename != 0)
				{
					IDirect3DTexture9* pTex = 0;
					D3DXCreateTextureFromFile(m_Device,mtrls[nIndex].pTextureFilename,&pTex);
					m_vecTextures.push_back(pTex);
				}
				else
				{
					m_vecTextures.push_back(0);
				}
			}
		}

		d3d::Release<ID3DXBuffer*>(mtrlBuffer);

		hr = m_SourceMesh->OptimizeInplace(		
			D3DXMESHOPT_ATTRSORT |
			D3DXMESHOPT_COMPACT  |
			D3DXMESHOPT_VERTEXCACHE,
			(DWORD*)adjBuffer->GetBufferPointer(),
			(DWORD*)adjBuffer->GetBufferPointer(), // new adjacency info
			0, 0);

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

		hr = D3DXGeneratePMesh(
			m_SourceMesh,
			(DWORD*)adjBuffer->GetBufferPointer(),
			0,
			0,
			1,
			D3DXMESHSIMP_FACE,
			&m_ProcessMesh);

		
	

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

		m_ProcessMesh->SetNumFaces(m_ProcessMesh->GetMaxFaces());

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

	}

	// 新建字体
	{
		D3DXFONT_DESCA lf;
		::ZeroMemory(&lf,sizeof(D3DXFONT_DESCA));

		lf.Height = 25;
		lf.Width = 14;
		lf.Weight = 500;
		lf.Italic = false;
		lf.CharSet = DEFAULT_CHARSET;
#pragma warning ( disable: 4996 )
		strcpy(lf.FaceName,"Times New Roman");
#pragma warning ( default : 4996 )
		D3DXCreateFontIndirect(m_Device,&lf,&m_XFont);
	}

	// 写Mesh数据文件
	{
		m_OutFile.open("MeshDumpX.txt");

		__dumpVertices(m_OutFile, m_SourceMesh);
		__dumpIndices(m_OutFile, m_SourceMesh);
		__dumpAttributeTable(m_OutFile, m_SourceMesh); 	
		__dumpAttributeBuffer(m_OutFile, m_SourceMesh);		
		__dumpAdjacencyBuffer(m_OutFile, m_SourceMesh);

		m_OutFile.close();
	}
	
	d3d::BoundingSphere boundingSphere;
	d3d::BoundingBox    boundingBox;

	__ComputeBoundingSphere(m_SourceMesh, &boundingSphere);
	__ComputeBoundingBox(m_SourceMesh, &boundingBox);

	D3DXCreateSphere(
		m_Device,
		boundingSphere._radius,
		20,
		20,
		&m_SphereMesh,
		0);

	D3DXCreateBox(
		m_Device,
		boundingBox._max.x - boundingBox._min.x,
		boundingBox._max.y - boundingBox._min.y,
		boundingBox._max.z - boundingBox._min.z,
		&m_BoxMesh,
		0);

	//
	// Set texture filters.
	//

	m_Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	m_Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	m_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);

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

	//
	// Set camera.
	//

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

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

	m_Device->SetTransform(D3DTS_VIEW, &V);

	//
	// Set projection matrix.
	//

	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(
		&proj,
		D3DX_PI * 0.5f, // 90 - degree
		(float)m_nWidth / (float)m_nHeight,
		1.0f,
		1000.0f);
	m_Device->SetTransform(D3DTS_PROJECTION, &proj);

	return true;
}
Esempio n. 8
0
//**関数***************************************************************************
// メッシュ初期化
//*********************************************************************************
bool CMesh::Initialize(LPCTSTR pszFName)
{
	TCHAR			szMsg[MAX_PATH + 32];
	TCHAR			szDir[_MAX_DIR];
	TCHAR			szCurrentDir[_MAX_PATH];

	LPD3DXBUFFER	pD3DXMtrlBuffer = NULL;

	// フォルダ名を抽出
	_tsplitpath(pszFName, NULL, szDir, NULL, NULL);

	// Xファイルからメッシュデータを読み込む
	HRESULT hr = D3DXLoadMeshFromX(pszFName, D3DXMESH_SYSTEMMEM, CGraphics::GetDevice(),
		NULL, &pD3DXMtrlBuffer, NULL, &m_dwNumMaterial, &m_pD3DMesh);
	if (FAILED(hr)) {
		_stprintf(szMsg, _T("Xファイル(%s)の読み込みに失敗しました。"), pszFName);
		MessageBox(NULL, szMsg, NULL, MB_OK);
		return false;
	}

	// FVF形式を補正(頂点フォーマットを変換)
	LPD3DXMESH pMeshTmp;
	DWORD dwFVF = m_pD3DMesh->GetFVF();
	if (dwFVF != FVF_BVERTEX) {
		hr = m_pD3DMesh->CloneMeshFVF(m_pD3DMesh->GetOptions(), FVF_BVERTEX,
			CGraphics::GetDevice(), &pMeshTmp);
		SAFE_RELEASE(m_pD3DMesh);
		if (FAILED(hr)) {
			SAFE_RELEASE(pD3DXMtrlBuffer);
			return false;
		}
		// 法線が無い場合は強制的に追加
		if ((dwFVF & D3DFVF_NORMAL) == 0) {
			D3DXComputeNormals(pMeshTmp, NULL);
		}
		m_pD3DMesh = pMeshTmp;
	}

	// 接ベクトルがない場合は強制的に追加
	D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE];
    D3DVERTEXELEMENT9 End = D3DDECL_END();
    int iElem;

	m_pD3DMesh->GetDeclaration(Declaration);
    BOOL bHasTangents = FALSE;
    for (iElem = 0; Declaration[iElem].Stream != End.Stream; iElem++)
    {
        if (Declaration[iElem].Usage == D3DDECLUSAGE_TANGENT)
        {
            bHasTangents = TRUE;
            break;
        }
    }

    // Update Mesh Semantics if changed
    if (!bHasTangents)
    {
        Declaration[iElem].Stream = 0;
        Declaration[iElem].Offset = (WORD)m_pD3DMesh->GetNumBytesPerVertex();
        Declaration[iElem].Type = D3DDECLTYPE_FLOAT3;
        Declaration[iElem].Method = D3DDECLMETHOD_DEFAULT;
        Declaration[iElem].Usage = D3DDECLUSAGE_TANGENT;
        Declaration[iElem].UsageIndex = 0;
        Declaration[iElem+1] = End;
        LPD3DXMESH pTempMesh;

		hr = m_pD3DMesh->CloneMesh(D3DXMESH_MANAGED, Declaration, CGraphics::GetDevice() , &pTempMesh);
        if (SUCCEEDED(hr))
        {
			SAFE_RELEASE(m_pD3DMesh);
			m_pD3DMesh = pTempMesh;
            //hr = D3DXComputeTangent(m_pMesh, 0, 0, D3DX_DEFAULT, TRUE, NULL);
			hr = D3DXComputeTangent(m_pD3DMesh , 0, 0, D3DX_DEFAULT, FALSE, NULL);
        }
    }

	// 属性テーブルを生成するための最適化
	hr = m_pD3DMesh->Optimize(D3DXMESHOPT_ATTRSORT, NULL, NULL, NULL, NULL, &pMeshTmp);
	if (SUCCEEDED(hr)) {
		m_pD3DMesh->Release();
		m_pD3DMesh = pMeshTmp;
	} else {
		SAFE_RELEASE(pD3DXMtrlBuffer);
		return false;
	}
	// 属性テーブル取得
	hr = m_pD3DMesh->GetAttributeTable(NULL, &m_dwAttr);
	if (FAILED(hr)) {
		SAFE_RELEASE(pD3DXMtrlBuffer);
		SAFE_RELEASE(m_pD3DMesh);
		return false;
	}
	m_pAttr = new D3DXATTRIBUTERANGE[m_dwAttr];
	hr = m_pD3DMesh->GetAttributeTable(m_pAttr, &m_dwAttr);
	// 頂点バッファ/インデックスバッファ固定
	LPVOID pVtx;
	m_pD3DMesh->LockVertexBuffer(D3DLOCK_READONLY, &pVtx);
	LPVOID pIdx;
	m_pD3DMesh->LockIndexBuffer(D3DLOCK_READONLY, &pIdx);
	// 抽出場所の確保
	m_dwVtx = m_pD3DMesh->GetNumVertices();
	m_pVtx = new BVERTEX[m_dwVtx];
	m_dwFace = m_pD3DMesh->GetNumFaces();
	m_dwIdx = m_dwFace * 3;
	m_pIdx = new WORD[m_dwIdx];
	m_pPiece = new PARTICLE[m_dwFace];
	m_pPieceVtx = new BVERTEX[m_dwIdx];
	// コピー
	CopyMemory(m_pVtx, pVtx, sizeof(BVERTEX) * m_dwVtx);
	CopyMemory(m_pIdx, pIdx, sizeof(WORD) * m_dwIdx);
	// 頂点バッファ/インデックスバッファ解放
	m_pD3DMesh->UnlockVertexBuffer();
	m_pD3DMesh->UnlockIndexBuffer();

	// カレントディレクトリを変更
	if (szDir[0]) {
		GetCurrentDirectory(_MAX_PATH, szCurrentDir);
		SetCurrentDirectory(szDir);
	}

	// マテリアル読み込み
	D3DXMATERIAL* pD3DMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
	m_pMaterial = new D3DMATERIAL9[m_dwNumMaterial];
	m_ppTexture = new LPDIRECT3DTEXTURE9[m_dwNumMaterial];
	for (DWORD i = 0; i < m_dwNumMaterial; i++) { 
		m_pMaterial[i] = pD3DMaterials[i].MatD3D;
		m_pMaterial[i].Ambient = m_pMaterial[i].Diffuse;
		m_ppTexture[i] = NULL;
		if (pD3DMaterials[i].pTextureFilename && pD3DMaterials[i].pTextureFilename[0]) {
			// テクスチャファイルを読み込む
			if (FAILED(D3DXCreateTextureFromFileA(CGraphics::GetDevice(),
				pD3DMaterials[i].pTextureFilename, &m_ppTexture[i]))) {
				_stprintf(szMsg, _T("テクスチャ(%hs)の読み込みに失敗しました。"),
					pD3DMaterials[i].pTextureFilename);
				MessageBox(NULL, szMsg, NULL, MB_OK);
			}
		}
	}

	// カレントディレクトリを元に戻す
	if (szDir[0])
		SetCurrentDirectory(szCurrentDir);

	pD3DXMtrlBuffer->Release();

	// 境界ボックス生成
	D3DXVECTOR3 vMin = m_pVtx[0].pos;
	D3DXVECTOR3 vMax = vMin;
	BVERTEX* pBVtx = m_pVtx + 1;
	for (DWORD i = 1; i < m_dwVtx; i++, pBVtx++) {
		if (vMin.x > pBVtx->pos.x)
			vMin.x = pBVtx->pos.x;
		if (vMin.y > pBVtx->pos.y)
			vMin.y = pBVtx->pos.y;
		if (vMin.z > pBVtx->pos.z)
			vMin.z = pBVtx->pos.z;
		if (vMax.x < pBVtx->pos.x)
			vMax.x = pBVtx->pos.x;
		if (vMax.y < pBVtx->pos.y)
			vMax.y = pBVtx->pos.y;
		if (vMax.z < pBVtx->pos.z)
			vMax.z = pBVtx->pos.z;
	}
	m_vHalf = (vMax - vMin) / 2.0f;
	m_vCenter = (vMax + vMin) / 2.0f;

	// 境界球の生成
	m_fRadius = 0.0f;
	float fR;
	for (DWORD i = 0; i < m_dwVtx; i++) {
		fR = D3DXVec3Length(&(m_pVtx[i].pos - m_vCenter));
		if (m_fRadius < fR)
			m_fRadius = fR;
	}

	// 境界球イメージの生成
	D3DXCreateSphere(CGraphics::GetDevice(),
		m_fRadius, 32, 16, &m_pSphere, NULL);

	// OBB生成
	float fWidth = vMax.x - vMin.x;
	float fHeight = vMax.y - vMin.y;
	float fDepth = vMax.z - vMin.z;

	m_vOBBHalf.x = fWidth / 2.0f;
	m_vOBBHalf.y = fHeight / 2.0f;
	m_vOBBHalf.z = fDepth / 2.0f;
	// OBBイメージの生成
	D3DXCreateBox(CGraphics::GetDevice() , 
		fWidth , fHeight , fDepth , &m_pBox , NULL);

	return true;
}
Esempio n. 9
0
//
// Framework Functions
//
bool Setup()
{
	//
	// Create objects.
	//

	D3DXCreateTeapot(Device, &Objects[0], 0);
	D3DXCreateSphere(Device, 1.0f, 20, 20, &Objects[1], 0);
	D3DXCreateTorus(Device, 0.5f, 1.0f, 20, 20, &Objects[2], 0);
	D3DXCreateCylinder(Device, 0.5f, 0.5f, 2.0f, 20, 20, &Objects[3], 0);

	//
	// Build world matrices - position the objects in world space.
	//

	D3DXMatrixTranslation(&Worlds[0],  0.0f,  2.0f, 0.0f);
	D3DXMatrixTranslation(&Worlds[1],  0.0f, -2.0f, 0.0f);
	D3DXMatrixTranslation(&Worlds[2], -3.0f,  0.0f, 0.0f);
	D3DXMatrixTranslation(&Worlds[3],  3.0f,  0.0f, 0.0f);

	//
	// Setup the object's materials.
	//

	Mtrls[0] = d3d::RED_MTRL;
	Mtrls[1] = d3d::BLUE_MTRL;
	Mtrls[2] = d3d::GREEN_MTRL;
	Mtrls[3] = d3d::YELLOW_MTRL;

	//
	// Setup a directional light.
	//

	D3DXVECTOR3 dir(1.0f, -0.0f, 0.25f);
	D3DXCOLOR   c = d3d::WHITE;
	D3DLIGHT9 dirLight = d3d::InitDirectionalLight(&dir, &c);

	//
	// Set and Enable the light.
	//

	Device->SetLight(0, &dirLight);
	Device->LightEnable(0, true);

	//
	// Set lighting related render states.
	//

	Device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
	Device->SetRenderState(D3DRS_SPECULARENABLE, false);

	//
	// Set the projection matrix.
	//

	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(
			&proj,
			D3DX_PI * 0.25f, // 45 - degree
			(float)Width / (float)Height,
			1.0f,
			1000.0f);
	Device->SetTransform(D3DTS_PROJECTION, &proj);

	Device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);


	return true;
}
Esempio n. 10
0
//since this is just the base level construction, we'll just make a sphere
bool AvatarConstruction::Construct( char* descriptionFile, DynamicsSolver* solver, Screen3D& Screen,MeshManager& MM, Position& Location, ICollisionHandler* aCollisionHandler )
{
    //deconstruct any old stuff
    Deconstruct();

    //save the solver pointer
    mySolver = solver;

    this->CollisionHandler = aCollisionHandler;

    //create the body list
    ObjectList = new DynamicsObject[1];
    this->nObjects = 1;

    //Create the geom group
    GeomGroup = dSimpleSpaceCreate (solver->GetSpaceID(false));

    //set up surface properties
    ObjectList[0].SurfaceDesc.ContactSlip1 = 0.01f;
    ObjectList[0].SurfaceDesc.ContactSlip2 = 0.01f;

    //set some other properties
    for(int i=0; i<nObjects; i++)
    {
        ObjectList[i].SurfaceDesc.Owner = &ObjectList[i];
        ObjectList[i].SurfaceDesc.ParentConstruction = this;
        ObjectList[i].SurfaceDesc.SoftCFM = .01f;
        ObjectList[i].SurfaceDesc.SoftERP = .1f;
        ObjectList[i].SurfaceDesc.mu	  = 10.0f;

        ObjectList[i].isAvatar = true;
        ObjectList[i].Owner = this;
    }


    //Create the actual body ( a sphere! )
    ObjectList[0].CreateBody( solver );
    dBodySetPosition ( ObjectList[0].Body, Location.x, Location.y, Location.z);
    dMassSetSphere ( &ObjectList[0].Mass, 1.0, 6.0 );
    dMassAdjust (&ObjectList[0].Mass, 1.0 );
    dBodySetMass( ObjectList[0].Body, &ObjectList[0].Mass);
    ObjectList[0].Geom = dCreateSphere (0,6.0);
    dGeomSetData( ObjectList[0].Geom, &ObjectList[0].SurfaceDesc );
    dGeomSetBody (ObjectList[0].Geom,ObjectList[0].Body);
    dSpaceAdd (GeomGroup,ObjectList[0].Geom);
    ObjectList[0].HasGeom = true;

    //create the angular motor
    this->nJoints = 1;
    JointList = new dJointID[nJoints];
    JointList[0] = dJointCreateAMotor( solver->GetWorldID(), 0 );
    dJointSetAMotorMode	( JointList[0], dAMotorUser );
    dJointSetAMotorNumAxes( JointList[0], 3 );
    dJointSetAMotorAxis(JointList[0], 0, 0, 1, 0, 0); //x axis
    dJointSetAMotorAxis(JointList[0], 1, 0, 0, 1, 0); //y axis
    dJointSetAMotorAxis(JointList[0], 2, 0, 0, 0, 1); //z axis
    dJointAttach( JointList[0], ObjectList[0].Body, NULL); //attach to world



    //set some properties
    LinearDisableEpsilon = .2;
    AngularDisableEpsilon = .01f;
    JumpDelay = 1000;
    LastJumpTime = 0;

    ForceEnable = false;
    //create the mesh for drawing
    D3DXCreateSphere( Screen.D3DDevice, 6.0f, 20, 20, &DrawMesh, NULL );



    return true;
}
Esempio n. 11
0
//
// Framework Functions
//
bool Setup()
{
	//
	// Create objects.
	//

	D3DXCreateTeapot(Device, &Objects[0], 0);
	D3DXCreateSphere(Device, 1.0f, 20, 20, &Objects[1], 0);
	D3DXCreateTorus(Device, 0.5f, 1.0f, 20, 20, &Objects[2], 0);
	D3DXCreateCylinder(Device, 0.5f, 0.5f, 2.0f, 20, 20, &Objects[3], 0);

	//
	// Build world matrices - position the objects in world space.
	//

	D3DXMatrixTranslation(&Worlds[0],  0.0f,  2.0f, 0.0f);
	D3DXMatrixTranslation(&Worlds[1],  0.0f, -2.0f, 0.0f);
	D3DXMatrixTranslation(&Worlds[2], -3.0f,  0.0f, 0.0f);
	D3DXMatrixTranslation(&Worlds[3],  3.0f,  0.0f, 0.0f);
	D3DXMATRIX Rx;
	D3DXMatrixRotationX(&Rx, D3DX_PI * 0.5f);
	Worlds[3] = Rx * Worlds[3];

	//
	// Setup the object's materials.
	//

	Mtrls[0] = d3d::RED_MTRL;
	Mtrls[1] = d3d::BLUE_MTRL;
	Mtrls[2] = d3d::GREEN_MTRL;
	Mtrls[3] = d3d::YELLOW_MTRL;

	for(int i = 0; i < 4; i++)
		Mtrls[i].Power = 20.0f;

	//
	// Setup a spot light
	//

	D3DXVECTOR3 pos(0.0f, 0.0f, -5.0f);
	D3DXVECTOR3 dir(0.0f, 0.0f,  1.0f);
	D3DXCOLOR   c = d3d::WHITE;
	Spot = d3d::InitSpotLight(&pos, &dir, &c);

	//
	// Set and Enable spotlight.
	//

	Device->SetLight(0, &Spot);
	Device->LightEnable(0, true);

	//
	// Set light related render states.
	//

	Device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
	Device->SetRenderState(D3DRS_SPECULARENABLE, true);

	//
	// Position and aim the camera.
	//
	D3DXVECTOR3 position( 0.0f, 0.0f, -5.0f );
	D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
	D3DXMATRIX V;
	D3DXMatrixLookAtLH(&V, &position, &target, &up);
	Device->SetTransform(D3DTS_VIEW, &V);

	//
	// Set the 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;
}
Esempio n. 12
0
void cMainGame::Setup()
{
//  	cObjLoader l;
//  	m_pGroupHead = l.Load("./obj/Map.obj");
// 
// 	m_pMesh = l.LoadMesh("./obj/Map.obj", m_vecMtlTex);

	
	//D3DXCreateBox(g_pD3DDevice, 2, 2, 2, &m_pSphere, NULL);
	D3DXCreateTeapot(g_pD3DDevice, &m_pTeapot, NULL);

	// 주전자의 바운딩 정보 획득
	ST_PN_VERTEX* pV = NULL;
	m_pTeapot->LockVertexBuffer(0, (LPVOID*)&pV);
	D3DXComputeBoundingSphere(&pV[0].p,
		m_pTeapot->GetNumVertices(),
		sizeof(ST_PN_VERTEX),
		&m_vTeapotPos,
		&m_fTeapotRadius);
	m_pTeapot->UnlockVertexBuffer();

	// 디버깅용 바운딩 스피어 생성.
	D3DXCreateSphere(g_pD3DDevice, m_fTeapotRadius, 10, 10, &m_pSphere, NULL);
	
// 	cAseLoader loader;
// 	m_pRoot = loader.Load("woman/woman_01_all.ASE");

	ZeroMemory(&m_stWhiteMtl, sizeof(D3DMATERIAL9));
	m_stWhiteMtl.Ambient = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);
	m_stWhiteMtl.Diffuse = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);
	m_stWhiteMtl.Specular = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);

	ZeroMemory(&m_stRedMtl, sizeof(D3DMATERIAL9));
	m_stRedMtl.Ambient = D3DXCOLOR(0.8f, 0.0f, 0.0f, 1.0f);
	m_stRedMtl.Diffuse = D3DXCOLOR(0.8f, 0.0f, 0.0f, 1.0f);
	m_stRedMtl.Specular = D3DXCOLOR(0.8f, 0.0f, 0.0f, 1.0f);


	//폰트 생성
	D3DXFONT_DESC fd;
	ZeroMemory(&fd,sizeof(D3DXFONT_DESC));
	fd.Height			= 45;
	fd.Width			= 28;
	fd.Weight			= FW_MEDIUM;
	fd.Italic			= false;
	fd.CharSet			= DEFAULT_CHARSET;
	fd.OutputPrecision  = OUT_DEFAULT_PRECIS;
	fd.PitchAndFamily   = FF_DONTCARE;
	//strcpy_s(fd.FaceName, "궁서체");	//글꼴 스타일
	AddFontResource("umberto.ttf");
	strcpy(fd.FaceName, "umberto");

	D3DXCreateFontIndirect(g_pD3DDevice, &fd, &m_pFont);

	m_pCamera = new cCamera;
	m_pCamera->Setup(NULL);

	m_pGrid = new cGrid;
	m_pGrid->Setup(15, 1.0f);
	
	SetLight();
}
Esempio n. 13
0
void Sphere::CreateSphere(IDirect3DDevice9 *pD3DDevice, float radius, UINT slices, UINT stacks)
{
	this->m_pD3DDevice = pD3DDevice;
	D3DXCreateSphere(m_pD3DDevice, radius, slices, stacks, &m_pSphereMesh, 0);
}
Esempio n. 14
0
void CEntity::InitSphereMesh()
{
	D3DXCreateSphere( _SINGLE(CDevice)->GetDevice(), 
		GetSize(), (UINT)16, (UINT)16, &m_SphereMesh, NULL);
}
Esempio n. 15
0
void Kinect::InitMesh(int number)
{

	System_Create(&m_pSystem);
	m_pSystem->init(3, FMOD_INIT_NORMAL, 0);
	m_pSystem->createSound("Data/Soccer/엉뚱.mp3", FMOD_LOOP_NORMAL, 0, &m_pSound[0]);
	m_pSystem->createSound("Data/Soccer/클릭음3.wav", FMOD_HARDWARE, 0, &m_pSound[2]);
	m_pSystem->createSound("Data/Soccer/타격음1.wav", FMOD_HARDWARE, 0, &m_pSound[1]);
	m_pSystem->createSound("Data/Soccer/크라잉 넛-03-오 필승 코리아.mp3", FMOD_HARDWARE, 0, &m_pSound[3]);
	m_football.InitMesh("Data/Soccer/FootBall.x");
	
	fireball.LoadFile(g_pDevice, { 0, 0, 0 }, { 0, 0, 0 }, "Data/Soccer/Fireball.png");
	//m_football.m_pMeshMaterials->Ambient = D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.3f);
	//m_football.m_pMeshMaterials ->Diffuse = D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.3f);
	////m_football.m_pMeshMaterials ->Specular = D3DXCOLOR(0.5f, 0.5f, 0.5f, 0.0f);
	//m_football.m_pMeshMaterials ->Power = 8.0f;
	m_ballCall_img.LoadFile(g_pDevice, { 0, 0, 0 }, { 0, 0, 0 }, "Data/Soccer/ball.png");
	m_main_img.LoadFile(g_pDevice, { 0, 0, 0 }, { 0, 0, 0 }, "Data/Soccer/background.png");
	m_StartButton_img.LoadFile(g_pDevice, { 0, 200, 0 }, { 0, 0, 0 }, "Data/Soccer/start.png");
	m_SettingButton_img.LoadFile(g_pDevice, { 0, 300, 0 }, { 0, 0, 0 }, "Data/Soccer/setting.png");
	m_EndButton_img.LoadFile(g_pDevice, { 0, 400, 0 }, { 0, 0, 0 }, "Data/Soccer/endingbutton.png");
	m_autioButton.LoadFile(g_pDevice, { 1000, 100, 0 }, { 0, 0, 0 }, "Data/Soccer/Audio.png");

	ButtonRECT[0].left = 0;
	ButtonRECT[0].right = 410;
	ButtonRECT[0].top = 0;
	ButtonRECT[0].bottom = 94;


	ButtonRECT[1].left = 410;
	ButtonRECT[1].right = 820;
	ButtonRECT[1].top = 0;
	ButtonRECT[1].bottom = 94;


	m_StartButton_img.rect = ButtonRECT[0];
	m_SettingButton_img.rect = ButtonRECT[0];
	m_EndButton_img.rect = ButtonRECT[0];
	m_autioButton.rect = ButtonRECT[0];
	fireRect[0].left = 0;
	fireRect[0].right = 192;
	fireRect[0].top = 0;
	fireRect[0].bottom = 192;
	int tempnum = 192;

	for (int i = 1; i < 5; i++)
	{
		fireRect[i].left = tempnum;
		tempnum += 192;
		fireRect[i].top = 0;
		fireRect[i].bottom = 192;
		fireRect[i].right = tempnum;
		
	}
	enemy.InitMesh("Data/Soccer/football.x");
	m_goalpost.InitMesh("Data/Soccer/GoalPost2.X");
	m_teaspot.InitMesh("Data/Soccer/teapot.X");
	stadium.InitMesh("Data/Soccer/Stadium.X");
	m_player = new CSkinnedMesh[2];
	m_player[0].LoadMesh(g_pDevice, CUtility::GetTheCurrentDirectory() + "/Data/Soccer/ironman2.X");//모델링위치
	
	D3DXCreateBox(g_pDevice, 1, 1, 0, &m_pBox, NULL);
	D3DXCreateSphere(g_pDevice, 1, 1, 1, &m_pSphere, NULL);
	VertexPNT* v = 0;
	/*m_football.m_pMesh->LockVertexBuffer(0, (void**)&v);

	D3DXComputeBoundingBox(&v[0].pos, m_football.m_pMesh->GetNumVertices(),
		sizeof(VertexPNT), &m_football.mBoundingBox.minPt, &m_football.mBoundingBox.maxPt);

	m_football.m_pMesh->UnlockVertexBuffer();*/

	//float width = m_football.mBoundingBox.maxPt.x - m_football.mBoundingBox.minPt.x;
	//float height = m_football.mBoundingBox.maxPt.y - m_football.mBoundingBox.minPt.y;
	//float depth = m_football.mBoundingBox.maxPt.z - m_football.mBoundingBox.minPt.z;
	
	//m_player2 = new CSkinnedMesh[2];
	//m_player2[0].LoadMesh(g_pDevice,CUtility::GetTheCurrentDirectory() + "/Data/Soccer/ironman.X");//모델링위치
	
	

}