Blender  V3.3
Macros | Enumerations | Functions
gim_basic_geometry_operations.h File Reference
#include "gim_linear_math.h"

Go to the source code of this file.

Macros

#define PLANEDIREPSILON   0.0000001f
 
#define PARALELENORMALS   0.000001f
 
#define TRIANGLE_NORMAL(v1, v2, v3, n)
 
#define TRIANGLE_NORMAL_FAST(v1, v2, v3, n)
 
#define TRIANGLE_PLANE(v1, v2, v3, plane)
 plane is a vec4f More...
 
#define TRIANGLE_PLANE_FAST(v1, v2, v3, plane)
 plane is a vec4f More...
 
#define EDGE_PLANE(e1, e2, n, plane)
 Calc a plane from an edge an a normal. plane is a vec4f. More...
 
#define DISTANCE_PLANE_POINT(plane, point)   (VEC_DOT(plane, point) - plane[3])
 
#define PROJECT_POINT_PLANE(point, plane, projected)
 
#define PLANE_MINOR_AXES(plane, i0, i1)   VEC_MINOR_AXES(plane, i0, i1)
 Finds the 2 smallest cartesian coordinates of a plane normal. More...
 

Enumerations

enum  ePLANE_INTERSECTION_TYPE { G_BACK_PLANE = 0 , G_COLLIDE_PLANE , G_FRONT_PLANE }
 
enum  eLINE_PLANE_INTERSECTION_TYPE {
  G_FRONT_PLANE_S1 = 0 , G_FRONT_PLANE_S2 , G_BACK_PLANE_S1 , G_BACK_PLANE_S2 ,
  G_COLLIDE_PLANE_S1 , G_COLLIDE_PLANE_S2
}
 

Functions

template<typename CLASS_POINT , typename CLASS_PLANE >
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. More...
 
template<typename CLASS_POINT , typename CLASS_PLANE >
SIMD_FORCE_INLINE void PLANE_CLIP_SEGMENT (const CLASS_POINT &s1, const CLASS_POINT &s2, const CLASS_PLANE &plane, CLASS_POINT &clipped)
 
template<typename CLASS_POINT , typename CLASS_PLANE >
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. More...
 
template<typename CLASS_POINT , typename CLASS_PLANE >
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. More...
 
template<typename T , typename CLASS_POINT , typename CLASS_PLANE >
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. More...
 
template<typename T , typename CLASS_POINT , typename CLASS_PLANE >
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 More...
 
template<typename CLASS_POINT , typename CLASS_PLANE >
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 collision. More...
 
template<typename CLASS_POINT >
SIMD_FORCE_INLINE void CLOSEST_POINT_ON_SEGMENT (CLASS_POINT &cp, const CLASS_POINT &v, const CLASS_POINT &e1, const CLASS_POINT &e2)
 
template<typename T , typename CLASS_POINT >
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. More...
 
template<typename CLASS_POINT >
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. More...
 
template<typename T >
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. More...
 
template<typename T >
SIMD_FORCE_INLINE void SORT_3_INDICES (const T *values, GUINT *order_indices)
 Sorts 3 componets. More...
 

Detailed Description

Author
Francisco Leon Najera type independant geometry routines

Definition in file gim_basic_geometry_operations.h.

Macro Definition Documentation

◆ DISTANCE_PLANE_POINT

#define DISTANCE_PLANE_POINT (   plane,
  point 
)    (VEC_DOT(plane, point) - plane[3])

Definition at line 89 of file gim_basic_geometry_operations.h.

◆ EDGE_PLANE

#define EDGE_PLANE (   e1,
  e2,
  n,
  plane 
)
Value:
{ \
vec3f _dif; \
VEC_DIFF(_dif, e2, e1); \
VEC_CROSS(plane, _dif, n); \
VEC_NORMALIZE(plane); \
plane[3] = VEC_DOT(e1, plane); \
}
#define VEC_DOT(a, b)
Vector dot product.

Calc a plane from an edge an a normal. plane is a vec4f.

Definition at line 80 of file gim_basic_geometry_operations.h.

◆ PARALELENORMALS

#define PARALELENORMALS   0.000001f

Definition at line 45 of file gim_basic_geometry_operations.h.

◆ PLANE_MINOR_AXES

#define PLANE_MINOR_AXES (   plane,
  i0,
  i1 
)    VEC_MINOR_AXES(plane, i0, i1)

Finds the 2 smallest cartesian coordinates of a plane normal.

Definition at line 235 of file gim_basic_geometry_operations.h.

◆ PLANEDIREPSILON

#define PLANEDIREPSILON   0.0000001f

Definition at line 41 of file gim_basic_geometry_operations.h.

◆ PROJECT_POINT_PLANE

#define PROJECT_POINT_PLANE (   point,
  plane,
  projected 
)
Value:
{ \
GREAL _dis; \
_dis = DISTANCE_PLANE_POINT(plane, point); \
VEC_SCALE(projected, -_dis, plane); \
VEC_SUM(projected, projected, point); \
}
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 Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise 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
#define DISTANCE_PLANE_POINT(plane, point)

Definition at line 91 of file gim_basic_geometry_operations.h.

◆ TRIANGLE_NORMAL

#define TRIANGLE_NORMAL (   v1,
  v2,
  v3,
 
)
Value:
{ \
vec3f _dif1, _dif2; \
VEC_DIFF(_dif1, v2, v1); \
VEC_DIFF(_dif2, v3, v1); \
VEC_CROSS(n, _dif1, _dif2); \
VEC_NORMALIZE(n); \
}
_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
ATTR_WARN_UNUSED_RESULT const BMVert * v2

Definition at line 48 of file gim_basic_geometry_operations.h.

◆ TRIANGLE_NORMAL_FAST

#define TRIANGLE_NORMAL_FAST (   v1,
  v2,
  v3,
 
)
Value:
{ \
vec3f _dif1, _dif2; \
VEC_DIFF(_dif1, v2, v1); \
VEC_DIFF(_dif2, v3, v1); \
VEC_CROSS(n, _dif1, _dif2); \
}

Definition at line 57 of file gim_basic_geometry_operations.h.

◆ TRIANGLE_PLANE

#define TRIANGLE_PLANE (   v1,
  v2,
  v3,
  plane 
)
Value:
{ \
TRIANGLE_NORMAL(v1, v2, v3, plane); \
plane[3] = VEC_DOT(v1, plane); \
}

plane is a vec4f

Definition at line 66 of file gim_basic_geometry_operations.h.

◆ TRIANGLE_PLANE_FAST

#define TRIANGLE_PLANE_FAST (   v1,
  v2,
  v3,
  plane 
)
Value:
{ \
TRIANGLE_NORMAL_FAST(v1, v2, v3, plane); \
plane[3] = VEC_DOT(v1, plane); \
}

plane is a vec4f

Definition at line 73 of file gim_basic_geometry_operations.h.

Enumeration Type Documentation

◆ eLINE_PLANE_INTERSECTION_TYPE

Enumerator
G_FRONT_PLANE_S1 
G_FRONT_PLANE_S2 
G_BACK_PLANE_S1 
G_BACK_PLANE_S2 
G_COLLIDE_PLANE_S1 
G_COLLIDE_PLANE_S2 

Definition at line 133 of file gim_basic_geometry_operations.h.

◆ ePLANE_INTERSECTION_TYPE

Enumerator
G_BACK_PLANE 
G_COLLIDE_PLANE 
G_FRONT_PLANE 

Definition at line 126 of file gim_basic_geometry_operations.h.

Function Documentation

◆ BOX_AXIS_INTERSECT()

template<typename T >
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.

Parameters
posPosition of the ray
dirProjection of the Direction of the ray
bminMinimum bound of the box
bmaxMaximum bound of the box
tfirstthe minimum projection. Assign to 0 at first.
tlastthe maximum projection. Assign to INFINITY at first.
Returns
true if there is an intersection.

Definition at line 496 of file gim_basic_geometry_operations.h.

References GIM_IS_ZERO, GIM_MAX, GIM_MIN, GIM_SWAP_NUMBERS, GREAL, and pos.

◆ CLOSEST_POINT_ON_SEGMENT()

template<typename CLASS_POINT >
SIMD_FORCE_INLINE void CLOSEST_POINT_ON_SEGMENT ( CLASS_POINT &  cp,
const CLASS_POINT &  v,
const CLASS_POINT &  e1,
const CLASS_POINT &  e2 
)

Finds the closest point(cp) to (v) on a segment (e1,e2)

Definition at line 341 of file gim_basic_geometry_operations.h.

References GREAL, v, VEC_COPY, VEC_DIFF, VEC_DOT, VEC_SCALE, and VEC_SUM.

Referenced by SEGMENT_COLLISION().

◆ INTERSECT_PLANES()

template<typename CLASS_POINT , typename CLASS_PLANE >
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 collision.

Parameters
p1Plane 1
p2Plane 2
pContains the origin of the ray upon returning if planes intersect
dContains the direction of the ray upon returning if planes intersect
Returns
true if the planes intersect, 0 if paralell.

Definition at line 316 of file gim_basic_geometry_operations.h.

