Example #1
0
void CExplosive::Explode()
{
	VERIFY(0xffff != Initiator());
	VERIFY(m_explosion_flags.test(flReadyToExplode));//m_bReadyToExplode
	VERIFY(!physics_world()->Processing());
	//m_bExploding = true;
	m_explosion_flags.set(flExploding,TRUE);
	cast_game_object()->processing_activate();

	Fvector& pos = m_vExplodePos;
	Fvector& dir = m_vExplodeDir;
#ifdef DEBUG
	if(ph_dbg_draw_mask.test(phDbgDrawExplosions))
	{
		DBG_OpenCashedDraw();
		DBG_DrawPoint(pos,0.3f,D3DCOLOR_XRGB(255,0,0));
	}
#endif
//	Msg("---------CExplosive Explode [%d] frame[%d]",cast_game_object()->ID(), Device.dwFrame);
	OnBeforeExplosion();
	//играем звук взрыва
	Sound->play_at_pos(sndExplode, 0, pos, false);
	
	//показываем эффекты

	m_wallmark_manager.PlaceWallmarks		(pos);

	Fvector									vel;
	smart_cast<CPhysicsShellHolder*>(cast_game_object())->PHGetLinearVell(vel);

	Fmatrix explode_matrix;
	explode_matrix.identity();
	explode_matrix.j.set(dir);
	Fvector::generate_orthonormal_basis(explode_matrix.j, explode_matrix.i, explode_matrix.k);
	explode_matrix.c.set(pos);

	CParticlesObject* pStaticPG; 
	pStaticPG = CParticlesObject::Create(*m_sExplodeParticles,!m_bDynamicParticles); 
	if (m_bDynamicParticles) m_pExpParticle = pStaticPG;
	pStaticPG->UpdateParent(explode_matrix,vel);
	pStaticPG->Play(false);

	//включаем подсветку от взрыва
	StartLight();

	//trace frags
	Fvector frag_dir; 
	
	//////////////////////////////
	//осколки
	//////////////////////////////
	//-------------------------------------
	bool SendHits = false;
	if (OnServer()) SendHits = true;
	else SendHits = false;


	for(int i = 0; i < m_iFragsNum; ++i){
		frag_dir.random_dir	();
		frag_dir.normalize	();
		
		CCartridge cartridge;
		cartridge.param_s.kDist				= 1.f;
		cartridge.param_s.kHit				= 1.f;
//.		cartridge.param_s.kCritical			= 1.f;
		cartridge.param_s.kImpulse			= 1.f;
		cartridge.param_s.kAP				= 1.f;
		cartridge.param_s.fWallmarkSize		= fWallmarkSize;
		cartridge.bullet_material_idx		= GMLib.GetMaterialIdx(WEAPON_MATERIAL_NAME);
		cartridge.m_flags.set				(CCartridge::cfTracer,FALSE);

		Level().BulletManager().AddBullet(	pos, frag_dir, m_fFragmentSpeed,
											m_fFragHit, m_fFragHitImpulse, Initiator(),
											cast_game_object()->ID(), m_eHitTypeFrag, m_fFragsRadius, 
											cartridge, 1.f, SendHits );
	}	

	if (cast_game_object()->Remote()) return;
	
	/////////////////////////////////
	//взрывная волна
	////////////////////////////////
	//---------------------------------------------------------------------
	xr_vector<ISpatial*>	ISpatialResult;
	g_SpatialSpace->q_sphere(ISpatialResult,0,STYPE_COLLIDEABLE,pos,m_fBlastRadius);

	m_blasted_objects.clear	();
	for (u32 o_it=0; o_it<ISpatialResult.size(); o_it++)
	{
		ISpatial*		spatial	= ISpatialResult[o_it];
		//		feel_touch_new(spatial->dcast_CObject());

		CPhysicsShellHolder	*pGameObject = smart_cast<CPhysicsShellHolder*>(spatial->dcast_CObject());
		if(pGameObject && cast_game_object()->ID() != pGameObject->ID()) 
			m_blasted_objects.push_back(pGameObject);
	}

	GetExplosionBox(m_vExplodeSize);
START_PROFILE("explosive/activate explosion box")
	ActivateExplosionBox(m_vExplodeSize,m_vExplodePos);
STOP_PROFILE
	//---------------------------------------------------------------------
#ifdef DEBUG
	if(ph_dbg_draw_mask.test(phDbgDrawExplosions))
	{
		DBG_ClosedCashedDraw(100000);
		
	}
#endif
	//////////////////////////////////////////////////////////////////////////
	// Explode Effector	//////////////
	CGameObject* GO = smart_cast<CGameObject*>(Level().CurrentEntity());
	CActor* pActor = smart_cast<CActor*>(GO);
	if(pActor)
	{
		float dist_to_actor = pActor->Position().distance_to(pos);
		float max_dist		= EFFECTOR_RADIUS;
		if (dist_to_actor < max_dist)
			AddEffector	(pActor, effExplodeHit, effector.effect_sect_name, (max_dist - dist_to_actor) / max_dist );
	}
}
Example #2
0
HRESULT MoonScene::RestoreDeviceObjects()
{
	HRESULT hr = E_FAIL;

	if(_SnowSystem && _SnowSystem->init(_device,const_cast<char*>(IMAGE_DIR(_SnowTex.c_str()))) == false)
	{
		LogWarning("MoonScene::RestoreDeviceObjects() Initialize the MoonSnow failed!");
		SAFE_DELETE(_SnowSystem);
	}
	if(_Firework && _Firework->init(_device,const_cast<char*>(IMAGE_DIR(_FireTex.c_str()))) == false)
	{
		LogWarning("MoonScene::RestoreDeviceObjects() Initialize the MoonFirework failed!");
		SAFE_DELETE(_Firework);
	}

    // Material
    D3DMATERIAL9 Material;
    Moon_InitMaterial( Material, 1.0f, 1.0f, 1.0f, 1.0f );
    hr = _device->SetMaterial( &Material );
	if(SUCCEEDED(hr))
		LogInfo("MoonScene::RestoreDeviceObjects() SetMaterial OK!");
	else
		LogError("MoonScene::RestoreDeviceObjects() SetMaterial Failed!");

	if(FAILED(hr = _device->SetLight(0, &_environmentLight)))
		return hr;
	if(FAILED(hr = _device->LightEnable(0, true)))
		return hr;

	if(FAILED(hr = _device->SetRenderState(D3DRS_AMBIENT,
			D3DCOLOR_XRGB((int)_ambient.x, (int)_ambient.y, (int)_ambient.z))))
		return hr;

	//设置雾化效果
	if(_dwFog == TRUE)
	{
		_device->SetRenderState(D3DRS_FOGENABLE, TRUE);
		_device->SetRenderState(D3DRS_FOGCOLOR, _dwFogColor);
		switch(_dwFogTableMode)
		{
			case D3DFOG_LINEAR:
				_device->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
				_device->SetRenderState(D3DRS_FOGSTART, _dwFogStart);
				_device->SetRenderState(D3DRS_FOGEND, _dwFogEnd);
				break;
			case D3DFOG_EXP:
				_device->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_EXP);
				_device->SetRenderState(D3DRS_FOGDENSITY, _dwFogDensity);
				break;
			case D3DFOG_EXP2:
				_device->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_EXP2);
				_device->SetRenderState(D3DRS_FOGDENSITY, _dwFogDensity);
				break;
		}
		D3DCAPS9 d3dCaps;
		_device->GetDeviceCaps(&d3dCaps);
		if(d3dCaps.RasterCaps&D3DPRASTERCAPS_FOGRANGE)
			_device->SetRenderState(D3DRS_RANGEFOGENABLE, TRUE);
	}

	_device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);//允许使用alpha混合
	_device->SetRenderState(D3DRS_SRCBLEND,  D3DBLEND_SRCALPHA);
	_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
	//Turn on lighting
    _device->SetRenderState(D3DRS_LIGHTING, TRUE);
    _device->SetRenderState( D3DRS_NORMALIZENORMALS, TRUE );
    _device->SetRenderState( D3DRS_DITHERENABLE,     TRUE );
	_device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
	_device->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);

	_device->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
	_device->SetSamplerState( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR);
	_device->SetSamplerState( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR);

	if(FAILED(_device->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE)))
		LogError("MoonScene::RestoreDeviceObjects() SetRenderState(AntiAlias) Failed!");

	_device->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
	_device->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
	_device->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
	_device->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
	_device->SetSamplerState( 2, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
	_device->SetSamplerState( 2, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
	_device->SetSamplerState( 3, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
	_device->SetSamplerState( 3, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
	_device->SetSamplerState( 4, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
	_device->SetSamplerState( 4, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
	_device->SetSamplerState( 5, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
	_device->SetSamplerState( 5, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
	_device->SetSamplerState( 6, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
	_device->SetSamplerState( 6, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );

	return hr;
}
Example #3
0
HRESULT 
CPlaneScene::DrawScene( IDirect3DDevice9* d3ddev,
                        IDirect3DTexture9* texture ) 
{
    HRESULT hr;

    if( !( d3ddev && texture ) )
    {
        return E_POINTER;
    }

    if( m_vertexBuffer == NULL )
    {
        return D3DERR_INVALIDCALL;
    }

    // get the difference in time
    DWORD dwCurrentTime;
    dwCurrentTime = GetTickCount();
    double difference = m_time - dwCurrentTime ;
    
    // figure out the rotation of the plane
    float x = (float) ( -cos(difference / 2000.0 ) ) ;
    float y = (float) ( cos(difference / 2000.0 ) ) ;
    float z = (float) ( sin(difference / 2000.0 ) ) ;

    // update the two rotating vertices with the new position
    m_vertices[0].position = CUSTOMVERTEX::Position(x,  y, z);   // top left
    m_vertices[3].position = CUSTOMVERTEX::Position(-x, -y, -z); // bottom right

    // Adjust the color so the blue is always on the bottom.
    // As the corner approaches the bottom, get rid of all the other
    // colors besides blue
    DWORD mask0 = (DWORD) (255 * ( ( y + 1.0  )/ 2.0 ));
    DWORD mask3 = (DWORD) (255 * ( ( -y + 1.0  )/ 2.0 ));
    m_vertices[0].color = 0xff0000ff | ( mask0 << 16 ) | ( mask0 << 8 );
    m_vertices[3].color = 0xff0000ff | ( mask3 << 16 ) | ( mask3 << 8 );

    // write the new vertex information into the buffer
    void* pData;
    FAIL_RET( m_vertexBuffer->Lock(0,sizeof(pData), &pData,0) );
    memcpy(pData,m_vertices,sizeof(m_vertices));                            
    FAIL_RET( m_vertexBuffer->Unlock() );  

    // clear the scene so we don't have any articats left
    d3ddev->Clear( 0L, NULL, D3DCLEAR_TARGET, 
                   D3DCOLOR_XRGB(255,255,255), 1.0f, 0L );

    FAIL_RET( d3ddev->BeginScene() );
    FAIL_RET( d3ddev->SetTexture( 0, texture));

    FAIL_RET(hr = d3ddev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE));
    FAIL_RET(hr = d3ddev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE));
    FAIL_RET(hr = d3ddev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE));
    FAIL_RET(hr = d3ddev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE));

    FAIL_RET( d3ddev->SetStreamSource(0, m_vertexBuffer.p, 0, sizeof(CPlaneScene::CUSTOMVERTEX)  ) );            //set next source ( NEW )
    FAIL_RET( d3ddev->SetFVF( D3DFVF_CUSTOMVERTEX ) );
    FAIL_RET( d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2) );  //draw quad 
    FAIL_RET( d3ddev->SetTexture( 0, NULL));
    FAIL_RET( d3ddev->EndScene());

    return hr;
}
void CGameStateIntro::Render(CGraphics &con, CGameData &data, CConfigData &cfg){
  ::ShowCursor(false);
  CLog *pLog = CLog::Instance();
  static bool bLostDevice = false;

  //test to see if graphic device is lost, if so, deal with it
  //**********************************************************
  HRESULT hr;
  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){
    
    //device is lost...cannot be reset...exit Render() function
    if(hr == D3DERR_DEVICELOST){
      if(bLostDevice == false){
        bLostDevice = true;
        con.DeleteLost();    //delete one time per failure
        m_effect.Delete();
        pLog->Log("Deleted");
      }
      return;
    }

    //device was lost...but now can be RESET
    else if( hr == D3DERR_DEVICENOTRESET ){
      hr = con.m_d3ddev->Reset(&con.GetDPP());      
      if(SUCCEEDED(hr)){
        m_effect.Init(con.m_d3ddev);
        m_effect.LoadFile(cfg.EffectsFileI);// "assets\\data\\effects_i.dat");
        m_effectNumber = 0;
        m_effectMax = m_effect.GetNumberEffects();
        pLog->Log("******* Number of effects reloaded", m_effectMax);
        con.LoadAssetFile(cfg.GamePlayAssetFile);
        con.LoadAssetFile(cfg.FrameworkAssetFile);     
        con.ReloadLost();
        bLostDevice = false;
      }
      return;
    }
  }

  // clear the window to a deep blue
  //if(m_graphic == 0)
  //  con.m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 111, 255), 1.0f, 0);
  //else
  con.m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(106, 126, 67), 1.0f, 0);
  con.m_d3ddev->BeginScene();    // begins the 3D scene

  GRAPHIC_IMAGE gi;  
  con.BeginRender();
  
  //render title
  if(m_secondCounter < 3){
    gi = con.GetSprite(1000);
    con.RenderGraphicModulate(gi, con.GetScreenCenterX() - gi.width/2, con.GetScreenCenterY() - gi.height/2, 255, 255, 255);
  }
  else{
    gi = con.GetSprite(1001);
    con.RenderGraphicModulate(gi, con.GetScreenCenterX() - gi.width/2, con.GetScreenCenterY() - gi.height/2, 255, 255, 255);
  }
  if(m_secondCounter > 3){
    gi = con.GetSprite(1002);
    con.RenderGraphicModulate(gi, - 20 + con.GetScreenCenterX() - gi.width/2, 60 + con.GetScreenCenterY() - gi.height/2, 255, 255, 255);
  }

  con.EndRender();

  m_effect.Render(); 

  //mouse cursor
  con.DrawCircle(m_mouse.MouseX(), m_mouse.MouseY(), 255, 255, 255, 10);

  if(cfg.DisplayDebugInfo == true){
    con.Print("Mouse X", m_mouse.MouseX(), F_V16, 10, 30, 255, 255, 255, 255);
    con.Print("Mouse Y", m_mouse.MouseY(), F_V16, 10, 50, 255, 255, 255, 255);
  }

  //con.Print("Introduction Splash Screen", F_V20B, cfg.ScreenWidth/2 - 120, 100, 255, 255, 0, 255);
  //con.Print("Left Click to Continue", F_V20B, cfg.ScreenWidth/2 - 110, 130, 255, 255, 255, 255);
  //con.Print("FPS", data.m_FPS, F_V16, 30, 50, 255, 255, 255, 255);
  //if(cfg.DisplayDebugInfo == true){
   // con.Print("FPS", data.m_FPS , F_V16, 30, 30,  255, 255, 255, 255);
  //}  

  con.m_d3ddev->EndScene();    // ends the 3D scene
  hr = con.m_d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
 
  return;
}
Example #5
0
#if 1

    #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
    struct CUSTOMVERTEX {
        FLOAT X, Y, Z, RHW;
        DWORD COLOR;
    };
    CUSTOMVERTEX vertices[] = {
        { -10.0f,  10.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255), },
        {  10.0f,  10.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0), },
        { -10.0f, -10.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0), },
        {  10.0f, -10.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 255), },
    }; 

    // Create a vertex buffer
    LPDIRECT3DDEVICE9 d3d = (LPDIRECT3DDEVICE9) info.mDevice;
    IDirect3DVertexBuffer9* v_buffer;
    VOID* p;
    d3d->CreateVertexBuffer(4 * sizeof(CUSTOMVERTEX),    // change to 4, instead of 3
        0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL);

    // Lock v_buffer and load the vertices into it
    v_buffer->Lock(0, 0, (void**) &p, 0);
    memcpy(p, vertices, sizeof(vertices));
    v_buffer->Unlock();

    d3d->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
    d3d->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
