예제 #1
0
void PhysicsModel::deserialize(database::IArchive& ar)
{
    ar.readStringChunk("name", name);

    database::IArchive::chunk_info info;
    if ( !ar.openChunk("collisionObjects", info) ) {
        throw database::serialization_error(AUTO_LOGGER, "Missing collision objects chunk");
    }
	while ( ar.openChunk("collision_object", info) )
	{
		std::string target;
		ar.readStringChunk("target", target);
		collision_object_ptr rbody = ar.readSerializable<CollisionObject>(false, true);
		addCollisionObject(rbody, target);
		ar.closeChunk();
	}
    ar.closeChunk();

    if ( !ar.openChunk("constraints", info) ) {
        throw database::serialization_error(AUTO_LOGGER, "Missing constraints chunk");
    }
    while ( Constraint* constraint = ar.readSerializable<Constraint>(false, true) ) {
        constraints.insert( constraint_ptr(constraint) );
    }
    ar.closeChunk();
}
예제 #2
0
/**
 * Constructs a new WavefrontBody object.
 *
 * @param name the name of this WavefrontBody.
 */
WavefrontBody::WavefrontBody(const QString &name, const QString& filename, double scale)
	: SimBody(name), mReferenceObjectName(0), mLocalPosition(0), mReferenceObject(0)
{
	mScale = new DoubleValue(scale);
	mFilename = new FileNameValue(filename);
	//mFilename->useAsFileName(true);
	mReferenceObjectName = new StringValue("");
	mLocalPosition = new Vector3DValue(0.0, 0.0, 0.0);
	mLocalOrientation = new Vector3DValue(0.0, 0.0, 0.0);

	addParameter("Scale", mScale);
	addParameter("FileName", mFilename);
	addParameter("ReferenceObject", mReferenceObjectName);
	addParameter("LocalPosition", mLocalPosition);
	addParameter("LocalOrientation", mLocalOrientation);

	//Collision and visualization geometries (will be initialized in update().
	mBodyCollisionObject = new CollisionObject(WavefrontGeom(this, filename, scale));

	addGeometry(mBodyCollisionObject->getGeometry());
	mBodyCollisionObject->setMaterialType(mMaterialValue->get());
	mBodyCollisionObject->setTextureType("Default");
	mBodyCollisionObject->getGeometry()->setColor(mGeometryColorValue->get());
	addCollisionObject(mBodyCollisionObject);
}
예제 #3
0
void	btSimpleDynamicsWorld::addRigidBody(btRigidBody* body)
{
	body->setGravity(m_gravity);

	if (body->getCollisionShape())
	{
		addCollisionObject(body);
	}
}
void	btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body, short group, short mask)
{
	if (!body->isStaticOrKinematicObject())
	{
		body->setGravity(m_gravity);
	}

	if (body->getCollisionShape())
	{
		addCollisionObject(body,group,mask);
	}
}
예제 #5
0
파일: BulletDS.cpp 프로젝트: xhub/siconos
void BulletDS::addCollisionShape(SP::btCollisionShape shape,
                                 SP::SiconosVector pos,
                                 SP::SiconosVector ori,
                                 int group)
{
  SP::btCollisionObject collisionObject(new btCollisionObject());
  collisionObject->setUserPointer(this);
  collisionObject->setCollisionFlags(collisionObject->getCollisionFlags()|
                                     btCollisionObject::CF_KINEMATIC_OBJECT);
  collisionObject->setCollisionShape(&*shape);

  addCollisionObject(collisionObject, pos, ori, group);
}
예제 #6
0
/**
 * Copy constructor. 
 * 
 * @param other the CapsuleBody object to copy.
 */
