Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8668355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:11:36+00:00 2026-06-12T18:11:36+00:00

I need to compute a rotation matrix from a direction vector, and a direction

  • 0

I need to compute a rotation matrix from a direction vector,
and a direction vector from a rotation matrix.

The up direction should correspond to the z-axis,
forward is y and right is x;

    D3DXMATRIX m; // the rotation matrix
    D3DXVECTOR3 v; // this is the direction vector wich is given
    D3DXVECTOR3 r; // resulting direction vector

    float len = D3DXVec3Length(&v); // length of the initial direction vector

    // compute matrix
    D3DXMatrixLookAtLH(&m, &v, &D3DXVECTOR3(0,0,0), &D3DXVECTOR3(0,0,1));

    // use the matrix on a vector { 0, len, 0 }
    D3DXVec3TransformCoord(&r, &D3DXVECTOR3(0,len,0), &m);

Now, the vector r should be equal to v, but it isnt.
What exactly do I have to do to get the results I need?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:11:38+00:00Added an answer on June 12, 2026 at 6:11 pm

    The question is a bit confusing for me. Using a direction vector, you can define infinite rotation matrices that would make the camera point/look at that direction, unless you define some additional constraints.
    I will assume, based on your code, that you want the up vector to be Z 🙂

    In first place, be careful: it seems that you are describing a right-handed coordinate system, but using a left-handed function D3DXMatrixLookAtLH.
    In second place, reference for this function says that:

    D3DXMATRIX* D3DXMatrixLookAtLH(
      _Inout_  D3DXMATRIX *pOut,
      _In_     const D3DXVECTOR3 *pEye,
      _In_     const D3DXVECTOR3 *pAt,
      _In_     const D3DXVECTOR3 *pUp
    );
    

    You are creating a look-at matrix specifying that:

    • The camera is located at the end of the v vector,
    • Camera is looking towards [0 0 0]

    Are you sure this is right, or were you maybe looking for the opposite?

    In third place, you are applying the rotation matrix to a scaled Y basis vector [0 length 0]. If you want the rotated vector to be v, I think you should apply it to the scaled X basis vector instead [len 0 0].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to compute a numeric representation of a string which is bi-direction. For
I need to compute MD5 hash of a String and googling I found this
I have 9 values in the form of a matrix and need to compute
I need to compute the resulting bitmap obtained from overlapping two different bitmaps that
I need to compute hashes of multiple blocks of data independently. Something like this:
I need to compute this equation in C/C++: x=(a*b-1)/c; with a,b,c,x of type __int64
Background: I have an iterative hash algorithm I need to compute from a Python
I need to compute imaginary exponential in C. As far as I know, there
I need to compute the area of the region of overlap between two triangles
I need to compute combinatorials (nCr) in Python but cannot find the function to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.