DirectX lighting question

Miscellaneous Forums/General Discussion/DirectX lighting question

Hi, for those who remember, I AM working on that engine i was talking about, and I'm having some trouble in the LIGHT class. I have directional lights working fine and dandy, but spotlights and point lights won't work. By changing the line:

g_light.Type = D3DLIGHT_DIRECTIONAL;


to either

g_light.Type = D3DLIGHT_POINT;


or

g_light.Type = D3DLIGHT_SPOT;


it won't light the scene (i get pitch black). It would make more sense for the spotlight simply because it is directionally based and the rotation of a directional light could give differing results for a spotlight. But point lights are independent of rotation, so I'm stumped. Also, how do I change light properties in runtime after it has been registerred and activated using:

 g_D3DDevice->SetLight(0, &g_light);
 g_D3DDevice->LightEnable(0, TRUE);


If it helps, I found that when creating a series of lights, if either a spotlight or point light is included as a light, i get no lighting, which inclines me to believe that the light initialization is failing, so some DirectX function is returning false without me realizing.


Any help is appreciated!!

figured it out, turns out that theta, phi, attenuation, etc. all default to 0, and I wasn't defining those.

don't you love it when you answer your own questions

well, i'd been stumped by this for the past 8 hours, so I posted it here, and minutes later I found the solution. Though i still can't figure out how to change the properties after initialization...

I hate when that happends. You think you have looked everywhere and tried everything, and the second after you hit submit you find the solution. :P

nevermind, this question is still open, i broke it again and it turns out the way i had it working was structurally unstable and messed up.

class entity
{
public:
	entity(){}
	virtual ~entity(){}
	virtual void PositionEntity() = 0;
	virtual void RotateEntity() = 0;
	virtual void MoveEntity() = 0;
	virtual void TranslateEntity() = 0;
	virtual void TurnEntity() = 0;
protected:
	float itsX;
	float itsY;
	float itsZ;
	float itsPitch;
	float itsYaw;
	float itsRoll;
};

class LIGHT : public entity
{
public:

	LIGHT(int type):
		itsType(type)
		{	
			D3DLIGHT9 e_light;
			//Set parameters based on the kind of light
			switch (type)
			{
			case 1:
				e_light.Type = D3DLIGHT_POINT;
				e_light.Attenuation0 = 0;
				e_light.Attenuation1 = 0.5f;
				e_light.Attenuation2 = 0;
				e_light.Range = 1000;
			case 2:
				e_light.Type = D3DLIGHT_SPOT;
			case 3:
				e_light.Type = D3DLIGHT_DIRECTIONAL;
				e_light.Direction = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
			default:
				e_light.Type = D3DLIGHT_POINT;
				e_light.Attenuation0 = 0;
				e_light.Attenuation1 = 0.5f;
				e_light.Attenuation2 = 0;
				e_light.Range = 10;
			}
			e_light.Diffuse.r = e_light.Diffuse.g = 1;
			e_light.Diffuse.b = e_light.Diffuse.a = 1;
			e_light.Specular.r = e_light.Specular.g = 1;
			e_light.Specular.b = e_light.Specular.a = 1;
			e_light.Ambient.r = e_light.Ambient.g = 1;
			e_light.Ambient.b = e_light.Ambient.a = 1;
			itsIndex = _lIndex_;

			//Register the light
			g_D3DDevice->SetLight(0, &e_light);
			g_D3DDevice->LightEnable(0, TRUE);

			//increment the next light index number
			_lIndex_++;
		}
	~LIGHT(){}
	//light property functions commands
	void SetAmbient(float r, float g, float b, float a)
	{
		ambientR = r;
		ambientG = g;
		ambientB = b;
		ambientA = a;
		UpdateLightProperties();
	}
	void SetDiffuse(float r, float g, float b, float a)
	{
		diffuseR = r;
		diffuseG = g;
		diffuseB = b;
		diffuseA = a;
		UpdateLightProperties();
	}
	void SetSpecular(float r, float g, float b, float a)
	{
		specularR = r;
		specularG = g;
		specularB = b;
		specularA = a;
		UpdateLightProperties();
	}
	void SetRange(float r) 
	{
		range = r;
		UpdateLightProperties();
	}
	void SetFallof(float f) 
	{
		falloff = f;
		UpdateLightProperties();
	}
	void SetAttenuation(float a0, float a1, float a2)
	{
		attenuation0 = a0;
		attenuation1 = a1;
		attenuation2 = a2;
		UpdateLightProperties();
	}
	void SetCone(float th, float ph)
	{
		theta = th;
		phi = ph;
		UpdateLightProperties();
	}

	//translation functions
	void PositionEntity()
	{
	}
	void RotateEntity()
	{
	}
	void MoveEntity()
	{
	}
	void TranslateEntity()
	{
	}
	void TurnEntity()
	{
	}

private:
	void UpdateLightProperties()
	{
		e_light.Ambient.a = ambientA;
		e_light.Ambient.r = ambientR;
		e_light.Ambient.g = ambientG;
		e_light.Ambient.b = ambientB;
		e_light.Diffuse.a = diffuseA;
		e_light.Diffuse.r = diffuseR;
		e_light.Diffuse.g = diffuseG;
		e_light.Diffuse.b = diffuseB;
		e_light.Specular.a = specularA;
		e_light.Specular.r = specularR;
		e_light.Specular.g = specularG;
		e_light.Specular.b = specularB;
		e_light.Range = range;
		e_light.Falloff = falloff;
		e_light.Attenuation0 = attenuation0;
		e_light.Attenuation1 = attenuation1;
		e_light.Attenuation2 = attenuation2;
		e_light.Theta = theta;
		e_light.Phi = phi;
	}

	int itsType;
	float ambientR, ambientG, ambientB, ambientA;
	float diffuseR, diffuseG, diffuseB, diffuseA;
	float specularR, specularG, specularB, specularA;
	float range;
	float falloff;
	float attenuation0, attenuation1, attenuation2;
	float theta, phi;

	int itsIndex;
};


I need to have this work!