This is where I'm rendering the primitives, in the switch is where I'm displaying the HP bar
the HP is at 100 its just an int that hold the HP and I've loaded 11 different textures for the health
starting from hp 0,1,2,3,4,5,6,7,8,9,10. The calculation for subtracting from the HP bar is elsewhere, what I'm having
trouble with is getting the HP bar to either follow a player model on the screen or to get the bar to follow the viewport so that it follows the screen on the bottom right hand corner, I'm not sure how to approach this problem.
void vRenderScene(void)
{
D3DXMATRIX matWorld;
D3DXMATRIX matTranslation;
D3DXMATRIX matRotation;
D3DXMATRIX matRotation2;
D3DXMATRIX matScale;
int i, j;
int mat; //material
RECT rTemp4 = { 5, 5, 600, 30 };
RECT rTemp1 = { 5, (SCREEN_HEIGHT-65), 400, (SCREEN_HEIGHT) };
char szScore[256];
// Clear the backbuffer and the zbuffer
pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
// Begin Rendering
pd3dDevice->BeginScene();
// Update the camera position
vUpdateCamera();
// Set the vertex buffer to render
pd3dDevice->SetStreamSource( 0, lpVertexBuffer,0, sizeof(MYVERTEX) );
// Set the vertex format
pd3dDevice->SetFVF( D3DFVF_MYVERTEX );
// Draw the Ground and walls
for( i = -5; i < 5; i++) {
for( j = -5; j < 5; j++) {
// Draw back wall
if( i == -5 ) {
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, (j*50.0f)+25.0f, 25.0f, (i*50.0f)+0.0f );
D3DXMatrixRotationX( &matRotation, 0.0f/RADIAN_TO_DEGREES );
//combine the matrix, order is important
matScale *= matRotation;
matScale *= matTranslation;
//tell the device to us this matrix
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
if( j == 0 )
pd3dDevice->SetTexture( 0, g_pTexture[12] );
else
pd3dDevice->SetTexture( 0, g_pTexture[11] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
}
// Front Wall
else if( i == 4 ) {
if( PlayerInfo[g_iMyPlayerId].vecCurPos.z >= 200.0f )
pd3dDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);
else
pd3dDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, (j*50.0f)+25.0f, 25.0f, (i*50.0f)+50.0f );
D3DXMatrixRotationX( &matRotation, 0.0f/RADIAN_TO_DEGREES );
matScale *= matRotation;
matScale *= matTranslation;
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
if( j == 0 )
pd3dDevice->SetTexture( 0, g_pTexture[12] );
else
pd3dDevice->SetTexture( 0, g_pTexture[11] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
pd3dDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
}
//left wall
if( j == -5 ) {
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, (j*50.0f), 25.0f, (i*50.0f)+25.0f );
D3DXMatrixRotationY( &matRotation, 90.0f/RADIAN_TO_DEGREES );
matScale *= matRotation;
matScale *= matTranslation;
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
if( i == 0 )
pd3dDevice->SetTexture( 0, g_pTexture[12] );
else
pd3dDevice->SetTexture( 0, g_pTexture[11] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
}
//right wall
if( j == 4 ) {
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, (j*50.0f)+50.0f, 25.0f, (i*50.0f)+25.0f );
D3DXMatrixRotationY( &matRotation, -90.0f/RADIAN_TO_DEGREES );
matScale *= matRotation;
matScale *= matTranslation;
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
if( i == 0 )
pd3dDevice->SetTexture( 0, g_pTexture[12] );//set texture activates a texture ,we are using texture array
else
pd3dDevice->SetTexture( 0, g_pTexture[11] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
}
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, (j*50.0f)+25.0f, 0.0f, (i*50.0f)+25.0f );
D3DXMatrixRotationX( &matRotation, -90.0f/RADIAN_TO_DEGREES );
matScale *= matRotation;
matScale *= matTranslation;
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
//different pictures on the floor
if( (i == -5 && j == -5) || (i == 4 && j == -5) || (i == -5 && j == 4) || (i == 4 && j == 4) )
pd3dDevice->SetTexture( 0, g_pTexture[13] );
else
pd3dDevice->SetTexture( 0, g_pTexture[10] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
}
}
// Display our Robots
for( i = 0 ; i < MAX_PLAYERS ; i++ ) {
if( PlayerInfo[i].bActive )
o3dShip[PlayerInfo[i].iFrame].vDisplayXYZ(PlayerInfo[i].vecCurPos.x,
0.0f, //Y
PlayerInfo[i].vecCurPos.z,
0.0f,//x rot
PlayerInfo[i].fRot,// y rot
0.0f);//z rot
}
// Restore scene material
pd3dDevice->SetMaterial( &mtrlDefault );
// Display Explosions, setup rendering for transparency
pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
// Make ambient completely bright, this will make sure explosions are bright
pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0xffffffff );
pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
// Set the vertex buffer to render
pd3dDevice->SetStreamSource( 0, lpVertexBuffer,0, sizeof(MYVERTEX) );
// Set the vertex format
// pd3dDevice->SetVertexShader( D3DFVF_MYVERTEX );
pd3dDevice->SetFVF( D3DFVF_MYVERTEX );
// Disable lighting
pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
// Render active Explosions
for( i = 0 ; i < MAX_EXPLOSIONS ; i++ ) {
if( Explosion[i].bActive ) {
D3DXMatrixTranslation( &matTranslation, Explosion[i].fx, 0.0f+(0.25f*i), Explosion[i].fz );
D3DXMatrixRotationX( &matRotation, -90.0f/RADIAN_TO_DEGREES );
matRotation *= matTranslation;
pd3dDevice->SetTransform(D3DTS_WORLD, &matRotation);
// Set the explosion's texture frame
pd3dDevice->SetTexture( 0, g_pTexture[Explosion[i].iFrame] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
}
}
// Turn Z-buffer back on
pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
// Activate the bullet texture
pd3dDevice->SetTexture( 0, g_pTexture[14] );
// Render Bullets
for( i = 0 ; i < MAX_BULLETS ; i++ ) {
if( Bullet[i].bActive ) {
D3DXMatrixScaling( &matScale, 0.5f, 0.5f, 0.5f );
D3DXMatrixTranslation( &matTranslation, Bullet[i].fx, 15.0f, Bullet[i].fz );
D3DXMatrixRotationX( &matRotation, -90.0f/RADIAN_TO_DEGREES );
matScale *= matRotation;
matScale *= matTranslation;
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
}
}
////HP bar Render setup
pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
switch(PlayerInfo[0].HP)
{
//___________________________________________________________________________
case 100:
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, 1.0f, 1.0f, 1.0f );
D3DXMatrixRotationX( &matRotation, 0.0f/RADIAN_TO_DEGREES );
//combine the matrix, order is important
matScale *= matRotation;
matScale *= matTranslation;
//tell the device to us this matrix
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
pd3dDevice->SetTexture( 0, g_pTexture[25] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
break;
//___________________________________________________________________________
case 90:
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation,
(PlayerInfo[g_iMyPlayerId].vecCurPos.x + 2.0f),
PlayerInfo[g_iMyPlayerId].vecCurPos.y,
(PlayerInfo[g_iMyPlayerId].vecCurPos.z + 2.0f));
D3DXMatrixRotationX( &matRotation, 0.0f/RADIAN_TO_DEGREES );
//combine the matrix, order is important
//tell the device to us this matrix
pd3dDevice->SetTransform(D3DTS_WORLD, &matTranslation);
pd3dDevice->SetTexture( 0, g_pTexture[24] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
break;
//___________________________________________________________________________
case 80:
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, 1.0f, 1.0f, 1.0f );
D3DXMatrixRotationX( &matRotation, 0.0f/RADIAN_TO_DEGREES );
//combine the matrix, order is important
matScale *= matRotation;
matScale *= matTranslation;
//tell the device to us this matrix
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
pd3dDevice->SetTexture( 0, g_pTexture[23] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
break;
//___________________________________________________________________________
case 70:
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, 1.0f, 1.0f, 1.0f );
D3DXMatrixRotationX( &matRotation, 0.0f/RADIAN_TO_DEGREES );
//combine the matrix, order is important
matScale *= matRotation;
matScale *= matTranslation;
//tell the device to us this matrix
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
pd3dDevice->SetTexture( 0, g_pTexture[22] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
break;
//___________________________________________________________________________
case 60:
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, 1.0f, 1.0f, 1.0f );
D3DXMatrixRotationX( &matRotation, 0.0f/RADIAN_TO_DEGREES );
//combine the matrix, order is important
matScale *= matRotation;
matScale *= matTranslation;
//tell the device to us this matrix
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
pd3dDevice->SetTexture( 0, g_pTexture[21] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
break;
//___________________________________________________________________________
case 50:
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, 1.0f, 1.0f, 1.0f );
D3DXMatrixRotationX( &matRotation, 0.0f/RADIAN_TO_DEGREES );
//combine the matrix, order is important
matScale *= matRotation;
matScale *= matTranslation;
//tell the device to us this matrix
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
pd3dDevice->SetTexture( 0, g_pTexture[20] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
break;
//___________________________________________________________________________
case 40:
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, 1.0f, 1.0f, 1.0f );
D3DXMatrixRotationX( &matRotation, 0.0f/RADIAN_TO_DEGREES );
//combine the matrix, order is important
matScale *= matRotation;
matScale *= matTranslation;
//tell the device to us this matrix
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
pd3dDevice->SetTexture( 0, g_pTexture[19] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
break;
//___________________________________________________________________________
case 30:
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, 1.0f, 1.0f, 1.0f );
D3DXMatrixRotationX( &matRotation, 0.0f/RADIAN_TO_DEGREES );
//combine the matrix, order is important
matScale *= matRotation;
matScale *= matTranslation;
//tell the device to us this matrix
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
pd3dDevice->SetTexture( 0, g_pTexture[18] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
break;
//___________________________________________________________________________
case 20:
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, 1.0f, 1.0f, 1.0f );
D3DXMatrixRotationX( &matRotation, 0.0f/RADIAN_TO_DEGREES );
//combine the matrix, order is important
matScale *= matRotation;
matScale *= matTranslation;
//tell the device to us this matrix
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
pd3dDevice->SetTexture( 0, g_pTexture[17] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
break;
//___________________________________________________________________________
case 10:
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, 1.0f, 1.0f, 1.0f );
D3DXMatrixRotationX( &matRotation, 0.0f/RADIAN_TO_DEGREES );
//combine the matrix, order is important
matScale *= matRotation;
matScale *= matTranslation;
//tell the device to us this matrix
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
pd3dDevice->SetTexture( 0, g_pTexture[16] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
break;
//___________________________________________________________________________
case 0:
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, 1.0f, 1.0f, 1.0f );
D3DXMatrixRotationX( &matRotation, 0.0f/RADIAN_TO_DEGREES );
//combine the matrix, order is important
matScale *= matRotation;
matScale *= matTranslation;
//tell the device to us this matrix
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
pd3dDevice->SetTexture( 0, g_pTexture[15] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
break;
//__________________________________________________________________________
default:
D3DXMatrixScaling( &matScale, 1.0f, 1.0f, 1.0f );
D3DXMatrixTranslation( &matTranslation, 1.0f, 1.0f, 1.0f );
D3DXMatrixRotationX( &matRotation, 0.0f/RADIAN_TO_DEGREES );
//combine the matrix, order is important
matScale *= matRotation;
matScale *= matTranslation;
//tell the device to us this matrix
pd3dDevice->SetTransform(D3DTS_WORLD, &matScale);
pd3dDevice->SetTexture( 0, g_pTexture[15] );
// Draw the primitive
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
break;
}
pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00808080 );
pd3dDevice->SetTexture( 0, NULL );
// Display the score
sprintf(szScore,"SCORE %ld , HighScore: %s (%ld)", PlayerInfo[g_iMyPlayerId].lScore, szHighestScoreWinner, g_lHighestScore);
pD3DXFont->DrawText(NULL, szScore, -1, &rTemp4, DT_LEFT, D3DCOLOR_RGBA(255, 255, 255, 255));
if( strlen(szSystemMessage) ) {
pD3DXFont->DrawText(NULL,szSystemMessage, -1, &rTemp1, DT_LEFT, D3DCOLOR_RGBA(255, 255, 255, 255));
}
// Stop Rendering
pd3dDevice->EndScene();
// Output the scene
if( (pd3dDevice->Present( NULL, NULL, NULL, NULL )) == D3DERR_DEVICELOST ) {
}
}

New Topic/Question
Reply



MultiQuote





|