Jump to content
  • Advertisement

Archived

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

TheGecko

Rather embarassing question about linear math...

This topic is 6042 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 know I''m supposed to know this (but all my math books are packed away) but I can''t for the love of god remember how to go about solving this. I''ve got my mesh that stores its own center of mass (D3DXVECTOR3 Center) and it''s radius (float Radius). Now after translating my mesh like so:
  
			D3DXMATRIX mat;
			D3DXMatrixTranslation(&mat,10.0f,0.0f,0.0f);
			temp->GetD3DDevice()->SetTransform(D3DTS_WORLD,&(D3DMATRIX)mat);
			mesh.Render();
  
I need to get the NEW center of the object.How do I transform the Center vector to its new position.I know I''m supposed to multiply something by some inverted matrix but I can''t remember and I''m not too sure what the DX function calls are. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Translation is easy. Just add the x, y, and z that you translated the mesh by to the meshes center of mass.

If you want to get real spiffy and allow for rotation and scaling, look up D3DXVec3TransformCoord. Just pass a matrix and a vector and it will trasnform it.

Jack

Share this post


Link to post
Share on other sites
Thanx man...I was looking for that but now I have another problem.I can''t seem to get the transformation matrix from my code above.

You see, the code in my previous post is being called in the main application.Now, in my mesh class I have this function


  
UINT CMesh::Render(void)
{
...
D3DXMATRIX matTrans;
D3DXMatrixIdentity(&matTrans);
device->GetTransform(D3DTS_WORLD,&(D3DMATRIX)matTrans);
...
//Calculate the new center of the mesh from the original

CVector3 Result = m_Mesh.Meshes[i].Center;
Result.m_fx += matTrans(3,0);
Result.m_fy += matTrans(3,1);
Result.m_fz += matTrans(3,2);
...
}


When I check to see if I got the translation values correctly back from the world matrix,it was all wrong.The translation coordinates were all 0.0 instead of (10.0,0.0,0.0)

What am I doing wrong? Or am I getting the wrong matrix for this operation?

Share this post


Link to post
Share on other sites

matTrans(3,0);

Should be

matTrans(0,3);

Remember matrices are (row, column) not (x,y)

HTH, Steve

Steve
DirectX Programmer
Soon to be the new Bill Gates

[edited by - Evil Bill on May 31, 2002 6:11:19 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by TheGecko

When I check to see if I got the translation values correctly back from the world matrix,it was all wrong.The translation coordinates were all 0.0 instead of (10.0,0.0,0.0)

What am I doing wrong? Or am I getting the wrong matrix for this operation?




Are you using a hardware TnL pure device? If so then you cannot rely on the Get* calls (such as GetTransform) because they are not available to pure devices...

Share this post


Link to post
Share on other sites
Evil Bill: That''s right.The matrices are (row,col) and the translation values in the matrix are at (3,0) (3,1) and (3,2). that''s what I''m trying to get.

Sharky: Then what am I supposed to do in order to get that matrix? Right now,I''m passing the matrix as a parameter to my rendering function and that works all fine.But I''m still curious as to how to get the matrix from D3D.

Any ideas?

Share this post


Link to post
Share on other sites
quote:
Original post by TheGecko
Sharky: Then what am I supposed to do in order to get that matrix? Right now,I''m passing the matrix as a parameter to my rendering function and that works all fine.But I''m still curious as to how to get the matrix from D3D.

Any ideas?



What I usually do is create, say, three global matrices - these being the world, view and projection matrices.

D3DMATRIX g_worldMatrix;
D3DMATRIX g_viewMatrix;
D3DMATRIX g_projectionMatrix;

I then have a wrapper function for the Direct3D SetTransform and GetTransform functions, along the lines of...

void SetMyOwnTransform(int transType,D3DMATRIX *mtx);
void GetMyOwnTransform(int transType,D3DMATRIX *mtx);

Whenever I want to set the transform I call my ''Set'' function with the relevant transformation type and matrix...

D3DMATRIX worldMatrix;
SetMyOwnTransform(TRANSTYPE_WORLD,&worldMatrix);

And I call the ''Get'' function when I want to retrieve a particular transformation...

D3DMATRIX viewMatrix;
GetMyOwnTransform(TRANSTYPE_VIEW,&viewMatrix);

Inside the functions I do something along the lines of:


  
void SetMyOwnTransform(int transType,D3DMATRIX *mtx)
{
switch(transType)
{
case TRANSTYPE_WORLD:
// set world matrix

g_worldMatrix = *mtx;
pD3DDevice->SetTransform(D3DTS_WORLD,mtx);
break;

case TRANSTYPE_VIEW:
// set view matrix

g_viewMatrix = *mtx;
pD3DDevice->SetTransform(D3DTS_VIEW,mtx);
break;

case TRANSTYPE_PROJECTION:
// set projection matrix

g_projectionMatrix = *mtx;
pD3DDevice->SetTransform(D3DTS_PROJECTION,mtx);
break;
}
}


void GetMyOwnTransform(int transType,D3DMATRIX *mtx)
{
switch(transType)
{
case TRANSTYPE_WORLD:
// get world matrix

*mtx = g_worldMatrix;
break;

case TRANSTYPE_VIEW:
// get view matrix

*mtx = g_viewMatrix;
break;

case TRANSTYPE_PROJECTION:
// get projection matrix

*mtx = g_projectionMatrix;
break;
}
}


The above is off the top of my head but is similar to a method I use for setting and getting transforms. I hope this makes sense and helps you out a bit!!

Cheers,
Sharky

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!