#endif
Example #6
0
void HudElements::Render()
{
#ifdef _DEBUG
	D3DPERF_EndEvent( );
	D3DPERF_BeginEvent( D3DCOLOR_XRGB(255, 0, 0 ), L"DRAWING HUD BOXES");
#endif

	HRESULT hr;
	hr = g_RenderDevices.GetDevice()->SetRenderState(D3DRS_ZENABLE, false);

	// big ol hack...
	if( m_hudEntities.size() > 0 )
	{
		//g_RenderManager.SetSceneOrthoConstants();

		for( int i = 0; i < m_hudEntities.size(); i++ )
		{
			g_RenderManager.SetUniformData( m_hudEntities[i], m_hudEntities[i]->m_material->rm_Reference.m_effect, m_hudEntities[i]->m_material, false, false, 1 );
			m_hudEntities[i]->Draw();
		}

		//g_RenderManager.SetSceneConstants();
	}

	if( m_currentVertices > 0 )
	{
		//return ;

		if (m_dirty )	// Copy local vertex data into VB if it is new.
		{
			gHUDQuad  *pVerts = NULL;
			m_pVBuff->Lock(0, 0, (void**)&pVerts, 0);
			memcpy(pVerts, m_boxVertices, m_currentVertices * sizeof(gHUDQuad));

			m_pVBuff->Unlock();

			m_dirty = false;    //vert data isn't new anymore
		}


		hr = g_RenderDevices.GetDevice()->SetVertexShader( m_vertexShader->rm_Reference.m_vertexShader );
		//assert( SUCCEEDED( result ) );
		hr = g_RenderDevices.GetDevice()->SetPixelShader( m_pixelShader->rm_Reference.m_pixelShader );
		//assert( SUCCEEDED( result )

		// Draw the lines.
		//hr = g_RenderDevices.GetDevice()->SetIndices(m_pIBuff);
		hr = g_RenderDevices.GetDevice()->SetIndices( m_pIBuff );
		hr = g_RenderDevices.GetDevice()->SetStreamSource(0, m_pVBuff, 0, sizeof(gHUDQuad));
		hr = g_RenderDevices.GetDevice()->SetVertexDeclaration( m_vertexDeclaration );
		//g_RenderDevices.GetDevice()->SetStreamSource( 0, 0, 0, 0 );
		//g_RenderDevices.GetDevice()->SetVertexDeclaration( 0 );

		//Render
		hr = g_RenderDevices.GetDevice()->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, m_currentVertices, 0, m_currentVertices / 2 );
	}



#ifdef _DEBUG
	D3DPERF_EndEvent( );
	D3DPERF_BeginEvent( D3DCOLOR_XRGB(255, 0, 0 ), L"DRAWING HUD TEXT");
#endif

	HRESULT result = m_sprite->Begin( D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE );
	assert( result == D3D_OK );

	// Render the text
	for( unsigned i = 0; i < m_text.size(); i++)
	{
		HRESULT result = m_font->DrawTextA( m_sprite, m_text[i].m_text, -1, &m_text[i].m_rectDimensions, DT_LEFT | DT_NOCLIP | DT_VCENTER | DT_SINGLELINE, m_text[i].m_color );
		assert( result != 0 );
	}



	result = m_sprite->End();
	assert( result == D3D_OK );
}
Example #7
0
void DxPoint::SetColor(const BYTE& r, const BYTE& g, const BYTE& b)
{
	SetColor(D3DCOLOR_XRGB(r, g, b));
}
void CBulletHook::Render(void)
{
	static RECT r = {525,728, 553, 769};
	CSGD_TextureManager *pTM = CSGD_TextureManager::GetInstance();
	pTM->Draw(GetImageID(),GetCollisionRect().left,GetCollisionRect().top + 32,1.5f,1.5f,&r,GetWidth() / 2, GetHeight() /2,GetRotation(),D3DCOLOR_XRGB(255,255,255));
}
Example #9
0
bool CD3dSystem::BeginScene()
{
	m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(253, 179, 40), 1.0f, 0 ); // D3DCOLOR_XRGB

	return SUCCEEDED( m_pd3dDevice->BeginScene() ) ;
}
Example #10
0
/**
 * It allocates and initializes the resources needed to render the scene.
 */
static int Direct3DCreateScene(vout_display_t *vd, const video_format_t *fmt)
{
    vout_display_sys_t *sys = vd->sys;
    LPDIRECT3DDEVICE9       d3ddev = sys->d3ddev;
    HRESULT hr;

    /*
     * Create a texture for use when rendering a scene
     * for performance reason, texture format is identical to backbuffer
     * which would usually be a RGB format
     */
    LPDIRECT3DTEXTURE9 d3dtex;
    hr = IDirect3DDevice9_CreateTexture(d3ddev,
                                        fmt->i_width,
                                        fmt->i_height,
                                        1,
                                        D3DUSAGE_RENDERTARGET,
                                        sys->d3dpp.BackBufferFormat,
                                        D3DPOOL_DEFAULT,
                                        &d3dtex,
                                        NULL);
    if (FAILED(hr)) {
        msg_Err(vd, "Failed to create texture. (hr=0x%lx)", hr);
        return VLC_EGENERIC;
    }

    /*
    ** Create a vertex buffer for use when rendering scene
    */
    LPDIRECT3DVERTEXBUFFER9 d3dvtc;
    hr = IDirect3DDevice9_CreateVertexBuffer(d3ddev,
                                             sizeof(CUSTOMVERTEX)*4,
                                             D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
                                             D3DFVF_CUSTOMVERTEX,
                                             D3DPOOL_DEFAULT,
                                             &d3dvtc,
                                             NULL);
    if (FAILED(hr)) {
        msg_Err(vd, "Failed to create vertex buffer. (hr=0x%lx)", hr);
        IDirect3DTexture9_Release(d3dtex);
        return VLC_EGENERIC;
    }

    /* */
    sys->d3dtex = d3dtex;
    sys->d3dvtc = d3dvtc;

    sys->d3dregion_count = 0;
    sys->d3dregion       = NULL;

    sys->clear_scene = true;

    // Texture coordinates outside the range [0.0, 1.0] are set
    // to the texture color at 0.0 or 1.0, respectively.
    IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
    IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);

    // Set linear filtering quality
    if (sys->d3dcaps.TextureFilterCaps & D3DPTFILTERCAPS_MINFLINEAR) {
        msg_Dbg(vd, "Using D3DTEXF_LINEAR for minification");
        IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
    } else {
        msg_Dbg(vd, "Using D3DTEXF_POINT for minification");
        IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
    }
    if (sys->d3dcaps.TextureFilterCaps & D3DPTFILTERCAPS_MAGFLINEAR) {
        msg_Dbg(vd, "Using D3DTEXF_LINEAR for magnification");
        IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
    } else {
        msg_Dbg(vd, "Using D3DTEXF_POINT for magnification");
        IDirect3DDevice9_SetSamplerState(d3ddev, 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
    }

    // set maximum ambient light
    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_AMBIENT, D3DCOLOR_XRGB(255,255,255));

    // Turn off culling
    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_CULLMODE, D3DCULL_NONE);

    // Turn off the zbuffer
    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ZENABLE, D3DZB_FALSE);

    // Turn off lights
    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_LIGHTING, FALSE);

    // Enable dithering
    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_DITHERENABLE, TRUE);

    // disable stencil
    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_STENCILENABLE, FALSE);

    // manage blending
    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHABLENDENABLE, FALSE);
    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
    IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);

    if (sys->d3dcaps.AlphaCmpCaps & D3DPCMPCAPS_GREATER) {
        IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHATESTENABLE,TRUE);
        IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHAREF, 0x00);
        IDirect3DDevice9_SetRenderState(d3ddev, D3DRS_ALPHAFUNC,D3DCMP_GREATER);
    }

    // Set texture states
    IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_COLOROP,D3DTOP_SELECTARG1);
    IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_COLORARG1,D3DTA_TEXTURE);

    IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
    IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
    IDirect3DDevice9_SetTextureStageState(d3ddev, 0, D3DTSS_ALPHAARG2,D3DTA_DIFFUSE);

    msg_Dbg(vd, "Direct3D scene created successfully");

    return VLC_SUCCESS;
}
int CGameStateMain::Render(CGraphics &con,  CGameData &data, CConfigData &cfg){
  CLog *pLog = CLog::Instance();
  static bool bLostDevice = false;

  ::ShowCursor(true);

  //test to see if graphic device is lost, if so, deal with it
  //**********************************************************
  HRESULT hr;
  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){
    
    //device is lost...cannot be reset...exit Render() function
    if(hr == D3DERR_DEVICELOST){
      if(bLostDevice == false){
        bLostDevice = true;
        con.DeleteLost();    //delete one time per failure
      }
      return 0;
    }

    //device was lost...but now can be RESET
    else if( hr == D3DERR_DEVICENOTRESET ){
      hr = con.m_d3ddev->Reset(&con.GetDPP());      
      if(SUCCEEDED(hr)){
        con.LoadAssetFile(cfg.GamePlayAssetFile);
        con.LoadAssetFile(cfg.FrameworkAssetFile);     
        con.ReloadLost();
        bLostDevice = false;
      }
      return 0;
    }
  }

  // clear the window to a deep blue
  con.m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
  con.m_d3ddev->BeginScene();    // begins the 3D scene
  con.BeginRender();

  GRAPHIC_IMAGE gi;
  gi = con.GetSprite(2001);
  con.RenderSprite(gi, 0, 0, 255, 255, 255);  
  
  //instructions
