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

Started by
5 comments, last by johnnyBravo 20 years, 8 months ago
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
Advertisement
You do not need a direction with pointlights, you need a position.

[edit] Check out the Lighting example in the SDK.


.lick


[edited by - Pipo DeClown on August 7, 2003 7:11:38 AM]

[edited by - Pipo DeClown on August 7, 2003 7:12:32 AM]
the example is for directional lights...thats where i got the original code from.

D3DXVec3Normalize( (D3DXVECTOR3*)&light.Position, &vecDir );

ive changed the direction to Position

so its not using direction
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
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?
thanks that helped me get it working
1) Ah.. I feel so dumb.
2) The SDK does help alot if you know how to use it.
3) Goodluck..
4) Erorr!
5) BSOD - Access violation 0xe01948e021930... (bullshit)

.lick

This topic is closed to new replies.

Advertisement