• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ btDiscreteDynamicsWorld类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中btDiscreteDynamicsWorld的典型用法代码示例。如果您正苦于以下问题:C++ btDiscreteDynamicsWorld类的具体用法?C++ btDiscreteDynamicsWorld怎么用?C++ btDiscreteDynamicsWorld使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了btDiscreteDynamicsWorld类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: setup

	void setup()
	{
		mCam = new CameraPersp( getWindowWidth(), getWindowHeight(), 60.0f );
		mCam->lookAt(Vec3f(100,400,-400), Vec3f::zero());
		
		mSurface = 0;
		mTexture = 0;
		mCapture = new Capture( 320, 240 );
		mCapture->startCapture();
		mPaused = false;
		mDrawTextured = true;
		
		btVector3 worldAabbMin(-10000,-10000,-10000);
		btVector3 worldAabbMax(10000,10000,10000);
		int maxProxies = 1024;
		
		btAxisSweep3 * broadphase									= new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
		btDefaultCollisionConfiguration	* collisionConfiguration	= new btDefaultCollisionConfiguration();
		btCollisionDispatcher * dispatcher							= new btCollisionDispatcher(collisionConfiguration);
		btSequentialImpulseConstraintSolver * solver				= new btSequentialImpulseConstraintSolver;
		
		dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
		dynamicsWorld->setGravity(btVector3(0,-10,0));
		
		btCollisionShape * groundShape	= new btStaticPlaneShape(btVector3(0,1,0),1);
		
		btDefaultMotionState * groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
		btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
		
		groundRigidBody = new btRigidBody(groundRigidBodyCI);
		dynamicsWorld->addRigidBody(groundRigidBody);
		
	}
开发者ID:AaronMeyers,项目名称:Cinder,代码行数:33,代码来源:bullettest.cpp


示例2: init

    void init()
    {
        m_collisionConfiguration = new btDefaultCollisionConfiguration();
        m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
        m_overlappingPairCache = new btDbvtBroadphase();
        m_solver = new btSequentialImpulseConstraintSolver();
        m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher, m_overlappingPairCache, m_solver, m_collisionConfiguration);

        m_dynamicsWorld->setGravity(btVector3(0, 0, 0));

        m_debugDraw = new BulletDebugDraw();
        m_dynamicsWorld->setDebugDrawer(m_debugDraw);
    }
开发者ID:selony,项目名称:libdf3d,代码行数:13,代码来源:PhysicsManager.cpp


示例3:

BulletBoundsInstance::BulletBoundsInstance(btDiscreteDynamicsWorld& dynamicsWorld, float mass, const btTransform& instanceToWorldTransform, btCollisionShape* collisionShape, const btVector3& localInertia) :
	motionState_(instanceToWorldTransform),
	rigidBody_( btRigidBody::btRigidBodyConstructionInfo(mass, &motionState_, collisionShape, localInertia) )
{
	rigidBody_.setDamping(0.1, 0.75);

	//add the body to the dynamics world
	dynamicsWorld.addRigidBody(&rigidBody_);
}
开发者ID:JonnyRivers,项目名称:rorn,代码行数:9,代码来源:BulletBoundsInstance.cpp


示例4: btDefaultCollisionConfiguration

void triMeshApp::initPhysics()
{
	// setup physics environment. for all basic rigid body physics this can be left as it is
	m_collisionConfiguration = new btDefaultCollisionConfiguration();
	m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
	m_broadphase = new btDbvtBroadphase();
	btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
	m_solver = sol;
	
	m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration);
	m_dynamicsWorld->setGravity(btVector3(0,-10,0));
	
}
开发者ID:jdduke,项目名称:Cinder,代码行数:13,代码来源:triMeshApp.cpp


示例5: btDefaultCollisionConfiguration

