123456789101112131415161718192021222324 |
- #include "core/Plane.h"
- #include <stdio.h>
- #define CV30 (&CORE_VECTOR3)
- CorePlane* coreInitPlane(CorePlane* p, const CoreVector3* a,
- const CoreVector3* b, const CoreVector3* c) {
- coreCross(&p->abc, coreSubV3(CV30, b, a), coreSubV3(CV30, c, a));
- coreNormalizeV3(&p->abc);
- p->d = -coreDotV3(&p->abc, b);
- return p;
- }
- float coreSignedDistance(const CorePlane* p, const CoreVector3* v) {
- return coreDotV3(&p->abc, v) + p->d;
- }
- size_t coreToStringPlane(const CorePlane* p, char* buffer, size_t n) {
- int w = snprintf(buffer, n, "(%.3f x + %.3f y + %.3f z + %.3f)",
- (double)p->abc.data[0], (double)p->abc.data[1],
- (double)p->abc.data[2], (double)p->d);
- return w < 0 ? 0 : (size_t)w;
- }
|