void ofxRParticleSystem::init() { uniqueIDs = 0; count = new float; damping = new float; restitution = new float; accLimit = new float; velLimit = new float; dt = new float; setDt(1.0); setCount(0); setDamping(.25); setRestitution(1.0); setAccelerationLimit(5.0); setVelocityLimit(10.0); renderer = new ofxRParticleRenderer(); renderer->setParticlesPtr(&particles); solver = NULL; solver = new ofxSolver(1); setSolver(*solver); }
PhysicsInterface::BodyObject Bullet::createCapsuleBody(float height, float radius, float mass, bool fixed, const Entity* entity, const SimpleTransform& initialTransform) { auto collisionShape = new btCapsuleShape(radius, height); // Calculate inertia auto localInertia = btVector3(0.0f, 0.0f, 0.0f); if (!fixed) collisionShape->calculateLocalInertia(mass, localInertia); // Motion state for this body auto motionState = new btDefaultMotionState(toBullet(initialTransform)); // Create Bullet rigid body auto bulletBody = new btRigidBody( btRigidBody::btRigidBodyConstructionInfo(fixed ? 0.0f : mass, motionState, collisionShape, localInertia)); bulletBody->setDamping(DefaultLinearDamping, DefaultAngularDamping); bulletBody->setSleepingThresholds(DefaultLinearSleepingThreshold, DefaultAngularSleepingThreshold); bulletBody->setRestitution(0.0f); // Add body to the simulation dynamicsWorld_->addRigidBody(bulletBody); // Create local body auto body = new Body(bulletBody, entity, fixed); bodies_.append(body); body->ownedCollisionShape = collisionShape; bulletBody->setUserPointer(body); return body; }
void btRigidBody::setupRigidBody(const btRigidBody::btRigidBodyConstructionInfo& constructionInfo) { m_internalType=CO_RIGID_BODY; m_linearVelocity.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)); m_angularVelocity.setValue(btScalar(0.),btScalar(0.),btScalar(0.)); m_angularFactor.setValue(1,1,1); m_linearFactor.setValue(1,1,1); m_gravity.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)); m_gravity_acceleration.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)); m_totalForce.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)); m_totalTorque.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)), setDamping(constructionInfo.m_linearDamping, constructionInfo.m_angularDamping); m_linearSleepingThreshold = constructionInfo.m_linearSleepingThreshold; m_angularSleepingThreshold = constructionInfo.m_angularSleepingThreshold; m_optionalMotionState = constructionInfo.m_motionState; m_contactSolverType = 0; m_frictionSolverType = 0; m_additionalDamping = constructionInfo.m_additionalDamping; m_additionalDampingFactor = constructionInfo.m_additionalDampingFactor; m_additionalLinearDampingThresholdSqr = constructionInfo.m_additionalLinearDampingThresholdSqr; m_additionalAngularDampingThresholdSqr = constructionInfo.m_additionalAngularDampingThresholdSqr; m_additionalAngularDampingFactor = constructionInfo.m_additionalAngularDampingFactor; if (m_optionalMotionState) { m_optionalMotionState->getWorldTransform(m_worldTransform); } else { m_worldTransform = constructionInfo.m_startWorldTransform; } m_interpolationWorldTransform = m_worldTransform; m_interpolationLinearVelocity.setValue(0,0,0); m_interpolationAngularVelocity.setValue(0,0,0); //moved to btCollisionObject m_friction = constructionInfo.m_friction; m_restitution = constructionInfo.m_restitution; setCollisionShape( constructionInfo.m_collisionShape ); m_debugBodyId = uniqueId++; setMassProps(constructionInfo.m_mass, constructionInfo.m_localInertia); updateInertiaTensor(); m_rigidbodyFlags = 0; m_deltaLinearVelocity.setZero(); m_deltaAngularVelocity.setZero(); m_invMass = m_inverseMass*m_linearFactor; m_pushVelocity.setZero(); m_turnVelocity.setZero(); }
RigidBody::RigidBody( const MassProps& massProps,SimdScalar linearDamping,SimdScalar angularDamping,SimdScalar friction,SimdScalar restitution) : m_gravity(0.0f, 0.0f, 0.0f), m_totalForce(0.0f, 0.0f, 0.0f), m_totalTorque(0.0f, 0.0f, 0.0f), m_linearVelocity(0.0f, 0.0f, 0.0f), m_angularVelocity(0.f,0.f,0.f), m_linearDamping(0.f), m_angularDamping(0.5f), m_kinematicTimeStep(0.f), m_contactSolverType(0), m_frictionSolverType(0) { //moved to CollisionObject m_friction = friction; m_restitution = restitution; m_debugBodyId = uniqueId++; setMassProps(massProps.m_mass, massProps.m_inertiaLocal); setDamping(linearDamping, angularDamping); m_worldTransform.setIdentity(); updateInertiaTensor(); }
Boid::Boid( ofVec2f position, ofVec2f velocity) { pos = position; vel = velocity; setPosition(pos); setVelocity(vel); damping = 0.98; setDamping(damping); }
OpenCloth::OpenCloth() : _built(false), _device(nullptr), _vertexBuffer(nullptr), _indexBuffer(nullptr), _vertices(nullptr), _indexCount(0), _indices(nullptr), _positions(nullptr), _lastPositions(nullptr), _forces(nullptr), _springCount(0), _springs(nullptr), _shader(nullptr), _constantsBuffer(nullptr) { setDivisions(20, 20); setSize(7); setMass(1.0f); setDamping(-0.0125f); setSpringParams(500.75f, -0.25f, 500.75f, -0.25f, 500.95f, -0.25f); setGravity(cc::Vec3f(0.0f, -9.81f ,0.0f)); _timeStep = 1.0f / 60.0f; _timeAccumulator = _timeStep; }
// you can call this function directly if you wish to use the same collision object for multiple rigid bodies, // which will increase performance // //-------------------------------------------------------------- void ofxBulletBaseShape::create( btDiscreteDynamicsWorld* a_world, btCollisionShape* a_colShape, btTransform &a_bt_tr, float a_mass ) { if(a_world == NULL) { ofLog(OF_LOG_ERROR, "ofxBulletSphere :: create : a_world param is NULL"); return; } _mass = a_mass; _world = a_world; _bCreated = true; _rigidBody = ofGetBtRigidBodyFromCollisionShape( a_colShape, a_bt_tr, a_mass); setProperties(.4, .75); setDamping( .25 ); }
void grafVParticleField::setup(int w_, int h_) { w = w_; h = h_; PS.setup(FIELD_SIZE,WIDTH_FIELD,HEIGHT_FIELD,w,h,&VF); //particleSystem psx; int toatlXtra = 4; for( int i = 0; i < toatlXtra; i++) { //XTRA_PS.push_back(psx); XTRA_PS[i].setup(FIELD_SIZE,WIDTH_FIELD,HEIGHT_FIELD,w,h,&VF); } setDamping( particle_damping); setParticleSize( particle_size ); }
PhysicsInterface::BodyObject Bullet::createGeometryBodyFromTemplate(BodyTemplateObject bodyTemplateObject, float mass, bool fixed, const Entity* entity, const SimpleTransform& initialTransform) { auto bodyTemplate = reinterpret_cast<BodyTemplate*>(bodyTemplateObject); if (!bodyTemplateObject || !bodyTemplate->collisionShape) { LOG_ERROR << "Invalid body template"; return nullptr; } // Calculate inertia auto localInertia = btVector3(0.0f, 0.0f, 0.0f); if (!fixed) bodyTemplate->collisionShape->calculateLocalInertia(mass, localInertia); // Motion state for this body auto motionState = new btDefaultMotionState(toBullet(initialTransform), btTransform(btQuaternion::getIdentity(), toBullet(Vec3::Zero))); // Create Bullet rigid body auto bulletBody = new btRigidBody( btRigidBody::btRigidBodyConstructionInfo((fixed ? 0.0f : mass), motionState, bodyTemplate->collisionShape, (fixed ? btVector3(0.0f, 0.0f, 0.0f) : localInertia))); bulletBody->setDamping(DefaultLinearDamping, DefaultAngularDamping); bulletBody->setSleepingThresholds(DefaultLinearSleepingThreshold, DefaultAngularSleepingThreshold); bulletBody->setRestitution(0.0f); // Add body to the simulation dynamicsWorld_->addRigidBody(bulletBody); // Create local body auto body = new Body(bulletBody, entity, fixed); bodies_.append(body); bulletBody->setUserPointer(body); return body; }
void PoweredRagdollControlsModifierUI::toggleSignals(bool toggleconnections){ if (toggleconnections){ connect(name, SIGNAL(textEdited(QString)), this, SLOT(setName(QString)), Qt::UniqueConnection); connect(enable, SIGNAL(released()), this, SLOT(setEnable()), Qt::UniqueConnection); connect(maxForce, SIGNAL(editingFinished()), this, SLOT(setMaxForce()), Qt::UniqueConnection); connect(tau, SIGNAL(editingFinished()), this, SLOT(setTau()), Qt::UniqueConnection); connect(damping, SIGNAL(editingFinished()), this, SLOT(setDamping()), Qt::UniqueConnection); connect(proportionalRecoveryVelocity, SIGNAL(released()), this, SLOT(setProportionalRecoveryVelocity()), Qt::UniqueConnection); connect(constantRecoveryVelocity, SIGNAL(released()), this, SLOT(setConstantRecoveryVelocity()), Qt::UniqueConnection); connect(poseMatchingBone0, SIGNAL(editingFinished()), this, SLOT(setPoseMatchingBone0()), Qt::UniqueConnection); connect(poseMatchingBone1, SIGNAL(editingFinished()), this, SLOT(setPoseMatchingBone1()), Qt::UniqueConnection); connect(poseMatchingBone2, SIGNAL(editingFinished()), this, SLOT(setPoseMatchingBone2()), Qt::UniqueConnection); connect(mode, SIGNAL(currentIndexChanged(int)), this, SLOT(setMode(int)), Qt::UniqueConnection); connect(bones, SIGNAL(pressed()), this, SLOT(viewBones()), Qt::UniqueConnection); connect(bones, SIGNAL(enabled(bool)), this, SLOT(toggleBones(bool)), Qt::UniqueConnection); connect(boneIndexUI, SIGNAL(returnToParent()), this, SLOT(returnToWidget()), Qt::UniqueConnection); connect(boneWeights, SIGNAL(pressed()), this, SLOT(viewBoneWeights()), Qt::UniqueConnection); connect(boneWeights, SIGNAL(enabled(bool)), this, SLOT(toggleBoneWeights(bool)), Qt::UniqueConnection); connect(boneWeightsUI, SIGNAL(returnToParent()), this, SLOT(returnToWidget()), Qt::UniqueConnection); connect(table, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(viewSelected(int,int)), Qt::UniqueConnection); }else{
// constructor // anchor, axis1 and axis2 are in world coordinate system // axis1 must be orthogonal to axis2 btHinge2Constraint::btHinge2Constraint(btRigidBody& rbA, btRigidBody& rbB, btVector3& anchor, btVector3& axis1, btVector3& axis2) : btGeneric6DofSpringConstraint(rbA, rbB, btTransform::getIdentity(), btTransform::getIdentity(), true), m_anchor(anchor), m_axis1(axis1), m_axis2(axis2) { // build frame basis // 6DOF constraint uses Euler angles and to define limits // it is assumed that rotational order is : // Z - first, allowed limits are (-PI,PI); // new position of Y - second (allowed limits are (-PI/2 + epsilon, PI/2 - epsilon), where epsilon is a small positive number // used to prevent constraint from instability on poles; // new position of X, allowed limits are (-PI,PI); // So to simulate ODE Universal joint we should use parent axis as Z, child axis as Y and limit all other DOFs // Build the frame in world coordinate system first btVector3 zAxis = axis1.normalize(); btVector3 xAxis = axis2.normalize(); btVector3 yAxis = zAxis.cross(xAxis); // we want right coordinate system btTransform frameInW; frameInW.setIdentity(); frameInW.getBasis().setValue( xAxis[0], yAxis[0], zAxis[0], xAxis[1], yAxis[1], zAxis[1], xAxis[2], yAxis[2], zAxis[2]); frameInW.setOrigin(anchor); // now get constraint frame in local coordinate systems m_frameInA = rbA.getCenterOfMassTransform().inverse() * frameInW; m_frameInB = rbB.getCenterOfMassTransform().inverse() * frameInW; // sei limits setLinearLowerLimit(btVector3(0.f, 0.f, -1.f)); setLinearUpperLimit(btVector3(0.f, 0.f, 1.f)); // like front wheels of a car setAngularLowerLimit(btVector3(1.f, 0.f, -SIMD_HALF_PI * 0.5f)); setAngularUpperLimit(btVector3(-1.f, 0.f, SIMD_HALF_PI * 0.5f)); // enable suspension enableSpring(2, true); setStiffness(2, SIMD_PI * SIMD_PI * 4.f); // period 1 sec for 1 kilogramm weel :-) setDamping(2, 0.01f); setEquilibriumPoint(); }
//-------------------------------------------------------------- void ofxBulletCustomShape::add() { _bAdded = true; btTransform trans; trans.setIdentity(); for(int i = 0; i < centroids.size(); i++) { _centroid += centroids[i]; } if(centroids.size() > 0) _centroid /= (float)centroids.size(); btVector3 shiftCentroid; for(int i = 0; i < shapes.size(); i++) { shiftCentroid = btVector3(centroids[i].x, centroids[i].y, centroids[i].z); shiftCentroid -= btVector3(_centroid.x, _centroid.y, _centroid.z); trans.setOrigin( ( shiftCentroid ) ); ((btCompoundShape*)_shape)->addChildShape( trans, shapes[i]); } _rigidBody = ofGetBtRigidBodyFromCollisionShape( _shape, _startTrans, _mass); createInternalUserData(); _world->addRigidBody(_rigidBody); setProperties(.4, .75); setDamping( .25 ); }
BodySystemGPU<T>::BodySystemGPU(unsigned int numBodies, unsigned int numDevices, unsigned int blockSize, bool usePBO, bool useSysMem) : m_numBodies(numBodies), m_numDevices(numDevices), m_bInitialized(false), m_bUsePBO(usePBO), m_bUseSysMem(useSysMem), m_currentRead(0), m_currentWrite(1), m_blockSize(blockSize) { m_hPos[0] = m_hPos[1] = 0; m_hVel = 0; m_deviceData = 0; _initialize(numBodies); setSoftening(0.00125f); setDamping(0.995f); }
PhysicsInterface::BodyObject Bullet::createBoundingBoxBody(const AABB& aabb, float mass, bool fixed, const Entity* entity, const SimpleTransform& initialTransform) { auto collisionShape = new btBoxShape(toBullet((aabb.getMaximum() - aabb.getMinimum()) * 0.5f)); // Calculate inertia auto localInertia = btVector3(0.0f, 0.0f, 0.0f); if (!fixed) collisionShape->calculateLocalInertia(mass, localInertia); // Motion state for this body auto motionState = new btDefaultMotionState(toBullet(initialTransform), btTransform(btQuaternion::getIdentity(), toBullet(aabb.getCenter()))); // Create Bullet rigid body auto bulletBody = new btRigidBody( btRigidBody::btRigidBodyConstructionInfo(fixed ? 0.0f : mass, motionState, collisionShape, localInertia)); bulletBody->setDamping(DefaultLinearDamping, DefaultAngularDamping); bulletBody->setSleepingThresholds(DefaultLinearSleepingThreshold, DefaultAngularSleepingThreshold); bulletBody->setRestitution(0.0f); // Add body to the simulation dynamicsWorld_->addRigidBody(bulletBody); // Create local body auto body = new Body(bulletBody, entity, fixed); bodies_.append(body); body->ownedCollisionShape = collisionShape; bulletBody->setUserPointer(body); return body; }
void velocityNav::updateInteraction() { // If we are not supposed to be active, then don't run if ( ! this->isActive() ) { return; } mAcceleratingForward = checkForAction(mActionButtons, mAccelForwardCombo); mBraking = checkForAction(mActionButtons, mBrakeCombo); mStopping = checkForAction(mActionButtons, mStopCombo); mResetting = checkForAction(mActionButtons, mResetCombo); mRotating = checkForAction(mActionButtons, mRotateCombo); // Braking if ( mBraking ) { mDamping = 0.85f; } else { mDamping = 1.0f; } // Stopping -- NOTE: This must go after braking if ( mStopping ) { setDamping(0.0f); } // Accelerate Forward // TODO: add other directions to accelerate. (since it's hard coded to // forward (0,0,-x) here...) if ( mAcceleratingForward ) { accelerate(gmtl::Vec3f(0.0f, 0.0f, -mAcceleration)); } // Resetting if ( mResetting ) { this->reset(); } // Rotating gmtl::Matrix44f rot_mat = mNavWand->getData(); //std::cout<<"1: "<<rot_mat<<"\n"<<std::flush; gmtl::setTrans(rot_mat, gmtl::Vec3f(0.0f, 0.0f, 0.0f)); //std::cout<<"2: "<<rot_mat<<"\n=======\n\n"<<std::flush; setRotationalAcceleration(rot_mat); // Output visual feedback if ( mAcceleratingForward ) { vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL) << clrOutNORM(clrCYAN,"velNav: Accelerating Forward") << "(Accel = " << mAcceleration << ")" << std::endl << vprDEBUG_FLUSH; } if ( mBraking ) { vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL) << clrOutNORM(clrCYAN,"velNav: Braking") << std::endl << vprDEBUG_FLUSH; } if ( mStopping ) { vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL) << clrOutNORM(clrCYAN,"velNav: Stopping") << std::endl << vprDEBUG_FLUSH; } if ( mResetting ) { gmtl::Vec3f hpos; gmtl::setTrans(hpos, mHomePos); vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL) << clrOutNORM(clrCYAN,"velNav: Resetting") << " to " << hpos << std::endl << vprDEBUG_FLUSH; } if ( mRotating ) { vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL) << clrOutNORM(clrCYAN,"velNav: Rotating") << std::endl << vprDEBUG_FLUSH; } }
//-------------------------------------------------------------- void ofxBulletBaseShape::setDamping( float a_linear_damp ) { setDamping( a_linear_damp, getAngularDamping() ); }
//-------------------------------------------------------------- void ofxBulletBaseShape::setAngularDamping( float a_angular_damp ) { setDamping( getDamping(), a_angular_damp ); }
void ofxBox2dBaseShape::setDamping(float f) { setDamping(f, f); }
void BConstraint::setAllAxisDamping(float damping) { for(int i = 0; i < 6; i++) setDamping(i, damping); }
connect(poseMatchingBone1, SIGNAL(editingFinished()), this, SLOT(setPoseMatchingBone1()), Qt::UniqueConnection); connect(poseMatchingBone2, SIGNAL(editingFinished()), this, SLOT(setPoseMatchingBone2()), Qt::UniqueConnection); connect(mode, SIGNAL(currentIndexChanged(int)), this, SLOT(setMode(int)), Qt::UniqueConnection); connect(bones, SIGNAL(pressed()), this, SLOT(viewBones()), Qt::UniqueConnection); connect(bones, SIGNAL(enabled(bool)), this, SLOT(toggleBones(bool)), Qt::UniqueConnection); connect(boneIndexUI, SIGNAL(returnToParent()), this, SLOT(returnToWidget()), Qt::UniqueConnection); connect(boneWeights, SIGNAL(pressed()), this, SLOT(viewBoneWeights()), Qt::UniqueConnection); connect(boneWeights, SIGNAL(enabled(bool)), this, SLOT(toggleBoneWeights(bool)), Qt::UniqueConnection); connect(boneWeightsUI, SIGNAL(returnToParent()), this, SLOT(returnToWidget()), Qt::UniqueConnection); connect(table, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(viewSelected(int,int)), Qt::UniqueConnection); }else{ disconnect(name, SIGNAL(textEdited(QString)), this, SLOT(setName(QString))); disconnect(enable, SIGNAL(released()), this, SLOT(setEnable())); disconnect(maxForce, SIGNAL(editingFinished()), this, SLOT(setMaxForce())); disconnect(tau, SIGNAL(editingFinished()), this, SLOT(setTau())); disconnect(damping, SIGNAL(editingFinished()), this, SLOT(setDamping())); disconnect(proportionalRecoveryVelocity, SIGNAL(released()), this, SLOT(setProportionalRecoveryVelocity())); disconnect(constantRecoveryVelocity, SIGNAL(released()), this, SLOT(setConstantRecoveryVelocity())); disconnect(poseMatchingBone0, SIGNAL(editingFinished()), this, SLOT(setPoseMatchingBone0())); disconnect(poseMatchingBone1, SIGNAL(editingFinished()), this, SLOT(setPoseMatchingBone1())); disconnect(poseMatchingBone2, SIGNAL(editingFinished()), this, SLOT(setPoseMatchingBone2())); disconnect(mode, SIGNAL(currentIndexChanged(int)), this, SLOT(setMode(int))); disconnect(bones, SIGNAL(pressed()), this, SLOT(viewBones())); disconnect(bones, SIGNAL(enabled(bool)), this, SLOT(toggleBones(bool))); disconnect(boneIndexUI, SIGNAL(returnToParent()), this, SLOT(returnToWidget())); disconnect(boneWeights, SIGNAL(pressed()), this, SLOT(viewBoneWeights())); disconnect(boneWeights, SIGNAL(enabled(bool)), this, SLOT(toggleBoneWeights(bool))); disconnect(boneWeightsUI, SIGNAL(returnToParent()), this, SLOT(returnToWidget())); disconnect(table, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(viewSelected(int,int))); } }