CapsuleBody::CapsuleBody(const CapsuleBody &other) 
	: Object(), ValueChangedListener(), SimBody(other) 
{
	mRadius = dynamic_cast<DoubleValue*>(getParameter("Radius"));
	mLength = dynamic_cast<DoubleValue*>(getParameter("Length"));

	mBodyCollisionObject = new CollisionObject(
		CapsuleGeom(this, mLength->get(), mRadius->get()));

	mBodyCollisionObject->getGeometry()->setColor(mGeometryColorValue->get());
	mBodyCollisionObject->setMaterialType(mMaterialValue->get());
	mBodyCollisionObject->setTextureType(mTexturesValue->get());

	addGeometry(mBodyCollisionObject->getGeometry());
	addCollisionObject(mBodyCollisionObject);
}
void	btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body)
{
	if (!body->isStaticOrKinematicObject())
	{
		body->setGravity(m_gravity);
	}

	if (body->getCollisionShape())
	{
		bool isDynamic = !(body->isStaticObject() || body->isKinematicObject());
		short collisionFilterGroup = isDynamic? short(btBroadphaseProxy::DefaultFilter) : short(btBroadphaseProxy::StaticFilter);
		short collisionFilterMask = isDynamic? 	short(btBroadphaseProxy::AllFilter) : 	short(btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter);

		addCollisionObject(body,collisionFilterGroup,collisionFilterMask);
	}
}
예제 #8
0
/**
 * Constructs a new CapsuleBody.
 */
CapsuleBody::CapsuleBody(const QString &name, double length, double radius)
	: SimBody(name), mRadius(0), mLength(0)
{
	mRadius = new DoubleValue(radius);
	mLength = new DoubleValue(length);

	addParameter("Radius", mRadius);
	addParameter("Length", mLength);

	//Collision and visualization geometries (will be initialized in update().
	mBodyCollisionObject = new CollisionObject(
		CapsuleGeom(this, mLength->get(), mRadius->get()));
	addGeometry(mBodyCollisionObject->getGeometry());
	mBodyCollisionObject->setMaterialType(mMaterialValue->get());
	mBodyCollisionObject->setTextureType("None");
	mBodyCollisionObject->getGeometry()->setColor(mGeometryColorValue->get());
	addCollisionObject(mBodyCollisionObject);
}
예제 #9
0
/**
 * Creates a copy of object body.
 * The default CollisionObject and Geometry of a BoxBody are copied as well.
 * @param body the BoxBody to copy.
 */
BoxBody::BoxBody(const BoxBody &body)
	: Object(), ValueChangedListener(), SimBody(body)
{
	mWidth = dynamic_cast<DoubleValue*>(getParameter("Width"));
	mHeight = dynamic_cast<DoubleValue*>(getParameter("Height"));
	mDepth = dynamic_cast<DoubleValue*>(getParameter("Depth"));

	mBodyCollisionObject = new CollisionObject(
		BoxGeom(this, mWidth->get(), mHeight->get(), mDepth->get()));
	//mBodyCollisionObject = new CollisionObject(WavefrontGeom(this, "alice.obj", 0.1));

	mBodyCollisionObject->getGeometry()->setColor(mGeometryColorValue->get());
	mBodyCollisionObject->setMaterialType(mMaterialValue->get());
	mBodyCollisionObject->setTextureType(mTexturesValue->get());

	addGeometry(mBodyCollisionObject->getGeometry());
	addCollisionObject(mBodyCollisionObject);
}
예제 #10
0
/**
 * Creates a copy of object body.
 * The default CollisionObject and Geometry of a WavefrontBody are copied as well.
 * @param body the WavefrontBody to copy.
 */
