• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
VitaliBR

Control Of Bone

38 posts in this topic

[font="arial, sans-serif"][size="2"]I'm trying to control your character's arm, and make it point to where your cursor is on the screen (so it aim the gun where the mouse)[/size][/font]
[font="arial, sans-serif"] [/font]


[font="arial, sans-serif"][size="2"]So:[/size][/font]
[font="arial, sans-serif"][/font][code]void SKINNEDMESH::UpdateMatrices(bool bones, BONE* bone, D3DXMATRIX *parentMatrix)
{
if(bones)
{
if(parentMatrix != NULL)
{
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;
if(mouseLocation.x > m_Width/2)
{
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;
}
else
{
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;
}
}
else
{
D3DXMatrixMultiply(&bone->CombinedTransformationMatrix,
&bone->TransformationMatrix,
parentMatrix);
}
}
else
bone->CombinedTransformationMatrix = bone->TransformationMatrix;


if(bone->pFrameSibling)
{
UpdateMatrices(bones, (BONE*)bone->pFrameSibling, parentMatrix);
}
if(bone->pFrameFirstChild)
{
UpdateMatrices(bones, (BONE*)bone->pFrameFirstChild, &bone->CombinedTransformationMatrix);
}
}
else
{
if(bone != NULL)
D3DXMatrixMultiply(&bone->CombinedTransformationMatrix,
&bone->TransformationMatrix,
parentMatrix);
else
bone->CombinedTransformationMatrix = bone->TransformationMatrix;


if(bone->pFrameSibling)
UpdateMatrices(bones, (BONE*)bone->pFrameSibling, parentMatrix);
if(bone->pFrameFirstChild)
UpdateMatrices(bones, (BONE*)bone->pFrameFirstChild, &bone->CombinedTransformationMatrix);
}}[/code]
[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"][size="3"][size="2"]But he does not move properly in the direction that the mouse cursor is, why?[/size][/size][/font]
[font="arial, sans-serif"][size="3"][size="2"]as, I move the mouse, it moves very little, but in reverse (back)[/size][/size][/font]
[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"][size="3"][size="2"]Thanks[/size][/size][/font]
[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"][size="2"]I'm sending a video to youtube with my problem, wait [/size][/font][img]http://public.gamedev.net/public/style_emoticons/default/rolleyes.gif[/img]
0

Share this post


Link to post
Share on other sites
The video with problem:

[url="http://www.youtube.com/watch?v=nYjT5iXXXaE"]http://www.youtube.com/watch?v=nYjT5iXXXaE[/url]

Thanks [img]http://public.gamedev.net/public/style_emoticons/default/smile.gif[/img]
0

Share this post


Link to post
Share on other sites
[quote name='VitaliBR' timestamp='1294601091' post='4756153']
The video with problem:

[url="http://www.youtube.com/watch?v=nYjT5iXXXaE"]http://www.youtube.c...h?v=nYjT5iXXXaE[/url]

Thanks [img]http://public.gamedev.net/public/style_emoticons/default/smile.gif[/img]
[/quote]

In your "world" (as shown in the video), which direction is the Y axis? You're adding a rotation about the Y axis to "aim" the bone. Is that the correct axis?
1

Share this post


Link to post
Share on other sites
[quote name='Buckeye' timestamp='1294602140' post='4756177']
In your "world" (as shown in the video), which direction is the Y axis? You're adding a rotation about the Y axis to "aim" the bone. Is that the correct axis?
[/quote]

[font=arial, sans-serif][size="2"]The Y-Axis is "up" and "down",[/size][/font]
[font=arial, sans-serif][size="2"]I used another class for SkinnedMesh, and it worked perfectly, but I had to create a new class, because there was conflict with my octree and now this new class as it is going wrong in the video :([/size][/font]
0

Share this post


Link to post
Share on other sites
You add a rotation about the Y axis to move the arm. As asked above but not answered: is that the correct axis for your model's local arm? You might try changing to D3DXMatrixRotationX or Z.

EDIT: The method you're using assumes the [b]local[/b] Y axis for the bone is into/out-of the screen.
0

Share this post


Link to post
Share on other sites
[quote name='Buckeye' timestamp='1294671069' post='4756665']
You add a rotation about the Y axis to move the arm. As asked above but not answered: is that the correct axis for your model's local arm? You might try changing to D3DXMatrixRotationX or Z.

EDIT: The method you're using assumes the [b]local[/b] Y axis for the bone is into/out-of the screen.
[/quote]

[font="arial, sans-serif"][size="2"]I tried using the axis X or Z, but the results were wrong, if you watch the video (720p in fullscreen), you will see that the arm moves in the right direction, but it moves very little,[/size][/font]
[size="2"][font="arial, sans-serif"]and when it is facing to the left, [/font][font="arial, sans-serif"]the arm is back [/font][/size][img]http://public.gamedev.net/public/style_emoticons/default/blink.gif[/img]
0

Share this post


Link to post
Share on other sites
First, solve one problem at a time. You're apparently changing the facing direction of the entire model based on the location of the mouse. Until you can get the arm to point to the correct location, [i]don't do that![/i].

Second, double-check that the mouse location you're using is in client (not screen) coordinates.

Then, you need to determine the [b]local[/b] axis for the bone which, when multiplied by the bone's parent's matrices, points into/out-of the screen. That's the axis about which you want to add the rotation based on the mouse position. You can experiment a bit by guessing at various axes - something like:
[code]
D3DXVECTOR3 guessAxis(0,0,1);
D3DXVec3TransformNormal(&guessAxis,&guessAxis,&final);
// Now check if guessAxis is the axis for your system that points into/out-of the screen
[/code]
When you find the correct axis, use that for your D3DXRotation function. Then you can play around with changing the direction of the model.

EDIT: More simply, determine the axis that points into/out-of your screen. Then:
[code]
D3DXVECTOR3 screenAxis(...); // set this to the axis in/out of screen - USE A UNIT VECTOR
D3DXMATRIX invFinal;
D3DXMatrixInverse(&invFinal,NULL,&final);
D3DXVec3TransformNormal(&screenAxis,&screenAxis,&invFinal);
[/code]
After the conversion, screenAxis will be the axis about which you need to rotate with respect to the mouse position.
1

Share this post


Link to post
Share on other sites
[size="2"][font="arial, sans-serif"]I'm not rotating the model as the mouse position [/font][font="arial, sans-serif"](as you told me not to do)[/font][/size]
[font="arial, sans-serif"][size="2"]See how it's the code:[/size][/font]
[font="arial, sans-serif"][size="2"][code]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 cal
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;]
}[/code][/size]
[/font]

[font="arial, sans-serif"][size="2"]But still the same problem, and now I realized that as I move the player up or down, I'mcontrolling the bone moves alone, see the video when the player starts to fly upwards[/size][/font]Look:
[url="http://www.youtube.com/watch?v=vm6W1SjZsag"]http://www.youtube.c...h?v=vm6W1SjZsag[/url]

[font="arial, sans-serif"][size="2"]And I'm passing the Coordinators of the mouse as follows:[/size][/font]
[font="arial, sans-serif"][size="2"][code]GetCursorPos(&absCursor);
///////////////////////////////////////////////////////
// Get matrices and the viewport
///////////////////////////////////////////////////////
D3DXMATRIX pm; // projection matrix
D3DXMATRIX vm; // view matrix
D3DVIEWPORT9 vp; //viewport

m_pDevice->GetTransform(D3DTS_PROJECTION, &pm);
m_pDevice->GetTransform(D3DTS_VIEW, &vm);
m_pDevice->GetViewport(&vp);

D3DXVECTOR3 mouseLocation((float)absCursor.x,(float)absCursor.y,0);
player->mouselocal(mouseLocation, WIDTH, pm, vm,vp);[/code][/size][/font]
0

Share this post


Link to post
Share on other sites
You're trying to solve too many problems at once. Work on one problem at a time. You apparently haven't gotten the arm rotation fixed, so you shouldn't be worrying about "flying." When you introduce new functions and variables, it's too difficult to help you, particularly since you don't answer questions that're necessary to understand what you're doing.

For instance, I don't know what player->mouselocal(...) does. I would suggest, for clarity:
[code]
GetCursorPos(&absCursor);
ScreenToClient(hWnd,&absCursor); // hWnd = the handle to your DirectX window
D3DXVECTOR3 mouseLocation( absCursor.x, absCursor.y, 0 ); // mouse in client coordinates
[/code]
Also, you're still rotating the arm about the Y axis. Did you determine that's the correct axis to rotate about?
0

Share this post


Link to post
Share on other sites
[size="2"][quote name='Buckeye' timestamp='1294768783' post='4757299']
For instance, I don't know what player->mouselocal(...) does.
[/quote]

the player->mouselocal(...) [font="arial, sans-serif"]given parameters such as viewport, etc...[/font]
[font="arial, sans-serif"][code]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;}[/code]
[/font]
[font="arial, sans-serif"]
[/font]
[quote name='Buckeye' timestamp='1294768783' post='4757299']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"][/quote][/font]
[font="arial, sans-serif"]Yes, I tested the three axis and the axis is correct to rotate the Y[/font]
[font="arial, sans-serif"]
[/font]
[font="arial, sans-serif"][font="arial, verdana, tahoma, sans-serif"][quote name='Buckeye' timestamp='1294768783' post='4757299'][font="arial, sans-serif"][color="#1C2837"][font="arial, verdana, tahoma, sans-serif"]I would suggest, for clarity:[/font][/color][/quote][/font][/font][/font]
[font="arial, sans-serif"][font="arial, verdana, tahoma, sans-serif"][font="arial, sans-serif"]I need to study a way of passing 'the handle' for my class, so I can use theScreenToClient[/font][/font][/font][/size]
0

Share this post


Link to post
Share on other sites
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."
0

Share this post


Link to post
Share on other sites
[quote name='Buckeye' timestamp='1294771244' post='4757327']
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."
[/quote]

There is no function where I can "get" the handle? such as I "get" the viewport:
[code]
D3DVIEWPORT9 vp; //viewport

m_pDevice->GetViewport(&vp);[/code]
0

Share this post


Link to post
Share on other sites
[quote name='VitaliBR' timestamp='1294780844' post='4757364']
There is no function where I can "get" the handle? such as I "get" the viewport:
[code]
D3DVIEWPORT9 vp; //viewport

m_pDevice->GetViewport(&vp);[/code]

[/quote]
When you setup your device present parameters, don't you use a window handle?
0

Share this post


Link to post
Share on other sites
[quote name='Buckeye' timestamp='1294785031' post='4757402']
When you setup your device present parameters, don't you use a window handle?
[/quote]

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

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

virtual void Update() = 0;
virtual void Draw() = 0;
};[/code][/size][/font]

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

