您的位置:首页 > 其它

物理引擎中的刚体转动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]

 

参考:

物理引擎中的刚体转动2

刚体质量分布与牛顿-欧拉方程

Bullet物理引擎的安装与使用

Game Physics

Rigid Body Dynamics

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

Physics in 3D How to simulate the motion of rigid bodies

Physically Based Modeling ONLINE SIGGRAPH 2001 COURSE NOTES

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: