物理引擎中的刚体转动1
2018-06-19 08:31
405 查看
在VREP中的物体上添加一个力矩看看它会怎么运动。新建一个场景,向其中添加一个立方体,将立方体抬高离开地面,并在Dynamics选项卡中将重力设置为0. 然后在立方体上施加一个力矩T={1,1,1},立方体将在力矩作用下旋转起来:
#include <btBulletDynamicsCommon.h> #include <stdio.h> #include <iostream> #include <fstream> using namespace std; /// This is a Hello World program for running a basic Bullet physics simulation int main(int argc, char** argv) { btBroadphaseInterface* broadphase = new btDbvtBroadphase(); ///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration. btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); ///use the default collision dispatcher. For parallel processing you can use a differnt dispatcher btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration); ///the default constraint solver. For parallel processing you can use a different solver btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; ///instantiate the dynamics world btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration); ///sets the gravity dynamicsWorld->setGravity(btVector3(0, 0, 0)); btCollisionShape* Shape = new btSphereShape(1); //The btTransform class supports rigid transforms with only translation and rotation btDefaultMotionState* MotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 50, 0))); btScalar mass = 1; btVector3 Inertia(2, 1, 1); btVector3 torque(1, 1, 1); btVector3 angularVelocity(0, 0, 0); ///when bodies are constructed, they are passed certain parameters. This is done through a special structure Bullet provides for this. ///rigid body is dynamic if and only if mass is non zero, otherwise static btRigidBody::btRigidBodyConstructionInfo RigidBodyCI(mass, MotionState, Shape, Inertia); btRigidBody* RigidBody = new btRigidBody(RigidBodyCI); dynamicsWorld->addRigidBody(RigidBody); ofstream outfile("data.csv", ios::out); for (int i = 0; i < 300; i++) { RigidBody->applyTorque(torque); dynamicsWorld->stepSimulation(1 / 60.f, 10); angularVelocity = RigidBody->getAngularVelocity(); outfile << angularVelocity.getX() << "," << angularVelocity.getY() << "," << angularVelocity.getZ() << endl; } outfile.close(); delete Shape; delete dynamicsWorld; delete solver; delete dispatcher; delete collisionConfiguration; delete broadphase; printf("Press a key to exit\n"); getchar(); }View Code [p] 接下来我们将进行正确的公式推到和转动模拟。 [/p]
参考:
Modern Robotics Mechanics, Planning, and Control Chapter 8. Dynamics of Open Chains
Game Physics Engine Development(https://github.com/idmillington/cyclone-physics)
Overview of core principles behind real-time physics systems
相关文章推荐
- 物理引擎中的刚体转动2
- Unity3D物理引擎中刚体组件的运用
- 【Unity 3D】学习笔记三十六:物理引擎——刚体
- Cocos2d-x3.3 Physics物理引擎模块解决了刚体穿透问题------沈大海
- Unity3D学习笔记(十一)物理引擎:刚体与力
- [原]Unity3D深入浅出 - 物理引擎之刚体部件(Rigidbody)
- unity3d 第四天 物理引擎 刚体
- Unity物理引擎-刚体碰撞
- Unity3D深入浅出 - 物理引擎之刚体部件(Rigidbody)
- 使用PhysicsEditor为物理引擎创建刚体形状
- cocos2d-x lua 物理引擎,速度过快导致的刚体穿透,穿越边界问题
- Cocos2d-x3.3 Physics物理引擎模块解决了刚体穿透问题
- Cocos2d-x3.3 Physics物理引擎模块解决了刚体穿透问题
- flash与物理引擎:销毁刚体
- Cocos物理引擎刚体的3种掩码
- 物理引擎Box2D之刚体
- Cocos2d-x3.3 Physics物理引擎模块解决了刚体穿透问题
- Unity3D - 物理引擎之刚体部件(Rigidbody)详解
- Cocos2d-x3.3 Physics物理引擎模块解决了刚体穿透问题
- Havok物理引擎-刚体介绍