-
Notifications
You must be signed in to change notification settings - Fork 160
/
common.hpp
44 lines (36 loc) · 1.54 KB
/
common.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef COMMON_HPP
#define COMMON_HPP
#include <cstdio>
#include <type_traits>
#include <btBulletDynamicsCommon.h>
#define COMMON_PRINTF_FLOAT "%.3e"
#define COMMON_PRINTF_HEADER "step body x y z vx vy vz rx ry rz angle rvx rvy rvz"
constexpr double PI2 = 2 * acos(-1.0);
void commonPrintBodyState(const btRigidBody *body, int step, int bodyIndex) {
btTransform trans;
if (body && body->getMotionState()) {
body->getMotionState()->getWorldTransform(trans);
} else {
trans = body->getWorldTransform();
}
auto position = trans.getOrigin();
auto velocity = body->getLinearVelocity();
auto rotationQuat = body->getCenterOfMassTransform().getRotation();
auto rotationAxis = rotationQuat.getAxis();
auto rotationAngle = rotationQuat.getAngle() / PI2;
auto angularVelocity = body->getAngularVelocity();
std::printf(
"%d %d "
COMMON_PRINTF_FLOAT " " COMMON_PRINTF_FLOAT " " COMMON_PRINTF_FLOAT " "
COMMON_PRINTF_FLOAT " " COMMON_PRINTF_FLOAT " " COMMON_PRINTF_FLOAT " "
COMMON_PRINTF_FLOAT " " COMMON_PRINTF_FLOAT " " COMMON_PRINTF_FLOAT " " COMMON_PRINTF_FLOAT " "
COMMON_PRINTF_FLOAT " " COMMON_PRINTF_FLOAT " " COMMON_PRINTF_FLOAT " "
,
step, bodyIndex,
position.getX(), position.getY(), position.getZ(),
velocity.getX(), velocity.getY(), velocity.getZ(),
rotationAxis.getX(), rotationAxis.getY(), rotationAxis.getZ(), rotationAngle,
angularVelocity.getX(), angularVelocity.getY(), angularVelocity.getZ()
);
}
#endif