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
n
Vector3Normalized normal vector to which based the AAA construction.
x
Vector3Computed xbase..
y
Vector3Computed ybase.
z
Vector3Computed 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
tri
IGLTriangle
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
sAngleXRad
floatCamera rotation screen X angle (rad)..
sAngleYRad
floatCamera rotation screen Y angle (rad).
wCameraPos
Vector3Actual camera position [world].
wCameraTarget
Vector3Actual camera target [world].
wCameraUp
Vector3Actual camera up [world].
wRotatedCameraTarget
Vector3Rotated camera target [world].
wRotatedCameraUp
Vector3Rotated 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
angleRad
floatTilt angle (rad) [view].
cu
Vector3Camera up vector (x,y,z) [view].
cuTilted
Vector3Tilted 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
clip
Vector4Clip space coord (x,y,z,w).
mvm
Matrix4x4Modelview matrix (model * view).
pm
Matrix4x4Projection 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
clip
Vector4Clip 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
lPts
IEnumerable<Vector3>Local space coordinates (x,y,z) [local] to include in evaluation of th eye space bbox.
mm
Matrix4x4Model matrix [local].
vm
Matrix4x4View matrix [world].
eMin
Vector2Computed minimum eye space coordinate (x,y,z) [eye],
eMax
Vector2Computed 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
lPts
IEnumerable<Vector3>Local space coordinates (x,y,z) [local] to include in evaluation of screen space bbox.
size
Vector2Screen size (x,y) [screen].
mm
Matrix4x4Model matrix [local].
vm
Matrix4x4View matrix [world].
pm
Matrix4x4Projection matrix [eye].
sMin
Vector2Computed minimum screen space coordinate (x,y) [screen].
sMax
Vector2Computed maximum screen space coordinate (x,y) [screen].
lBBox
BBoxIf 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
scale
Vector3Scale factor (x,y).
rotation
QuaternionRotation quaternion (x,y,z,w).
translation
Vector3Translation (x,y,z).
mm
Matrix4x4Model 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
size
Vector2screen size (x,y) [screen].
eOrthoZoom
float[eye] zoom factor about screen size used as a reference.
near
floatAbsolute position along [eye] z axis of the near clipping plane.
far
floatAbsolute position along [eye] z axis of the far clipping plane.
vm
Matrix4x4pm
Matrix4x4
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
fovDeg
floatAngle of view [deg].
ar
floatProjection screen aspection ratio (x/y).
near
floatAbsolute position along [eye] z axis of the near clipping plane.
far
floatAbsolute position along [eye] z axis of the far clipping plane.
pm
Matrix4x4Projection 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
cameraPos
Vector3Camera position (x,y,z) [world].
cameraTarget
Vector3Camera target (x,y,z) [world].
cameraUp
Vector3Camera up (x,y,z) [world].
vm
Matrix4x4View 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
tri
IGLTriangleTriangle 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
txt
stringSerialized 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
offset
floatOffset in range [0,1] of the color to choose in given hue range.
hueFrom
intHue of color range from.
hueTo
intHue of color range to.
decreaseHue
boolIf 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
tol
floatComparision length tolerance.
lines
IEnumerable<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
local
Vector3Local space coord (x,y,z).
size
Vector2Sceen size (x,y).
mvpm
Matrix4x4ModelViewProjection 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
cameraPos
Vector3Camera position [world].
cameraTarget
Vector3Camera target [world].
cameraUp
Vector3Camera 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
origin
Vector3World origin.
vx
Vector3Reference vector to compute basex.
vy
Vector3Reference vector to compute basey.
makeOrthonormalization
boolIf 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
origin
Vector3World origin.
baseX
Vector3World basex.
baseY
Vector3World basey.
baseZ
Vector3World 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
glControl
GLControl
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
cameraPos
Vector3Camera position [world].
cameraTarget
Vector3Camera target [world].
cameraUp
Vector3Camera up [world].
near
floatNear plane [world].
far
floatFar plane [world].
fov
floatField of view (rad).
mm
Matrix4x4Model 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
origin
Vector3?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
glContext
GLContextGl context ( used to access GLFontCharManager ).
glText
GLTextGl 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
glModel
GLModelGl model ( used to access GLFontCharManager ).
glText
GLTextGl 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
origin
Vector3?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
angleXRad
floatEye space x angle rotation (rad).
angleYRad
floatEye space y angle rotation (rad).
rot_center
Vector3Local space (x,y,z) rotation center [local].
mm
Matrix4x4Model matrix [local].
vm
Matrix4x4View matrix [world].
mmRotated
Matrix4x4Rotated 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
ndc
Vector3(x,y,z) ndc coord
w
floatValue 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
from
Vector2Screen pan from coord (x,y) [screen].
to
Vector2Screen pan "from" coord (x,y) [screen].
size
Vector2Screen size (x,y) [screen].
vm
Matrix4x4View matrix [world].
pm
Matrix4x4Projection matrix [eye].
cameraPos
Vector3Camera position (x,y,z) [world].
cameraTarget
Vector3Camera target (x,y,z) [world].
panCameraPos
Vector3Pan result new camera position (x,y,z) [world].
panCameraTarget
Vector3Pan 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
scale
floatZoom scale factor.
orthoZoom
floatEye space ortho zoom.
scaledOrthoZoom
floatComputed 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
pts
IEnumerable<Vector3>model points [local]
size
Vector2size [screen]
mm
Matrix4x4mm [local]
vm
Matrix4x4vm [world]
pm
Matrix4x4pm [eye]
orthoZoom
floatorthoZoom [eye]
near
floatnear [world]
far
floatfar [world]
cameraPos
Vector3cameraPos [world]
cameraTarget
Vector3cameraTarget [world]
cameraUp
Vector3cameraUp [world]
fitOrthoZoom
floatfitOrthoZoom [eye]
panCameraPos
Vector3panCameraPos [world]
panCameraTarget
Vector3panCameraTarget [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
pts
IEnumerable<Vector3>Local space point that represents entire model [local].
size
Vector2Screen size (x,y) [screen].
mm
Matrix4x4Model matrix [local].
vm
Matrix4x4View matrix [world].
pm
Matrix4x4Projection matrix [eye].
cameraPos
Vector3Camera position (x,y,z) [world].
cameraTarget
Vector3Camera target (x,y,z) [world].
panCameraPos
Vector3Computed pan camera pos [world].
panCameraTarget
Vector3Computed pan camera target [world].
lBBox
BBoxComputed 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
refPt
Vector3A reference point [local] inside model bbox ( generally BBox.Middle ) for relative coord calc.
from
Vector2Screen pan from coord (x,y) [screen].
to
Vector2Screen pan "from" coord (x,y) [screen].
size
Vector2Screen pan "to" coord (x,y) [screen].
mm
Matrix4x4Model matrix [local].
vm
Matrix4x4View matrix [world].
pm
Matrix4x4Projection matrix [eye].
cameraPos
Vector3Camera position (x,y,z) [world].
cameraTarget
Vector3Camera target (x,y,z) [world].
panCameraPos
Vector3Pan result new camera position (x,y,z) [world].
panCameraTarget
Vector3Pan 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
scale
floatZoom scale factor.
bbox
BBoxModel bbox [local].
mm
Matrix4x4Model matrix [local].
vm
Matrix4x4View matrix [world].
cameraPos
Vector3Camera position (x,y,z) [world].
cameraTarget
Vector3Camera target (x,y,z) [world].
scaledCameraPos
Vector3Computed camera position (x,y,z) [world].
scaledCameraTarget
Vector3Computed 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
pts
IEnumerable<Vector3>model or bbox points [local]
size
Vector2size [screen]
mm
Matrix4x4mm [local]
vm
Matrix4x4vm [world]
pm
Matrix4x4pm [eye]
cameraPos
Vector3cameraPos [world]
cameraTarget
Vector3cameraTarget [world]
cameraUp
Vector3cameraUp [world]
fovDeg
floatfovDeg [world]
fitCameraPos
Vector3fitCameraPos [world]
fitCameraTarget
Vector3fitCameraTarget [world]
LOOP_CNT_MAX
intnr of max loop to compute fit
FACTOR_TOL
floatbreak 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
bbox
BBoxLocal space bbox of model for which compute best near, far [local].
mm
Matrix4x4Model matrix [local].
vm
Matrix4x4View matrix [world].
cameraPos
Vector3Camera position [world].
near
floatComputed absolute position along [eye] z axis of the near clipping plane.
far
floatComputed 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
screen
Vector2Screen coord (x,y) [screen].
size
Vector2Screen size (x,y) [screen].
mm
Matrix4x4Model matrix [local].
vm
Matrix4x4View matrix [world].
pm
Matrix4x4Projection matrix [eye].
cp
Vector3Camera position [world].
perspective
boolPerspective 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
screen
Vector2Screen coord (x,y).
size
Vector2Screen size (x,y).
w
floatValue 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
screen
Vector2Screen coord (x,y).
size
Vector2Screen size (x,y).
pm
Matrix4x4Projection matrix.
eye_z
floatValue 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
screen
Vector2Screen coord (x,y).
size
Vector2Screen size (x,y).
mvm
Matrix4x4Modelview matrix (model * view).
pm
Matrix4x4Projection matrix.
eye_z
floatValue of 3-th component to set in computed eye space coord ( Default: -1 ).
w
floatValue 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
tol
floatlines
IList<Line>debug
DebugVtxMgr
Returns
ToDxfFace3D(IGLTriangle)
Retrieve dxf face from given triangle.
public static Face3D ToDxfFace3D(this IGLTriangle tri)
Parameters
tri
IGLTriangleGl triangle.
Returns
- Face3D
Dxf face.
ToFigure(IEnumerable<GLLine>)
Create line figure from given line set.
public static GLLineFigure ToFigure(this IEnumerable<GLLine> lines)
Parameters
lines
IEnumerable<GLLine>
Returns
ToFigure(IEnumerable<Line>)
Create line figure from given line set.
public static GLLineFigure ToFigure(this IEnumerable<Line> lines)
Parameters
lines
IEnumerable<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
pts
IEnumerable<Vector3>Points set.
closed
boolIf 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).