void winBodiesApp::initPhysics()
{
	// setup physics environment. for all basic rigid body physics this can be left as it is
	m_collisionConfiguration = new btDefaultCollisionConfiguration();
	m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
	m_broadphase = new btDbvtBroadphase();
	btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
	m_solver = sol;
	
	m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration);
	m_dynamicsWorld->setGravity(btVector3(0,-10,0));
	
	
	// make a ground plane that cannot be moved
	btCollisionShape * groundShape	= new btStaticPlaneShape(btVector3(0,1,0),1);
	
	btDefaultMotionState * groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
	btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
	
	m_groundRigidBody = std::shared_ptr<btRigidBody>(new btRigidBody(groundRigidBodyCI));
	m_dynamicsWorld->addRigidBody(m_groundRigidBody.get());
	
	
}
开发者ID:jdduke,项目名称:Cinder,代码行数:24,代码来源:winBodiesApp.cpp


示例6: PhysicsObject

     PhysicsObject(btDiscreteDynamicsWorld & world, const T & shape, 
             btScalar mass, btVector3 velocity,
             const btTransform & transform, 
             GameBall * ptrBall):
         _shape(shape),
         _motionState(transform),
         _rigidBody(mass, &_motionState, &_shape),
         _ptrBall(ptrBall)
 {
     // TODO angular velocity ?
     _rigidBody.setLinearVelocity(velocity);
     _rigidBody.setDamping(0.1, 0.1);
     _rigidBody.setRestitution(0.7);
     _rigidBody.setFriction(0.1);
     // TODO _rigidBody.setRollingFriction(0.01);
     world.addRigidBody(&_rigidBody);
 }
开发者ID:juliendehos,项目名称:petanqulator,代码行数:17,代码来源:Physics.hpp


示例7: assert

void BulletWrapper::init()
{
  assert(!m_Broadphase && !m_CollisionConfiguration && !m_Dispatcher && !m_Solver && !m_DynamicsWorld);

  m_Broadphase = new btDbvtBroadphase();

  m_CollisionConfiguration = new btDefaultCollisionConfiguration();
  m_Dispatcher = new btCollisionDispatcher(m_CollisionConfiguration);

  m_Dispatcher->setNearCallback(MyNearCallback);

  m_Solver = new btSequentialImpulseConstraintSolver;

  m_DynamicsWorld = new btDiscreteDynamicsWorld(m_Dispatcher, m_Broadphase, m_Solver, m_CollisionConfiguration);

  //m_DynamicsWorld->setGravity(btVector3(0, -10, 0));
  m_DynamicsWorld->setGravity(btVector3(0, 0, 0));
}
开发者ID:FutingFan,项目名称:hackstate,代码行数:18,代码来源:PhysicsLayer.cpp


