Skip to content

Get Sansar

Script API

Vector

Where: Client
More page actions

For the complete documentation index, see llms.txt. This page is also available as Markdown.

Struct Namespace Sansar

The Vector class represents a 3 dimensional vector.

public struct Vector

Members at a glance

KindMembers
ConstructorsVector
FieldsBack · Down · Forward · Left · ObjectBack · ObjectDown · ObjectForward · ObjectLeft · ObjectRight · ObjectUp · One · Right · Up · Zero
PropertiesItem · W · X · Y · Z
MethodsAngleTo · Cross · Dot · Dot3 · Dot4 · Length · LengthSquared · Lerp · Normalized · Orthonormalize · Parse · Rotate · ToString · ToString4 · TryParse
Operatorsop_Addition · op_Division · op_Implicit · op_Multiply · op_Subtraction

Constructors

Vector

public Vector(     [System.Runtime.CompilerServices.IsReadOnly] ref Mono.Simd.Vector4f v )

Creates a new vector with the supplied values.

ParameterTypeDescription
vMono.Simd.Vector4fInitializes the vector from a Vector4f. W should be 0 and is assumed to be 0 for most operations.
public Vector(float all)

Creates a new vector with all values set to the given value.

ParameterTypeDescription
allfloatThe value for all coordinates.
Remarks

W will be set to 0.

public Vector(float x, float y, float z, float w)

Creates a new vector with the supplied values.

ParameterTypeDescription
xfloatThe x coordinate.
yfloatThe y coordinate.
zfloatThe z coordinate.
wfloatThe w coordinate. W defaults to 0 and is assumed to be 0 for most operations.

Fields

Back

Deprecated
[System.Obsolete("Use ObjectBack for correct back vector.", false)] public static readonly Vector Back

Deprecated back vector.

Down

Deprecated
[System.Obsolete("Use ObjectDown for correct down vector.", false)] public static readonly Vector Down

Deprecated down vector.

Forward

Deprecated
[System.Obsolete("Use ObjectForward for correct forward vector.", false)] public static readonly Vector Forward

Deprecated forward vector.

Left

Deprecated
[System.Obsolete("Use ObjectLeft for correct left vector.", false)] public static readonly Vector Left

Deprecated left vector.

ObjectBack

Added in 36.0.1
public static readonly Vector ObjectBack

The default world back vector.

ObjectDown

Added in 36.0.1
public static readonly Vector ObjectDown

The default world down vector.

ObjectForward

Added in 36.0.1
public static readonly Vector ObjectForward

The default world forward vector.

ObjectLeft

Added in 36.0.1
public static readonly Vector ObjectLeft

The default world left vector.

ObjectRight

Added in 36.0.1
public static readonly Vector ObjectRight

The default world right vector.

ObjectUp

Added in 36.0.1
public static readonly Vector ObjectUp

The default world up vector.

One

public static readonly Vector One

A vector with all components 1.

Deprecated
[System.Obsolete("Use ObjectRight for correct right vector.", false)] public static readonly Vector Right

Deprecated right vector.

Up

Deprecated
[System.Obsolete("Use ObjectUp for correct up vector.", false)] public static readonly Vector Up

Deprecated up Vector

Zero

public static readonly Vector Zero

A vector with all components 0.

Properties

Item

public float this [int index] { get; set; }

Allows getting coordinates by index.

ParameterTypeDescription
indexint0=>X, 1=>Y, 2=>Z, 3=>W

W

public float W { get; set; }

The W coordinate of the vector.

Remarks

W should be 0 and is assumed to be 0 for most operations.

X

public float X { get; set; }

The X coordinate of the vector.

Y

public float Y { get; set; }

The Y coordinate of the vector.

Z

public float Z { get; set; }

The Z coordinate of the vector.

Methods

AngleTo

public float AngleTo(     [System.Runtime.CompilerServices.IsReadOnly] ref Vector b )

Returns the angle in radians between this vector and the given vector.

ParameterTypeDescription
bVectorThe angle to compare.

Returns: float — The smallest angle in radians between the two vectors.

Cross

public Vector Cross(     [System.Runtime.CompilerServices.IsReadOnly] ref Vector b )

Calculates the cross product of 2 3D vectors.

ParameterTypeDescription
bVectorThe second vector.

Returns: Vector — a X b

Dot

public float Dot(     [System.Runtime.CompilerServices.IsReadOnly] ref Vector b )

Performs a 3-component scalar or dot product.

ParameterTypeDescription
bVectorThe second vector.

Returns: float — Returns X*b.X+Y*b.Y+Z*b.Z

Dot3

public float Dot3(     [System.Runtime.CompilerServices.IsReadOnly] ref Vector b )

Performs a 3-component scalar or dot product.

ParameterTypeDescription
bVectorThe second vector.

Returns: float — Returns X*b.X+Y*b.Y+Z*b.Z

Dot4

public float Dot4(     [System.Runtime.CompilerServices.IsReadOnly] ref Vector b )

Performs a 4-component scalar or dot product.

ParameterTypeDescription
bVectorThe second vector.

Returns: float — Returns X*b.X+Y*b.Y+Z*b.Z+W*b.W

Length

public float Length()

Calculates the magnitude of this vector.

Returns: float — The 3D vector length.

LengthSquared

public float LengthSquared()

Calculates the square magnitude of this vector.

Returns: float — The square of the 3D vector length.

Lerp

public Vector Lerp(     [System.Runtime.CompilerServices.IsReadOnly] ref Vector b,     float amount )

Performs a linear interpolation between two vectors.

ParameterTypeDescription
bVectorThe second vector.
amountfloatValue from [0..1] indicating the weight for the second vector.

Returns: Vector — A vector that is linearly interpolated between the two sources.

Remarks

This method performs the linear interpolation as:

a + (b-a) * amount.

An amount value of 0 returns vector a, and 1 returns vector b.

Normalized

public Vector Normalized()

Returns a vector with the same orientation and unit length.

Returns: Vector — A vector with the same orientation and unit length.

Orthonormalize

Added in 35.0.0
public static Vector Orthonormalize(ref Vector forward, ref Vector up)

Normalizes the two vectors and returns the normalized cross product.

ParameterTypeDescription
forwardVectorThe facing ve
upVector

Returns: Vector

Parse

public static Vector Parse(string vectorString)

Parse a Vector from a string.

ParameterTypeDescription
vectorStringstringA string of the format <X,Y,Z> or <X,Y,Z,W>

Returns: Vector — The Vector parsed from the string.

Throws ArgumentException: If vectorString is null.

Throws FormatException: If the string is not a valid vector or its components are not valid floats.

Example
Vector myVector = Vector.Parse("<1,2.34,5.6>");

Rotate

public Vector Rotate(     [System.Runtime.CompilerServices.IsReadOnly] ref Quaternion q )

Returns a new vector which is this vector rotated by the given quaternion.

ParameterTypeDescription
qQuaternionThe quaternion rotation.

Returns: Vector

ToString

public override string ToString()

Generates a string representation of the vector.

Returns: string — The vector as a string.

public string ToString(string format)

Generates a string representation of the vector.

ParameterTypeDescription
formatstringFormat to use for each of the coordinates.

Returns: string — The vector as a string.

ToString4

public string ToString4(string format)

Generates a string representation of the vector, including the W parameter.

ParameterTypeDescription
formatstringFormat to use for each of the coordinates.

Returns: string — The vector as a string.

TryParse

public static bool TryParse(string vectorString, out Vector vector)

Attempt to parse a Vector from a string

ParameterTypeDescription
vectorStringstringA string of the format <X,Y,Z> or <X,Y,Z,W>
vectorVectorThe vector that will be set if vectorString represents a valid vector.

Returns: bool — True if successfully parsed a vector, false if not.

Example
Vector myVector;
if (Vector.Parse("<1,2.34,5.6>", out myVector)
{
// myVector is set
}

Operators

op_Addition

public static Vector operator +(     [System.Runtime.CompilerServices.IsReadOnly] ref Vector a,     [System.Runtime.CompilerServices.IsReadOnly] ref Vector b )

Performs vector addition.

ParameterTypeDescription
aVectorThe first Vector.
bVectorThe second Vector.

Returns: Vector — A new vector that is the sum of the arguments.

op_Division

public static Vector operator /(     [System.Runtime.CompilerServices.IsReadOnly] ref Vector a,     float b )

Divides vector components by a scalar.

ParameterTypeDescription
aVectorThe vector.
bfloatThe scalar.

Returns: Vector — Returns a new vector with value [a.X/b, a.Y/b, a.Z/b, a.W/b]

op_Implicit

public static implicit operator Vector(     [System.Runtime.CompilerServices.IsReadOnly] ref Mono.Simd.Vector4f v )

Converts a Mono.Simd.Vector4f to a vector.

ParameterTypeDescription
vMono.Simd.Vector4fThe vector to convert
public static implicit operator Mono.Simd.Vector4f(     [System.Runtime.CompilerServices.IsReadOnly] ref Vector v )

Converts a vector to a Mono.Simd.Vector4f

ParameterTypeDescription
vVectorThe vector to convert

op_Multiply

public static Vector operator *(     [System.Runtime.CompilerServices.IsReadOnly] ref Vector a,     float b )

Performs a vector scalar multiplication.

ParameterTypeDescription
aVectorThe vector.
bfloatThe scalar.

Returns: Vector — Returns a new vector with value [a.X*b, a.Y*b, a.Z*b, a.W*b]

public static Vector operator *(     float a,     [System.Runtime.CompilerServices.IsReadOnly] ref Vector b )

Performs a vector scalar multiplication.

ParameterTypeDescription
afloatThe scalar.
bVectorThe vector.

Returns: Vector — Returns a new vector with value [a*b.X, a*b.Y, a*b.Z, a*b.W]

op_Subtraction

public static Vector operator -(     [System.Runtime.CompilerServices.IsReadOnly] ref Vector a,     [System.Runtime.CompilerServices.IsReadOnly] ref Vector b )

Performs vector subtraction.

ParameterTypeDescription
aVectorThe first Vector.
bVectorThe second Vector.

Returns: Vector — A new vector that is the difference of the arguments.

Used in examples

…and 8 more examples in the snapshot.

Generated from the Sansar 47.10.0 client ScriptApi snapshot.