//if(cfg.DisplayDebugInfo == true){
//  con.Print("FPS", data.m_FPS, F_A12, 10, 10, 0, 0, 0, 255);
//  con.Print("Mouse X", m_mouse.MouseX(), F_A12, 10, 30, 255, 255, 255, 255);
//  con.Print("Mouse Y", m_mouse.MouseY(), F_A12, 10, 50, 255, 255, 255, 255);
//}
  con.EndRender();

  con.Print("INSTRUCTIONS",F_V20, 420, 30, 255, 255, 255, 255);
  
  con.Print("There are five levels. Each level contains 4 parts to a song. There are several songs per level.",F_V20, 100, 62, 255, 255, 0, 255);
  con.Print("Your goal is to move the 4 related parts of a song to the top assembly area. The program will",F_V20, 100, 90, 255, 255, 0, 255);
  con.Print("assemble the parts automatically. Points are scored for each song correctly assembled.",F_V20, 100, 118, 255, 255, 0, 255);

  con.Print(" Level 1 -  4 songs,  40 pts/song  Bonus if completed within  80 seconds ( 40 pts per second under)", F_V20, 100, 150, 0, 255, 0, 255);
  con.Print(" Level 2 -  6 songs,  60 pts/song  Bonus if completed within 120 seconds ( 60 pts per second under)", F_V20, 100, 180, 0, 255, 0, 255);
  con.Print(" Level 3 -  8 songs,  80 pts/song  Bonus if completed within 160 seconds ( 80 pts per second under)", F_V20, 100, 210, 0, 255, 0, 255);
  con.Print(" Level 4 - 10 songs, 100 pts/song  Bonus if completed within 200 seconds (100 pts per second under)", F_V20, 100, 240, 0, 255, 0, 255);
  con.Print(" Level 5 - 20 songs, 200 pts/song  Bonus if completed within 400 seconds (200 pts per second under)", F_V20, 100, 270, 0, 255, 0, 255);
  //con.Print("                                      Level 1 -  40 points per song",F_V20, 100, 150, 255, 255, 0, 255);
  //con.Print("                                      Level 2 -  80 points per song",F_V20, 100, 180, 255, 255, 0, 255);
  //con.Print("                                      Level 3 -  120 points per song",F_V20, 100, 210, 255, 255, 0, 255);
  //con.Print("                                      Level 4 -  160 points per song",F_V20, 100, 240, 255, 255, 0, 255);
  //con.Print("                                      Level 5 -  200 points per song",F_V20, 100, 270, 255, 255, 0, 255);

  con.Print("Left click and hold to drag song parts to assembly area. Right click a song part in the assembly",F_V20, 100, 330, 255, 255, 0, 255);
  con.Print("area to remove it. Right click sparingingly. You will lose points for each tile you remove.",F_V20, 100, 360, 255, 255, 0, 255);
  con.Print("In addition you will lose points for each incorrect guess.",F_V20, 100, 390, 255, 255, 0, 255);
  con.Print(" Level 1 - Lose  40 pts per removed tile", F_V20, 100, 420, 255, 0, 0, 255);
  con.Print(" Level 2 - Lose  60 pts per removed tile", F_V20, 100, 450, 255, 0, 0, 255);
  con.Print(" Level 3 - Lose  80 pts per removed tile", F_V20, 100, 480, 255, 0, 0, 255);
  con.Print(" Level 4 - Lose 100 pts per removed tile", F_V20, 100, 510, 255, 0, 0, 255);
  con.Print(" Level 5 - Lose 200 pts per removed tile", F_V20, 100, 540, 255, 0, 0, 255);

  con.Print("Be careful moving tiles. They may be stacked upon one another.",F_V20, 100, 570, 255, 255, 255, 255);
  con.Print("Press ESC at any time to quit. The game is not saved.",F_V20, 100, 600, 255, 255, 255, 255);
  con.Print("There are 48 songs in total. Good Luck!",F_V20, 100, 630, 255, 255, 255, 255);
  
  
  con.Print("Click to continue",F_V20, 420, 730, 255, 255, 255, 255);
  //draw mouse cursor
  //draw mouse
  //con.DrawCircle((float)m_mouse.MouseX(), (float)m_mouse.MouseY(), 255, 255, 255, 5);  
  //con.DrawRect(m_mouse.MouseX() - 16, m_mouse.MouseY() - 16, m_mouse.MouseX() + 16, m_mouse.MouseY() + 16, 255, 255, 255);

  con.m_d3ddev->EndScene();    // ends the 3D scene
  hr = con.m_d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen

  return 0;
}
void CBulletPaper::Render(void)
{
	static RECT r = {615,32,624,42};
	CSGD_TextureManager *pTM = CSGD_TextureManager::GetInstance();
	pTM->Draw(GetImageID(),GetPosX(),GetPosY(),2.0f,2.0f,&r,GetWidth() / 2, GetHeight() /2,GetRotation(),D3DCOLOR_XRGB(255,255,255));
}
Example #13
0
void Engine::Graphics::loadImages()
{
	ImageValue temp_storage;

	std::string temp_file_name;
	std::string temp_handle;
	//LPCWSTR rFilename;

	struct temp_Data
	{
		std::string temp_handle;
		std::wstring temp_file_name;
	};

	std::vector<temp_Data> tempStorageData;

	//TODO: read from text file
	std::ifstream file("Textures2D.txt");
	//std::wstring wtemp;

	//read til end of file
	while(!file.eof())
	{
		//store file name and handle to the file in temp variables
		file >> temp_file_name >> temp_handle;

		//create a temporary struct to hold data

		temp_Data some_data;
		some_data.temp_file_name = L"";
		some_data.temp_handle = temp_handle;

		//convert string to LPCWSTR 
		some_data.temp_file_name = std::wstring(temp_file_name.begin(), temp_file_name.end());
		//LPCWSTR stemp = wtemp.c_str();
		//some_data.temp_file_name = stemp;
		//wtemp = string2wstring(temp_file_name);
		//some_data.temp_file_name = wtemp.c_str();


		//push back the data
		tempStorageData.push_back(some_data);


	}
	//end of file, close file
	file.close();

	//Iterate through temporary data storage to create textures
	for(unsigned int i = 0; i < tempStorageData.size(); i++)
	{
		D3DXCreateTextureFromFileEx(Engine::DX::instance()->getDevice(),
			tempStorageData[i].temp_file_name.c_str(), 0, 0, 0, 0,
			D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT,
			D3DCOLOR_XRGB(255,255,255), &temp_storage.info, 0, &temp_storage.texture);
		//temp_storage.handle = tempStorageData[i].temp_handle;

		imageStorage[tempStorageData[i].temp_handle] = temp_storage;
		//set pointer to nullptr before reusing
		temp_storage.texture = nullptr;
	}

	//TODO sort storage

	//Create Error texture to show errors
	D3DXCreateTextureFromFileEx(Engine::DX::instance()->getDevice(),
		L"error.png", 0, 0, 0, 0,
		D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT,
		D3DCOLOR_XRGB(255,255,255), &errorinfo, 0, &error);

}
COptions::COptions()
{
	m_nImageID[0] = -1;
	m_nImageID[1] = -1;

	m_nSoundID[0] = -1;
	m_nSoundID[1] = -1;

	m_nMusicVolume = 100;
	m_nSFXVolume = 100;

	m_nDifficulty = DIFFICULTY_MEDIUM;

	m_Font.SetFontImageID( CSGD_TextureManager::GetInstance()->LoadTexture("resource/JoA_023 - large.bmp", D3DCOLOR_XRGB(0, 0, 0)) );
	m_Font.SetCharWidth( 32 );
	m_Font.SetCharHeight( 32 );
	m_Font.SetNumCols( 10 );
	m_Font.SetStartChar( ' ' );


	rBarRect.top = 0;
	rBarRect.bottom = 62;
	rBarRect.left = 0;
	rBarRect.right = 200;
}
Example #15
0
//===========================================================================
// DG_Color3ubv
//===========================================================================
void DG_Color3ubv(DGLubyte *data)
{
	currentVertex.color = D3DCOLOR_XRGB(data[0], data[1], data[2]);
}
Example #16
0
void CWndVendorCtrl::OnDraw( C2DRender* p2DRender )
{
	if( m_pMover == NULL )
		return;
	
	CRect rect	= GetClientRect();
	int nWidth	= rect.Width() / 32;
	int nHeight		= rect.Height() / 32;

#if __VER >= 8 //__S8_VENDOR_REVISION
	int i; for( i = 0; i < MAX_VENDOR_REVISION; i++ )
#else //__S8_VENDOR_REVISION
	int i; for( i = 0; i < MAX_VENDITEM; i++ )
#endif //__S8_VENDOR_REVISION
	{
		int x	= i % 2;
		int y	= i / 2;
		
		int nX;
		int nY = y * 32 + 8 + y * 4;
		if( x == 0 )
			nX = x * 32 + 15;
		else
			nX = 235;

		CRect rectHittest = CRect( nX, nY, nX + 180, nY + 32 );
		CPoint point	= GetMousePoint();
		if( rectHittest.PtInRect( point ) )
		{
			if( CWndBase::m_GlobalShortcut.m_dwData )
			{
				m_nCurSel = -1;
				{
					CPoint ptx = CPoint(nX, nY);
					m_pTex->Render( p2DRender, ptx );		// 아이템 테두리 그리기
				}
			}
		}			
		CItemBase* pItemBase = GetItem( i );
		if( pItemBase )
		{

			// 툴팁
			float fScal = 1.0f;
			CPoint point	= GetMousePoint();
			if( rectHittest.PtInRect( point ) )
			{
				fScal = 1.15f;
				CPoint point2 = point;
				ClientToScreen( &point2 );
				ClientToScreen( &rectHittest );
				g_WndMng.PutToolTip_Item( pItemBase, point2, &rectHittest, APP_VENDOR );
			}

			// 아이템 아이콘 
			if( ((CItemElem*)pItemBase)->IsFlag( CItemElem::expired ) )
				pItemBase->GetTexture()->Render2( p2DRender, CPoint( nX, nY ), D3DCOLOR_XRGB( 255, 100, 100 ) );					
			else
				pItemBase->GetTexture()->Render2( p2DRender, CPoint( nX, nY ), D3DCOLOR_XRGB( 255, 255, 255 ), fScal, fScal );

			// 아이템 이름, 판매가격
			OnDrawItemInfo( p2DRender, ((CItemElem*)pItemBase), nX, nY );

			if( i == m_nCurSel )
				p2DRender->RenderRect( CRect( nX, nY, nX + 32, nY + 32 ), 0xff00ffff );
			CItemElem* pItemElem	= (CItemElem*)pItemBase;
			if( pItemElem->GetProp()->dwPackMax > 1 )
			{
				short nItemNum	= pItemBase->GetExtra();
				TCHAR szTemp[32];
				_stprintf( szTemp, "%d", nItemNum );
				CSize size	= p2DRender->m_pFont->GetTextExtent( szTemp );
				p2DRender->TextOut( nX - 7 + 32 - size.cx+5, nY - 11 + 32 - size.cy+12, szTemp, 0xff1010ff );
			}
		}
	}
}
Example #17
0
void CInventoryItem::PH_A_CrPr		()
{
	if (m_just_after_spawn)
	{
		VERIFY(object().Visual());
		IKinematics *K = object().Visual()->dcast_PKinematics();
		VERIFY( K );
		if (!object().PPhysicsShell())
		{
			Msg("! ERROR: PhysicsShell is NULL, object [%s][%d]", object().cName().c_str(), object().ID());
			VERIFY2(0, "physical shell is NULL");
			return;
		}
		if(!object().PPhysicsShell()->isFullActive())
		{
			K->CalculateBones_Invalidate();
			K->CalculateBones(TRUE);
		}
		object().PPhysicsShell()->GetGlobalTransformDynamic(&object().XFORM());
		K->CalculateBones_Invalidate();
		K->CalculateBones(TRUE);
#if	0
		Fbox bb= BoundingBox	();
		DBG_OpenCashedDraw		();
		Fvector c,r,p;
		bb.get_CD(c,r );
		XFORM().transform_tiny(p,c);
		DBG_DrawAABB( p, r,D3DCOLOR_XRGB(255, 0, 0));
		//PPhysicsShell()->XFORM().transform_tiny(c);
		Fmatrix mm;
		PPhysicsShell()->GetGlobalTransformDynamic(&mm);
		mm.transform_tiny(p,c);
		DBG_DrawAABB( p, r,D3DCOLOR_XRGB(0, 255, 0));
		DBG_ClosedCashedDraw	(50000);
#endif
		object().spatial_move();
		m_just_after_spawn = false;
		
		VERIFY(!OnServer());
		
		object().PPhysicsShell()->get_ElementByStoreOrder(0)->Fix();
		object().PPhysicsShell()->SetIgnoreStatic	();	
		//object().PPhysicsShell()->SetIgnoreDynamic	();
		//PPhysicsShell()->DisableCollision();
	}
	/*net_updateData* p					= NetSync();
	//restore recalculated data and get data for interpolation	
	if (!object().CrPr_IsActivated())	return;
	////////////////////////////////////
	CPHSynchronize* pSyncObj			= NULL;
	pSyncObj = object().PHGetSyncItem	(0);
	if (!pSyncObj)						return;
	////////////////////////////////////
	pSyncObj->get_State					(p->PredictedState);
	////////////////////////////////////
	pSyncObj->set_State					(p->RecalculatedState);
	////////////////////////////////////

	if (!m_flags.test(FInInterpolate)) return;
	////////////////////////////////////
	Fmatrix xformX;
	pSyncObj->cv2obj_Xfrom(p->PredictedState.quaternion, p->PredictedState.position, xformX);

	VERIFY2								(_valid(xformX),*object().cName());
	pSyncObj->cv2obj_Xfrom				(p->PredictedState.quaternion, p->PredictedState.position, xformX);
	
	p->IEndRot.set						(xformX);
	p->IEndPos.set						(xformX.c);
	VERIFY2								(_valid(p->IEndPos),*object().cName());
	/////////////////////////////////////////////////////////////////////////
	CalculateInterpolationParams		();
	///////////////////////////////////////////////////*/
};
Example #18
0
void CWndVendorCtrl::OnDraw( C2DRender* p2DRender )
{
	if( m_pMover == NULL )
		return;

	CRect rect	= GetClientRect();
	int nWidth	= rect.Width() / 32;
	int nHeight		= rect.Height() / 32;

	int i; for( i = 0; i < MAX_VENDITEM; i++ )
	{
		int x	= i % 6;
		int y	= i / 6;
		//p2DRender->RenderRect( CRect( x * 32 + 7, y * 32 + 11, x * 32 + 32 + 5, y * 32 + 32 + 9 ), 0xff00ffff );
		CRect rectHittest	= CRect( x * 32 + 7, y * 32 + 11, x * 32 + 32 + 5, y * 32 + 32 + 9 );

		CPoint point	= GetMousePoint();

		if( rectHittest.PtInRect( point ) )
		{
			if( CWndBase::m_GlobalShortcut.m_dwData )
			{
				m_nCurSel = -1;
				CPoint ptx = CPoint(x * 32 + 7, y * 32 + 11);
				{
					m_pTex->Render( p2DRender, ptx );
				}
			}
		}			
		CItemBase* pItemBase = GetItem( i );
		if( pItemBase )
		{
			if( ((CItemElem*)pItemBase)->IsFlag( CItemElem::expired ) )
			{
				pItemBase->GetTexture()->Render2( p2DRender, CPoint( x * 32 + 6, y * 32 + 10 ), D3DCOLOR_XRGB( 255, 100, 100 ) );
			}
			else
			{
				pItemBase->GetTexture()->Render( p2DRender, CPoint( x * 32 + 6, y * 32 + 10 ) );
			}

			CPoint point	= GetMousePoint();
			if( rectHittest.PtInRect( point ) )
			{
				CPoint point2 = point;
				ClientToScreen( &point2 );
				ClientToScreen( &rectHittest );
				g_WndMng.PutToolTip_Item( pItemBase, point2, &rectHittest, APP_VENDOR );
			}
			if( i == m_nCurSel )
				p2DRender->RenderRect( CRect( x * 32 + 7, y * 32 + 11, x * 32 + 32 + 5, y * 32 + 32 + 9 ), 0xff00ffff );
			CItemElem* pItemElem	= (CItemElem*)pItemBase;
			if( pItemElem->GetProp()->dwPackMax > 1 )
			{
				short nItemNum	= pItemBase->GetExtra();
				TCHAR szTemp[32];
				_stprintf( szTemp, "%d", nItemNum );
				CSize size	= p2DRender->m_pFont->GetTextExtent( szTemp );
				p2DRender->TextOut( x * 32 + 32 - size.cx+5, y * 32 + 32 - size.cy+12, szTemp, 0xff1010ff );
			}
		}
	}
}
int CGameStateIntro::Render(CGraphics &con, CGameData &data, CConfigData &cfg){
  ::ShowCursor(false);
  CLog *pLog = CLog::Instance();
  static bool bLostDevice = false;

  //test to see if graphic device is lost, if so, deal with it
  //**********************************************************
  HRESULT hr;
  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){
    
    //device is lost...cannot be reset...exit Render() function
    if(hr == D3DERR_DEVICELOST){
      if(bLostDevice == false){
        bLostDevice = true;
        con.DeleteLost();    //delete one time per failure
        //m_effect.Delete();
        //pLog->Log("Deleted");
      }
      return 0;
    }

    //device was lost...but now can be RESET
    else if( hr == D3DERR_DEVICENOTRESET ){
      hr = con.m_d3ddev->Reset(&con.GetDPP());      
      if(SUCCEEDED(hr)){
        //m_effect.Init(con.m_d3ddev);
        //m_effect.LoadFile(cfg.EffectsFileI);
        //m_effectNumber = 0;
        //m_effectMax = m_effect.GetNumberEffects();
        //pLog->Log("******* Number of effects reloaded", m_effectMax);
        con.LoadAssetFile(cfg.GamePlayAssetFile);
        con.LoadAssetFile(cfg.FrameworkAssetFile);     
        con.ReloadLost();
        bLostDevice = false;
      }
      return 0;
    }
  }

  // clear the window to a deep blue
  con.m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);//   0, 111, 255), 1.0f, 0);
  con.m_d3ddev->BeginScene();    // begins the 3D scene

  GRAPHIC_IMAGE gi;  
  con.BeginRender();
  //gi = con.GetSprite(1002);
  //gi.scale = 4.5;
  //con.RenderSprite(gi, 0, 0, 255, 255, 255);
  
  //gi = con.GetSprite(100);
  //gi.angle = 1.57f;
  //con.RenderSprite(gi, 392, 248, 0.5, 1, 120, 120);
  gi = con.GetSprite(2000);
  //gi.alpha = 255;
  //gi.angle = 1.57f;
  //gi.angle = m_angle;
  con.RenderSprite(gi, 0, 0, 255, 255,255);// m_posX, m_posY, m_scale, m_scale, 512, 10);

  con.EndRender();

  //m_effect.Render(); 

 // con.DrawRect(0, 0, 599, 449, 255, 0, 0);
 // con.DrawRect(601, 0, 1023, 449, 255, 0, 0);
 // con.DrawRect(0, 451, 1023, 766, 255, 0, 0);
  //con.DrawLine(0, 384, 1024, 384, 0, 0, 255);
  //con.DrawLine(512, 0, 512, 768, 0, 0, 255);

  //mouse cursor
  //con.DrawCircle(m_mouse.MouseX(), m_mouse.MouseY(), 255, 255, 255, 10);

  //*********************************************
  //test of vector
  /*
  std::vector<float> vecNum;
  for(int i = 0; i < 50; ++i)
    vecNum.push_back(3.14159345f);
  con.PrintVector(vecNum, F_V12, 5, 5, 0, 0, 0, 255);
  */
  //*********************************************

  //*********************************************
  //THIS IS MORE EFFICIENT THAN
  //con.PrintTest("FPS", data.m_FPS, F_A12, 10, 10, 0, 0, 0, 255);

  //THIS.....................
  /*
  for(int i = 0; i < 50;++i){
    for(int j = 0; j < 10; ++j){
      con.Print("FPS", data.m_FPS, F_A12, 10 + (j * 100), 10 + (i * 15), i * 5, i * 5, i * 5, 255);
    }  
  }
  */
  //*********************************************

  con.Print("Click to continue",F_V20, 420, 730, 0, 0, 0, 255);

  ////con.Print("
  //if(cfg.DisplayDebugInfo == true){
  //  con.Print("FPS", data.m_FPS, F_A14, 500, 680, 255, 255, 0, 255);
  //  con.Print("Mouse X", m_mouse.MouseX(), F_V12, 510, 330, 255, 255, 255, 255);
  //  con.Print("Mouse Y", m_mouse.MouseY(), F_V12, 510, 350, 255, 255, 255, 255);
  //  

  //}

  con.m_d3ddev->EndScene();    // ends the 3D scene
  hr = con.m_d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
 
  return 0;
}
//***************************************************************
//                         R E N D E R 
//***************************************************************
void cGameStatePlay2::render(CGraphics &con, Camera &cam, CGameData &data){
  CLog *pLog = CLog::Instance();

  //variables
  static bLostDevice = false;
  static int lostCount = 0;
  GRAPHIC_IMAGE gi;
  GAME_OBJECT go;
  HRESULT hr;
  GAME_OBJECT temp;

  ::ShowCursor(false);
 
  //first time code
  static bool bFirstTime = true;
  if(bFirstTime == true){

    //look for animated data...and load GI stuff into GO
    for(int i = 0; i < data.LevelSize(); ++i){
      go = data.GetLevelData(i);
      if(go.asset == C_SPRITE){
        for(int j = 2; j < 7; ++j){
          gi = con.GetSprite(go.spriteID);
          go.maxFrames = gi.maxFrames;
          go.updateInterval = gi.updateInterval;
          data.UpdateLevelData(i, go);          
        }
      }
    }
    bFirstTime = false;
  }

  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){
    pLog->Log("Failed test");
    if(hr == D3DERR_DEVICELOST)
      return;
    pLog->Log("No lost");
    if( hr == D3DERR_DEVICENOTRESET){// && bLostDevice == true  ){
      lostCount++;
      pLog->Log("Time to reset");
      con.DeleteLost();
      pLog->Log("Deleted everything");
      data.LoadConfigFile("data//config.txt");
      data.LoadGameLevel("data//level1.dat", con);

      hr = con.m_d3ddev->Reset(&con.GetDPP());
      pLog->Log("Dev reset");
      con.ReloadLost();
      pLog->Log("ReloadLost");
      bLostDevice = false;
      return;
    }
  }

  D3DXMATRIX V;
  D3DXVECTOR3 pos;
  cam.getPosition(&pos);  
  cam.getViewMatrix(&V, m_viewChoice);
  con.m_d3ddev->SetTransform(D3DTS_VIEW, &V);

  // clear the window to a deep blue
  //con.m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
  con.m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
  con.m_d3ddev->BeginScene();    // begins the 3D scene
  
  //render layer 0 
  for(int i = 0; i < data.LevelSize(); ++i){
    temp = data.GetLevelData(i);
    if(temp.asset == C_SPLATTER)
      con.RenderSplatter(temp.meshID, temp.x, temp.y, temp.z, temp.rx, temp.ry, temp.rz);//, temp.ry);
  }

  //render layer 1
  for(int i = 0; i < data.LevelSize(); ++i){
    temp = data.GetLevelData(i);
    if(temp.asset == C_MESH){
      if(temp.meshID == 1){//BADGE test
        temp.rx = 0;//m_badgeAngleX;
        temp.ry = 0;//m_badgeAngleZ;
        con.RenderMesh(temp);
      }
      else
        con.RenderMesh(temp);//.meshID, temp.rx, temp.ry, temp.rz);
    }
  }
    
  //render all objects
  int w = con.GetScreenWidth()/2;
  int h = con.GetScreenHeight()/2;
  int px = data.m_player.go.pos.x;
  int py = data.m_player.go.pos.y;

  go = data.m_player.GetGameObject();

  for(int j = 3; j <= 6; ++j){//3..4
    for(int i = 0; i < data.m_pObject.size(); ++i){
      if(data.m_pObject[i]->go.layer == j && data.m_pObject[i]->go.alive == true ){
        if(data.m_pObject[i]->go.pos.x > px - w - 128  && data.m_pObject[i]->go.pos.x < px + w + 128 &&
           data.m_pObject[i]->go.pos.y > py - h - 128 && data.m_pObject[i]->go.pos.y < py + h + 128)
          con.RenderGraphicModulate(data.m_pObject[i]->go, con.GetScreenWidth()/2 + (data.m_pObject[i]->go.pos.x - go.pos.x) - 16, con.GetScreenHeight()/2 + (data.m_pObject[i]->go.pos.y - go.pos.y) - 16, 255, 255, 255);
      }
    }
  }

  //draws cindy's face as a graphic place holder
  go.width = 32;
  go.height = 32;
  go.pos.x = con.GetScreenWidth()/2 ;//- gi.width/2;
  go.pos.y = con.GetScreenHeight()/2 ;// - gi.height/2;
  con.RenderGraphicModulate(go, 255, 255, 255);

  //draws cindy's face as a graphic place holder
  //gi = con.GetSprite(21);
  //gi.scale = 0.75f/2.0f;//pos.y;
  //con.RenderGraphicModulate(gi, con.GetScreenWidth()/2 - (gi.scale * gi.width)/2 , con.GetScreenHeight()/2 - (gi.scale * gi.height)/2, 255, 255, 255);


  go = data.m_player.GetGameObject();

  for(int j = 7; j <= 8; ++j){//5..9
    for(int i = 0; i < data.m_pObject.size(); ++i){
      if(data.m_pObject[i]->go.layer == j ){//&& data.m_pObject[i]->go.alive == true){
        if(data.m_pObject[i]->go.pos.x > px - w - 128  && data.m_pObject[i]->go.pos.x < px + w + 128 &&
           data.m_pObject[i]->go.pos.y > py - h - 128 && data.m_pObject[i]->go.pos.y < py + h + 128)
          con.RenderGraphicModulate(data.m_pObject[i]->go, con.GetScreenWidth()/2 + (data.m_pObject[i]->go.pos.x - go.pos.x) - 16, con.GetScreenHeight()/2 + (data.m_pObject[i]->go.pos.y - go.pos.y) - 16, 255, 255, 255);
      }
    }
  }
   
  //render grandmas
  for(int i = 0; i < data.m_grandma.size(); ++i){
   // pLog->Log(data.m_grandma[i].go.objectID, data.m_grandma[i].go.spriteID, data.m_grandma[i].go.pos.x, data.m_grandma[i].go.pos.y);
    con.RenderGraphicModulate(data.m_grandma[i].go, con.GetScreenWidth()/2 + (data.m_grandma[i].go.pos.x - go.pos.x) - 16, con.GetScreenHeight()/2 + (data.m_grandma[i].go.pos.y - go.pos.y) - 16, 255, 255, 255);
  }


  //draw projectiles
  for(int i = 0; i < data.m_projectiles.size(); ++i){
    gi = con.GetSprite(data.m_projectiles[i].m_WO.spriteID);
    if(data.m_projectiles[i].go.alive == true)
      con.RenderGraphicModulate(data.m_projectiles[i].go, con.GetScreenWidth()/2 + (data.m_projectiles[i].go.pos.x - go.pos.x) - 16, con.GetScreenHeight()/2 + (data.m_projectiles[i].go.pos.y - go.pos.y) - 16, 255, 255, 255);
  }

  //draws a circle around Cindy's position
  if(data.m_player.m_rechargeKindness == false)
    con.DrawCircle(data.m_screenWidth/2, data.m_screenHeight/2, 255, 255, 255, 48);
  else
    con.DrawCircle(data.m_screenWidth/2, data.m_screenHeight/2, 0, 0, 255, 48);

  //draw rectangle around screen
  if(m_bInventory == true)
    con.DrawRect(3, 3, data.m_screenWidth - 6, data.m_screenHeight - 6, 255, 255, 255);
  
  //map
  //************************************************
  gi = con.GetSprite(45);
  go = data.m_player.GetGameObject();

  m_mapX = 10 + gi.width + 220;
  m_mapY = 10;
  if(m_bInventory == true)
    con.DrawRect((float)m_mapX, (float)m_mapY, (float)(m_mapX + 80), (float)(m_mapY + 80), 255,0,0);//draw map
  int smallW = con.GetScreenWidth()/64;
  int smallH = con.GetScreenHeight()/85;
  if(m_bInventory == true)
    con.DrawRect((float)m_mapX + data.m_player.go.pos.x/32 - smallW, (float)m_mapY + data.m_player.go.pos.y/32 - smallH, 
                 (float)m_mapX + data.m_player.go.pos.x/32 + smallW, (float)m_mapY + data.m_player.go.pos.y/32 + smallH,255, 255, 255); //draw player

  //inventory
  //*******************************************************************************
  int transParency = 120;
  if(m_bInventory == true && m_bHelp == false){
    gi = con.GetSprite(58);
    gi.alpha = transParency;
    con.RenderGraphicModulate(gi, m_inventoryX, m_inventoryY, 255, 255, 255);
    if(data.m_weapons[1].exists == true && data.m_weapons[1].rounds > 0 )
      gi = con.GetSprite(65);
    else
      gi = con.GetSprite(64);
    gi.alpha = transParency;
    con.RenderGraphicModulate(gi, m_inventoryX + 14, m_inventoryY + 63,  255, 255, 255);
    if(data.m_weapons[2].exists == true && data.m_weapons[2].rounds > 0)
      gi = con.GetSprite(67);
    else
      gi = con.GetSprite(66);
    gi.alpha = transParency;
    con.RenderGraphicModulate(gi, m_inventoryX + 14, m_inventoryY + 192,  255, 255, 255);
    if(data.m_weapons[3].exists == true  && data.m_weapons[3].rounds > 0)
      gi = con.GetSprite(69);
    else
      gi = con.GetSprite(68);
    gi.alpha = transParency;
    con.RenderGraphicModulate(gi, m_inventoryX + 14, m_inventoryY + 321,  255, 255, 255);

    if(data.m_weapons[4].exists == true  && data.m_weapons[4].rounds > 0)
      gi = con.GetSprite(71);
    else
      gi = con.GetSprite(70);
    gi.alpha = transParency;
    con.RenderGraphicModulate(gi, m_inventoryX + 14, m_inventoryY + 450, 255, 255, 255);
    if(data.m_weapons[5].exists == true  && data.m_weapons[5].rounds > 0)
      gi = con.GetSprite(73);
    else
      gi = con.GetSprite(72);
    gi.alpha = transParency;
    con.RenderGraphicModulate(gi, m_inventoryX + 14, m_inventoryY + 579, 255, 255, 255);
  }

  //display round count
  if(m_bInventory == true && m_bHelp == false){
    con.Print(data.m_weapons[1].rounds, F_V20, m_inventoryX + 24, m_inventoryY + 73, 255, 0, 0, 255);
    con.Print(data.m_weapons[2].rounds, F_V20, m_inventoryX + 24, m_inventoryY + 201, 255, 0, 0, 255);
    con.Print(data.m_weapons[3].rounds, F_V20, m_inventoryX + 24, m_inventoryY + 329, 255, 0, 0, 255);
    con.Print(data.m_weapons[4].rounds, F_V20, m_inventoryX + 24, m_inventoryY + 457, 255, 0, 0, 255);
    con.Print(data.m_weapons[5].rounds, F_V20, m_inventoryX + 24, m_inventoryY + 595, 255, 0, 0, 255);
  }

  //draws outline around selected weapon using m_weaponType;
  if(m_bInventory == true && m_bHelp == false){
    if(data.m_weaponType >= 0 && data.m_weaponType <= 5){
      con.DrawRect(m_inventoryX + 15, m_inventoryY + 64 + ((data.m_weaponType - 1) * 129), m_inventoryX + 139, m_inventoryY + 189 + ((data.m_weaponType - 1) * 129), 255, 0, 0);
      con.DrawRect(m_inventoryX + 16, m_inventoryY + 65 + ((data.m_weaponType - 1) * 129), m_inventoryX + 138, m_inventoryY + 188 + ((data.m_weaponType - 1) * 129), 255, 0, 0);
      con.DrawRect(m_inventoryX + 17, m_inventoryY + 66 + ((data.m_weaponType - 1) * 129), m_inventoryX + 137, m_inventoryY + 187 + ((data.m_weaponType - 1) * 129), 255, 0, 0);
    }
  }

  //status bar
  if(m_bHelp == false){
    gi = con.GetSprite(59);
    gi.alpha = transParency;
    con.RenderGraphicModulate(gi, m_statusX, m_statusY, 255, 255, 255);
   
    //health
    gi = con.GetSprite(60);
    gi.alpha = transParency;
    gi.width =  (float)gi.width * (float)data.m_player.m_health * 0.001;
    con.RenderGraphicModulate(gi, m_statusX + 113, m_statusY + 17, 255, 255, 255);
    gi = con.GetSprite(61);
    gi.alpha = transParency;
    gi.width =  (float)gi.width * (float)data.m_player.m_kindness * 0.001;
    con.RenderGraphicModulate(gi, m_statusX + 113, m_statusY + 43, 255, 255, 255);

    //time and score
    con.Print(data.m_player.m_time, F_V20, m_statusX + 580, m_statusY + 20, 255, 255, 255, 255);
    con.Print(data.m_player.m_score, F_V20, m_statusX + 570, m_statusY + 46, 255, 255, 255, 255);
  }
  //draw mouse cursor
  if(m_bInventory == true){
    con.DrawLine(m_mouse.MouseX(), m_mouse.MouseY(), m_mouse.MouseX() + 15, m_mouse.MouseY(),255,255,0);
    con.DrawLine(m_mouse.MouseX(), m_mouse.MouseY(), m_mouse.MouseX() - 15, m_mouse.MouseY(),255,255,0);
    con.DrawLine(m_mouse.MouseX(), m_mouse.MouseY(), m_mouse.MouseX(), m_mouse.MouseY() + 15,255,255,0);
    con.DrawLine(m_mouse.MouseX(), m_mouse.MouseY(), m_mouse.MouseX(), m_mouse.MouseY() - 15,255,255,0);
  }

  //print text to display
  if(data.m_displayDebugInfo == true){
    //con.Print("PLAY1 STATE - Version", data.m_version, F_V16, 10, 10,  255, 255, 255, 255);
    con.Print("FPS", data.m_FPS , F_V16, 510, 10,  255, 255, 0, 255);
    //con.Print("X", m_mouse.MouseX(), F_V16, 10, 30, 0, 255, 255, 255);
    //con.Print("Y", m_mouse.MouseY(), F_V16, 150, 30, 0, 255, 255, 255);
    //con.Print("X", data.m_player.go.pos.x, F_V16, 10, 50, 0, 255, 255, 255);
    //con.Print("Y", data.m_player.go.pos.y, F_V16, 150, 50, 0, 255, 255, 255);
    //con.Print("Projectiles", data.m_projectiles.size(), F_V16, 10, 70, 255, 0, 255);
  }
  
  //overlay help information
  if(m_bHelp == true){
    gi = con.GetSprite(106);
    con.RenderGraphicModulate(gi, 20, 20, 255, 255, 255);//number keys
    gi = con.GetSprite(107);
    con.RenderGraphicModulate(gi, 700, 20, 255, 255, 255);//H, I, P
    gi = con.GetSprite(108);
    con.RenderGraphicModulate(gi, 20, 250, 255, 255, 255);//W, A, S, D
    gi = con.GetSprite(110);
    con.RenderGraphicModulate(gi, 360, 450, 255, 255, 255);
    gi = con.GetSprite(109);
    con.RenderGraphicModulate(gi, 700, 250, 255, 255, 255);
  }


  if(m_bPause == true)
    con.Print("PAUSED!", F_V20, data.m_screenWidth/2 - 50, data.m_screenHeight/2 - 10, 255, 0, 0, 255);

  //mouse coordinates
  con.Print("Press ESC to quit", F_V20, data.m_screenWidth/2 - 100, data.m_screenHeight/2 + 260, 255, 0, 0, 255);

  //finish rendering
  con.m_d3ddev->EndScene();                             // ends the 3D scene
  hr = con.m_d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
  
  if(FAILED(hr = con.m_d3ddev->TestCooperativeLevel())){
    if(hr == D3DERR_DEVICELOST)
      bLostDevice = true;
      lostCount++;
  }
  return;  
}
Example #21
0
void GameScene::Draw(float gameTime, User& user)
{
	RECT rcSrcRect;
	RECT bgRect;
	D3DXVECTOR3 vecCenter;

	static int offset =0;

	rcSrcRect.left = 0;
	rcSrcRect.top = 0;
	rcSrcRect.right = 59;
	rcSrcRect.bottom = 88;

	vecCenter.x = .0f;
	vecCenter.y = .0f;
	vecCenter.z = .0f;

	srand((unsigned int)time(NULL));
	
	if( currentEnemyNum < om->ManageMaxEnemy() )
	{
		if(GetTickCount()%60==0)
		{
			om->insertObj();
			currentEnemyNum++;
		}
	}
	
	if ((GetKeyState(VK_LEFT) & 0x80000000) && vecPosition.x > 0) 	
			vecPosition.x -= 7.0f;
	if ((GetKeyState(VK_RIGHT) & 0x80000000) && vecPosition.x+rcSrcRect.right < SCREEN_WIDTH) 
		vecPosition.x += 7.0f;
	if ((GetKeyState(VK_UP) & 0x80000000) && vecPosition.y > 0 ) 
		vecPosition.y -= 5.0f;
	if ((GetKeyState(VK_DOWN) & 0x80000000) && vecPosition.y+rcSrcRect.bottom < SCREEN_HEIGHT) 	
		vecPosition.y += 10.0f;

	// 충돌체크
	// 보이는 적중에 부딪히면 파괴
	if(currentEnemyNum>=0)
	{	
		for(int i=0; i<om->ManageMaxEnemy(); i++)
			if(om->getAlive(i))
			{
				if( !(om->getEnemy(i).manageMoving(gDevice->g_pd3dDevice, i*100+100)) ) 
				{
					//새의 위치가 위아래로 벗어나면 파괴
					om->deleteObj(i);
					currentEnemyNum--;
				} 
				else 
				{
					// 충돌체크 보이는 적중에 부딪히면 파괴		
					D3DXVECTOR3* pos = om->getEnemy(i).getPosition();
					if( vecPosition.x < pos->x + BIRD_RECT_RIGHT
						&&pos->x < vecPosition.x + rcSrcRect.right
						&&vecPosition.y < pos->y + BIRD_RECT_BOTTOM
						&&pos->y < vecPosition.y + rcSrcRect.bottom)
					{	
						currentScore -= 50;
						if(currentScore < 0)
							currentScore =0;							
						life -= 10;
						om->deleteObj(i);
						currentEnemyNum--;
					}	
				}
			}
	}

	if(life<=0)
	{
		MessageBox(NULL, _T("Oops! ,You are dead!"), NULL, MB_OK);
		exit(1);
	}
	
	gDevice->Clear(D3DCOLOR_XRGB(0,0,255));
	gDevice->Begin();

	if(spriter != NULL && balloonTexture != NULL && backGroundTexture!= NULL)
	{
		spriter->Begin(D3DXSPRITE_ALPHABLEND);

		bgRect.left = 0;
		bgRect.right = SCREEN_WIDTH;
		bgRect.top = 0;
		bgRect.bottom = SCREEN_HEIGHT;
		vecPosBG.y = -(float)offset;
		spriter->Draw(backGroundTexture, &bgRect, NULL, &vecPosBG, 0xFFFFFFFF);

		bgRect.top = 0;
		bgRect.bottom = offset;
		
		D3DXVECTOR3 vecPosBG2(0,(float)(SCREEN_HEIGHT-offset),0);
		spriter->Draw(backGroundTexture, &bgRect, NULL, &vecPosBG2, 0xFFFFFFFF);
		offset++;
		offset = offset%SCREEN_HEIGHT;

		//시작하고 10초뒤에 골라인 올라옴
		time_t crtTime;
		time(&crtTime);
		if(goalTime < crtTime)
		{
			g_GoalLine.Position.y -= 3.0f;
			spriter->Draw( g_GoalLine.Texture, &g_GoalLine.Source, &g_GoalLine.Center, &g_GoalLine.Position, 0xffffffff );
		}
		
		if(currentEnemyNum > 0)
		{
			for(int i=0; i<om->ManageMaxEnemy(); i++)
			{
				if(om->getAlive(i) == TRUE)
					spriter->Draw( om->getEnemy(i).getTexture(), om->getEnemy(i).getSource(), om->getEnemy(i).getCenter(), om->getEnemy(i).getPosition(), 0xffffffff );
			}
		}

		// 골라인과 플레이어가 만나면 
		if ( g_GoalLine.Position.y < vecPosition.y )
		{
			if(currentStage == 5)
			{
				// 스테이지 클리어
				user.SetScore(currentScore);
				user.SetStage(currentStage);
				user.SetUserState(user.GAME_CLEAR);
				SetGameOver(true);
				//MessageBox(NULL, _T("ALL STAGE CLEAR!, Congraturations!"), NULL, MB_OK);
				//exit(0);
			}
			currentStage++;
			delete om;
			InitStage(currentStage);
		}

		spriter->Draw(balloonTexture, &rcSrcRect, &vecCenter, &vecPosition, 0xffffffff);

		RECT scoreRect = {400,20,-1,-1};
		RECT lifeRect = {20,20,-1,-1};
		RECT stageRect = {220,20,-1,-1};
		
		if(prevTimer == NULL)
			prevTimer = crtTime;
		if(crtTime-prevTimer != 0)
		{
			currentScore+=5;
		}
		prevTimer = crtTime;

		std::string scoreStr = "SCORE ";
		scoreStr.append(std::to_string(currentScore));

		std::string lifeStr = "LIFE ";
		lifeStr.append(std::to_string(life));

		std::string stageStr = "STAGE ";

		stageStr.append(std::to_string(om->GetStageNumber()));

		std::wstring scoreWstr = std::wstring(scoreStr.begin(), scoreStr.end());
		std::wstring lifeWstr = std::wstring(lifeStr.begin(), lifeStr.end());
		std::wstring stageWstr = std::wstring(stageStr.begin(), stageStr.end());
		//LPCWSTR scoreResult = _T(scoreStr.c_str());
		if(scoreFont)
			scoreFont->DrawText(spriter, scoreWstr.c_str(), scoreWstr.length(), &scoreRect, DT_NOCLIP, D3DXCOLOR(0,0,0,1));

		if(lifeFont)
			lifeFont->DrawText(spriter, lifeWstr.c_str(), lifeWstr.length(), &lifeRect,DT_NOCLIP, D3DXCOLOR(0,0,0,1));
		if(stageFont)
			stageFont->DrawText(spriter, stageWstr.c_str(), stageWstr.length(), &stageRect, DT_NOCLIP, D3DXCOLOR(0,0,0,1));
	
		spriter->End();
	}
	//else
		//MessageBox(NULL, _T("Error"), NULL, NULL);
	gDevice->End();
	gDevice->Present();
}
    int Engine::Init(int width, int height, int colordepth, bool fullscreen)
    {
       //initialize Direct3D
        this->p_d3d = Direct3DCreate9(D3D_SDK_VERSION);
        if (this->p_d3d == NULL) {
            return 0;
        }
    
        //get system desktop color depth
        D3DDISPLAYMODE dm;
        this->p_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dm);
    
        //set configuration options for Direct3D
        D3DPRESENT_PARAMETERS d3dpp;
        ZeroMemory(&d3dpp, sizeof(d3dpp));
        d3dpp.Windowed = (!fullscreen);
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
        d3dpp.EnableAutoDepthStencil = TRUE;
        d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
        d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;
        d3dpp.BackBufferFormat = dm.Format;
        d3dpp.BackBufferCount = 1;
        d3dpp.BackBufferWidth = width;
        d3dpp.BackBufferHeight = height;
        d3dpp.hDeviceWindow = p_windowHandle;
    
        //create Direct3D device
        this->p_d3d->CreateDevice(
            D3DADAPTER_DEFAULT,
            D3DDEVTYPE_HAL,
            this->p_windowHandle,
            D3DCREATE_HARDWARE_VERTEXPROCESSING,
            &d3dpp,
            &this->p_device);
    
        if (this->p_device == NULL) return 0;
    
        //clear the backbuffer to black
        this->ClearScene(D3DCOLOR_XRGB(0,0,0));
    
        //create pointer to the back buffer
        this->p_device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &this->p_backbuffer);
    
        //use ambient lighting and z-buffering
        this->p_device->SetRenderState(D3DRS_ZENABLE, TRUE);
        this->p_device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);

        this->p_device->SetRenderState(D3DRS_LIGHTING, true);
        this->SetAmbient(this->p_ambientColor);
    
        //initialize 2D renderer
        HRESULT result = D3DXCreateSprite(this->p_device, &this->p_sprite_handler);
        if (result != D3D_OK) return 0;
    
		//initialize DirectInput
        p_input = new Input(this->getWindowHandle());

        //create audio system
        audio = new Audio();
        if (!audio->Init())    return 0;

        
        //call game initialization extern function
        if (!game_init(this->getWindowHandle()))
            return 0;
    
        //set a default material
        SetDefaultMaterial();
    
        return 1;
    }