示例8: createBulletSim

    void createBulletSim(void) {
         // EN:: collision configuration contains default setup for memory, collision setup.
         // EN:: Advanced users can create their own configuration.

         // BR:: configuração de colisão contem configurações padrão da memória.
         // BR:: usuários avançados podem criar suas próprias configurações.
         collisionConfiguration = new btDefaultCollisionConfiguration();

         // EN:: use the default collision dispatcher. For parallel processing
         // EN:: you can use a diffent dispatcher (see Extras/BulletMultiThreaded)

         // BR:: use o dispatcher padrão. para processamento paralelo
         // BR:: você pode usar um dispatcher diferente. (ver Doc)
         dispatcher = new   btCollisionDispatcher(collisionConfiguration);

         // EN:: btDbvtBroadphase is a good general purpose broadphase.
         // EN:: You can also try out btAxis3Sweep.

         // BR:: btDbvtBroadphase é um bom broadphase de propósito geral.
         // BR:: Você pode tentar também btAxis3Sweep.
         overlappingPairCache = new btDbvtBroadphase();

         // EN:: the default constraint solver. For parallel processing
         // EN:: you can use a different solver (see Extras/BulletMultiThreaded)

         // BR:: usa a constraint solver padrão. Para processamento paralelo
         // BR:: você pode ver um solver diferente (ver Doc)
         solver = new btSequentialImpulseConstraintSolver;

         dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,overlappingPairCache,solver,collisionConfiguration);
         dynamicsWorld->setGravity(btVector3(0,-10,0));

         // EN:: create a few basic rigid bodies
         // EN:: start with ground plane, 1500, 1500

         // BR:: cria alguns corpos rígidos básicos
         // BR:: inicializa com um chão plano.
         btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(1500.),btScalar(1.),btScalar(1500.)));

         collisionShapes.push_back(groundShape);

         btTransform groundTransform;
         groundTransform.setIdentity();
         groundTransform.setOrigin(btVector3(0,-2,0));

         {
            btScalar mass(0.);

            // EN:: rigidbody is dynamic if and only if mass is non zero, otherwise static
            // BR:: corpo rigido é dimâmico apenas se massa for diferente de 0.
            bool isDynamic = (mass != 0.f);

            btVector3 localInertia(0,0,0);
            if (isDynamic)
               groundShape->calculateLocalInertia(mass,localInertia);

            btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
            btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
            btRigidBody* body = new btRigidBody(rbInfo);

            // EN:: add the body to the dynamics world
            // BR:: adiciona o corpo às dinâmicas do mundo
            dynamicsWorld->addRigidBody(body);
         }


         {
            // EN:: create a dynamic rigidbody
            // BR:: cria um corpo rígido dinâmico
            btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));
            collisionShapes.push_back(colShape);

            // EN:: Create Dynamic Objects
            // BR:: Cria objetos dinâmicos
            btTransform startTransform;
            startTransform.setIdentity();

            btScalar   mass(1.f);

            // EN:: rigidbody is dynamic if and only if mass is non zero, otherwise static
            // BR:: corpo rigido é dimâmico apenas se massa for diferente de 0.
            bool isDynamic = (mass != 0.f);

            btVector3 localInertia(0,0,-1.0);
            if (isDynamic)
               colShape->calculateLocalInertia(mass,localInertia);

               startTransform.setOrigin(btVector3(0,250,0));
               // *** give it a slight twist so it bouncees more interesting
               startTransform.setRotation(btQuaternion(btVector3(1.0, 1.0, 0.0), 0.6));

               //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
               //btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
               MyMotionState* motionState = new MyMotionState(startTransform, boxNode);
               btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,motionState,colShape,localInertia);
               btRigidBody* body = new btRigidBody(rbInfo);

               dynamicsWorld->addRigidBody(body);
         }
    }
开发者ID:DurvalPCN,项目名称:ogre3d-example,代码行数:100,代码来源:ogre3d-cubeDemo.cpp


示例9: clean

    void clean()
    {
        if (!m_dynamicsWorld)
            return;

        for (int i = m_dynamicsWorld->getNumCollisionObjects() - 1; i >= 0; i--)
        {
            btCollisionObject *obj = m_dynamicsWorld->getCollisionObjectArray()[i];
            btRigidBody *body = btRigidBody::upcast(obj);
            if (body && body->getMotionState())
                delete body->getMotionState();
            if (body && body->getCollisionShape())
                delete body->getCollisionShape();

            m_dynamicsWorld->removeCollisionObject(obj);
            delete obj;
        }

        SAFE_DELETE(m_dynamicsWorld);
        SAFE_DELETE(m_solver);
        SAFE_DELETE(m_overlappingPairCache);
        SAFE_DELETE(m_dispatcher);
        SAFE_DELETE(m_collisionConfiguration);
        SAFE_DELETE(m_debugDraw);
    }
开发者ID:selony,项目名称:libdf3d,代码行数:25,代码来源:PhysicsManager.cpp


示例10: exitPhysics

void triMeshApp::exitPhysics()
{
	//cleanup in the reverse order of creation/initialization
	
	if(m_convexRigidBody->getMotionState())
		delete m_convexRigidBody->getMotionState();
	m_dynamicsWorld->removeRigidBody(m_convexRigidBody);
	delete m_convexRigidBody;
	
	if(m_concaveRigidBody->getMotionState())
		delete m_concaveRigidBody->getMotionState();
	m_dynamicsWorld->removeRigidBody(m_concaveRigidBody);
	delete m_concaveRigidBody;
	
	if(m_hfRigidBody->getMotionState())
		delete m_hfRigidBody->getMotionState();
	m_dynamicsWorld->removeRigidBody(m_hfRigidBody);
	delete m_hfRigidBody;
	
	
	delete m_dynamicsWorld;
	
	delete m_solver;
	
	delete m_broadphase;
	
	delete m_dispatcher;
	
	delete m_collisionConfiguration;
}
开发者ID:jdduke,项目名称:Cinder,代码行数:30,代码来源:triMeshApp.cpp


