How To Use Vector3 in XNA

In this article I will explain all about Vector3.


In this article I will explain all about Vector3.

Vector3 is a 3-components based struct which is generally used in 3d space(x,y,z).

So vector3 is much more used in loading models and 3d transformations.

As we analyze vector3' structure we will figure out that most of the structure is already being used by Vector2 so some will be the same.

We can add 2 Vector3 variable:

1.gif
 
Returns a vector3(0,0,1):

2.gif
 
BaryCentric Calculation:

3.gif
 
Calculating CatmullRom:

4.gif
 
Using Clamp:

5.gif
 
Calculate Cross Product:

6.gif
 
Calculate Distance:

7.gif
 
Calculate Distance Squared:

8.gif
 
Calculating Divide:

9.gif
 
Calculating Dot Product of the given Vector3:

10.gif
 
Setting Down Vector3(0,-1,0):

11.gif
 
Setting Forward Vector3(0,0,-1):

12.gif
 
Using Hermite to perform a spline interpolation:

13.gif
 
Setting Left Vector3(-1,0,0):

14.gif 

Using Lerp for a linear interpolation:

15.gif
 
Getting the Max Vector3:

16.gif
 
Getting the Min Vector3:

17.gif
 
Multiplying 2 Vector3:

18.gif
 
Returning Negative of the given Vector3:

19.gif
 
Creating an unit vector from the specified Vector3:

20.gif
 
Setting One Vector3(1,1,1):

21.gif
 
Using Reflect with a normal:

22.gif
 
Setting Right Vector3(1,0,0):

23.gif
 
Using SmoothStep for interpolating a cubic equation:

24.gif
 
Subtracting 2 Vector3:

25.gif
 
Transforming Vector3:

26.gif   
 
TransformNormal is different from the Transform function so it only transforms normal values:

27.gif
 
Setting UnitX,UnitY,UnitZ,Up and Zero Vector3:

28.gif 

As I said before Vector3 are used in 3D Coordinate systems(x,y,z)

You can use it for Model Transformations(Rotate,Scale,Move).