OpenGL+Bullet Kinematic 角色控制

本文介绍了如何利用OpenGL结合Bullet物理引擎,通过Kinematic类实现角色控制。文中引用了《OpenGL游戏编程》中Chess游戏的代码,并展示了创建地面盒子、中央球体以及角色控制的初步实现。最后,提供了实验成果的截图。
摘要由CSDN通过智能技术生成

首先要感谢《OpenGL游戏编程》中的Chess游戏的部分代码。

下面是Bullet物理引擎初试话部分。其中包括一个代表地面的盒子btBoxShape,以及一个球体放置在最中央,最后是我们的角色使用Bullet中的Kinematic类来控制

m_collisionConfiguration = new btDefaultCollisionConfiguration();
	//m_collisionConfiguration->setConvexConvexMultipointIterations();

	///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
	m_dispatcher = new	btCollisionDispatcher(m_collisionConfiguration);
	
	m_broadphase = new btDbvtBroadphase();

	btVector3 worldMin(-1000,-1000,-1000);
	btVector3 worldMax(1000,1000,1000);
	btAxisSweep3* sweepBP = new btAxisSweep3(worldMin,worldMax);
	m_overlappingPairCache = sweepBP;

	///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
	btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
	m_solver = sol;

	m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_solver,m_collisionConfiguration);
	
	m_dynamicsWorld->getDispatchInfo().m_allowedCcdPenetration=0.0001f;

	m_dynamicsWorld->setGravity(btVector3(0,-10,0));
	
	btBoxShape* box = new btBoxShape(btVector3(btScalar(8.),btScalar(1.0),btScalar(8.)));
//	box->initializePolyhedralFeatures();
	btCollisionShape* groundShape = box;

//	btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50);
	
	m_collisionShapes.push_back(groundShape);
//	m_colli
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值