SceneDbgDrawer.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "SceneDbgDrawer.h"
  2. #include "Dbg.h"
  3. #include "Camera.h"
  4. #include "Light.h"
  5. #include "ParticleEmitter.h"
  6. #include "SkinNode.h"
  7. //======================================================================================================================
  8. // drawCamera =
  9. //======================================================================================================================
  10. void SceneDbgDrawer::drawCamera(const Camera& cam) const
  11. {
  12. dbg.setColor(Vec4(1.0, 0.0, 1.0, 1.0));
  13. dbg.setModelMat(Mat4(cam.getWorldTransform()));
  14. const float camLen = 1.0;
  15. float tmp0 = camLen / tan((M::PI - cam.getFovX()) * 0.5) + 0.001;
  16. float tmp1 = camLen * tan(cam.getFovY() * 0.5) + 0.001;
  17. Vec3 points[] = {
  18. Vec3(0.0, 0.0, 0.0), // 0: eye point
  19. Vec3(-tmp0, tmp1, -camLen), // 1: top left
  20. Vec3(-tmp0, -tmp1, -camLen), // 2: bottom left
  21. Vec3(tmp0, -tmp1, -camLen), // 3: bottom right
  22. Vec3(tmp0, tmp1, -camLen) // 4: top right
  23. };
  24. const uint indeces[] = {0, 1, 0, 2, 0, 3, 0, 4, 1, 2, 2, 3, 3, 4, 4, 1};
  25. dbg.begin();
  26. for(uint i = 0; i < sizeof(indeces) / sizeof(uint); i++)
  27. {
  28. dbg.pushBackVertex(points[indeces[i]]);
  29. }
  30. dbg.end();
  31. }
  32. //======================================================================================================================
  33. // drawLight =
  34. //======================================================================================================================
  35. void SceneDbgDrawer::drawLight(const Light& light) const
  36. {
  37. dbg.setColor(light.getDiffuseCol());
  38. dbg.setModelMat(Mat4(light.getWorldTransform()));
  39. dbg.drawSphere(0.1);
  40. }
  41. //======================================================================================================================
  42. // drawParticleEmitter =
  43. //======================================================================================================================
  44. void SceneDbgDrawer::drawParticleEmitter(const ParticleEmitter& pe) const
  45. {
  46. dbg.setColor(Vec4(1.0));
  47. dbg.setModelMat(Mat4(pe.getWorldTransform()));
  48. dbg.drawCube();
  49. }
  50. //======================================================================================================================
  51. // drawSkinNodeSkeleton =
  52. //======================================================================================================================
  53. void SceneDbgDrawer::drawSkinNodeSkeleton(const SkinNode& sn) const
  54. {
  55. dbg.setModelMat(Mat4(sn.getWorldTransform()));
  56. dbg.begin();
  57. for(uint i = 0; i < sn.getHeads().size(); i++)
  58. {
  59. dbg.setColor(Vec4(1.0, 0.0, 0.0, 1.0));
  60. dbg.pushBackVertex(sn.getHeads()[i]);
  61. dbg.setColor(Vec4(1.0));
  62. dbg.pushBackVertex(sn.getTails()[i]);
  63. }
  64. dbg.end();
  65. }