52 if ((((
max[0] >
A[0]) && (
A[0] >
min[0])) && ((
max[0] >
B[0]) && (
B[0] >
min[0]))) &&
53 (((
max[1] >
A[1]) && (
A[1] >
min[1])) && ((
max[1] >
B[1]) && (
B[1] >
min[1])))) {
62 real a1, a2, b1, b2, c1, c2;
69 c1 = p2[0] * p1[1] - p1[0] * p2[1];
72 r3 = a1 * p3[0] + b1 * p3[1] + c1;
73 r4 = a1 * p4[0] + b1 * p4[1] + c1;
77 if (r3 != 0 && r4 != 0 && r3 * r4 > 0.0) {
84 c2 = p4[0] * p3[1] - p3[0] * p4[1];
87 r1 = a2 * p1[0] + b2 * p1[1] + c2;
88 r2 = a2 * p2[0] + b2 * p2[1] + c2;
92 if (r1 != 0 && r2 != 0 && r1 * r2 > 0.0) {
97 denom = a1 * b2 - a2 * b1;
102 num = b1 * c2 - b2 * c1;
103 res[0] = num / denom;
105 num = a2 * c1 - a1 * c2;
106 res[1] = num / denom;
114 real a1, a2, b1, b2, c1, c2;
120 c1 = p2[0] * p1[1] - p1[0] * p2[1];
125 c2 = p4[0] * p3[1] - p3[0] * p4[1];
128 denom = a1 * b2 - a2 * b1;
133 num = b1 * c2 - b2 * c1;
134 res[0] = num / denom;
136 num = a2 * c1 - a1 * c2;
137 res[1] = num / denom;
150 real a1, a2, b1, b2, c1, c2;
157 c1 = p2[0] * p1[1] - p1[0] * p2[1];
160 r3 = a1 * p3[0] + b1 * p3[1] + c1;
161 r4 = a1 * p4[0] + b1 * p4[1] + c1;
165 if (r3 != 0 && r4 != 0 && r3 * r4 > 0.0) {
172 c2 = p4[0] * p3[1] - p3[0] * p4[1];
175 r1 = a2 * p1[0] + b2 * p1[1] + c2;
176 r2 = a2 * p2[0] + b2 * p2[1] + c2;
180 if (r1 != 0 && r2 != 0 && r1 * r2 > 0.0) {
185 denom = a1 * b2 - a2 * b1;
195 num = -b2 * d1 - a2 * e1;
198 num = -b1 * d1 - a1 * e1;
217 #define FINDMINMAX(x0, x1, x2, min, max) \
236 #define AXISTEST_X01(a, b, fa, fb) \
238 p0 = a * v0[Y] - b * v0[Z]; \
239 p2 = a * v2[Y] - b * v2[Z]; \
248 rad = fa * boxhalfsize[Y] + fb * boxhalfsize[Z]; \
249 if (min > rad || max < -rad) { \
255 #define AXISTEST_X2(a, b, fa, fb) \
257 p0 = a * v0[Y] - b * v0[Z]; \
258 p1 = a * v1[Y] - b * v1[Z]; \
267 rad = fa * boxhalfsize[Y] + fb * boxhalfsize[Z]; \
268 if (min > rad || max < -rad) { \
275 #define AXISTEST_Y02(a, b, fa, fb) \
277 p0 = -a * v0[X] + b * v0[Z]; \
278 p2 = -a * v2[X] + b * v2[Z]; \
287 rad = fa * boxhalfsize[X] + fb * boxhalfsize[Z]; \
288 if (min > rad || max < -rad) { \
294 #define AXISTEST_Y1(a, b, fa, fb) \
296 p0 = -a * v0[X] + b * v0[Z]; \
297 p1 = -a * v1[X] + b * v1[Z]; \
306 rad = fa * boxhalfsize[X] + fb * boxhalfsize[Z]; \
307 if (min > rad || max < -rad) { \
314 #define AXISTEST_Z12(a, b, fa, fb) \
316 p1 = a * v1[X] - b * v1[Y]; \
317 p2 = a * v2[X] - b * v2[Y]; \
326 rad = fa * boxhalfsize[X] + fb * boxhalfsize[Y]; \
327 if (min > rad || max < -rad) { \
333 #define AXISTEST_Z0(a, b, fa, fb) \
335 p0 = a * v0[X] - b * v0[Y]; \
336 p1 = a * v1[X] - b * v1[Y]; \
345 rad = fa * boxhalfsize[X] + fb * boxhalfsize[Y]; \
346 if (min > rad || max < -rad) { \
362 real min,
max, d, p0, p1, p2, rad, fex, fey, fez;
366 v0 = triverts[0] - boxcenter;
367 v1 = triverts[1] - boxcenter;
368 v2 = triverts[2] - boxcenter;
405 if (
min > boxhalfsize[
X] ||
max < -boxhalfsize[
X]) {
411 if (
min > boxhalfsize[
Y] ||
max < -boxhalfsize[
Y]) {
417 if (
min > boxhalfsize[
Z] ||
max < -boxhalfsize[
Z]) {
454 Vec3r edge1, edge2, tvec, pvec, qvec;
475 if (u < 0.0 || u > det) {
481 if (v < 0.0 || u + v > det) {
488 if (u > 0.0 || u < det) {
494 if (
v > 0.0 || u +
v < det) {
504 t = (edge2 * qvec) * inv_det;
529 t = -(d + (
norm * orig)) / denom;
548 float tymin, tymax, tzmin, tzmax;
549 Vec3r inv_direction(1.0 / dir[0], 1.0 / dir[1], 1.0 / dir[2]);
551 sign[0] = (inv_direction.
x() < 0);
552 sign[1] = (inv_direction.
y() < 0);
553 sign[2] = (inv_direction.
z() < 0);
559 tmin = (
bounds[
sign[0]].x() - orig.
x()) * inv_direction.
x();
560 tmax = (
bounds[1 -
sign[0]].x() - orig.
x()) * inv_direction.
x();
561 tymin = (
bounds[
sign[1]].y() - orig.
y()) * inv_direction.
y();
562 tymax = (
bounds[1 -
sign[1]].y() - orig.
y()) * inv_direction.
y();
563 if ((tmin > tymax) || (tymin > tmax)) {
572 tzmin = (
bounds[
sign[2]].z() - orig.
z()) * inv_direction.
z();
573 tzmax = (
bounds[1 -
sign[2]].z() - orig.
z()) * inv_direction.
z();
574 if ((tmin > tzmax) || (tzmin > tmax)) {
583 return ((tmin < t1) && (tmax > t0));
600 Vec3r J(AB ^ AP),
K(BC ^ BP),
L(CA ^ CP);
622 HVec3r hvert(vert), res_tmp;
624 for (
unsigned int j = 0; j < 4; j++) {
626 for (
unsigned int i = 0; i < 4; i++) {
627 res_tmp[i] += matrix(i, j) * scale;
631 res[0] = res_tmp.
x();
632 res[1] = res_tmp.
y();
633 res[2] = res_tmp.
z();
639 res.resize(vertices.size());
640 for (i = 0; i < vertices.size(); i++) {
648 for (
unsigned int i = 0; i < 3; i++) {
650 for (
unsigned int j = 0; j < 3; j++) {
651 res[i] += mat(i, j) *
v[j];
674 q[0] = viewport[0] + viewport[2] * (p[0] + 1.0) / 2.0;
677 q[1] = viewport[1] + viewport[3] * (p[1] + 1.0) / 2.0;
680 q[2] = (p[2] + 1.0) / 2.0;
685 const real model_view_matrix[4][4],
686 const real projection_matrix[4][4],
687 const int viewport[4])
701 q[0] = viewport[0] + viewport[2] * (q[0] + 1.0) / 2.0;
704 q[1] = viewport[1] + viewport[3] * (q[1] + 1.0) / 2.0;
710 q[0] = 2.0 * (q[0] - viewport[0]) / viewport[2] - 1.0;
711 q[1] = 2.0 * (q[1] - viewport[1]) / viewport[3] - 1.0;
716 if (projection_matrix[3][3] == 0.0) {
717 q[0] = (-p[0] * focal) / projection_matrix[0][0];
718 q[1] = (-p[1] * focal) / projection_matrix[1][1];
722 q[0] = p[0] / projection_matrix[0][0];
723 q[1] = p[1] / projection_matrix[1][1];
730 real translation[3] = {
731 model_view_matrix[0][3],
732 model_view_matrix[1][3],
733 model_view_matrix[2][3],
735 for (
unsigned short i = 0; i < 3; i++) {
737 for (
unsigned short j = 0; j < 3; j++) {
738 q[i] += model_view_matrix[j][i] * (p[j] - translation[j]);
754 #define PERP(u, v) ((u)[0] * (v)[1] - (u)[1] * (v)[0])
758 if (seg[0] == seg[1]) {
765 Vec2r dseg = seg[1] - seg[0];
768 for (
unsigned int i = 0; i < n; i++) {
769 e = poly[i + 1] - poly[i];
770 N =
PERP(
e, seg[0] - poly[i]);
807 for (
unsigned int q =
X; q <=
Z; q++) {
809 vmin[q] = -maxbox[q];
814 vmax[q] = -maxbox[q];
817 if ((
normal * vmin) + d > 0.0f) {
820 if ((
normal * vmax) + d >= 0.0f) {
831 for (
unsigned int i = 0; i < 4; i++) {
832 for (
unsigned int j = 0; j < 4; j++) {
842 for (
unsigned int k = 0; k < 3; k++) {
843 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
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
ccl_device_inline float2 fabs(const float2 &a)