diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2006-12-02 06:48:36 +0300 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2006-12-02 06:48:36 +0300 |
commit | 28bbf2d61616f7b8b3c59b54b46af7ee4dbf1e11 (patch) | |
tree | 942f1211d5d0bb2f4ceaa6f08e3718f21c942dbb /source/gameengine | |
parent | bcb3aec646ad197874ceaf1ed535251e536cb3fd (diff) |
- added support for generic 6DOF constraint
- only 6DOF constraint shows buttons for limits
- added python support for rigidbody constraint (untested, but required for COLLADA Physics support)
Diffstat (limited to 'source/gameengine')
6 files changed, 92 insertions, 22 deletions
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index b8e273f3d19..2432462fecc 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -1939,12 +1939,37 @@ void BL_ConvertBlenderObjects(struct Main* maggie, for (curcon = (bConstraint *)conlist->first; curcon; curcon=(bConstraint *)curcon->next) { if (curcon->type==CONSTRAINT_TYPE_RIGIDBODYJOINT){ bRigidBodyJointConstraint *dat=(bRigidBodyJointConstraint *)curcon->data; - if (dat->tar) + //if (dat->tar) if (!dat->child){ - KX_GameObject *gotar=getGameOb(dat->tar->id.name,sumolist); + PHY_IPhysicsController* physctr2 = 0; + if (dat->tar) + { + KX_GameObject *gotar=getGameOb(dat->tar->id.name,sumolist); + physctr2 = (PHY_IPhysicsController*) gotar->GetPhysicsController()->GetUserData(); + } + PHY_IPhysicsController* physctrl = (PHY_IPhysicsController*) gameobj->GetPhysicsController()->GetUserData(); - PHY_IPhysicsController* physctr2 = (PHY_IPhysicsController*) gotar->GetPhysicsController()->GetUserData(); - kxscene->GetPhysicsEnvironment()->createConstraint(physctrl,physctr2,(PHY_ConstraintType)dat->type,(float)dat->pivX,(float)dat->pivY,(float)dat->pivZ,(float)dat->axX,(float)dat->axY,(float)dat->axZ); + + int constraintId = kxscene->GetPhysicsEnvironment()->createConstraint(physctrl,physctr2,(PHY_ConstraintType)dat->type,(float)dat->pivX,(float)dat->pivY,(float)dat->pivZ,(float)dat->axX,(float)dat->axY,(float)dat->axZ); + //if it is a generic 6DOF constraint, set all the limits accordingly + if (dat->type == PHY_GENERIC_6DOF_CONSTRAINT) + { + int dof; + int dofbit=1; + for (dof=0;dof<6;dof++) + { + if (dat->flag & dofbit) + { + kxscene->GetPhysicsEnvironment()->setConstraintParam(constraintId,dof,dat->minLimit[dof],dat->maxLimit[dof]); + } else + { + //minLimit > maxLimit means free(disabled limit) for this degree of freedom + kxscene->GetPhysicsEnvironment()->setConstraintParam(constraintId,dof,1,-1); + } + dofbit<<=1; + } + } + } } } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 37eb0ef76e3..db5de7c7d43 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -782,24 +782,37 @@ CcdPhysicsController* CcdPhysicsEnvironment::GetPhysicsController( int index) - +void CcdPhysicsEnvironment::setConstraintParam(int constraintId,int param,float value0,float value1) +{ + btTypedConstraint* typedConstraint = getConstraintById(constraintId); + switch (typedConstraint->getUserConstraintType()) + { + case PHY_GENERIC_6DOF_CONSTRAINT: + { + //param = 1..12, min0,max0,min1,max1...min6,max6 + btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint; + genCons->SetLimit(param,value0,value1); + break; + }; + default: + { + }; + }; +} btTypedConstraint* CcdPhysicsEnvironment::getConstraintById(int constraintId) { - return 0; - /* - int numConstraint = m_constraints.size(); + + int numConstraints = m_dynamicsWorld->getNumConstraints(); int i; - for (i=0;i<numConstraint;i++) + for (i=0;i<numConstraints;i++) { - btTypedConstraint* constraint = m_constraints[i]; + btTypedConstraint* constraint = m_dynamicsWorld->getConstraint(i); if (constraint->getUserConstraintId()==constraintId) { return constraint; } } - */ - return 0; } @@ -1004,7 +1017,8 @@ int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl return 0; btVector3 pivotInA(pivotX,pivotY,pivotZ); - btVector3 pivotInB = rb1 ? rb1->getCenterOfMassTransform().inverse()(rb0->getCenterOfMassTransform()(pivotInA)) : pivotInA; + btVector3 pivotInB = rb1 ? rb1->getCenterOfMassTransform().inverse()(rb0->getCenterOfMassTransform()(pivotInA)) : + rb0->getCenterOfMassTransform() * pivotInA; btVector3 axisInA(axisX,axisY,axisZ); btVector3 axisInB = rb1 ? (rb1->getCenterOfMassTransform().getBasis().inverse()*(rb0->getCenterOfMassTransform().getBasis() * axisInA)) : @@ -1072,17 +1086,41 @@ int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl } else { - // TODO: Implement single body case... + static btRigidBody s_fixedObject2( 0,0,0); + btTransform frameInA; + btTransform frameInB; + + btVector3 axis1, axis2; + btPlaneSpace1( axisInA, axis1, axis2 ); + + frameInA.getBasis().setValue( axisInA.x(), axis1.x(), axis2.x(), + axisInA.y(), axis1.y(), axis2.y(), + axisInA.z(), axis1.z(), axis2.z() ); + + btPlaneSpace1( axisInB, axis1, axis2 ); + frameInB.getBasis().setValue( axisInB.x(), axis1.x(), axis2.x(), + axisInB.y(), axis1.y(), axis2.y(), + axisInB.z(), axis1.z(), axis2.z() ); + + frameInA.setOrigin( pivotInA ); + frameInB.setOrigin( pivotInB ); + + + genericConstraint = new btGeneric6DofConstraint( + *rb0,s_fixedObject2, + frameInA,frameInB); } - - //m_constraints.push_back(genericConstraint); - m_dynamicsWorld->addConstraint(genericConstraint); - genericConstraint->setUserConstraintId(gConstraintUid++); - genericConstraint->setUserConstraintType(type); - //64 bit systems can't cast pointer to int. could use size_t instead. - return genericConstraint->getUserConstraintId(); + if (genericConstraint) + { + //m_constraints.push_back(genericConstraint); + m_dynamicsWorld->addConstraint(genericConstraint); + genericConstraint->setUserConstraintId(gConstraintUid++); + genericConstraint->setUserConstraintType(type); + //64 bit systems can't cast pointer to int. could use size_t instead. + return genericConstraint->getUserConstraintId(); + } break; } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h index 05c9e2a6b03..9a8fc3f435d 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h @@ -131,6 +131,7 @@ protected: const btVector3& angularMaxLimits ); + virtual void setConstraintParam(int constraintId,int param,float value,float value1); virtual void removeConstraint(int constraintid); diff --git a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h index 278f4eea9ca..bd4e00e9fa5 100644 --- a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h +++ b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h @@ -83,6 +83,9 @@ public: virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;} virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight) { return 0;} + virtual void setConstraintParam(int constraintId,int param,float value,float value1) + { + } }; diff --git a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h index 886bc8bb5fd..1afb9433500 100644 --- a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h +++ b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h @@ -86,7 +86,9 @@ public: virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position); virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight); - + virtual void setConstraintParam(int constraintId,int param,float value,float value1) + { + } SM_Scene* GetSumoScene() { return m_sumoScene; diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h index 2f3d8283d10..2716baa0d6d 100644 --- a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h +++ b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h @@ -107,6 +107,7 @@ class PHY_IPhysicsEnvironment virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) =0; virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight)=0; + virtual void setConstraintParam(int constraintId,int param,float value,float value1) = 0; }; #endif //_IPHYSICSENVIRONMENT |