I use DirectX3D 11 for the application, and the target camera vector is determined by the variables xdelta, ydelta and zdelta.
I have a PAN my look in XY when I move the mouse around the screen with RMB and LMB pressed.
I decided that I need to add the delta in the mouse movement to my VIEW space so that it is cropped in X and Y relative to my view, and not the world of X and Y.
However, being new to this, I'm not sure how to convert my VIEW coordinates back to WORLD coordinates.
I hope that I follow all the formatting rules, since I do not post here enough to remember all of them accurately.
Any help would be greatly appreciated. below is my code snippet. Perhaps there is a better way.
if ( m_Input->RMBPressed() == true && m_Input->LMBPressed() == true ) // Pan View { if ( curX != mouseX || curY != mouseY ) { //Get Target Coordinates in View Space D3DXVECTOR3 targetView = (D3DXVECTOR3 ( mView(2,0), mView(2,1), mView(2,2) ); //Add mouse XY delta vector to target View Coordinates D3DXVECTOR3 delta ( (float)curX-(float)mouseX, (float)curY-(float)mouseY, zdelta ); targetView += delta; //Convert back to World Coordinates } }
I am trying to use a different approach, which I believe is the right approach, but it still does not work correctly. I get delta in X and Y from the screen when my mouse moves and saves them in the variables "xdelta" and "ydelta".
Then I create a transformation matrix
D3DXMATRIX mTrans;
Then I fill in the values ββin the matrix
Now, to get the corresponding View coordinates, I think I should multiply it by the View Matrix, which I call mView.
mTrans= mTrans*mView;
Now add these translated values ββto my current target X and Y, which are determined by the variables "target_x" and "target_y", they should move my target vector relative to my coordinates of the X and Y coordinates (i.e. orthogonal to my current view) .
target_x += mTrans(0,3); target_y += mTrans(1,3);
But this is not so. It moves my target along the entire X and Y axis, not the X and Y axis.
MORE SNIPPERS
I use the D3DXMatrixLookAtLH function, but I am trying to calculate the change in the target location based on my mouse movements to get a new target to feed into this function. I have added some code snippets:
if ( m_Input->RMBPressed() == true && m_Input->LMBPressed() == true ) // Pan View { if ( curX != mouseX || curY != mouseY ) { //Get mouse XY delta vector D3DXVECTOR3 delta ( (float)curX-(float)mouseX, (float)curY-(float)mouseY, zdelta ); //Create Transformation Matrix D3DXMATRIX mTemp; // Rotation mTemp (0,0) = delta.x; mTemp (1,1) = delta.y; mTemp (2,2) = delta.z; // Translation mTemp (0,3) = delta.x; mTemp (1,3) = delta.y; mTemp (2,3) = delta.z; //Convert to View Coordinates mTemp = mTemp*mView; xdelta += mTemp(0,3); ydelta += mTemp(1,3); // Convert Spherical to Cartesian coordinates: mPhi measured from +y // and mTheta measured counterclockwise from z. float height = mRadius * cosf(mPhi); float sideRadius = mRadius * sinf(mPhi); float x = xdelta + sideRadius * cosf(mTheta); float z = zdelta + sideRadius * sinf(mTheta); float y = ydelta + height; // Build the view matrix. D3DXVECTOR3 pos(x, y, z); D3DXVECTOR3 target(xdelta, ydelta, zdelta); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); // Y Axis is up. Looking down Z. D3DXMatrixLookAtLH(&mView, &pos, &target, &up);
First of all, thanks for all your information. This helps me slowly understand DirectX matrices. Am I correct in the logic below? Suppose my mouse change is 5.0 in X and 5.0 in Y on the screen. this is my delta. Z will always be 0.0. I could find the coordinates of the view as follows.
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
Now should I have the coordinates of the XY-delta view stored in the matrix of the form mTemp?
If so, this is the best way to proceed by adding the XY delta View coordinates to the mView XY coordinates, and then translating back to world coordinates to get the actual XY value in the world. Should I set a goal on?
I donβt understand how to do this. All this is not entirely clear to me, and all the books that I bought on this subject are also not clear.