References GIM_IS_ZERO, GREAL, VEC_CROSS, and VEC_DOT.

◆ LINE_INTERSECTION_PARAMS()

template<typename T , typename CLASS_POINT >
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.

Parameters
dir1Direction of line 1
point1Point of line 1
dir2Direction of line 2
point2Point of line 2
t1Result Parameter for line 1
t2Result Parameter for line 2
dointersect0 if the lines won't intersect, else 1

Definition at line 377 of file gim_basic_geometry_operations.h.

References GIM_IS_ZERO, GREAL, VEC_DIFF, and VEC_DOT.

◆ LINE_PLANE_COLLISION()

template<typename T , typename CLASS_POINT , typename CLASS_PLANE >
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

Returns
-0 if the ray never intersects -1 if the ray collides in front -2 if the ray collides in back

Definition at line 270 of file gim_basic_geometry_operations.h.

References btFabs(), DISTANCE_PLANE_POINT, GREAL, PLANEDIREPSILON, VEC_DOT, VEC_SCALE, and VEC_SUM.

Referenced by GIM_TRIANGLE::ray_collision(), GIM_TRIANGLE::ray_collision_front_side(), and SEGMENT_COLLISION().

◆ PLANE_CLIP_SEGMENT()

template<typename CLASS_POINT , typename CLASS_PLANE >
SIMD_FORCE_INLINE void PLANE_CLIP_SEGMENT ( const CLASS_POINT &  s1,
const CLASS_POINT &  s2,
const CLASS_PLANE &  plane,
CLASS_POINT &  clipped 
)

◆ PLANE_CLIP_SEGMENT2()

template<typename CLASS_POINT , typename CLASS_PLANE >
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.

intersection type must have the following values

  • 0 : Segment in front of plane, s1 closest
  • 1 : Segment in front of plane, s2 closest
  • 2 : Segment in back of plane, s1 closest
  • 3 : Segment in back of plane, s2 closest
  • 4 : Segment collides plane, s1 in back
  • 5 : Segment collides plane, s2 in back

Definition at line 157 of file gim_basic_geometry_operations.h.

References DISTANCE_PLANE_POINT, G_BACK_PLANE_S1, G_BACK_PLANE_S2, G_COLLIDE_PLANE_S1, G_COLLIDE_PLANE_S2, G_EPSILON, G_FRONT_PLANE_S1, G_FRONT_PLANE_S2, GREAL, VEC_DIFF, VEC_DOT, VEC_SCALE, and VEC_SUM.

Referenced by PLANE_CLIP_SEGMENT_CLOSEST().

◆ PLANE_CLIP_SEGMENT_CLOSEST()

template<typename CLASS_POINT , typename CLASS_PLANE >
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.

clipped1 and clipped2 are the vertices behind the plane. clipped1 is the closest

intersection_type must have the following values

  • 0 : Segment in front of plane, s1 closest
  • 1 : Segment in front of plane, s2 closest
  • 2 : Segment in back of plane, s1 closest
  • 3 : Segment in back of plane, s2 closest
  • 4 : Segment collides plane, s1 in back
  • 5 : Segment collides plane, s2 in back

Definition at line 199 of file gim_basic_geometry_operations.h.

References G_BACK_PLANE_S1, G_BACK_PLANE_S2, G_COLLIDE_PLANE_S1, G_COLLIDE_PLANE_S2, G_FRONT_PLANE_S1, G_FRONT_PLANE_S2, PLANE_CLIP_SEGMENT2(), and VEC_COPY.

◆ POINT_IN_HULL()

template<typename CLASS_POINT , typename CLASS_PLANE >
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.

Definition at line 101 of file gim_basic_geometry_operations.h.

References DISTANCE_PLANE_POINT, GREAL, GUINT, and point.

◆ RAY_PLANE_COLLISION()

template<typename T , typename CLASS_POINT , typename CLASS_PLANE >
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.

Intersects plane in one way only. The ray must face the plane (normals must be in opossite directions).
It uses the PLANEDIREPSILON constant.

Definition at line 243 of file gim_basic_geometry_operations.h.

References DISTANCE_PLANE_POINT, GREAL, PLANEDIREPSILON, VEC_DOT, VEC_SCALE, and VEC_SUM.

◆ SEGMENT_COLLISION()

template<typename CLASS_POINT >
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 
)

◆ SORT_3_INDICES()

template<typename T >
SIMD_FORCE_INLINE void SORT_3_INDICES ( const T values,
GUINT order_indices 
)

Sorts 3 componets.

Definition at line 513 of file gim_basic_geometry_operations.h.

References GUINT, and i1.