iNET Interactive - Online Advertising Agency
          
Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Game Programming > DirectX > Mouse coordinates and positioning


Reply
 
Thread Tools Display Modes
  #1  
Old 09-20-2002, 08:52 AM
gav gav is offline
Newcomer
 
Join Date: Dec 2001
Location: England
Posts: 8
Default Mouse coordinates and positioning

Hi,

I'm currently writing a program which requires the coordinates of the mouse to place things within DirectX. The code I'm using is as follows:

Function GetWorldMouseClickPoint() As D3DVECTOR
'return position in the world where the mouse was clicked
g_D3DDevice.GetViewport viewport
vIn.x = CursorX: vIn.y = CursorY: vIn.Z = 0
D3DXVec3Unproject vNear, vIn, viewport, matProj, matView, matWorld
'compute point on far clip plane at cursor
vIn.Z = 1
D3DXVec3Unproject vFar, vIn, viewport, matProj, matView, matWorld
D3DXVec3Subtract vDir, vFar, vNear

t = (-(vFar.Z) / vDir.Z)
GetWorldMouseClickPoint.x = vFar.x + t * vDir.x
GetWorldMouseClickPoint.y = vFar.y + t * vDir.y
end function

and i get the X,Y coordinates of the mouse from ...

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
CursorX = x / Screen.TwipsPerPixelX
CursorY = y / Screen.TwipsPerPixelY
End Sub

The problem I'm having is that the coordinates returned from GetWorldMouseClickPoint don't quite match the movement of the mouse. For example if I move the mouse upwards only, the image which I'm placing at the coordinates of GetWorldMouseClickPoint will appear to move diagonally up and to the left, but its x coordinate will remain the same.

I'm guessing this is something to do with my view or world matrices, but I don't fully understand how they work and so am having trouble finding a solution to my problem. The matrices are set up as follows

sub SetUpView()
D3DXMatrixRotationY matWorld, 0
g_D3DDevice.SetTransform D3DTS_WORLD, matWorld
D3DXMatrixLookAtLH matView, vec3(0#, 0#, camZ), _
vec3(camX, camY, 0), _
vec3(0, 1#, 0#)
g_D3DDevice.SetTransform D3DTS_VIEW, matView
D3DXMatrixPerspectiveFovLH matProj, 3.14159265358979 / 3, 1, 1, 2000
g_D3DDevice.SetTransform D3DTS_PROJECTION, matProj
end sub

the variables CamX and CamY are both = 50 and CamZ = -900.

I should also mention that I'm trying to show everything in 2 Dimensions, however when i move anything, I'm giving it a Z coordinate to match its Y coordinate, so that as something moves up the screen, it also appears to move away. I initially thought that was a possible cause of my problem, but couldn't see a reason why.

I would greatly appreciate any ideas?

Thanks in advance,

Gav.
Reply With Quote
  #2  
Old 09-20-2002, 12:26 PM
Banjo's Avatar
Banjo Banjo is offline
Hell's Angel
Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,080
Default

Are you in full screen or windowed mode?
__________________
A wise one man once said "what you talking about dog breath"
Reply With Quote
  #3  
Old 09-21-2002, 04:13 AM
gav gav is offline
Newcomer
 
Join Date: Dec 2001
Location: England
Posts: 8
Default

I'm in full screen mode
Reply With Quote
  #4  
Old 09-21-2002, 04:35 AM
gav gav is offline
Newcomer
 
Join Date: Dec 2001
Location: England
Posts: 8
Default

Ah, after reading through my question again I've just found out the answer. The z coordinate is the only possible place I could be going wrong. If I set the z coordinate to always be 0 then I always get teh correct position.

I guess it really does help to just talk out your problems !!

Thanks for the help!

gav.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Advertisement: