-
Notifications
You must be signed in to change notification settings - Fork 510
Vector3
DirectXTK | SimpleMath |
---|
Three component vector class modeled after the XNA Game Studio 4 (Microsoft.Xna.Framework.Vector3
) math library.
#include <SimpleMath.h>
using namespace DirectX::SimpleMath;
Vector3 v; // Creates a vector [0, 0, 0]
Vector3 v(10); // Creates a vector [10, 10, 10]
Vector3 v(1, 2, 3); // Creates a vector [1, 2, 3]
float arr[3] = { 1, 2, 3 };
Vector3 v(arr); // Creates a vector [1, 2, 3]
- x component of vector
- y component of vector
- z component of vector
-
Comparison operators:
==
and!=
-
Assignment operators:
=
,+=
,-=
,*=
,/=
-
Unary operators:
+
,-
-
Binary operators:
+
,-
,*
,/
-
InBounds: Tests if the vector is within the bounds set by the positive and negative of the input bounds.
-
Length, LengthSquared: Compute vector length.
-
Dot: Returns the dot-product of two 3-vectors.
-
Cross: Computes the cross product of two 3-vectors.
-
Normalize: Computes a unit-length vector.
-
Clamp: Clamps the values of the vector per component between a minimum and a maximum.
-
Distance, DistanceSquared: Compute distance between two vectors.
-
Min, Max: Determine minimum/maximum vector elements.
-
Lerp: Performs a linear interpolation.
-
SmoothStep: Performs a cube interpolation.
-
Barycentric: Returns a point in Barycentric coordinates.
-
CatmullRom: Performs a Catmull-Rom interpolation.
-
Hermite: Performs a Hermite spline interpolation.
-
Reflect: Reflects an incident vector across a normal vector.
-
Refract: Refracts an incident vector across a normal vector.
-
Transform: Transform the vector by a matrix or a quaternion. See XMVector3Transform. There are overloads for returning the homogenous normalized
Vector3
result (i.e.w = 1
) or theVector4
result. There is also an overload for transforming an array of vectors. -
TransformNormal: Transforms the vector by matrix, ignoring translation (row 3). There is also an overload for transforming an array of vectors. See XMVector3TransformNormal.
- Zero: Zero vector [0, 0, 0]
- One: One vector [1, 1, 1]
- UnitX: Unit X vector [1, 0, 0]
- UnitY: Unit Y vector [0, 1, 0]
- UnitZ: Unit Z vector [0, 0, 1]
- Up: Up direction vector [0, 1, 0]
- Down: Down direction vector [0, -1, 0]
- Right: Right direction vector [1, 0, 0]
- Left: Left direction vector [-1, 0, 0]
- Forward: Forward direction vector for right-handed (RH) coordinates [0, 0, -1]
- Backward: Backward direction vector for right-handed (RH) coordinates [0, 0, 1]
Vector3 can freely convert to and from a XMFLOAT3
and XMVECTOR
(the w component is lost).
When assigning an RGB color from DirectXColors.h
to a Vector3, use the .v
union element
Vector3 color = Colors::White.v;
All content and source code for this package are subject to the terms of the MIT License.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Windows 8.1
- Windows 7 Service Pack 1
- Xbox One
- x86
- x64
- ARM64
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v18
- MinGW 12.2, 13.2
- CMake 3.20