Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
    
AFAIK there's no standard matrix in C++. What type of matrix are you using? –  Laurent Couvidou Jun 14 '12 at 16:00
    
XMMATRIX from DirecXMath –  ChaosDev Jun 14 '12 at 16:01
add comment

2 Answers

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)

share|improve this answer
add comment

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;
    } 
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.