Table of Contents

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 Vector3

Normalized normal vector to which based the AAA construction.

x Vector3

Computed xbase..

y Vector3

Computed ybase.

z Vector3

Computed zbase.

Remarks

AverageColor(IGLTriangle)

Average color of triangles vertexes color.

public static Color AverageColor(this IGLTriangle tri)

Parameters

tri IGLTriangle

Returns

Color

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 float

Camera rotation screen X angle (rad)..

sAngleYRad float

Camera rotation screen Y angle (rad).

wCameraPos Vector3

Actual camera position [world].

wCameraTarget Vector3

Actual camera target [world].

wCameraUp Vector3

Actual camera up [world].

wRotatedCameraTarget Vector3

Rotated camera target [world].

wRotatedCameraUp Vector3

Rotated 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 float

Tilt angle (rad) [view].

cu Vector3

Camera up vector (x,y,z) [view].

cuTilted Vector3

Tilted 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

clip Vector4

Clip space coord (x,y,z,w).

pm Matrix4x4

Projection matrix.

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 Vector4

Clip space coord (x,y,z,w).

mvm Matrix4x4

Modelview matrix (model * view).

pm Matrix4x4

Projection 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 Vector4

Clip 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

clip Vector4

Clip space coord (x,y,z,w).

size Vector2

Screen size (x,y).

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 Matrix4x4

Model matrix [local].

vm Matrix4x4

View matrix [world].

eMin Vector2

Computed minimum eye space coordinate (x,y,z) [eye],

eMax Vector2

Computed 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 Vector2

Screen size (x,y) [screen].

mm Matrix4x4

Model matrix [local].

vm Matrix4x4

View matrix [world].

pm Matrix4x4

Projection matrix [eye].

sMin Vector2

Computed minimum screen space coordinate (x,y) [screen].

sMax Vector2

Computed maximum screen space coordinate (x,y) [screen].

lBBox BBox

If 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 Vector3

Scale factor (x,y).

rotation Quaternion

Rotation quaternion (x,y,z,w).

translation Vector3

Translation (x,y,z).

mm Matrix4x4

Model 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 Vector2

screen size (x,y) [screen].

eOrthoZoom float

[eye] zoom factor about screen size used as a reference.

near float

Absolute position along [eye] z axis of the near clipping plane.

far float

Absolute position along [eye] z axis of the far clipping plane.

vm Matrix4x4
pm 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 float

Angle of view [deg].

ar float

Projection screen aspection ratio (x/y).

near float

Absolute position along [eye] z axis of the near clipping plane.

far float

Absolute position along [eye] z axis of the far clipping plane.

pm Matrix4x4

Projection 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 Vector3

Camera position (x,y,z) [world].

cameraTarget Vector3

Camera target (x,y,z) [world].

cameraUp Vector3

Camera up (x,y,z) [world].

vm Matrix4x4

View 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 IGLTriangle

Triangle 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 string

Serialized Matrix4x4 text input.

Returns

Matrix4x4
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

eye Vector3

Eye coord (x,y,z).

pm Matrix4x4

Projection matrix.

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

eye Vector3

Eye space (x,y,z) coord.

mvm Matrix4x4

Modelview matrix (model * view).

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

eye Vector3

Eye space coord (x,y,z).

vm Matrix4x4

View matrix.

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 float

Offset in range [0,1] of the color to choose in given hue range.

hueFrom int

Hue of color range from.

hueTo int

Hue of color range to.

decreaseHue bool

If 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 float

Comparision length tolerance.

lines IEnumerable<Line>

Input lines.

Returns

List<List<Line>>

Line groups.

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

local Vector3

Local space coord (x,y,z).

mvm Matrix4x4

Modelview matrix ( model * view ).

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

local Vector3

Local space coord (x,y,z).

om Matrix4x4

Object matrix.

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 Vector3

Local space coord (x,y,z).

size Vector2

Sceen size (x,y).

mvpm Matrix4x4

ModelViewProjection 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

local Vector3

Local space coord (x,y,z).

mm Matrix4x4

Model matrix.

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 Vector3

Camera position [world].

cameraTarget Vector3

Camera target [world].

cameraUp Vector3

Camera up versor [world].

Returns

Matrix4x4

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

origin Vector3

Origin to set to the created world matrix.

N Vector3

Normalized normal vector.

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

origin Vector3

World origin.

baseX Vector3

World basex.

baseY Vector3

World basey.

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 Vector3

World origin.

vx Vector3

Reference vector to compute basex.

vy Vector3

Reference vector to compute basey.

makeOrthonormalization bool

If 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 Vector3

World origin.

baseX Vector3

World basex.

baseY Vector3

World basey.

baseZ Vector3

World 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

List<GLFigureBase>

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 Vector3

Camera position [world].

cameraTarget Vector3

Camera target [world].

cameraUp Vector3

Camera up [world].

near float

Near plane [world].

far float

Far plane [world].

fov float

Field of view (rad).

mm Matrix4x4

Model 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 GLContext

Gl context ( used to access GLFontCharManager ).

glText GLText

Gl 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 GLModel

Gl model ( used to access GLFontCharManager ).

glText GLText

Gl 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

ox float

World x origin.

oy float

World y origin.

oz float

World z origin.

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 float

Eye space x angle rotation (rad).

angleYRad float

Eye space y angle rotation (rad).

rot_center Vector3

Local space (x,y,z) rotation center [local].

mm Matrix4x4

Model matrix [local].

vm Matrix4x4

View matrix [world].

mmRotated Matrix4x4

Rotated 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 float

Value 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

ndc Vector3

Normalized device coord (x,y,z).

size Vector2

Screen size (x,y).

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

obj Vector3

Object space coord (x,y,z).

om Matrix4x4

Object matrix.

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 Vector2

Screen pan from coord (x,y) [screen].

to Vector2

Screen pan "from" coord (x,y) [screen].

size Vector2

Screen size (x,y) [screen].

vm Matrix4x4

View matrix [world].

pm Matrix4x4

Projection matrix [eye].

cameraPos Vector3

Camera position (x,y,z) [world].

cameraTarget Vector3

Camera target (x,y,z) [world].

panCameraPos Vector3

Pan result new camera position (x,y,z) [world].

panCameraTarget Vector3

Pan 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 float

Zoom scale factor.

orthoZoom float

Eye space ortho zoom.

scaledOrthoZoom float

Computed 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 Vector2

size [screen]

mm Matrix4x4

mm [local]

vm Matrix4x4

vm [world]

pm Matrix4x4

pm [eye]

orthoZoom float

orthoZoom [eye]

near float

near [world]

far float

far [world]

cameraPos Vector3

cameraPos [world]

cameraTarget Vector3

cameraTarget [world]

cameraUp Vector3

cameraUp [world]

fitOrthoZoom float

fitOrthoZoom [eye]

panCameraPos Vector3

panCameraPos [world]

panCameraTarget Vector3

