Class Toolkit
- Namespace
- SearchAThing.OpenGL.Core
- Assembly
- netcore-opengl-core.dll
public static class Toolkit
- Inheritance
-
Toolkit
- Inherited Members
Methods
ArbitraryAxisAlghorithm(in Vector3, out Vector3, out Vector3, out Vector3)
Build world matrix using Arbitrary Axis Algorithm.
public static void ArbitraryAxisAlghorithm(in Vector3 n, out Vector3 x, out Vector3 y, out Vector3 z)
Parameters
nVector3Normalized normal vector to which based the AAA construction.
xVector3Computed xbase..
yVector3Computed ybase.
zVector3Computed zbase.
Remarks
Origin has to be specified apart ( MakeCS(in Vector3, in Vector3) ).
References: https://images.autodesk.com/adsk/files/autocad_2012_pdf_dxf-reference_enu.pdf ( page 252 )
AverageColor(IGLTriangle)
Average color of triangles vertexes color.
public static Color AverageColor(this IGLTriangle tri)
Parameters
triIGLTriangle
Returns
CameraRotate(float, float, in Vector3, in Vector3, in Vector3, out Vector3, out Vector3)
Rotate the camera [view] a given rotation center [local].
public static void CameraRotate(float sAngleXRad, float sAngleYRad, in Vector3 wCameraPos, in Vector3 wCameraTarget, in Vector3 wCameraUp, out Vector3 wRotatedCameraTarget, out Vector3 wRotatedCameraUp)
Parameters
sAngleXRadfloatCamera rotation screen X angle (rad)..
sAngleYRadfloatCamera rotation screen Y angle (rad).
wCameraPosVector3Actual camera position [world].
wCameraTargetVector3Actual camera target [world].
wCameraUpVector3Actual camera up [world].
wRotatedCameraTargetVector3Rotated camera target [world].
wRotatedCameraUpVector3Rotated camera up [world].
CameraTilt(float, in Vector3, out Vector3)
Tilt camera [view] by rotating it's up vector around [view] z axis.
public static void CameraTilt(float angleRad, in Vector3 cu, out Vector3 cuTilted)
Parameters
angleRadfloatTilt angle (rad) [view].
cuVector3Camera up vector (x,y,z) [view].
cuTiltedVector3Tilted camera up vector (x,y,z) [view].
ClipToEye(in Vector4, in Matrix4x4)
Converts given clip space coord to the corresponding eye space coord.
Makes use of the inverse of the given projection matrix.
public static Vector3 ClipToEye(in Vector4 clip, in Matrix4x4 pm)
Parameters
Returns
- Vector3
Eye space coord (x,y,z).
ClipToLocal(in Vector4, in Matrix4x4, in Matrix4x4)
Converts given clip space coord to the corresponding local space coord.
It makes use of the inverse of given modelview matrix and projection matrix.
public static Vector3 ClipToLocal(in Vector4 clip, in Matrix4x4 mvm, in Matrix4x4 pm)
Parameters
clipVector4Clip space coord (x,y,z,w).
mvmMatrix4x4Modelview matrix (model * view).
pmMatrix4x4Projection matrix.
Returns
- Vector3
Local space coord (x,y,z).
ClipToNDC(in Vector4)
Converts given clip coord to the corresponding ndc space coord.
public static Vector3 ClipToNDC(in Vector4 clip)
Parameters
clipVector4Clip space coord (x,y,z,w).
Returns
- Vector3
Normalized device coord (x,y,z).
ClipToScreen(in Vector4, in Vector2)
Converts given clip space coord to the corresponding screen coord.
public static Vector2 ClipToScreen(in Vector4 clip, in Vector2 size)
Parameters
Returns
- Vector2
Screen space coord (x,y).
ComputeEBBox(IEnumerable<Vector3>, in Matrix4x4, in Matrix4x4, out Vector2, out Vector2)
Compute the eye space bounding box (x,y,z) of all local space coordinates (x,y,z) given.
public static void ComputeEBBox(IEnumerable<Vector3> lPts, in Matrix4x4 mm, in Matrix4x4 vm, out Vector2 eMin, out Vector2 eMax)
Parameters
lPtsIEnumerable<Vector3>Local space coordinates (x,y,z) [local] to include in evaluation of th eye space bbox.
mmMatrix4x4Model matrix [local].
vmMatrix4x4View matrix [world].
eMinVector2Computed minimum eye space coordinate (x,y,z) [eye],
eMaxVector2Computed maximum eye space coordinate (x,y,z) [eye].
ComputeSBBox(IEnumerable<Vector3>, in Vector2, in Matrix4x4, in Matrix4x4, in Matrix4x4, out Vector2, out Vector2, BBox?)
Compute the screen space bounding box (x,y) of all local space coordinates (x,y,z) given.
public static void ComputeSBBox(IEnumerable<Vector3> lPts, in Vector2 size, in Matrix4x4 mm, in Matrix4x4 vm, in Matrix4x4 pm, out Vector2 sMin, out Vector2 sMax, BBox? lBBox = null)
Parameters
lPtsIEnumerable<Vector3>Local space coordinates (x,y,z) [local] to include in evaluation of screen space bbox.
sizeVector2Screen size (x,y) [screen].
mmMatrix4x4Model matrix [local].
vmMatrix4x4View matrix [world].
pmMatrix4x4Projection matrix [eye].
sMinVector2Computed minimum screen space coordinate (x,y) [screen].
sMaxVector2Computed maximum screen space coordinate (x,y) [screen].
lBBoxBBoxIf given a non null BBox, the corresponding local space bbox [local] will emitted.
CreateModelMatrix(in Vector3, in Quaternion, in Vector3, out Matrix4x4)
Create model matrix to convert [local] space to [world] space.
It's a SRT ( Scale-Rotate-Translate ) transformations matrix.
It's used for one touch rotation of the model space objects.
public static void CreateModelMatrix(in Vector3 scale, in Quaternion rotation, in Vector3 translation, out Matrix4x4 mm)
Parameters
scaleVector3Scale factor (x,y).
rotationQuaternionRotation quaternion (x,y,z,w).
translationVector3Translation (x,y,z).
mmMatrix4x4Model matrix [local].
- See Also
CreateOrthogonalProjectionMatrix(in Vector2, float, float, float, in Matrix4x4, out Matrix4x4)
Create projection matrix ( Orthogonal mode ) to convert [eye] to [clip] space.
public static void CreateOrthogonalProjectionMatrix(in Vector2 size, float eOrthoZoom, float near, float far, in Matrix4x4 vm, out Matrix4x4 pm)
Parameters
sizeVector2screen size (x,y) [screen].
eOrthoZoomfloat[eye] zoom factor about screen size used as a reference.
nearfloatAbsolute position along [eye] z axis of the near clipping plane.
farfloatAbsolute position along [eye] z axis of the far clipping plane.
vmMatrix4x4pmMatrix4x4
CreatePerspectiveProjectionMatrix(float, float, float, float, out Matrix4x4)
Create projection matrix ( Perspective mode ) to convert [eye] to [clip] space.
It's used to create perspective field of view in perspective mode.
public static void CreatePerspectiveProjectionMatrix(float fovDeg, float ar, float near, float far, out Matrix4x4 pm)
Parameters
fovDegfloatAngle of view [deg].
arfloatProjection screen aspection ratio (x/y).
nearfloatAbsolute position along [eye] z axis of the near clipping plane.
farfloatAbsolute position along [eye] z axis of the far clipping plane.
pmMatrix4x4Projection matrix [eye].
- See Also
CreateViewMatrix(in Vector3, in Vector3, in Vector3, out Matrix4x4)
Create view matrix to convert [world] to [eye] space.
It's used for pan, camera movements functions and either for scale function in perspective mode.
public static void CreateViewMatrix(in Vector3 cameraPos, in Vector3 cameraTarget, in Vector3 cameraUp, out Matrix4x4 vm)
Parameters
cameraPosVector3Camera position (x,y,z) [world].
cameraTargetVector3Camera target (x,y,z) [world].
cameraUpVector3Camera up (x,y,z) [world].
vmMatrix4x4View matrix [world].
- See Also
DefaultTriangleNormal(IGLTriangle)
Default triangle compute normal function:
Normalize((V2-V1) x (V3-V1))
public static Vector3 DefaultTriangleNormal(this IGLTriangle tri)
Parameters
triIGLTriangleTriangle which compute default normal.
Returns
- Vector3
Triangle default normal.
DeserializeMatrix4x4(string)
Deserialize to a Matrix4x4 from a string of 16 float space separated ( invariant ).
public static Matrix4x4 DeserializeMatrix4x4(string txt)
Parameters
txtstringSerialized Matrix4x4 text input.
Returns
- See Also
EyeToClip(in Vector3, in Matrix4x4)
Converts given world eye coord to the corresponding clip space coord.
public static Vector4 EyeToClip(in Vector3 eye, in Matrix4x4 pm)
Parameters
Returns
- Vector4
Clip space coord (x,y,z,w).
EyeToLocal(in Vector3, in Matrix4x4)
Converts given eye space coord to the corresponding local space coord.
It makes use of the inverse of given modelview matrix.
public static Vector3 EyeToLocal(in Vector3 eye, in Matrix4x4 mvm)
Parameters
Returns
- Vector3
Local space coord (x,y,z).
EyeToWorld(in Vector3, in Matrix4x4)
Converts given eye space coord to the corresponding world space coord.
Makes use of the inverse of the given view matrix.
public static Vector3 EyeToWorld(in Vector3 eye, in Matrix4x4 vm)
Parameters
Returns
- Vector3
World space coord (x,y,z).
GetContourColor(float, int, int, bool)
Retrieve color that is in the given offset in given hue range.
Default: hue range [240, 300] generating gradients in offeset range [0, 1] traversing following colors (
[blue, cyan, green, yellow, orange, red, fuchsia].
Following some colors hue values:
- 240 = Blue (0,0,255)
- 180 = Cyan (0,255,255)
- 120 = Green (0,255,0)
- 60 = Yellow (255,255,0)
- 30 = Orange (255,128,0)
- 0 = Red (255,0,0)
- 300 = Fuchsia (255,0,255)
- 270 = Violet (128,0,255)
ref: https://en.wikipedia.org/wiki/HSL_and_HSV
public static Color GetContourColor(float offset, int hueFrom = 240, int hueTo = 300, bool decreaseHue = true)
Parameters
offsetfloatOffset in range [0,1] of the color to choose in given hue range.
hueFromintHue of color range from.
hueTointHue of color range to.
decreaseHueboolIf true (default) offset traverse hue range decreasing hue starting by "from" toward "to". Otherwise "to" hue will reached by the "from" through increment of hue.
Returns
- Color
Color corresponding given range offset.
GroupByAdjacency(float, IEnumerable<Line>)
From a set of lines makes groups of them where each group is a set of lines
that constitute a single polyline within lines sorted by adjacency (from,to not necessary contiguous).
Lines with zero length will discarded.
public static List<List<Line>> GroupByAdjacency(float tol, IEnumerable<Line> lines)
Parameters
tolfloatComparision length tolerance.
linesIEnumerable<Line>Input lines.
Returns
- See Also
LocalToEye(in Vector3, in Matrix4x4)
Converts given local space coord to the corresponding eye coord.
public static Vector3 LocalToEye(in Vector3 local, in Matrix4x4 mvm)
Parameters
Returns
- Vector3
Eye space coord (x,y,z).
LocalToObject(in Vector3, in Matrix4x4)
Converts given local space coord to the corresponding object space coord.
Makes use of the inverse of the given object matrix.
public static Vector3 LocalToObject(in Vector3 local, in Matrix4x4 om)
Parameters
Returns
- Vector3
Object space coord (x,y,z).
LocalToScreen(in Vector3, in Vector2, in Matrix4x4)
Converts given local space coord to the corresponding screen coord.
public static Vector2 LocalToScreen(in Vector3 local, in Vector2 size, in Matrix4x4 mvpm)
Parameters
localVector3Local space coord (x,y,z).
sizeVector2Sceen size (x,y).
mvpmMatrix4x4ModelViewProjection matrix ( model * view * projection ).
Returns
- Vector2
Screen space coord (x,y).
LocalToWorld(in Vector3, in Matrix4x4)
Converts given local space coord to the corresponding world space coord.
public static Vector3 LocalToWorld(in Vector3 local, in Matrix4x4 mm)
Parameters
Returns
- Vector3
World space coord (x,y,z).
MakeCCS(in Vector3, in Vector3, in Vector3)
Make a world matrix that represent the one used by the camera [world].
Basey = Normalized(cameraUp)
Basez = Normalized(cameraPos - cameraTarget)
public static Matrix4x4 MakeCCS(in Vector3 cameraPos, in Vector3 cameraTarget, in Vector3 cameraUp)
Parameters
cameraPosVector3Camera position [world].
cameraTargetVector3Camera target [world].
cameraUpVector3Camera up versor [world].
Returns
MakeCS(in Vector3, in Vector3)
Build world matrix using ArbitraryAxisAlghorithm(in Vector3, out Vector3, out Vector3, out Vector3) and sets the origin to the given one.
public static Matrix4x4 MakeCS(in Vector3 origin, in Vector3 N)
Parameters
Returns
- Matrix4x4
World matrix.
MakeCS(in Vector3, in Vector3, in Vector3)
Create a right-hand rule world matrix with given origin and normalized orthonormal x, y base vectors.
public static Matrix4x4 MakeCS(in Vector3 origin, in Vector3 baseX, in Vector3 baseY)
Parameters
Returns
- Matrix4x4
World matrix.
MakeCS(in Vector3, in Vector3, in Vector3, bool)
Create a right-hand rule world matrix with given origin and reference vectors vx, vy.
public static Matrix4x4 MakeCS(in Vector3 origin, in Vector3 vx, in Vector3 vy, bool makeOrthonormalization = false)
Parameters
originVector3World origin.
vxVector3Reference vector to compute basex.
vyVector3Reference vector to compute basey.
makeOrthonormalizationboolIf false (default) vx and vy must given already normalized and ensured to be orthonormal.
If true base vector are computed by giving hinting vx, vy arguments:
- baseZ = Normalize(vx x vy)
- baseX = Normalize(vx)
- baseY = baseZ x baseX
Returns
- Matrix4x4
World matrix with basex aligned to given vx.
MakeCS(in Vector3, in Vector3, in Vector3, in Vector3)
Create world matrix with given origin and normalized orthonormal x, y, z base vectors.
public static Matrix4x4 MakeCS(in Vector3 origin, in Vector3 baseX, in Vector3 baseY, in Vector3 baseZ)
Parameters
originVector3World origin.
baseXVector3World basex.
baseYVector3World basey.
baseZVector3World basez.
Returns
- Matrix4x4
World matrix.
MakeFrustum(GLControl)
Generate a gl figure that represents the camera frustum object.
public static List<GLFigureBase> MakeFrustum(this GLControl glControl)
Parameters
glControlGLControl
Returns
MakeFrustum(in Vector3, in Vector3, in Vector3, float, float, float, in Matrix4x4)
Generate a gl figure that represent the camera frustum object.
public static List<GLFigureBase> MakeFrustum(in Vector3 cameraPos, in Vector3 cameraTarget, in Vector3 cameraUp, float near, float far, float fov, in Matrix4x4 mm)
Parameters
cameraPosVector3Camera position [world].
cameraTargetVector3Camera target [world].
cameraUpVector3Camera up [world].
nearfloatNear plane [world].
farfloatFar plane [world].
fovfloatField of view (rad).
mmMatrix4x4Model matrix [world].
Returns
- List<GLFigureBase>
frustum figures
MakeScreenCS(in Vector3?)
Create a screen matrix using given origin.
That is the same of a world matrix with y flipped like the screen coordinates are with (0,0) on (left,top).
public static Matrix4x4 MakeScreenCS(in Vector3? origin = null)
Parameters
originVector3?Screen origin.
Returns
- Matrix4x4
Screen matrix.
MakeTextFigure(GLContext, GLText)
Generate a triangle figure textured to represents the given GLText
public static List<GLTriangleFigure> MakeTextFigure(this GLContext glContext, GLText glText)
Parameters
glContextGLContextGl context ( used to access GLFontCharManager ).
glTextGLTextGl text.
Returns
- List<GLTriangleFigure>
Gl triangle figure.
MakeTextFigure(GLModel, GLText)
Generate a triangle figure textured to represents the given GLText
public static List<GLTriangleFigure> MakeTextFigure(this GLModel glModel, GLText glText)
Parameters
glModelGLModelGl model ( used to access GLFontCharManager ).
glTextGLTextGl text.
Returns
- List<GLTriangleFigure>
Gl triangle figure.
MakeWCS(in Vector3?)
Create world matrix using given origin and basex=(1,0,0), basey=(0,1,0), basez=(0,0,1).
public static Matrix4x4 MakeWCS(in Vector3? origin = null)
Parameters
originVector3?World origin.
Returns
- Matrix4x4
World matrix.
MakeWCS(float, float, float)
Create world matrix using given origin and basex=(1,0,0), basey=(0,1,0), basez=(0,0,1).
public static Matrix4x4 MakeWCS(float ox, float oy, float oz)
Parameters
Returns
- Matrix4x4
World matrix.
ModelRotate(float, float, in Vector3, in Matrix4x4, in Matrix4x4, out Matrix4x4)
Rotate the model by given [eye] x,y angles around given [local] rotation center.
public static void ModelRotate(float angleXRad, float angleYRad, in Vector3 rot_center, in Matrix4x4 mm, in Matrix4x4 vm, out Matrix4x4 mmRotated)
Parameters
angleXRadfloatEye space x angle rotation (rad).
angleYRadfloatEye space y angle rotation (rad).
rot_centerVector3Local space (x,y,z) rotation center [local].
mmMatrix4x4Model matrix [local].
vmMatrix4x4View matrix [world].
mmRotatedMatrix4x4Rotated model matrix [local].
NDCToClip_virtual(in Vector3, float)
Converts given normalized device coord to virtual clip space coord (w=1).
public static Vector4 NDCToClip_virtual(in Vector3 ndc, float w = 1)
Parameters
ndcVector3(x,y,z) ndc coord
wfloatValue of 4-th component to set in computed clip space coord ( Default: 1 )
Returns
- Vector4
(virtual) Clip space coord (x,y,z,w).
NDCToScreen(in Vector3, in Vector2)
Convert given normalized device coord to the corresponding screen coord.
Depending on YAxisOrientation ( default: YPositiveDown ):
- YPositiveDown : ndc (-1,+1,), ..., (+1,-1,) to screen (0, 0), ..., (w-1, h-1)
- YPositiveUp : ndc (-1,-1,), ..., (+1,+1,) to screen (0, 0), ..., (w-1, h-1)
public static Vector2 NDCToScreen(in Vector3 ndc, in Vector2 size)
Parameters
Returns
- Vector2
Screen coord (x,y).
ObjectToLocal(in Vector3, in Matrix4x4)
Converts given object space coord to the corresponding local space coord.
public static Vector3 ObjectToLocal(in Vector3 obj, in Matrix4x4 om)
Parameters
Returns
- Vector3
Local space coord (x,y,z).
OrthoPan(in Vector2, in Vector2, in Vector2, in Matrix4x4, in Matrix4x4, in Vector3, in Vector3, out Vector3, out Vector3)
Pan the view ( Orthogonal mode ) by the given screen translation coord generating new camera config.
public static void OrthoPan(in Vector2 from, in Vector2 to, in Vector2 size, in Matrix4x4 vm, in Matrix4x4 pm, in Vector3 cameraPos, in Vector3 cameraTarget, out Vector3 panCameraPos, out Vector3 panCameraTarget)
Parameters
fromVector2Screen pan from coord (x,y) [screen].
toVector2Screen pan "from" coord (x,y) [screen].
sizeVector2Screen size (x,y) [screen].
vmMatrix4x4View matrix [world].
pmMatrix4x4Projection matrix [eye].
cameraPosVector3Camera position (x,y,z) [world].
cameraTargetVector3Camera target (x,y,z) [world].
panCameraPosVector3Pan result new camera position (x,y,z) [world].
panCameraTargetVector3Pan result new camera target (x,y,z) [world].
OrthoZoom(float, float, out float)
Scale by given factor the given [eye] zoom ( Orthogonal mode ).
public static void OrthoZoom(float scale, float orthoZoom, out float scaledOrthoZoom)
Parameters
scalefloatZoom scale factor.
orthoZoomfloatEye space ortho zoom.
scaledOrthoZoomfloatComputed eye space ortho zoom.
OrthoZoomFit(IEnumerable<Vector3>, in Vector2, in Matrix4x4, in Matrix4x4, in Matrix4x4, float, float, float, Vector3, Vector3, Vector3, out float, out Vector3, out Vector3)
Fit current model view for orthographic projection
public static void OrthoZoomFit(IEnumerable<Vector3> pts, in Vector2 size, in Matrix4x4 mm, in Matrix4x4 vm, in Matrix4x4 pm, float orthoZoom, float near, float far, Vector3 cameraPos, Vector3 cameraTarget, Vector3 cameraUp, out float fitOrthoZoom, out Vector3 panCameraPos, out Vector3 panCameraTarget)
Parameters
ptsIEnumerable<Vector3>model points [local]
sizeVector2size [screen]
mmMatrix4x4mm [local]
vmMatrix4x4vm [world]
pmMatrix4x4pm [eye]
orthoZoomfloatorthoZoom [eye]
nearfloatnear [world]
farfloatfar [world]
cameraPosVector3cameraPos [world]
cameraTargetVector3cameraTarget [world]
cameraUpVector3cameraUp [world]
fitOrthoZoomfloatfitOrthoZoom [eye]
panCameraPosVector3panCameraPos [world]
panCameraTargetVector3panCameraTarget [world]
ParseVector3(string, int)
Depending on given pointCnt argument make an invariant parse:
- (pointCnt=1) p1x,p1y,p1z;...
- (pointCnt=2) p1x,p1y,p1z,p2x,p2y,p2z;...
- (pointCnt=3) p1x,p1y,p1z,p2x,p2y,p2z,p3x,p3y,p3z;...
public static IEnumerable<Vector3> ParseVector3(string vstr, int pointCnt = 1)
Parameters
Returns
PerspectiveCenter(IEnumerable<Vector3>, in Vector2, in Matrix4x4, in Matrix4x4, in Matrix4x4, in Vector3, in Vector3, out Vector3, out Vector3, out BBox)
Center the view ( Perspective mode ) by computing camera [world] position and target.
public static void PerspectiveCenter(IEnumerable<Vector3> pts, in Vector2 size, in Matrix4x4 mm, in Matrix4x4 vm, in Matrix4x4 pm, in Vector3 cameraPos, in Vector3 cameraTarget, out Vector3 panCameraPos, out Vector3 panCameraTarget, out BBox lBBox)
Parameters
ptsIEnumerable<Vector3>Local space point that represents entire model [local].
sizeVector2Screen size (x,y) [screen].
mmMatrix4x4Model matrix [local].
vmMatrix4x4View matrix [world].
pmMatrix4x4Projection matrix [eye].
cameraPosVector3Camera position (x,y,z) [world].
cameraTargetVector3Camera target (x,y,z) [world].
panCameraPosVector3Computed pan camera pos [world].
panCameraTargetVector3Computed pan camera target [world].
lBBoxBBoxComputed local space bbox [local].
PerspectivePan(in Vector3, in Vector2, in Vector2, in Vector2, in Matrix4x4, in Matrix4x4, in Matrix4x4, in Vector3, in Vector3, out Vector3, out Vector3)
Pan the view ( Perspective mode ) by the given screen translation coord generating new camera config.
public static void PerspectivePan(in Vector3 refPt, in Vector2 from, in Vector2 to, in Vector2 size, in Matrix4x4 mm, in Matrix4x4 vm, in Matrix4x4 pm, in Vector3 cameraPos, in Vector3 cameraTarget, out Vector3 panCameraPos, out Vector3 panCameraTarget)
Parameters
refPtVector3A reference point [local] inside model bbox ( generally BBox.Middle ) for relative coord calc.
fromVector2Screen pan from coord (x,y) [screen].
toVector2Screen pan "from" coord (x,y) [screen].
sizeVector2Screen pan "to" coord (x,y) [screen].
mmMatrix4x4Model matrix [local].
vmMatrix4x4View matrix [world].
pmMatrix4x4Projection matrix [eye].
cameraPosVector3Camera position (x,y,z) [world].
cameraTargetVector3Camera target (x,y,z) [world].
panCameraPosVector3Pan result new camera position (x,y,z) [world].
panCameraTargetVector3Pan result new camera target (x,y,z) [world].
PerspectiveZoom(float, BBox, in Matrix4x4, in Matrix4x4, in Vector3, in Vector3, out Vector3, out Vector3)
Zoom the view [eye] ( Perspective mode ) by the given scale factor.
public static void PerspectiveZoom(float scale, BBox bbox, in Matrix4x4 mm, in Matrix4x4 vm, in Vector3 cameraPos, in Vector3 cameraTarget, out Vector3 scaledCameraPos, out Vector3 scaledCameraTarget)
Parameters
scalefloatZoom scale factor.
bboxBBoxModel bbox [local].
mmMatrix4x4Model matrix [local].
vmMatrix4x4View matrix [world].
cameraPosVector3Camera position (x,y,z) [world].
cameraTargetVector3Camera target (x,y,z) [world].
scaledCameraPosVector3Computed camera position (x,y,z) [world].
scaledCameraTargetVector3Computed camera target (x,y,z) [world].
PerspectiveZoomFit(IEnumerable<Vector3>, in Vector2, in Matrix4x4, in Matrix4x4, in Matrix4x4, in Vector3, in Vector3, in Vector3, float, out Vector3, out Vector3, int, float)
Fit current model view for perspective projection
public static void PerspectiveZoomFit(IEnumerable<Vector3> pts, in Vector2 size, in Matrix4x4 mm, in Matrix4x4 vm, in Matrix4x4 pm, in Vector3 cameraPos, in Vector3 cameraTarget, in Vector3 cameraUp, float fovDeg, out Vector3 fitCameraPos, out Vector3 fitCameraTarget, int LOOP_CNT_MAX = 10, float FACTOR_TOL = 0.01)
Parameters
ptsIEnumerable<Vector3>model or bbox points [local]
sizeVector2size [screen]
mmMatrix4x4mm [local]
vmMatrix4x4vm [world]
pmMatrix4x4pm [eye]
cameraPosVector3cameraPos [world]
cameraTargetVector3cameraTarget [world]
cameraUpVector3cameraUp [world]
fovDegfloatfovDeg [world]
fitCameraPosVector3fitCameraPos [world]
fitCameraTargetVector3fitCameraTarget [world]
LOOP_CNT_MAXintnr of max loop to compute fit
FACTOR_TOLfloatbreak fit loop when factor equals 1 with given factor tolerance
PreventZFighting(BBox, in Matrix4x4, in Matrix4x4, in Vector3, out float, out float)
Compute best fitting near and far values based on local space bbox given.
public static void PreventZFighting(BBox bbox, in Matrix4x4 mm, in Matrix4x4 vm, in Vector3 cameraPos, out float near, out float far)
Parameters
bboxBBoxLocal space bbox of model for which compute best near, far [local].
mmMatrix4x4Model matrix [local].
vmMatrix4x4View matrix [world].
cameraPosVector3Camera position [world].
nearfloatComputed absolute position along [eye] z axis of the near clipping plane.
farfloatComputed absolute position along [eye] z axis of the far clipping plane.
RayCastLocal(in Vector2, in Vector2, in Matrix4x4, in Matrix4x4, in Matrix4x4, in Vector3, bool)
Create a raycast line [local] suitable to hit test of figure primitives.
public static Line RayCastLocal(in Vector2 screen, in Vector2 size, in Matrix4x4 mm, in Matrix4x4 vm, in Matrix4x4 pm, in Vector3 cp, bool perspective)
Parameters
screenVector2Screen coord (x,y) [screen].
sizeVector2Screen size (x,y) [screen].
mmMatrix4x4Model matrix [local].
vmMatrix4x4View matrix [world].
pmMatrix4x4Projection matrix [eye].
cpVector3Camera position [world].
perspectiveboolPerspective mode.
Returns
- Line
Raycast line [local].
RightHandXFromYZ(in Vector3, in Vector3)
Detect basex from given normalized basey and basez vectors using right-hand rule.
public static Vector3 RightHandXFromYZ(in Vector3 y, in Vector3 z)
Parameters
Returns
- Vector3
Basex versor.
ScreenToClip_virtual(in Vector2, in Vector2, float)
Converts given screen space coord to corresponding virtual in clip space coord (z=0, w=1).
public static Vector4 ScreenToClip_virtual(in Vector2 screen, in Vector2 size, float w = 1)
Parameters
screenVector2Screen coord (x,y).
sizeVector2Screen size (x,y).
wfloatValue of 4-th component to set in computed clip space coord ( Default: 1 ).
Returns
- Vector4
(virtual) Clip space coord (x,y,z,w).
ScreenToEye_virtual(in Vector2, in Vector2, in Matrix4x4, float)
Converts given screen space coord to corresponding virtual in eye space coord (z=0, w=1, eye_z=-1).
It makes use of the inverse of given projection matrix.
public static Vector3 ScreenToEye_virtual(in Vector2 screen, in Vector2 size, in Matrix4x4 pm, float eye_z = -1)
Parameters
screenVector2Screen coord (x,y).
sizeVector2Screen size (x,y).
pmMatrix4x4Projection matrix.
eye_zfloatValue of 3-th component to set in computed eye space coord ( Default: -1 ).
Returns
- Vector3
(virtual) Eye space coord (x,y,z).
ScreenToLocal_virtual(in Vector2, in Vector2, in Matrix4x4, in Matrix4x4, float, float)
Converts given screen space coord to corresponding virtual in local space coord (z=0, w=1, eye_z=-1).
It makes use of the inverse of given modelview matrix and projection matrix.
public static Vector3 ScreenToLocal_virtual(in Vector2 screen, in Vector2 size, in Matrix4x4 mvm, in Matrix4x4 pm, float eye_z = -1, float w = 1)
Parameters
screenVector2Screen coord (x,y).
sizeVector2Screen size (x,y).
mvmMatrix4x4Modelview matrix (model * view).
pmMatrix4x4Projection matrix.
eye_zfloatValue of 3-th component to set in computed eye space coord ( Default: -1 ).
wfloatValue of 4-th component to set in computed clip space coord ( Default: 1 ).
Returns
- Vector3
(virtual) Local space coord (x,y,z).
ScreenToNDC_virtual(in Vector2, in Vector2)
Converts given screen coord to virtual normalized device coord (z=0).
Actual YAxisOrientation will considered.
public static Vector3 ScreenToNDC_virtual(in Vector2 screen, in Vector2 size)
Parameters
Returns
- Vector3
(virtual) normalized device coord (x,y,z).
Serialize(in Matrix4x4)
Serialize to a string of 16 float space separated ( invariant ).
public static string Serialize(in Matrix4x4 m)
Parameters
Returns
SetupClosedXMLFonts()
Helper to overcome ClosedXML font issue when adjust columns contents of an xlsx document.
public static void SetupClosedXMLFonts()
SortByAdjacency(float, IList<Line>)
Sort given line list by adjacency.
public static List<Line> SortByAdjacency(float tol, IList<Line> lines)
Parameters
Returns
SortByAdjacency(float, IList<Line>, DebugVtxMgr?)
public static List<Line> SortByAdjacency(float tol, IList<Line> lines, DebugVtxMgr? debug)
Parameters
tolfloatlinesIList<Line>debugDebugVtxMgr
Returns
ToDxfFace3D(IGLTriangle)
Retrieve dxf face from given triangle.
public static Face3D ToDxfFace3D(this IGLTriangle tri)
Parameters
triIGLTriangleGl triangle.
Returns
- Face3D
Dxf face.
ToFigure(IEnumerable<GLLine>)
Create line figure from given line set.
public static GLLineFigure ToFigure(this IEnumerable<GLLine> lines)
Parameters
linesIEnumerable<GLLine>
Returns
ToFigure(IEnumerable<Line>)
Create line figure from given line set.
public static GLLineFigure ToFigure(this IEnumerable<Line> lines)
Parameters
linesIEnumerable<Line>
Returns
ToGLLines(IEnumerable<Vector3>, bool)
Enumerate given point set with gl lines.
public static IEnumerable<GLLine> ToGLLines(this IEnumerable<Vector3> pts, bool closed = false)
Parameters
ptsIEnumerable<Vector3>Points set.
closedboolIf true a line will added between last and first point.
Returns
WordlToEye(in Vector3, in Matrix4x4)
Converts given world space coord to the corresponding eye space coord.
public static Vector3 WordlToEye(in Vector3 world, in Matrix4x4 vm)
Parameters
Returns
- Vector3
Eye space coord (x,y,z).
WorldToLocal(in Vector3, in Matrix4x4)
Converts given world space coord to the corresponding local space coord.
Makes use of the inverse of the given model matrix.
public static Vector3 WorldToLocal(in Vector3 world, in Matrix4x4 mm)
Parameters
Returns
- Vector3
Local space coord (x,y,z).