struct Vec3

A vector with 3 components: x, y, z. This can represent a point in space, a directional vector, or any other sort of value with 3 dimensions to it!

StereoKit uses a right-handed coordinate system, where +x is to the right, +y is upwards, and -z is forward.

Instance Fields and Properties

   
float Length This is the length, or magnitude of the vector! The distance from the origin to this point. Uses Math.Sqrt, so it’s not dirt cheap or anything.
float LengthSq This is the squared length of the vector! It skips the Sqrt call, and just gives you the squared version for speedy calculations that can work with it squared.
float Magnitude Magnitude is the length of the vector! The distance from the origin to this point. Uses Math.Sqrt, so it’s not dirt cheap or anything.
float MagnitudeSq This is the squared magnitude of the vector! It skips the Sqrt call, and just gives you the squared version for speedy calculations that can work with it squared.
Vec3 Normalized Creates a normalized vector (vector with a length of 1) from the current vector. Will not work properly if the vector has a length of zero.
Vector3 v The internal, wrapped System.Numerics type. This can be nice to have around so you can pass its fields as ‘ref’, which you can’t do with properties. You won’t often need this, as implicit conversions to System.Numerics types are also provided.
float x X component.
Vec3 X0Z This returns a Vec3 that has been flattened to 0 on the Y axis. No other changes are made.
Vec2 XY This extracts a Vec2 from the X and Y axes.
Vec3 XY0 This returns a Vec3 that has been flattened to 0 on the Z axis. No other changes are made.
Vec2 XZ This extracts a Vec2 from the X and Z axes.
float y Y component.
Vec2 YZ This extracts a Vec2 from the Y and Z axes.
float z Z component.

Instance Methods

   
Vec3 Creates a vector from x, y, and z values! StereoKit uses a right-handed metric coordinate system, where +x is to the right, +y is upwards, and -z is forward.
InRadius Checks if a point is within a certain radius of this one. This is an easily readable shorthand of the squared distance check.
Normalize Turns this vector into a normalized vector (vector with a length of 1) from the current vector. Will not work properly if the vector has a length of zero.
ToString Mostly for debug purposes, this is a decent way to log or inspect the vector in debug mode. Looks like “[x, y, z]”

Static Fields and Properties

   
Vec3 Forward StereoKit uses a right-handed coordinate system, which means that forward is looking down the -Z axis! This value is the same as new Vec3(0,0,-1). This is NOT the same as UnitZ!
Vec3 One Shorthand for a vector where all values are 1! Same as new Vec3(1,1,1).
Vec3 Right When looking forward, this is the direction to the right! In StereoKit, this is the same as new Vec3(1,0,0)
Vec3 UnitX A normalized Vector that points down the X axis, this is the same as new Vec3(1,0,0).
Vec3 UnitY A normalized Vector that points down the Y axis, this is the same as new Vec3(0,1,0).
Vec3 UnitZ A normalized Vector that points down the Z axis, this is the same as new Vec3(0,0,1). This is NOT the same as Forward!
Vec3 Up A vector representing the up axis. In StereoKit, this is the same as new Vec3(0,1,0).
Vec3 Zero Shorthand for a vector where all values are 0! Same as new Vec3(0,0,0).

Static Methods

   
AngleBetween Calculates the angle between two vectors in degrees! Vectors do not need to be normalized, and the result will always be positive.
AngleXY Creates a vector that points out at the given 2D angle! This creates the vector on the XY plane, and allows you to specify a constant z value.
AngleXZ Creates a vector that points out at the given 2D angle! This creates the vector on the XZ plane, and allows you to specify a constant y value.
Cross The cross product of two vectors!
Direction Creates a normalized delta vector that points out from an origin point to a target point!
Distance Calculates the distance between two points in space! Make sure they’re in the same coordinate space! Uses a Sqrt, so it’s not blazing fast, prefer DistanceSq when possible.
DistanceSq Calculates the distance between two points in space, but leaves them squared! Make sure they’re in the same coordinate space! This is a fast function :)
Dot The dot product is an extremely useful operation! One major use is to determine how similar two vectors are. If the vectors are Unit vectors (magnitude/length of 1), then the result will be 1 if the vectors are the same, -1 if they’re opposite, and a gradient in-between with 0 being perpendicular. See Freya Holmer’s excellent visualization of this concept
Lerp Blends (Linear Interpolation) between two vectors, based on a ‘blend’ value, where 0 is a, and 1 is b. Doesn’t clamp percent for you.
Max Returns a vector where each elements is the maximum value for each corresponding pair.
Min Returns a vector where each elements is the minimum value for each corresponding pair.
PerpendicularRight Exactly the same as Vec3.Cross, but has some naming mnemonics for getting the order right when trying to find a perpendicular vector using the cross product. This’ll also make it more obvious to read if that’s what you’re actually going for when crossing vectors! If you consider a forward vector and an up vector, then the direction to the right is pretty trivial to imagine in relation to those vectors!

Operators

   
+ Adds matching components together. Commutative.
/ A component-wise vector division. Not commutative
Implicit Conversions Allows implicit conversion from System.Numerics.Vector3 to StereoKit.Vec3.
* A component-wise vector multiplication, same thing as a non-uniform scale. NOT a dot or cross product! Commutative.
- Subtracts matching components from eachother. Not commutative.
- Vector negation, returns a vector where each component has been negated.




Found an issue with these docs, or have some additional questions? Create an Issue on Github!