Пример #1
0
/**
 * @brief 敵を描画する
 *
 */
void Enemy::render()
{
    LPDIRECT3DDEVICE9 pDevice = DXUTGetD3D9Device();

    D3DXMATRIXA16 worldMatrix;
    D3DXMatrixTranslation(&worldMatrix, m_position.x, m_position.y, m_position.z);
    pDevice->SetTransform(D3DTS_WORLD, &worldMatrix);

    for (DWORD i = 0; i < s_numberOfMaterials; ++i) {
        if (this->isDead()) {
            if (m_dieOutTime <= 0) {
                return;
            }

            // 死亡時は、消滅するまで徐々に赤から色を黒くしていく
            D3DMATERIAL9 deadMaterial = s_deadMaterial;
            float red = m_dieOutTime / GameConfiguration::s_ENEMY_DIE_OUT_TIME;
            if (red < 0.50f) {
                red = 0.5f;
            }
            deadMaterial.Diffuse.r = deadMaterial.Ambient.r = red;
            pDevice->SetMaterial(&deadMaterial);
        }
        else {
            pDevice->SetMaterial(&s_meshMaterials.at(i));
        }
        pDevice->SetTexture(0, s_meshTexturePointers.at(i));

        s_pMesh->DrawSubset(i);
    }

#ifdef DEBUG
    s_debugCollision.render();
#endif
}
Пример #2
0
VOID render(){
	g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
		D3DCOLOR_XRGB(192, 192, 192), 1.0f, 0);

	if(SUCCEEDED(g_pDevice->BeginScene())){

		setWorldMatrix();
		//First, Render the not transparent part
		for(DWORD i=0; i<g_dwNumMaterials; ++i){
			if(g_pMeshMaterials[i].Diffuse.a == 1.0f){
				g_pDevice->SetMaterial(&g_pMeshMaterials[i]);
				g_pDevice->SetTexture(0, g_pMeshTextures[i]);

				g_pMesh->DrawSubset(i);
			}
		}

		//Second , Render the transparent part
		for(DWORD i=0; i<g_dwNumMaterials; ++i){
			if(g_pMeshMaterials[i].Diffuse.a != 1.0f){
				g_pDevice->SetMaterial(&g_pMeshMaterials[i]);
				g_pDevice->SetTexture(0, g_pMeshTextures[i]);

				g_pMesh->DrawSubset(i);
			}
		}
		g_pDevice->EndScene();
	}
	g_pDevice->Present(NULL, NULL, NULL, NULL);
}
Пример #3
0
//=============================================================================
// 描画処理
//=============================================================================
void DrawEnemy(void)
{
	LPDIRECT3DDEVICE9 pDevice = GetDevice();
	D3DXMATRIX mtxScl, mtxRot, mtxTranslate;
	D3DXMATERIAL *pD3DXMat;
	D3DMATERIAL9 matDef;

	for(int nCntEnemy = 0; nCntEnemy < MAX_ENEMY; nCntEnemy++)
	{
		if(g_enemy[nCntEnemy].bUse)
		{
			// ワールドマトリックスの初期化
			D3DXMatrixIdentity( &g_enemy[nCntEnemy].mtxWorld);
	
			// スケールを反映
			D3DXMatrixScaling( &mtxScl, g_enemy[nCntEnemy].scl.x, g_enemy[nCntEnemy].scl.y, g_enemy[nCntEnemy].scl.z);
			D3DXMatrixMultiply( &g_enemy[nCntEnemy].mtxWorld, &g_enemy[nCntEnemy].mtxWorld, &mtxScl);
	
			// 回転を反映
			D3DXMatrixRotationYawPitchRoll( &mtxRot, g_enemy[nCntEnemy].rot.y, g_enemy[nCntEnemy].rot.x, g_enemy[nCntEnemy].rot.z);
			D3DXMatrixMultiply( &g_enemy[nCntEnemy].mtxWorld, &g_enemy[nCntEnemy].mtxWorld, &mtxRot);
	
			// 移動を反映
			D3DXMatrixTranslation( &mtxTranslate, g_enemy[nCntEnemy].pos.x, g_enemy[nCntEnemy].pos.y, g_enemy[nCntEnemy].pos.z);
			D3DXMatrixMultiply( &g_enemy[nCntEnemy].mtxWorld, &g_enemy[nCntEnemy].mtxWorld, &mtxTranslate);
	
			// ワールドマトリックスの設定
			pDevice->SetTransform( D3DTS_WORLD, &g_enemy[nCntEnemy].mtxWorld);

			// 現在のマテリアルを取得
			pDevice->GetMaterial(&matDef);
	
			
			ENEMY_TYPE type = g_enemy[nCntEnemy].type;
			// マテリアル情報に対するポインタを取得
			pD3DXMat = (D3DXMATERIAL *)g_modelData[type].pD3DXBuffMat->GetBufferPointer();
			for(int nCntMat = 0; nCntMat < (int)g_modelData[type].nNumMat; nCntMat++)
			{
				// マテリアルの設定
				pDevice->SetMaterial( &pD3DXMat[nCntMat].MatD3D);
				// テクスチャの設定
				pDevice->SetTexture( 0, g_modelData[type].pD3DTexture);
				// 描画
				g_modelData[type].pD3DXMesh->DrawSubset( nCntMat);
			}

			// マテリアルをデフォルトに戻す
			pDevice->SetMaterial( &matDef);		
		}
	}

}
Пример #4
0
	//	球描画
	void	DrawSphere( LPDIRECT3DDEVICE9 d3dd, CONST D3DXVECTOR3 &p0, FLOAT r, D3DCOLOR c )
	{
		CONST INT N = 36;

		static _VB vb( d3dd, sizeof( D3DXVECTOR3 ) * ( N + 1 ) );
		for ( int n = 0; n < 3; n++ )
		{
			D3DXVECTOR3 *p;
			vb->Lock( 0, 0, ( void ** )&p, 0 );
			for ( int i = 0; i < N; i++ )
			{
				switch (  n )
				{
				case 0: p[i] = r * D3DXVECTOR3( sinf( 360.0f / N * 0.01745f * i ), cosf( 360.0f / N * 0.01745f * i ), 0 ) + p0; break;
				case 1: p[i] = r * D3DXVECTOR3( sinf( 360.0f / N * 0.01745f * i ), 0, cosf( 360.0f / N * 0.01745f * i ) ) + p0; break;
				case 2: p[i] = r * D3DXVECTOR3( 0, sinf( 360.0f / N * 0.01745f * i ), cosf( 360.0f / N * 0.01745f * i ) ) + p0; break;
				}
			}
			p[N] = p[0];
			vb->Unlock();

			D3DMATERIAL9 m = { 0 };
			m.Diffuse = m.Ambient = D3DXCOLOR( c );
			d3dd->SetMaterial( &m );

			d3dd->SetFVF( D3DFVF_XYZ );
			d3dd->SetStreamSource( 0, vb, 0, sizeof( D3DXVECTOR3 ) );
			d3dd->SetTransform( D3DTS_WORLD, &D3DXMATRIX( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ) );
			d3dd->DrawPrimitive( D3DPT_LINESTRIP, 0, N );
		}
	}
