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

Converting the mouse position to

11 posts in this topic

I'm in the process of making a 2d game, and have made a transition from using d3d's 2D scene to just using 3d quads, however this is giving me a bit of issues with mouse control. While yes the mouse position is indeed moving in the direction I am moving my mouse physically, it is moving at a different rate. I am wandering how one would deal with this? my screen is 800/600 and my view transform matrix is 600 units away on the z axis, looking at everything from a distance.

0

Share this post


Link to post
Share on other sites

If you mean that you went from using a 2-d orthographic projection matrix to using a 3-d perspective projection matrix, then you are going to have to think in terms of a view frustum. Because the virtual world your camera is looking at is now 3-d dimensional along the z-axis, the width of the horizon is now specified in world coordinates, not simply 0..599 like in 2-d.

 

Can you give more details about your projection matrix and what you are trying to accomplish?

2

Share this post


Link to post
Share on other sites

I'm in the process of making a 2d game, and have made a transition from using d3d's 2D scene to just using 3d quads, however this is giving me a bit of issues with mouse control. While yes the mouse position is indeed moving in the direction I am moving my mouse physically, it is moving at a different rate. I am wandering how one would deal with this? my screen is 800/600 and my view transform matrix is 600 units away on the z axis, looking at everything from a distance.

As Steve said, if you are using a perspective matrix, you need to translate your screen coordinates to world coordinates. look up UnProject/Project functions to accomplish this for generic perspective/view matrixs. Edited by slicer4ever
1

Share this post


Link to post
Share on other sites

If you mean that you went from using a 2-d orthographic projection matrix to using a 3-d perspective projection matrix, then you are going to have to think in terms of a view frustum. Because the virtual world your camera is looking at is now 3-d dimensional along the z-axis, the width of the horizon is now specified in world coordinates, not simply 0..599 like in 2-d.

 

Can you give more details about your projection matrix and what you are trying to accomplish?

1So these are the Matrices I have set up for my camera.

 D3DXMatrixLookAtLH(&mCamera,	
    &D3DXVECTOR3 (0, 0, 600),    // the camera position
    &D3DXVECTOR3 (0, 0, 0.0f),      // the look-at position
    &D3DXVECTOR3 (0.0f, -1.0f, 0.0f));    // the up direction

	D3DXMatrixPerspectiveFovLH(&mLense,
                               D3DXToRadian(45),//Field of view
                               _w / _h,//dimensions or somethin
                               1.0f,    // the near view-plane
                               1000.0f);    // the far view-plane
// set the view transform
d3ddev->SetTransform(D3DTS_VIEW, &(camera->GetCamera()));
 
    // set the projection transform
d3ddev->SetTransform(D3DTS_PROJECTION, &(camera->GetLense()));
 

What I'm doing is creating a level editing program for a game I am making, there is a grid on the screen and I wish to make it so that when I click on one of the tiles it changes to the type of tile i have selected. I have just been using the getcursorpos() and screentoclient() to find the mouse position, but since this isn't a flat 2d program those co-ordinates aren't lining up with what I see on screen.

Edited by ThePointingMan
0

Share this post


Link to post
Share on other sites

ThePointingMan, on 04 Apr 2013 - 03:50, said:

Steve_Segreto, on 04 Apr 2013 - 03:15, said:
If you mean that you went from using a 2-d orthographic projection matrix to using a 3-d perspective projection matrix, then you are going to have to think in terms of a view frustum. Because the virtual world your camera is looking at is now 3-d dimensional along the z-axis, the width of the horizon is now specified in world coordinates, not simply 0..599 like in 2-d.

Can you give more details about your projection matrix and what you are trying to accomplish?

