Control Of Bone

Started by
37 comments, last by VitaliBR 13 years, 3 months ago

For instance, I don't know what player->mouselocal(...) does.


the player->mouselocal(...) [font="arial, sans-serif"]given parameters such as viewport, etc...
[font="arial, sans-serif"]void SKINNEDMESH::mouselocal(D3DXVECTOR3 pos, int Width, D3DXMATRIX pm, D3DXMATRIX vm, D3DVIEWPORT9 vp)
{
mouseLocation = pos;
m_Width = Width;
m_pm = pm;
m_vm = vm;
m_vp = vp;}


[font="arial, sans-serif"]

Also, you're still rotating the arm about the Y axis. Did you determine that's the correct axis to rotate about?[font="arial, sans-serif"]

[font="arial, sans-serif"]Yes, I tested the three axis and the axis is correct to rotate the Y
[font="arial, sans-serif"]

[font="arial, sans-serif"][font="arial, verdana, tahoma, sans-serif"]
[font="arial, sans-serif"][font=&quot;arial, verdana, tahoma, sans-serif&quot;]I would suggest, for clarity:</blockquote><br /> [font=&quot;arial, sans-serif&quot;][font=&quot;arial, verdana, tahoma, sans-serif&quot;][font=&quot;arial, sans-serif&quot;]I need to study a way of passing &#39;the handle&#39; for my class, so I can use theScreenToClient
http://mateusvitali.wordpress.com/
Advertisement
Your "mouselocal" function doesn't convert from screen to client coordinates. I would suspect that's part of the problem. If you're going to calculate angles using mouse and bone locations, both vectors need to be in the same "space."

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.


Your "mouselocal" function doesn't convert from screen to client coordinates. I would suspect that's part of the problem. If you're going to calculate angles using mouse and bone locations, both vectors need to be in the same "space."


There is no function where I can "get" the handle? such as I "get" the viewport:

D3DVIEWPORT9 vp; //viewport

m_pDevice->GetViewport(&vp);

http://mateusvitali.wordpress.com/

There is no function where I can "get" the handle? such as I "get" the viewport:

D3DVIEWPORT9 vp; //viewport

m_pDevice->GetViewport(&vp);



When you setup your device present parameters, don't you use a window handle?

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.


When you setup your device present parameters, don't you use a window handle?


[font="arial, sans-serif"]Yes, I use, but i use ScreenManager, and in class I'm using is derived from this abstract class:
[font="arial, sans-serif"]class IGameScreen
{
public:
IGameScreen() { }
~IGameScreen() { }

virtual bool Initialize(IDirect3DDevice9 *pDevice) = 0;
virtual void Unload() = 0;

virtual void Update() = 0;
virtual void Draw() = 0;
};


[font="arial, sans-serif"]
[font="arial, sans-serif"]And I would be very complicated to have to go through the handler parameter in allclasses of the management screens :(
[font="arial, sans-serif"]If there was a function to get the handler, would be much easier
[font="arial, sans-serif"]
[font="arial, sans-serif"]
[font="arial, sans-serif"]EDIT:
[font="arial, sans-serif"]This function does exactly what?
[font="arial, sans-serif"]http://msdn.microsoft.com/en-us/library/aa344214(v=vs.85).aspx
http://mateusvitali.wordpress.com/

[font="arial, sans-serif"]Yes, I use, but i use ScreenManager
<snippet removed>
[font="arial, sans-serif"]EDIT:
[font="arial, sans-serif"]This function does exactly what?
[font="arial, sans-serif"]http://msdn.microsof...4(v=vs.85).aspx

Sounds like you should be using an interface that helps you rather than hinders you. So why not change the interface to do what you want it to do? E.g., add a GetWindowHandle function to the interface.

Re: The GetHandle function - it apparently has something to do with transactions.

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 modified my class and now I'm doing this:
[font="arial, sans-serif"]GetCursorPos(&absCursor);
ScreenToClient(hWnd,&absCursor); // hWnd = the handle to your DirectX window
D3DXVECTOR3 mouseLocation( absCursor.x, absCursor.y, 0 ); // mouse in client coordinates


[font="arial, sans-serif"]
[font="arial, sans-serif"]The hand is straight and now moves toward the table as the mouse moves, but is moving very little
http://mateusvitali.wordpress.com/
You haven't described how you determined that the Y axis is the correct axis to rotate about. If the local Y axis of the bone doesn't transform to the axis that points in/out of the screen, it won't work correctly.

There're a couple things you can do. I suggest that, first, you confirm you have the right axis by rotating the arm continuously to see if that works. Something like:

static float angle = 0;
if( bone != NULL && ... )
{
angle += 0.01f;
D3DXMATRIX rot;
D3DXMatrixRotationY(&rot,angle);
D3DXMATRIX final = bone->TransformationMatrix * (*parentMatrix);
bone->CombinedTransformationMatrix = rot * final;
// etc.
}

That should cause the arm to rotate continuously, assuming you're updating and rendering continuously.

If that works, output some data from the routine you posted in post #9 above to your debug output window - things like mouse location, bone location, angle, etc., and see if the values are correct as you move the mouse.

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"]Just anticipating some results, I took the test asyou said in the Y axis:
[font="arial, sans-serif"] static float angle = 0;
if(bone->Name != NULL && strcmp(bone->Name,"Bip01_L_UpperArm")==0)
{
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

float offset = D3DX_PI/2.0f;
angle += 0.1;
D3DXMATRIX rot;
D3DXMatrixRotationY(&rot,angle);
bone->CombinedTransformationMatrix = rot*final;
}


[font="arial, sans-serif"]
[font="arial, sans-serif"]See how it:
[font="arial, sans-serif"]http://www.youtube.c...h?v=t_3-hRqhSus
http://mateusvitali.wordpress.com/
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);

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.

This topic is closed to new replies.

Advertisement