42 if ((((max[0] > A[0]) && (A[0] >
min[0])) && ((max[0] >
B[0]) && (
B[0] >
min[0]))) &&
43 (((max[1] > A[1]) && (A[1] >
min[1])) && ((max[1] >
B[1]) && (
B[1] >
min[1]))))
53 real a1, a2, b1, b2, c1, c2;
60 c1 = p2[0] * p1[1] - p1[0] * p2[1];
63 r3 = a1 * p3[0] + b1 * p3[1] + c1;
64 r4 = a1 * p4[0] + b1 * p4[1] + c1;
68 if (r3 != 0 && r4 != 0 && r3 * r4 > 0.0) {
75 c2 = p4[0] * p3[1] - p3[0] * p4[1];
78 r1 = a2 * p1[0] + b2 * p1[1] + c2;
79 r2 = a2 * p2[0] + b2 * p2[1] + c2;
83 if (r1 != 0 && r2 != 0 && r1 * r2 > 0.0) {
88 denom = a1 * b2 - a2 * b1;
93 num = b1 * c2 - b2 * c1;
96 num = a2 * c1 - a1 * c2;
105 real a1, a2, b1, b2, c1, c2;
111 c1 = p2[0] * p1[1] - p1[0] * p2[1];
116 c2 = p4[0] * p3[1] - p3[0] * p4[1];
119 denom = a1 * b2 - a2 * b1;
124 num = b1 * c2 - b2 * c1;
125 res[0] = num / denom;
127 num = a2 * c1 - a1 * c2;
128 res[1] = num / denom;
141 real a1, a2, b1, b2, c1, c2;
148 c1 = p2[0] * p1[1] - p1[0] * p2[1];
151 r3 = a1 * p3[0] + b1 * p3[1] + c1;
152 r4 = a1 * p4[0] + b1 * p4[1] + c1;
156 if (r3 != 0 && r4 != 0 && r3 * r4 > 0.0) {
163 c2 = p4[0] * p3[1] - p3[0] * p4[1];
166 r1 = a2 * p1[0] + b2 * p1[1] + c2;
167 r2 = a2 * p2[0] + b2 * p2[1] + c2;
171 if (r1 != 0 && r2 != 0 && r1 * r2 > 0.0) {
176 denom = a1 * b2 - a2 * b1;
177 if (
fabs(denom) < epsilon) {
186 num = -b2 * d1 - a2 * e1;
189 num = -b1 * d1 - a1 * e1;
208#define FINDMINMAX(x0, x1, x2, min, max) \
227#define AXISTEST_X01(a, b, fa, fb) \
229 p0 = a * v0[Y] - b * v0[Z]; \
230 p2 = a * v2[Y] - b * v2[Z]; \
239 rad = fa * boxhalfsize[Y] + fb * boxhalfsize[Z]; \
240 if (min > rad || max < -rad) { \
246#define AXISTEST_X2(a, b, fa, fb) \
248 p0 = a * v0[Y] - b * v0[Z]; \
249 p1 = a * v1[Y] - b * v1[Z]; \
258 rad = fa * boxhalfsize[Y] + fb * boxhalfsize[Z]; \
259 if (min > rad || max < -rad) { \
266#define AXISTEST_Y02(a, b, fa, fb) \
268 p0 = -a * v0[X] + b * v0[Z]; \
269 p2 = -a * v2[X] + b * v2[Z]; \
278 rad = fa * boxhalfsize[X] + fb * boxhalfsize[Z]; \
279 if (min > rad || max < -rad) { \
285#define AXISTEST_Y1(a, b, fa, fb) \
287 p0 = -a * v0[X] + b * v0[Z]; \
288 p1 = -a * v1[X] + b * v1[Z]; \
297 rad = fa * boxhalfsize[X] + fb * boxhalfsize[Z]; \
298 if (min > rad || max < -rad) { \
305#define AXISTEST_Z12(a, b, fa, fb) \
307 p1 = a * v1[X] - b * v1[Y]; \
308 p2 = a * v2[X] - b * v2[Y]; \
317 rad = fa * boxhalfsize[X] + fb * boxhalfsize[Y]; \
318 if (min > rad || max < -rad) { \
324#define AXISTEST_Z0(a, b, fa, fb) \
326 p0 = a * v0[X] - b * v0[Y]; \
327 p1 = a * v1[X] - b * v1[Y]; \
336 rad = fa * boxhalfsize[X] + fb * boxhalfsize[Y]; \
337 if (min > rad || max < -rad) { \
358 Vec3r v0, v1,
v2, normal, e0, e1, e2;
359 real min,
max, d, p0, p1, p2, rad, fex, fey, fez;
363 v0 = triverts[0] - boxcenter;
364 v1 = triverts[1] - boxcenter;
365 v2 = triverts[2] - boxcenter;
402 if (
min > boxhalfsize[
X] || max < -boxhalfsize[
X]) {
408 if (
min > boxhalfsize[
Y] || max < -boxhalfsize[
Y]) {
414 if (
min > boxhalfsize[Z] || max < -boxhalfsize[Z]) {
446 Vec3r edge1, edge2, tvec, pvec, qvec;
467 if (u < 0.0 || u > det) {
477 else if (det < -epsilon) {
480 if (u > 0.0 || u < det) {
486 if (
v > 0.0 || u +
v < det) {
496 t = (edge2 * qvec) * inv_det;
514 if (
fabs(denom) <= epsilon) {
515 if (
fabs((
norm * orig) + d) <= epsilon) {
522 t = -(d + (
norm * orig)) / denom;
541 float tymin, tymax, tzmin, tzmax;
542 Vec3r inv_direction(1.0 / dir[0], 1.0 / dir[1], 1.0 / dir[2]);
544 sign[0] = (inv_direction.
x() < 0);
545 sign[1] = (inv_direction.
y() < 0);
546 sign[2] = (inv_direction.
z() < 0);
552 tmin = (
bounds[sign[0]].x() - orig.
x()) * inv_direction.
x();
553 tmax = (
bounds[1 - sign[0]].x() - orig.
x()) * inv_direction.
x();
554 tymin = (
bounds[sign[1]].y() - orig.
y()) * inv_direction.
y();
555 tymax = (
bounds[1 - sign[1]].y() - orig.
y()) * inv_direction.
y();
556 if ((tmin > tymax) || (tymin > tmax)) {
565 tzmin = (
bounds[sign[2]].z() - orig.
z()) * inv_direction.
z();
566 tzmax = (
bounds[1 - sign[2]].z() - orig.
z()) * inv_direction.
z();
567 if ((tmin > tzmax) || (tzmin > tmax)) {
576 return ((tmin < t1) && (tmax > t0));
593 Vec3r J(AB ^ AP),
K(BC ^ BP),
L(CA ^ CP);
615 HVec3r hvert(vert), res_tmp;
617 for (
uint j = 0; j < 4; j++) {
619 for (
uint i = 0; i < 4; i++) {
620 res_tmp[i] += matrix(i, j) * scale;
624 res[0] = res_tmp.
x();
625 res[1] = res_tmp.
y();
626 res[2] = res_tmp.
z();
632 res.resize(vertices.size());
633 for (i = 0; i < vertices.size(); i++) {
641 for (
uint i = 0; i < 3; i++) {
643 for (
uint j = 0; j < 3; j++) {
644 res[i] += mat(i, j) *
v[j];
667 q[0] = viewport[0] + viewport[2] * (p[0] + 1.0) / 2.0;
670 q[1] = viewport[1] + viewport[3] * (p[1] + 1.0) / 2.0;
673 q[2] = (p[2] + 1.0) / 2.0;
678 const real model_view_matrix[4][4],
679 const real projection_matrix[4][4],
680 const int viewport[4])
694 q[0] = viewport[0] + viewport[2] * (q[0] + 1.0) / 2.0;
697 q[1] = viewport[1] + viewport[3] * (q[1] + 1.0) / 2.0;
703 q[0] = 2.0 * (q[0] - viewport[0]) / viewport[2] - 1.0;
704 q[1] = 2.0 * (q[1] - viewport[1]) / viewport[3] - 1.0;
709 if (projection_matrix[3][3] == 0.0) {
710 q[0] = (-p[0] * focal) / projection_matrix[0][0];
711 q[1] = (-p[1] * focal) / projection_matrix[1][1];
715 q[0] = p[0] / projection_matrix[0][0];
716 q[1] = p[1] / projection_matrix[1][1];
723 real translation[3] = {
724 model_view_matrix[0][3],
725 model_view_matrix[1][3],
726 model_view_matrix[2][3],
728 for (
ushort i = 0; i < 3; i++) {
730 for (
ushort j = 0; j < 3; j++) {
731 q[i] += model_view_matrix[j][i] * (p[j] - translation[j]);
747#define PERP(u, v) ((u)[0] * (v)[1] - (u)[1] * (v)[0])
751 if (seg[0] == seg[1]) {
758 Vec2r dseg = seg[1] - seg[0];
761 for (
uint i = 0; i < n; i++) {
762 e = poly[i + 1] - poly[i];
763 N =
PERP(
e, seg[0] - poly[i]);
800 for (
uint q =
X; q <=
Z; q++) {
801 if (normal[q] > 0.0f) {
802 vmin[q] = -maxbox[q];
807 vmax[q] = -maxbox[q];
810 if ((normal * vmin) + d > 0.0f) {
813 if ((normal * vmax) + d >= 0.0f) {
824 for (
uint i = 0; i < 4; i++) {
825 for (
uint j = 0; j < 4; j++) {
826 hq[i] += transform[i][j] * hp[j];
835 for (
uint k = 0; k < 3; k++) {
836 q[k] = hq[k] / hq[3];
#define AXISTEST_Y02(a, b, fa, fb)
#define FINDMINMAX(x0, x1, x2, min, max)
#define AXISTEST_Z12(a, b, fa, fb)
#define AXISTEST_Y1(a, b, fa, fb)
#define AXISTEST_X2(a, b, fa, fb)
#define AXISTEST_X01(a, b, fa, fb)
#define AXISTEST_Z0(a, b, fa, fb)
Various tools for geometry.
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Vec< T, N > & normalize()
ccl_device_inline float2 fabs(const float2 a)
bool overlapPlaneBox(const Vec3r &normal, const real d, const Vec3r &maxbox)
void fromRetinaToImage(const Vec3r &p, Vec3r &q, const int viewport[4])
void fromWorldToImage(const Vec3r &p, Vec3r &q, const real model_view_matrix[4][4], const real projection_matrix[4][4], const int viewport[4])
bool overlapTriangleBox(const Vec3r &boxcenter, const Vec3r &boxhalfsize, const Vec3r triverts[3])
void transformVertex(const Vec3r &vert, const Matrix44r &matrix, Vec3r &res)
void fromWorldToCamera(const Vec3r &p, Vec3r &q, const real model_view_matrix[4][4])
intersection_test intersect2dSeg2dSegParametric(const Vec2r &p1, const Vec2r &p2, const Vec2r &p3, const Vec2r &p4, real &t, real &u, real epsilon)
bool intersect2dSeg2dArea(const Vec2r &min, const Vec2r &max, const Vec2r &A, const Vec2r &B)
intersection_test intersect2dSeg2dSeg(const Vec2r &p1, const Vec2r &p2, const Vec2r &p3, const Vec2r &p4, Vec2r &res)
void fromCoordAToCoordB(const Vec3r &p, Vec3r &q, const real transform[4][4])
void fromCameraToWorld(const Vec3r &p, Vec3r &q, const real model_view_matrix[4][4])
bool intersectRayTriangle(const Vec3r &orig, const Vec3r &dir, const Vec3r &v0, const Vec3r &v1, const Vec3r &v2, real &t, real &u, real &v, const real epsilon)
bool includePointTriangle(const Vec3r &P, const Vec3r &A, const Vec3r &B, const Vec3r &C)
void fromCameraToRetina(const Vec3r &p, Vec3r &q, const real projection_matrix[4][4])
void transformVertices(const vector< Vec3r > &vertices, const Matrix44r &trans, vector< Vec3r > &res)
bool intersect2dSegPoly(Vec2r *seg, Vec2r *poly, uint n)
bool intersectRayBBox(const Vec3r &orig, const Vec3r &dir, const Vec3r &boxMin, const Vec3r &boxMax, real t0, real t1, real &tmin, real &tmax, real)
bool include2dSeg2dArea(const Vec2r &min, const Vec2r &max, const Vec2r &A, const Vec2r &B)
intersection_test intersectRayPlane(const Vec3r &orig, const Vec3r &dir, const Vec3r &norm, const real d, real &t, const real epsilon)
void fromRetinaToCamera(const Vec3r &p, Vec3r &q, real focal, const real projection_matrix[4][4])
void fromImageToRetina(const Vec3r &p, Vec3r &q, const int viewport[4])
intersection_test intersect2dLine2dLine(const Vec2r &p1, const Vec2r &p2, const Vec2r &p3, const Vec2r &p4, Vec2r &res)
Vec3r rotateVector(const Matrix44r &mat, const Vec3r &v)
VecMat::Vec3< real > Vec3r
static const real M_EPSILON