Пример #5
0
//-----------------------------------------------------------------------------
// Name: render_1()
// Desc:
//-----------------------------------------------------------------------------
void render_1( void )
{
    D3DXMATRIX matView;
    D3DXMATRIX matWorld;
    D3DXMATRIX matRotation;
    D3DXMATRIX matTranslation;

    // Now we can clear just view-port's portion of the buffer to green...
    g_pd3dDevice_1->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE( 0.0f, 1.0f, 0.0f, 1.0f ), 1.0f, 0 );

    g_pd3dDevice_1->BeginScene();

    // For the left view-port, leave the view at the origin...
    D3DXMatrixIdentity( &matView );
    g_pd3dDevice_1->SetTransform( D3DTS_VIEW, &matView );

    // ... and use the world matrix to spin and translate the teapot
    // out where we can see it...
    D3DXMatrixRotationYawPitchRoll( &matRotation, D3DXToRadian(g_fSpinX), D3DXToRadian(g_fSpinY), 0.0f );
    D3DXMatrixTranslation( &matTranslation, 0.0f, 0.0f, 5.0f );
    matWorld = matRotation * matTranslation;
    g_pd3dDevice_1->SetTransform( D3DTS_WORLD, &matWorld );


    g_pd3dDevice_1->SetMaterial( &g_teapotMtrl );
    g_pTeapotMesh_1->DrawSubset(0);

    g_pd3dDevice_1->EndScene();

    // We're done! Now, we just call Present()
    g_pd3dDevice_1->Present( NULL, NULL, NULL, NULL );
}
Пример #6
0
//**関数***************************************************************************
//	概要	:	メッシュ半透明部分のみ描画 (アルファ有効化/無効化なし)
//*********************************************************************************
void CMesh::DrawAlpha(D3DXMATRIX& world , S_HANDLE nShadeHndle)
{
	// ワールド マトリックス設定
    LPDIRECT3DDEVICE9 pDevice = CGraphics::GetDevice();
	CShader* pShade = REGISTER_H_P(nShadeHndle , CShader*);
	
	if(nShadeHndle == 0)
		pDevice->SetTransform(D3DTS_WORLD, &world);
	else
		pShade->SetWorldMatrix(&world);

	for (DWORD i = 0; i < m_dwAttr; i++) 
	{
		DWORD id = m_pAttr[i].AttribId;
        // アルファ値をチェック
        D3DMATERIAL9 mtrl = m_pMaterial[id];
		if (mtrl.Diffuse.a >= 1.0f)
			continue;

		if(nShadeHndle == 0)
		{
			pDevice->SetMaterial(&mtrl);
			pDevice->SetTexture(0, m_ppTexture[id]);	// テクスチャを設定
		}
		else
			pShade->SetMaterial(&mtrl , m_ppTexture[id]);

		m_pD3DMesh->DrawSubset(id);					// 描画を実行
	}
}
Пример #7
0
//**関数***************************************************************************
//	概要	:	OBBの描画
//*********************************************************************************
void CMesh::DrawBox(D3DXMATRIX& world, D3DCOLORVALUE color)
{
    LPDIRECT3DDEVICE9 pDevice = CGraphics::GetDevice();

	// ワールド マトリックス設定
	D3DXMATRIX m;
	D3DXMatrixTranslation(&m, m_vCenter.x, m_vCenter.y, m_vCenter.z);
	m *= world;
    pDevice->SetTransform(D3DTS_WORLD, &m);

    // アルファ ブレンド有効化
	pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
    pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

	// メッシュ描画
	D3DMATERIAL9 mtrl = {
		color,//Diffuse
		color,//Ambient
		{1.0f, 1.0f, 1.0f, 1.0f},//Specular
		{0.0f, 0.0f, 0.0f, 1.0f},//Emissive
		1.0f//Power
	};

	pDevice->SetMaterial(&mtrl);
	pDevice->SetTexture(0, NULL);
	pDevice->SetFVF(D3DFVF_XYZ |
		D3DFVF_NORMAL | D3DFVF_TEX1);
	m_pBox->DrawSubset(0);

    // アルファ ブレンド無効化
    pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
Пример #8
0
//**関数***************************************************************************
//	概要	:	半透明描画
//*********************************************************************************
void CMesh::Draw(D3DXMATRIX& world, float fAlpha)
{
    // ワールド マトリックス設定
    LPDIRECT3DDEVICE9 pDevice = CGraphics::GetDevice();
    pDevice->SetTransform(D3DTS_WORLD, &world);

    // アルファ ブレンド有効化
    pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
    pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

    for (DWORD i = 0; i < m_dwAttr; i++) {
        DWORD id = m_pAttr[i].AttribId;

        // アルファ値を変更
        D3DMATERIAL9 mtrl = m_pMaterial[id];
        mtrl.Diffuse.a *= fAlpha;
        pDevice->SetMaterial(&mtrl);

        pDevice->SetTexture(0, m_ppTexture[id]);
        pDevice->SetFVF(FVF_BVERTEX);

		pDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST,
			m_pAttr[i].FaceCount,
			&m_pPieceVtx[m_pAttr[i].FaceStart * 3],
			sizeof(BVERTEX));
    }

    // アルファ ブレンド無効化
    pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
Пример #9
0
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render(bool b_AutoRotation, bool b_WireframeMode)
{
    // Clear the backbuffer and the zbuffer
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
                         D3DCOLOR_ARGB( 0, 0, 0, 0 ), 1.0f, 0 );

    // Begin the scene
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
        // Setup the world, view, and projection matrices
		// SetupMatrices();
        if (b_AutoRotation) SetupMatrices();
		g_pd3dDevice->SetRenderState(D3DRS_FILLMODE, (b_WireframeMode) ? D3DFILL_WIREFRAME : D3DFILL_SOLID);
		g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, (b_WireframeMode) ? D3DCULL_NONE : D3DCULL_CCW);

        // D3DRenderer are divided into subsets, one for each material. Render them in
        // a loop
        for( DWORD i = 0; i < g_dwNumMaterials; i++ )
        {
            // Set the material and texture for this subset
            g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
            g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );

            // Draw the mesh subset
            g_pMesh->DrawSubset( i );
        }

        // End the scene
        g_pd3dDevice->EndScene();
    }

    // Present the backbuffer contents to the display
    // g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Пример #10