Share this post


Link to post
Share on other sites
[quote name='VitaliBR' timestamp='1294785776' post='4757407']
[font="arial, sans-serif"][size="2"]Yes, I use, but i use ScreenManager
<snippet removed>
[/size][/font][font="arial, sans-serif"][size="2"]EDIT:[/size][/font]
[font="arial, sans-serif"][size="2"]This function does exactly what?[/size][/font]
[font="arial, sans-serif"][size="2"][url="http://msdn.microsoft.com/en-us/library/aa344214(v=vs.85).aspx"]http://msdn.microsof...4(v=vs.85).aspx[/url][/size][/font]
[/quote]
Sounds like you should be using an interface that helps you rather than hinders you. So why not change the interface to do what [i]you[/i] 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.
0

Share this post


Link to post
Share on other sites
[font="arial, sans-serif"][size="2"]I modified my class and now I'm doing this:[/size][/font]
[font="arial, sans-serif"][size="2"][code]GetCursorPos(&absCursor);
ScreenToClient(hWnd,&absCursor); // hWnd = the handle to your DirectX window
D3DXVECTOR3 mouseLocation( absCursor.x, absCursor.y, 0 ); // mouse in client coordinates[/code]
[/size][/font]
[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"][size="2"]The hand is straight and now moves toward the table as the mouse moves, but is moving very little[/size][/font]
0

Share this post


Link to post
Share on other sites
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:
[code]
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.
}
[/code]
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.

0

Share this post


Link to post
Share on other sites
[size="2"][font="arial, sans-serif"]Just anticipating some results, I took the test asyou said in the Y axis:[/font][/size]
[font="arial, sans-serif"][size="2"][code] 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;
}[/code][/size]
[/font]
[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"][size="2"]See how it:[/size][/font]
[font="arial, sans-serif"][size="2"][url="http://www.youtube.com/watch?v=t_3-hRqhSus"]http://www.youtube.c...h?v=t_3-hRqhSus[/url][/size][/font]
0

Share this post


Link to post
Share on other sites
Good job. It appears that the bone's local Y axis is pointing [i]out[/i] 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:
[code]
dev->SetTransform(D3DTS_WORLD, &modelWorld);
// draw the model
[/code]
then you need to use the same modelWorld in the D3DXVec3Project call:
[code]
D3DXVec3Project(&boneLocation,&boneLocation,&m_vp,&m_pm,&m_vm,&modelWorld);
[/code]
0

Share this post


Link to post
Share on other sites
[quote name='Buckeye' timestamp='1294886178' post='4758114']
Good job. It appears that the bone's local Y axis is pointing [i]out[/i] 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:
[code]
dev->SetTransform(D3DTS_WORLD, &modelWorld);
// draw the model
[/code]
then you need to use the same modelWorld in the D3DXVec3Project call:
[code]
D3DXVec3Project(&boneLocation,&boneLocation,&m_vp,&m_pm,&m_vm,&modelWorld);
[/code]
[/quote]

[font="arial, sans-serif"][size="2"]But not sure how I'm doing using the identity matrix?[/size][/font]
[font="arial, sans-serif"][size="2"][code]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;[/code]
[/size][/font]
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
[font="arial, sans-serif"][size="2"]Ok, I did as you said, the arm responds to the mouse, but moves very little, not totally in sync with the cursor[/size][/font]
[code] 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;[/code]
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
[font=arial, sans-serif][size="2"]I do not know if these data shall go help on something, but I did as follows:[/size][/font][code] 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;

Logging->LogMessage(MSG_INFO,"mouseLocation.x ",mouseLocation.x);
Logging->LogMessage(MSG_INFO,"mouseLocation.y ",mouseLocation.y);
Logging->LogMessage(MSG_INFO,"mouseLocation.z ",mouseLocation.z);
Logging->LogMessage(MSG_INFO,"dir.x ",dir.x);
Logging->LogMessage(MSG_INFO,"dir.y ",dir.y);
Logging->LogMessage(MSG_INFO,"dir.z ",dir.z);

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;[/code]

Look the data:
[quote]INFO: boneLocation.x -60.4733
INFO: boneLocation.y 853.739
INFO: boneLocation.z 0.947493
INFO: mouseLocation.x -56
INFO: mouseLocation.y 74
INFO: mouseLocation.z 0
INFO: dir.x 4.47333
INFO: dir.y -779.739
INFO: dir.z -0.947493
INFO: boneLocation.x -60.4733
INFO: boneLocation.y 853.739
INFO: boneLocation.z 0.947493
INFO: mouseLocation.x -105
INFO: mouseLocation.y 174
INFO: mouseLocation.z 0
INFO: dir.x -44.5267
INFO: dir.y -679.739
INFO: dir.z -0.947493
INFO: boneLocation.x -60.4733
INFO: boneLocation.y 853.739
INFO: boneLocation.z 0.947493
INFO: mouseLocation.x -115
INFO: mouseLocation.y 225
INFO: mouseLocation.z 0
INFO: dir.x -54.5267
INFO: dir.y -628.739
INFO: dir.z -0.947493
INFO: boneLocation.x -60.4733
INFO: boneLocation.y 853.739
INFO: boneLocation.z 0.947493
INFO: mouseLocation.x -99
INFO: mouseLocation.y 225
INFO: mouseLocation.z 0
INFO: dir.x -38.5267
INFO: dir.y -628.739
INFO: dir.z -0.947493
INFO: boneLocation.x -60.4733
INFO: boneLocation.y 853.739
INFO: boneLocation.z 0.947493
INFO: mouseLocation.x 159
INFO: mouseLocation.y 79
INFO: mouseLocation.z 0
INFO: dir.x 219.473
INFO: dir.y -774.739
INFO: dir.z -0.947493
INFO: boneLocation.x -60.4734
INFO: boneLocation.y 853.739
INFO: boneLocation.z 0.947493
INFO: mouseLocation.x 427
INFO: mouseLocation.y 65
INFO: mouseLocation.z 0
INFO: dir.x 487.473
INFO: dir.y -788.739
INFO: dir.z -0.947493
INFO: boneLocation.x -60.4734
INFO: boneLocation.y 853.739
INFO: boneLocation.z 0.947493
INFO: mouseLocation.x 586
INFO: mouseLocation.y 106
INFO: mouseLocation.z 0
INFO: dir.x 646.473
INFO: dir.y -747.739
INFO: dir.z -0.947493[/quote]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0