• 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
Anddos

Setting a new mouse location with mouse

6 posts in this topic

What i want todo is set a new target to move to using the mouse, this is for the directx sdk sample , "multianimation" , when it picks a new location to move to it uses this function...

[code]
void CTiny::ChooseNewLocation( D3DXVECTOR3* pV )
{


pV->x = ( float )( rand() % 256 ) / 256.f;
pV->y = 0.f;
pV->z = ( float )( rand() % 256 ) / 256.f;

}
[/code]

so instead of using this i want to use my own which is take the mouse 2d point and turn it in to a 3d vector position ...

[code]
void CTiny::SetNewClickTarge(D3DXVECTOR3* pV)
{
GetCursorPos(&point);
src.x = (int)point.x;
src.z = (int)point.y;
DXUTGetD3D9Device()->GetTransform(D3DTS_VIEW,&viw);
DXUTGetD3D9Device()->GetTransform(D3DTS_PROJECTION,&prj);
DXUTGetD3D9Device()->GetTransform(D3DTS_WORLD,&wld);


//D3DXMatrixIdentity(&wld);
DXUTGetD3D9Device()->GetViewport(&v9);


D3DXVec3Unproject(&r,&src,&v9,&prj,&viw,&wld);
pV->x = r.x;
pV->y = r.y;
pV->z = r.z;
}
[/code]

when i run the sample and tick control , and move the mouse around nothing seems to happen?
0

Share this post


Link to post
Share on other sites
You cannot really convert a 2D point on the screen to a 3D point in the scene without additional specification, because a single 2D position on the screen corresponds to infinite number of points in 3D forming a line, or [i]ray[/i].

Try to google [i]mouse picking[/i]. There also is an example in the DirectX SDK, called [b]Pick[/b]. The example does a little bit more than what you need, it:
- builds the ray from the mouse position,
- casts the ray in the 3D space and tests which mesh it intersects with (and even which triangle of the mesh).

You need the first part (build the ray) and then I guess you'll probably want to find the intersection of this ray with a plane defined as [b]y = 0[/b] (the [b]x-z [/b]plane). That will be your point. This step is just simple mathematics.

Few other notes:
- GetCursorPos returns the mouse position in screen coordinates. If your application runs in window, this coordinates will be completely unimportant and wrong for you. I would suggest using the windows messages, namely [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms645616%28v=vs.85%29.aspx"]WM_MOUSEMOVE[/url].
- It's better to avoid using the GetXXXX methods of the d3d9device. You should keep your own copies of the world, view, proj matrices. After all, it's you who created these matrices, so there really is no reason to set them first (by SetTransform) and then ask for them (by GetTransform).
1

Share this post


Link to post
Share on other sites
I dont need to intersect with a mesh , just find out the 3d position from a 2d position mate.
0

Share this post


Link to post
Share on other sites
And are you sure you did read my WHOLE post, including the following parts?


[quote name='Tom KQT' timestamp='1334563603' post='4931662']
You cannot really convert a 2D point on the screen to a 3D point in the scene without additional specification, because a single 2D position on the screen corresponds to infinite number of points in 3D forming a line, or [i]ray[/i].

....

You need the first part (build the ray) and then I guess you'll probably want to find the intersection of this ray with a plane defined as [b]y = 0[/b] (the [b]x-z [/b]plane). That will be your point. This step is just simple mathematics.
[/quote]
0

Share this post


Link to post
Share on other sites
You actually DO need to intersect with a mesh, in a manner of speaking. As Tom KQT state, you can not reverse-project a screen point to a single 3D point without additional information--namely, the depth of the point to project. Some reverse-projections will perform a read of the depth buffer to get the depth of the pixel at the mouse location, but if your purpose as stated is to find a target to move to, then this might not be optimal since the depth of the pixel might not lie on the movable area; it might be a piece of blocking geometry instead.

In your case, you need to compute the ray corresponding to the mouse location, then test intersection of that ray with any geometry forming the walkable or movable area, to find the point to move to. In the case that your walkable area is a simple flat plane, then this case is trivial and doesn't actually require testing against the geometry of your scene. Instead, you can just solve the case of the intersection of the ray against the ground plane.
0

Share this post


Link to post
Share on other sites
what space does my ray need to be in then if the floor transform is like this

[code]
V( g_pEffect->SetTexture( "g_txScene", g_pTxFloor ) );
V( g_pEffect->SetMatrix( "g_mWorld", &g_mxFloor ) );
[/code]

this is my pick code

[code]
void detect_picking(IDirect3DDevice9* pd3dDevice)
{
// get the current transform matrices
D3DXMATRIX matProjection, matView, matWorld, matInverse;
pd3dDevice->GetTransform(D3DTS_PROJECTION, &matProjection);
pd3dDevice->GetTransform(D3DTS_VIEW, &matView);
//pd3dDevice->GetTransform(D3DTS_WORLD, &matWorld);
g_pEffect->GetMatrix("g_mWorld",&matWorld);

// use the mouse coordinates to get the mouse angle
POINT MousePos;
GetCursorPos(&MousePos);
float xAngle = (((2.0f * MousePos.x) / 800) - 1.0f) / matProjection(0, 0);
float yAngle = (((-2.0f * MousePos.y) / 600) + 1.0f) / matProjection(1, 1);

D3DXVECTOR3 origin, direction;
origin = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
direction = D3DXVECTOR3(xAngle, yAngle, 1.0f);

// find the inverse matrix
D3DXMatrixInverse(&matInverse, NULL, &(matWorld * matView));

// convert origin and direction into model space
D3DXVec3TransformCoord(&origin, &origin, &matInverse);
D3DXVec3TransformNormal(&direction, &direction, &matInverse);
D3DXVec3Normalize(&direction, &direction);

// detect picking
BOOL hit;
D3DXIntersect(g_pMeshFloor, &origin, &direction, &hit, NULL, NULL, NULL, NULL, NULL, NULL);
if(hit)
pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
else
pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
}
[/code]

it seems to set the foor to wireframe no matter where the mouse is
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