0
	type_result HierarchySubReferer::_render( D3DMATERIAL9& material )
	{
		_initializeMesh();
		//	main:
		//		DX9 바인딩:
		DX9& dx9 = getDependent();
		if( ! &dx9)
		{
			ALERT_ERROR(" : 디바이스 바인딩 실패로 중지");
			return RESULT_TYPE_ERROR;
		}
		LPDIRECT3DDEVICE9 device = dx9.getDevice();		
		//		월드좌표 갱신:
		D3DXMATRIX& world = getWorldMatrix();
		D3DXMATRIX origin;
		device->GetTransform(D3DTS_WORLD, &origin);
		device->SetTransform(D3DTS_WORLD, &world);

		device->SetRenderState(D3DRS_AMBIENT, 0xffffffff);

		//device->SetTexture(0, NULL);
		device->SetMaterial(&material);
		device->SetTexture(0, 0);
		if(_ball)
		{			
			_ball->DrawSubset(0);
		}

		//		자식과 선을 잇기:
		device->SetTransform(D3DTS_WORLD, &origin);

		_searchModuleSet(getConnector().getModuleCodeSetKey().getValue(), &ThisClass::_renderLineBetweenChild);			//		월드 좌표 복귀:
		return RESULT_SUCCESS;
	}
Пример #11
0
//-----------------------------------------------------------------------------
// Name: SetupLights()
// Desc: Sets up the lights and materials for the scene.
//-----------------------------------------------------------------------------
VOID SetupLights()
{
    // Set up a material. The material here just has the diffuse and ambient
    // colors set to yellow. Note that only one material can be used at a time.
    D3DMATERIAL9 mtrl;
    ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) );
    mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f;
    mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f;
    mtrl.Diffuse.b = mtrl.Ambient.b = 0.0f;
    mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f;
    g_pd3dDevice->SetMaterial( &mtrl );

    // Set up a white, directional light, with an oscillating direction.
    // Note that many lights may be active at a time (but each one slows down
    // the rendering of our scene). However, here we are just using one. Also,
    // we need to set the D3DRS_LIGHTING renderstate to enable lighting
    D3DXVECTOR3 vecDir;
    D3DLIGHT9 light;
    ZeroMemory( &light, sizeof(D3DLIGHT9) );
    light.Type       = D3DLIGHT_DIRECTIONAL;
    light.Diffuse.r  = 1.0f;
    light.Diffuse.g  = 1.0f;
    light.Diffuse.b  = 1.0f;
    vecDir = D3DXVECTOR3(cosf(timeGetTime()/350.0f),
                         1.0f,
                         sinf(timeGetTime()/350.0f) );
    D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );
    light.Range       = 1000.0f;
    g_pd3dDevice->SetLight( 0, &light );
    g_pd3dDevice->LightEnable( 0, TRUE );
    g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );

    // Finally, turn on some ambient light.
    g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00202020 );
}
Пример #12
0
// ---------- framework : display ----------
bool rtvsD3dApp::display (LPDIRECT3DDEVICE9 pd3dDevice)
{
 	// clear backbuffers
  pd3dDevice->Clear( 0,
	NULL,
	D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
	D3DCOLOR_COLORVALUE(0.0f,0.3f,0.7f,1.0f),
	1.0f,
	0);

  // check if should render
  if (m_antShouldRender) { // ant says render
    if (
      !m_pTracer->m_shouldRender // tracer isn't rendering
      && !m_pTracer->m_isRenderDone // tracer isn't done
    ) { 
      // tell it to render
      m_pTracer->startRender();
    }
    else if (
      !m_pTracer->m_shouldRender // tracer isn't rendering
      && m_pTracer->m_isRenderDone // tracer is done
    ) {
      // reset and tell it to render
      m_pTracer->resetRender(pTexture);
      m_pTracer->startRender();
    }
  }
  else // ant says don't render
  {
    if(m_pTracer->m_shouldRender) // tracer is rendering
      m_pTracer->m_shouldRender = false; // tell it to stop
  }

  // if tracer should be rendering
  if(m_pTracer->m_shouldRender)
  {
    // trace line by line & check if done
    m_antShouldRender = m_pTracer->traceNextLine();

    // try to render
    returnvalue = m_pTracer->render(pTexture);
    if (FAILED(returnvalue))
      return false;
  }

	// display solid textured quad
	pd3dDevice->SetMaterial( &quadMtrl );
	pd3dDevice->SetTexture( 0, pTexture );
	pd3dDevice->SetStreamSource( 0, pQuadVertexBuffer, 0, sizeof(QuadVertex) );
	pd3dDevice->SetFVF( QuadVertex::FVF_Flags );
	pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
	pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, numQuadTriangles );

	TwDraw();  // draw the tweak bar GUI

	// ok
	return true;

}
Пример #13
0
void InitLight()
{
    D3DMATERIAL9 material;    // create the material struct

	D3DLIGHT9 light;    // create the light struct
	ZeroMemory(&light, sizeof(light));    // clear out the light struct for use
    light.Type = D3DLIGHT_DIRECTIONAL;    // make the light type 'directional light'
    light.Diffuse = D3DXCOLOR(0.7f, 0.7f, 0.7f, 1.0f);    // set the light's color
    light.Position = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
	light.Direction = D3DXVECTOR3(0.5f, -1.0f, -1.0f);
    d3ddev->SetLight(0, &light);    // send the light struct properties to light #0
    d3ddev->LightEnable(0, TRUE);    // turn on light #0

	D3DLIGHT9 pointLight;    // create the light struct
	ZeroMemory(&pointLight, sizeof(pointLight));    // clear out the light struct for use
	pointLight.Type = D3DLIGHT_POINT;    // make the light type 'point light'
	pointLight.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);    // set the light's color
	pointLight.Position = D3DXVECTOR3(0.0f, 7.0f, 5.0f);
	//pointLight.Direction = D3DXVECTOR3(0.5f, -1.0f, -1.0f);
	pointLight.Range = 100.0f;
	pointLight.Attenuation0 = 0.0f;    // no constant inverse attenuation
	pointLight.Attenuation1 = 0.125f;    // only .125 inverse attenuation
	pointLight.Attenuation2 = 0.0f;    // no square inverse attenuation
	d3ddev->SetLight(1, &pointLight);    // send the light struct properties to light #0
	d3ddev->LightEnable(1, TRUE);    // turn on light #1

    ZeroMemory(&material, sizeof(D3DMATERIAL9));    // clear out the struct for use
    material.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);    // set diffuse color to white
    material.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);    // set ambient color to white

    d3ddev->SetMaterial(&material);    // set the globably-used material to &material
}
Пример #14
0
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
    // Clear the backbuffer and the zbuffer
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 
                         D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
    
    // Begin the scene
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
        // Setup the world, view, and projection matrices
        SetupMatrices();

        // Meshes are divided into subsets, one for each material. Render them in
        // a loop
        for( DWORD i=0; i<g_dwNumMaterials; i++ )
        {
            // Set the material and texture for this subset
            g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
            g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );
        
            // Draw the mesh subset
            g_pMesh->DrawSubset( i );
        }

        // End the scene
        g_pd3dDevice->EndScene();
    }

    // Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Пример #15