1So these are the Matrices I have set up for my camera.
 D3DXMatrixLookAtLH(&mCamera,	
    &D3DXVECTOR3 (0, 0, 600),    // the camera position
    &D3DXVECTOR3 (0, 0, 0.0f),      // the look-at position
    &D3DXVECTOR3 (0.0f, -1.0f, 0.0f));    // the up direction

	D3DXMatrixPerspectiveFovLH(&mLense,
                               D3DXToRadian(45),//Field of view
                               _w / _h,//dimensions or somethin
                               1.0f,    // the near view-plane
                               1000.0f);    // the far view-plane
// set the view transform
d3ddev->SetTransform(D3DTS_VIEW, &(camera->GetCamera()));

// set the projection transform
d3ddev->SetTransform(D3DTS_PROJECTION, &(camera->GetLense()));

What I'm doing is creating a level editing program for a game I am making, there is a grid on the screen and I wish to make it so that when I click on one of the tiles it changes to the type of tile i have selected. I have just been using the getcursorpos() and screentoclient() to find the mouse position, but since this isn't a flat 2d program those co-ordinates aren't lining up with what I see on screen.

I don't know the directX naming conventions for Project/UnProject(they might not exist, and you'll have to implement them yourself). but basically this is what i'd do in pseudo-code:
  Matrix View = GetViewMatrix(); //Get our view matrix(your lookat function might return this, or it might directly set the matrix to the gpu?)
  Matrix Perspective = GetPerspectiveMatrix(); //Get our perspective matrix.
  Vector2 MouseScreen = GetMouseScreenCoordinates(); //Get the screen coordinates that are relative to the window.
  Vector3 WorldNear = UnProject(MouseScreen.X, MouseScreen.Y, 0.0f, View, Perspective); //We get the world coordinates that are at the camera's near plane.
  Vector3 WorldFar = UnProject(MouseScreen.X, MouseScreen.Y, 1.0f, View, Perspective); //We get the world coordinates that are at the camera's far plane.
  //Since the game tile's world position z-depth is at 0(note that the camera is at 600, but the object's are at 0 on the z-axis(or so i assume anyway)).
  //We basically have a ray from the front of the camera, to the back of the camera, now we just need to get the point on the plane that the game is on:
  Vector3 WorldDir = WorldFar-WorldNear;
  float D = WorldNear.Z/WorldDir.Z; //since our plane is along the z axis, we can assume that the A and B components of the plane are 0, and the C component is 1. and that the Distance of the plane is also 0, which simplifies our calculations. down to the near/dir. (see: [url="http://www.yaldex.com/game-programming/0131020099_ch22lev1sec2.html"]http://www.yaldex.com/game-programming/0131020099_ch22lev1sec2.html[/url]
  Vector3 WorldPoint = WorldNear+WorldDir*D; //you can take the x/y position and treat these values the same way you did when the game was 2D.  You don't need the z value unless your game world has actual depth.
And that's basically the gist of it.
1

Share this post


Link to post
Share on other sites

I have the code to do this using gluUnproject, but apparently, im too noob to help so, too bad...

-6

Share this post


Link to post
Share on other sites

I do not know if this would help, I do not use this language, But when I did the same thing in the language I use,  I had to relocate the call to the function to draw the mouse to a different section of the Draw/Renderworld Loop.

 

  Where as I had the mouse draw prior to updating the world, I had to move it to after the update/render world code and then do a page flip.

 

This solved my problem as it was much like yours.

 

Again!!  I stress that I am using a different language!!

0

Share this post


Link to post
Share on other sites

Firstly, thankyou very much Slice4Ever andEndurion, you two have been a great help. I'm still having a wee bit of trouble with the Unproject function though. D3d's unproject looks like this

 

 

D3DXVECTOR3* D3DXVec3Unproject(
_Inout_  D3DXVECTOR3 *pOut,
_In_     const D3DXVECTOR3 *pV,
_In_     const D3D10_VIEWPORT *pViewport,
_In_     const D3DXMATRIX *pProjection,
_In_     const D3DXMATRIX *pView,
_In_     const D3DXMATRIX *pWorld
);
 

As far as I can tell I should be putting the vector holding the mouse co-ords for pV,