示例11:

 ~World(void) {
   for (auto &robot : robots)
     dynamics.removeRigidBody(&robot.body);
   for (auto &ball : balls)
     dynamics.removeRigidBody(&ball.body);
   dynamics.removeRigidBody(&field.ground_body);
   dynamics.removeRigidBody(&field.ceil_body);
   dynamics.removeRigidBody(&field.left_wall_body);
   dynamics.removeRigidBody(&field.right_wall_body);
   dynamics.removeRigidBody(&field.top_wall_body);
   dynamics.removeRigidBody(&field.bottom_wall_body);
   dynamics.removeRigidBody(&field.left_goal_body);
   dynamics.removeRigidBody(&field.right_goal_body);
 }
开发者ID:gustavokcouto,项目名称:ssl-sim,代码行数:14,代码来源:sslsim.cpp


示例12: World

 World(const FieldGeometry *const field_geom)
     : field_geometry{field_geom}, field{field_geom} {
   dynamics.setGravity({0, 0, -9.80665});
   dynamics.addRigidBody(&field.ground_body);
   dynamics.addRigidBody(&field.ceil_body);
   dynamics.addRigidBody(&field.left_wall_body);
   dynamics.addRigidBody(&field.right_wall_body);
   dynamics.addRigidBody(&field.top_wall_body);
   dynamics.addRigidBody(&field.bottom_wall_body);
   dynamics.addRigidBody(&field.left_goal_body);
   dynamics.addRigidBody(&field.right_goal_body);
   balls.emplace_back();
   dynamics.addRigidBody(&balls.back().body);
   ball_set_vec(&balls.back(), {});
 }
开发者ID:gustavokcouto,项目名称:ssl-sim,代码行数:15,代码来源:sslsim.cpp


示例13: RefreshColShape

	// Physics dll internal
	void RefreshColShape(IPhysicsInterface* colProvider){
		if (!colProvider)
		{
			Logger::Log(FB_ERROR_LOG_ARG, "No colProvider");			
			return;
		}
		mWorld->removeRigidBody(mSelf);
		mAddedToWorld = false;
		auto prevColShape = mSelf->getCollisionShape();
		if (prevColShape){
			Physics::GetInstance().Release(prevColShape);
		}

		btCollisionShape* colShape = 0;
		float mass = 1.0f;
		auto& physics = Physics::GetInstance();
		if (mGroupedRigidBody){
			if (colProvider->GetNumColShapes(mGroupIdx) == 0)
				return;

			colShape = physics.CreateColShapeForGroup(colProvider, mGroupIdx);
			mass = colProvider->GetMassForGroup(mGroupIdx);
		}
		else{
			if (colProvider->GetNumColShapes() == 0)
				return;

			colShape = physics.CreateColShape(colProvider);
			mass = colProvider->GetMass();
		}
		assert(colShape);
		mSelf->setCollisionShape(colShape);
		if (colShape)
			physics.AddRef(colShape);

		if (mass > 0 && colShape)
		{
			btVector3 inertia;
			colShape->calculateLocalInertia(mass, inertia);			
			mSelf->setMassProps(mass, inertia);
		}
		else{
			SetMass(0.f);
		}
		assert(!mAddedToWorld);
		mWorld->addRigidBody(mSelf, colProvider->GetCollisionGroup(), colProvider->GetCollisionMask());
		mAddedToWorld = true;
	}
开发者ID:wangscript,项目名称:fastbirdEngine,代码行数:49,代码来源:RigidBodyImpl.cpp


示例14: update

void triMeshApp::update()
{
	
	m_dynamicsWorld->stepSimulation(1.0f, 10);
	
	double now = getElapsedSeconds();
	double dt = now - lastTime;
	lastTime = now;
	
	bool objectsErased = false;
	
	for(int i = 0; i < mObjects.size(); i++)
	{
		mObjects[i]->update(dt);
		
		if(mObjects[i]->lifetime > MAX_LIFETIME)
		{
			mObjects.erase(mObjects.begin() + i);
			objectsErased = true;
		}
	}
	
	if(objectsErased)
		activateAllObjects(m_dynamicsWorld);
	
	yrot += dt * 36.0;
	if(yrot >=360.0) yrot = 0.0;
	
}
开发者ID:jdduke,项目名称:Cinder,代码行数:29,代码来源:triMeshApp.cpp


