0
\$\begingroup\$

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).

\$\endgroup\$
2
  • \$\begingroup\$ AFAIK there's no standard matrix in C++. What type of matrix are you using? \$\endgroup\$ Commented Jun 14, 2012 at 16:00
  • \$\begingroup\$ XMMATRIX from DirecXMath \$\endgroup\$
    – ChaosDev
    Commented Jun 14, 2012 at 16:01

2 Answers 2

1
\$\begingroup\$

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)

\$\endgroup\$
1
\$\begingroup\$

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;
    } 
}
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .