Jump to content


Drag and Drop Meshes


  • You cannot reply to this topic
2 replies to this topic

#1 durban

    New Member

  • Members
  • Pip
  • 9 posts

Posted 12 September 2005 - 12:49 AM

Hello, I'm pretty new to DirectX and I still haven't gathered how all the functions work yet. My question lies in Transforming from Model Space to Screen space then adjusting a Meshes position from screen space coordinates. Here's some code:


_device->GetTransform(D3DTS_PROJECTION, &proj);
_device->GetTransform(D3DTS_VIEW, &view);

GetCursorPos(&ptCursor);
ScreenToClient(GetCapture(), &ptCursor);

numVerts = mesh->_mesh->GetNumVertices();
fvf = mesh->_mesh->GetFVF();
vertSize = D3DXGetFVFVertexSize(fvf);

mesh->_mesh->LockVertexBuffer(0, &ptr)

for( DWORD i=0; i<numVerts; i++ )
{
	D3DXVECTOR3* vPtr = (D3DXVECTOR3*)ptr;
	D3DXVECTOR3 temp;
	D3DXVec3TransformCoord(&temp, vPtr, &view); // Is this right?
	D3DXVec3TransformCoord(&temp, vPtr, &proj); // as well as this?
	vPtr->x += temp.x*ptCursor.x; // this doesn't work
}

I read a post here that said you multiply the Vertex by the view matrix, then the projection matrix...

#2 Trip99

    New Member

  • Members
  • Pip
  • 8 posts

Posted 20 September 2005 - 04:49 PM

Hi, model space is how you define your model in an editor e.g. 3ds max and normally 0,0,0 is the centre. To put this model in your game world you will obviously need to move it so you apply a world matrix transformation that takes the vertices from model space to world space. You also want to view the world from a set position via a camera and so you next need to transform from world space into view space by setting the view matrix. Finally the 3D data needs to be converted to 2D screen data. This is done by applying a perspective transform and takes the data from view space to screen space.

So the calc is view matrix * world matrix * projection matrix

So there are three matrices, world, view and perspective. These can all be set in Direct3D by using SetTransform and they will cause the vertices to be transformed by Direct3D or the graphics card (if HW support available).

Doing it manually as you are above is very slow, so unless you have a particular reason to do it like this I would just set the matrix.
See my games site at: www.toymaker.info

#3 bladder

    DevMaster Staff

  • Moderators
  • 1057 posts

Posted 21 September 2005 - 02:26 AM

I think he's tring to click on a mesh and drag around?

Algo would be something like:
- click and check if a mesh is selected
- while mouse button is down
- - transform mouse coord to world space coord
- - set world transform of object to calculated world space coord





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users