Skip to content

Instantly share code, notes, and snippets.

@XProger
Created September 17, 2018 13:32
Show Gist options
  • Save XProger/da6fbd037a257c4e96ab1a6387121c93 to your computer and use it in GitHub Desktop.
Save XProger/da6fbd037a257c4e96ab1a6387121c93 to your computer and use it in GitHub Desktop.
support mapping for basic primitives
void supportPoint(const Body &body, const vec3 &dir, vec3 &v) {
v = vec3::ZERO;
}
void supportSegment(const Body &body, const vec3 &dir, vec3 &v) {
v.x = v.z = 0.0f;
v.y = sign(dir.y) * body.height;
}
void supportRect(const Body &body, const vec3 &dir, vec3 &v) {
v.x = sign(dir.x) * body.size.x;
v.y = sign(dir.y) * body.size.y;
v.z = 0.0f;
}
void supportDisc(const Body &body, const vec3 &dir, vec3 &v) {
v = vec3(dir.x, 0, dir.z).normal() * body.radius;
}
void supportSphere(const Body &body, const vec3 &dir, vec3 &v) {
v = dir * (body.radius / dir.length());
}
void supportBox(const Body &body, const vec3 &dir, vec3 &v) {
v = vec3(sign(dir.x), sign(dir.y), sign(dir.z)) * body.size;
}
void supportRound(const Body &body, const vec3 &dir, vec3 &v) {
vec3 s;
supportBox(body, dir, v);
supportSphere(body, dir, s);
v += s;
}
void supportCapsule(const Body &body, const vec3 &dir, vec3 &v) {
vec3 s;
supportSegment(body, dir, v);
supportSphere(body, dir, s);
v += s;
}
void supportCylinder(const Body &body, const vec3 &dir, vec3 &v) {
vec3 s;
supportSegment(body, dir, v);
supportDisc(body, dir, s);
v += s;
}
void supportCone(const Body &body, const vec3 &dir, vec3 &v) {
vec3 s = vec3(0.0f, body.height, 0.0f);
supportDisc(body, dir, v);
v = dir.dot(v) > dir.dot(s) ? v : s;
}
void supportWheel(const Body &body, const vec3 &dir, vec3 &v) {
vec3 s;
supportDisc(body, dir, v);
supportSphere(body, dir, s);
v += s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment