fix a lot of issues, add gyroscopic force integrator, add contact polygon winding, add some quaternion constraints, add more tests
This commit is contained in:
@ -27,7 +27,21 @@
|
||||
extern Camera g_camera;
|
||||
extern DebugDraw* g_debugDraw;
|
||||
|
||||
Mat44 Camera::BuildProjectionMatrix() const
|
||||
static B3_FORCE_INLINE b3Mat34 Convert34(const b3Transform& T)
|
||||
{
|
||||
return b3Mat34(T.rotation.x, T.rotation.y, T.rotation.z, T.position);
|
||||
}
|
||||
|
||||
static B3_FORCE_INLINE b3Mat44 Convert44(const b3Transform& T)
|
||||
{
|
||||
return b3Mat44(
|
||||
b3Vec4(T.rotation.x.x, T.rotation.x.y, T.rotation.x.z, 0.0f),
|
||||
b3Vec4(T.rotation.y.x, T.rotation.y.y, T.rotation.y.z, 0.0f),
|
||||
b3Vec4(T.rotation.z.x, T.rotation.z.y, T.rotation.z.z, 0.0f),
|
||||
b3Vec4(T.position.x, T.position.y, T.position.z, 1.0f));
|
||||
}
|
||||
|
||||
b3Mat44 Camera::BuildProjectionMatrix() const
|
||||
{
|
||||
float32 t = tan(0.5f * m_fovy);
|
||||
float32 sy = 1.0f / t;
|
||||
@ -39,11 +53,11 @@ Mat44 Camera::BuildProjectionMatrix() const
|
||||
float32 sz = invRange * (m_zNear + m_zFar);
|
||||
float32 tz = invRange * m_zNear * m_zFar;
|
||||
|
||||
Mat44 m;
|
||||
m.x.Set(sx, 0.0f, 0.0f, 0.0f);
|
||||
m.y.Set(0.0f, sy, 0.0f, 0.0f);
|
||||
m.z.Set(0.0f, 0.0f, sz, -1.0f);
|
||||
m.w.Set(0.0f, 0.0f, tz, 0.0f);
|
||||
b3Mat44 m;
|
||||
m.x = b3Vec4(sx, 0.0f, 0.0f, 0.0f);
|
||||
m.y = b3Vec4(0.0f, sy, 0.0f, 0.0f);
|
||||
m.z = b3Vec4(0.0f, 0.0f, sz, -1.0f);
|
||||
m.w = b3Vec4(0.0f, 0.0f, tz, 0.0f);
|
||||
return m;
|
||||
}
|
||||
|
||||
@ -55,10 +69,10 @@ b3Transform Camera::BuildWorldTransform() const
|
||||
return xf;
|
||||
}
|
||||
|
||||
Mat44 Camera::BuildWorldMatrix() const
|
||||
b3Mat44 Camera::BuildWorldMatrix() const
|
||||
{
|
||||
b3Transform xf = BuildWorldTransform();
|
||||
return GetMat44(xf);
|
||||
return Convert44(xf);
|
||||
}
|
||||
|
||||
b3Transform Camera::BuildViewTransform() const
|
||||
@ -69,10 +83,10 @@ b3Transform Camera::BuildViewTransform() const
|
||||
return b3Inverse(xf);
|
||||
}
|
||||
|
||||
Mat44 Camera::BuildViewMatrix() const
|
||||
b3Mat44 Camera::BuildViewMatrix() const
|
||||
{
|
||||
b3Transform xf = BuildViewTransform();
|
||||
return GetMat44(xf);
|
||||
return Convert44(xf);
|
||||
}
|
||||
|
||||
b3Vec2 Camera::ConvertWorldToScreen(const b3Vec3& pw) const
|
||||
@ -150,11 +164,11 @@ static void PrintLog(GLuint id)
|
||||
static GLuint CreateShader(const char* source, GLenum type)
|
||||
{
|
||||
GLuint shaderId = glCreateShader(type);
|
||||
|
||||
|
||||
const char* sources[] = { source };
|
||||
glShaderSource(shaderId, 1, sources, NULL);
|
||||
glCompileShader(shaderId);
|
||||
|
||||
|
||||
GLint status = GL_FALSE;
|
||||
glGetShaderiv(shaderId, GL_COMPILE_STATUS, &status);
|
||||
if (status == GL_FALSE)
|
||||
@ -164,7 +178,7 @@ static GLuint CreateShader(const char* source, GLenum type)
|
||||
glDeleteShader(shaderId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return shaderId;
|
||||
}
|
||||
|
||||
@ -225,7 +239,7 @@ struct DrawPoints
|
||||
m_sizeAttribute = 2;
|
||||
|
||||
glGenBuffers(3, m_vboIds);
|
||||
|
||||
|
||||
glGenVertexArrays(1, &m_vaoId);
|
||||
|
||||
glBindVertexArray(m_vaoId);
|
||||
@ -282,14 +296,14 @@ struct DrawPoints
|
||||
|
||||
glUseProgram(m_programId);
|
||||
|
||||
Mat44 m1 = g_camera.BuildViewMatrix();
|
||||
Mat44 m2 = g_camera.BuildProjectionMatrix();
|
||||
Mat44 m = m2 * m1;
|
||||
|
||||
b3Mat44 m1 = g_camera.BuildViewMatrix();
|
||||
b3Mat44 m2 = g_camera.BuildProjectionMatrix();
|
||||
b3Mat44 m = m2 * m1;
|
||||
|
||||
glUniformMatrix4fv(m_projectionUniform, 1, GL_FALSE, &m.x.x);
|
||||
|
||||
glBindVertexArray(m_vaoId);
|
||||
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vboIds[0]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, m_count * sizeof(b3Vec3), m_vertices);
|
||||
|
||||
@ -321,13 +335,13 @@ struct DrawPoints
|
||||
b3Color m_colors[e_vertexCapacity];
|
||||
float32 m_sizes[e_vertexCapacity];
|
||||
u32 m_count;
|
||||
|
||||
|
||||
GLuint m_programId;
|
||||
GLuint m_projectionUniform;
|
||||
GLuint m_vertexAttribute;
|
||||
GLuint m_colorAttribute;
|
||||
GLuint m_sizeAttribute;
|
||||
|
||||
|
||||
GLuint m_vboIds[3];
|
||||
GLuint m_vaoId;
|
||||
};
|
||||
@ -361,8 +375,8 @@ struct DrawLines
|
||||
m_projectionUniform = glGetUniformLocation(m_programId, "projectionMatrix");
|
||||
m_vertexAttribute = 0;
|
||||
m_colorAttribute = 1;
|
||||
|
||||
glGenVertexArrays(1, &m_vaoId);
|
||||
|
||||
glGenVertexArrays(1, &m_vaoId);
|
||||
glGenBuffers(2, m_vboIds);
|
||||
|
||||
glBindVertexArray(m_vaoId);
|
||||
@ -376,7 +390,7 @@ struct DrawLines
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vboIds[1]);
|
||||
glVertexAttribPointer(m_colorAttribute, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
|
||||
glBufferData(GL_ARRAY_BUFFER, e_vertexCapacity * sizeof(b3Color), m_colors, GL_DYNAMIC_DRAW);
|
||||
|
||||
|
||||
AssertGL();
|
||||
|
||||
glBindVertexArray(0);
|
||||
@ -413,9 +427,9 @@ struct DrawLines
|
||||
|
||||
glUseProgram(m_programId);
|
||||
|
||||
Mat44 m1 = g_camera.BuildViewMatrix();
|
||||
Mat44 m2 = g_camera.BuildProjectionMatrix();
|
||||
Mat44 m = m2 * m1;
|
||||
b3Mat44 m1 = g_camera.BuildViewMatrix();
|
||||
b3Mat44 m2 = g_camera.BuildProjectionMatrix();
|
||||
b3Mat44 m = m2 * m1;
|
||||
glUniformMatrix4fv(m_projectionUniform, 1, GL_FALSE, &m.x.x);
|
||||
|
||||
glBindVertexArray(m_vaoId);
|
||||
@ -427,7 +441,7 @@ struct DrawLines
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, m_count * sizeof(b3Color), m_colors);
|
||||
|
||||
glDrawArrays(GL_LINES, 0, m_count);
|
||||
|
||||
|
||||
AssertGL();
|
||||
|
||||
glBindVertexArray(0);
|
||||
@ -450,7 +464,7 @@ struct DrawLines
|
||||
GLuint m_projectionUniform;
|
||||
GLuint m_vertexAttribute;
|
||||
GLuint m_colorAttribute;
|
||||
|
||||
|
||||
GLuint m_vboIds[2];
|
||||
GLuint m_vaoId;
|
||||
};
|
||||
@ -470,7 +484,7 @@ struct DrawTriangles
|
||||
"{\n"
|
||||
" vec3 La = vec3(0.5f, 0.5f, 0.5f);\n"
|
||||
" vec3 Ld = vec3(0.5f, 0.5f, 0.5f);\n"
|
||||
" vec3 L = vec3(0.0f, 0.0f, 1.0f);\n"
|
||||
" vec3 L = vec3(0.0f, 0.3f, 0.7f);\n"
|
||||
" vec3 Ma = v_color.xyz;\n"
|
||||
" vec3 Md = v_color.xyz;\n"
|
||||
" vec3 a = La * Ma;\n"
|
||||
@ -498,7 +512,7 @@ struct DrawTriangles
|
||||
glGenBuffers(3, m_vboIds);
|
||||
|
||||
glBindVertexArray(m_vaoId);
|
||||
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vboIds[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, e_vertexCapacity * sizeof(b3Vec3), m_vertices, GL_DYNAMIC_DRAW);
|
||||
glVertexAttribPointer(m_vertexAttribute, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
|
||||
@ -518,7 +532,7 @@ struct DrawTriangles
|
||||
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
|
||||
m_count = 0;
|
||||
}
|
||||
|
||||
@ -551,9 +565,9 @@ struct DrawTriangles
|
||||
|
||||
glUseProgram(m_programId);
|
||||
|
||||
Mat44 m1 = g_camera.BuildViewMatrix();
|
||||
Mat44 m2 = g_camera.BuildProjectionMatrix();
|
||||
Mat44 m = m2 * m1;
|
||||
b3Mat44 m1 = g_camera.BuildViewMatrix();
|
||||
b3Mat44 m2 = g_camera.BuildProjectionMatrix();
|
||||
b3Mat44 m = m2 * m1;
|
||||
|
||||
glUniformMatrix4fv(m_projectionUniform, 1, GL_FALSE, &m.x.x);
|
||||
|
||||
@ -567,7 +581,7 @@ struct DrawTriangles
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vboIds[2]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, m_count * sizeof(b3Vec3), m_normals);
|
||||
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, m_count);
|
||||
|
||||
AssertGL();
|
||||
@ -578,7 +592,7 @@ struct DrawTriangles
|
||||
|
||||
m_count = 0;
|
||||
}
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
e_vertexCapacity = 3 * 512
|
||||
@ -724,13 +738,13 @@ struct DrawWire
|
||||
{
|
||||
glUseProgram(m_programId);
|
||||
|
||||
Mat44 m1 = GetMat44(xf);
|
||||
b3Mat44 m1 = Convert44(xf);
|
||||
m1.x = radius * m1.x;
|
||||
m1.y = radius * m1.y;
|
||||
m1.z = radius * m1.z;
|
||||
Mat44 m2 = g_camera.BuildViewMatrix();
|
||||
Mat44 m3 = g_camera.BuildProjectionMatrix();
|
||||
Mat44 m = m3 * m2 * m1;
|
||||
b3Mat44 m2 = g_camera.BuildViewMatrix();
|
||||
b3Mat44 m3 = g_camera.BuildProjectionMatrix();
|
||||
b3Mat44 m = m3 * m2 * m1;
|
||||
|
||||
glUniformMatrix4fv(m_projectionUniform, 1, GL_FALSE, &m.x.x);
|
||||
|
||||
@ -759,8 +773,8 @@ struct DrawSolidSphere
|
||||
{
|
||||
enum
|
||||
{
|
||||
e_rings = 12,
|
||||
e_sectors = 12,
|
||||
e_rings = 18,
|
||||
e_sectors = 18,
|
||||
e_vertexCount = e_rings * e_sectors,
|
||||
e_indexCount = (e_rings - 1) * (e_sectors - 1) * 6,
|
||||
e_faceCount = e_indexCount / 3
|
||||
@ -773,18 +787,31 @@ struct DrawSolidSphere
|
||||
|
||||
b3Vec3 vs[e_vertexCount];
|
||||
b3Vec3 ns[e_vertexCount];
|
||||
|
||||
|
||||
u32 vc = 0;
|
||||
for (u32 r = 0; r < e_rings; r++)
|
||||
{
|
||||
for (u32 s = 0; s < e_sectors; s++)
|
||||
{
|
||||
float32 y = sin(-0.5f * B3_PI + B3_PI * r * R);
|
||||
float32 x = cos(2.0f * B3_PI * s * S) * sin(B3_PI * r * R);
|
||||
float32 z = sin(2.0f * B3_PI * s * S) * sin(B3_PI * r * R);
|
||||
float32 a1 = 2.0f * B3_PI * float32(s) * S;
|
||||
float32 c1 = cos(a1);
|
||||
float32 s1 = sin(a1);
|
||||
|
||||
vs[vc].Set(x, y, z);
|
||||
ns[vc].Set(x, y, z);
|
||||
float32 a2 = -0.5f * B3_PI + B3_PI * float32(r) * R;
|
||||
float32 s2 = sin(a2);
|
||||
|
||||
float32 a3 = B3_PI * float32(r) * R;
|
||||
float32 s3 = sin(a3);
|
||||
|
||||
float32 x = c1 * s3;
|
||||
float32 y = s2;
|
||||
float32 z = s1 * s3;
|
||||
|
||||
b3Vec3 v(x, y, z);
|
||||
v.Normalize();
|
||||
|
||||
vs[vc] = v;
|
||||
ns[vc] = v;
|
||||
++vc;
|
||||
}
|
||||
}
|
||||
@ -843,7 +870,7 @@ struct DrawSolidCylinder
|
||||
{
|
||||
enum
|
||||
{
|
||||
e_segments = 24,
|
||||
e_segments = 64,
|
||||
e_vertexCount = e_segments * 6,
|
||||
};
|
||||
|
||||
@ -851,12 +878,12 @@ struct DrawSolidCylinder
|
||||
{
|
||||
b3Vec3 vs[e_vertexCount];
|
||||
b3Vec3 ns[e_vertexCount];
|
||||
|
||||
|
||||
u32 vc = 0;
|
||||
for (u32 i = 0; i < e_segments; ++i)
|
||||
{
|
||||
float32 t0 = 2.0f * B3_PI * (float32)i / (float32)e_segments;
|
||||
float32 t1 = 2.0f * B3_PI * (float32)(i + 1) / (float32)e_segments;
|
||||
float32 t0 = 2.0f * B3_PI * float32(i) / float32(e_segments);
|
||||
float32 t1 = 2.0f * B3_PI * float32(i + 1) / float32(e_segments);
|
||||
|
||||
float32 c0 = cos(t0);
|
||||
float32 s0 = sin(t0);
|
||||
@ -868,22 +895,22 @@ struct DrawSolidCylinder
|
||||
v1.x = s0;
|
||||
v1.y = -0.5f;
|
||||
v1.z = c0;
|
||||
|
||||
|
||||
b3Vec3 v2;
|
||||
v2.x = s1;
|
||||
v2.y = -0.5f;
|
||||
v2.z = c1;
|
||||
|
||||
|
||||
b3Vec3 v3;
|
||||
v3.x = s1;
|
||||
v3.y = 0.5f;
|
||||
v3.z = c1;
|
||||
|
||||
|
||||
b3Vec3 v4;
|
||||
v4.x = s0;
|
||||
v4.y = 0.5f;
|
||||
v4.z = c0;
|
||||
|
||||
|
||||
b3Vec3 n = b3Cross(v2 - v1, v3 - v1);
|
||||
n.Normalize();
|
||||
|
||||
@ -966,7 +993,7 @@ struct DrawSolid
|
||||
" gl_Position = projectionMatrix * vec4(v_position, 1.0f);\n"
|
||||
" vec3 La = vec3(0.5f, 0.5f, 0.5f);\n"
|
||||
" vec3 Ld = vec3(0.5f, 0.5f, 0.5f);\n"
|
||||
" vec3 L = vec3(0.0f, 0.0f, 1.0f);\n"
|
||||
" vec3 L = vec3(0.0f, 0.3f, 0.7f);\n"
|
||||
" vec3 Ma = color.xyz;\n"
|
||||
" vec3 Md = color.xyz;\n"
|
||||
" vec3 a = La * Ma;\n"
|
||||
@ -999,14 +1026,14 @@ struct DrawSolid
|
||||
{
|
||||
glUseProgram(m_programId);
|
||||
|
||||
Mat44 m1 = GetMat44(xf);
|
||||
b3Mat44 m1 = Convert44(xf);
|
||||
m1.x = radius * m1.x;
|
||||
m1.y = height * m1.y;
|
||||
m1.z = radius * m1.z;
|
||||
|
||||
Mat44 m2 = g_camera.BuildViewMatrix();
|
||||
Mat44 m3 = g_camera.BuildProjectionMatrix();
|
||||
Mat44 m = m3 * m2 * m1;
|
||||
b3Mat44 m2 = g_camera.BuildViewMatrix();
|
||||
b3Mat44 m3 = g_camera.BuildProjectionMatrix();
|
||||
b3Mat44 m = m3 * m2 * m1;
|
||||
|
||||
glUniform4fv(m_colorUniform, 1, &c.r);
|
||||
glUniformMatrix4fv(m_modelUniform, 1, GL_FALSE, &m1.x.x);
|
||||
@ -1033,14 +1060,14 @@ struct DrawSolid
|
||||
{
|
||||
glUseProgram(m_programId);
|
||||
|
||||
Mat44 m1 = GetMat44(xf);
|
||||
b3Mat44 m1 = Convert44(xf);
|
||||
m1.x = radius * m1.x;
|
||||
m1.y = radius * m1.y;
|
||||
m1.z = radius * m1.z;
|
||||
|
||||
Mat44 m2 = g_camera.BuildViewMatrix();
|
||||
Mat44 m3 = g_camera.BuildProjectionMatrix();
|
||||
Mat44 m = m3 * m2 * m1;
|
||||
b3Mat44 m2 = g_camera.BuildViewMatrix();
|
||||
b3Mat44 m3 = g_camera.BuildProjectionMatrix();
|
||||
b3Mat44 m = m3 * m2 * m1;
|
||||
|
||||
glUniform4fv(m_colorUniform, 1, &c.r);
|
||||
glUniformMatrix4fv(m_modelUniform, 1, GL_FALSE, &m1.x.x);
|
||||
@ -1071,7 +1098,7 @@ struct DrawSolid
|
||||
GLuint m_normalAttribute;
|
||||
|
||||
DrawSolidSphere m_sphere;
|
||||
DrawSolidCylinder m_cylinder;
|
||||
DrawSolidCylinder m_cylinder;
|
||||
};
|
||||
|
||||
DebugDraw::DebugDraw()
|
||||
@ -1115,7 +1142,7 @@ void DebugDraw::DrawSolidTriangle(const b3Vec3& normal, const b3Vec3& p1, const
|
||||
m_triangles->Vertex(p1, color, normal);
|
||||
m_triangles->Vertex(p2, color, normal);
|
||||
m_triangles->Vertex(p3, color, normal);
|
||||
|
||||
|
||||
b3Color edgeColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
DrawTriangle(p2, p3, p3, edgeColor);
|
||||
}
|
||||
@ -1126,7 +1153,7 @@ void DebugDraw::DrawPolygon(const b3Vec3* vertices, u32 count, const b3Color& co
|
||||
for (u32 i = 0; i < count; ++i)
|
||||
{
|
||||
b3Vec3 p2 = vertices[i];
|
||||
|
||||
|
||||
m_lines->Vertex(p1, color);
|
||||
m_lines->Vertex(p2, color);
|
||||
|
||||
@ -1143,7 +1170,7 @@ void DebugDraw::DrawSolidPolygon(const b3Vec3& normal, const b3Vec3* vertices, u
|
||||
{
|
||||
b3Vec3 p2 = vertices[i];
|
||||
b3Vec3 p3 = vertices[i + 1];
|
||||
|
||||
|
||||
m_triangles->Vertex(p1, fillColor, normal);
|
||||
m_triangles->Vertex(p2, fillColor, normal);
|
||||
m_triangles->Vertex(p3, fillColor, normal);
|
||||
@ -1171,7 +1198,7 @@ void DebugDraw::DrawCircle(const b3Vec3& normal, const b3Vec3& center, float32 r
|
||||
}
|
||||
|
||||
n1.Normalize();
|
||||
|
||||
|
||||
// Build a quaternion to rotate the tangent about the normal.
|
||||
u32 kEdgeCount = 20;
|
||||
float32 kAngleInc = 2.0f * B3_PI / float32(kEdgeCount);
|
||||
@ -1185,7 +1212,7 @@ void DebugDraw::DrawCircle(const b3Vec3& normal, const b3Vec3& center, float32 r
|
||||
|
||||
m_lines->Vertex(p1, color);
|
||||
m_lines->Vertex(p2, color);
|
||||
|
||||
|
||||
n1 = n2;
|
||||
p1 = p2;
|
||||
}
|
||||
@ -1195,7 +1222,7 @@ void DebugDraw::DrawSolidCircle(const b3Vec3& normal, const b3Vec3& center, floa
|
||||
{
|
||||
b3Color fillColor(color.r, color.g, color.b, color.a);
|
||||
b3Color frameColor(0.5f * color.r, 0.5f * color.g, 0.5f * color.b, 1.0f);
|
||||
|
||||
|
||||
// Build a tangent vector to normal.
|
||||
b3Vec3 u = b3Cross(normal, b3Vec3(1.0f, 0.0f, 0.0f));
|
||||
b3Vec3 v = b3Cross(normal, b3Vec3(0.0f, 1.0f, 0.0f));
|
||||
@ -1223,7 +1250,7 @@ void DebugDraw::DrawSolidCircle(const b3Vec3& normal, const b3Vec3& center, floa
|
||||
{
|
||||
b3Vec3 n2 = b3Mul(q, n1);
|
||||
b3Vec3 p2 = center + radius * n2;
|
||||
|
||||
|
||||
m_triangles->Vertex(center, fillColor, normal);
|
||||
m_triangles->Vertex(p1, fillColor, normal);
|
||||
m_triangles->Vertex(p2, fillColor, normal);
|
||||
@ -1281,35 +1308,29 @@ void DebugDraw::DrawAABB(const b3AABB3& aabb, const b3Color& color)
|
||||
|
||||
b3Vec3 vs[8];
|
||||
|
||||
// Face 1
|
||||
vs[0] = lower;
|
||||
vs[1] = b3Vec3(lower.x, upper.y, lower.z);
|
||||
vs[2] = b3Vec3(upper.x, upper.y, lower.z);
|
||||
vs[3] = b3Vec3(upper.x, lower.y, lower.z);
|
||||
|
||||
// Face 2
|
||||
vs[4] = upper;
|
||||
vs[5] = b3Vec3(upper.x, lower.y, upper.z);
|
||||
vs[6] = b3Vec3(lower.x, lower.y, upper.z);
|
||||
vs[7] = b3Vec3(lower.x, upper.y, upper.z);
|
||||
|
||||
// Face 1 edges
|
||||
DrawSegment(vs[0], vs[1], color);
|
||||
DrawSegment(vs[1], vs[2], color);
|
||||
DrawSegment(vs[2], vs[3], color);
|
||||
DrawSegment(vs[3], vs[0], color);
|
||||
|
||||
// Face 2 edges
|
||||
DrawSegment(vs[4], vs[5], color);
|
||||
DrawSegment(vs[5], vs[6], color);
|
||||
DrawSegment(vs[6], vs[7], color);
|
||||
DrawSegment(vs[7], vs[4], color);
|
||||
|
||||
// Face 3 edges
|
||||
DrawSegment(vs[2], vs[4], color);
|
||||
DrawSegment(vs[5], vs[3], color);
|
||||
|
||||
// Face 4 edges
|
||||
DrawSegment(vs[6], vs[0], color);
|
||||
DrawSegment(vs[1], vs[7], color);
|
||||
}
|
||||
@ -1349,9 +1370,15 @@ void DebugDraw::DrawCapsule(const b3CapsuleShape* s, const b3Color& c, const b3T
|
||||
if (height > 0.0f)
|
||||
{
|
||||
{
|
||||
b3Mat33 R;
|
||||
R.y = (1.0f / height) * (c1 - c2);
|
||||
R.z = b3Perp(R.y);
|
||||
R.x = b3Cross(R.y, R.z);
|
||||
|
||||
b3Transform xfc;
|
||||
xfc.rotation = xf.rotation;
|
||||
xfc.position = xf * ( 0.5f * (c1 + c2) );
|
||||
xfc.position = xf * (0.5f * (c1 + c2));
|
||||
xfc.rotation = xf.rotation * R;
|
||||
|
||||
m_solid->DrawCylinder(radius, height, c, xfc);
|
||||
}
|
||||
|
||||
@ -1409,13 +1436,13 @@ void DebugDraw::DrawMesh(const b3MeshShape* s, const b3Color& c, const b3Transfo
|
||||
|
||||
b3Vec3 n1 = b3Cross(p2 - p1, p3 - p1);
|
||||
n1.Normalize();
|
||||
|
||||
|
||||
m_triangles->Vertex(p1, c, n1);
|
||||
m_triangles->Vertex(p2, c, n1);
|
||||
m_triangles->Vertex(p3, c, n1);
|
||||
|
||||
b3Vec3 n2 = -n1;
|
||||
|
||||
|
||||
m_triangles->Vertex(p1, c, n2);
|
||||
m_triangles->Vertex(p3, c, n2);
|
||||
m_triangles->Vertex(p2, c, n2);
|
||||
@ -1481,7 +1508,7 @@ void DebugDraw::Draw(const b3World& world)
|
||||
DrawShape(s, c, xf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
g_debugDraw->Submit();
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,6 @@
|
||||
#define DEBUG_DRAW_H
|
||||
|
||||
#include <bounce/bounce.h>
|
||||
#include "mat44.h"
|
||||
|
||||
struct DrawPoints;
|
||||
struct DrawLines;
|
||||
@ -28,6 +27,23 @@ struct DrawTriangles;
|
||||
struct DrawWire;
|
||||
struct DrawSolid;
|
||||
|
||||
struct Ray3
|
||||
{
|
||||
b3Vec3 A() const
|
||||
{
|
||||
return origin;
|
||||
}
|
||||
|
||||
b3Vec3 B() const
|
||||
{
|
||||
return origin + fraction * direction;
|
||||
}
|
||||
|
||||
b3Vec3 direction;
|
||||
b3Vec3 origin;
|
||||
float32 fraction;
|
||||
};
|
||||
|
||||
class Camera
|
||||
{
|
||||
public:
|
||||
@ -38,15 +54,15 @@ public:
|
||||
m_width = 1024.0f;
|
||||
m_height = 768.0f;
|
||||
m_zNear = 1.0f;
|
||||
m_zFar = 500.0f;
|
||||
m_zFar = 1000.0f;
|
||||
m_fovy = 0.25f * B3_PI;
|
||||
m_zoom = 10.0f;
|
||||
}
|
||||
|
||||
Mat44 BuildProjectionMatrix() const;
|
||||
Mat44 BuildViewMatrix() const;
|
||||
b3Mat44 BuildProjectionMatrix() const;
|
||||
b3Mat44 BuildViewMatrix() const;
|
||||
b3Transform BuildViewTransform() const;
|
||||
Mat44 BuildWorldMatrix() const;
|
||||
b3Mat44 BuildWorldMatrix() const;
|
||||
b3Transform BuildWorldTransform() const;
|
||||
|
||||
b3Vec2 ConvertWorldToScreen(const b3Vec3& pw) const;
|
||||
|
@ -16,13 +16,18 @@
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#if defined(__APPLE_CC__)
|
||||
#include <OpenGL/gl3.h>
|
||||
#else
|
||||
#include <glad/glad.h>
|
||||
#include <glfw/glfw3.h>
|
||||
#endif
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/imgui_impl_glfw_gl3.h>
|
||||
|
||||
#include <testbed/tests/test.h>
|
||||
|
||||
#include <glfw/glfw3.h>
|
||||
|
||||
GLFWwindow* g_window;
|
||||
Settings g_settings;
|
||||
Test* g_test;
|
||||
@ -35,13 +40,13 @@ bool g_rightDown;
|
||||
bool g_shiftDown;
|
||||
b3Vec2 g_ps0;
|
||||
|
||||
void WindowSize(int w, int h)
|
||||
static void WindowSize(int w, int h)
|
||||
{
|
||||
g_camera.m_width = float32(w);
|
||||
g_camera.m_height = float32(h);
|
||||
}
|
||||
|
||||
void MouseMove(GLFWwindow* w, double x, double y)
|
||||
static void MouseMove(GLFWwindow* w, double x, double y)
|
||||
{
|
||||
b3Vec2 ps;
|
||||
ps.Set(float32(x), float32(y));
|
||||
@ -83,7 +88,7 @@ void MouseMove(GLFWwindow* w, double x, double y)
|
||||
}
|
||||
}
|
||||
|
||||
void MouseWheel(GLFWwindow* w, double dx, double dy)
|
||||
static void MouseWheel(GLFWwindow* w, double dx, double dy)
|
||||
{
|
||||
float32 n = b3Clamp(float32(dy), -1.0f, 1.0f);
|
||||
if (g_shiftDown)
|
||||
@ -92,7 +97,7 @@ void MouseWheel(GLFWwindow* w, double dx, double dy)
|
||||
}
|
||||
}
|
||||
|
||||
void MouseButton(GLFWwindow* w, int button, int action, int mods)
|
||||
static void MouseButton(GLFWwindow* w, int button, int action, int mods)
|
||||
{
|
||||
double x, y;
|
||||
glfwGetCursorPos(w, &x, &y);
|
||||
@ -147,7 +152,7 @@ void MouseButton(GLFWwindow* w, int button, int action, int mods)
|
||||
}
|
||||
}
|
||||
|
||||
void KeyButton(GLFWwindow* w, int button, int scancode, int action, int mods)
|
||||
static void KeyButton(GLFWwindow* w, int button, int scancode, int action, int mods)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
@ -163,12 +168,12 @@ void KeyButton(GLFWwindow* w, int button, int scancode, int action, int mods)
|
||||
{
|
||||
if (button == GLFW_KEY_DOWN)
|
||||
{
|
||||
g_camera.m_zoom += 0.05f;
|
||||
g_camera.m_zoom += 0.2f;
|
||||
}
|
||||
|
||||
if (button == GLFW_KEY_UP)
|
||||
{
|
||||
g_camera.m_zoom -= 0.05f;
|
||||
g_camera.m_zoom -= 0.2f;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -199,30 +204,30 @@ void KeyButton(GLFWwindow* w, int button, int scancode, int action, int mods)
|
||||
}
|
||||
}
|
||||
|
||||
void Char(GLFWwindow* w, unsigned int codepoint)
|
||||
static void Char(GLFWwindow* w, unsigned int codepoint)
|
||||
{
|
||||
ImGui_ImplGlfwGL3_CharCallback(w, codepoint);
|
||||
}
|
||||
|
||||
void CreateInterface()
|
||||
static void CreateInterface()
|
||||
{
|
||||
ImGui_ImplGlfwGL3_Init(g_window, false);
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.Fonts[0].AddFontDefault();
|
||||
}
|
||||
|
||||
void DestroyInterface()
|
||||
static void DestroyInterface()
|
||||
{
|
||||
ImGui_ImplGlfwGL3_Shutdown();
|
||||
}
|
||||
|
||||
bool GetTestName(void*, int idx, const char** name)
|
||||
static bool GetTestName(void*, int idx, const char** name)
|
||||
{
|
||||
*name = g_tests[idx].name;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Interface()
|
||||
static void Interface()
|
||||
{
|
||||
ImGui::SetNextWindowPos(ImVec2(g_camera.m_width, 0.0f));
|
||||
ImGui::SetNextWindowSize(ImVec2(250.0f, g_camera.m_height));
|
||||
@ -255,11 +260,18 @@ void Interface()
|
||||
g_settings.testID = b3Clamp(g_settings.testID + 1, 0, int(g_testCount) - 1);
|
||||
g_settings.lastTestID = -1;
|
||||
}
|
||||
if (ImGui::Button("Dump", buttonSize))
|
||||
{
|
||||
if (g_test)
|
||||
{
|
||||
g_test->Dump();
|
||||
}
|
||||
}
|
||||
if (ImGui::Button("Exit", buttonSize))
|
||||
{
|
||||
glfwSetWindowShouldClose(g_window, true);
|
||||
}
|
||||
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::Text("Step");
|
||||
@ -271,8 +283,8 @@ void Interface()
|
||||
ImGui::Text("Position Iterations");
|
||||
ImGui::SliderInt("#Position Iterations", &g_settings.positionIterations, 0, 50);
|
||||
ImGui::Checkbox("Sleep", &g_settings.sleep);
|
||||
ImGui::Checkbox("Convex Cache", &g_settings.convexCache);
|
||||
ImGui::Checkbox("Warm Start", &g_settings.warmStart);
|
||||
//ImGui::Checkbox("Convex Cache", &g_settings.convexCache);
|
||||
|
||||
if (ImGui::Button("Play/Pause", buttonSize))
|
||||
{
|
||||
@ -283,7 +295,7 @@ void Interface()
|
||||
g_settings.pause = true;
|
||||
g_settings.singleStep = true;
|
||||
}
|
||||
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::Text("View");
|
||||
@ -296,6 +308,7 @@ void Interface()
|
||||
ImGui::Checkbox("Contact Points", &g_settings.drawContactPoints);
|
||||
ImGui::Checkbox("Contact Normals", &g_settings.drawContactNormals);
|
||||
ImGui::Checkbox("Contact Tangents", &g_settings.drawContactTangents);
|
||||
ImGui::Checkbox("Contact Areas", &g_settings.drawContactAreas);
|
||||
ImGui::Checkbox("Statistics", &g_settings.drawStats);
|
||||
ImGui::Checkbox("Profile", &g_settings.drawProfile);
|
||||
|
||||
@ -303,10 +316,16 @@ void Interface()
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
void Step()
|
||||
static void Step()
|
||||
{
|
||||
if (g_settings.drawGrid)
|
||||
{
|
||||
b3Color color(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
|
||||
b3Vec3 pn(0.0f, 1.0f, 0.0f);
|
||||
b3Vec3 p(0.0f, 0.0f, 0.0f);
|
||||
g_debugDraw->DrawCircle(pn, p, 1.0f, color);
|
||||
|
||||
int n = 20;
|
||||
|
||||
b3Vec3 t;
|
||||
@ -314,7 +333,6 @@ void Step()
|
||||
t.y = 0.0f;
|
||||
t.z = -0.5f * float32(n);
|
||||
|
||||
b3Color color(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
for (int i = 0; i < n; i += 1)
|
||||
{
|
||||
for (int j = 0; j < n; j += 1)
|
||||
@ -347,16 +365,16 @@ void Step()
|
||||
g_debugDraw->Submit();
|
||||
}
|
||||
|
||||
void Run()
|
||||
static void Run()
|
||||
{
|
||||
glFrontFace(GL_CCW);
|
||||
glCullFace(GL_BACK);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
|
||||
glClearDepth(1.0f);
|
||||
|
||||
double t1 = glfwGetTime();
|
||||
@ -489,5 +507,6 @@ int main(int argc, char** args)
|
||||
|
||||
// Destroy g_window
|
||||
glfwTerminate();
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2016 Irlan Robson http://www.irlan.net
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef MAT44_H
|
||||
#define MAT44_H
|
||||
|
||||
#include <bounce/bounce.h>
|
||||
|
||||
struct Vec4
|
||||
{
|
||||
Vec4() { }
|
||||
Vec4(float32 _x, float32 _y, float32 _z, float32 _w) : x(_x), y(_y), z(_z), w(_w) { }
|
||||
|
||||
void SetZero()
|
||||
{
|
||||
x = y = z = w = 0.0f;
|
||||
}
|
||||
|
||||
void Set(float32 _x, float32 _y, float32 _z, float32 _w)
|
||||
{
|
||||
x = _x;
|
||||
y = _y;
|
||||
z = _z;
|
||||
w = _w;
|
||||
}
|
||||
|
||||
float32 x, y, z, w;
|
||||
};
|
||||
|
||||
inline Vec4 operator+(const Vec4& a, const Vec4& b)
|
||||
{
|
||||
return Vec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
|
||||
}
|
||||
|
||||
inline Vec4 operator*(float32 s, const Vec4& v)
|
||||
{
|
||||
return Vec4(s * v.x, s * v.y, s * v.z, s * v.w);
|
||||
}
|
||||
|
||||
struct Mat44
|
||||
{
|
||||
Mat44() { }
|
||||
Mat44(const Vec4& _x, const Vec4& _y, const Vec4& _z, const Vec4& _w) : x(_x), y(_y), z(_z), w(_w) { }
|
||||
|
||||
void SetIdentity()
|
||||
{
|
||||
x.Set(1.0f, 0.0f, 0.0f, 0.0f);
|
||||
y.Set(0.0f, 1.0f, 0.0f, 0.0f);
|
||||
z.Set(0.0f, 0.0f, 1.0f, 0.0f);
|
||||
w.Set(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
Vec4 x, y, z, w;
|
||||
};
|
||||
|
||||
inline Vec4 operator*(const Mat44& A, const Vec4& v)
|
||||
{
|
||||
return v.x * A.x + v.y * A.y + v.z * A.z + v.w * A.w;
|
||||
}
|
||||
|
||||
inline b3Vec3 operator*(const Mat44& A, const b3Vec3& v)
|
||||
{
|
||||
Vec4 q = v.x * A.x + v.y * A.y + v.z * A.z + A.w;
|
||||
return b3Vec3(q.x, q.y, q.z);
|
||||
}
|
||||
|
||||
inline Mat44 operator*(const Mat44& A, const Mat44& B)
|
||||
{
|
||||
return Mat44(A * B.x, A * B.y, A * B.z, A * B.w);
|
||||
}
|
||||
|
||||
inline Mat44 GetMat44(const b3Transform& T)
|
||||
{
|
||||
return Mat44(
|
||||
Vec4(T.rotation.x.x, T.rotation.x.y, T.rotation.x.z, 0.0f),
|
||||
Vec4(T.rotation.y.x, T.rotation.y.y, T.rotation.y.z, 0.0f),
|
||||
Vec4(T.rotation.z.x, T.rotation.z.y, T.rotation.z.z, 0.0f),
|
||||
Vec4(T.position.x, T.position.y, T.position.z, 1.0f));
|
||||
}
|
||||
|
||||
inline b3Transform GetTransform(const Mat44& T)
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.rotation.x.Set(T.x.x, T.x.y, T.x.z);
|
||||
xf.rotation.y.Set(T.y.x, T.y.y, T.y.z);
|
||||
xf.rotation.z.Set(T.z.x, T.z.y, T.z.z);
|
||||
xf.position.Set(T.w.x, T.w.y, T.w.z);
|
||||
return xf;
|
||||
}
|
||||
|
||||
inline float32 RandomFloat(float32 a, float32 b)
|
||||
{
|
||||
float32 x = float32(rand()) / float32(RAND_MAX);
|
||||
float32 diff = b - a;
|
||||
float32 r = x * diff;
|
||||
return a + r;
|
||||
}
|
||||
|
||||
struct Ray3
|
||||
{
|
||||
b3Vec3 Start() const
|
||||
{
|
||||
return origin;
|
||||
}
|
||||
|
||||
b3Vec3 End() const
|
||||
{
|
||||
return origin + fraction * direction;
|
||||
}
|
||||
|
||||
b3Vec3 direction;
|
||||
b3Vec3 origin;
|
||||
float32 fraction;
|
||||
};
|
||||
|
||||
#endif
|
@ -20,8 +20,8 @@
|
||||
|
||||
extern u32 b3_allocCalls, b3_maxAllocCalls;
|
||||
extern u32 b3_gjkCalls, b3_gjkIters, b3_gjkMaxIters;
|
||||
extern bool b3_convexCache;
|
||||
extern u32 b3_convexCalls, b3_convexCacheHits;
|
||||
extern bool b3_enableConvexCache;
|
||||
extern b3Draw* b3_debugDraw;
|
||||
|
||||
extern Settings g_settings;
|
||||
@ -29,21 +29,86 @@ extern DebugDraw* g_debugDraw;
|
||||
extern Camera g_camera;
|
||||
extern Profiler* g_profiler;
|
||||
|
||||
static void BuildGrid(b3Mesh* mesh, u32 w, u32 h, bool randomY = false)
|
||||
{
|
||||
b3Vec3 t;
|
||||
t.x = -0.5f * float32(w);
|
||||
t.y = 0.0f;
|
||||
t.z = -0.5f * float32(h);
|
||||
|
||||
mesh->vertexCount = w * h;
|
||||
mesh->vertices = (b3Vec3*)b3Alloc(mesh->vertexCount * sizeof(b3Vec3));
|
||||
|
||||
for (u32 i = 0; i < w; ++i)
|
||||
{
|
||||
for (u32 j = 0; j < h; ++j)
|
||||
{
|
||||
u32 v1 = i * w + j;
|
||||
|
||||
b3Vec3 v;
|
||||
v.x = float32(i);
|
||||
v.y = randomY ? RandomFloat(0.0f, 1.0f) : 0.0f;
|
||||
v.z = float32(j);
|
||||
|
||||
v += t;
|
||||
|
||||
mesh->vertices[v1] = v;
|
||||
}
|
||||
}
|
||||
|
||||
mesh->triangleCount = 2 * (w - 1) * (h - 1);
|
||||
mesh->triangles = (b3Triangle*)b3Alloc(mesh->triangleCount * sizeof(b3Triangle));
|
||||
|
||||
u32 triangleCount = 0;
|
||||
for (u32 i = 0; i < w - 1; ++i)
|
||||
{
|
||||
for (u32 j = 0; j < h - 1; ++j)
|
||||
{
|
||||
u32 v1 = i * w + j;
|
||||
u32 v2 = (i + 1) * w + j;
|
||||
u32 v3 = (i + 1) * w + (j + 1);
|
||||
u32 v4 = i * w + (j + 1);
|
||||
|
||||
B3_ASSERT(triangleCount < mesh->triangleCount);
|
||||
b3Triangle* t1 = mesh->triangles + triangleCount;
|
||||
++triangleCount;
|
||||
|
||||
t1->v1 = v3;
|
||||
t1->v2 = v2;
|
||||
t1->v3 = v1;
|
||||
|
||||
B3_ASSERT(triangleCount < mesh->triangleCount);
|
||||
b3Triangle* t2 = mesh->triangles + triangleCount;
|
||||
++triangleCount;
|
||||
|
||||
t2->v1 = v1;
|
||||
t2->v2 = v4;
|
||||
t2->v3 = v3;
|
||||
}
|
||||
}
|
||||
|
||||
B3_ASSERT(triangleCount == mesh->triangleCount);
|
||||
|
||||
mesh->BuildTree();
|
||||
}
|
||||
|
||||
Test::Test()
|
||||
{
|
||||
b3_allocCalls = 0;
|
||||
b3_gjkCalls = 0;
|
||||
b3_gjkIters = 0;
|
||||
b3_gjkMaxIters = 0;
|
||||
b3_convexCache = g_settings.convexCache;
|
||||
b3_convexCalls = 0;
|
||||
b3_convexCacheHits = 0;
|
||||
b3_enableConvexCache = g_settings.convexCache;
|
||||
b3_debugDraw = g_debugDraw;
|
||||
|
||||
m_world.SetContactListener(this);
|
||||
|
||||
g_camera.m_q = b3Quat(b3Vec3(0.0f, 1.0f, 0.0f), 0.15f * B3_PI);
|
||||
g_camera.m_q = g_camera.m_q * b3Quat(b3Vec3(1.0f, 0.0f, 0.0f), -0.15f * B3_PI);
|
||||
b3Quat q_y(b3Vec3(0.0f, 1.0f, 0.0f), 0.15f * B3_PI);
|
||||
b3Quat q_x(b3Quat(b3Vec3(1.0f, 0.0f, 0.0f), -0.15f * B3_PI));
|
||||
|
||||
g_camera.m_q = q_y * q_x;
|
||||
g_camera.m_zoom = 50.0f;
|
||||
g_camera.m_center.SetZero();
|
||||
|
||||
@ -51,255 +116,17 @@ Test::Test()
|
||||
m_mouseJoint = NULL;
|
||||
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.position.SetZero();
|
||||
xf.rotation = b3Diagonal(50.0f, 1.0f, 50.0f);
|
||||
m_groundHull.SetTransform(xf);
|
||||
b3Transform m;
|
||||
m.position.SetZero();
|
||||
m.rotation = b3Diagonal(50.0f, 1.0f, 50.0f);
|
||||
m_groundHull.SetTransform(m);
|
||||
}
|
||||
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.position.SetZero();
|
||||
xf.rotation = b3Diagonal(1.0f, 1.0f, 1.0f);
|
||||
m_boxHull.SetTransform(xf);
|
||||
}
|
||||
m_boxHull.SetIdentity();
|
||||
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.position.SetZero();
|
||||
xf.rotation = b3Diagonal(1.0f, 5.0f, 1.0f);
|
||||
m_tallHull.SetTransform(xf);
|
||||
}
|
||||
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.position.SetZero();
|
||||
xf.rotation = b3Diagonal(2.0f, 4.0f, 0.5f);
|
||||
m_doorHull.SetTransform(xf);
|
||||
}
|
||||
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.position.SetZero();
|
||||
xf.rotation = b3Diagonal(25.0f, 0.5f, 25.0f);
|
||||
m_rampHull.SetTransform(xf);
|
||||
}
|
||||
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.position.SetZero();
|
||||
xf.rotation = b3Diagonal(1.0f, 0.5f, 3.0f);
|
||||
m_plankHull.SetTransform(xf);
|
||||
}
|
||||
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.position.SetZero();
|
||||
xf.rotation = b3Diagonal(4.05f, 2.0f * B3_LINEAR_SLOP, 4.05f);
|
||||
m_thinHull.SetTransform(xf);
|
||||
}
|
||||
|
||||
{
|
||||
const u32 w = 5;
|
||||
const u32 h = 5;
|
||||
|
||||
b3Vec3 t;
|
||||
t.x = -0.5f * float32(w);
|
||||
t.y = 0.0f;
|
||||
t.z = -0.5f * float32(h);
|
||||
|
||||
b3Mesh* mesh = m_meshes + e_clothMesh;
|
||||
|
||||
mesh->vertexCount = w * h;
|
||||
mesh->vertices = (b3Vec3*)b3Alloc(mesh->vertexCount * sizeof(b3Vec3));
|
||||
|
||||
for (u32 i = 0; i < w; ++i)
|
||||
{
|
||||
for (u32 j = 0; j < h; ++j)
|
||||
{
|
||||
u32 v1 = i * w + j;
|
||||
|
||||
b3Vec3 v;
|
||||
v.x = float32(i);
|
||||
v.y = RandomFloat(0.0f, 0.5f);
|
||||
v.z = float32(j);
|
||||
|
||||
v += t;
|
||||
|
||||
mesh->vertices[v1] = v;
|
||||
}
|
||||
}
|
||||
|
||||
mesh->triangleCount = 2 * (w - 1) * (h - 1);
|
||||
mesh->triangles = (b3Triangle*)b3Alloc(mesh->triangleCount * sizeof(b3Triangle));
|
||||
|
||||
u32 triangleCount = 0;
|
||||
for (u32 i = 0; i < w - 1; ++i)
|
||||
{
|
||||
for (u32 j = 0; j < h - 1; ++j)
|
||||
{
|
||||
u32 v1 = i * w + j;
|
||||
u32 v2 = (i + 1) * w + j;
|
||||
u32 v3 = (i + 1) * w + (j + 1);
|
||||
u32 v4 = i * w + (j + 1);
|
||||
|
||||
B3_ASSERT(triangleCount < mesh->triangleCount);
|
||||
b3Triangle* t1 = mesh->triangles + triangleCount;
|
||||
++triangleCount;
|
||||
|
||||
t1->v1 = v3;
|
||||
t1->v2 = v2;
|
||||
t1->v3 = v1;
|
||||
|
||||
B3_ASSERT(triangleCount < mesh->triangleCount);
|
||||
b3Triangle* t2 = mesh->triangles + triangleCount;
|
||||
++triangleCount;
|
||||
|
||||
t2->v1 = v1;
|
||||
t2->v2 = v4;
|
||||
t2->v3 = v3;
|
||||
}
|
||||
}
|
||||
|
||||
B3_ASSERT(triangleCount == mesh->triangleCount);
|
||||
|
||||
mesh->BuildTree();
|
||||
}
|
||||
|
||||
{
|
||||
const u32 w = 50;
|
||||
const u32 h = 50;
|
||||
|
||||
b3Vec3 t;
|
||||
t.x = -0.5f * float32(w);
|
||||
t.y = 0.0f;
|
||||
t.z = -0.5f * float32(h);
|
||||
|
||||
b3Mesh* mesh = m_meshes + e_gridMesh;
|
||||
|
||||
mesh->vertexCount = w * h;
|
||||
mesh->vertices = (b3Vec3*)b3Alloc(mesh->vertexCount * sizeof(b3Vec3));
|
||||
|
||||
for (u32 i = 0; i < w; ++i)
|
||||
{
|
||||
for (u32 j = 0; j < h; ++j)
|
||||
{
|
||||
u32 v1 = i * w + j;
|
||||
|
||||
b3Vec3 v;
|
||||
v.x = float32(i);
|
||||
v.y = 0.0f;
|
||||
v.z = float32(j);
|
||||
|
||||
v += t;
|
||||
|
||||
mesh->vertices[v1] = v;
|
||||
}
|
||||
}
|
||||
|
||||
// 2 triangles per quad
|
||||
mesh->triangleCount = 2 * (w - 1) * (h - 1);
|
||||
mesh->triangles = (b3Triangle*)b3Alloc(mesh->triangleCount * sizeof(b3Triangle));
|
||||
|
||||
u32 triangleCount = 0;
|
||||
for (u32 i = 0; i < w - 1; ++i)
|
||||
{
|
||||
for (u32 j = 0; j < h - 1; ++j)
|
||||
{
|
||||
u32 v1 = i * w + j;
|
||||
u32 v2 = (i + 1) * w + j;
|
||||
u32 v3 = (i + 1) * w + (j + 1);
|
||||
u32 v4 = i * w + (j + 1);
|
||||
|
||||
B3_ASSERT(triangleCount < mesh->triangleCount);
|
||||
b3Triangle* t1 = mesh->triangles + triangleCount;
|
||||
++triangleCount;
|
||||
|
||||
t1->v1 = v3;
|
||||
t1->v2 = v2;
|
||||
t1->v3 = v1;
|
||||
|
||||
B3_ASSERT(triangleCount < mesh->triangleCount);
|
||||
b3Triangle* t2 = mesh->triangles + triangleCount;
|
||||
++triangleCount;
|
||||
|
||||
t2->v1 = v1;
|
||||
t2->v2 = v4;
|
||||
t2->v3 = v3;
|
||||
}
|
||||
}
|
||||
|
||||
B3_ASSERT(triangleCount == mesh->triangleCount);
|
||||
|
||||
mesh->BuildTree();
|
||||
}
|
||||
|
||||
{
|
||||
const u32 w = 50;
|
||||
const u32 h = 50;
|
||||
|
||||
b3Vec3 t;
|
||||
t.x = -0.5f * float32(w);
|
||||
t.y = 0.0f;
|
||||
t.z = -0.5f * float32(h);
|
||||
|
||||
b3Mesh* mesh = m_meshes + e_terrainMesh;
|
||||
|
||||
mesh->vertexCount = w * h;
|
||||
mesh->vertices = (b3Vec3*)b3Alloc(mesh->vertexCount * sizeof(b3Vec3));
|
||||
|
||||
for (u32 i = 0; i < w; ++i)
|
||||
{
|
||||
for (u32 j = 0; j < h; ++j)
|
||||
{
|
||||
u32 v1 = i * w + j;
|
||||
|
||||
b3Vec3 v;
|
||||
v.x = 2.0f * float32(i);
|
||||
v.y = RandomFloat(0.0f, 0.5f);
|
||||
v.z = 2.0f *float32(j);
|
||||
|
||||
v += t;
|
||||
|
||||
mesh->vertices[v1] = v;
|
||||
}
|
||||
}
|
||||
|
||||
mesh->triangleCount = 2 * (w - 1) * (h - 1);
|
||||
mesh->triangles = (b3Triangle*)b3Alloc(mesh->triangleCount * sizeof(b3Triangle));
|
||||
|
||||
u32 triangleCount = 0;
|
||||
for (u32 i = 0; i < w - 1; ++i)
|
||||
{
|
||||
for (u32 j = 0; j < h - 1; ++j)
|
||||
{
|
||||
u32 v1 = i * w + j;
|
||||
u32 v2 = (i + 1) * w + j;
|
||||
u32 v3 = (i + 1) * w + (j + 1);
|
||||
u32 v4 = i * w + (j + 1);
|
||||
|
||||
B3_ASSERT(triangleCount < mesh->triangleCount);
|
||||
b3Triangle* t1 = mesh->triangles + triangleCount;
|
||||
++triangleCount;
|
||||
|
||||
t1->v1 = v3;
|
||||
t1->v2 = v2;
|
||||
t1->v3 = v1;
|
||||
|
||||
B3_ASSERT(triangleCount < mesh->triangleCount);
|
||||
b3Triangle* t2 = mesh->triangles + triangleCount;
|
||||
++triangleCount;
|
||||
|
||||
t2->v1 = v1;
|
||||
t2->v2 = v4;
|
||||
t2->v3 = v3;
|
||||
}
|
||||
}
|
||||
|
||||
B3_ASSERT(triangleCount == mesh->triangleCount);
|
||||
|
||||
mesh->BuildTree();
|
||||
}
|
||||
BuildGrid(m_meshes + e_gridMesh, 50, 50);
|
||||
BuildGrid(m_meshes + e_terrainMesh, 50, 50, true);
|
||||
BuildGrid(m_meshes + e_clothMesh, 10, 10);
|
||||
}
|
||||
|
||||
Test::~Test()
|
||||
@ -345,10 +172,10 @@ void Test::Step()
|
||||
b3_gjkCalls = 0;
|
||||
b3_gjkIters = 0;
|
||||
b3_gjkMaxIters = 0;
|
||||
b3_convexCache = g_settings.convexCache;
|
||||
b3_convexCalls = 0;
|
||||
b3_convexCacheHits = 0;
|
||||
b3_enableConvexCache = g_settings.convexCache;
|
||||
|
||||
|
||||
// Step
|
||||
ProfileBegin();
|
||||
|
||||
@ -369,6 +196,7 @@ void Test::Step()
|
||||
drawFlags += g_settings.drawContactPoints * b3Draw::e_contactPointsFlag;
|
||||
drawFlags += g_settings.drawContactNormals * b3Draw::e_contactNormalsFlag;
|
||||
drawFlags += g_settings.drawContactTangents * b3Draw::e_contactTangentsFlag;
|
||||
drawFlags += g_settings.drawContactAreas * b3Draw::e_contactAreasFlag;
|
||||
|
||||
g_debugDraw->SetFlags(drawFlags);
|
||||
m_world.DebugDraw();
|
||||
@ -448,7 +276,7 @@ void Test::MouseMove(const Ray3& pw)
|
||||
float32 w1 = 1.0f - t;
|
||||
float32 w2 = t;
|
||||
|
||||
b3Vec3 target = w1 * pw.Start() + w2 * pw.End();
|
||||
b3Vec3 target = w1 * pw.A() + w2 * pw.B();
|
||||
m_mouseJoint->SetTarget(target);
|
||||
}
|
||||
}
|
||||
@ -468,8 +296,8 @@ void Test::MouseLeftDown(const Ray3& pw)
|
||||
}
|
||||
|
||||
// Perform the ray cast
|
||||
b3Vec3 p1 = pw.Start();
|
||||
b3Vec3 p2 = pw.End();
|
||||
b3Vec3 p1 = pw.A();
|
||||
b3Vec3 p2 = pw.B();
|
||||
|
||||
b3RayCastSingleOutput out;
|
||||
if (m_world.RayCastSingle(&out, p1, p2))
|
||||
|
@ -20,20 +20,25 @@
|
||||
#include <testbed/tests/quickhull_test.h>
|
||||
#include <testbed/tests/cluster_test.h>
|
||||
#include <testbed/tests/distance_test.h>
|
||||
#include <testbed/tests/capsule_distance.h>
|
||||
#include <testbed/tests/collide_test.h>
|
||||
#include <testbed/tests/capsule_collision.h>
|
||||
#include <testbed/tests/capsule_and_hull_collision.h>
|
||||
#include <testbed/tests/capsule_and_hull_collision_1.h>
|
||||
#include <testbed/tests/capsule_and_hull_collision_2.h>
|
||||
#include <testbed/tests/hull_collision.h>
|
||||
#include <testbed/tests/hull_collision_2.h>
|
||||
#include <testbed/tests/linear_motion.h>
|
||||
#include <testbed/tests/angular_motion.h>
|
||||
#include <testbed/tests/multiple_shapes.h>
|
||||
#include <testbed/tests/initial_overlap.h>
|
||||
#include <testbed/tests/capsule_and_hull_contact_1.h>
|
||||
#include <testbed/tests/quadric_shapes.h>
|
||||
#include <testbed/tests/multiple_shapes.h>
|
||||
#include <testbed/tests/gyro_test.h>
|
||||
#include <testbed/tests/spring.h>
|
||||
#include <testbed/tests/weld_test.h>
|
||||
#include <testbed/tests/newton_cradle.h>
|
||||
#include <testbed/tests/cone_test.h>
|
||||
#include <testbed/tests/hinge_motor.h>
|
||||
#include <testbed/tests/hinge_chain.h>
|
||||
#include <testbed/tests/newton_cradle.h>
|
||||
#include <testbed/tests/ragdoll.h>
|
||||
#include <testbed/tests/mesh_contact_test.h>
|
||||
#include <testbed/tests/sphere_stack.h>
|
||||
@ -51,27 +56,32 @@
|
||||
#include <testbed/tests/varying_friction.h>
|
||||
#include <testbed/tests/varying_restitution.h>
|
||||
#include <testbed/tests/cloth_test.h>
|
||||
#include <testbed/tests/tumbler.h>
|
||||
|
||||
TestEntry g_tests[] =
|
||||
{
|
||||
{ "Quickhull Test", &QuickhullTest::Create },
|
||||
{ "Cluster Test", &Cluster::Create },
|
||||
{ "Distance Test", &Distance::Create },
|
||||
{ "Capsule Distance", &CapsuleDistance::Create },
|
||||
{ "Capsule Collision", &CapsuleCollision::Create },
|
||||
{ "Capsule and Hull Collision", &CapsuleAndHull::Create },
|
||||
{ "Hull Collision", &HullAndHull::Create },
|
||||
{ "Capsule and Hull Collision (1)", &CapsuleAndHullCollision1::Create },
|
||||
{ "Capsule and Hull Collision (2)", &CapsuleAndHullCollision2::Create },
|
||||
{ "Hull Collision (1)", &HullAndHull::Create },
|
||||
{ "Hull Collision (2)", &HullAndHull2::Create },
|
||||
{ "Capsule and Hull Contact (1)", &CapsuleAndHullContact1::Create },
|
||||
{ "Linear Motion", &LinearMotion::Create },
|
||||
{ "Angular Motion", &AngularMotion::Create },
|
||||
{ "Multiple Shapes", &MultipleShapes::Create },
|
||||
{ "Quadric Shapes", &QuadricShapes::Create },
|
||||
{ "Thin Boxes", &Thin::Create },
|
||||
{ "Gyroscopic Test", &GyroTest::Create },
|
||||
{ "Springs", &Spring::Create },
|
||||
{ "Weld Test", &WeldTest::Create },
|
||||
{ "Newton's Cradle", &NewtonCradle::Create },
|
||||
{ "Cone Test", &ConeTest::Create },
|
||||
{ "Hinge Motor", &HingeMotor::Create },
|
||||
{ "Hinge Chain", &HingeChain::Create },
|
||||
{ "Ragdoll", &Ragdoll::Create },
|
||||
{ "Thin Boxes", &Thin::Create },
|
||||
{ "Newton's Cradle", &NewtonCradle::Create },
|
||||
{ "Mesh Contact Test", &MeshContactTest::Create },
|
||||
{ "Sphere Stack", &SphereStack::Create },
|
||||
{ "Capsule Stack", &CapsuleStack::Create },
|
||||
@ -87,5 +97,7 @@ TestEntry g_tests[] =
|
||||
{ "Varying Friction", &VaryingFriction::Create },
|
||||
{ "Varying Restitution", &VaryingRestitution::Create },
|
||||
{ "Cloth", &Cloth::Create },
|
||||
{ "Tumbler", &Tumbler::Create },
|
||||
{ "Initial Overlap", &InitialOverlap::Create },
|
||||
{ NULL, NULL }
|
||||
};
|
Reference in New Issue
Block a user