1#ifndef GIM_BASIC_GEOMETRY_OPERATIONS_H_INCLUDED
2#define GIM_BASIC_GEOMETRY_OPERATIONS_H_INCLUDED
40#ifndef PLANEDIREPSILON
41#define PLANEDIREPSILON 0.0000001f
44#ifndef PARALELENORMALS
45#define PARALELENORMALS 0.000001f
48#define TRIANGLE_NORMAL(v1, v2, v3, n) \
51 VEC_DIFF(_dif1, v2, v1); \
52 VEC_DIFF(_dif2, v3, v1); \
53 VEC_CROSS(n, _dif1, _dif2); \
57#define TRIANGLE_NORMAL_FAST(v1, v2, v3, n) \
60 VEC_DIFF(_dif1, v2, v1); \
61 VEC_DIFF(_dif2, v3, v1); \
62 VEC_CROSS(n, _dif1, _dif2); \
66#define TRIANGLE_PLANE(v1, v2, v3, plane) \
68 TRIANGLE_NORMAL(v1, v2, v3, plane); \
69 plane[3] = VEC_DOT(v1, plane); \
73#define TRIANGLE_PLANE_FAST(v1, v2, v3, plane) \
75 TRIANGLE_NORMAL_FAST(v1, v2, v3, plane); \
76 plane[3] = VEC_DOT(v1, plane); \
80#define EDGE_PLANE(e1, e2, n, plane) \
83 VEC_DIFF(_dif, e2, e1); \
84 VEC_CROSS(plane, _dif, n); \
85 VEC_NORMALIZE(plane); \
86 plane[3] = VEC_DOT(e1, plane); \
89#define DISTANCE_PLANE_POINT(plane, point) (VEC_DOT(plane, point) - plane[3])
91#define PROJECT_POINT_PLANE(point, plane, projected) \
94 _dis = DISTANCE_PLANE_POINT(plane, point); \
95 VEC_SCALE(projected, -_dis, plane); \
96 VEC_SUM(projected, projected, point); \
100template <
typename CLASS_POINT,
typename CLASS_PLANE>
102 const CLASS_POINT &
point,
const CLASS_PLANE *planes,
GUINT plane_count)
105 for (
GUINT _i = 0; _i < plane_count; ++_i)
108 if (_dis > 0.0f)
return false;
113template <
typename CLASS_POINT,
typename CLASS_PLANE>
115 const CLASS_POINT &s1,
116 const CLASS_POINT &s2,
const CLASS_PLANE &plane, CLASS_POINT &clipped)
121 _dis2 =
VEC_DOT(clipped, plane);
122 VEC_SCALE(clipped, -_dis1 / _dis2, clipped);
156template <
typename CLASS_POINT,
typename CLASS_PLANE>
158 const CLASS_POINT &s1,
159 const CLASS_POINT &s2,
160 const CLASS_PLANE &plane, CLASS_POINT &clipped)
176 _dis2 =
VEC_DOT(clipped, plane);
177 VEC_SCALE(clipped, -_dis1 / _dis2, clipped);
198template <
typename CLASS_POINT,
typename CLASS_PLANE>
200 const CLASS_POINT &s1,
201 const CLASS_POINT &s2,
202 const CLASS_PLANE &plane,
203 CLASS_POINT &clipped1, CLASS_POINT &clipped2)
206 switch (intersection_type)
231 return intersection_type;
235#define PLANE_MINOR_AXES(plane, i0, i1) VEC_MINOR_AXES(plane, i0, i1)
242template <
typename T,
typename CLASS_POINT,
typename CLASS_PLANE>
244 const CLASS_PLANE &plane,
245 const CLASS_POINT &vDir,
246 const CLASS_POINT &vPoint,
247 CLASS_POINT &pout,
T &tparam)
250 _dotdir =
VEC_DOT(plane, vDir);
256 tparam = -_dis / _dotdir;
269template <
typename T,
typename CLASS_POINT,
typename CLASS_PLANE>
271 const CLASS_PLANE &plane,
272 const CLASS_POINT &vDir,
273 const CLASS_POINT &vPoint,
279 _dotdir =
VEC_DOT(plane, vDir);
286 char returnvalue = _dis < 0.0f ? 2 : 1;
287 tparam = -_dis / _dotdir;
294 else if (tparam > tmax)
315template <
typename CLASS_POINT,
typename CLASS_PLANE>
317 const CLASS_PLANE &p1,
318 const CLASS_PLANE &p2,
326 _n[0] = p1[3] * p2[0] - p2[3] * p1[0];
327 _n[1] = p1[3] * p2[1] - p2[3] * p1[1];
328 _n[2] = p1[3] * p2[2] - p2[3] * p1[2];
340template <
typename CLASS_POINT>
342 CLASS_POINT &cp,
const CLASS_POINT &
v,
343 const CLASS_POINT &e1,
const CLASS_POINT &e2)
354 else if (_scalar > 1.0f)
376template <
typename T,
typename CLASS_POINT>
378 const CLASS_POINT &dir1,
380 const CLASS_POINT &dir2,
392 det = e1e2 * e1e2 - e1e1 * e2e2;
394 t1 = (e1e2 * p1p2e2 - e2e2 * p1p2e1) / det;
395 t2 = (e1e1 * p1p2e2 - e1e2 * p1p2e1) / det;
400template <
typename CLASS_POINT>
402 const CLASS_POINT &vA1,
403 const CLASS_POINT &vA2,
404 const CLASS_POINT &vB1,
405 const CLASS_POINT &vB2,
406 CLASS_POINT &vPointA,
407 CLASS_POINT &vPointB)
409 CLASS_POINT _AD, _BD, n;
418 bool invert_b_order =
false;
423 invert_b_order =
true;
429 n[0] = (_M[0] + _M[1]) * 0.5f;
430 n[1] = (_M[2] + _M[3]) * 0.5f;
436 vPointB = invert_b_order ? vB1 : vB2;
439 else if (_M[1] < _M[3])
441 vPointB = invert_b_order ? vB1 : vB2;
454 vPointB = invert_b_order ? vB2 : vB1;
457 else if (_M[3] < _M[1])
464 vPointB = invert_b_order ? vB1 : vB2;
481 VEC_SUM(vPointB, vPointB, vB1);
507 if (tlast < tfirst)
return false;
515 GUINT *order_indices)
518 order_indices[0] = values[0] < values[1] ? (values[0] < values[2] ? 0 : 2) : (values[1] < values[2] ? 1 : 2);
521 GUINT i0 = (order_indices[0] + 1) % 3;
522 GUINT i1 = (i0 + 1) % 3;
524 if (values[i0] < values[i1])
526 order_indices[1] = i0;
527 order_indices[2] = i1;
531 order_indices[1] = i1;
532 order_indices[2] = i0;
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
ATTR_WARN_UNUSED_RESULT const BMVert * v
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
SIMD_FORCE_INLINE btScalar btFabs(btScalar x)
#define SIMD_FORCE_INLINE
SIMD_FORCE_INLINE bool RAY_PLANE_COLLISION(const CLASS_PLANE &plane, const CLASS_POINT &vDir, const CLASS_POINT &vPoint, CLASS_POINT &pout, T &tparam)
Ray plane collision in one way.
#define DISTANCE_PLANE_POINT(plane, point)
SIMD_FORCE_INLINE eLINE_PLANE_INTERSECTION_TYPE PLANE_CLIP_SEGMENT2(const CLASS_POINT &s1, const CLASS_POINT &s2, const CLASS_PLANE &plane, CLASS_POINT &clipped)
Confirms if the plane intersect the edge or nor.
SIMD_FORCE_INLINE void CLOSEST_POINT_ON_SEGMENT(CLASS_POINT &cp, const CLASS_POINT &v, const CLASS_POINT &e1, const CLASS_POINT &e2)
SIMD_FORCE_INLINE void SORT_3_INDICES(const T *values, GUINT *order_indices)
Sorts 3 componets.
SIMD_FORCE_INLINE void PLANE_CLIP_SEGMENT(const CLASS_POINT &s1, const CLASS_POINT &s2, const CLASS_PLANE &plane, CLASS_POINT &clipped)
SIMD_FORCE_INLINE bool POINT_IN_HULL(const CLASS_POINT &point, const CLASS_PLANE *planes, GUINT plane_count)
Verifies if a point is in the plane hull.
SIMD_FORCE_INLINE eLINE_PLANE_INTERSECTION_TYPE PLANE_CLIP_SEGMENT_CLOSEST(const CLASS_POINT &s1, const CLASS_POINT &s2, const CLASS_PLANE &plane, CLASS_POINT &clipped1, CLASS_POINT &clipped2)
Confirms if the plane intersect the edge or not.
SIMD_FORCE_INLINE bool INTERSECT_PLANES(const CLASS_PLANE &p1, const CLASS_PLANE &p2, CLASS_POINT &p, CLASS_POINT &d)
Returns the Ray on which 2 planes intersect if they do. Written by Rodrigo Hernandez on ODE convex co...
eLINE_PLANE_INTERSECTION_TYPE
SIMD_FORCE_INLINE bool BOX_AXIS_INTERSECT(T pos, T dir, T bmin, T bmax, T &tfirst, T &tlast)
Line box intersection in one dimension.
SIMD_FORCE_INLINE void SEGMENT_COLLISION(const CLASS_POINT &vA1, const CLASS_POINT &vA2, const CLASS_POINT &vB1, const CLASS_POINT &vB2, CLASS_POINT &vPointA, CLASS_POINT &vPointB)
Find closest points on segments.
SIMD_FORCE_INLINE GUINT LINE_PLANE_COLLISION(const CLASS_PLANE &plane, const CLASS_POINT &vDir, const CLASS_POINT &vPoint, CLASS_POINT &pout, T &tparam, T tmin, T tmax)
line collision
SIMD_FORCE_INLINE bool LINE_INTERSECTION_PARAMS(const CLASS_POINT &dir1, CLASS_POINT &point1, const CLASS_POINT &dir2, CLASS_POINT &point2, T &t1, T &t2)
Finds the line params where these lines intersect.
#define VEC_CROSS(c, a, b)
Vector cross.
#define VEC_DOT(a, b)
Vector dot product.
#define VEC_SCALE(c, a, b)
scalar times vector
#define VEC_SUM(v21, v2, v1)
Vector sum.
#define VEC_COPY(b, a)
Copy 3D vector.
#define VEC_DIFF(v21, v2, v1)
Vector difference.
#define GIM_IS_ZERO(value)
#define GIM_SWAP_NUMBERS(a, b)
Swap numbers.
#define GIM_CLAMP(number, minval, maxval)
returns a clamped number