panCameraTarget [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

vstr string
pointCnt int

Returns

IEnumerable<Vector3>

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 Vector2

Screen size (x,y) [screen].

mm Matrix4x4

Model matrix [local].

vm Matrix4x4

View matrix [world].

pm Matrix4x4

Projection matrix [eye].

cameraPos Vector3

Camera position (x,y,z) [world].

cameraTarget Vector3

Camera target (x,y,z) [world].

panCameraPos Vector3

Computed pan camera pos [world].

panCameraTarget Vector3

Computed pan camera target [world].

lBBox BBox

Computed 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 Vector3

A reference point [local] inside model bbox ( generally BBox.Middle ) for relative coord calc.

from Vector2

Screen pan from coord (x,y) [screen].

to Vector2

Screen pan "from" coord (x,y) [screen].

size Vector2

Screen pan "to" coord (x,y) [screen].

mm Matrix4x4

Model matrix [local].

vm Matrix4x4

View matrix [world].

pm Matrix4x4

Projection matrix [eye].

cameraPos Vector3

Camera position (x,y,z) [world].

cameraTarget Vector3

Camera target (x,y,z) [world].

panCameraPos Vector3

Pan result new camera position (x,y,z) [world].

panCameraTarget Vector3

Pan 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 float

Zoom scale factor.

bbox BBox

Model bbox [local].

mm Matrix4x4

Model matrix [local].

vm Matrix4x4

View matrix [world].

cameraPos Vector3

Camera position (x,y,z) [world].

cameraTarget Vector3

Camera target (x,y,z) [world].

scaledCameraPos Vector3

Computed camera position (x,y,z) [world].

scaledCameraTarget Vector3

Computed 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 Vector2

size [screen]

mm Matrix4x4

mm [local]

vm Matrix4x4

vm [world]

pm Matrix4x4

pm [eye]

cameraPos Vector3

cameraPos [world]

cameraTarget Vector3

cameraTarget [world]

cameraUp Vector3

cameraUp [world]

fovDeg float

fovDeg [world]

fitCameraPos Vector3

fitCameraPos [world]

fitCameraTarget Vector3

fitCameraTarget [world]

LOOP_CNT_MAX int

nr of max loop to compute fit

FACTOR_TOL float

break 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 BBox

Local space bbox of model for which compute best near, far [local].

mm Matrix4x4

Model matrix [local].

vm Matrix4x4

View matrix [world].

cameraPos Vector3

Camera position [world].

near float

Computed absolute position along [eye] z axis of the near clipping plane.

far float

Computed 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 Vector2

Screen coord (x,y) [screen].

size Vector2

Screen size (x,y) [screen].

mm Matrix4x4

Model matrix [local].

vm Matrix4x4

View matrix [world].

pm Matrix4x4

Projection matrix [eye].

cp Vector3

Camera position [world].

perspective bool

Perspective 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

y Vector3

Basey versor.

z Vector3

Basez versor.

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 Vector2

Screen coord (x,y).

size Vector2

Screen size (x,y).

w float

Value 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 Vector2

Screen coord (x,y).

size Vector2

Screen size (x,y).

pm Matrix4x4

Projection matrix.

eye_z float

Value 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 Vector2

Screen coord (x,y).

size Vector2

Screen size (x,y).

mvm Matrix4x4

Modelview matrix (model * view).

pm Matrix4x4

Projection matrix.

eye_z float

Value of 3-th component to set in computed eye space coord ( Default: -1 ).

w float

Value 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

screen Vector2

(x,y) screen coord

size Vector2

(x,y) screen size

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

m Matrix4x4

Returns

string

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

tol float

Comparision length tolerance.

lines IList<Line>

Input lines.

Returns

List<Line>

List of lines sorted by their adjacency.

SortByAdjacency(float, IList<Line>, DebugVtxMgr?)

public static List<Line> SortByAdjacency(float tol, IList<Line> lines, DebugVtxMgr? debug)

Parameters

tol float
lines IList<Line>
debug DebugVtxMgr

Returns

List<Line>

ToDxfFace3D(IGLTriangle)

Retrieve dxf face from given triangle.

public static Face3D ToDxfFace3D(this IGLTriangle tri)

Parameters

tri IGLTriangle

Gl 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

GLLineFigure

ToFigure(IEnumerable<Line>)

Create line figure from given line set.

public static GLLineFigure ToFigure(this IEnumerable<Line> lines)

Parameters

lines IEnumerable<Line>

Returns

GLLineFigure

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 bool

If true a line will added between last and first point.

Returns

IEnumerable<GLLine>

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

world Vector3

World coord (x,y,z).

vm Matrix4x4

View matrix.

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

world Vector3

World space coord (x,y,z).

mm Matrix4x4

Model matrix.

Returns

Vector3

Local space coord (x,y,z).