Yello !
I’m trying to establish the field of view of characters.
I already implemented the collision between mouse and models, so I know a little bit about collision management.
What I need is this : a first collision test must determine what characters are in a radius from another one : since I would need a circle, the Sphere seems more appropriated.
Then, I will need to use probably a CollisionSegment, to find if nothing obstructs the line of view (it shouldn’t be that different from the mouse clicking on models).
I’ve based the code on the manual and the CollisionRay thing for mouse colliding, and here is what I have :
(_root is the root NodePath of the characters)
Constructor
_collisionHandlerQueue = new CollisionHandlerQueue();
_collisionFov = new CollisionSphere(_root.get_x(), _root.get_y(), _root.get_z(), 1500.f);
_collisionNode = new CollisionNode("FovSphere" + data["name"].Value());
_collisionPath = NodePath(_collisionNode);
_collisionNode->add_solid(_collisionFov);
_collisionTraverser.add_collider(_collisionPath, _collisionHandlerQueue);
Loop
_collisionFov->set_center(_root.get_pos());
_collisionTraverser.traverse(_window->get_render());
cout << "Num of collisions -> " _collisionHandlerQueue->get_num_entries() << endl;
for(unsigned int i = 1; i<= _collisionHandlerQueue->get_num_entries();i++)
{
CollisionEntry* entry = _collisionHandlerQueue->get_entry(i);
cout<<entry;
}
There’s a lot (a huge lot) of models around _root, but it doesn’t detect anything. With a radius that huge, I can’t imagine that no collision should be detected.
Could you help me with that one too ?