Raylib
raylib
是一个简单易用的2D/3D图形库。
ODE
open dynamics engine
是一个很老的高性能刚体物理运算库。
效果
代码
#include <vector>
#include <map>
#include "ode/ode.h"
#include "raylib.h"
int screenWidth = 1280; // 窗口宽
int screenHeight = 720; //窗口高
int fps = 60; // 帧率
int count = 15; // 单摆数量
double interval = .001; //每个小球之间的间隙
double phyicsStep = 0.0001; // 每次物理运算经过的时间
int subStep = 300; // 每一帧物理运算次数
dWorldID world;
dJointGroupID contactgroup;
dSpaceID space;
dMass m1;
std::map<dGeomID, dJointID> g2j;
std::map<dGeomID, Color> g2c;
const dReal *pos, *R;
struct MyObject {
dBodyID body;
dGeomID geom;
Model model;
dReal size;
};
void nearCallback(void *data, dGeomID o1, dGeomID o2) {
if (g2j.contains(o1) && g2j.contains(o2) && g2j[o1] == g2j[o2]) {
return;
}
int N = 1;
dContact contact[N];
int n = dCollide(o1, o2, N, &contact[0].geom, sizeof(dContact));
if (n > 0) {
g2c[o1] = RED;
g2c[o2] = RED;
}
for (int i = 0; i < n; i++) {
contact[i].surface.mod