gxlight.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "std.h"
  2. #include "gxlight.h"
  3. #include "gxscene.h"
  4. #include "gxgraphics.h"
  5. const float PI=3.14159265359f; //180 degrees
  6. const float TWOPI=PI*2.0f; //360 degrees
  7. const float HALFPI=PI*.5f; //90 degrees
  8. const float EPSILON=.000001f;
  9. gxLight::gxLight( gxScene *s,int type ):
  10. scene(s){
  11. memset(&d3d_light,0,sizeof(d3d_light));
  12. switch( type ){
  13. case LIGHT_POINT:
  14. d3d_light.dltType=D3DLIGHT_POINT;
  15. break;
  16. case LIGHT_SPOT:
  17. d3d_light.dltType=D3DLIGHT_SPOT;
  18. break;
  19. default:
  20. d3d_light.dltType=D3DLIGHT_DIRECTIONAL;
  21. }
  22. d3d_light.dcvDiffuse.a=1;
  23. d3d_light.dcvDiffuse.r=d3d_light.dcvDiffuse.g=d3d_light.dcvDiffuse.b=1;
  24. d3d_light.dcvSpecular.r=d3d_light.dcvSpecular.g=d3d_light.dcvSpecular.b=1;
  25. d3d_light.dvRange=D3DLIGHT_RANGE_MAX;
  26. d3d_light.dvTheta=0;
  27. d3d_light.dvPhi=HALFPI;
  28. d3d_light.dvFalloff=1;
  29. d3d_light.dvDirection.z=1;
  30. setRange( 1000 );
  31. }
  32. gxLight::~gxLight(){
  33. }
  34. void gxLight::setRange( float r ){
  35. d3d_light.dvAttenuation1=1.0f/r;
  36. }
  37. void gxLight::setPosition( const float pos[3] ){
  38. d3d_light.dvPosition.x=pos[0];
  39. d3d_light.dvPosition.y=pos[1];
  40. d3d_light.dvPosition.z=pos[2];
  41. }
  42. void gxLight::setDirection( const float dir[3] ){
  43. d3d_light.dvDirection.x=dir[0];
  44. d3d_light.dvDirection.y=dir[1];
  45. d3d_light.dvDirection.z=dir[2];
  46. }
  47. void gxLight::setConeAngles( float inner,float outer ){
  48. d3d_light.dvTheta=inner;
  49. d3d_light.dvPhi=outer;
  50. }