Skip to content

Vector3

Chuck Walbourn edited this page Nov 3, 2015 · 16 revisions

Three component vector class modeled after the XNA Game Studio math library.

Header

#include <SimpleMath.h>

Initialization

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]

Fields

  • x component of vector
  • y component of vector
  • z component of vector

Methods

  • Comparison operators: == and !=
  • Assignment operators: =, +=, -=, *=, /=
  • Unary operators: +, -
  • Binary operators: +, -, *, /
  • InBounds
  • Length
  • LengthSquared
  • Dot
  • Cross
  • Normalize
  • Clamp

Statics

  • Distance
  • DistanceSquared
  • Min
  • Max
  • Lerp
  • SmoothStep
  • Barycentric
  • CatmullRom
  • Hermite
  • Reflect
  • Refract
  • Transform
  • TransformNormal

Constants

  • 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]

Remark

Vector3 can freely convert to and from a XMFLOAT3 and XMVECTOR

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 11
  • Windows 10
  • Windows 8.1
  • Xbox One

Architecture

  • x86
  • x64
  • ARM64

For Development

  • Visual Studio 2022
  • Visual Studio 2019 (16.11)
  • clang/LLVM v12 - v18
  • MinGW 12.2, 13.2
  • CMake 3.20

Related Projects

DirectX Tool Kit for DirectX 12

DirectXMesh

DirectXTex

DirectXMath

Win2D

Tools

Test Suite

Model Viewer

Content Exporter

DxCapsViewer

Clone this wiki locally