Commit f1f5576f authored by Inge Wallin's avatar Inge Wallin

Separate class Body from world.h and world.cc

parent f836715f
......@@ -2,6 +2,7 @@
set(stepcore_SRCS
object.cc
constants.cc
body.cc
world.cc
solver.cc
collisionsolver.cc
......
/* This file is part of StepCore library.
Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
StepCore library 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; either version 2 of the License, or
(at your option) any later version.
StepCore library 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 StepCore; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "body.h"
namespace StepCore
{
STEPCORE_META_OBJECT(Body, QT_TRANSLATE_NOOP("ObjectClass", "Body"), QT_TR_NOOP("Body"),
MetaObject::ABSTRACT,,)
} // namespace StepCore
/* This file is part of StepCore library.
Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
StepCore library 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; either version 2 of the License, or
(at your option) any later version.
StepCore library 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 StepCore; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/** \file world.h
* \brief Item, Body, Force and Tool interfaces, World class
*/
#ifndef STEPCORE_BODY_H
#define STEPCORE_BODY_H
#include <vector> // XXX: Replace if Qt is enabled.
#include "types.h"
#include "object.h"
namespace StepCore
{
//class World;
//class Solver;
//class Item;
//class ItemGroup;
//class CollisionSolver;
//class ConstraintSolver;
/** \ingroup bodies
* \brief Interface for bodies
*
* Body is anything that has dynamic variables that require ODE integration
*/
class Body
{
STEPCORE_OBJECT(Body)
public:
Body(): _variablesOffset(0) {}
virtual ~Body() {}
/** Get count of dynamic variables (not including velocities) */
virtual int variablesCount() = 0;
/** Set positions, velocities and (possibly) its variances using values in arrays and
* also reset accelerations and its variances. Variances should only be copied
* and reseted if positionVariance != NULL. */
virtual void setVariables(const double* position, const double* velocity,
const double* positionVariance, const double* velocityVariance) = 0;
/** Copy positions, velocities and (possibly) its variances to arrays.
* Variances should only be copied if positionVariance != NULL. */
virtual void getVariables(double* position, double* velocity,
double* positionVariance, double* velocityVariance) = 0;
/** Add force and (possibly) its variance to force accomulator.
* \note This function is used only by generic constraints handling code,
* force objects should use body-specific functions. */
virtual void addForce(const double* force, const double* forceVariance) = 0;
/** Reset force accomulator and (possibly) its variance to zero.
* Variance should only be reseted if resetVariance == true. */
virtual void resetForce(bool resetVariance) = 0;
/** Copy acceleration (forces left-multiplied by inverse mass)
* and (possibly) its variances to arrays.
* Variances should only be copied if accelerationVariance != NULL. */
virtual void getAccelerations(double* acceleration, double* accelerationVariance) = 0;
/** Get inverse mass and (possibly) its variance matrixes.
* Variance should only be copied of variance != NULL. */
virtual void getInverseMass(VectorXd* inverseMass,
DynSparseRowMatrix* variance, int offset) = 0;
/** Offset of body's variables in global arrays
* (meaningless if the body is not a part of the world) */
int variablesOffset() const { return _variablesOffset; }
private:
friend class World;
/** \internal Set offset of body's variables in global arrays */
void setVariablesOffset(int variablesOffset)
{
_variablesOffset = variablesOffset;
}
int _variablesOffset;
};
/** List of pointers to Body */
typedef std::vector<Body*> BodyList;
} // namespace StepCore
#endif
......@@ -29,7 +29,6 @@ namespace StepCore
STEPCORE_META_OBJECT(Item, QT_TRANSLATE_NOOP("ObjectClass", "Item"), QT_TR_NOOP("Item"), MetaObject::ABSTRACT, STEPCORE_SUPER_CLASS(Object),
STEPCORE_PROPERTY_RW(StepCore::Color, color, QT_TRANSLATE_NOOP("PropertyName", "color"), STEPCORE_UNITS_NULL, QT_TR_NOOP("Item color"), color, setColor))
STEPCORE_META_OBJECT(Body, QT_TRANSLATE_NOOP("ObjectClass", "Body"), QT_TR_NOOP("Body"), MetaObject::ABSTRACT,,)
STEPCORE_META_OBJECT(Force, QT_TRANSLATE_NOOP("ObjectClass", "Force"), QT_TR_NOOP("Force"), MetaObject::ABSTRACT,,)
STEPCORE_META_OBJECT(Joint, QT_TRANSLATE_NOOP("ObjectClass", "Joint"), QT_TR_NOOP("Joint"), MetaObject::ABSTRACT,,)
STEPCORE_META_OBJECT(Tool, QT_TRANSLATE_NOOP("ObjectClass", "Tool"), QT_TR_NOOP("Tool"), MetaObject::ABSTRACT,,)
......
......@@ -26,6 +26,7 @@
#include "types.h"
#include "util.h"
#include "object.h"
#include "body.h"
#include "vector.h"
#include <vector> // XXX: replace if QT is enabled
......@@ -130,67 +131,6 @@ private:
Color _color;
};
/** \ingroup bodies
* \brief Interface for bodies
*
* Body is anything that has dynamic variables that require ODE integration
*/
class Body
{
STEPCORE_OBJECT(Body)
public:
Body(): _variablesOffset(0) {}
virtual ~Body() {}
/** Get count of dynamic variables (not including velocities) */
virtual int variablesCount() = 0;
/** Set positions, velocities and (possibly) its variances using values in arrays and
* also reset accelerations and its variances. Variances should only be copied
* and reseted if positionVariance != NULL. */
virtual void setVariables(const double* position, const double* velocity,
const double* positionVariance, const double* velocityVariance) = 0;
/** Copy positions, velocities and (possibly) its variances to arrays.
* Variances should only be copied if positionVariance != NULL. */
virtual void getVariables(double* position, double* velocity,
double* positionVariance, double* velocityVariance) = 0;
/** Add force and (possibly) its variance to force accomulator.
* \note This function is used only by generic constraints handling code,
* force objects should use body-specific functions. */
virtual void addForce(const double* force, const double* forceVariance) = 0;
/** Reset force accomulator and (possibly) its variance to zero.
* Variance should only be reseted if resetVariance == true. */
virtual void resetForce(bool resetVariance) = 0;
/** Copy acceleration (forces left-multiplied by inverse mass)
* and (possibly) its variances to arrays.
* Variances should only be copied if accelerationVariance != NULL. */
virtual void getAccelerations(double* acceleration, double* accelerationVariance) = 0;
/** Get inverse mass and (possibly) its variance matrixes.
* Variance should only be copied of variance != NULL. */
virtual void getInverseMass(VectorXd* inverseMass,
DynSparseRowMatrix* variance, int offset) = 0;
/** Offset of body's variables in global arrays
* (meaningless if the body is not a part of the world) */
int variablesOffset() const { return _variablesOffset; }
private:
friend class World;
/** \internal Set offset of body's variables in global arrays */
void setVariablesOffset(int variablesOffset) {
_variablesOffset = variablesOffset;
}
int _variablesOffset;
};
/** \ingroup forces
* \brief Interface for forces
*
......@@ -296,8 +236,6 @@ public:
/** List of pointers to Item */
typedef std::vector<Item*> ItemList;
/** List of pointers to Body */
typedef std::vector<Body*> BodyList;
/** List of pointers to Force */
typedef std::vector<Force*> ForceList;
/** List of pointers to Joint */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment