Draw solid stuff inside b3World
This commit is contained in:
@ -302,16 +302,16 @@ void Draw::DrawSolidCircle(const b3Vec3& normal, const b3Vec3& center, float32 r
|
||||
void Draw::DrawSphere(const b3Vec3& center, float32 radius, const b3Color& color)
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.SetIdentity();
|
||||
xf.rotation.SetIdentity();
|
||||
xf.position = center;
|
||||
|
||||
m_wire->DrawSphere(radius, color, xf);
|
||||
}
|
||||
|
||||
void Draw::DrawSolidSphere(const b3Vec3& center, float32 radius, const b3Color& color)
|
||||
void Draw::DrawSolidSphere(const b3Vec3& center, float32 radius, const b3Mat33& rotation, const b3Color& color)
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.SetIdentity();
|
||||
xf.rotation = rotation;
|
||||
xf.position = center;
|
||||
|
||||
m_solid->DrawSphere(radius, color, xf);
|
||||
@ -529,171 +529,6 @@ void Draw::DrawString(const b3Color& color, const char* text, ...)
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void Draw::DrawSolidSphere(const b3SphereShape* s, const b3Color& c, const b3Transform& xf)
|
||||
{
|
||||
b3Transform xfc;
|
||||
xfc.rotation = xf.rotation;
|
||||
xfc.position = xf * s->m_center;
|
||||
m_solid->DrawSphere(s->m_radius, c, xfc);
|
||||
}
|
||||
|
||||
void Draw::DrawSolidCapsule(const b3CapsuleShape* s, const b3Color& c, const b3Transform& xf)
|
||||
{
|
||||
b3Vec3 c1 = s->m_centers[0];
|
||||
b3Vec3 c2 = s->m_centers[1];
|
||||
float32 height = b3Length(c1 - c2);
|
||||
float32 radius = s->m_radius;
|
||||
|
||||
{
|
||||
b3Transform xfc;
|
||||
xfc.rotation = xf.rotation;
|
||||
xfc.position = xf * c1;
|
||||
m_solid->DrawSphere(radius, c, xfc);
|
||||
}
|
||||
|
||||
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.position = xf * (0.5f * (c1 + c2));
|
||||
xfc.rotation = xf.rotation * R;
|
||||
|
||||
m_solid->DrawCylinder(radius, height, c, xfc);
|
||||
}
|
||||
|
||||
{
|
||||
b3Transform xfc;
|
||||
xfc.rotation = xf.rotation;
|
||||
xfc.position = xf * c2;
|
||||
m_solid->DrawSphere(radius, c, xfc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Draw::DrawSolidHull(const b3HullShape* s, const b3Color& c, const b3Transform& xf)
|
||||
{
|
||||
const b3Hull* hull = s->m_hull;
|
||||
|
||||
for (u32 i = 0; i < hull->faceCount; ++i)
|
||||
{
|
||||
const b3Face* face = hull->GetFace(i);
|
||||
const b3HalfEdge* begin = hull->GetEdge(face->edge);
|
||||
|
||||
b3Vec3 n = xf.rotation * hull->planes[i].normal;
|
||||
|
||||
const b3HalfEdge* edge = hull->GetEdge(begin->next);
|
||||
do
|
||||
{
|
||||
u32 i1 = begin->origin;
|
||||
u32 i2 = edge->origin;
|
||||
const b3HalfEdge* next = hull->GetEdge(edge->next);
|
||||
u32 i3 = next->origin;
|
||||
|
||||
b3Vec3 p1 = xf * hull->vertices[i1];
|
||||
b3Vec3 p2 = xf * hull->vertices[i2];
|
||||
b3Vec3 p3 = xf * hull->vertices[i3];
|
||||
|
||||
m_triangles->Vertex(p1, c, n);
|
||||
m_triangles->Vertex(p2, c, n);
|
||||
m_triangles->Vertex(p3, c, n);
|
||||
|
||||
edge = next;
|
||||
} while (hull->GetEdge(edge->next) != begin);
|
||||
}
|
||||
}
|
||||
|
||||
void Draw::DrawSolidMesh(const b3MeshShape* s, const b3Color& c, const b3Transform& xf)
|
||||
{
|
||||
const b3Mesh* mesh = s->m_mesh;
|
||||
for (u32 i = 0; i < mesh->triangleCount; ++i)
|
||||
{
|
||||
const b3Triangle* t = mesh->triangles + i;
|
||||
|
||||
b3Vec3 p1 = xf * mesh->vertices[t->v1];
|
||||
b3Vec3 p2 = xf * mesh->vertices[t->v2];
|
||||
b3Vec3 p3 = xf * mesh->vertices[t->v3];
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void Draw::DrawSolidShape(const b3Shape* s, const b3Color& c, const b3Transform& xf)
|
||||
{
|
||||
switch (s->GetType())
|
||||
{
|
||||
case e_sphereShape:
|
||||
{
|
||||
DrawSolidSphere((b3SphereShape*)s, c, xf);
|
||||
break;
|
||||
}
|
||||
case e_capsuleShape:
|
||||
{
|
||||
DrawSolidCapsule((b3CapsuleShape*)s, c, xf);
|
||||
break;
|
||||
}
|
||||
case e_hullShape:
|
||||
{
|
||||
DrawSolidHull((b3HullShape*)s, c, xf);
|
||||
break;
|
||||
}
|
||||
case e_meshShape:
|
||||
{
|
||||
DrawSolidMesh((b3MeshShape*)s, c, xf);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Draw::DrawSolidShapes(const b3World& world)
|
||||
{
|
||||
for (b3Body* b = world.GetBodyList().m_head; b; b = b->GetNext())
|
||||
{
|
||||
b3Color c;
|
||||
if (b->IsAwake() == false)
|
||||
{
|
||||
c = b3Color(0.5f, 0.25f, 0.25f, 1.0f);
|
||||
}
|
||||
else if (b->GetType() == e_staticBody)
|
||||
{
|
||||
c = b3Color(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
}
|
||||
else if (b->GetType() == e_dynamicBody)
|
||||
{
|
||||
c = b3Color(1.0f, 0.5f, 0.5f, 1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
c = b3Color(0.5f, 0.5f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
b3Transform xf = b->GetTransform();
|
||||
for (b3Shape* s = b->GetShapeList().m_head; s; s = s->GetNext())
|
||||
{
|
||||
DrawSolidShape(s, c, xf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Draw::Flush()
|
||||
{
|
||||
m_triangles->Flush();
|
||||
|
Reference in New Issue
Block a user