⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clight.cpp

📁 俄罗斯方块3D 程序+源码俄罗斯方块3D(程序+源码
💻 CPP
字号:
#include "CLight.h"
#include "3dhelp.h"

CLight::CLight()
{
	SetLightType( D3DLIGHT_DIRECTIONAL );
	SetDiffuse( 1.0f, 1.0f, 1.0f, 1.0f );
	SetDirection( 1.0f, 1.0f, 1.0f );

	SetAmbientColor( 128, 128, 128 );
	m_IsLightEnable = true;
}

CLight::~CLight()
{

}

void CLight::OpenLight( IDirect3DDevice9 *pD )
{
	m_IsLightEnable = true;
	//pD->SetRenderState( D3DRS_LIGHTING, TRUE );
}

void CLight::CloseLight( IDirect3DDevice9 *pD )
{
	m_IsLightEnable = false;
	//pD->SetRenderState( D3DRS_LIGHTING, FALSE );
}

void CLight::SetAmbientColor( DWORD r, DWORD g, DWORD b )
{
	AmbientColor = D3DCOLOR_XRGB( r, g, b );
}

void CLight::SetLightType( D3DLIGHTTYPE t )
{
	m_light.Type = t;
}

void CLight::SetDiffuse( float r, float g, float b, float a )
{
	SetColorValue( m_light.Diffuse, r, g, b, a );
}

void CLight::SetAmbient(float r, float g, float b, float a )
{
	SetColorValue( m_light.Ambient, r, g, b, a );
}

void CLight::SetSpecular(float r, float g, float b, float a )
{
	SetColorValue( m_light.Specular, r, g, b ,a );
}


void CLight::SetPosition( float x, float y, float z ) 
{
	SetVector( m_light.Position, x, y, z );
	D3DXVECTOR3 pos;
	pos.x = 0.0f;
	pos.y = 0.0f;
	pos.z = 0.0f;
	m_light.Direction.x = pos.x - m_light.Position.x;
	m_light.Direction.y = pos.y - m_light.Position.y;
	m_light.Direction.z = pos.z - m_light.Position.z;
}

void CLight::SetDirection( float x, float y, float z )
{
	SetVector( m_light.Direction, x, y, z );

}

void CLight::SetRange( float f )
{
	m_light.Range = f;
}

void CLight::SetFalloff( float f )
{
	m_light.Falloff = f;
}

void CLight::SetTheta( float f )
{
	m_light.Theta = f;
}

void CLight::SetPhi( float f )
{
	m_light.Phi = f;
}

void CLight::SetAttenuation( float f0, float f1, float f2 )
{
	m_light.Attenuation0 = f0;
	m_light.Attenuation1 = f1;
	m_light.Attenuation2 = f2;
}

void CLight::SetLight( IDirect3DDevice9 *pD )
{
	if ( m_IsLightEnable )
	{
		pD->SetRenderState( D3DRS_AMBIENT, AmbientColor );
		pD->SetLight( 0, &m_light );
		pD->LightEnable( 0, TRUE );
		pD->SetRenderState( D3DRS_LIGHTING, TRUE );	
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -