000
21.05.2011, 18:52 Uhr
~MPi
Gast
|
Hallo!
ich beschäftige mich nun seit 3 Tagen mit Direct3D und haben ein Problem mit der Position der D3D Lichtquellen. Die Lichtquelle (hier Nr.1 *) beleuchtet nicht den Bereich um Ihre Position in der Welt, sondern scheint sich irgendwie mit der Camera zu bewegen.
Kann mir jemand sagen, ob ich hier irgendetwas falsch mache? (Den relevanten Quellcodebereich habe ich unten angehängt und ein wenig mit Kommentaren versehen)
Danke!
//Set projection Values D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian(60.0f ), (float)Screen_sx/(float)Screen_sy, 5.0f, 4000.0f ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
//D3D Licht an g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
//Worldmatrix D3DXMatrixLookAtLH(&matWorld,&D3DXVECTOR3 (Scene.x , Scene.y , Scene.z ), // camera position &D3DXVECTOR3 (Scene.dx, Scene.dy, Scene.dz), // the look-at position &D3DXVECTOR3 (0.0f, 1.0f, 0.0f)); // the up direction g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
//Lights 0- directional, 1- point light g_pd3dDevice->SetLight( 0, &g_light[0] ); g_pd3dDevice->SetLight( 1, &g_light[1] ); //*
g_pd3dDevice->LightEnable( 0, TRUE ); g_pd3dDevice->LightEnable( 1, TRUE );
//d3d Light active g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE); g_pd3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE);
//Zbuffer active g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); //Cullmode CounterClockWise g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW );
for (i=0; i<NUM_SCENE_OBJECTS; i++) { if (Scene.object_active[i]) { //Translation of Object in Scene D3DXMatrixTranslation ( &matObjectTrans,Scene.object_x [i],Scene.object_y [i],-Scene.object_z [i]); //Rotation of Object in Scene D3DXMatrixRotationYawPitchRoll( &matObjectRot ,Scene.object_rx[i],Scene.object_ry[i], Scene.object_rz[i]); //Scaling of Object in Scene D3DXMatrixScaling ( &matObjectScale,Scene.object_sx[i],Scene.object_sy[i], Scene.object_sz[i]);
matObject = matObjectScale * matObjectRot * matObjectTrans * matWorld; //SetTransform to Object in World g_pd3dDevice->SetTransform(D3DTS_WORLD, &matObject );
//Render Object g_pd3dDevice->SetStreamSource( 0, g_pVertexBuffer[Scene.object_nr[i]], 0, sizeof(Vertex) ); g_pd3dDevice->SetFVF( Vertex::FVF_Flags );
g_pd3dDevice->SetMaterial( &g_Material[Object[Scene.object_nr[i]].material]); g_pd3dDevice->SetTexture (0,g_pTexture[Object[Scene.object_nr[i]].texture]);
for (j=0; j<Object[Scene.object_nr[i]].stripes; j++) { g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, Object[Scene.object_nr[i]].stripes_s[j], Object[Scene.object_nr[i]].stripes_n[j]); } } } |