   Moving on-screen objects using DirectInput and a mouse
  Hi I''m developing a simple program using DirectX that allows someone to move a cube around the screen using a mouse. I''m trying to do this using DirectInput and I''ve got the following code: if (mousestate.rgbButtons[0] & 0x80) // left mouse button pressed{D3DXVECTOR3 temp(cubeCentreX, cubeCentreY, cubeCentreZ);D3DXVECTOR3 temp2, temp3;D3DVIEWPORT9 viewport;g_pDirect3DDevice->GetViewport(&viewport);D3DXVec3Project(&temp2, &temp, &viewport, &projectionMatrix, &viewMatrix, &worldMatrix);temp2.x += mousestate.lX;temp2.y += mousestate.lY;D3DXVec3Unproject(&temp3, &temp2, &viewport, &projectionMatrix, &viewMatrix, &worldMatrix);cubeCentreX += temp3.x; cubeCentreY += temp3.y;}However when I run the program the cube just shoots offscreen at a crazy rate in the direction I move the mouse (when I''m holding down the left button). I want the cube to move with the cursor when I hold down the left button - at this stage I''m not bothered whether the cursor is actually over the cube, I just want it to move when the left mouse button is pressed. Any help? Asim  
  Either slow down the mouse movement, or look into getCursorPos();,  and SetCursorPos(); ;  since the vectors are floats, you could scale them to suite your needs:quote:temp2.x += mousestate.lX;temp2.y += mousestate.lY;could be: temp2.x += (float)(mousestate.lX * 0.0001f);temp2.y += (float)(mousestate.lY * 0.0001f);That would slow it down quite a bit, at least enough to let you see whats going on. ;  Thansk all - I''ve managed to get it working reasonably well now.The main problem was that I hadcubeCentreX += temp3.x; cubeCentreY += temp3.y;in the original code when really I should have hadcubeCentreX = temp3.x; cubeCentreY = temp3.y;Asim 