[Opal-commits] opal/src BoxShapeData.h,1.5,1.6 CapsuleShapeData.h,1.6,1.7 MeshShapeData.h,1.6,1.7 Pl
Status: Inactive
Brought to you by:
tylerstreeter
|
From: tylerstreeter <tyl...@us...> - 2005-07-21 15:59:46
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21343/src Modified Files: BoxShapeData.h CapsuleShapeData.h MeshShapeData.h PlaneShapeData.h ShapeData.h Solid.cpp Solid.h SphereShapeData.h Log Message: Added 'getLocalAABB' function to ShapeData. Added 'getLocalAABB' and 'getGlobalAABB' functions to Solid. Index: CapsuleShapeData.h =================================================================== RCS file: /cvsroot/opal/opal/src/CapsuleShapeData.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** CapsuleShapeData.h 31 Mar 2005 08:47:02 -0000 1.6 --- CapsuleShapeData.h 21 Jul 2005 15:59:01 -0000 1.7 *************** *** 69,72 **** --- 69,84 ---- } + OPAL_DECL virtual void OPAL_CALL getLocalAABB(real aabb[6]) + { + // The standard initial capsule orientation in OPAL is to + // align it along the Z axis. + aabb[0] = -radius; + aabb[1] = radius; + aabb[2] = -radius; + aabb[3] = radius; + aabb[4] = -(real)0.5 * length - radius; + aabb[5] = (real)0.5 * length + radius; + } + /// The capsule's radius. real radius; Index: SphereShapeData.h =================================================================== RCS file: /cvsroot/opal/opal/src/SphereShapeData.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SphereShapeData.h 11 Mar 2005 05:31:56 -0000 1.5 --- SphereShapeData.h 21 Jul 2005 15:59:01 -0000 1.6 *************** *** 66,69 **** --- 66,79 ---- } + OPAL_DECL virtual void OPAL_CALL getLocalAABB(real aabb[6]) + { + aabb[0] = -radius; + aabb[1] = radius; + aabb[2] = -radius; + aabb[3] = radius; + aabb[4] = -radius; + aabb[5] = radius; + } + /// The sphere's radius. real radius; Index: ShapeData.h =================================================================== RCS file: /cvsroot/opal/opal/src/ShapeData.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ShapeData.h 25 Mar 2005 02:44:19 -0000 1.8 --- ShapeData.h 21 Jul 2005 15:59:01 -0000 1.9 *************** *** 63,67 **** } ! /// Returns the Shape's type. OPAL_DECL virtual ShapeType OPAL_CALL getType()const { --- 63,67 ---- } ! /// Returns the ShapeData's type. OPAL_DECL virtual ShapeType OPAL_CALL getType()const { *************** *** 69,72 **** --- 69,77 ---- } + /// Returns the axis-aligned bounding box of the ShapeData relative + /// to its center. The 'aabb' array stores data in the following + /// order: min x, max x, min y, max y, min z, max z. + OPAL_DECL virtual void OPAL_CALL getLocalAABB(real aabb[6]) = 0; + /// The offset transform from a Solid's transform. Matrix44r offset; Index: PlaneShapeData.h =================================================================== RCS file: /cvsroot/opal/opal/src/PlaneShapeData.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PlaneShapeData.h 11 Mar 2005 05:31:56 -0000 1.5 --- PlaneShapeData.h 21 Jul 2005 15:59:01 -0000 1.6 *************** *** 73,76 **** --- 73,82 ---- } + /// Planes don't have a bounding box, so this does nothing. + OPAL_DECL virtual void OPAL_CALL getLocalAABB(real aabb[6]) + { + // Do nothing. + } + /// Parameters used to define the plane equation: /// a*x + b*y + c*z = d. Index: Solid.h =================================================================== RCS file: /cvsroot/opal/opal/src/Solid.h,v retrieving revision 1.90 retrieving revision 1.91 diff -C2 -d -r1.90 -r1.91 *** Solid.h 4 May 2005 21:04:01 -0000 1.90 --- Solid.h 21 Jul 2005 15:59:01 -0000 1.91 *************** *** 39,48 **** class ShapeData; ! /// Solids are the physical objects in the simulation. Solids can be ! /// static or dynamic. Static Solids are simple collision shapes; ! /// they are not physically simulated but can still be positioned ! /// manually. Dynamic Solids have collision shapes and are also ! /// physically simulated. All Solids start out enabled, but they don't ! /// do much until Shapes are added. class Solid { --- 39,47 ---- class ShapeData; ! /// Solids are the physical objects in a simulation. Solids can be ! /// static or dynamic: basically, dynamic Solids move, and static Solids ! /// don't move. (Static Solids can still be positioned manually.) All ! /// Solids start out enabled, but they don't do much until Shapes are ! /// added. class Solid { *************** *** 138,146 **** virtual Quaternion OPAL_CALL getQuaternion()const; ! /// Removes all shapes from this Solid. virtual void OPAL_CALL clearShapes() = 0; ! /// Adds a Shape to this Solid. ! virtual void OPAL_CALL addShape(const ShapeData& data) = 0; /// Applies a force/torque to this Solid. If the Solid is disabled, --- 137,155 ---- virtual Quaternion OPAL_CALL getQuaternion()const; ! /// Returns the axis-aligned bounding box for all of the Solid's ! /// shapes relative to the Solid. ! virtual void OPAL_CALL getLocalAABB(real aabb[6])const; ! ! /// Returns the axis-aligned bounding box for all of the Solid's ! /// shapes in global coordinates. ! virtual void OPAL_CALL getGlobalAABB(real aabb[6])const; ! ! /// Removes all shapes from this Solid. Resets the Solid's ! /// axis-aligned bounding box. virtual void OPAL_CALL clearShapes() = 0; ! /// Adds a Shape to this Solid. Updates the Solid's axis-aligned ! /// bounding box. ! virtual void OPAL_CALL addShape(ShapeData& data) = 0; /// Applies a force/torque to this Solid. If the Solid is disabled, *************** *** 237,240 **** --- 246,255 ---- virtual void applyForce(const Force& f) = 0; + /// Adds the given axis-aligned bounding box to the Solid's AABB. + void addToLocalAABB(const real aabb[6]); + + /// Resets the Solid's axis-aligned bounding box. + void resetAABB(); + /// An internal list of this Solid's pending Forces. std::vector<Force> mForceList; *************** *** 243,246 **** --- 258,267 ---- SolidData mData; + /// The axis-aligned bounding box of all shapes in local + /// coordinates. This array stores data in the following order: + /// min x, max x, min y, max y, min z, max z. This gets updated + /// whenever a shape is added or removed. + real mLocalAABB[6]; + /// Pointer to this Solid's collision event handler. CollisionEventHandler* mCollisionEventHandler; Index: Solid.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Solid.cpp,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** Solid.cpp 4 May 2005 21:04:01 -0000 1.36 --- Solid.cpp 21 Jul 2005 15:59:01 -0000 1.37 *************** *** 35,38 **** --- 35,39 ---- setCollisionEventHandler(NULL); setUserData(NULL); + resetAABB(); } *************** *** 160,163 **** --- 161,189 ---- } + void Solid::getLocalAABB(real aabb[6])const + { + for (unsigned int i = 0; i < 6; ++i) + { + aabb[i] = mLocalAABB[i]; + } + } + + void Solid::getGlobalAABB(real aabb[6])const + { + Point3r minExtents(mLocalAABB[0], mLocalAABB[2], mLocalAABB[4]); + Point3r maxExtents(mLocalAABB[1], mLocalAABB[3], mLocalAABB[5]); + + // Transform the AABB extents to global coordinates. + minExtents = mData.transform * minExtents; + maxExtents = mData.transform * maxExtents; + + aabb[0] = minExtents[0]; + aabb[1] = maxExtents[0]; + aabb[2] = minExtents[1]; + aabb[3] = maxExtents[1]; + aabb[4] = minExtents[2]; + aabb[5] = maxExtents[2]; + } + //void Solid::addPlane(const Point3r& point, const Vec3r& normal, const Material& m) //{ *************** *** 245,248 **** --- 271,299 ---- } + void Solid::addToLocalAABB(const real aabb[6]) + { + // Loop over the 3 dimensions of the AABB's extents. + for (unsigned int i = 0; i < 3; ++i) + { + if (aabb[i * 2] < mLocalAABB[i * 2]) + { + mLocalAABB[i * 2] = aabb[i * 2]; + } + + if (aabb[i * 2 + 1] > mLocalAABB[i * 2 + 1]) + { + mLocalAABB[i * 2 + 1] = aabb[i * 2 + 1]; + } + } + } + + void Solid::resetAABB() + { + for (unsigned int i = 0; i < 6; ++i) + { + mLocalAABB[i] = 0; + } + } + //void Solid::internal_updateSleeping() //{ Index: BoxShapeData.h =================================================================== RCS file: /cvsroot/opal/opal/src/BoxShapeData.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** BoxShapeData.h 11 Mar 2005 05:31:56 -0000 1.5 --- BoxShapeData.h 21 Jul 2005 15:59:01 -0000 1.6 *************** *** 65,68 **** --- 65,78 ---- } + OPAL_DECL virtual void OPAL_CALL getLocalAABB(real aabb[6]) + { + aabb[0] = -(real)0.5 * dimensions[0]; + aabb[1] = (real)0.5 * dimensions[0]; + aabb[2] = -(real)0.5 * dimensions[1]; + aabb[3] = (real)0.5 * dimensions[1]; + aabb[4] = -(real)0.5 * dimensions[2]; + aabb[5] = (real)0.5 * dimensions[2]; + } + /// The box's dimensions. Vec3r dimensions; Index: MeshShapeData.h =================================================================== RCS file: /cvsroot/opal/opal/src/MeshShapeData.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MeshShapeData.h 18 Jun 2005 17:45:53 -0000 1.6 --- MeshShapeData.h 21 Jul 2005 15:59:01 -0000 1.7 *************** *** 58,61 **** --- 58,66 ---- triangleArray = NULL; numTriangles = 0; + + for (unsigned int i = 0; i < 6; ++i) + { + localAABB[i] = 0; + } } *************** *** 81,84 **** --- 86,143 ---- triangleArray = data.triangleArray; numTriangles = data.numTriangles; + + for (unsigned int i = 0; i < 6; ++i) + { + localAABB[i] = data.localAABB[i]; + } + } + + /// This recomputes the axis-aligned bounding box from the vertex + /// data, so it should not be called very often. + OPAL_DECL virtual void OPAL_CALL getLocalAABB(real aabb[6]) + { + // Compute the AABB from the vertex data. + if (vertexArray) + { + for (unsigned int i = 0; i < numVertices; ++i) + { + unsigned int vertexIndex = i * 3; + + // Check x component. + if (vertexArray[vertexIndex] < localAABB[0]) + { + localAABB[0] = vertexArray[vertexIndex]; + } + else if (vertexArray[vertexIndex] > localAABB[1]) + { + localAABB[1] = vertexArray[vertexIndex]; + } + + // Check y component. + if (vertexArray[vertexIndex + 1] < localAABB[2]) + { + localAABB[2] = vertexArray[vertexIndex + 1]; + } + else if (vertexArray[vertexIndex + 1] > localAABB[3]) + { + localAABB[3] = vertexArray[vertexIndex + 1]; + } + + // Check z component. + if (vertexArray[vertexIndex + 2] < localAABB[4]) + { + localAABB[4] = vertexArray[vertexIndex + 2]; + } + else if (vertexArray[vertexIndex + 2] > localAABB[5]) + { + localAABB[5] = vertexArray[vertexIndex+ 2]; + } + } + } + + for (unsigned int i = 0; i < 6; ++i) + { + aabb[i] = localAABB[i]; + } } *************** *** 110,113 **** --- 169,177 ---- protected: + /// The mesh's local axis-aligned bounding box. This array stores + /// data in the following order: min x, max x, min y, max y, min z, + /// max z. This will be updated automatically when the mesh is + /// added to a Solid. + real localAABB[6]; private: |