From: Markus R. <rol...@us...> - 2006-04-14 16:27:30
|
Update of /cvsroot/simspark/simspark/spark/oxygen/physicsserver In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13309/physicsserver Modified Files: body.h body.cpp collider.h collider.cpp Added Files: transformcollider.h transformcollider.cpp Log Message: - implemented support for the ODE transfom geom. This geom allows the displacement of a geom relative to the associated body. This allows to attach more than one geom to a body in a meaningful way to construct composite bodies - added method TranslateMass() to Body. This method translates the mass center of the body relativ to the body frame Index: body.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/body.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** body.cpp 5 Dec 2005 21:16:49 -0000 1.1 --- body.cpp 14 Apr 2006 16:27:27 -0000 1.2 *************** *** 345,346 **** --- 345,353 ---- return Vector3f(pos[0], pos[1], pos[2]); } + + void Body::TranslateMass(const salt::Vector3f& v) + { + dMass m; + dBodyGetMass(mODEBody, &m); + dMassTranslate(&m,v[0],v[1],v[2]); + } Index: body.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/body.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** body.h 5 Dec 2005 21:16:49 -0000 1.1 --- body.h 14 Apr 2006 16:27:26 -0000 1.2 *************** *** 143,146 **** --- 143,149 ---- void SetCappedCylinderTotal(float total_mass, float radius, float length); + /** displace the mass center relative to the body frame */ + void TranslateMass(const salt::Vector3f& v); + /** returns the current linear velocity vector of this body */ salt::Vector3f GetVelocity() const; --- NEW FILE: transformcollider.h --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: transformcollider.h,v 1.1 2006/04/14 16:27:27 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef OXYGEN_TRANSFORMCOLLIDER_H #define OXYGEN_TRANSFORMCOLLIDER_H #include "collider.h" namespace oxygen { /** TransformCollider encapsulates an ODE transform geometry object that encapsulates another geom. It allows the encapsulated geom to be positioned and rotated arbitrarily with respect to its point of reference. Most geoms (like the sphere and box) have their point of reference corresponding to their center of mass, allowing them to be easily connected to dynamics objects. Transform objects give you more flexibility - for example, you can offset the center of a sphere, or rotate a cylinder so that its axis is something other than the default. Transform geoms are further used to create composite objects. As they allow multiple displaced geoms to be connected to one body. */ class TransformCollider : public Collider { // // Functions // public: TransformCollider(); protected: virtual bool ConstructInternal(); }; DECLARE_CLASS(TransformCollider); } //namespace oxygen #endif //OXYGEN_TRANSFORMCOLLIDER_H --- NEW FILE: transformcollider.cpp --- /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- this file is part of rcssserver3D Fri May 9 2003 Copyright (C) 2002,2003 Koblenz University Copyright (C) 2003 RoboCup Soccer Server 3D Maintenance Group $Id: transformcollider.cpp,v 1.1 2006/04/14 16:27:27 rollmark Exp $ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "transformcollider.h" using namespace oxygen; using namespace salt; TransformCollider::TransformCollider() : Collider() { } bool TransformCollider::ConstructInternal() { if (! Collider::ConstructInternal()) { return false; } mODEGeom = dCreateGeomTransform(0); if (mODEGeom == 0) { return false; } //! do not automatically destroy encapsulated geoms dGeomTransformSetCleanup(mODEGeom, 0); /** report the transform geom in collisions instead of the encapsulated geoms */ dGeomTransformSetInfo(mODEGeom, 1); return true; } Index: collider.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/collider.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** collider.cpp 5 Dec 2005 21:16:49 -0000 1.1 --- collider.cpp 14 Apr 2006 16:27:27 -0000 1.2 *************** *** 20,28 **** */ #include "collider.h" #include "space.h" #include "body.h" #include "collisionhandler.h" ! #include <oxygen/sceneserver/scene.h> ! #include <zeitgeist/logserver/logserver.h> using namespace oxygen; --- 20,29 ---- */ #include "collider.h" + #include <oxygen/sceneserver/scene.h> + #include <zeitgeist/logserver/logserver.h> #include "space.h" #include "body.h" #include "collisionhandler.h" ! #include "transformcollider.h" using namespace oxygen; *************** *** 48,56 **** ODEObject::OnLink(); ! if (mODEGeom == 0) { return; } // if we have a space add the geom to it dSpaceID space = GetSpaceID(); --- 49,75 ---- ODEObject::OnLink(); ! weak_ptr<Node> parent = GetParent(); ! if ( ! (mODEGeom == 0) || ! (parent.expired()) ! ) { return; } + shared_ptr<TransformCollider> tcParent = + shared_dynamic_cast<TransformCollider>(parent.lock()); + + if (tcParent.get() != 0) + { + // our parent is an ODE transform geom that encapsulates + // this geom, so register ourself to it. This geom must + // not directly register to a space or a body. + dGeomTransformSetGeom(tcParent->GetODEGeom(), mODEGeom); + return; + } + + // this geom is independent, so register to space and body + // if we have a space add the geom to it dSpaceID space = GetSpaceID(); *************** *** 66,70 **** // if there is a Body below our parent, link to it shared_ptr<Body> body = shared_static_cast<Body> ! (make_shared(GetParent())->GetChildOfClass("Body")); if (body.get() != 0) --- 85,89 ---- // if there is a Body below our parent, link to it shared_ptr<Body> body = shared_static_cast<Body> ! (parent.lock()->GetChildOfClass("Body")); if (body.get() != 0) *************** *** 106,117 **** void Collider::PrePhysicsUpdateInternal(float /*deltaTime*/) { ! if (GetChildSupportingClass("CollisionHandler").get() == 0) ! { ! // for convenience we add a ContactJointHandler if no ! // other handler is registered. This behaviour covers the ! // majority of all use cases and eases the creation of ! // Colliders. ! AddCollisionHandler("oxygen/ContactJointHandler"); ! } } --- 125,136 ---- void Collider::PrePhysicsUpdateInternal(float /*deltaTime*/) { ! // if (GetChildSupportingClass("CollisionHandler").get() == 0) ! // { ! // // for convenience we add a ContactJointHandler if no ! // // other handler is registered. This behaviour covers the ! // // majority of all use cases and eases the creation of ! // // Colliders. ! // AddCollisionHandler("oxygen/ContactJointHandler"); ! // } } Index: collider.h =================================================================== RCS file: /cvsroot/simspark/simspark/spark/oxygen/physicsserver/collider.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** collider.h 5 Dec 2005 21:16:49 -0000 1.1 --- collider.h 14 Apr 2006 16:27:27 -0000 1.2 *************** *** 95,99 **** /** returns the ID of managed ODE geom */ dGeomID GetODEGeom(); - /** sets the relative position of the managed geom directly. If the geom is connected to a body, the position of the body will --- 95,98 ---- |