hunter
November 4, 2005, 4:25pm
1
Hi there!
I'm using a Quad to create the character's inventory in my game. You can see the screenshot I'm sending to have a better understanding of the work. The problem is that I can't capture the user's click inside the Quad. How can I do this?
public MouseClique(Camera camera, Node inv) {
As your quad is in ortho queue you don't need picking.
To compute coordinates relative to your quad get the cursor location via MouseInput
x = MouseInput.get().getXAbsolute()
y = MouseInput.get().getYAbsolute()
and convert
x = (int) ( x - quad.getWorldTranslation().x + quadWidth / 2 );
y = (int) ( DisplaySystem.getDisplaySystem().getHeight() - y - getWorldTranslation().y + quadHeight / 2 );
Also, if you still want to do picking, you can do this:
quad = new Quad("quadone", 3, 3);
quad.setModelBound(new BoundingBox());
quad.updateModelBound();
That way the mouse picking for the quad is able to touch a bounding box, albeit a really skinny one.
From there, if you want to get the name of the quad, "quadone"
Vector2f screenPos = new Vector2f();
screenPos.set(abmouse.getHotSpotPosition().x, abmouse.getHotSpotPosition().y);
Vector3f worldCoords = display.getWorldCoordinates(screenPos, 0);
Vector3f worldCoords2 = display.getWorldCoordinates(screenPos, 1);
mousePickRay = new Ray(worldCoords, worldCoords2.subtractLocal(worldCoords).normalizeLocal());
pickResults.clear();
rootNode.findPick(mousePickRay, pickResults);
pickResults.getPickData(0).getTargetMesh().getParentGeom().getName();
should do.
Woohoo the newbie gave useful advice! :D I feel so not newbish! :D 8)
Even though this question is two years old!! >_<