Click or drag to resize
AB4D logo

DXMeshGeometry3DSortTrianglesByCameraDistance Method

SortTrianglesByCameraDistance method sorts the triangle indices so that the triangles are sorted by camera distance - triangles that are farther away are rendered first. After sorting indices, the Update(Boolean) method needs to be called to update the DirectX buffer. When using this method it is highly recommended to set CreateDynamicIndexBuffer to true. See remarks for more info.

Namespace: Ab3d.DirectX.Models
Assembly: Ab3d.DXEngine.Wpf (in Ab3d.DXEngine.Wpf.dll) Version: 7.0.8865.1045
Syntax
C#
public bool SortTrianglesByCameraDistance(
	Vector3 cameraPosition,
	Matrix meshWorldTransformMatrix,
	bool transformCamera,
	bool updateDirectXBuffer = true
)

Parameters

cameraPosition  Vector3
position of the camera
meshWorldTransformMatrix  Matrix
world transformation matrix
transformCamera  Boolean
when true, then the camera's position is transformed by inverted world matrix (recommended when object's world transform is changing); when false the original camera position is used but all the positions are transformed by the world transform (recommended when the object's world transform is not changing)
updateDirectXBuffer  Boolean  (Optional)
when true (by default) then this method also calls Update(Boolean) method to update the DirectX index buffer

Return Value

Boolean
true if triangle indices array was changed
Remarks

SortTrianglesByCameraDistance method sorts the triangle indices so that the triangles are sorted by camera distance - triangles that are farther away are rendered first.

When the updateDirectXBuffer parameter is set to true (by default) and when the sort order was changed, then the Update(Boolean) method is called to update the DirectX buffer.

When using this method it is highly recommended to set CreateDynamicIndexBuffer to true.

When the objects' world transformation is usually changed, then it is recommended to call this method with transformCamera parameter set to true. This transforms the camera's position by inverted world matrix and does not require to transform all positions. When objects' world transformation is not changed, then it is recommended to set transformCamera to false. This transforms all positions by world transform once and does not require to calculate the inverted world matrix.

See Also