Hi,
a thing that I need for all the 3D games I make is the mouse, but I haven't found a good tutorial to combine Mouse and Graphics.
I'm using Direct3D7.
I wonder how I can transform the (x,y) coordinates of the mouse into 3D space. (And I know de Y-coordinate of the destination space, not X and Y)
(picking?)
Do I have to proceed like this?
transform Pmouse(x,y) 3 times:
1. projection matrix ^-1
2. view matrix ^-1
3. world matrix ^-1
Questions:
1) True?
2) Is there a function in VB to make the inverse matrix?
3) Why are there 4 rows and cols in those 3 matrices (x,y,z,?)
4) Is there a good tutorial for this problem (DX7! + VB6)
I can find the coords of the mouse easily, but I don't know how to transform those coordinates into Direct3D's 3D world. it's more a direct3d (7) question than a mouse question... (That tutorial had no relation with direct3d)
But thanks for the try!
DixCie
Like what do you mean? Using the Y coordinates as Z? It's that simple. Just use the Y coordinates as Z coordinates. You can't move the mouse in a 3-axis coordinate system (XYZ). It can only move 2-axises (XY). So yeah, you get the picture.
You can try downloading anyone of my projects at
www.angelfire.com/fl5/memorydll/index.html. That shows you controling the camera with the mouse as well as the numpad keys. For the Y axis in my code, just replace the Camera_Angle_X with Camera_Position_Z in the mouse event callback located in FrmMain.
[Edit]No better yet, something like this only it needs modified a bit to work with the mouse. I don't have VB in front of me so I can't test it now:
No JACOB, he wants to go from screen space (x,y) to world space (x,y,z)
It is done by extrapolating from screen space through the projection and camera matrix.
I had a function which did this very easily, I was going to share it but I cannot find it anywhere.
To determine the exact point, for example if you are clicking on a unit, you fire a ray from your screen space through to the 3d world and keep it going until it colldes with anything, that is where the user clicked...
Sorry I can't provide any tutorials or source.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
Using the Vertex_Out() variables, you test for a mouse click within that region by just using its X and Y variables. If it passes, you can have it do whatever you want.
Is this what you meant? Or was it the other way around. If it's the other way around, then you have to use DirectX's D3DXVec3Unproject with the Vertices() being your mouse coordinates.
Last edited by Jacob Roman; Apr 25th, 2005 at 07:35 PM.
Using D3DXVec3Unproject, it'll just convert screen coordinates to World coordinates. No math needed. It does it for you. Same goes with D3DXVec3Project only you get opposite results.
I believe the math part you are talking about might have something to do with testing to see if the mouse is within the 3D coordinates after the conversion is made, right?
This is in OpenGL and in C++ but it might help. Converting it to DX and VB6 wouldn't be a problem.
Last edited by Jacob Roman; Apr 25th, 2005 at 08:46 PM.
(I tried to add DirectX8 to the project, but he gave an error on that line: 'Type d'argument ByRef incompatible' (FR) => any solutions?
=> matInverse is a D3Dmatrix, but maybe for DX7 instead of DX8???)
(but on this site I find the VectorMatrixMultiply function )
I still wonder how I can find matInverse...
Last edited by dixcie; Apr 27th, 2005 at 10:23 AM.
Hey, while we are on the subject of clicking polygons in 3D coordinates and all of that, what if you have a quad with a texture of a circle, such as a vinyl (which is what's in my DJ program) and you just wanted the the click to be within the radius of that polygon, no matter what angle it appears to be on? That way there, when you make it transparent to reveal just the vinyl, then you wouldn't see weird things like clicking within the invisible corners for when you are gonna scratch.
(I tried to add DirectX8 to the project, but he gave an error on that line: 'Type d'argument ByRef incompatible' (FR) => any solutions?
=> matInverse is a D3Dmatrix, but maybe for DX7 instead of DX8???)
(but on this site I find the VectorMatrixMultiply function )
I still wonder how I can find matInverse...
Theres just one problem with that VB program. It only works with static non moving polygons, although the camera can move freely. That's why I made a thread on Getting Transformed Vertices so I can test that rather than testing the model vertices.