I’ve been learning linear algebra to build a more robust collision detection system (one that relies on vectors, points, rays, spheres, and cubes); I got it up and working about three or four days ago. Then, while exploring some code for camera controls, I landed upon the Vec3 object–and realized that Panda3D already handles a lot of linear algebra equations for you. On top of that, it’s got premade collision tests for a ton of primitives!
So, crap. Now I’m kind of stuck between a decision of trying to understand Panda3D’s related class objects or just relying on my own code. The former has the advantage of deeper integration–no need to make any messy wrappers to turn my points and vectors into formats that Python3D objects will understand (not that it’s hard; the objects understand tuples, after all!). There’s also probably the simple fact that Panda3D is very likely to do all the stuff I’m doing with higher levels of efficiency (at the moment, my collision engine can handle about 600-700 cubes–each with a volume of 10–moving within a 500x500x1000 space by a random vector of three ‘units’ length every frame–without noticeable slowdown, and no apparent collisions. I have no idea if this is good or bad. The number flies up when the majority of those objects aren’t moving, of course).
In trying to understand the Panda3D API in reference to these objects, though, I’m encountering some problems. Like the Hpr setting–I get that it’s a rotation, but how can I set it to a normalized vector without getting weird results? I know lookAt() will get me whatever rotation I need, but I’d like to know how to set the rotation of an object by a vector manually. EDIT: Actually, reading Vec3 now, I bet it’s not working because I’m not making it a zero-length Vector before attempting to assign it to the camera’s Hpr!
Another question–one of the optimization methods I set up for collision detection of cubes was creating an inner and outer sphere for each cube (inner is contained by the cube; outer contains the cube) and, for every collision test, asking whether or not the given object’s outer sphere overlaps with the outer sphere (no? no collision) and the inner (yes? collision). I figure checking for sphere collisions is way cheaper than more complex primitives since it’s basically just a quick and dirty radius check (is the vector between their two points greater or smaller than their combined radii?). But if I switch over to Panda3D’s collision API, I don’t want to do this check if it’s already instituted (or if there are better, quicker checks already in place). Does the collision API for cubes include such a check? Is there any worth in instituting it?
Sorry for the abundance of questions; I realize I could find the answers myself by experimenting, but that would take a lot of time, and the answers to some of these questions is directly relevant toward my decision whether or not to switch over to Panda3D’s vector, point, and primitive classes instead of using my own!