Archived

This topic is now archived and is closed to further replies.

Whats wrong with this point light, i can't move it!

This topic is 5240 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This code is for my point light basically. It was created from the sdk directional light tutorial, i just modified a few things to make it work for a point light. The problem is, I cant seem to be able to move the light around. I don''t see what the error is, so have a look thanks.
quote:
D3DXVECTOR3 vecDir; D3DLIGHT9 light; ZeroMemory( &light, sizeof(D3DLIGHT9) ); light.Type = D3DLIGHT_POINT ; light.Diffuse.r = 1.0f; light.Diffuse.g = 1; light.Diffuse.b = 1; vecDir = D3DXVECTOR3(5, 5,5); D3DXVec3Normalize( (D3DXVECTOR3*)&light.Position, &vecDir ); light.Range = 530.0f; myDevice->SetLight( 0, &light ); myDevice->LightEnable( 0, TRUE ); myDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); myDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_XRGB(50,50,50) );
by the way if anyone has any suggestions to modify this code for the better etc, let me know, thanks

Share this post


Link to post
Share on other sites
From the DirectX 9.0 SDK:
//-----------------------------------------------------------------------------

// Name: FrameMove()

// Desc: Called once per frame, the call is the entry point for animating

// the scene.

//-----------------------------------------------------------------------------

HRESULT CMyD3DApplication::FrameMove()
{
ZeroMemory( &m_light, sizeof(m_light) );

// Rotate through the various light types

m_light.Type = (D3DLIGHTTYPE)(1+(((DWORD)m_fTime)/5)%3);

// Make sure the light type is supported by the device. If

// D3DVTXPCAPS_POSITIONALLIGHTS is not set, the device does not support

// point or spot lights, so change light #2''s type to a directional light.

DWORD dwCaps = m_d3dCaps.VertexProcessingCaps;
if( 0 == ( dwCaps & D3DVTXPCAPS_POSITIONALLIGHTS ) )
{
if( m_light.Type == D3DLIGHT_POINT || m_light.Type == D3DLIGHT_SPOT )
m_light.Type = D3DLIGHT_DIRECTIONAL;
}

// Values for the light position, direction, and color

FLOAT x = sinf( m_fTime*2.000f );
FLOAT y = sinf( m_fTime*2.246f );
FLOAT z = sinf( m_fTime*2.640f );

m_light.Diffuse.r = 0.5f + 0.5f * x;
m_light.Diffuse.g = 0.5f + 0.5f * y;
m_light.Diffuse.b = 0.5f + 0.5f * z;
m_light.Range = 100.0f;

switch( m_light.Type )
{
case D3DLIGHT_POINT:
m_light.Position = 4.5f * D3DXVECTOR3( x, y, z );
m_light.Attenuation1 = 0.4f;
break;
case D3DLIGHT_DIRECTIONAL:
m_light.Direction = D3DXVECTOR3( x, y, z );
break;
case D3DLIGHT_SPOT:
m_light.Position = 2.0f * D3DXVECTOR3( x, y, z );
m_light.Direction = D3DXVECTOR3( x, y, z );
m_light.Theta = 0.5f;
m_light.Phi = 1.0f;
m_light.Falloff = 1.0f;
m_light.Attenuation0 = 1.0f;
}
m_pd3dDevice->SetLight( 2, &m_light );

return S_OK;
}


The light changes every n seconds.

.lick

Share this post


Link to post
Share on other sites
When you Normalize the position, you''re bringing the value down to between 0.0 and 1.0 - this doesn''t sound like what you want for position. Does your light move when you remove/comment the Normalize step?

Also, I''m not seeing the code to actually move the light, but I''m assuming the position is being normalized there as well?

Share this post


Link to post
Share on other sites