reckfellENGINE

Basis

Three axes of a linear 3D transform without translation.

On this page
struct BasisReckfellSharpInherits ValueType

Basis stores rotation, scale and possible shear. Basis.Identity is the identity basis; a zero struct is not a substitute. Uniform scale s has determinant s³; s = 2 gives 8. A zero determinant means no inverse exists.

Pure orientation needs orthonormal axes or a unit Quaternion. Orthonormalized changes the original scale/skew. Transform a normal under nonuniform scale with Inverse().Transposed(), then normalize; ordinary Basis multiplication need not preserve surface perpendicularity.

Practical guide.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors4

Basis4 overloads
# Basis · 1/4
C#
public Basis(Quaternion quaternion);

Constructs a Basis from 3 axis vectors. These are the columns of the basis matrix.

Parameters
NameTypeDefault
quaternionQuaternion—
quaternion

The quaternion to create the basis from.

# Basis · 2/4
C#
public Basis(Vector3 column0, Vector3 column1, Vector3 column2);

Constructs a Basis from 3 axis vectors. These are the columns of the basis matrix.

Parameters
NameTypeDefault
column0Vector3—
column1Vector3—
column2Vector3—
column0

The X vector, or Column0.

column1

The Y vector, or Column1.

column2

The Z vector, or Column2.

# Basis · 3/4
C#
public Basis(Vector3 axis, float angle);

Constructs a Basis from 3 axis vectors. These are the columns of the basis matrix.

Parameters
NameTypeDefault
axisVector3—
anglefloat—
axis

The axis to rotate around. Must be normalized.

angle

The angle to rotate, in radians.

# Basis · 4/4
C#
public Basis(float xx, float yx, float zx, float xy, float yy, float zy, float xz, float yz, float zz);

Constructs a Basis from 3 axis vectors. These are the columns of the basis matrix.

Parameters
NameTypeDefault
xxfloat—
yxfloat—
zxfloat—
xyfloat—
yyfloat—
zyfloat—
xzfloat—
yzfloat—
zzfloat—
xx

The X component of the X column vector, accessed via b.X.X or [0][0].

yx

The X component of the Y column vector, accessed via b.Y.X or [1][0].

zx

The X component of the Z column vector, accessed via b.Z.X or [2][0].

xy

The Y component of the X column vector, accessed via b.X.Y or [0][1].

yy

The Y component of the Y column vector, accessed via b.Y.Y or [1][1].

zy

The Y component of the Z column vector, accessed via b.Y.Y or [2][1].

xz

The Z component of the X column vector, accessed via b.X.Y or [0][2].

yz

The Z component of the Y column vector, accessed via b.Y.Y or [1][2].

zz

The Z component of the Z column vector, accessed via b.Y.Y or [2][2].

Properties13

Column0Property
# Column0
C#
public Vector3 Column0 { get; set; }

Column 0 of the basis matrix (the X vector).

Column1Property
# Column1
C#
public Vector3 Column1 { get; set; }

Column 1 of the basis matrix (the Y vector).

Column2Property
# Column2
C#
public Vector3 Column2 { get; set; }

Column 2 of the basis matrix (the Z vector).

FlipXProperty
# FlipX
C#
public static Basis FlipX { get; }

When any basis is multiplied by Basis.FlipX, it negates all components of the Basis.X axis (the X column). When Basis.FlipX is multiplied by any basis, it negates the Vector3.X component of all axes (the X row).

FlipYProperty
# FlipY
C#
public static Basis FlipY { get; }

When any basis is multiplied by Basis.FlipY, it negates all components of the Basis.Y axis (the Y column). When Basis.FlipY is multiplied by any basis, it negates the Vector3.Y component of all axes (the Y row).

FlipZProperty
# FlipZ
C#
public static Basis FlipZ { get; }

When any basis is multiplied by Basis.FlipZ, it negates all components of the Basis.Z axis (the Z column). When Basis.FlipZ is multiplied by any basis, it negates the Vector3.Z component of all axes (the Z row).

IdentityProperty
# Identity
C#
public static Basis Identity { get; }

The identity Basis. This is an orthonormal basis with no rotation, no shear, and a scale of Vector3.One. This also means that:

If a Vector3 or another Basis is transformed (multiplied) by this constant, no transformation occurs. Note: In C#, this constant is equivalent to creating a [constructor Basis] without any arguments. It can be used to make your code clearer, and for consistency with C#.

