Good job. It appears that the bone's local Y axis is pointing out of the screen - the rotation is clockwise with increasing angle.
For the model, what do you set for the world transform when you render it? The equations you're using assume the model is rendered with an identity world matrix. You need to use the same world matrix for D3DXVec3Project as you do when you render it, to ensure that the projected bone location is in screen space with the mouse location.
I.e., if you render the model something like:
dev->SetTransform(D3DTS_WORLD, &modelWorld);
// draw the model
then you need to use the same modelWorld in the D3DXVec3Project call:
D3DXVec3Project(&boneLocation,&boneLocation,&m_vp,&m_pm,&m_vm,&modelWorld);
[font="arial, sans-serif"]But not sure how I'm doing using the identity matrix?
[font="arial, sans-serif"]D3DXMATRIX ident;
D3DXMatrixIdentity(&ident);
D3DXMATRIX final = bone->TransformationMatrix*(*parentMatrix);
D3DXVECTOR3 boneLocation(final._41,final._42,final._43);
D3DXVec3Project(&boneLocation,&boneLocation,&m_vp,&m_pm,&m_vm,&ident); // use YOUR viewport, projection and view matrices in this call
D3DXVECTOR3 dir = mouseLocation - boneLocation;
The last parameter in the D3DXVec3Project call should be the world matrix for the vector you want projected. If you render the mesh with a world matrix other than the identity matrix, substitute the mesh's world matrix as shown in my post.
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.
You don't forget how to play when you grow old; you grow old when you forget how to play.
[font="arial, sans-serif"]Ok, I did as you said, the arm responds to the mouse, but moves very little, not totally in sync with the cursor D3DXMATRIX ident;
D3DXMATRIX modelWorld;
D3DXMatrixIdentity(&ident);
m_pDevice->SetTransform(D3DTS_WORLD, &modelWorld);
D3DXMATRIX final = bone->TransformationMatrix*(*parentMatrix);
D3DXVECTOR3 boneLocation(final._41,final._42,final._43);
D3DXVec3Project(&boneLocation,&boneLocation,&m_vp,&m_pm,&m_vm,&modelWorld); // use YOUR viewport, projection and view matrices in this call
D3DXVECTOR3 dir = mouseLocation - boneLocation;
float offset = D3DX_PI/2.0f;
float angle = offset - atan2(dir.y,dir.x); // change this when you rotate the model
D3DXMATRIX rot;
D3DXMatrixRotationY(&rot,angle);
bone->CombinedTransformationMatrix = rot*final;
You need to really try to get a better understanding of what you're trying to do. In your code, you don't set the modelWorld matrix to a valid value. You should be using the same world transform that you use when you render the mesh.
Answer for yourself: what world transform is set when the mesh is rendered? For instance, if you're using a shader, what world transform is used by the shader when the mesh is rendered. Use that same transform in the D3DXVec3Project call.
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.
You don't forget how to play when you grow old; you grow old when you forget how to play.
[font=arial, sans-serif]I do not know if these data shall go help on something, but I did as follows: D3DXMATRIX ident;
D3DXMATRIX modelWorld;
D3DXMatrixIdentity(&ident);
m_pDevice->SetTransform(D3DTS_WORLD, &modelWorld);
D3DXMATRIX final = bone->TransformationMatrix*(*parentMatrix);
D3DXVECTOR3 boneLocation(final._41,final._42,final._43);
D3DXVec3Project(&boneLocation,&boneLocation,&m_vp,&m_pm,&m_vm,&modelWorld); // use YOUR viewport, projection and view matrices in this call
Logging->LogMessage(MSG_INFO,"boneLocation.x ",boneLocation.x);
Logging->LogMessage(MSG_INFO,"boneLocation.y ",boneLocation.y);
Logging->LogMessage(MSG_INFO,"boneLocation.z ",boneLocation.z);
D3DXVECTOR3 dir = mouseLocation - boneLocation;
float offset = D3DX_PI/2.0f;
float angle = offset - atan2(dir.y,dir.x); // change this when you rotate the model
D3DXMATRIX rot;
D3DXMatrixRotationY(&rot,angle);
bone->CombinedTransformationMatrix = rot*final;
In your code, you don't set the modelWorld matrix to a valid value. You should be using the same world transform that you use when you render the mesh.
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.
You don't forget how to play when you grow old; you grow old when you forget how to play.
In your code, you don't set the modelWorld matrix to a valid value. You should be using the same world transform that you use when you render the mesh.
[font="arial, sans-serif"]Sorry by my ignorance, but if I'm not doing correctly, how about it?