Simple game engine with complete export to scripting language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
784 B

14 years ago
  1. #ifndef BLUECORE_PLANE_H
  2. #define BLUECORE_PLANE_H
  3. #include "Scalar.h"
  4. #include "Vector.h"
  5. namespace BlueCore
  6. {
  7. template <class T>
  8. class PlaneTemplate
  9. {
  10. public:
  11. Vector3Template<T> _n;
  12. T _d;
  13. /**
  14. * contructor
  15. */
  16. inline PlaneTemplate() : _d( 0. )
  17. {
  18. }
  19. /**
  20. * contructor
  21. */
  22. inline PlaneTemplate(
  23. Vector3Template<T> a,
  24. Vector3Template<T> b,
  25. Vector3Template<T> c )
  26. {
  27. _n = (a - b).cross(a - c).normalized();
  28. _d = _n.dot( a );
  29. }
  30. /**
  31. * distance
  32. */
  33. inline T distance( const Vector3Template<T> a )
  34. {
  35. return _n.dot( a ) - _d;
  36. }
  37. };
  38. typedef PlaneTemplate<float> PlaneFloat;
  39. typedef PlaneTemplate<double> PlaneDouble;
  40. typedef PlaneTemplate<Scalar> Plane;
  41. }
  42. #endif