Item2 overloads
# Item · 1/2
C#
public Vector3 this[int column] { get; set; }

Access whole columns in the form of Vector3.

# Item · 2/2
C#
public float this[int column, int row] { get; set; }

Access matrix elements in column-major order.

ScaleProperty
# Scale
C#
public Vector3 Scale { get; }

Assuming that the matrix is the combination of a rotation and scaling, return the absolute value of scaling factors along each axis.

XProperty
# X
C#
public Vector3 X { get; set; }

The basis's X axis, and the column 0 of the matrix. On the identity basis, this vector points right (Vector3.Right).

YProperty
# Y
C#
public Vector3 Y { get; set; }

The basis's Y axis, and the column 1 of the matrix. On the identity basis, this vector points up (Vector3.Up).

ZProperty
# Z
C#
public Vector3 Z { get; set; }

The basis's Z axis, and the column 2 of the matrix. On the identity basis, this vector points back (Vector3.Back).

Methods29

Determinantfloat
# Determinant
C#
public float Determinant();

Determinant of the 3×3 matrix. Uniform scale s gives s³: scale 2 yields 8. Zero means noninvertible; a negative sign reverses basis orientation.

Returns float

The determinant of the basis matrix.

Equals2 overloads
# Equals · 1/2
C#
public bool Equals(Basis other);

Returns true if the basis matrices are exactly equal. Note: Due to floating-point precision errors, consider using Basis.IsEqualApprox instead, which is more reliable.

Parameters
NameTypeDefault
otherBasis—
other

The other basis.

Returns bool

Whether or not the basis matrices are exactly equal.

# Equals · 2/2
C#
public override bool Equals(object? obj);

Returns true if the Basis is exactly equal to the given object (obj). Note: Due to floating-point precision errors, consider using Basis.IsEqualApprox instead, which is more reliable.

Parameters
NameTypeDefault
objobject—
obj

The object to compare with.

Returns bool

Whether or not the basis matrix and the object are exactly equal.

FromEulerBasis
# FromEuler
C#
public static Basis FromEuler(Vector3 euler, EulerOrder order = EulerOrder.Yxz);

Constructs a new Basis that only represents rotation from the given Vector3 of Euler angles, in radians.

C#
// Creates a Basis whose z axis points down.
var myBasis = Basis.FromEuler(new Vector3(Mathf.Tau / 4.0f, 0.0f, 0.0f));

ReckfellApi.Print(myBasis.Z); // Prints (0, -1, 0)

The order of each consecutive rotation can be changed with order (see EulerOrder constants). In Reckfell, Euler angles always use intrinsic order. By default, the intrinsic YXZ convention is used (EULER_ORDER_YXZ): the basis rotates first around the local Y axis (yaw), then local X (pitch), and lastly local Z (roll). When using the opposite method Basis.GetEuler to decompose a rotation, this order is reversed.

Parameters
NameTypeDefault
eulerVector3—
orderEulerOrderEulerOrder.Yxz
euler

The Euler angles to use.

order

The order to compose the Euler angles.

Returns Basis
FromScaleBasis
# FromScale
C#
public static Basis FromScale(Vector3 scale);

Constructs a new Basis that only represents scale, with no rotation or shear, from the given scale vector.

C#
var myBasis = Basis.FromScale(new Vector3(2.0f, 4.0f, 8.0f));

ReckfellApi.Print(myBasis.X); // Prints (2, 0, 0)
ReckfellApi.Print(myBasis.Y); // Prints (0, 4, 0)
ReckfellApi.Print(myBasis.Z); // Prints (0, 0, 8)

Note: In linear algebra, the matrix of this basis is also known as a diagonal matrix.

Parameters
NameTypeDefault
scaleVector3—
scale

The scale Vector3.

Returns Basis

A pure scale Basis matrix.

GetEulerVector3
# GetEuler
C#
public Vector3 GetEuler(EulerOrder order = EulerOrder.Yxz);

Returns this basis's rotation as a Vector3 of Euler angles, in radians. For the returned value:

  • The Vector3.X contains the angle around the Basis.X axis (pitch);
  • The Vector3.Y contains the angle around the Basis.Y axis (yaw);
  • The Vector3.Z contains the angle around the Basis.Z axis (roll). The order of each consecutive rotation can be changed with order (see EulerOrder constants). In Reckfell, Euler angles always use intrinsic order. By default, the intrinsic YXZ convention is used (EULER_ORDER_YXZ): since we are decomposing, local Z (roll) is calculated first, then local X (pitch), and lastly local Y (yaw). When using the opposite method Basis.FromEuler to compose a rotation, this order is reversed. Note: For this method to return correctly, the basis needs to be orthonormal (see Basis.Orthonormalized). Note: Euler angles are much more intuitive but are not suitable for 3D math. Because of this, consider using the Basis.GetRotationQuaternion method instead, which returns a Quaternion. Note: In the Inspector dock, a basis's rotation is often displayed in Euler angles (in degrees), as is the case with the Entity3D.Rotation property.
Parameters
NameTypeDefault
orderEulerOrderEulerOrder.Yxz
order

The Euler order to use. By default, use YXZ order (most common).

Returns Vector3

A Vector3 representing the basis rotation in Euler angles.

GetHashCodeint
# GetHashCode
C#
public override int GetHashCode();

Serves as the hash function for Basis.

Returns int

A hash code for this basis.

GetRotationQuaternionQuaternion
# GetRotationQuaternion
C#
public Quaternion GetRotationQuaternion();

Returns this basis's rotation as a Quaternion. Note: Quaternions are much more suitable for 3D math but are less intuitive. For user interfaces, consider using the Basis.GetEuler method, which returns Euler angles.

Returns Quaternion

The basis rotation.

InverseBasis
# Inverse
C#
public Basis Inverse();

Returns the inverse Basis. An exactly zero determinant throws InvalidOperationException; near-degenerate inputs can greatly amplify numerical error.

Returns Basis

The inverse value. An exactly zero determinant throws InvalidOperationException instead of returning a result.

IsEqualApproxbool
# IsEqualApprox
C#
public bool IsEqualApprox(Basis other);

Returns true if this basis and b are approximately equal, by calling @GlobalScope.is_equal_approx on all vector components.

Parameters
NameTypeDefault
otherBasis—
other

The other basis to compare.

Returns bool

Whether or not the bases are approximately equal.

IsFinitebool
# IsFinite
C#
public bool IsFinite();

Returns true if this basis is finite, by calling @GlobalScope.is_finite on all vector components.

Returns bool

Whether this vector is finite or not.

LookingAt2 overloads
# LookingAt · 1/2
C#
public static Basis LookingAt(Vector3 target, Vector3 up);

Creates a new Basis with a rotation such that the forward axis (-Z) points towards the target position. By default, the -Z axis (camera forward) is treated as forward (implies +X is right). If use_model_front is true, the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the target position. The up axis (+Y) points as close to the up vector as possible while staying perpendicular to the forward axis. The returned basis is orthonormalized (see Basis.Orthonormalized). The target and the up cannot be Vector3.Zero, and shouldn't be colinear to avoid unintended rotation around local Z axis.

Parameters
NameTypeDefault
targetVector3—
upVector3—
Returns Basis
# LookingAt · 2/2
C#
public static Basis LookingAt(Vector3 target, Vector3? up = default, bool useModelFront = false);

Creates a new Basis with a rotation such that the forward axis (-Z) points towards the target position. By default, the -Z axis (camera forward) is treated as forward (implies +X is right). If use_model_front is true, the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the target position. The up axis (+Y) points as close to the up vector as possible while staying perpendicular to the forward axis. The returned basis is orthonormalized (see Basis.Orthonormalized). The target and the up cannot be Vector3.Zero, and shouldn't be colinear to avoid unintended rotation around local Z axis.

Parameters
NameTypeDefault
targetVector3—
upVector3?default
useModelFrontboolfalse
target

The position to look at.

up

The relative up direction.

useModelFront

If true, then the model is oriented in reverse, towards the model front axis (+Z, Vector3.ModelFront), which is more useful for orienting 3D models.

Returns Basis

The resulting basis matrix.

OrthonormalizedBasis
# Orthonormalized
C#
public Basis Orthonormalized();

Returns the orthonormalized version of this basis. An orthonormal basis is both orthogonal (the axes are perpendicular to each other) and normalized (the axes have a length of 1.0), which also means it can only represent a rotation. It is often useful to call this method to avoid rounding errors on a rotating basis:

C#
// Rotate this Entity3D every frame.
public override void _Process(double delta)
{
    Basis = Basis.Rotated(Vector3.Up, Mathf.Tau * (float)delta)
            .Rotated(Vector3.Right, Mathf.Tau * (float)delta)
            .Orthonormalized();
}
Returns Basis

An orthonormalized basis matrix.

RotatedBasis
# Rotated
C#
public Basis Rotated(Vector3 axis, float angle);

Returns a copy of this basis rotated around the given axis by the given angle (in radians). The axis must be a normalized vector (see Vector3.Normalized). If angle is positive, the basis is rotated counter-clockwise around the axis.

C#
var myBasis = Basis.Identity;
var angle = Mathf.Tau / 2.0f;

myBasis = myBasis.Rotated(Vector3.Up, angle);    // Rotate around the up axis (yaw).
myBasis = myBasis.Rotated(Vector3.Right, angle); // Rotate around the right axis (pitch).
myBasis = myBasis.Rotated(Vector3.Back, angle);  // Rotate around the back axis (roll).
Parameters
NameTypeDefault
axisVector3—
anglefloat—
axis

The axis to rotate around. Must be normalized.

angle

The angle to rotate, in radians.

Returns Basis

The rotated basis matrix.

ScaledBasis
# Scaled
C#
public Basis Scaled(Vector3 scale);

Returns this basis with each axis's components scaled by the given scale's components. The basis matrix's rows are multiplied by scale's components. This operation is a global scale (relative to the parent).

C#
var myBasis = new Basis(
    new Vector3(1.0f, 1.0f, 1.0f),
    new Vector3(2.0f, 2.0f, 2.0f),
    new Vector3(3.0f, 3.0f, 3.0f)
);
myBasis = myBasis.Scaled(new Vector3(0.0f, 2.0f, -2.0f));

ReckfellApi.Print(myBasis.X); // Prints (0, 2, -2)
ReckfellApi.Print(myBasis.Y); // Prints (0, 4, -4)
ReckfellApi.Print(myBasis.Z); // Prints (0, 6, -6)
Parameters
NameTypeDefault
scaleVector3—
scale

The scale to introduce.

Returns Basis

The scaled basis matrix.

ScaledLocalBasis
# ScaledLocal
C#
public Basis ScaledLocal(Vector3 scale);

Returns this basis with each axis scaled by the corresponding component in the given scale. The basis matrix's columns are multiplied by scale's components. This operation is a local scale (relative to self).

C#
var myBasis = new Basis(
    new Vector3(1.0f, 1.0f, 1.0f),
    new Vector3(2.0f, 2.0f, 2.0f),
    new Vector3(3.0f, 3.0f, 3.0f)
);
myBasis = myBasis.ScaledLocal(new Vector3(0.0f, 2.0f, -2.0f));

ReckfellApi.Print(myBasis.X); // Prints (0, 0, 0)
ReckfellApi.Print(myBasis.Y); // Prints (4, 4, 4)
ReckfellApi.Print(myBasis.Z); // Prints (-6, -6, -6)
Parameters
NameTypeDefault
scaleVector3—
scale

The scale to introduce.

Returns Basis

The scaled basis matrix.

SlerpBasis
# Slerp
C#
public Basis Slerp(Basis target, float weight);

Performs a spherical-linear interpolation with the to basis, given a weight. Both this basis and to should represent a rotation. Example: Smoothly rotate a Entity3D to the target basis over time, with a Tween:

Parameters
NameTypeDefault
targetBasis—
weightfloat—
target

The destination basis for interpolation.

weight

A value on the range of 0.0 to 1.0, representing the amount of interpolation.

Returns Basis

The resulting basis matrix of the interpolation.

Tdotxfloat
# Tdotx
C#
public float Tdotx(Vector3 with);

Returns the transposed dot product between with and the Basis.X axis (see Basis.Transposed). This is equivalent to basis.x.dot(vector).

Parameters
NameTypeDefault
withVector3—
with

A vector to calculate the dot product with.

Returns float

The resulting dot product.

Tdotyfloat
# Tdoty
C#
public float Tdoty(Vector3 with);

Returns the transposed dot product between with and the Basis.Y axis (see Basis.Transposed). This is equivalent to basis.y.dot(vector).

Parameters
NameTypeDefault
withVector3—
with

A vector to calculate the dot product with.

Returns float

The resulting dot product.

Tdotzfloat
# Tdotz
C#
public float Tdotz(Vector3 with);

Returns the transposed dot product between with and the Basis.Z axis (see Basis.Transposed). This is equivalent to basis.z.dot(vector).

Parameters
NameTypeDefault
withVector3—
with

A vector to calculate the dot product with.

Returns float

The resulting dot product.

ToString2 overloads
# ToString · 1/2
C#
public override string ToString();

Converts this Basis to a string.

Returns string

A string representation of this basis.

# ToString · 2/2
C#
public string ToString(string? format);

Converts this Basis to a string with the given format.

Parameters
NameTypeDefault
formatstring—
Returns string

A string representation of this basis.

TransposedBasis
# Transposed
C#
public Basis Transposed();

Returns the transposed version of this basis. This turns the basis matrix's columns into rows, and its rows into columns.

C#
var myBasis = new Basis(
    new Vector3(1.0f, 2.0f, 3.0f),
    new Vector3(4.0f, 5.0f, 6.0f),
    new Vector3(7.0f, 8.0f, 9.0f)
);
myBasis = myBasis.Transposed();

ReckfellApi.Print(myBasis.X); // Prints (1, 4, 7)
ReckfellApi.Print(myBasis.Y); // Prints (2, 5, 8)
ReckfellApi.Print(myBasis.Z); // Prints (3, 6, 9)
Returns Basis

The transposed basis matrix.

op_Equalitybool
# op_Equality
C#
public static bool operator ==(Basis left, Basis right);

Returns true if the basis matrices are exactly equal. Note: Due to floating-point precision errors, consider using Basis.IsEqualApprox instead, which is more reliable.

Parameters
NameTypeDefault
leftBasis—
rightBasis—
left

The left basis.

right

The right basis.

Returns bool

Whether or not the basis matrices are exactly equal.

op_Inequalitybool
# op_Inequality
C#
public static bool operator !=(Basis left, Basis right);

Returns true if the basis matrices are not equal. Note: Due to floating-point precision errors, consider using Basis.IsEqualApprox instead, which is more reliable.

Parameters
NameTypeDefault
leftBasis—
rightBasis—
left

The left basis.

right

The right basis.

Returns bool

Whether or not the basis matrices are not equal.

op_Multiply3 overloads
# op_Multiply · 1/3
C#
public static Basis operator *(Basis left, Basis right);

Composes these two basis matrices by multiplying them together. This has the effect of transforming the second basis (the child) by the first basis (the parent).

Parameters
NameTypeDefault
leftBasis—
rightBasis—
left

The parent basis.

right

The child basis.

Returns Basis

The composed basis.

# op_Multiply · 2/3
C#
public static Vector3 operator *(Basis basis, Vector3 vector);

Returns a Vector3 transformed (multiplied) by the basis matrix.

Parameters
NameTypeDefault
basisBasis—
vectorVector3—
basis

The basis matrix transformation to apply.

vector

A Vector3 to transform.

Returns Vector3

The transformed Vector3.

# op_Multiply · 3/3
C#
public static Vector3 operator *(Vector3 vector, Basis basis);

Returns a Vector3 transformed (multiplied) by the inverse basis matrix, under the assumption that the transformation basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not). vector * basis is equivalent to basis.Transposed() * vector. See Basis.Transposed. For transforming by inverse of a non-orthonormal basis (e.g. with scaling) basis.Inverse() * vector can be used instead. See Basis.Inverse.

Parameters
NameTypeDefault
vectorVector3—
basisBasis—
vector

A Vector3 to inversely transform.

basis

The basis matrix transformation to apply.

Returns Vector3

The inversely transformed vector.

Fields and constants3

Row0Field
# Row0
C#
public Vector3 Row0;

Row 0 of the basis matrix. Shows which vectors contribute to the X direction. Rows are not very useful for user code, but are more efficient for some internal calculations.

Row1Field
# Row1
C#
public Vector3 Row1;

Row 1 of the basis matrix. Shows which vectors contribute to the Y direction. Rows are not very useful for user code, but are more efficient for some internal calculations.

Row2Field
# Row2
C#
public Vector3 Row2;

Row 2 of the basis matrix. Shows which vectors contribute to the Z direction. Rows are not very useful for user code, but are more efficient for some internal calculations.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.