示例15: frameStarted

      // frame listener
   bool frameStarted(const FrameEvent &evt)
    {
      mKeyboard->capture();

        // update physics simulation
      dynamicsWorld->stepSimulation(evt.timeSinceLastFrame,50);
        return mContinue;
    }
开发者ID:Doctatur,项目名称:OgreBulletKinect,代码行数:9,代码来源:BulletHelloWorld.cpp


示例16: update

	void update()
	{
		if( mCapture->checkNewFrame() ) {
			delete mTexture;
			mTexture = new gl::Texture( mCapture->getSurface() );
		}
		
		if( ! mPaused )
			dynamicsWorld->stepSimulation(1.0f, 10);
	}
开发者ID:AaronMeyers,项目名称:Cinder,代码行数:10,代码来源:bullettest.cpp


示例17: UnregisterFromWorld

	void UnregisterFromWorld(){
		if (mWorld){
			auto num = mSelf->getNumConstraintRefs();
			for (int i = 0; i < num; ++i){
				auto constraint = mSelf->getConstraintRef(i);
				assert(constraint);
				constraint->setEnabled(false);
			}
			mWorld->removeRigidBody(mSelf);
			mAddedToWorld = false;
		}		
	}
开发者ID:wangscript,项目名称:fastbirdEngine,代码行数:12,代码来源:RigidBodyImpl.cpp


示例18: UnregisterFromWorld

	void UnregisterFromWorld(){
		if (mWorld){
			auto num = mSelf->getNumConstraintRefs();
			for (int i = 0; i < num; ++i){
				auto constraint = mSelf->getConstraintRef(i);
				assert(constraint);
				constraint->setEnabled(false);
			}
			mWorld->removeRigidBody(mSelf);
			mAddedToWorld = false;
		}
		else
			Logger::Log(FB_ERROR_LOG_ARG, "No colprovier exists!");			
	}
开发者ID:fastbird,项目名称:fastbirdEngine_NewAPI,代码行数:14,代码来源:RigidBodyImpl.cpp


示例19: drawEvent

void BulletExample::drawEvent() {
    GL::defaultFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);

    /* Housekeeping: remove any objects which are far away from the origin */
    for(Object3D* obj = _scene.children().first(); obj; )
    {
        Object3D* next = obj->nextSibling();
        if(obj->transformation().translation().dot() > 100*100)
            delete obj;

        obj = next;
    }

    /* Step bullet simulation */
    _bWorld.stepSimulation(_timeline.previousFrameDuration(), 5);

    /* Draw the cubes */
    if(_drawCubes) _camera->draw(_drawables);

    /* Debug draw. If drawing on top of cubes, avoid flickering by setting
       depth function to <= instead of just <. */
    if(_drawDebug) {
        if(_drawCubes)
            GL::Renderer::setDepthFunction(GL::Renderer::DepthFunction::LessOrEqual);

        _debugDraw.setTransformationProjectionMatrix(
            _camera->projectionMatrix()*_camera->cameraMatrix());
        _bWorld.debugDrawWorld();

        if(_drawCubes)
            GL::Renderer::setDepthFunction(GL::Renderer::DepthFunction::Less);
    }

    swapBuffers();
    _timeline.nextFrame();
    redraw();
}
开发者ID:mosra,项目名称:magnum-examples,代码行数:37,代码来源:BulletExample.cpp


示例20: removeAllBodies

void BulletWrapper::removeAllBodies()
{
  for (unsigned int i = 0; i < m_BodyDatas.size(); i++)
  {
    btRigidBody* body = m_BodyDatas[i].m_Body;

    m_DynamicsWorld->removeRigidBody(body);
    delete body->getMotionState();
    delete body;

    // Shape is automatically released via the shared pointer
  }

  m_BodyDatas.clear();
}
开发者ID:FutingFan,项目名称:hackstate,代码行数:15,代码来源:PhysicsLayer.cpp



注:本文中的btDiscreteDynamicsWorld类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ btDispatcher类代码示例发布时间:2022-05-31
下一篇:
C++ btConstraintSolver类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap