The Vector class represents a 3 dimensional vector.
public struct VectorMembers at a glance
| Kind | Members |
|---|---|
| Constructors | Vector |
| Fields | Back · Down · Forward · Left · ObjectBack · ObjectDown · ObjectForward · ObjectLeft · ObjectRight · ObjectUp · One · Right · Up · Zero |
| Properties | Item · W · X · Y · Z |
| Methods | AngleTo · Cross · Dot · Dot3 · Dot4 · Length · LengthSquared · Lerp · Normalized · Orthonormalize · Parse · Rotate · ToString · ToString4 · TryParse |
| Operators | op_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.
| Parameter | Type | Description |
|---|---|---|
v | Mono.Simd.Vector4f | Initializes 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.
| Parameter | Type | Description |
|---|---|---|
all | float | The 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.
| Parameter | Type | Description |
|---|---|---|
x | float | The x coordinate. |
y | float | The y coordinate. |
z | float | The z coordinate. |
w | float | The w coordinate. W defaults to 0 and is assumed to be 0 for most operations. |
Fields
Back
[System.Obsolete("Use ObjectBack for correct back vector.", false)]
public static readonly Vector BackDeprecated back vector.
Down
[System.Obsolete("Use ObjectDown for correct down vector.", false)]
public static readonly Vector DownDeprecated down vector.
Forward
[System.Obsolete("Use ObjectForward for correct forward vector.", false)]
public static readonly Vector ForwardDeprecated forward vector.
Left
[System.Obsolete("Use ObjectLeft for correct left vector.", false)]
public static readonly Vector LeftDeprecated left vector.
ObjectBack
public static readonly Vector ObjectBackThe default world back vector.
ObjectDown
public static readonly Vector ObjectDownThe default world down vector.
ObjectForward
public static readonly Vector ObjectForwardThe default world forward vector.
ObjectLeft
public static readonly Vector ObjectLeftThe default world left vector.
ObjectRight
public static readonly Vector ObjectRightThe default world right vector.
ObjectUp
public static readonly Vector ObjectUpThe default world up vector.
One
public static readonly Vector OneA vector with all components 1.
Right
[System.Obsolete("Use ObjectRight for correct right vector.", false)]
public static readonly Vector RightDeprecated right vector.
Up
[System.Obsolete("Use ObjectUp for correct up vector.", false)]
public static readonly Vector UpDeprecated up Vector
Zero
public static readonly Vector ZeroA vector with all components 0.
Properties
Item
public float this [int index] { get; set; }Allows getting coordinates by index.
| Parameter | Type | Description |
|---|---|---|
index | int | 0=>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.
| Parameter | Type | Description |
|---|---|---|
b | Vector | The 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.
| Parameter | Type | Description |
|---|---|---|
b | Vector | The 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.
| Parameter | Type | Description |
|---|---|---|
b | Vector | The 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.
| Parameter | Type | Description |
|---|---|---|
b | Vector | The 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.
| Parameter | Type | Description |
|---|---|---|
b | Vector | The 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.
| Parameter | Type | Description |
|---|---|---|
b | Vector | The second vector. |
amount | float | Value 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
public static Vector Orthonormalize(ref Vector forward, ref Vector up)Normalizes the two vectors and returns the normalized cross product.
| Parameter | Type | Description |
|---|---|---|
forward | Vector | The facing ve |
up | Vector |
Returns: Vector
Parse
public static Vector Parse(string vectorString)Parse a Vector from a string.
| Parameter | Type | Description |
|---|---|---|
vectorString | string | A 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.
| Parameter | Type | Description |
|---|---|---|
q | Quaternion | The 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.
| Parameter | Type | Description |
|---|---|---|
format | string | Format 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.
| Parameter | Type | Description |
|---|---|---|
format | string | Format 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
| Parameter | Type | Description |
|---|---|---|
vectorString | string | A string of the format <X,Y,Z> or <X,Y,Z,W> |
vector | Vector | The 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.
| Parameter | Type | Description |
|---|---|---|
a | Vector | The first Vector. |
b | Vector | The 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.
| Parameter | Type | Description |
|---|---|---|
a | Vector | The vector. |
b | float | The 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.
| Parameter | Type | Description |
|---|---|---|
v | Mono.Simd.Vector4f | The 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
| Parameter | Type | Description |
|---|---|---|
v | Vector | The vector to convert |
op_Multiply
public static Vector operator *(
[System.Runtime.CompilerServices.IsReadOnly] ref Vector a,
float b
)Performs a vector scalar multiplication.
| Parameter | Type | Description |
|---|---|---|
a | Vector | The vector. |
b | float | The 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.
| Parameter | Type | Description |
|---|---|---|
a | float | The scalar. |
b | Vector | The 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.
| Parameter | Type | Description |
|---|---|---|
a | Vector | The first Vector. |
b | Vector | The second Vector. |
Returns: Vector — A new vector that is the difference of the arguments.
Used in examples
- FollowThePath.cs
- MoverExample1.cs
- MoverExample2.cs
- MoverExample3.cs
- RandomMovement.cs
- BanHammerExample.cs
CameraShakeExample.cs- CastRayExample.cs
MoverExample4.cs- ReactionsExample.cs
- ScriptLibrary/Quest/QuestObjectBase.cs
- ScriptLibrary/Scene/Dispenser.cs
…and 8 more examples in the snapshot.
Generated from the Sansar 47.10.0 client ScriptApi snapshot.