home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2006 July & August
/
PCWorld_2006-07-08_cd.bin
/
temacd
/
planearcade
/
planearcade.exe
/
Tank3.bmp
/
light.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2004-10-08
|
4KB
|
178 lines
#include "main.h"
//---------------------------------------------------------------------
//Globalne PremennΘ
//---------------------------------------------------------------------
//Light Manager
LIGHTMANAGER LightManager;
//------------------------------------------------------------------
// Name: LIGHTMANAGER()
// Desc: Konstruktor
//------------------------------------------------------------------
LIGHTMANAGER::LIGHTMANAGER()
{
Light = NULL;
D3DLight = NULL;
NumLights = 0;
}
//------------------------------------------------------------------
// Name: LIGHTMANAGER()
// Desc: Destruktor
//------------------------------------------------------------------
LIGHTMANAGER::~LIGHTMANAGER()
{
//
if (Light !=NULL)
delete [] Light;
Light = NULL;
//
if (D3DLight !=NULL)
delete [] D3DLight;
D3DLight = NULL;
}
//------------------------------------------------------------------
// Name: Initialize()
// Desc: Maximalny pocet svetiel
//------------------------------------------------------------------
void LIGHTMANAGER::Initialize(int NLights)
{
//
Light = new LIGHT[NLights];
D3DLight = new D3DLIGHT9[NLights];
NumLights = 0;
}
//------------------------------------------------------------------
// Name: CleanUp()
// Desc: Zresetuj svetla
//------------------------------------------------------------------
void LIGHTMANAGER::CleanUp()
{
if (Light !=NULL)
delete [] Light;
Light = NULL;
NumLights = 0;
}
//------------------------------------------------------------------
// Name: AddLightPoint
// Desc: Pridaj bodove svetlo
//------------------------------------------------------------------
void LIGHTMANAGER::AddLightPoint(VECTOR3D Pos,COLOR Diffuse,
COLOR Ambient,
COLOR Specular,
float Atten,float Range)
{
Light[NumLights].Pos = Pos;
Light[NumLights].Type = D3DLIGHT_POINT;
Light[NumLights].Ambient = Ambient;
Light[NumLights].Diffuse = Diffuse;
Light[NumLights].Specular = Specular;
Light[NumLights].Atten0 = Atten;
Light[NumLights].Range = Range;
Light[NumLights].Active = true;
NumLights++;
}
//------------------------------------------------------------------
// Name: AddLightDir
// Desc: pridaj smerove svetlo (slnko)
//------------------------------------------------------------------
void LIGHTMANAGER::AddLightDir(VECTOR3D Dir,COLOR Diffuse,
COLOR Ambient,
COLOR Specular)
{
Light[NumLights].Dir = Dir;
Light[NumLights].Type = D3DLIGHT_DIRECTIONAL;
Light[NumLights].Range = 5.0f;
Light[NumLights].Ambient = Ambient;
Light[NumLights].Diffuse = Diffuse;
Light[NumLights].Specular = Specular;
Light[NumLights].Active = true;
NumLights++;
}
//------------------------------------------------------------------
// Name: RefreshLights()
// Desc: obnovi svetla
//------------------------------------------------------------------
void LIGHTMANAGER::RefreshLights()
{
for (int i=0;i<NumLights;i++)
{
if (Light[i].Active == true)
{
ZeroMemory( &D3DLight[i], sizeof(D3DLIGHT9) );
//ambient
D3DLight[i].Ambient.a = Light[i].Ambient.A;
D3DLight[i].Ambient.r = Light[i].Ambient.R;
D3DLight[i].Ambient.g = Light[i].Ambient.G;
D3DLight[i].Ambient.b = Light[i].Ambient.B;
//Diffuse
D3DLight[i].Diffuse.a = Light[i].Diffuse.A;
D3DLight[i].Diffuse.r = Light[i].Diffuse.R;
D3DLight[i].Diffuse.g = Light[i].Diffuse.G;
D3DLight[i].Diffuse.b = Light[i].Diffuse.B;
//Specular
D3DLight[i].Specular.a = Light[i].Specular.A;
D3DLight[i].Specular.r = Light[i].Specular.R;
D3DLight[i].Specular.g = Light[i].Specular.G;
D3DLight[i].Specular.b = Light[i].Specular.B;
//vlastnosti
D3DLight[i].Direction.x = Light[i].Dir.X ;
D3DLight[i].Direction.y = Light[i].Dir.Y ;
D3DLight[i].Direction.z = Light[i].Dir.Z ;
D3DLight[i].Attenuation0 = Light[i].Atten0 ;
D3DLight[i].Position.x = Light[i].Pos.X;
D3DLight[i].Position.y = Light[i].Pos.Y;
D3DLight[i].Position.z = Light[i].Pos.Z;
D3DLight[i].Type = Light[i].Type;
D3DLight[i].Range = Light[i].Range ;
g_pd3dDevice->SetLight( i, &D3DLight[i] );
g_pd3dDevice->LightEnable( i, TRUE );
}
}
}