• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
lucky6969b

View Matrix Decomposition (Direct3D)

5 posts in this topic

I want to retrieve back the eye position of the camera when a view matrix is given.
How can I achieve that? Any good articles that I can take a look at?
Thanks
Jack
0

Share this post


Link to post
Share on other sites
do you have variables that are being plugged into the x, y, and z values of the camera's position? If you do, then it should be easy to just display it with Directx text or GDI text. If you do have variables plugged in, are they global? If not(which they shouldn't, globals are evil ;) ) then do you have a way of Setting and Getting them?
0

Share this post


Link to post
Share on other sites
Depending on how your matrix is set up. If you are using row major it will be the last row of your matrix. if you are using Column major it will be the last column of your matrix. Or to put it in better perspective. If you your matrix is represented as a single dimensional array it will be index 12,13,14. Edited by BornToCode
0

Share this post


Link to post
Share on other sites
Extending off the above post, the view matrix is actually the inverse of the camera matrix. You should first invert the view matrix to get the camera matrix and then extract the position from that.
Since this is DirectX, once you have the camera matrix, the position will be in the _41, _42, and _43 members of the matrix.

But world, view, and projection matrices are concepts generally reserved for graphics processing and nothing else. Meaning you are not meant to extract anything from them except things directly related to graphics, such as view frustums etc. In other words, whatever the reason you have for getting the camera’s position this way is invalid and a hack. It indicates you have a flaw in your design that should be addressed.


L. Spiro
0

Share this post


