Hey Guys,
i’m sure its a silly beginner question, but i have the following newbie problem. :}
By clicking my model in the scene, i detect the collision point and mark it with an red sphere.
No problem at this point. (look at code)
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("Shoot") && !isPressed) {
// Reset results list.
CollisionResults results = new CollisionResults();
// Convert screen click to 3d position
Vector3f click3d = cam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y),0f).clone();
Vector3f dir = cam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y),1f).subtractLocal(click3d).normalizeLocal();
// Aim the ray from the clicked spot forwards.
Ray ray = new Ray(click3d, dir);
// Collect intersections between ray and all nodes in results list.
modelNode.collideWith(ray, results);
if (results.size() > 0) {
// The closest collision point is what was truly hit:
CollisionResult closest = results.getClosestCollision();
Vector3f v = new Vector3f();
v = modelNode.worldToLocal(closest.getContactPoint(), v); \\get local position
// Let's interact - we mark the hit with a red dot.
mark.setLocalTranslation(v);
modelNode.attachChild(mark);
} else {
// No hits? Then remove the red mark.
modelNode.detachChild(mark);
}
}
But how can I get different spheres. One more with every mouse click, without loosing the current sphere.
In the beginner tutorials, allways create all objects in the beginning. Then the scene is initialized and the app started. However, how can i create new objects during running the app and add them permanently to the node .
In my case, different instances of the spehre at different positions, by clicking.
I hope somebody can give me a helpful advice where I can read more about this topic.
Best regards,
EsKay :}