I’m currently facing an issue with my mouse picking. I have a character mesh, which feet are at 0 on the Y axis when it is playing its “standup still” animation. However, my character is also able to swim, which will make its feet go below 0 on Y.
The problem is that when doing my mouse picking, the collision model still matches the standup animation, and not the swimming animation.
Here’s the code I’m using to do my mouse picking:
CollisionResults results = new CollisionResults();
Vector2f click2d = mInputManager.getCursorPosition(); Vector3f click3d = mRenderer.getCamera().getWorldCoordinates( new Vector2f(click2d.x, click2d.y), 0f).clone(); Vector3f dir = mRenderer.getCamera().getWorldCoordinates( new Vector2f(click2d.x, click2d.y), 1f).subtractLocal(click3d).normalizeLocal(); Ray ray = new Ray(click3d, dir);
From quick tests, it seems like the raycasting is done at the polygon-level. As I’m used to bounding-box picking from Ogre3D, I was looking for a way to “collide” against a bounding volume instead of the mesh exact polygons. I tried doing [java]mesh.setBound(new BoundingSphere()); mesh.updateBounds();[/java] but that doesn’t seem to make any difference.
Searching the forums, I found a thread talking about the fact that collision models aren’t updated per frame, but only at the first call of collideWith (which makes sense). So I tried to put this into the rendering loop (regardless of the FPS hit):
Geometry tmpGeo = (Geometry) child;
(‘this’ extends Node, mModelNode is attached to ‘this’, and mModel is a Spatial attached to mModelNode)
But this didn’t make any difference either. I’m highlighting the currently picked model, and it still only highlights when I hover my mouse “above” (on the Y axis) the model swimming, and doesn’t do anything when I hover my mouse on the body ; that is to say, it still seems to have a collision model based on the “stand up still” animation, where feet are above the origin.