the projection matrix and view matrix in their places,

but I'm unsure as to what I should be putting in the ViewPort section and pWorld. Honestly I don't even fully understand what a view port is!

 

Edit: Alright, funny that trying to setup the mouse would teach me so much about the camera, at one point I ended up accidentally turning my level editor into a first person shooter! Minus the bullets of course :/ I understand what the view port is now, all is good! Thank you all for your help! For others who may come across this issue, here is something that helped me out a bit. an example of what this should look like using directx's functions http://gamedev.stackexchange.com/questions/44364/zooming-into-mouse-position and MSDN's page on viewports http://msdn.microsoft.com/en-ca/library/windows/desktop/bb206341(v=vs.85).aspx

 

Edit*2: I have noticed one slight error though, I remember dealing with this with my last project but I don't quite remember how. The WS style SYSMENU includes a little bar at the top of the screen, and this is interfering with my mouse position, does anyone know of any ways to work around this?

Edited by ThePointingMan
1

Share this post


Link to post
Share on other sites

I do not know if this would help, I do not use this language, But when I did the same thing in the language I use,  I had to relocate the call to the function to draw the mouse to a different section of the Draw/Renderworld Loop.

 

  Where as I had the mouse draw prior to updating the world, I had to move it to after the update/render world code and then do a page flip.

 

This solved my problem as it was much like yours.

 

Again!!  I stress that I am using a different language!!

Language shouldn't matter, implementation does.

0

Share this post


Link to post
Share on other sites

ThePointingMan, on 04 Apr 2013 - 19:44, said:
Firstly, thankyou very much Slice4Ever andEndurion, you two have been a great help. I'm still having a wee bit of trouble with the Unproject function though. D3d's unproject looks like this


D3DXVECTOR3* D3DXVec3Unproject(
_Inout_  D3DXVECTOR3 *pOut,
_In_	 const D3DXVECTOR3 *pV,
_In_	 const D3D10_VIEWPORT *pViewport,
_In_	 const D3DXMATRIX *pProjection,
_In_	 const D3DXMATRIX *pView,
_In_	 const D3DXMATRIX *pWorld
);
As far as I can tell I should be putting the vector holding the mouse co-ords for pV,
the projection matrix and view matrix in their places,
but I'm unsure as to what I should be putting in the ViewPort section and pWorld. Honestly I don't even fully understand what a view port is!

Edit: Alright, funny that trying to setup the mouse would teach me so much about the camera, at one point I ended up accidentally turning my level editor into a first person shooter! Minus the bullets of course :/ I understand what the view port is now, all is good! Thank you all for your help! For others who may come across this issue, here is something that helped me out a bit. an example of what this should look like using directx's functions http://gamedev.stackexchange.com/questions/44364/zooming-into-mouse-position and MSDN's page on viewports http://msdn.microsoft.com/en-ca/library/windows/desktop/bb206341(v=vs.85).aspx

Edit*2: I have noticed one slight error though, I remember dealing with this with my last project but I don't quite remember how. The WS style SYSMENU includes a little bar at the top of the screen, and this is interfering with my mouse position, does anyone know of any ways to work around this?

In old openGL(i.e. 1.1/2.0) the view matrix was called the modelview matrix, which combines both the model matrix, and the view matrix. from my understanding of that function, it expects the view matrix(your camera matrix) is separate from the model(or world) matrix.

the viewport(as you've discovered), is simply the actual window rectangle that your world is drawn into, it's useful for making split-screen games, and for rendering to small framebuffers for post-processing effects.

as for your last edit, in my implementation of reading mouse input, i read the mouse messages passed from windows. Which takes care of making sure the mouse is actually the top left of the drawable window. however if i remember correctly(and it's been awhile since i've had to do it on windows) you needed to get the window client size, and subtract that from the total window size to get the correct offset? But you'll have to do a bit more googling as I don't remember the exact implementation.
1

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