bool Render()
{
	LRESULT lRet;
	//Read Data
	//RGB
	if (fread(buffer, 1, pixel_w*pixel_h*bpp/8, fp) != pixel_w*pixel_h*bpp/8){
		// Loop
		fseek(fp, 0, SEEK_SET);
		fread(buffer, 1, pixel_w*pixel_h*bpp/8, fp);
	}

	if(buffer == NULL || m_pDirect3DDevice == NULL) 
		return false;
	//Clears one or more surfaces
	lRet = m_pDirect3DDevice->Clear(0, NULL, D3DCLEAR_TARGET,
		D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0);
	
	D3DLOCKED_RECT d3d_rect;
	//Locks a rectangle on a texture resource.
	//And then we can manipulate pixel data in it.
	lRet = m_pDirect3DTexture->LockRect( 0, &d3d_rect, 0, 0 );
	if ( FAILED(lRet) ){
		return false;
	}
	// Copy pixel data to texture
	byte *pSrc = buffer;
	byte *pDest = (byte *)d3d_rect.pBits;
	int stride = d3d_rect.Pitch;
	unsigned long i = 0;


	int pixel_w_size=pixel_w*bpp/8;
	for(unsigned long i=0; i< pixel_h; i++){
		memcpy( pDest, pSrc, pixel_w_size );
		pDest += stride;
		pSrc += pixel_w_size;
	}

	m_pDirect3DTexture->UnlockRect( 0 );

	//Begin the scene
	if ( FAILED(m_pDirect3DDevice->BeginScene()) ){
		return false;
	}

	lRet = m_pDirect3DDevice->SetTexture( 0, m_pDirect3DTexture );

	
	//Binds a vertex buffer to a device data stream.
	m_pDirect3DDevice->SetStreamSource( 0, m_pDirect3DVertexBuffer,
		0, sizeof(CUSTOMVERTEX) );
	//Sets the current vertex stream declaration.
	lRet = m_pDirect3DDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
	//Renders a sequence of nonindexed, geometric primitives of the 
	//specified type from the current set of data input streams.
	m_pDirect3DDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 );
	m_pDirect3DDevice->EndScene();
	//Presents the contents of the next buffer in the sequence of back 
	//buffers owned by the device.
	m_pDirect3DDevice->Present( NULL, NULL, NULL, NULL );
	return true;
}
Example #24
0
void Render()
{
	if (NULL == device.GetDirect3D())
	{
		return;
	}
	device.Get3DDevice()->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, D3DCOLOR_XRGB(0, 100, 130), 1.0f, 0);
	device.Get3DDevice()->BeginScene();
	device.light.SetLightForShader();
	D3DXMATRIX m = plane.CreateShadowMatrix(device.light.PointLightPosition);
    pyramid.SetShadowMatrix(m);
	cylinder.SetShadowMatrix(m);
	device.Get3DDevice()->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE);
	plane.Draw(false);
	device.Get3DDevice()->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_ZERO);
	device.Get3DDevice()->SetRenderState(D3DRS_ZENABLE, FALSE);
    device.Get3DDevice()->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL);
    device.Get3DDevice()->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	pyramid.Draw(true);  //shadow
	cylinder.Draw(true); //shadow
	
	device.Get3DDevice()->SetRenderState(D3DRS_ZENABLE, TRUE);
    device.Get3DDevice()->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
    device.Get3DDevice()->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
	cylinder.Draw(false); //model
	pyramid.Draw(false);  //model
	device.Get3DDevice()->EndScene();
	device.Get3DDevice()->Present(NULL, NULL, NULL, NULL);
}
Example #25
0
//
// Program starts here
//
int main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
    //
    // Create a window and attach directx to it
    //
    g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
    g_pHWND = CreateGameWindow();
    CreateD3DDevice();
    RECT FrameBounds;
    GetClientRect(g_pHWND, &FrameBounds);
    //
    // Create a GWEN DirectX renderer
    //
    Gwen::Renderer::DirectX9* pRenderer = new Gwen::Renderer::DirectX9(g_pD3DDevice);
    //
    // Create a GWEN skin
    //
    Gwen::Skin::TexturedBase* pSkin = new Gwen::Skin::TexturedBase(pRenderer);
    pSkin->Init("DefaultSkin.png");
    //
    // Create a Canvas (it's root, on which all other GWEN panels are created)
    //
    Gwen::Controls::Canvas* pCanvas = new Gwen::Controls::Canvas(pSkin);
    pCanvas->SetSize(FrameBounds.right, FrameBounds.bottom);
    pCanvas->SetDrawBackground(true);
    pCanvas->SetBackgroundColor(Gwen::Color(150, 170, 170, 255));
    //
    // Create our unittest control (which is a Window with controls in it)
    //
    UnitTest* pUnit = new UnitTest(pCanvas);
    pUnit->SetPos(10, 10);
    //
    // Create a Windows Control helper
    // (Processes Windows MSG's and fires input at GWEN)
    //
    Gwen::Input::Windows GwenInput;
    GwenInput.Initialize(pCanvas);
    //
    // Begin the main game loop
    //
    MSG msg;

    while (true)
    {
        // Skip out if the window is closed
        if (!IsWindowVisible(g_pHWND))
            break;

        // If we have a message from windows..
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            // .. give it to the input handler to process
            GwenInput.ProcessMessage(msg);

            // if it's QUIT then quit..
            if (msg.message == WM_QUIT)
                break;

            // Handle the regular window stuff..
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
        {
            // Normal DirectX rendering loop
            g_pD3DDevice->BeginScene();
            g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1, 0);
            // This is how easy it is to render GWEN!
            pCanvas->RenderCanvas();
            g_pD3DDevice->EndScene();
            g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
        }
    }

    delete pCanvas;
    delete pSkin;
    delete pRenderer;

    if (g_pD3DDevice)
    {
        g_pD3DDevice->Release();
        g_pD3DDevice = NULL;
    }

    if (g_pD3D)
    {
        g_pD3D->Release();
        g_pD3D = NULL;
    }
}
//////////////////////////////////////////////////////////////////////////
//캐릭터 툴을 위한 렌더 함수
//render를 pre - main - post renderring 구조에서 main을 담당
//////////////////////////////////////////////////////////////////////////
YAMANGDXDLL_API void RenderingTool( MESHOBJECT* inputVal )
{
	if ( NULL == g_D3dDevice )
	{
		return;
	}

	if ( g_Mesh == nullptr )
	{
		InitGroundMesh( 100, 100 );
	}
	g_D3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 30, 10, 10 ), 1.0f, 0 );

	// 렌더 방어코드
	if ( SUCCEEDED( g_D3dDevice->BeginScene() ) )
	{
		// SetupTranslateMatricesTool();
		// 일단 height map 등 다른 쪽을 생각할 것

		// ViewSetting();

		// lightsetting
		// 일단 1로 진행, 향후 라이트 개수 등 확정되면 인자 받아 설정
		int lightNum = 1;
		Lighting( lightNum );
		// Log( "라이팅 세팅!\n" );

		g_D3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
		g_D3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		g_D3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
		g_D3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

		// Log( "Render Begin \n" );
		// Log( "pre render 완료!\n" );
	}

	// 카메라 셋팅
	D3DXMATRIXA16 viewMatrix;
	D3DXMatrixLookAtLH( &viewMatrix, &g_EyePoint, &g_LookAtPoint, &g_UpVector );
	SetCameraMatrix( &viewMatrix );

	// 보여주기 위한 땅을 만듬
	//InitGroundMesh(100, 100);
	CreateRawGround( 100, 100, 10 );
	RenderHeightMap();

	g_D3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );

	// Log( "Now Render : %p \n", inputVal );
	for ( DWORD i = 0; i < inputVal->NumMaterials; ++i )
	{
		g_D3dDevice->SetMaterial( &inputVal->MeshMarterials[i] );
		g_D3dDevice->SetTexture( 0, inputVal->MeshTexture[i] );

		( inputVal->importedMesh )->DrawSubset( i );
	}
	g_D3dDevice->EndScene();

	// Log( "Render End \n" );
	g_D3dDevice->Present( NULL, NULL, NULL, NULL );
}
Example #27
0
bool MoonScene::Initialize(D3DCAPS9* d3dCaps, const char* scenename)
{
	_device = NULL;
	_d3dCaps = d3dCaps;
	//检查场景配置文件是否存在
	string scnpath(SCENE_DIR(scenename));
	scnpath += ".scn";
	if(!PathFileExists(scnpath.c_str()))
	{
		LogError("MoonScene::Initialize() Cannot find scene configure file!");
		::MessageBox(0,"Cannot find scene configure file, please check bin/start.cfg.",0,0);
		return false;
	}

	char ch[256];
	string temp;
	char c[5];
	//读取场景配置信息
	GetPrivateProfileString("configure","bRenderCollisionBox","false",ch,256,scnpath.c_str());
	temp = ch;
	if(temp == "true")
		_CollisionTS = new MoonCollision(true);
	else
		_CollisionTS = new MoonCollision();

	//初始化摄像机
	_ThirdCamera = new MoonCamera(MoonCamera::RPG);
	_ThirdCamera->setPosition(&D3DXVECTOR3(0.0f, 0.0f, 0.0f));
	_ThirdCamera->setLook(&D3DXVECTOR3(0.0f, 0.0f, 1.0f));
	LogInfo("MoonScene::Initialize() Initialize CameraOnPlayer OK!");
	_FirstCamera = new MoonCamera(MoonCamera::LANDOBJECT);
	_FirstCamera->setPosition(&D3DXVECTOR3(0.0f, 150.0f, 0.0f));
	_FirstCamera->setLook(&D3DXVECTOR3(0.0f, 0.0f, 1.0f));
	LogInfo("MoonScene::Initialize() Initialize FreeCamera OK!");
	_Camera = _ThirdCamera;

	//读取地形和天空的配置名称
	GetPrivateProfileString("environment","terrain",NULL,ch,256,scnpath.c_str());
	_terrainname = ch;
	GetPrivateProfileString("environment","skybox",NULL,ch,256,scnpath.c_str());
	_skyboxname = ch;

	//读取环境光照参数
	D3DXVECTOR3 v;
	GetPrivateProfileString("environmentlight","range",NULL,ch,256,scnpath.c_str());
	_environmentLight.Range=CharToFloat(ch);
	GetPrivateProfileString("environmentlight","diffuse",NULL,ch,256,scnpath.c_str());
	v = CharToVector3(ch);
	_environmentLight.Diffuse.r=v.x;
	_environmentLight.Diffuse.b=v.y;
	_environmentLight.Diffuse.g=v.z;
	GetPrivateProfileString("environmentlight","ambient",NULL,ch,256,scnpath.c_str());
	v = CharToVector3(ch);
	_environmentLight.Ambient.r=v.x;
	_environmentLight.Ambient.b=v.y;
	_environmentLight.Ambient.g=v.z;
	GetPrivateProfileString("environmentlight","specular",NULL,ch,256,scnpath.c_str());
	v = CharToVector3(ch);
	_environmentLight.Specular.r=v.x;
	_environmentLight.Specular.b=v.y;
	_environmentLight.Specular.g=v.z;
	GetPrivateProfileString("environmentlight","direction",NULL,ch,256,scnpath.c_str());
	v = CharToVector3(ch);
	D3DXVec3Normalize((D3DXVECTOR3*)&(_environmentLight.Direction),&v);
	_environmentLight.Type = D3DLIGHT_DIRECTIONAL;

	GetPrivateProfileString("ambient","ambient",NULL,ch,256,scnpath.c_str());
	_ambient = CharToVector3(ch);

	//读取雾化参数
	GetPrivateProfileString("fog","fog",NULL,ch,256,scnpath.c_str());
	temp = ch;
	if(temp == "true")
	{
		_dwFog = TRUE;
		GetPrivateProfileString("fog","fogcolor",NULL,ch,256,scnpath.c_str());
		v = CharToVector3(ch);
		_dwFogColor = D3DCOLOR_XRGB((int)v.x,(int)v.y,(int)v.z);
		GetPrivateProfileString("fog","fogtablemode",NULL,ch,256,scnpath.c_str());
		temp = ch;
		float f;
		if(temp == "linear")
		{
			_dwFogTableMode = D3DFOG_LINEAR;
			GetPrivateProfileString("fog","fogstart",NULL,ch,256,scnpath.c_str());
			f = CharToFloat(ch);
			_dwFogStart = *(DWORD*)&f;
			GetPrivateProfileString("fog","fogend",NULL,ch,256,scnpath.c_str());
			f = CharToFloat(ch);
			_dwFogEnd = *(DWORD*)&f;
		}
		else
		{
			if(temp == "exp")
				_dwFogTableMode = D3DFOG_EXP;
			else if(temp == "exp2")
				_dwFogTableMode = D3DFOG_EXP2;
			GetPrivateProfileString("fog","fogdensity",NULL,ch,256,scnpath.c_str());
			f = CharToFloat(ch);
			_dwFogDensity = *(DWORD*)&f;
		}
	}
	else
	{
		_dwFog = FALSE;
	}

	//读取角色相关参数
	string strPlayerName;
	D3DXVECTOR3 PlayerPos;
	D3DXVECTOR3 PlayerDir;
	D3DXVECTOR3 PlayerScl;
	GetPrivateProfileString("player","player",NULL,ch,256,scnpath.c_str());
	strPlayerName = ch;
	GetPrivateProfileString("player","position",NULL,ch,256,scnpath.c_str());
	PlayerPos = CharToVector3(ch);
	GetPrivateProfileString("player","direction",NULL,ch,256,scnpath.c_str());
	PlayerDir = CharToVector3(ch);
	GetPrivateProfileString("player","scale",NULL,ch,256,scnpath.c_str());
	PlayerScl = CharToVector3(ch);
	_thePlayer = new MoonCharacter(_d3dCaps,strPlayerName.c_str(), _ID++ ,PlayerPos,PlayerDir, PlayerScl);
	LogInfo("MoonScene::Initialize() Create MoonCharacter OK!");
	ReadCollisionBox("player",scnpath.c_str(),_thePlayer);

	//读取地面物体参数
	_blockcount = 0;
	_pBlock = NULL;
	GetPrivateProfileString("block","blockcount","0",ch,256,scnpath.c_str());
	_blockcount = CharToInt(ch);
	if(_blockcount>0)
		_pBlock = new MoonBlock[_blockcount];
	string str="block";
	string blockname;
	D3DXVECTOR3 blockpos,blockscl,blockrot;
	for(int i = 0; i < _blockcount; i++)
	{
		sprintf_s(c,"%04d",i);
		str+=c;
		GetPrivateProfileString(str.c_str(),"name",NULL,ch,256,scnpath.c_str());
		blockname = ch;
		GetPrivateProfileString(str.c_str(),"pos",NULL,ch,256,scnpath.c_str());
		blockpos = CharToVector3(ch);
		GetPrivateProfileString(str.c_str(),"scl",NULL,ch,256,scnpath.c_str());
		blockscl = CharToVector3(ch);
		GetPrivateProfileString(str.c_str(),"rot",NULL,ch,256,scnpath.c_str());
		blockrot = CharToVector3(ch);
		(_pBlock[i]).Initialize(_d3dCaps,blockname.c_str(), _ID++ ,blockpos,blockrot,blockscl);
		LogInfo("MoonScene::Initialize() Create new MoonBlock, name: %s.",blockname.c_str());
		ReadCollisionBox(str.c_str(),scnpath.c_str(),&_pBlock[i]);
		str="block";
	}

	//是否下雨
	GetPrivateProfileString("rain","brainy","false",ch,256,scnpath.c_str());
	temp = ch;
	if(temp=="true")
		_pRain = new MoonRain();
	else
		_pRain = NULL;

	D3DXVECTOR3 vec1,vec2;
	//是否下雪
	GetPrivateProfileString("snow","bsnow","false",ch,256,scnpath.c_str());
	temp = ch;
	if(temp=="true")
	{
		GetPrivateProfileString("snow","boundingmin","(0,0,0)",ch,256,scnpath.c_str());
		vec1 = CharToVector3(ch);
		GetPrivateProfileString("snow","boundingmax","(1,1,1)",ch,256,scnpath.c_str());
		vec2 = CharToVector3(ch);
		GetPrivateProfileString("snow","size","0.5",ch,256,scnpath.c_str());
		float fsize = CharToFloat(ch);
		GetPrivateProfileString("snow","texture","snow.tga",ch,256,scnpath.c_str());
		_SnowTex = ch;
		GetPrivateProfileString("snow","numparticles","100",ch,256,scnpath.c_str());
		int num = CharToInt(ch);
		_SnowSystem = new MoonSnow(&BoundingBox(&vec1, &vec2), fsize, num);
	}
	else
		_SnowSystem = NULL;

	//是否绘制焰火
	GetPrivateProfileString("firework","bfirework","false",ch,256,scnpath.c_str());
	temp = ch;
	if(temp=="true")
	{
		GetPrivateProfileString("firework","position","(0,0,0)",ch,256,scnpath.c_str());
		vec1 = CharToVector3(ch);
		GetPrivateProfileString("firework","texture","fire.tga",ch,256,scnpath.c_str());
		_FireTex = ch;
		GetPrivateProfileString("firework","numparticles","100",ch,256,scnpath.c_str());
		int num = CharToInt(ch);
		_Firework = new MoonFirework(&vec1,num);
	}
	else
		_Firework = NULL;

	// 读取水体配置信息
	GetPrivateProfileString("water","water","false",ch,256,scnpath.c_str());
	temp = ch;
	if(temp == "true")
		_pWater = new MoonWater();
	else
		_pWater = NULL;
	if(_pWater)
	{
		GetPrivateProfileString("water","height","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","flx","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","flz","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","brx","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","brz","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","waveheight","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","flowspeedu","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","flowspeedv","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
	}

	_SoundManager = new MoonSoundManager();
	if(_SoundManager->Initialize())
		LogInfo("MoonScene::Initialize() SoundManager initialized OK!");

	return true;
}
Example #28
0
//===========================================================================
// DG_Color3ub
//===========================================================================
void DG_Color3ub(DGLubyte r, DGLubyte g, DGLubyte b)
{
	currentVertex.color = D3DCOLOR_XRGB(r, g, b);
}
Example #29
0
void Sprite::SetColor(Engine::EColor eColor)
{
    static D3DCOLOR aZXColors[] = {
        D3DCOLOR_XRGB(  0,   0,   0),	// Black
        D3DCOLOR_XRGB(  0,   0, 200),	// Blue
        D3DCOLOR_XRGB(200,   0,   0),	// Red
        D3DCOLOR_XRGB(200,   0, 200),	// Magenta

        D3DCOLOR_XRGB(  0, 200,   0),	// Green
        D3DCOLOR_XRGB(  0, 200, 200),	// Cyan
        D3DCOLOR_XRGB(200, 200,   0),	// Yellow
        D3DCOLOR_XRGB(200, 200, 200),	// Grey

        D3DCOLOR_XRGB(  0,   0,   0),	// Light black
        D3DCOLOR_XRGB(  0,   0, 248),	// Light blue
        D3DCOLOR_XRGB(248,   0,   0),	// Light red
        D3DCOLOR_XRGB(248,   0, 248),	// Light magenta

        D3DCOLOR_XRGB(  0, 248,   0),	// Light green
        D3DCOLOR_XRGB(  0, 248, 248),	// Light cyan
        D3DCOLOR_XRGB(248, 248,   0),	// Light yellow
        D3DCOLOR_XRGB(248, 248, 248),	// White
    };

    m_color = aZXColors[eColor];
}
Example #30
0
float CExplosive::ExplosionEffect(collide::rq_results& storage, CExplosive*exp_obj,CPhysicsShellHolder*blasted_obj,  const Fvector &expl_centre, const float expl_radius) 
{
	
	const Fmatrix	&obj_xform=blasted_obj->XFORM();
	Fmatrix	inv_obj_form;inv_obj_form.invert(obj_xform);
	Fvector	local_exp_center;inv_obj_form.transform_tiny(local_exp_center,expl_centre);

	const Fbox &l_b1 = blasted_obj->BoundingBox();
	if(l_b1.contains(local_exp_center)) 
										return 1.f;
	Fvector l_c, l_d;l_b1.get_CD(l_c,l_d);
	float effective_volume=l_d.x*l_d.y*l_d.z;
	float max_s=effective_volume/(_min(_min(l_d.x,l_d.y),l_d.z));
	if(blasted_obj->PPhysicsShell()&&blasted_obj->PPhysicsShell()->isActive())
	{
		float ph_volume=blasted_obj->PPhysicsShell()->getVolume();
		if(ph_volume<effective_volume)effective_volume=ph_volume;
	}
	float effect=0.f;
#ifdef DEBUG
	if(ph_dbg_draw_mask.test(phDbgDrawExplosions))
	{
		Fmatrix dbg_box_m;dbg_box_m.set(obj_xform);
		dbg_box_m.c.set(l_c);obj_xform.transform(dbg_box_m.c);
		DBG_DrawOBB(dbg_box_m,l_d,D3DCOLOR_XRGB(255,255,0));
	}
#endif

	for(u16 i=0;i<TEST_RAYS_PER_OBJECT;++i){
		Fvector l_source_p,l_end_p;
		l_end_p.random_point(l_d);
		l_end_p.add(l_c);
		obj_xform.transform_tiny(l_end_p);
		GetRaySourcePos(exp_obj,expl_centre,l_source_p);
		Fvector l_local_source_p;inv_obj_form.transform_tiny(l_local_source_p,l_source_p);
		if(l_b1.contains(l_local_source_p))
		{
			effect+=1.f;continue;
		}
		Fvector l_dir; l_dir.sub(l_end_p,l_source_p);
		float mag=l_dir.magnitude();
		
		if(fis_zero(mag)) return 1.f;

		l_dir.mul(1.f/mag);
#ifdef DEBUG
			if(ph_dbg_draw_mask.test(phDbgDrawExplosions))
			{
			DBG_DrawPoint(l_source_p,0.1f,D3DCOLOR_XRGB(0,0,255));
			DBG_DrawPoint(l_end_p,0.1f,D3DCOLOR_XRGB(0,0,255));
			DBG_DrawLine(l_source_p,l_end_p,D3DCOLOR_XRGB(0,0,255));
			}
#endif
		
#ifdef DEBUG
		float l_S=effective_volume*(_abs(l_dir.dotproduct(obj_xform.i))/l_d.x+_abs(l_dir.dotproduct(obj_xform.j))/l_d.y+_abs(l_dir.dotproduct(obj_xform.k))/l_d.z);
		float add_eff=_sqrt(l_S/max_s)*TestPassEffect(l_source_p,l_dir,mag,expl_radius,storage,blasted_obj);
		effect+=add_eff;
		if(ph_dbg_draw_mask.test(phDbgDrawExplosions))
		{
			Msg("dist %f,effect R %f",mag,expl_radius);
			Msg("test pass effect %f",add_eff);
			Msg("S effect %f",_sqrt(l_S/max_s));
			Msg("dist/overlap effect, %f",add_eff/_sqrt(l_S/max_s));
		}
#else
		float l_S=effective_volume*(_abs(l_dir.dotproduct(obj_xform.i))/l_d.x+_abs(l_dir.dotproduct(obj_xform.j))/l_d.y+_abs(l_dir.dotproduct(obj_xform.k))/l_d.z);
		effect+=_sqrt(l_S/max_s)*TestPassEffect(l_source_p,l_dir,mag,expl_radius,storage,blasted_obj);
#endif

	}
#ifdef DEBUG
	if(ph_dbg_draw_mask.test(phDbgDrawExplosions))
	{
			Msg("damage effect %f",effect/TEST_RAYS_PER_OBJECT);
	}
#endif
	return effect/TEST_RAYS_PER_OBJECT;
	
}