Thread: [Opal-commits] opal/src Matrix44r.h,1.27,1.28 Simulator.cpp,1.39,1.40 Simulator.h,1.75,1.76
Status: Inactive
Brought to you by:
tylerstreeter
|
From: tylerstreeter <tyl...@us...> - 2005-03-02 05:31:03
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21640/src Modified Files: Matrix44r.h Simulator.cpp Simulator.h Log Message: added offset matrix and scaling factor to blueprint instantiation; fixed matrix bug in rotation functions where axis wasn't getting normalized Index: Simulator.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.cpp,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** Simulator.cpp 28 Feb 2005 03:27:57 -0000 1.39 --- Simulator.cpp 2 Mar 2005 05:30:32 -0000 1.40 *************** *** 28,31 **** --- 28,36 ---- #include "Simulator.h" #include "BlueprintInstance.h" + #include "BoxShapeData.h" + #include "SphereShapeData.h" + #include "CapsuleShapeData.h" + #include "PlaneShapeData.h" + #include "RayShapeData.h" namespace opal *************** *** 238,243 **** void Simulator::instantiateBlueprint( ! BlueprintInstance& instance, const Blueprint& bp) { if (!bp.isFinalized()) { --- 243,251 ---- void Simulator::instantiateBlueprint( ! BlueprintInstance& instance, const Blueprint& bp, ! const Matrix44r& offset, real scale) { + assert(scale > 0); + if (!bp.isFinalized()) { *************** *** 249,252 **** --- 257,274 ---- } + bool useOffset = false; + if (Matrix44r() != offset) + { + useOffset = true; + } + + bool useScale = false; + Matrix44r scaleMat; + if (1 != scale) + { + useScale = true; + scaleMat.makeScale(scale); + } + // For each object created here, only the ones with names get added // to the BlueprintInstance. *************** *** 260,264 **** // Joints, Motors, and Sensors), use the stored indices to // find pointers in the appropriate array. ! // Create these temporary arrays of pointers. Other objects // will use these to find pointers to their dependencies. --- 282,286 ---- // Joints, Motors, and Sensors), use the stored indices to // find pointers in the appropriate array. ! // Create these temporary arrays of pointers. Other objects // will use these to find pointers to their dependencies. *************** *** 271,276 **** { Solid* s = createSolid(); ! s->init(*bp.getSolidData(i)); solidList.push_back(s); --- 293,378 ---- { Solid* s = createSolid(); ! SolidData sd = *bp.getSolidData(i); ! ! if (useOffset) ! { ! // Offset the Solid's transform. ! sd.transform = offset * sd.transform; ! } ! ! if (useScale) ! { ! // Scale the Solid's transform. ! sd.transform[12] *= scale; ! sd.transform[13] *= scale; ! sd.transform[14] *= scale; ! ! // Scale the Solid's Shape's offsets and dimensions. ! int i=0; ! for (i=0; i<sd.getNumShapes(); ++i) ! { ! ShapeData* shapeData = sd.getShapeData(i); ! shapeData->offset[12] *= scale; ! shapeData->offset[13] *= scale; ! shapeData->offset[14] *= scale; ! ! switch(shapeData->getType()) ! { ! case BOX_SHAPE: ! { ! BoxShapeData* boxData = ! (BoxShapeData*)shapeData; ! boxData->dimensions = ! scale * boxData->dimensions; ! break; ! } ! case SPHERE_SHAPE: ! { ! SphereShapeData* sphereData = ! (SphereShapeData*)shapeData; ! sphereData->radius = ! scale * sphereData->radius; ! break; ! } ! case CAPSULE_SHAPE: ! { ! CapsuleShapeData* capsuleData = ! (CapsuleShapeData*)shapeData; ! capsuleData->radius = ! scale * capsuleData->radius; ! capsuleData->length = ! scale * capsuleData->length; ! break; ! } ! case PLANE_SHAPE: ! { ! PlaneShapeData* planeData = ! (PlaneShapeData*)shapeData; ! planeData->abcd[3] = ! scale * planeData->abcd[3]; ! break; ! } ! case RAY_SHAPE: ! { ! RayShapeData* rayData = ! (RayShapeData*)shapeData; ! Point3r origin = rayData->ray.getOrigin(); ! origin = scale * origin; ! rayData->ray.setOrigin(origin); ! break; ! } ! case MESH_SHAPE: ! { ! // Not implemented. Scaling the Mesh data ! // should be handled elsewhere. ! break; ! } ! default: ! assert(false); ! } ! } ! } + s->init(sd); solidList.push_back(s); *************** *** 290,295 **** Joint* j = createJoint(); ! j->init(*data); jointList.push_back(j); --- 392,413 ---- Joint* j = createJoint(); ! JointData jd = *data; + if (useOffset) + { + // Offset the Joint's anchor and axes. + jd.anchor = offset * jd.anchor; + jd.axis[0].direction = offset * jd.axis[0].direction; + jd.axis[1].direction = offset * jd.axis[1].direction; + jd.axis[2].direction = offset * jd.axis[2].direction; + } + + if (useScale) + { + // Scale the Joint's anchor. + jd.anchor = scale * jd.anchor; + } + + j->init(jd); jointList.push_back(j); Index: Matrix44r.h =================================================================== RCS file: /cvsroot/opal/opal/src/Matrix44r.h,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Matrix44r.h 26 Feb 2005 07:17:09 -0000 1.27 --- Matrix44r.h 2 Mar 2005 05:30:32 -0000 1.28 *************** *** 190,193 **** --- 190,199 ---- inline void makeRotation(real theta, real x, real y, real z) { + Vec3r axis(x, y, z); + axis.normalize(); + x = axis[0]; + y = axis[1]; + z = axis[2]; + // source: http://www.euclideanspace.com/maths/geometry/rotations/ // conversions/angleToMatrix/ Index: Simulator.h =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.h,v retrieving revision 1.75 retrieving revision 1.76 diff -C2 -d -r1.75 -r1.76 *** Simulator.h 25 Feb 2005 06:40:26 -0000 1.75 --- Simulator.h 2 Mar 2005 05:30:32 -0000 1.76 *************** *** 89,95 **** /// Creates instances of all objects in a Blueprint and fills the ! /// given BlueprintInstance with pointers of the named objects. virtual void OPAL_CALL instantiateBlueprint( ! BlueprintInstance& instance, const Blueprint& bp); /// A convenient volume collision check function. TODO: replace --- 89,99 ---- /// Creates instances of all objects in a Blueprint and fills the ! /// given BlueprintInstance with pointers of the named objects. The ! /// offset transform and scale factor can be used to affect ! /// all instantiated objects at once. The scale factor must be ! /// greater than zero. virtual void OPAL_CALL instantiateBlueprint( ! BlueprintInstance& instance, const Blueprint& bp, ! const Matrix44r& offset=Matrix44r(), real scale=1); /// A convenient volume collision check function. TODO: replace |