How to map mouse cordinates to Canvas

Hi in my project i am implementing pick and drag features on the Objects.
But the problem is movement of object is either fast or slow in comparison to mouse motion …to overcome this i changed the scaling factor in my method

private static void rightDrag(MouseEvent e) {
		float scalingFactor=130f;
		mouseDrag_X = (e.getX() - mouseClickPos_X) / scalingFactor;
		mouseDrag_Y = -(e.getY() - mouseClickPos_Y) / scalingFactor;
		mouseClickPos_X = e.getX();
		mouseClickPos_Y = e.getY();
		isTranslationScheduled = true;
	}

but now what happens is when i resize my screen …obviously again the mismatch comes…so what should i use so that automatically this scalling factor ajdust itself to the changed dimension…

I have good news for you : your problem has been solved weeks ago !

You just need to use Arne’s picking algorithm (you can find it here : http://www.java-gaming.org/forums/index.php?topic=5549.0)
It’s perfect. You just need to create a rectangle that fill the whole window, and then you do picking each step, you get the Point3f and it’s done !

If you have other questions or want more details, don’t bother asking.

i appologise for asking such a simple question but i am not able to figure out how to update the scalingFactor


mouseDrag_X = (e.getX() - mouseClickPos_X) / scalingFactor;
In the Demo examples its been taken as 100 but that works only on specific size of screen so on resizing the movement of mouse and corresponding object is not same ..........i was not able to get solun for this thing in that thread........ I think this scaling factor should be related with the screen Width and Heigh so that it can get updated on changing the screen dimension............

You’re partially right.
Yes the scaling factor depends on your Canvas’ size but not only on that.
With the perspective effect, your method isn’t really applicable.
The method I proposed you is simple :

  • You can use a picking algorithm to “detect if you click on some 3D object”
  • This picking algorithm gives you also the position of the intersection between the mouse position and the object
  • So you can create a rectangle (that you don’t need to display) and test picking with this rectangle, where the intersection position is the exact mapping of the mouse coordinates to your Canvas. The only problem is to make sure that your rectangle fit the entire Canvas.

Don’t do it that complicated with picking - that’s unnessecary.
Simply use
Canvas3D.createPickRay(int x, int y, javax.vecmath.Point3f o, javax.vecmath.Vector3f d)

(See the javadocs for more info)

thanks for the help…will try it out …

And what’s that if not picking ?? :smiley:

That’s not picking. Picking, is, when you want to know the object you clicked at. This simply generates you a ray of possible positions your mouse is showing at.
Picking is much more, and much more calculation-consuming.

Oh maybe you’re right. But then, why is the function called createPICKray() ??

because you need to create such a ray to do picking. Its needed for picking. (As you would see if you looked at my picking-code you used lately :wink: ) But it’s not the complete picking.