Link to post
Share on other sites
Comment on this code snippet?
The eye pos is very weird.
Thanks
Jack
	//// Start exporting View and projection matrices
   Interface *ip2 = GetCOREInterface();
   ViewExp * pView = ip2->GetActiveViewport();  //  Get the viewport in question
   GraphicsWindow *gw = pView->getGW();  //  Get the GraphicsWindow context
   gw->getCameraMatrix( mat, &invTM, &persp, &hither, &yon); // getting these values to work with ... see above for their types
   float oneOverDepth = 1.0f / (yon - hither);
   // Set the Direct3D Camera View Position and Camera Projection Transforms.
   //
   // The first matrix is the full projection transformation matrix that
   // converts World Coordinates into NPC.  This means that the matrix is the
   // product of the Camera View Position transformation matrix and the Camera
   // Projection matrix.  The second matrix is the inverse of the Camera View
   // Position transformation matrix so if we multiply this second matrix by
   // the first, we get the Camera Projection matrix.  If we take the inverse
   // of the second matrix, we get the Camera View Position matrix.
   //
   // The Camera View Position transformation converts World coordinates into
   // Camera View Position coordinates where the camera is located at the
   // origin.  We have been given the inverse of the Camera View Position
   // matrix so the first step is to take the inverse of this transform to
   // obtain the Camera View Position matrix.
   // General conversion from 3ds max coords to Direct3D coords:
   //
   // 3ds max:  (Up, Front, Right) == (+Z, +Y, +X)
   //
   // Direct3D: (Up, Front, Right) == (+Y, +Z, +X)
   //
   // Conversion from 3ds max to Direct3D coords:
   //
   // 3ds max * conversion matrix = Direct3D
   //
   // [ x y z w ] * | +1  0  0  0 | = [ X Y Z W ]
   //               |  0  0 +1  0 |
   //               |  0 +1  0  0 |
   //               |  0  0  0 +1 |
   //
   // The View transform below accomplishes this.  The standard View transform
   // received makes the rotation about the X axis because the assumption was
   // to transform to RH coords with the XY plane being the vertical plane
   // instead of the XZ plane.  The negation of the the Z column does the RH
   // to LH flip.  Thus, the View transform makes the transition from RH 3ds
   // max coords to LH Direct3D coords.
   // View Matrix in 3ds max, inverse's inverse to become original [Jacky Luk]
	Matrix3 camTM = Inverse(invTM);

		 
   // We now have an affine matrix (4x3) with no perspective column (it is
   // understood to be (0, 0, 0, 1)).  We add the fourth column and flip the
   // Z-axis because Direct3D uses a left-handed coordinate system and MAX
   // uses a right-handed coordinate system.
   // Copy the affine view matrix data


   int ki, kj;
   MRow *pcvm = camTM.GetAddr();
   for (ki = 0; ki < 4; ki++) {
 	for (kj = 0; kj < 3; kj++) {
		d3dViewXform.m[ki][kj] = pcvm[ki][kj];
	}
   }
   // Assign the fourth column (perspective terms)
   d3dViewXform.m[0][3] = d3dViewXform.m[1][3] = d3dViewXform.m[2][3] = 0.0f;
   d3dViewXform.m[3][3] = 1.0f;

    	
   // Scale the Z-axis (third column) by -1 to flip to left-handed Direct3D
   // coordinate system

   for (ki = 0; ki < 4; ki++) {
	d3dViewXform.m[ki][2] *= -1.0f;
   }


   // Calculate the Direct3D Camera Projection transformation matrix.
   //
   // First, multiply the MAX full projection matrix by the inverse of the MAX
   // Camera View Position matrix to obtain the MAX Camera Projection matrix.
   //
   // This gives us a correct Direct3D Camera Projection matrix except for the
   // lower right quadrant.
   //

   MRow *pa = invTM.GetAddr();
   for (ki = 0; ki < 4; ki++) {
     float val = (float)(ki==3);
     for (kj = 0; kj < 4; kj++) {
	d3dProjXform.m[ki][kj] = pa[ki][0] * mat[0][kj] +
	pa[ki][1] * mat[1][kj] +
	pa[ki][2] * mat[2][kj] +
	val		 * mat[3][kj];
    }
  }

  // Now calculate the lower right quadrant of the Camera Projection matrix
  // using the facts that MAX uses an NPC Z-axis range of +1 to -1 whereas
  // Direct3D uses an NPC Z-axis range of zero to +1.
  //
  // For ease of reference, the general forms of the Direct3D Projection
  // matrix for perspective and orthographic projections are given below.
  //
  // Please note that the matrices are specified in row-major order.  This
  // means that the translate terms are located in the fourth row and the
  // projection terms in the fourth column.  This is consistent with the way
  // MAX, Direct3D, and OpenGL all handle matrices.  Even though the OpenGL
  // documentation is in column-major form, the OpenGL code is designed to
  // handle matrix operations in row-major form.
  if (persp) {
      // Perspective projection.  The general form of the Direct3D Camera
      // Projection matrix is:
      //
      // |    2n/(r-l)       0            0            0       |
      // |      0          2n/(t-b)       0            0       |
      // | (r+l)/(r-l)  (t+b)/(t-b)      f/(f-n)       1       |
      // |      0            0         -fn/(f-n)       0       |
      // 
      // Construct the lower right four terms correctly for Direct3D.
      //
      d3dProjXform.m[2][2] = yon*oneOverDepth;
      d3dProjXform.m[2][3] = 1.0f;
      d3dProjXform.m[3][2] = -(yon*hither*oneOverDepth);
      d3dProjXform.m[3][3] = 0.0f;
		
   } else {

    	
      // Orthographic projection.  The general form of the Direct3D Camera
      // Projection matrix is:
      //
      // |     2/(r-l)       0            0            0       |
      // |      0           2/(t-b)       0            0       |
      // |      0            0           1/(f-n)       0       |
      // | (r+l)/(r-l)  (t+b)/(t-b)     -n/(f-n)       1       |
      // 
      // Construct the lower right four terms correctly for Direct3D.
      //

      d3dProjXform.m[2][2] = oneOverDepth;
      d3dProjXform.m[2][3] = 0.0f;
      d3dProjXform.m[3][2] = -(hither*oneOverDepth);
      d3dProjXform.m[3][3] = 1.0f;
  }
  D3DXVECTOR3 v;
  D3DXQUATERNION q;
  D3DXVECTOR3 s;

  D3DXMatrixDecompose(&s, &q, &v, &d3dViewXform);
  DOMElement *elem1 = doc->createElement(L"Eye-Pos");
Edited by lucky6969b
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0