Plane.c 777 B

123456789101112131415161718192021222324
  1. #include "core/Plane.h"
  2. #include <stdio.h>
  3. #define CV30 (&CORE_VECTOR3)
  4. CorePlane* coreInitPlane(CorePlane* p, const CoreVector3* a,
  5. const CoreVector3* b, const CoreVector3* c) {
  6. coreCross(&p->abc, coreSubV3(CV30, b, a), coreSubV3(CV30, c, a));
  7. coreNormalizeV3(&p->abc);
  8. p->d = -coreDotV3(&p->abc, b);
  9. return p;
  10. }
  11. float coreSignedDistance(const CorePlane* p, const CoreVector3* v) {
  12. return coreDotV3(&p->abc, v) + p->d;
  13. }
  14. size_t coreToStringPlane(const CorePlane* p, char* buffer, size_t n) {
  15. int w = snprintf(buffer, n, "(%.3f x + %.3f y + %.3f z + %.3f)",
  16. (double)p->abc.data[0], (double)p->abc.data[1],
  17. (double)p->abc.data[2], (double)p->d);
  18. return w < 0 ? 0 : (size_t)w;
  19. }