WavefrontBody::WavefrontBody(const WavefrontBody &body) 
	: Object(), ValueChangedListener(), SimBody(body), mReferenceObjectName(0), 
	  mLocalPosition(0), mReferenceObject(0)
{
	mScale = dynamic_cast<DoubleValue*>(getParameter("Scale"));
	mFilename = dynamic_cast<FileNameValue*>(getParameter("FileName"));
	mReferenceObjectName = dynamic_cast<StringValue*>(getParameter("ReferenceObject"));
	mLocalPosition = dynamic_cast<Vector3DValue*>(getParameter("LocalPosition"));
	mLocalOrientation = dynamic_cast<Vector3DValue*>(getParameter("LocalOrientation"));

	mBodyCollisionObject = new CollisionObject(WavefrontGeom(this, mFilename->get(), mScale->get()));

	addGeometry(mBodyCollisionObject->getGeometry());
	mBodyCollisionObject->setMaterialType(mMaterialValue->get());
	mBodyCollisionObject->setTextureType("Default");
	mBodyCollisionObject->getGeometry()->setColor(mGeometryColorValue->get());
	
	addCollisionObject(mBodyCollisionObject);
}
예제 #11
0
void	btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body, short group, short mask)
{
	if (!body->isStaticOrKinematicObject() && !(body->getFlags() &BT_DISABLE_WORLD_GRAVITY))
	{
		body->setGravity(m_gravity);
	}

	if (body->getCollisionShape())
	{
		if (!body->isStaticObject())
		{
			m_nonStaticRigidBodies.push_back(body);
		}
		 else
		{
			body->setActivationState(ISLAND_SLEEPING);
		}
		addCollisionObject(body,group,mask);
	}
}
예제 #12
0
BoxBody::BoxBody(const QString &name, double width, double height, double depth)
		: SimBody(name)
{
	mWidth = new DoubleValue(width);
	mHeight = new DoubleValue(height);
	mDepth = new DoubleValue(depth);

	addParameter("Width", mWidth);
	addParameter("Height", mHeight);
	addParameter("Depth", mDepth);

	//Collision and visualization geometries (will be initialized in update().
	mBodyCollisionObject = new CollisionObject(
		BoxGeom(this, mWidth->get(), mHeight->get(), mDepth->get()));
	//mBodyCollisionObject = new CollisionObject(WavefrontGeom(this, "alice.obj", 0.1));

	addGeometry(mBodyCollisionObject->getGeometry());
	mBodyCollisionObject->setMaterialType(mMaterialValue->get());
	mBodyCollisionObject->setTextureType("Default");
	mBodyCollisionObject->getGeometry()->setColor(mGeometryColorValue->get());
	addCollisionObject(mBodyCollisionObject);
}
예제 #13
0
void	btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body)
{
	if (!body->isStaticOrKinematicObject() && !(body->getFlags() &BT_DISABLE_WORLD_GRAVITY))
	{
		body->setGravity(m_gravity);
	}

	if (body->getCollisionShape())
	{
		if (!body->isStaticObject())
		{
			m_nonStaticRigidBodies.push_back(body);
		} else
		{
			body->setActivationState(ISLAND_SLEEPING);
		}

		bool isDynamic = !(body->isStaticObject() || body->isKinematicObject());
		short collisionFilterGroup = isDynamic? short(btBroadphaseProxy::DefaultFilter) : short(btBroadphaseProxy::StaticFilter);
		short collisionFilterMask = isDynamic? 	short(btBroadphaseProxy::AllFilter) : 	short(btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter);

		addCollisionObject(body,collisionFilterGroup,collisionFilterMask);
	}
}
예제 #14
0
	void SimpleLightSource::createCollisionObject() {
		
		if(mBodyCollisionObject != 0) {
			delete mBodyCollisionObject;
		}
		mBodyCollisionObject = 0;

		CylinderGeom geom(this, mRadius->get(), 0.05);
		Quaternion orientation;
		if(mSwitchYZAxes != 0 && mSwitchYZAxes->get()) {
			orientation.setFromAngles(90.0, 0.0, 0.0);
		}
		else {
			orientation.setFromAngles(0.0, 0.0, 90.0);
		}
		geom.setLocalOrientation(orientation);
		mBodyCollisionObject = new CollisionObject(geom);

		addGeometry(mBodyCollisionObject->getGeometry());
		mBodyCollisionObject->setMaterialType("Light");
		mBodyCollisionObject->setTextureType("None");
		mBodyCollisionObject->getGeometry()->setColor(mLightColor->get());
		addCollisionObject(mBodyCollisionObject);
	}