What’s the difference? They seem to act the same at first glance. I can’t seem to figure out why there are two seperate types of base-3 vector.
Any subtle nuances?
EDIT: The only thing I see is that adding two of them together gives a point, rather than a vector as when two VBase3 objects are added.
The difference is on the C++ layer that the vector objects wrap around.
VBase3 is (kindof) the base class, and Vec3 (C++ name: LVector3f) and Vec3D (C++ name: LVector3d) are derived from this base class. ‘Kindof’ because inheritance is done with some nifty preprocessor macros and not spelled out explicitely.
LVector3f has single-precision (float) coordinates, and
LVector3d has double-precision (double) coordinates. That’s all.
On the Python layer you should not see any difference. But some Panda3D methods return or require Vec3, while other return or require VBase3 or Vec3D.
By the way: adding two vectors always gives a vector. Everything else would be highly suspicious. Adding a point and a vector should give a point though.
>>> from pandac.PandaModules import Vec3
>>> v1 = Vec3( 1, 0, 0 )
>>> v2 = Vec3( 0, 1, 0 )
>>> v1 + v2
Vec3(1, 1, 0)
>>> from pandac.PandaModules import VBase3
>>> v3 = VBase3( 1, 0, 0 )
>>> v4 = VBase3( 0, 1, 0 )
>>> v3 + v4
VBase3(1, 1, 0)
>>> v1 + v3
VBase3(2, 0, 0)
Right, though adding a Point3 + Vec3 gives you a Point3.
The reason we have these different classes is because of the different semantics. Choose the particular class that’s closest to the semantic meaning you require: if you are representing a point in 3-d space, use Point3; if you are representing a vector offset or direction, use Vec3, and if you just have three unrelated numbers (as in a H,P,R triple), use VBase3.
There was another post not too long ago where this same question was asked.
Ah, I do apologize for repeating the question then. The search function for the forum is a little hard to find topics on a subject, particularly if the search string has more than one word. Even with the “Search for all items” search type will yield results that simply contain both words, not necesarily both words together.
I apologize for my EDIT in my first post-- I meant so talk of the addition of a Vector and a Point, not a Vec3 and a Vec3. I had misread the documentation in the Reference about Vec3.
That info about using Vec3 for offsets and VBase3 for abstract associations is much appreciated; some of the examples in the Manual code use a lot of VBase3, and so I figured that was simply “how to do it”. I didn’t even know about Vec3 until making the code for the Physics engine script that I’ve posted in the Script Issues forum.
our search function is perfect your using it wrong!
j/k yeah i cant find crap when i look too. Stuff that i wrote for which i know near exact wording.