38 if ((((
max[0] >
A[0]) && (
A[0] >
min[0])) && ((
max[0] >
B[0]) && (
B[0] >
min[0]))) &&
39 (((
max[1] >
A[1]) && (
A[1] >
min[1])) && ((
max[1] >
B[1]) && (
B[1] >
min[1])))) {
48 real a1, a2, b1, b2, c1, c2;
55 c1 = p2[0] * p1[1] - p1[0] * p2[1];
58 r3 = a1 * p3[0] + b1 * p3[1] + c1;
59 r4 = a1 * p4[0] + b1 * p4[1] + c1;
63 if (r3 != 0 && r4 != 0 && r3 * r4 > 0.0) {
70 c2 = p4[0] * p3[1] - p3[0] * p4[1];
73 r1 = a2 * p1[0] + b2 * p1[1] + c2;
74 r2 = a2 * p2[0] + b2 * p2[1] + c2;
78 if (r1 != 0 && r2 != 0 && r1 * r2 > 0.0) {
83 denom = a1 * b2 - a2 * b1;
88 num = b1 * c2 - b2 * c1;
91 num = a2 * c1 - a1 * c2;
100 real a1, a2, b1, b2, c1, c2;
106 c1 = p2[0] * p1[1] - p1[0] * p2[1];
111 c2 = p4[0] * p3[1] - p3[0] * p4[1];
114 denom = a1 * b2 - a2 * b1;
119 num = b1 * c2 - b2 * c1;
120 res[0] = num / denom;
122 num = a2 * c1 - a1 * c2;
123 res[1] = num / denom;
136 real a1, a2, b1, b2, c1, c2;
143 c1 = p2[0] * p1[1] - p1[0] * p2[1];
146 r3 = a1 * p3[0] + b1 * p3[1] + c1;
147 r4 = a1 * p4[0] + b1 * p4[1] + c1;
151 if (r3 != 0 && r4 != 0 && r3 * r4 > 0.0) {
158 c2 = p4[0] * p3[1] - p3[0] * p4[1];
161 r1 = a2 * p1[0] + b2 * p1[1] + c2;
162 r2 = a2 * p2[0] + b2 * p2[1] + c2;
166 if (r1 != 0 && r2 != 0 && r1 * r2 > 0.0) {
171 denom = a1 * b2 - a2 * b1;
181 num = -b2 * d1 - a2 * e1;
184 num = -b1 * d1 - a1 * e1;
203 #define FINDMINMAX(x0, x1, x2, min, max) \
222 #define AXISTEST_X01(a, b, fa, fb) \
224 p0 = a * v0[Y] - b * v0[Z]; \
225 p2 = a * v2[Y] - b * v2[Z]; \
234 rad = fa * boxhalfsize[Y] + fb * boxhalfsize[Z]; \
235 if (min > rad || max < -rad) { \
241 #define AXISTEST_X2(a, b, fa, fb) \
243 p0 = a * v0[Y] - b * v0[Z]; \
244 p1 = a * v1[Y] - b * v1[Z]; \
253 rad = fa * boxhalfsize[Y] + fb * boxhalfsize[Z]; \
254 if (min > rad || max < -rad) { \
261 #define AXISTEST_Y02(a, b, fa, fb) \
263 p0 = -a * v0[X] + b * v0[Z]; \
264 p2 = -a * v2[X] + b * v2[Z]; \
273 rad = fa * boxhalfsize[X] + fb * boxhalfsize[Z]; \
274 if (min > rad || max < -rad) { \
280 #define AXISTEST_Y1(a, b, fa, fb) \
282 p0 = -a * v0[X] + b * v0[Z]; \
283 p1 = -a * v1[X] + b * v1[Z]; \
292 rad = fa * boxhalfsize[X] + fb * boxhalfsize[Z]; \
293 if (min > rad || max < -rad) { \
300 #define AXISTEST_Z12(a, b, fa, fb) \
302 p1 = a * v1[X] - b * v1[Y]; \
303 p2 = a * v2[X] - b * v2[Y]; \
312 rad = fa * boxhalfsize[X] + fb * boxhalfsize[Y]; \
313 if (min > rad || max < -rad) { \
319 #define AXISTEST_Z0(a, b, fa, fb) \
321 p0 = a * v0[X] - b * v0[Y]; \
322 p1 = a * v1[X] - b * v1[Y]; \
331 rad = fa * boxhalfsize[X] + fb * boxhalfsize[Y]; \
332 if (min > rad || max < -rad) { \
348 real min,
max, d, p0, p1, p2, rad, fex, fey, fez;
352 v0 = triverts[0] - boxcenter;
353 v1 = triverts[1] - boxcenter;
354 v2 = triverts[2] - boxcenter;
391 if (
min > boxhalfsize[
X] ||
max < -boxhalfsize[
X]) {
397 if (
min > boxhalfsize[
Y] ||
max < -boxhalfsize[
Y]) {
403 if (
min > boxhalfsize[
Z] ||
max < -boxhalfsize[
Z]) {
440 Vec3r edge1, edge2, tvec, pvec, qvec;
461 if (u < 0.0 || u > det) {
467 if (v < 0.0 || u + v > det) {
474 if (u > 0.0 || u < det) {
480 if (
v > 0.0 || u +
v < det) {
490 t = (edge2 * qvec) * inv_det;
515 t = -(d + (
norm * orig)) / denom;
534 float tymin, tymax, tzmin, tzmax;
535 Vec3r inv_direction(1.0 / dir[0], 1.0 / dir[1], 1.0 / dir[2]);
537 sign[0] = (inv_direction.
x() < 0);
538 sign[1] = (inv_direction.
y() < 0);
539 sign[2] = (inv_direction.
z() < 0);
545 tmin = (
bounds[
sign[0]].x() - orig.
x()) * inv_direction.
x();
546 tmax = (
bounds[1 -
sign[0]].x() - orig.
x()) * inv_direction.
x();
547 tymin = (
bounds[
sign[1]].y() - orig.
y()) * inv_direction.
y();
548 tymax = (
bounds[1 -
sign[1]].y() - orig.
y()) * inv_direction.
y();
549 if ((tmin > tymax) || (tymin > tmax)) {
558 tzmin = (
bounds[
sign[2]].z() - orig.
z()) * inv_direction.
z();
559 tzmax = (
bounds[1 -
sign[2]].z() - orig.
z()) * inv_direction.
z();
560 if ((tmin > tzmax) || (tzmin > tmax)) {
569 return ((tmin < t1) && (tmax > t0));
586 Vec3r J(AB ^ AP),
K(BC ^ BP),
L(CA ^ CP);
608 HVec3r hvert(vert), res_tmp;
610 for (
unsigned int j = 0; j < 4; j++) {
612 for (
unsigned int i = 0; i < 4; i++) {
613 res_tmp[i] += matrix(i, j) * scale;
617 res[0] = res_tmp.
x();
618 res[1] = res_tmp.
y();
619 res[2] = res_tmp.
z();
625 res.resize(vertices.size());
626 for (i = 0; i < vertices.size(); i++) {
634 for (
unsigned int i = 0; i < 3; i++) {
636 for (
unsigned int j = 0; j < 3; j++) {
637 res[i] += mat(i, j) *
v[j];
660 q[0] = viewport[0] + viewport[2] * (p[0] + 1.0) / 2.0;
663 q[1] = viewport[1] + viewport[3] * (p[1] + 1.0) / 2.0;
666 q[2] = (p[2] + 1.0) / 2.0;
671 const real model_view_matrix[4][4],
672 const real projection_matrix[4][4],
673 const int viewport[4])
687 q[0] = viewport[0] + viewport[2] * (q[0] + 1.0) / 2.0;
690 q[1] = viewport[1] + viewport[3] * (q[1] + 1.0) / 2.0;
696 q[0] = 2.0 * (q[0] - viewport[0]) / viewport[2] - 1.0;
697 q[1] = 2.0 * (q[1] - viewport[1]) / viewport[3] - 1.0;
702 if (projection_matrix[3][3] == 0.0) {
703 q[0] = (-p[0] * focal) / projection_matrix[0][0];
704 q[1] = (-p[1] * focal) / projection_matrix[1][1];
708 q[0] = p[0] / projection_matrix[0][0];
709 q[1] = p[1] / projection_matrix[1][1];
716 real translation[3] = {
717 model_view_matrix[0][3],
718 model_view_matrix[1][3],
719 model_view_matrix[2][3],
721 for (
unsigned short i = 0; i < 3; i++) {
723 for (
unsigned short j = 0; j < 3; j++) {
724 q[i] += model_view_matrix[j][i] * (p[j] - translation[j]);
740 #define PERP(u, v) ((u)[0] * (v)[1] - (u)[1] * (v)[0])
744 if (seg[0] == seg[1]) {
751 Vec2r dseg = seg[1] - seg[0];
754 for (
unsigned int i = 0; i < n; i++) {
755 e = poly[i + 1] - poly[i];
756 N =
PERP(
e, seg[0] - poly[i]);
793 for (
unsigned int q =
X; q <=
Z; q++) {
795 vmin[q] = -maxbox[q];
800 vmax[q] = -maxbox[q];
803 if ((
normal * vmin) + d > 0.0f) {
806 if ((
normal * vmax) + d >= 0.0f) {
817 for (
unsigned int i = 0; i < 4; i++) {
818 for (
unsigned int j = 0; j < 4; j++) {
828 for (
unsigned int k = 0; k < 3; k++) {
829 q[k] = hq[k] / hq[3];
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
#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
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Vec< T, N > & normalize()
IconTextureDrawCall normal
ccl_device_inline float2 fabs(const float2 &a)
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])
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)
bool intersect2dSegPoly(Vec2r *seg, Vec2r *poly, unsigned n)
bool overlapTriangleBox(Vec3r &boxcenter, Vec3r &boxhalfsize, Vec3r triverts[3])
bool overlapPlaneBox(Vec3r &normal, real d, Vec3r &maxbox)
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 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