So, I’m trying to create a collision Ray for selecting 3d objects in my world by following the manual and other posts on this forum, and I’m running into a peculiar problem.
I’ve created my collision ray, and attached it to my camera, and set it to show the ray and collisions. Then I call the “set_from_lens” on the collision ray when I click my mouse… however, I cannot see the ray anywhere. Checking the CollisionRay’s direction and origin, it seems they are being set to values that make no sense to me.
I know the Ray is being created, because I can retrieve it’s origin and direction, though the values seem wrong to me. Also, I randomly tried attaching the ray to one of the other nodes in my scene, and manually set it’s origin to my camera’s location, and the direction to a fixed point. I can see the ray just fine then, and it follows my other node around.
Also, as a side note, my collision traversal seems to be working fine.
What I’m guessing is wrong with my code is that I’m retrieving the wrong node when I’m looking for my camera and attaching the Ray to it… so I’ll post here what I’m using for each of those:
Here’s my camera:
Camera *camera = DCAST(Camera, window->get_camera_group().node()->get_child(0));
Here’s how I set up my Collision Ray:
pickerRay = new CollisionRay(); pickerNode = new CollisionNode("mouseRay"); pickerNode->add_solid(pickerRay); pickerNode->set_from_collide_mask(GeomNode::get_default_collide_mask()); pickerNP = window->get_camera_group()->attach_new_node(pickerNode); pickerNP.show(); mouseTrav.add_collider(pickerNP, mouseHandler);
Here’s how I call set_from_lens:
pickerRay->set_from_lens(camera, window->get_graphics_window()->get_pointer(0).get_x(), window->get_graphics_window()->get_pointer(0).get_y());
And for a little data, here’s a readout of the origin and direction of my collision ray after clicking my mouse near the center of my screen.
Meanwhile, window->get_camera_group().get_pos() gives:
Any help on this is greatly appreciated, and just let me know if I’m not providing enough information.