0
//-----------------------------------------------------------------------------
// Desc: 渲染场景
//-----------------------------------------------------------------------------
VOID Render()
{
	// 清除缓冲区
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 
		D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

	//开始渲染场景
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		SetWorldMatrix();  //设置世界矩阵

		//逐块渲染网格模型
		for( DWORD i=0; i<g_dwNumMaterials; i++ )
		{
			//设置材料和纹理
			g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
			g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );

			//渲染模型
			g_pMesh->DrawSubset( i );
		}

		//场景渲染结束
		g_pd3dDevice->EndScene();
	}

	//在屏幕上显示场景
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Пример #16
0
void Render()
{
    g_pd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
    g_pd3dDevice->BeginScene();

    D3DXMATRIXA16 matWorld;
    D3DXMatrixRotationY(&matWorld, timeGetTime() / 1000.0f);
    g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);

    D3DXVECTOR3 vEyePt(0.0f, 3.0f,-5.0f);
    D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 0.0f);
    D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f);
    D3DXMATRIXA16 matView;
    D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec);
    g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView);

    D3DXMATRIXA16 matProj;
    D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 4, 1.0f, 1.0f, 100.0f);
    g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);

    for (DWORD i = 0; i < g_dwNumMaterials; i++)
    {
        g_pd3dDevice->SetMaterial(&g_pMeshMaterials[i]);
        g_pd3dDevice->SetTexture(0, g_pMeshTextures[i]);
        g_pMesh->DrawSubset(i);
    }

    g_pd3dDevice->EndScene();
    g_pd3dDevice->Present(0, 0, 0, 0);
}
Пример #17
0
//랜더
void Render(int timeDelta)
{
	//화면 청소
	if (SUCCEEDED(g_pDevice->Clear( 
		0,			//청소할 영역의 D3DRECT 배열 갯수		( 전체 클리어 0 )
		NULL,		//청소할 영역의 D3DRECT 배열 포인터		( 전체 클리어 NULL )
		D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL,	//청소될 버퍼 플레그 ( D3DCLEAR_TARGET 컬러버퍼, D3DCLEAR_ZBUFFER 깊이버퍼, D3DCLEAR_STENCIL 스텐실버퍼
		D3DCOLOR_XRGB(0,0,0),			//컬러버퍼를 청소하고 채워질 색상( 0xAARRGGBB )
		1.0f,				//깊이버퍼를 청소할값 ( 0 ~ 1 0 이 카메라에서 제일가까운 1 이 카메라에서 제일 먼 )
		0					//스텐실 버퍼를 채울값
		)))
	{
		//화면 청소가 성공적으로 이루어 졌다면... 랜더링 시작
		g_pDevice->BeginScene();

		//r.SetTranslate(Vector3(0, 0, -498)); // teapot
		g_pDevice->SetTransform(D3DTS_WORLD, (D3DXMATRIX*)&g_LocalTm);

		g_pDevice->SetMaterial(&g_Mtrl);
		if (g_Mesh)
			g_Mesh->DrawSubset(0);

		//랜더링 끝
		g_pDevice->EndScene();
		//랜더링이 끝났으면 랜더링된 내용 화면으로 전송
		g_pDevice->Present( NULL, NULL, NULL, NULL );
	}
}
Пример #18
0
void CTile::Render(LPDIRECT3DDEVICE9 _device)
{
	_device->SetStreamSource( 0, m_pVB, 0, sizeof(TILEVERTEX) );
	_device->SetFVF( D3DFVF_CUSTOMVERTEX );
	_device->SetIndices( m_pIB );

	if(_b == true){
		_device->SetMaterial(&m_matrl);
	}else{
		ZeroMemory(&m_matrl, sizeof(D3DMATERIAL9));
		_device->SetMaterial(&m_matrl);
	}

	_device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 6, 0, 2);
	//_device->DrawPrimitive(D3DPT_TRIANGLELIST,0,2);
}
Пример #19
0
VOID SetupLights()
{
    // 初始化一个材料
	
    D3DMATERIAL9 mtrl;
    ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) );
    mtrl.Diffuse = mtrl.Ambient = D3DXCOLOR(1.0f,1.0f,0.0f,1.0f); //材质有漫射和环境光的设置,都为黄色
    g_pd3dDevice->SetMaterial( &mtrl );

    // 初始化一个白色的方向光
	///*
    D3DXVECTOR3 vecDir;
    D3DLIGHT9 light;
    ZeroMemory( &light, sizeof(D3DLIGHT9) );
    light.Type       = D3DLIGHT_DIRECTIONAL;//方向光
	light.Diffuse = D3DXCOLOR(1.0f,1.0f,1.0f,1.0f);//设置光源的漫射光颜色为白色
	light.Direction = D3DXVECTOR3(0.0f,0.0f,1.0f);//光的传播方向平行z轴
    light.Range       = 1000.0f;
    g_pd3dDevice->SetLight( 0, &light );
    g_pd3dDevice->LightEnable( 0, TRUE );
    g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );

    // Finally, turn on some ambient light.
    g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00202020 );
}
Пример #20
0
bool ObjectInit(HWND hwnd)
{
	srand(unsigned(time(nullptr)));
	PlaySound(_T("コミネリサ - Resuscitated Hope.wav"), nullptr, SND_ASYNC | SND_FILENAME | SND_LOOP);

	if (FAILED(D3DXCreateFont(gPD3DDevice, 38, 0, 0, 0, 0, 0, 0, 0, 0, _T("楷体"), &gPFont)))
	{
		return false;
	}
	D3DXCreateTeapot(gPD3DDevice, &gPTeapot, 0);
	D3DXCreateBox(gPD3DDevice, 2, 2, 2, &gPBox, 0);
	D3DXCreateTorus(gPD3DDevice, 1.0f, 2.0f, 25, 25, &gPTorus, 0);
	D3DXCreateSphere(gPD3DDevice, 2.0f, 25, 25, &gPSphere, 0);

	//D3DMATERIAL9 is a struct with diffuse, specular, ambient, and emissive;
	//There is also power typed float, however its usage not known yet.
	D3DMATERIAL9 material;
	ZeroMemory(&material, sizeof(material));
	material.Ambient = D3DXCOLOR(0.5f, 0.5f, 0.7f, 1.0f);
	material.Diffuse = D3DXCOLOR(0.4f, 0.6f, 0.6f, 1.0f);
	material.Specular = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f);
	material.Emissive = D3DXCOLOR(0.3f, 0.0f, 0.1f, 1.0f);
	gPD3DDevice->SetMaterial(&material);	

	return true;
}
Пример #21
0
void Cube::Render(LPDIRECT3DDEVICE9 pd3dDevice, DWORD dwAttribId) {
    // Set texture
    if (!m_pTexture) {
        m_pTexture = LoadTexture(pd3dDevice, "snow.bmp");
    }
    std::map<int, DWORD> mDwRenderState;
    pd3dDevice->SetTransform(D3DTS_WORLD, GetTransform());
    if (m_bBlending) {
        DWORD dwState;
        pd3dDevice->GetRenderState(D3DRS_ALPHABLENDENABLE, &dwState);
        mDwRenderState[D3DRS_SRCBLEND] = dwState;
        pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

        pd3dDevice->GetRenderState(D3DRS_SRCBLEND, &dwState);
        mDwRenderState[D3DRS_SRCBLEND] = dwState;
        pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);

        pd3dDevice->GetRenderState(D3DRS_DESTBLEND, &dwState);
        mDwRenderState[D3DRS_DESTBLEND] = dwState;
        pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
    } /*else {
        pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
        pd3dDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
    }  */  
    pd3dDevice->SetMaterial(&m_d3dMaterial);
    pd3dDevice->SetTexture(0, m_pTexture);
    m_pMesh->DrawSubset(dwAttribId);

    if (m_bBlending) {
        for (auto &it : mDwRenderState) {
            pd3dDevice->SetRenderState((D3DRENDERSTATETYPE)it.first, it.second);
        }
    }
}
Пример #22
0
VOID render(){
	g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
		D3DCOLOR_XRGB(192, 192, 192), 1.0f, 0);

	if(SUCCEEDED(g_pDevice->BeginScene())){
		
		//Render the Shutter
		g_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
		g_pDevice->SetTransform(D3DTS_WORLD, &g_matShutter);
		g_pDevice->SetStreamSource(0, g_pShutter, 0, sizeof(CUSTOMVERTEX));
		g_pDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
		g_pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

		//Render the Mesh
		g_pDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
		g_pDevice->SetTransform(D3DTS_WORLD, &g_matTank);
		for(DWORD i=0; i<g_dwNumMaterials; ++i){
			g_pDevice->SetMaterial(&g_pMeshMaterials[i]);
			g_pDevice->SetTexture(0, g_pMeshTextures[i]);

			g_pMesh->DrawSubset(i);
		}//Render the Mesh
		g_pDevice->EndScene();
	}
	g_pDevice->Present(NULL, NULL, NULL, NULL);
}
VOID SetupLights()
{
	D3DMATERIAL9 mtrl;
	ZeroMemory( &mtrl, sizeof( D3DMATERIAL9 ) );
	mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f;
	mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f;
	mtrl.Diffuse.b = mtrl.Ambient.b = 1.0f;
	mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f;
	g_pd3dDevice->SetMaterial( &mtrl );

	D3DXVECTOR3 vecDir;
	D3DLIGHT9 light;
	ZeroMemory( &light, sizeof( D3DLIGHT9 ) );
	light.Type = D3DLIGHT_DIRECTIONAL;
	light.Diffuse.r = 1.0f;
	light.Diffuse.g = 1.0f;
	light.Diffuse.b = 1.0f;
	vecDir = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
	D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );
	light.Range = 1000.0f;
	g_pd3dDevice->SetLight( 0, &light );
	g_pd3dDevice->LightEnable( 0, true );

	g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
	g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0xFFA0A0A0 );
}
/**-----------------------------------------------------------------------------
 * 광원 설정
 *------------------------------------------------------------------------------
 */
