KiCad PCB EDA Suite
Loading...
Searching...
No Matches
3d_math.h File Reference

Defines math related functions. More...

Go to the source code of this file.

Functions

glm::mat4 CalcModelMatrix (const SFVEC3F &aOffset, const SFVEC3F &aRotation, const SFVEC3F &aScale)
 Build the model-to-footprint transform used by rendering and picking.
 
SFVEC3F CalcModelRotation (const glm::mat3 &aRotation)
 Recover the FP_3DMODEL angles that CalcModelMatrix() would turn into aRotation.
 
SFVEC3F InterpolateModelRotation (const SFVEC3F &aStart, const SFVEC3F &aEnd, float aT)
 Interpolate between two model orientations along the shortest arc.
 
SFVEC3F SphericalToCartesian (float aInclination, float aAzimuth)
 https://en.wikipedia.org/wiki/Spherical_coordinate_system
 
SFVEC3F UniformRandomHemisphereDirection ()
 
SFVEC3F CosWeightedRandomHemisphereDirection (const SFVEC3F &n)
 
bool Refract (const SFVEC3F &aInVector, const SFVEC3F &aNormal, float aRin_over_Rout, SFVEC3F &aOutVector)
 Based on: https://github.com/mmp/pbrt-v3/blob/master/src/core/reflection.h See also: http://www.flipcode.com/archives/Raytracing_Topics_Techniques-Part_3_Refractions_and_Beers_Law.shtml.
 
float mapf (float x, float in_min, float in_max, float out_min, float out_max)
 
float RGBtoGray (const SFVEC3F &aColor)
 
SFVEC3F MaterialDiffuseToColorCAD (const SFVEC3F &aDiffuseColor)
 
float QuadricEasingInOut (float t)
 
float BezierBlend (float t)
 

Detailed Description

Defines math related functions.

Definition in file 3d_math.h.

Function Documentation

◆ BezierBlend()

float BezierBlend ( float t)
inline

Definition at line 210 of file 3d_math.h.

Referenced by TRACK_BALL::Interpolate().

◆ CalcModelMatrix()

glm::mat4 CalcModelMatrix ( const SFVEC3F & aOffset,
const SFVEC3F & aRotation,
const SFVEC3F & aScale )

Build the model-to-footprint transform used by rendering and picking.

Offsets are in millimetres, in the footprint's Y-up frame. Scale is applied in the model's original axes, before rotation and translation.

Parameters
aOffset
aRotationraw FP_3DMODEL::m_Rotation in degrees (the negation of the UI angles), applied about X, then Y, then Z before translation.
aScale

Definition at line 34 of file 3d_math.cpp.

Referenced by PANEL_PREVIEW_3D_MODEL::alignmentModelMatrix(), RENDER_3D_OPENGL::get3dModelsFromFootprint(), getModelHeight(), InterpolateModelRotation(), RENDER_3D_RAYTRACE_BASE::load3DModels(), ODB::ModelHeightAboveBoard(), and EDA_3D_CANVAS::PickModel().

◆ CalcModelRotation()

SFVEC3F CalcModelRotation ( const glm::mat3 & aRotation)

Recover the FP_3DMODEL angles that CalcModelMatrix() would turn into aRotation.

Parameters
aRotationan orthonormal rotation matrix.
Returns
the raw FP_3DMODEL::m_Rotation degrees.

Definition at line 47 of file 3d_math.cpp.

References std::abs().

Referenced by InterpolateModelRotation().

◆ CosWeightedRandomHemisphereDirection()

SFVEC3F CosWeightedRandomHemisphereDirection ( const SFVEC3F & n)
inline

Definition at line 100 of file 3d_math.h.

◆ InterpolateModelRotation()

SFVEC3F InterpolateModelRotation ( const SFVEC3F & aStart,
const SFVEC3F & aEnd,
float aT )

Interpolate between two model orientations along the shortest arc.

Both angle triplets are raw FP_3DMODEL::m_Rotation degrees. Interpolating the angles directly would tumble through gimbal lock, so the ends are converted to quaternions and the result is decomposed back.

Parameters
aStart
aEnd
aTthe interpolation parameter, clamped to [0, 1].

Definition at line 73 of file 3d_math.cpp.

References CalcModelMatrix(), CalcModelRotation(), and end.

Referenced by PANEL_PREVIEW_3D_MODEL::tickAlignmentAnimation().

◆ mapf()

float mapf ( float x,
float in_min,
float in_max,
float out_min,
float out_max )
inline

Definition at line 164 of file 3d_math.h.

Referenced by RENDER_3D_OPENGL::setupMaterials().

◆ MaterialDiffuseToColorCAD()

SFVEC3F MaterialDiffuseToColorCAD ( const SFVEC3F & aDiffuseColor)
inline

Definition at line 178 of file 3d_math.h.

References RGBtoGray().

Referenced by RENDER_3D_RAYTRACE_BASE::addModels(), MODEL_3D::Draw(), and MODEL_3D::MODEL_3D().

◆ QuadricEasingInOut()

float QuadricEasingInOut ( float t)
inline

Definition at line 194 of file 3d_math.h.

Referenced by TRACK_BALL::Interpolate().

◆ Refract()

bool Refract ( const SFVEC3F & aInVector,
const SFVEC3F & aNormal,
float aRin_over_Rout,
SFVEC3F & aOutVector )
inline

Based on: https://github.com/mmp/pbrt-v3/blob/master/src/core/reflection.h See also: http://www.flipcode.com/archives/Raytracing_Topics_Techniques-Part_3_Refractions_and_Beers_Law.shtml.

Parameters
aInVectorincoming vector.
aNormalnormal in the intersection point.
aRin_over_Routincoming refraction index / out refraction index.
aOutVectorthe refracted vector.
Returns
true

Definition at line 143 of file 3d_math.h.

Referenced by RENDER_3D_RAYTRACE_BASE::shadeHit().

◆ RGBtoGray()

float RGBtoGray ( const SFVEC3F & aColor)
inline

◆ SphericalToCartesian()

SFVEC3F SphericalToCartesian ( float aInclination,
float aAzimuth )
inline

https://en.wikipedia.org/wiki/Spherical_coordinate_system

Parameters
aInclinationθ ∈ [0, π]
aAzimuthφ ∈ [0, 2π]
Returns
Cartesian coordinates

Definition at line 74 of file 3d_math.h.

Referenced by init_lights(), and RENDER_3D_RAYTRACE_BASE::Reload().

◆ UniformRandomHemisphereDirection()

SFVEC3F UniformRandomHemisphereDirection ( )
inline
Todo
This is not correct because it is not a gaussian random.

Definition at line 86 of file 3d_math.h.

References Fast_RandFloat().

Referenced by RENDER_3D_RAYTRACE_BASE::shadeHit().