Light.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "Light.h"
  2. #include "collision.h"
  3. #include "Renderer.h"
  4. #include "LightProps.h"
  5. //=====================================================================================================================================
  6. // init [PointLight] =
  7. //=====================================================================================================================================
  8. void PointLight::init( const char* filename )
  9. {
  10. lightProps = Rsrc::lightProps.load( filename );
  11. radius = lightProps->getRadius();
  12. }
  13. //=====================================================================================================================================
  14. // init [SpotLight] =
  15. //=====================================================================================================================================
  16. void SpotLight::init( const char* filename )
  17. {
  18. lightProps = Rsrc::lightProps.load( filename );
  19. camera.setAll( lightProps->getFovX(), lightProps->getFovY(), 0.2, lightProps->getDistance() );
  20. castsShadow = lightProps->castsShadow();
  21. if( lightProps->getTexture() == NULL )
  22. {
  23. ERROR( "Light properties \"" << lightProps->getRsrcName() << "\" do not have a texture" );
  24. return;
  25. }
  26. }
  27. //=====================================================================================================================================
  28. // deinit =
  29. //=====================================================================================================================================
  30. void Light::deinit()
  31. {
  32. Rsrc::lightProps.unload( lightProps );
  33. }
  34. //=====================================================================================================================================
  35. // renderSphere =
  36. //=====================================================================================================================================
  37. static void RenderSphere( const Mat4& tsl, const Vec3& col )
  38. {
  39. glPushMatrix();
  40. R::multMatrix( tsl );
  41. R::color3( col );
  42. R::Dbg::renderSphere( 1.0/8.0, 8 );
  43. glPopMatrix();
  44. }
  45. //=====================================================================================================================================
  46. // render =
  47. //=====================================================================================================================================
  48. void PointLight::render()
  49. {
  50. RenderSphere( transformationWspace, lightProps->getDiffuseColor() );
  51. }
  52. //=====================================================================================================================================
  53. // render =
  54. //=====================================================================================================================================
  55. void SpotLight::render()
  56. {
  57. RenderSphere( transformationWspace, lightProps->getDiffuseColor() );
  58. }