# Vectors from matrix

In XNA you can get front/back/left/right vector of Matrix class. How get these vectors without XNA, through C++ using standart 4x4 matrix ? I dont understand what exactly they mean but found them very useful(in XNA).

• AFAIK there's no standard matrix in C++. What type of matrix are you using? Jun 14 '12 at 16:00
• XMMATRIX from DirecXMath Jun 14 '12 at 16:01

I'm not familiar with XNA, but front/back/left/right(top, bottom?) vectors could make sense in the context of a rotation matrix.

If that's what they are about, you could get them by simply doing a matrix multiplication with the unit vectors. i.e. multiplying Matrix * [0,0,1,1], Matrix * [0,1,0,1], Matrix * [1,0,0,1] would give you the z,y, and x axes' directions in untransformed space. (the 4th component is necessary, multiplying a 4x4 matrix with a 1x3 vector is not possible)

Im open XNA assembly with reflector and get answer.

public Vector3 Up
{
get
{
Vector3 vector;
vector.X = this.M21;
vector.Y = this.M22;
vector.Z = this.M23;
return vector;
}
}
public Vector3 Down
{
get
{
Vector3 vector;
vector.X = -this.M21;
vector.Y = -this.M22;
vector.Z = -this.M23;
return vector;
}
}
public Vector3 Right
{
get
{
Vector3 vector;
vector.X = this.M11;
vector.Y = this.M12;
vector.Z = this.M13;
return vector;
}
}
public Vector3 Left
{
get
{
Vector3 vector;
vector.X = -this.M11;
vector.Y = -this.M12;
vector.Z = -this.M13;
return vector;
}
}
public Vector3 Forward
{
get
{
Vector3 vector;
vector.X = -this.M31;
vector.Y = -this.M32;
vector.Z = -this.M33;
return vector;
}
}
public Vector3 Backward
{
get
{
Vector3 vector;
vector.X = this.M31;
vector.Y = this.M32;
vector.Z = this.M33;
return vector;
}
}