VOID SetupLights()
{
    /// 재질(material)설정
    /// 재질은 디바이스에 단 하나만 설정될 수 있다.
    D3DMATERIAL9 mtrl;
    ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) );
    mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f;
    mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f;
    mtrl.Diffuse.b = mtrl.Ambient.b = 1.0f;
    mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f;
    g_pd3dDevice->SetMaterial( &mtrl );

    /// 광원 설정
    D3DXVECTOR3 vecDir;									/// 방향성 광원(directional light)이 향할 빛의 방향
    D3DLIGHT9 light;									/// 광원 구조체
    ZeroMemory( &light, sizeof(D3DLIGHT9) );			/// 구조체를 0으로 지운다.
    light.Type       = D3DLIGHT_DIRECTIONAL;			/// 광원의 종류(점 광원,방향성 광원,스포트라이트)
    light.Diffuse.r  = 1.0f;							/// 광원의 색깔과 밝기
    light.Diffuse.g  = 1.0f;
    light.Diffuse.b  = 0.0f;
    vecDir = D3DXVECTOR3( 1, 1, 1 );					/// 광원 고정
    vecDir = D3DXVECTOR3(cosf(GetTickCount()/350.0f),	/// 광원 회전
                         1.0f,
                         sinf(GetTickCount()/350.0f) );
    D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );	/// 광원의 방향을 단위벡터로 만든다.
    light.Range       = 1000.0f;									/// 광원이 다다를수 있는 최대거리
    g_pd3dDevice->SetLight( 0, &light );							/// 디바이스에 0번 광원 설치
    g_pd3dDevice->LightEnable( 0, TRUE );							/// 0번 광원을 켠다
    g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );			/// 광원설정을 켠다

    g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00909090 );		/// 환경광원(ambient light)의 값 설정
}
Пример #25
0
//-----------------------------------------------------------------------------
// Desc: 设置材质和灯光
//-----------------------------------------------------------------------------
VOID SetLight()
{
	//设置材质
	D3DMATERIAL9 mtrl;
	ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) );
	mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f;
	mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f;
	mtrl.Diffuse.b = mtrl.Ambient.b = 0.0f;
	mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f;
	g_pd3dDevice->SetMaterial( &mtrl );

	//设置灯光
	D3DXVECTOR3 vecDir;
	D3DLIGHT9 light;
	ZeroMemory( &light, sizeof(D3DLIGHT9) );
	light.Type       = D3DLIGHT_DIRECTIONAL;
	light.Diffuse.r  = 1.0f;
	light.Diffuse.g  = 1.0f;
	light.Diffuse.b  = 1.0f;
	vecDir = D3DXVECTOR3(
		cosf(timeGetTime()/350.0f),
		1.0f,
		sinf(timeGetTime()/350.0f) );
	vecDir = D3DXVECTOR3(1.0f, 1.0f, 0.0f);
	D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );
	light.Range       = 1000.0f;
	g_pd3dDevice->SetLight( 0, &light );
	g_pd3dDevice->LightEnable( 0, TRUE );
	g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );

	//设置环境光
	g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00505050);
}
Пример #26
0
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
	// Clear the backbuffer and the zbuffer
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
		D3DCOLOR_XRGB( 0, 0, 0 ), 1.0f, 0 );

	// Begin the scene
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		// Setup the world, view, and projection matrices
		SetupMatrices();

		SetupLights();

		// Meshes are divided into subsets, one for each material. Render them in
		// a loop
		for( DWORD i = 0; i < g_dwNumMaterials; i++ )
		{
			// Set the material and texture for this subset
			g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
			g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );

			// Draw the mesh subset
			g_pMesh->DrawSubset( i );
		}
		D3DXMATRIXA16 mat;
		D3DXMatrixTranslation( &mat, 1,0,0 );
		g_pd3dDevice->SetTransform( D3DTS_WORLD, &mat );
		for( DWORD i = 0; i < g_dwNumMaterials2; i++ )
		{
			// Set the material and texture for this subset
			g_pd3dDevice->SetMaterial( &g_pMeshMaterials2[i] );
			g_pd3dDevice->SetTexture( 0, g_pMeshTextures2[i] );

			// Draw the mesh subset
			g_pMesh->DrawSubset( i );
		}

		// End the scene
		g_pd3dDevice->EndScene();
	}
	LPDIRECT3DTEXTURE9* pTemp = g_pMeshTextures;
	g_pMeshTextures = g_pMeshTextures2;
	g_pMeshTextures2 = pTemp;
	// Present the backbuffer contents to the display
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Пример #27
0
 /* ================ */
 virtual void commit ()
 {
     if (m_map_kd != NULL)
         m_device->SetTexture(0, m_map_kd->obj.base);
     else
         m_device->SetTexture(0, NULL);
     m_device->SetMaterial(&m_mtl);
 }
Пример #28
0
void Mesh::Draw(LPDIRECT3DDEVICE9 pDevice)
{
	for(DWORD i = 0; i < m_iNumMtrls; i++)
	{
		pDevice->SetMaterial(&m_vMtrls[i]);
		m_mesh->DrawSubset(i);
	}
}
Пример #29
0
 /* ================ */
 virtual void commit ()
 {
     if (m_map_kd != NULL)
         m_device->SetTexture(0, m_map_kd->obj.base);
     else
         m_device->SetTexture(0, NULL);
     m_device->SetMaterial(m_mtl);
     m_msh->DrawSubset(m_idx);
 }
Пример #30
0
void Mesh::Render(LPDIRECT3DDEVICE9 device)
{
	for(DWORD i = 0; i < m_numberOfMaterials; i++)
	{
		device->SetMaterial(&m_materials[i]);
		device->SetTexture(0, m_meshTextures[i]->GetTexture());
		m_mesh->DrawSubset(i);
	}
}