• Advertisement


This topic is now archived and is closed to further replies.

Moving a X mesh within a world

This topic is 5469 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have generated terrain using a vertex buffer and have loaded an .x mesh file into the scene. I am currently moving around in the world using the Eye vector and Lookat vector and calling this function at each frame:
  BOOL WhatIsTheMatrix(){
	D3DXMATRIXA16 matWorld;
	D3DXMatrixMultiply(&matWorld, &matWorld, ArcBall.GetRotationMatrix());
    D3DXMatrixMultiply(&matWorld, &matWorld, ArcBall.GetTranslationMatrix());

	Device->SetTransform(D3DTS_WORLD, &matWorld);

    // Set up our view matrix.

    D3DXVECTOR3 vEyePt(eyeX, eyeY, eyeZ);
    D3DXVECTOR3 vLookatPt(lookX, lookY, lookZ);
    D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f);
    D3DXMATRIXA16 matView;
    D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec);
    Device->SetTransform(D3DTS_VIEW, &matView);

    // For the projection matrix

    D3DXMATRIXA16 matProj;
    D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
    Device->SetTransform(D3DTS_PROJECTION, &matProj);
	return TRUE;
How can I have the X mesh in front of me at all times as I move about in the world? "Wireless mice 4R3 73|-| 5UX0R" - Me

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
i do this by taking the inverse of the view matrix and then transforming a ray, which extends from the center of the viewport into the 3D world space, by that matrix. kind of like a pick process. the math could be simplified but i''m lazy.

float distInFromOfCamera = 20.0f;

geVector v(0.0f, 0.0f, 1.0f); // position representing center of render viewport

geMatrix matModel;

// create a ray (Pos and Dir) extending into the 3D world

geVector vPos(matModel._41, matModel._42, matModel._43);
geVector vDir(v.x*matModel._11 + v.y*matModel._21 + v.z*matModel._31,
v.x*matModel._12 + v.y*matModel._22 + v.z*matModel._32,
v.x*matModel._13 + v.y*matModel._23 + v.z*matModel._33);

// offset the position into 3D space by the distance to the near z

// clipping plane plus the distance from the clipping plane to the

// actual position where the object is to be placed

vPos += vDir*(m_NearZ + distInFromOfCamera);



Share this post

Link to post
Share on other sites

  • Advertisement