Upgrade bounce
This commit is contained in:
@ -35,12 +35,23 @@ bool b3BodyDragger::StartDragging()
|
||||
{
|
||||
B3_ASSERT(IsDragging() == false);
|
||||
|
||||
class RayCastFilter : public b3RayCastFilter
|
||||
{
|
||||
public:
|
||||
bool ShouldRayCast(b3Shape* shape)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
RayCastFilter filter;
|
||||
|
||||
b3RayCastSingleOutput out;
|
||||
if (m_world->RayCastSingle(&out, m_ray->A(), m_ray->B()) == false)
|
||||
if (m_world->RayCastSingle(&out, &filter, m_ray->A(), m_ray->B()) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
m_x = out.fraction;
|
||||
m_shape = out.shape;
|
||||
|
||||
@ -54,7 +65,7 @@ bool b3BodyDragger::StartDragging()
|
||||
jd.bodyA = groundBody;
|
||||
jd.bodyB = body;
|
||||
jd.target = out.point;
|
||||
jd.maxForce = 2000.0f * body->GetMass();
|
||||
jd.maxForce = 1000.0f * body->GetMass();
|
||||
|
||||
m_mouseJoint = (b3MouseJoint*)m_world->CreateJoint(jd);
|
||||
|
||||
@ -79,10 +90,10 @@ void b3BodyDragger::StopDragging()
|
||||
m_shape = nullptr;
|
||||
}
|
||||
|
||||
b3Body* b3BodyDragger::GetBody() const
|
||||
b3Shape* b3BodyDragger::GetShape() const
|
||||
{
|
||||
B3_ASSERT(IsDragging() == true);
|
||||
return m_shape->GetBody();
|
||||
return m_shape;
|
||||
}
|
||||
|
||||
b3Vec3 b3BodyDragger::GetPointA() const
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <bounce/dynamics/shapes/shape.h>
|
||||
#include <bounce/dynamics/body.h>
|
||||
#include <bounce/dynamics/world.h>
|
||||
#include <bounce/dynamics/world_listeners.h>
|
||||
#include <bounce/dynamics/joints/mouse_joint.h>
|
||||
|
||||
// A body shape dragger.
|
||||
@ -43,14 +44,14 @@ public:
|
||||
|
||||
b3Ray3* GetRay() const;
|
||||
|
||||
b3Body* GetBody() const;
|
||||
b3Shape* GetShape() const;
|
||||
|
||||
b3Vec3 GetPointA() const;
|
||||
|
||||
b3Vec3 GetPointB() const;
|
||||
private:
|
||||
b3Ray3 * m_ray;
|
||||
float32 m_x;
|
||||
scalar m_x;
|
||||
|
||||
b3World* m_world;
|
||||
|
||||
|
@ -23,9 +23,9 @@ b3ClothDragger::b3ClothDragger(b3Ray3* ray, b3Cloth* cloth)
|
||||
m_staticDrag = true;
|
||||
m_ray = ray;
|
||||
m_cloth = cloth;
|
||||
m_triangle = nullptr;
|
||||
m_km = 10000.0f;
|
||||
m_kd = 0.0f;
|
||||
m_isDragging = false;
|
||||
m_km = 100000.0f;
|
||||
m_kd = 1000.0f;
|
||||
}
|
||||
|
||||
b3ClothDragger::~b3ClothDragger()
|
||||
@ -43,22 +43,20 @@ bool b3ClothDragger::StartDragging()
|
||||
return false;
|
||||
}
|
||||
|
||||
m_mesh = m_cloth->GetMesh();
|
||||
m_triangleIndex = rayOut.triangle;
|
||||
m_triangle = m_mesh->triangles + m_triangleIndex;
|
||||
m_isDragging = true;
|
||||
m_x = rayOut.fraction;
|
||||
|
||||
b3Particle* p1 = m_cloth->GetParticle(m_triangle->v1);
|
||||
b3Particle* p2 = m_cloth->GetParticle(m_triangle->v2);
|
||||
b3Particle* p3 = m_cloth->GetParticle(m_triangle->v3);
|
||||
m_p1 = rayOut.triangle->GetParticle1();
|
||||
m_p2 = rayOut.triangle->GetParticle2();
|
||||
m_p3 = rayOut.triangle->GetParticle3();
|
||||
|
||||
b3Vec3 v1 = p1->GetPosition();
|
||||
b3Vec3 v2 = p2->GetPosition();
|
||||
b3Vec3 v3 = p3->GetPosition();
|
||||
b3Vec3 v1 = m_p1->GetPosition();
|
||||
b3Vec3 v2 = m_p2->GetPosition();
|
||||
b3Vec3 v3 = m_p3->GetPosition();
|
||||
|
||||
b3Vec3 B = GetPointB();
|
||||
|
||||
float32 wABC[4];
|
||||
scalar wABC[4];
|
||||
b3BarycentricCoordinates(wABC, v1, v2, v3, B);
|
||||
|
||||
if (wABC[3] > B3_EPSILON)
|
||||
@ -73,33 +71,34 @@ bool b3ClothDragger::StartDragging()
|
||||
|
||||
if (m_staticDrag)
|
||||
{
|
||||
m_t1 = p1->GetType();
|
||||
p1->SetType(e_staticParticle);
|
||||
m_t1 = m_p1->GetType();
|
||||
m_p1->SetType(e_staticClothParticle);
|
||||
|
||||
m_t2 = p2->GetType();
|
||||
p2->SetType(e_staticParticle);
|
||||
m_t2 = m_p2->GetType();
|
||||
m_p2->SetType(e_staticClothParticle);
|
||||
|
||||
m_t3 = p3->GetType();
|
||||
p3->SetType(e_staticParticle);
|
||||
m_t3 = m_p3->GetType();
|
||||
m_p3->SetType(e_staticClothParticle);
|
||||
}
|
||||
else
|
||||
{
|
||||
b3ParticleDef pd;
|
||||
pd.type = e_staticParticle;
|
||||
b3ClothParticleDef pd;
|
||||
pd.type = e_staticClothParticle;
|
||||
pd.position = GetPointA();
|
||||
|
||||
m_particle = m_cloth->CreateParticle(pd);
|
||||
|
||||
b3ClothTriangle* triangle = m_cloth->GetTriangle(m_triangleIndex);
|
||||
|
||||
b3MouseForceDef def;
|
||||
def.particle = m_particle;
|
||||
def.triangle = triangle;
|
||||
def.p1 = m_particle;
|
||||
def.p2 = m_p1;
|
||||
def.p3 = m_p2;
|
||||
def.p4 = m_p3;
|
||||
def.w2 = m_u;
|
||||
def.w3 = m_v;
|
||||
def.w4 = (1.0f - m_u - m_v);
|
||||
def.w4 = 1.0f - m_u - m_v;
|
||||
def.mouse = m_km;
|
||||
def.damping = m_kd;
|
||||
def.restLength = 0.0f;
|
||||
|
||||
m_mf = (b3MouseForce*)m_cloth->CreateForce(def);
|
||||
}
|
||||
@ -111,24 +110,23 @@ void b3ClothDragger::Drag()
|
||||
{
|
||||
B3_ASSERT(IsDragging() == true);
|
||||
|
||||
b3Vec3 A = GetPointA();
|
||||
b3Vec3 B = GetPointB();
|
||||
|
||||
b3Vec3 dx = B - A;
|
||||
|
||||
if (m_staticDrag)
|
||||
{
|
||||
b3Particle* p1 = m_cloth->GetParticle(m_triangle->v1);
|
||||
p1->ApplyTranslation(dx);
|
||||
b3Vec3 A = GetPointA();
|
||||
|
||||
b3Particle* p2 = m_cloth->GetParticle(m_triangle->v2);
|
||||
p2->ApplyTranslation(dx);
|
||||
b3Vec3 dx = B - A;
|
||||
|
||||
b3Particle* p3 = m_cloth->GetParticle(m_triangle->v3);
|
||||
p3->ApplyTranslation(dx);
|
||||
m_p1->ApplyTranslation(dx);
|
||||
m_p2->ApplyTranslation(dx);
|
||||
m_p3->ApplyTranslation(dx);
|
||||
}
|
||||
else
|
||||
{
|
||||
//b3Vec3 A = m_particle->GetPosition();
|
||||
//b3Vec3 dx = B - A;
|
||||
//m_particle->ApplyTranslation(dx);
|
||||
m_particle->SetPosition(B);
|
||||
}
|
||||
}
|
||||
@ -154,9 +152,9 @@ void b3ClothDragger::StopDragging()
|
||||
|
||||
if (m_staticDrag)
|
||||
{
|
||||
m_cloth->GetParticle(m_triangle->v1)->SetType(m_t1);
|
||||
m_cloth->GetParticle(m_triangle->v2)->SetType(m_t2);
|
||||
m_cloth->GetParticle(m_triangle->v3)->SetType(m_t3);
|
||||
m_p1->SetType(m_t1);
|
||||
m_p2->SetType(m_t2);
|
||||
m_p3->SetType(m_t3);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -164,18 +162,18 @@ void b3ClothDragger::StopDragging()
|
||||
m_cloth->DestroyParticle(m_particle);
|
||||
}
|
||||
|
||||
m_triangle = nullptr;
|
||||
m_isDragging = false;
|
||||
}
|
||||
|
||||
b3Vec3 b3ClothDragger::GetPointA() const
|
||||
{
|
||||
B3_ASSERT(IsDragging() == true);
|
||||
|
||||
b3Vec3 A = m_cloth->GetParticle(m_triangle->v1)->GetPosition();
|
||||
b3Vec3 B = m_cloth->GetParticle(m_triangle->v2)->GetPosition();
|
||||
b3Vec3 C = m_cloth->GetParticle(m_triangle->v3)->GetPosition();
|
||||
b3Vec3 v1 = m_p1->GetPosition() + m_p1->GetTranslation();
|
||||
b3Vec3 v2 = m_p2->GetPosition() + m_p2->GetTranslation();
|
||||
b3Vec3 v3 = m_p3->GetPosition() + m_p3->GetTranslation();
|
||||
|
||||
return m_u * A + m_v * B + (1.0f - m_u - m_v) * C;
|
||||
return m_u * v1 + m_v * v2 + (1.0f - m_u - m_v) * v3;
|
||||
}
|
||||
|
||||
b3Vec3 b3ClothDragger::GetPointB() const
|
||||
|
@ -21,9 +21,8 @@
|
||||
|
||||
#include <bounce/common/geometry.h>
|
||||
#include <bounce/cloth/cloth.h>
|
||||
#include <bounce/cloth/cloth_mesh.h>
|
||||
#include <bounce/cloth/particle.h>
|
||||
#include <bounce/cloth/cloth_triangle.h>
|
||||
#include <bounce/cloth/cloth_particle.h>
|
||||
#include <bounce/cloth/shapes/cloth_triangle_shape.h>
|
||||
#include <bounce/cloth/forces/mouse_force.h>
|
||||
|
||||
// A cloth triangle dragger.
|
||||
@ -37,13 +36,13 @@ public:
|
||||
|
||||
bool GetStaticDrag() const;
|
||||
|
||||
void SetMouseStiffness(float32 k);
|
||||
void SetMouseStiffness(scalar k);
|
||||
|
||||
float32 GetMouseStiffness();
|
||||
scalar GetMouseStiffness();
|
||||
|
||||
void SetMouseDamping(float32 k);
|
||||
void SetMouseDamping(scalar k);
|
||||
|
||||
float32 GetMouseDamping();
|
||||
scalar GetMouseDamping();
|
||||
|
||||
bool IsDragging() const;
|
||||
|
||||
@ -58,21 +57,23 @@ public:
|
||||
b3Vec3 GetPointB() const;
|
||||
private:
|
||||
b3Ray3* m_ray;
|
||||
float32 m_x;
|
||||
scalar m_x;
|
||||
|
||||
b3Cloth* m_cloth;
|
||||
const b3ClothMesh* m_mesh;
|
||||
u32 m_triangleIndex;
|
||||
b3ClothMeshTriangle* m_triangle;
|
||||
float32 m_u, m_v;
|
||||
|
||||
bool m_isDragging;
|
||||
b3ClothParticle* m_p1;
|
||||
b3ClothParticle* m_p2;
|
||||
b3ClothParticle* m_p3;
|
||||
scalar m_u, m_v;
|
||||
|
||||
float32 m_km;
|
||||
float32 m_kd;
|
||||
b3Particle* m_particle;
|
||||
scalar m_km;
|
||||
scalar m_kd;
|
||||
b3ClothParticle* m_particle;
|
||||
b3MouseForce* m_mf;
|
||||
|
||||
bool m_staticDrag;
|
||||
b3ParticleType m_t1, m_t2, m_t3;
|
||||
b3ClothParticleType m_t1, m_t2, m_t3;
|
||||
};
|
||||
|
||||
inline bool b3ClothDragger::GetStaticDrag() const
|
||||
@ -80,29 +81,29 @@ inline bool b3ClothDragger::GetStaticDrag() const
|
||||
return m_staticDrag;
|
||||
}
|
||||
|
||||
inline void b3ClothDragger::SetMouseStiffness(float32 k)
|
||||
inline void b3ClothDragger::SetMouseStiffness(scalar k)
|
||||
{
|
||||
m_km = k;
|
||||
}
|
||||
|
||||
inline float32 b3ClothDragger::GetMouseStiffness()
|
||||
inline scalar b3ClothDragger::GetMouseStiffness()
|
||||
{
|
||||
return m_km;
|
||||
}
|
||||
|
||||
inline void b3ClothDragger::SetMouseDamping(float32 k)
|
||||
inline void b3ClothDragger::SetMouseDamping(scalar k)
|
||||
{
|
||||
m_kd = k;
|
||||
}
|
||||
|
||||
inline float32 b3ClothDragger::GetMouseDamping()
|
||||
inline scalar b3ClothDragger::GetMouseDamping()
|
||||
{
|
||||
return m_kd;
|
||||
}
|
||||
|
||||
inline bool b3ClothDragger::IsDragging() const
|
||||
{
|
||||
return m_triangle != nullptr;
|
||||
return m_isDragging;
|
||||
}
|
||||
|
||||
#endif
|
@ -50,17 +50,17 @@ Camera::Camera()
|
||||
|
||||
b3Mat44 Camera::BuildProjectionMatrix() const
|
||||
{
|
||||
float32 w = m_width, h = m_height;
|
||||
scalar w = m_width, h = m_height;
|
||||
|
||||
float32 t = tan(0.5f * m_fovy);
|
||||
float32 ratio = w / h;
|
||||
float32 sx = 1.0f / (ratio * t);
|
||||
float32 sy = 1.0f / t;
|
||||
scalar t = tan(0.5f * m_fovy);
|
||||
scalar ratio = w / h;
|
||||
scalar sx = 1.0f / (ratio * t);
|
||||
scalar sy = 1.0f / t;
|
||||
|
||||
float32 inv_range = 1.0f / (m_zNear - m_zFar);
|
||||
float32 sz = inv_range * (m_zNear + m_zFar);
|
||||
scalar inv_range = 1.0f / (m_zNear - m_zFar);
|
||||
scalar sz = inv_range * (m_zNear + m_zFar);
|
||||
|
||||
float32 tz = inv_range * m_zNear * m_zFar;
|
||||
scalar tz = inv_range * m_zNear * m_zFar;
|
||||
|
||||
b3Mat44 m;
|
||||
m.x = b3Vec4(sx, 0.0f, 0.0f, 0.0f);
|
||||
@ -73,8 +73,8 @@ b3Mat44 Camera::BuildProjectionMatrix() const
|
||||
b3Transform Camera::BuildWorldTransform() const
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.rotation = b3QuatMat33(m_q);
|
||||
xf.position = (m_zoom * xf.rotation.z) - m_center;
|
||||
xf.rotation = m_q;
|
||||
xf.translation = (m_zoom * m_q.GetZAxis()) - m_center;
|
||||
return xf;
|
||||
}
|
||||
|
||||
@ -87,8 +87,8 @@ b3Mat44 Camera::BuildWorldMatrix() const
|
||||
b3Transform Camera::BuildViewTransform() const
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.rotation = b3QuatMat33(m_q);
|
||||
xf.position = (m_zoom * xf.rotation.z) - m_center;
|
||||
xf.rotation = m_q;
|
||||
xf.translation = (m_zoom * m_q.GetZAxis()) - m_center;
|
||||
return b3Inverse(xf);
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ b3Mat44 Camera::BuildViewMatrix() const
|
||||
|
||||
b3Vec2 Camera::ConvertWorldToScreen(const b3Vec3& pw3) const
|
||||
{
|
||||
float32 w = m_width, h = m_height;
|
||||
scalar w = m_width, h = m_height;
|
||||
b3Mat44 P = BuildProjectionMatrix();
|
||||
b3Mat44 V = BuildViewMatrix();
|
||||
|
||||
@ -109,11 +109,11 @@ b3Vec2 Camera::ConvertWorldToScreen(const b3Vec3& pw3) const
|
||||
b3Vec4 pp = P * V * pw;
|
||||
|
||||
b3Vec3 pn(pp.x, pp.y, pp.z);
|
||||
float32 inv_w = pp.w != 0.0f ? 1.0f / pp.w : 1.0f;
|
||||
scalar inv_w = pp.w != 0.0f ? 1.0f / pp.w : 1.0f;
|
||||
pn *= inv_w;
|
||||
|
||||
float32 u = 0.5f * (pn.x + 1.0f);
|
||||
float32 v = 0.5f * (pn.y + 1.0f);
|
||||
scalar u = 0.5f * (pn.x + 1.0f);
|
||||
scalar v = 0.5f * (pn.y + 1.0f);
|
||||
|
||||
b3Vec2 ps;
|
||||
ps.x = u * w;
|
||||
@ -123,10 +123,10 @@ b3Vec2 Camera::ConvertWorldToScreen(const b3Vec3& pw3) const
|
||||
|
||||
b3Ray3 Camera::ConvertScreenToWorld(const b3Vec2& ps) const
|
||||
{
|
||||
float32 w = m_width, h = m_height;
|
||||
scalar w = m_width, h = m_height;
|
||||
|
||||
float32 t = tan(0.5f * m_fovy);
|
||||
float32 ratio = w / h;
|
||||
scalar t = tan(0.5f * m_fovy);
|
||||
scalar ratio = w / h;
|
||||
|
||||
b3Vec3 vv;
|
||||
vv.x = 2.0f * ratio * ps.x / w - ratio;
|
||||
@ -135,12 +135,12 @@ b3Ray3 Camera::ConvertScreenToWorld(const b3Vec2& ps) const
|
||||
|
||||
b3Transform xf = BuildWorldTransform();
|
||||
|
||||
b3Vec3 vw = xf.rotation * vv;
|
||||
b3Vec3 vw = b3Mul(xf.rotation, vv);
|
||||
vw.Normalize();
|
||||
|
||||
b3Ray3 rw;
|
||||
rw.direction = vw;
|
||||
rw.origin = xf.position;
|
||||
rw.origin = xf.translation;
|
||||
rw.fraction = m_zFar;
|
||||
return rw;
|
||||
}
|
||||
@ -194,7 +194,7 @@ void Draw::EnableDrawTriangles(bool flag)
|
||||
g_glDrawTriangles = flag;
|
||||
}
|
||||
|
||||
void Draw::DrawPoint(const b3Vec3& p, float32 size, const b3Color& color)
|
||||
void Draw::DrawPoint(const b3Vec3& p, scalar size, const b3Color& color)
|
||||
{
|
||||
m_points->Vertex(p, size, color);
|
||||
}
|
||||
@ -249,14 +249,15 @@ void Draw::DrawSolidPolygon(const b3Vec3& normal, const b3Vec3* vertices, u32 co
|
||||
}
|
||||
}
|
||||
|
||||
void Draw::DrawCircle(const b3Vec3& normal, const b3Vec3& center, float32 radius, const b3Color& color)
|
||||
void Draw::DrawCircle(const b3Vec3& normal, const b3Vec3& center, scalar radius, const b3Color& color)
|
||||
{
|
||||
b3Vec3 n1, n3;
|
||||
b3ComputeBasis(normal, n1, n3);
|
||||
|
||||
u32 kEdgeCount = 20;
|
||||
float32 kAngleInc = 2.0f * B3_PI / float32(kEdgeCount);
|
||||
b3Quat q(normal, kAngleInc);
|
||||
scalar kAngleInc = 2.0f * B3_PI / scalar(kEdgeCount);
|
||||
b3Quat q;
|
||||
q.SetAxisAngle(normal, kAngleInc);
|
||||
|
||||
b3Vec3 p1 = center + radius * n1;
|
||||
for (u32 i = 0; i < kEdgeCount; ++i)
|
||||
@ -272,7 +273,7 @@ void Draw::DrawCircle(const b3Vec3& normal, const b3Vec3& center, float32 radius
|
||||
}
|
||||
}
|
||||
|
||||
void Draw::DrawSolidCircle(const b3Vec3& normal, const b3Vec3& center, float32 radius, const b3Color& color)
|
||||
void Draw::DrawSolidCircle(const b3Vec3& normal, const b3Vec3& center, scalar radius, const b3Color& color)
|
||||
{
|
||||
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);
|
||||
@ -281,8 +282,10 @@ void Draw::DrawSolidCircle(const b3Vec3& normal, const b3Vec3& center, float32 r
|
||||
b3ComputeBasis(normal, n1, n3);
|
||||
|
||||
const u32 kEdgeCount = 20;
|
||||
const float32 kAngleInc = 2.0f * B3_PI / float32(kEdgeCount);
|
||||
b3Quat q(normal, kAngleInc);
|
||||
const scalar kAngleInc = 2.0f * B3_PI / scalar(kEdgeCount);
|
||||
|
||||
b3Quat q;
|
||||
q.SetAxisAngle(normal, kAngleInc);
|
||||
|
||||
b3Vec3 p1 = center + radius * n1;
|
||||
for (u32 i = 0; i < kEdgeCount; ++i)
|
||||
@ -299,32 +302,32 @@ void Draw::DrawSolidCircle(const b3Vec3& normal, const b3Vec3& center, float32 r
|
||||
}
|
||||
}
|
||||
|
||||
void Draw::DrawSphere(const b3Vec3& center, float32 radius, const b3Color& color)
|
||||
void Draw::DrawSphere(const b3Vec3& center, scalar radius, const b3Color& color)
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.rotation.SetIdentity();
|
||||
xf.position = center;
|
||||
xf.translation = center;
|
||||
|
||||
m_wire->DrawSphere(radius, color, xf);
|
||||
}
|
||||
|
||||
void Draw::DrawSolidSphere(const b3Vec3& center, float32 radius, const b3Mat33& rotation, const b3Color& color)
|
||||
void Draw::DrawSolidSphere(const b3Vec3& center, scalar radius, const b3Quat& rotation, const b3Color& color)
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.rotation = rotation;
|
||||
xf.position = center;
|
||||
xf.translation = center;
|
||||
|
||||
m_solid->DrawSphere(radius, color, xf);
|
||||
}
|
||||
|
||||
void Draw::DrawCapsule(const b3Vec3& c1, const b3Vec3& c2, float32 radius, const b3Color& color)
|
||||
void Draw::DrawCapsule(const b3Vec3& c1, const b3Vec3& c2, scalar radius, const b3Color& color)
|
||||
{
|
||||
float32 height = b3Length(c1 - c2);
|
||||
scalar height = b3Length(c1 - c2);
|
||||
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.rotation.SetIdentity();
|
||||
xf.position = c1;
|
||||
xf.translation = c1;
|
||||
m_wire->DrawSphere(radius, color, xf);
|
||||
}
|
||||
|
||||
@ -335,20 +338,20 @@ void Draw::DrawCapsule(const b3Vec3& c1, const b3Vec3& c2, float32 radius, const
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.rotation.SetIdentity();
|
||||
xf.position = c2;
|
||||
xf.translation = c2;
|
||||
m_wire->DrawSphere(radius, color, xf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Draw::DrawSolidCapsule(const b3Vec3& c1, const b3Vec3& c2, float32 radius, const b3Mat33& rotation, const b3Color& c)
|
||||
void Draw::DrawSolidCapsule(const b3Vec3& c1, const b3Vec3& c2, scalar radius, const b3Quat& rotation, const b3Color& c)
|
||||
{
|
||||
float32 height = b3Length(c1 - c2);
|
||||
scalar height = b3Length(c1 - c2);
|
||||
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.rotation = rotation;
|
||||
xf.position = c1;
|
||||
xf.translation = c1;
|
||||
m_solid->DrawSphere(radius, c, xf);
|
||||
}
|
||||
|
||||
@ -359,9 +362,11 @@ void Draw::DrawSolidCapsule(const b3Vec3& c1, const b3Vec3& c2, float32 radius,
|
||||
R.y = (1.0f / height) * (c1 - c2);
|
||||
b3ComputeBasis(R.y, R.z, R.x);
|
||||
|
||||
b3Quat Q = b3Mat33Quat(R);
|
||||
|
||||
b3Transform xf;
|
||||
xf.position = 0.5f * (c1 + c2);
|
||||
xf.rotation = R;
|
||||
xf.translation = 0.5f * (c1 + c2);
|
||||
xf.rotation = Q;
|
||||
|
||||
m_solid->DrawCylinder(radius, height, c, xf);
|
||||
}
|
||||
@ -369,7 +374,7 @@ void Draw::DrawSolidCapsule(const b3Vec3& c1, const b3Vec3& c2, float32 radius,
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.rotation = rotation;
|
||||
xf.position = c2;
|
||||
xf.translation = c2;
|
||||
m_solid->DrawSphere(radius, c, xf);
|
||||
}
|
||||
}
|
||||
@ -377,24 +382,24 @@ void Draw::DrawSolidCapsule(const b3Vec3& c1, const b3Vec3& c2, float32 radius,
|
||||
|
||||
void Draw::DrawTransform(const b3Transform& xf)
|
||||
{
|
||||
float32 lenght = 1.0f;
|
||||
scalar lenght = 1.0f;
|
||||
|
||||
b3Vec3 position = xf.position;
|
||||
b3Mat33 rotation = xf.rotation;
|
||||
b3Vec3 translation = xf.translation;
|
||||
b3Mat33 rotation = b3QuatMat33(xf.rotation);
|
||||
|
||||
b3Vec3 A = position + lenght * rotation.x;
|
||||
b3Vec3 B = position + lenght * rotation.y;
|
||||
b3Vec3 C = position + lenght * rotation.z;
|
||||
b3Vec3 A = translation + lenght * rotation.x;
|
||||
b3Vec3 B = translation + lenght * rotation.y;
|
||||
b3Vec3 C = translation + lenght * rotation.z;
|
||||
|
||||
DrawSegment(position, A, b3Color_red);
|
||||
DrawSegment(position, B, b3Color_green);
|
||||
DrawSegment(position, C, b3Color_blue);
|
||||
DrawSegment(translation, A, b3Color_red);
|
||||
DrawSegment(translation, B, b3Color_green);
|
||||
DrawSegment(translation, C, b3Color_blue);
|
||||
}
|
||||
|
||||
void Draw::DrawAABB(const b3AABB3& aabb, const b3Color& color)
|
||||
void Draw::DrawAABB(const b3AABB& aabb, const b3Color& color)
|
||||
{
|
||||
b3Vec3 lower = aabb.m_lower;
|
||||
b3Vec3 upper = aabb.m_upper;
|
||||
b3Vec3 lower = aabb.lowerBound;
|
||||
b3Vec3 upper = aabb.upperBound;
|
||||
|
||||
b3Vec3 vs[8];
|
||||
|
||||
@ -425,12 +430,12 @@ void Draw::DrawAABB(const b3AABB3& aabb, const b3Color& color)
|
||||
DrawSegment(vs[1], vs[7], color);
|
||||
}
|
||||
|
||||
void Draw::DrawPlane(const b3Vec3& normal, const b3Vec3& center, float32 radius, const b3Color& color)
|
||||
void Draw::DrawPlane(const b3Vec3& normal, const b3Vec3& center, scalar radius, const b3Color& color)
|
||||
{
|
||||
b3Vec3 n1, n2;
|
||||
b3ComputeBasis(normal, n1, n2);
|
||||
|
||||
float32 scale = 2.0f * radius;
|
||||
scalar scale = 2.0f * radius;
|
||||
|
||||
// v1__v4
|
||||
// | |
|
||||
@ -448,14 +453,14 @@ void Draw::DrawPlane(const b3Vec3& normal, const b3Vec3& center, float32 radius,
|
||||
DrawSegment(center, center + normal, color);
|
||||
}
|
||||
|
||||
void Draw::DrawSolidPlane(const b3Vec3& normal, const b3Vec3& center, float32 radius, const b3Color& color)
|
||||
void Draw::DrawSolidPlane(const b3Vec3& normal, const b3Vec3& center, scalar radius, const b3Color& color)
|
||||
{
|
||||
b3Color frameColor(0.5f * color.r, 0.5f * color.g, 0.5f * color.b, 1.0f);
|
||||
|
||||
b3Vec3 n1, n2;
|
||||
b3ComputeBasis(normal, n1, n2);
|
||||
|
||||
float32 scale = 2.0f * radius;
|
||||
scalar scale = 2.0f * radius;
|
||||
|
||||
b3Vec3 v1 = center - scale * n1 - scale * n2;
|
||||
b3Vec3 v2 = center + scale * n1 - scale * n2;
|
||||
|
@ -42,13 +42,13 @@ public:
|
||||
b3Vec2 ConvertWorldToScreen(const b3Vec3& pw) const;
|
||||
b3Ray3 ConvertScreenToWorld(const b3Vec2& ps) const;
|
||||
|
||||
float32 m_zoom;
|
||||
scalar m_zoom;
|
||||
b3Vec3 m_center;
|
||||
b3Quat m_q;
|
||||
float32 m_width, m_height;
|
||||
float32 m_fovy;
|
||||
float32 m_zNear;
|
||||
float32 m_zFar;
|
||||
scalar m_width, m_height;
|
||||
scalar m_fovy;
|
||||
scalar m_zNear;
|
||||
scalar m_zFar;
|
||||
};
|
||||
|
||||
class Draw : public b3Draw
|
||||
@ -67,7 +67,7 @@ public:
|
||||
|
||||
void EnableDrawTriangles(bool flag);
|
||||
|
||||
void DrawPoint(const b3Vec3& p, float32 size, const b3Color& color);
|
||||
void DrawPoint(const b3Vec3& p, scalar size, const b3Color& color);
|
||||
|
||||
void DrawSegment(const b3Vec3& p1, const b3Vec3& p2, const b3Color& color);
|
||||
|
||||
@ -79,23 +79,23 @@ public:
|
||||
|
||||
void DrawSolidPolygon(const b3Vec3& normal, const b3Vec3* vertices, u32 count, const b3Color& color);
|
||||
|
||||
void DrawCircle(const b3Vec3& normal, const b3Vec3& center, float32 radius, const b3Color& color);
|
||||
void DrawCircle(const b3Vec3& normal, const b3Vec3& center, scalar radius, const b3Color& color);
|
||||
|
||||
void DrawSolidCircle(const b3Vec3& normal, const b3Vec3& center, float32 radius, const b3Color& color);
|
||||
void DrawSolidCircle(const b3Vec3& normal, const b3Vec3& center, scalar radius, const b3Color& color);
|
||||
|
||||
void DrawSphere(const b3Vec3& center, float32 radius, const b3Color& color);
|
||||
void DrawSphere(const b3Vec3& center, scalar radius, const b3Color& color);
|
||||
|
||||
void DrawSolidSphere(const b3Vec3& center, float32 radius, const b3Mat33& rotation, const b3Color& color);
|
||||
void DrawSolidSphere(const b3Vec3& center, scalar radius, const b3Quat& rotation, const b3Color& color);
|
||||
|
||||
void DrawCapsule(const b3Vec3& p1, const b3Vec3& p2, float32 radius, const b3Color& color);
|
||||
void DrawCapsule(const b3Vec3& p1, const b3Vec3& p2, scalar radius, const b3Color& color);
|
||||
|
||||
void DrawSolidCapsule(const b3Vec3& p1, const b3Vec3& p2, float32 radius, const b3Mat33& rotation, const b3Color& color);
|
||||
void DrawSolidCapsule(const b3Vec3& p1, const b3Vec3& p2, scalar radius, const b3Quat& rotation, const b3Color& color);
|
||||
|
||||
void DrawPlane(const b3Vec3& normal, const b3Vec3& center, float32 radius, const b3Color& color);
|
||||
void DrawPlane(const b3Vec3& normal, const b3Vec3& center, scalar radius, const b3Color& color);
|
||||
|
||||
void DrawSolidPlane(const b3Vec3& normal, const b3Vec3& center, float32 radius, const b3Color& color);
|
||||
void DrawSolidPlane(const b3Vec3& normal, const b3Vec3& center, scalar radius, const b3Color& color);
|
||||
|
||||
void DrawAABB(const b3AABB3& aabb, const b3Color& color);
|
||||
void DrawAABB(const b3AABB& aabb, const b3Color& color);
|
||||
|
||||
void DrawTransform(const b3Transform& xf);
|
||||
|
||||
|
@ -166,7 +166,7 @@ struct DrawPoints
|
||||
glBufferData(GL_ARRAY_BUFFER, e_vertexCapacity * sizeof(b3Color), m_colors, GL_DYNAMIC_DRAW);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vboIds[2]);
|
||||
glBufferData(GL_ARRAY_BUFFER, e_vertexCapacity * sizeof(float32), m_sizes, GL_DYNAMIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, e_vertexCapacity * sizeof(scalar), m_sizes, GL_DYNAMIC_DRAW);
|
||||
|
||||
AssertGL();
|
||||
|
||||
@ -181,7 +181,7 @@ struct DrawPoints
|
||||
glDeleteBuffers(3, m_vboIds);
|
||||
}
|
||||
|
||||
void Vertex(const b3Vec3& v, float32 size, const b3Color& color)
|
||||
void Vertex(const b3Vec3& v, scalar size, const b3Color& color)
|
||||
{
|
||||
if (m_count == e_vertexCapacity)
|
||||
{
|
||||
@ -226,7 +226,7 @@ struct DrawPoints
|
||||
glVertexAttribPointer(m_colorAttribute, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vboIds[2]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, m_count * sizeof(float32), m_sizes);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, m_count * sizeof(scalar), m_sizes);
|
||||
glEnableVertexAttribArray(m_sizeAttribute);
|
||||
glVertexAttribPointer(m_sizeAttribute, 1, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
|
||||
|
||||
@ -255,7 +255,7 @@ struct DrawPoints
|
||||
|
||||
b3Vec3 m_vertices[e_vertexCapacity];
|
||||
b3Color m_colors[e_vertexCapacity];
|
||||
float32 m_sizes[e_vertexCapacity];
|
||||
scalar m_sizes[e_vertexCapacity];
|
||||
u32 m_count;
|
||||
|
||||
GLuint m_programId;
|
||||
@ -365,7 +365,7 @@ struct DrawLines
|
||||
|
||||
glDisableVertexAttribArray(m_colorAttribute);
|
||||
|
||||
glEnableVertexAttribArray(m_vertexAttribute);
|
||||
glDisableVertexAttribArray(m_vertexAttribute);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glUseProgram(0);
|
||||
@ -608,7 +608,7 @@ struct DrawWire
|
||||
glDeleteProgram(m_programId);
|
||||
}
|
||||
|
||||
void DrawSphere(float32 radius, const b3Color& c, const b3Transform& xf)
|
||||
void DrawSphere(scalar radius, const b3Color& c, const b3Transform& xf)
|
||||
{
|
||||
if (!g_glDrawLines)
|
||||
{
|
||||
@ -777,7 +777,7 @@ struct DrawSolid
|
||||
{
|
||||
}
|
||||
|
||||
void DrawCylinder(float32 radius, float32 height, const b3Color& c, const b3Transform& xf)
|
||||
void DrawCylinder(scalar radius, scalar height, const b3Color& c, const b3Transform& xf)
|
||||
{
|
||||
if (!g_glDrawTriangles)
|
||||
{
|
||||
@ -820,7 +820,7 @@ struct DrawSolid
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void DrawSphere(float32 radius, const b3Color& c, const b3Transform& xf)
|
||||
void DrawSphere(scalar radius, const b3Color& c, const b3Transform& xf)
|
||||
{
|
||||
if (!g_glDrawTriangles)
|
||||
{
|
||||
@ -874,4 +874,4 @@ struct DrawSolid
|
||||
DrawSolidCylinder m_cylinder;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -178,7 +178,7 @@ struct DrawPoints
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vboIds[2]);
|
||||
glVertexAttribPointer(m_sizeAttribute, 1, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
|
||||
glBufferData(GL_ARRAY_BUFFER, e_vertexCapacity * sizeof(float32), m_sizes, GL_DYNAMIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, e_vertexCapacity * sizeof(scalar), m_sizes, GL_DYNAMIC_DRAW);
|
||||
|
||||
AssertGL();
|
||||
|
||||
@ -195,7 +195,7 @@ struct DrawPoints
|
||||
glDeleteBuffers(3, m_vboIds);
|
||||
}
|
||||
|
||||
void Vertex(const b3Vec3& v, float32 size, const b3Color& color)
|
||||
void Vertex(const b3Vec3& v, scalar size, const b3Color& color)
|
||||
{
|
||||
if (m_count == e_vertexCapacity)
|
||||
{
|
||||
@ -238,7 +238,7 @@ struct DrawPoints
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, m_count * sizeof(b3Color), m_colors);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vboIds[2]);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, m_count * sizeof(float32), m_sizes);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, m_count * sizeof(scalar), m_sizes);
|
||||
|
||||
glEnable(GL_PROGRAM_POINT_SIZE);
|
||||
glDrawArrays(GL_POINTS, 0, m_count);
|
||||
@ -260,7 +260,7 @@ struct DrawPoints
|
||||
|
||||
b3Vec3 m_vertices[e_vertexCapacity];
|
||||
b3Color m_colors[e_vertexCapacity];
|
||||
float32 m_sizes[e_vertexCapacity];
|
||||
scalar m_sizes[e_vertexCapacity];
|
||||
u32 m_count;
|
||||
|
||||
GLuint m_programId;
|
||||
@ -625,7 +625,7 @@ struct DrawWire
|
||||
glDeleteProgram(m_programId);
|
||||
}
|
||||
|
||||
void DrawSphere(float32 radius, const b3Color& c, const b3Transform& xf)
|
||||
void DrawSphere(scalar radius, const b3Color& c, const b3Transform& xf)
|
||||
{
|
||||
if (!g_glDrawLines)
|
||||
{
|
||||
@ -792,7 +792,7 @@ struct DrawSolid
|
||||
{
|
||||
}
|
||||
|
||||
void DrawCylinder(float32 radius, float32 height, const b3Color& c, const b3Transform& xf)
|
||||
void DrawCylinder(scalar radius, scalar height, const b3Color& c, const b3Transform& xf)
|
||||
{
|
||||
if (!g_glDrawTriangles)
|
||||
{
|
||||
@ -831,7 +831,7 @@ struct DrawSolid
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void DrawSphere(float32 radius, const b3Color& c, const b3Transform& xf)
|
||||
void DrawSphere(scalar radius, const b3Color& c, const b3Transform& xf)
|
||||
{
|
||||
if (!g_glDrawTriangles)
|
||||
{
|
||||
|
@ -77,7 +77,7 @@ void JsonProfiler::EndEvents()
|
||||
m_file = nullptr;
|
||||
}
|
||||
|
||||
void JsonProfiler::BeginEvent(const char* name, float64 t)
|
||||
void JsonProfiler::BeginEvent(const char* name, scalar64 t)
|
||||
{
|
||||
if (!m_writer)
|
||||
{
|
||||
@ -86,7 +86,7 @@ void JsonProfiler::BeginEvent(const char* name, float64 t)
|
||||
|
||||
const char* phase = "B";
|
||||
|
||||
float64 scale = 1000.0;
|
||||
scalar64 scale = 1000.0;
|
||||
|
||||
m_writer->StartObject();
|
||||
m_writer->STRING("pid"); m_writer->Int(0);
|
||||
@ -99,7 +99,7 @@ void JsonProfiler::BeginEvent(const char* name, float64 t)
|
||||
m_writer->EndObject();
|
||||
}
|
||||
|
||||
void JsonProfiler::EndEvent(const char* name, float64 t)
|
||||
void JsonProfiler::EndEvent(const char* name, scalar64 t)
|
||||
{
|
||||
if (!m_writer)
|
||||
{
|
||||
@ -108,7 +108,7 @@ void JsonProfiler::EndEvent(const char* name, float64 t)
|
||||
|
||||
const char* phase = "E";
|
||||
|
||||
float64 scale = 1000.0;
|
||||
scalar64 scale = 1000.0;
|
||||
|
||||
m_writer->StartObject();
|
||||
m_writer->STRING("pid"); m_writer->Int(0);
|
||||
|
@ -43,9 +43,9 @@ public:
|
||||
|
||||
void EndEvents();
|
||||
|
||||
void BeginEvent(const char* name, float64 time);
|
||||
void BeginEvent(const char* name, scalar64 time);
|
||||
|
||||
void EndEvent(const char* name, float64 time);
|
||||
void EndEvent(const char* name, scalar64 time);
|
||||
private:
|
||||
FILE* m_file;
|
||||
FileWriteStream* m_stream;
|
||||
|
@ -24,6 +24,8 @@
|
||||
// error
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <glfw/glfw3.h>
|
||||
|
||||
#include <testbed/framework/model.h>
|
||||
@ -103,14 +105,12 @@ static void Run()
|
||||
|
||||
while (glfwWindowShouldClose(g_window) == 0)
|
||||
{
|
||||
g_frameAllocator->Reset();
|
||||
|
||||
g_profiler->Begin();
|
||||
|
||||
g_profilerSt->Begin();
|
||||
|
||||
g_profiler->BeginScope("Frame");
|
||||
|
||||
g_profilerSt->BeginScope("Frame");
|
||||
|
||||
g_view->BeginInterface();
|
||||
|
||||
if (g_model->IsPaused())
|
||||
@ -126,22 +126,13 @@ static void Run()
|
||||
|
||||
g_model->Update();
|
||||
|
||||
g_profilerSt->EndScope();
|
||||
|
||||
g_profiler->EndScope();
|
||||
|
||||
if (g_settings->drawProfileTree)
|
||||
if (g_settings->drawProfiler)
|
||||
{
|
||||
g_view->InterfaceProfileTree();
|
||||
g_view->InterfaceProfiler();
|
||||
}
|
||||
|
||||
if (g_settings->drawProfileTreeStats)
|
||||
{
|
||||
g_view->InterfaceProfileTreeStats();
|
||||
}
|
||||
|
||||
g_profilerSt->End();
|
||||
|
||||
#if PROFILE_JSON == 1
|
||||
g_model->UpdateJson();
|
||||
#endif
|
||||
@ -160,7 +151,7 @@ int main(int argc, char** args)
|
||||
#if defined(_WIN32)
|
||||
// Report memory leaks
|
||||
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
|
||||
//_CrtSetBreakAlloc(0);
|
||||
//_CrtSetBreakAlloc();
|
||||
#endif
|
||||
|
||||
if (glfwInit() == 0)
|
||||
@ -186,7 +177,7 @@ int main(int argc, char** args)
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwMakeContextCurrent(g_window);
|
||||
|
||||
|
||||
if (gladLoadGL() == 0)
|
||||
{
|
||||
fprintf(stderr, "Failed to load OpenGL extensions\n");
|
||||
|
@ -20,14 +20,17 @@
|
||||
#include <testbed/framework/view_model.h>
|
||||
#include <testbed/framework/test.h>
|
||||
|
||||
b3FrameAllocator* g_frameAllocator = nullptr;
|
||||
b3Profiler* g_profiler = nullptr;
|
||||
|
||||
Model::Model()
|
||||
{
|
||||
m_viewModel = nullptr;
|
||||
g_draw = &m_draw;
|
||||
g_camera = &m_camera;
|
||||
g_profiler = &m_profiler;
|
||||
g_profilerSt = &m_profilerSt;
|
||||
|
||||
g_frameAllocator = &m_frame;
|
||||
|
||||
#if (PROFILE_JSON == 1)
|
||||
g_jsonProfiler = &m_jsonProfiler;
|
||||
#endif
|
||||
@ -41,7 +44,7 @@ Model::Model()
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
|
||||
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
glClearDepth(1.0f);
|
||||
|
||||
Action_ResetCamera();
|
||||
@ -56,7 +59,7 @@ Model::~Model()
|
||||
g_draw = nullptr;
|
||||
g_camera = nullptr;
|
||||
g_profiler = nullptr;
|
||||
g_profilerSt = nullptr;
|
||||
g_frameAllocator = nullptr;
|
||||
|
||||
#if (PROFILE_JSON == 1)
|
||||
g_jsonProfiler = nullptr;
|
||||
@ -114,11 +117,11 @@ void Model::Update()
|
||||
|
||||
if (m_setTest)
|
||||
{
|
||||
Action_ResetCamera();
|
||||
delete m_test;
|
||||
m_test = g_tests[g_settings->testID].create();
|
||||
m_setTest = false;
|
||||
m_pause = true;
|
||||
Action_ResetCamera();
|
||||
}
|
||||
|
||||
if (g_settings->drawGrid)
|
||||
@ -129,9 +132,9 @@ void Model::Update()
|
||||
b3Vec3 vs[h * w];
|
||||
|
||||
b3Vec3 t;
|
||||
t.x = -0.5f * float32(w) + 0.5f;
|
||||
t.x = -0.5f * scalar(w) + 0.5f;
|
||||
t.y = 0.0f;
|
||||
t.z = -0.5f * float32(h) + 0.5f;
|
||||
t.z = -0.5f * scalar(h) + 0.5f;
|
||||
|
||||
for (u32 i = 0; i < h; ++i)
|
||||
{
|
||||
@ -140,9 +143,9 @@ void Model::Update()
|
||||
u32 iv = i * w + j;
|
||||
|
||||
b3Vec3 v;
|
||||
v.x = float32(j);
|
||||
v.x = scalar(j);
|
||||
v.y = 0.0f;
|
||||
v.z = float32(i);
|
||||
v.z = scalar(i);
|
||||
|
||||
v += t;
|
||||
|
||||
@ -150,57 +153,55 @@ void Model::Update()
|
||||
}
|
||||
}
|
||||
|
||||
b3Color color(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
b3Color borderColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
b3Color centerColor(0.8f, 0.8f, 0.8f, 1.0f);
|
||||
b3Color color(0.4f, 0.4f, 0.4f, 1.0f);
|
||||
|
||||
// Left-Right Lines
|
||||
u32 hv1 = (h - 1) / 2 * w + 0;
|
||||
u32 hv2 = (h - 1) / 2 * w + (w - 1);
|
||||
{
|
||||
b3Vec3 v1 = vs[hv1];
|
||||
b3Vec3 v2 = vs[hv2];
|
||||
|
||||
b3Draw_draw->DrawSegment(v1, v2, b3Color_black);
|
||||
}
|
||||
|
||||
// Left to right lines
|
||||
for (u32 i = 0; i < h; ++i)
|
||||
{
|
||||
if (i == hv1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
u32 iv1 = i * w + 0;
|
||||
u32 iv2 = i * w + (w - 1);
|
||||
|
||||
b3Vec3 v1 = vs[iv1];
|
||||
b3Vec3 v2 = vs[iv2];
|
||||
|
||||
b3Draw_draw->DrawSegment(v1, v2, color);
|
||||
}
|
||||
|
||||
// Up-Bottom Lines
|
||||
u32 wv1 = 0 * w + (w - 1) / 2;
|
||||
u32 wv2 = (h - 1) * w + (w - 1) / 2;
|
||||
{
|
||||
b3Vec3 v1 = vs[wv1];
|
||||
b3Vec3 v2 = vs[wv2];
|
||||
|
||||
b3Draw_draw->DrawSegment(v1, v2, b3Color_black);
|
||||
}
|
||||
|
||||
for (u32 j = 0; j < w; ++j)
|
||||
{
|
||||
if (j == wv1)
|
||||
if (i == 0 || i == (h - 1))
|
||||
{
|
||||
b3Draw_draw->DrawSegment(v1, v2, borderColor);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i == (h - 1) / 2)
|
||||
{
|
||||
b3Draw_draw->DrawSegment(v1, v2, centerColor);
|
||||
continue;
|
||||
}
|
||||
|
||||
b3Draw_draw->DrawSegment(v1, v2, color);
|
||||
}
|
||||
|
||||
// Up to bottom lines
|
||||
for (u32 j = 0; j < w; ++j)
|
||||
{
|
||||
u32 iv1 = 0 * w + j;
|
||||
u32 iv2 = (h - 1) * w + j;
|
||||
|
||||
b3Vec3 v1 = vs[iv1];
|
||||
b3Vec3 v2 = vs[iv2];
|
||||
|
||||
if (j == 0 || j == (w - 1))
|
||||
{
|
||||
b3Draw_draw->DrawSegment(v1, v2, borderColor);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (j == (w - 1) / 2)
|
||||
{
|
||||
b3Draw_draw->DrawSegment(v1, v2, centerColor);
|
||||
continue;
|
||||
}
|
||||
|
||||
b3Draw_draw->DrawSegment(v1, v2, color);
|
||||
}
|
||||
}
|
||||
@ -233,15 +234,17 @@ void Model::Update()
|
||||
|
||||
#if (PROFILE_JSON == 1)
|
||||
|
||||
static inline void RecurseEvents(ProfilerNode* node)
|
||||
static inline void RecurseEvents(b3ProfilerNode* node)
|
||||
{
|
||||
g_jsonProfiler->BeginEvent(node->name, node->t0);
|
||||
|
||||
g_jsonProfiler->EndEvent(node->name, node->t1);
|
||||
|
||||
for (u32 i = 0; i < node->children.Count(); ++i)
|
||||
b3ProfilerNode* child = node->head;
|
||||
while (child)
|
||||
{
|
||||
RecurseEvents(node->children[i]);
|
||||
RecurseEvents(child);
|
||||
child = child->next;
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,7 +252,7 @@ void Model::UpdateJson()
|
||||
{
|
||||
m_jsonProfiler.BeginEvents();
|
||||
|
||||
ProfilerNode* root = m_profiler.GetRoot();
|
||||
b3ProfilerNode* root = m_profiler.GetRoot();
|
||||
|
||||
if (root)
|
||||
{
|
||||
|
@ -20,8 +20,11 @@
|
||||
#define MODEL_H
|
||||
|
||||
#include <testbed/framework/draw.h>
|
||||
#include <testbed/framework/profiler.h>
|
||||
#include <testbed/framework/profiler_st.h>
|
||||
#include <bounce/common/profiler.h>
|
||||
|
||||
extern b3FrameAllocator* g_frameAllocator;
|
||||
|
||||
extern b3Profiler* g_profiler;
|
||||
|
||||
// Set to 1 to write profile events into a .json file. Set to 0 otherwise.
|
||||
#define PROFILE_JSON 0
|
||||
@ -53,12 +56,12 @@ public:
|
||||
void Command_Release_Mouse_Left(const b3Vec2& ps);
|
||||
void Command_Move_Cursor(const b3Vec2& ps);
|
||||
|
||||
void Command_ResizeCamera(float32 w, float32 h);
|
||||
void Command_RotateCameraX(float32 angle);
|
||||
void Command_RotateCameraY(float32 angle);
|
||||
void Command_TranslateCameraX(float32 d);
|
||||
void Command_TranslateCameraY(float32 d);
|
||||
void Command_ZoomCamera(float32 d);
|
||||
void Command_ResizeCamera(scalar w, scalar h);
|
||||
void Command_RotateCameraX(scalar angle);
|
||||
void Command_RotateCameraY(scalar angle);
|
||||
void Command_TranslateCameraX(scalar d);
|
||||
void Command_TranslateCameraY(scalar d);
|
||||
void Command_ZoomCamera(scalar d);
|
||||
|
||||
void Update();
|
||||
|
||||
@ -74,8 +77,8 @@ private:
|
||||
|
||||
Draw m_draw;
|
||||
Camera m_camera;
|
||||
Profiler m_profiler;
|
||||
ProfilerSt m_profilerSt;
|
||||
b3FrameAllocator m_frame;
|
||||
b3Profiler m_profiler;
|
||||
|
||||
#if (PROFILE_JSON == 1)
|
||||
JsonProfiler m_jsonProfiler;
|
||||
@ -115,13 +118,13 @@ inline void Model::Action_ResetCamera()
|
||||
m_camera.m_zoom = 50.0f;
|
||||
}
|
||||
|
||||
inline void Model::Command_ResizeCamera(float32 w, float32 h)
|
||||
inline void Model::Command_ResizeCamera(scalar w, scalar h)
|
||||
{
|
||||
m_camera.m_width = w;
|
||||
m_camera.m_height = h;
|
||||
}
|
||||
|
||||
inline void Model::Command_RotateCameraX(float32 angle)
|
||||
inline void Model::Command_RotateCameraX(scalar angle)
|
||||
{
|
||||
b3Quat d = b3QuatRotationX(angle);
|
||||
|
||||
@ -129,7 +132,7 @@ inline void Model::Command_RotateCameraX(float32 angle)
|
||||
m_camera.m_q.Normalize();
|
||||
}
|
||||
|
||||
inline void Model::Command_RotateCameraY(float32 angle)
|
||||
inline void Model::Command_RotateCameraY(scalar angle)
|
||||
{
|
||||
b3Quat d = b3QuatRotationY(angle);
|
||||
|
||||
@ -137,21 +140,21 @@ inline void Model::Command_RotateCameraY(float32 angle)
|
||||
m_camera.m_q.Normalize();
|
||||
}
|
||||
|
||||
inline void Model::Command_TranslateCameraX(float32 d)
|
||||
inline void Model::Command_TranslateCameraX(scalar d)
|
||||
{
|
||||
b3Transform transform = m_camera.BuildWorldTransform();
|
||||
|
||||
m_camera.m_center += d * transform.rotation.x;
|
||||
m_camera.m_center += d * transform.rotation.GetXAxis();
|
||||
}
|
||||
|
||||
inline void Model::Command_TranslateCameraY(float32 d)
|
||||
inline void Model::Command_TranslateCameraY(scalar d)
|
||||
{
|
||||
b3Transform transform = m_camera.BuildWorldTransform();
|
||||
|
||||
m_camera.m_center += d * transform.rotation.y;
|
||||
m_camera.m_center += d * transform.rotation.GetYAxis();
|
||||
}
|
||||
|
||||
inline void Model::Command_ZoomCamera(float32 d)
|
||||
inline void Model::Command_ZoomCamera(scalar d)
|
||||
{
|
||||
m_camera.m_zoom += d;
|
||||
}
|
||||
|
@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2019 Irlan Robson https://irlanrobson.github.io
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <testbed/framework/profiler.h>
|
||||
|
||||
Profiler* g_profiler = nullptr;
|
||||
|
||||
Profiler::Profiler() : m_pool(sizeof(ProfilerNode))
|
||||
{
|
||||
m_root = nullptr;
|
||||
m_top = nullptr;
|
||||
}
|
||||
|
||||
Profiler::~Profiler()
|
||||
{
|
||||
assert(m_root == nullptr);
|
||||
assert(m_top == nullptr);
|
||||
}
|
||||
|
||||
ProfilerNode* Profiler::CreateNode()
|
||||
{
|
||||
void* block = m_pool.Allocate();
|
||||
ProfilerNode* n = new (block) ProfilerNode();
|
||||
return n;
|
||||
}
|
||||
|
||||
void Profiler::DestroyNode(ProfilerNode* node)
|
||||
{
|
||||
node->~ProfilerNode();
|
||||
m_pool.Free(node);
|
||||
}
|
||||
|
||||
void Profiler::BeginScope(const char* name)
|
||||
{
|
||||
m_time.Update();
|
||||
|
||||
ProfilerNode* n = CreateNode();
|
||||
n->name = name;
|
||||
n->t0 = m_time.GetCurrentMilis();
|
||||
n->t1 = 0.0;
|
||||
n->parent = m_top;
|
||||
|
||||
if (m_root == nullptr)
|
||||
{
|
||||
m_root = n;
|
||||
m_top = n;
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_top)
|
||||
{
|
||||
m_top->children.PushBack(n);
|
||||
}
|
||||
|
||||
m_top = n;
|
||||
}
|
||||
|
||||
void Profiler::EndScope()
|
||||
{
|
||||
m_time.Update();
|
||||
|
||||
assert(m_top != nullptr);
|
||||
m_top->t1 = m_time.GetCurrentMilis();
|
||||
assert(m_top->t1 > m_top->t0);
|
||||
|
||||
m_top = m_top->parent;
|
||||
}
|
||||
|
||||
void Profiler::Begin()
|
||||
{
|
||||
// If this assert is hit then it means Profiler::End hasn't been called.
|
||||
assert(m_root == nullptr);
|
||||
assert(m_top == nullptr);
|
||||
}
|
||||
|
||||
void Profiler::RecurseDestroyNode(ProfilerNode* node)
|
||||
{
|
||||
for (u32 i = 0; i < node->children.Count(); ++i)
|
||||
{
|
||||
RecurseDestroyNode(node->children[i]);
|
||||
}
|
||||
|
||||
DestroyNode(node);
|
||||
}
|
||||
|
||||
void Profiler::End()
|
||||
{
|
||||
assert(m_top == nullptr);
|
||||
|
||||
if (m_root)
|
||||
{
|
||||
RecurseDestroyNode(m_root);
|
||||
m_root = nullptr;
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2019 Irlan Robson https://irlanrobson.github.io
|
||||
*
|
||||
* 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 PROFILER_H
|
||||
#define PROFILER_H
|
||||
|
||||
#include <bounce/common/math/math.h>
|
||||
#include <bounce/common/memory/block_pool.h>
|
||||
#include <bounce/common/template/array.h>
|
||||
#include <bounce/common/time.h>
|
||||
|
||||
// Profiler node
|
||||
struct ProfilerNode
|
||||
{
|
||||
const char* name;
|
||||
float64 t0;
|
||||
float64 t1;
|
||||
ProfilerNode* parent;
|
||||
b3StackArray<ProfilerNode*, 32> children;
|
||||
};
|
||||
|
||||
// A single-threaded profiler.
|
||||
class Profiler
|
||||
{
|
||||
public:
|
||||
Profiler();
|
||||
|
||||
~Profiler();
|
||||
|
||||
// Must be called before profiling.
|
||||
void Begin();
|
||||
|
||||
// Must be called after profiling.
|
||||
void End();
|
||||
|
||||
// Begin a new scope.
|
||||
void BeginScope(const char* name);
|
||||
|
||||
// End the top scope.
|
||||
void EndScope();
|
||||
|
||||
// Get the root profiler node.
|
||||
ProfilerNode* GetRoot() { return m_root; }
|
||||
private:
|
||||
ProfilerNode* CreateNode();
|
||||
void DestroyNode(ProfilerNode* node);
|
||||
|
||||
void RecurseDestroyNode(ProfilerNode* node);
|
||||
|
||||
b3BlockPool m_pool; // pool of nodes
|
||||
b3Time m_time; // timer
|
||||
ProfilerNode* m_root; // tree root node
|
||||
ProfilerNode* m_top; // top node
|
||||
};
|
||||
|
||||
extern Profiler* g_profiler;
|
||||
|
||||
#endif
|
@ -1,197 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2019 Irlan Robson https://irlanrobson.github.io
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <testbed/framework/profiler_st.h>
|
||||
|
||||
ProfilerSt* g_profilerSt = nullptr;
|
||||
|
||||
ProfilerSt::ProfilerSt() : m_pool(sizeof(ProfilerStNode))
|
||||
{
|
||||
m_root = nullptr;
|
||||
m_top = nullptr;
|
||||
}
|
||||
|
||||
ProfilerSt::~ProfilerSt()
|
||||
{
|
||||
assert(m_root == nullptr);
|
||||
assert(m_top == nullptr);
|
||||
}
|
||||
|
||||
ProfilerStNodeStat* ProfilerSt::FindStat(const char* name)
|
||||
{
|
||||
for (u32 i = 0; i < m_stats.Count(); ++i)
|
||||
{
|
||||
if (m_stats[i].name == name)
|
||||
{
|
||||
return &m_stats[i];
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ProfilerStNodeStat* ProfilerSt::CreateStat()
|
||||
{
|
||||
m_stats.PushBack(ProfilerStNodeStat());
|
||||
return &m_stats.Back();
|
||||
}
|
||||
|
||||
ProfilerStNode* ProfilerSt::CreateNode()
|
||||
{
|
||||
void* block = m_pool.Allocate();
|
||||
return new (block) ProfilerStNode();
|
||||
}
|
||||
|
||||
void ProfilerSt::DestroyNode(ProfilerStNode* node)
|
||||
{
|
||||
node->~ProfilerStNode();
|
||||
m_pool.Free(node);
|
||||
}
|
||||
|
||||
void ProfilerSt::RecurseDestroyNode(ProfilerStNode* node)
|
||||
{
|
||||
for (u32 i = 0; i < node->children.Count(); ++i)
|
||||
{
|
||||
return RecurseDestroyNode(node->children[i]);
|
||||
}
|
||||
|
||||
DestroyNode(node);
|
||||
}
|
||||
|
||||
static ProfilerStNode* RecurseFindNode(ProfilerStNode* node, const char* name)
|
||||
{
|
||||
if (node->name == name)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
ProfilerStNode* result = nullptr;
|
||||
for (u32 i = 0; result == nullptr && i < node->children.Count(); ++i)
|
||||
{
|
||||
result = RecurseFindNode(node->children[i], name);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ProfilerStNode* ProfilerSt::FindNode(const char* name)
|
||||
{
|
||||
if (m_top)
|
||||
{
|
||||
return RecurseFindNode(m_top, name);
|
||||
}
|
||||
|
||||
if (m_root)
|
||||
{
|
||||
return RecurseFindNode(m_root, name);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ProfilerSt::BeginScope(const char* name)
|
||||
{
|
||||
ProfilerStNode* fn = FindNode(name);
|
||||
|
||||
if (fn)
|
||||
{
|
||||
m_time.Update();
|
||||
fn->t0 = m_time.GetCurrentMilis();
|
||||
++fn->callCount;
|
||||
m_top = fn;
|
||||
return;
|
||||
}
|
||||
|
||||
m_time.Update();
|
||||
|
||||
ProfilerStNode* n = CreateNode();
|
||||
n->name = name;
|
||||
n->t0 = m_time.GetCurrentMilis();
|
||||
n->elapsed = 0.0f;
|
||||
n->callCount = 1;
|
||||
n->parent = m_top;
|
||||
n->stat = nullptr;
|
||||
|
||||
if (m_root == nullptr)
|
||||
{
|
||||
m_root = n;
|
||||
m_top = n;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_top)
|
||||
{
|
||||
m_top->children.PushBack(n);
|
||||
}
|
||||
|
||||
m_top = n;
|
||||
}
|
||||
|
||||
void ProfilerSt::EndScope()
|
||||
{
|
||||
assert(m_top != nullptr);
|
||||
|
||||
m_time.Update();
|
||||
|
||||
m_top->t1 = m_time.GetCurrentMilis();
|
||||
|
||||
float64 elapsedTime = m_top->t1 - m_top->t0;
|
||||
|
||||
m_top->elapsed += elapsedTime;
|
||||
|
||||
ProfilerStNodeStat* stat = FindStat(m_top->name);
|
||||
|
||||
if (stat == nullptr)
|
||||
{
|
||||
stat = CreateStat();
|
||||
stat->name = m_top->name;
|
||||
stat->minElapsed = elapsedTime;
|
||||
stat->maxElapsed = elapsedTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
stat->minElapsed = b3Min(stat->minElapsed, elapsedTime);
|
||||
stat->maxElapsed = b3Max(stat->maxElapsed, elapsedTime);
|
||||
}
|
||||
|
||||
if (m_top->stat == nullptr)
|
||||
{
|
||||
m_top->stat = stat;
|
||||
}
|
||||
|
||||
assert(m_top->stat == stat);
|
||||
|
||||
m_top = m_top->parent;
|
||||
}
|
||||
|
||||
void ProfilerSt::Begin()
|
||||
{
|
||||
assert(m_top == nullptr);
|
||||
}
|
||||
|
||||
void ProfilerSt::End()
|
||||
{
|
||||
assert(m_top == nullptr);
|
||||
|
||||
if (m_root)
|
||||
{
|
||||
RecurseDestroyNode(m_root);
|
||||
m_root = nullptr;
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2019 Irlan Robson https://irlanrobson.github.io
|
||||
*
|
||||
* 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 PROFILER_ST_H
|
||||
#define PROFILER_ST_H
|
||||
|
||||
#include <bounce/common/math/math.h>
|
||||
#include <bounce/common/memory/block_pool.h>
|
||||
#include <bounce/common/template/array.h>
|
||||
#include <bounce/common/time.h>
|
||||
|
||||
// Profiler tree node statistics
|
||||
struct ProfilerStNodeStat
|
||||
{
|
||||
const char* name;
|
||||
float64 minElapsed;
|
||||
float64 maxElapsed;
|
||||
};
|
||||
|
||||
// A profiler tree node
|
||||
struct ProfilerStNode
|
||||
{
|
||||
const char* name;
|
||||
float64 t0;
|
||||
float64 t1;
|
||||
|
||||
float64 elapsed;
|
||||
u32 callCount;
|
||||
|
||||
ProfilerStNode* parent;
|
||||
b3StackArray<ProfilerStNode*, 32> children;
|
||||
|
||||
ProfilerStNodeStat* stat;
|
||||
};
|
||||
|
||||
// A profiler tree
|
||||
class ProfilerSt
|
||||
{
|
||||
public:
|
||||
ProfilerSt();
|
||||
|
||||
~ProfilerSt();
|
||||
|
||||
// Must be called before profiling.
|
||||
void Begin();
|
||||
|
||||
// Must be called after profiling.
|
||||
void End();
|
||||
|
||||
// Begin a new scope.
|
||||
void BeginScope(const char* name);
|
||||
|
||||
// End the top scope.
|
||||
void EndScope();
|
||||
|
||||
ProfilerStNode* GetRoot() { return m_root; }
|
||||
private:
|
||||
ProfilerStNode* CreateNode();
|
||||
void DestroyNode(ProfilerStNode* node);
|
||||
|
||||
void RecurseDestroyNode(ProfilerStNode* node);
|
||||
|
||||
ProfilerStNode* FindNode(const char* name);
|
||||
|
||||
ProfilerStNodeStat* CreateStat();
|
||||
|
||||
ProfilerStNodeStat* FindStat(const char* name);
|
||||
|
||||
b3BlockPool m_pool; // pool of nodes
|
||||
b3Time m_time; // timer
|
||||
ProfilerStNode* m_root; // tree root node
|
||||
ProfilerStNode* m_top; // top node
|
||||
|
||||
b3StackArray<ProfilerStNodeStat, 256> m_stats; // node statistics
|
||||
};
|
||||
|
||||
extern ProfilerSt* g_profilerSt;
|
||||
|
||||
#endif
|
@ -22,7 +22,7 @@ b3SoftBodyDragger::b3SoftBodyDragger(b3Ray3* ray, b3SoftBody* body)
|
||||
{
|
||||
m_ray = ray;
|
||||
m_body = body;
|
||||
m_tetrahedron = nullptr;
|
||||
m_isDragging = false;
|
||||
}
|
||||
|
||||
b3SoftBodyDragger::~b3SoftBodyDragger()
|
||||
@ -40,41 +40,45 @@ bool b3SoftBodyDragger::StartDragging()
|
||||
return false;
|
||||
}
|
||||
|
||||
m_mesh = m_body->GetMesh();
|
||||
m_tetrahedron = m_mesh->tetrahedrons + rayOut.tetrahedron;
|
||||
m_v1 = m_tetrahedron->v1;
|
||||
m_v2 = m_tetrahedron->v2;
|
||||
m_v3 = m_tetrahedron->v3;
|
||||
m_v4 = m_tetrahedron->v4;
|
||||
m_isDragging = true;
|
||||
m_x = rayOut.fraction;
|
||||
|
||||
b3SoftBodyNode* n1 = m_body->GetVertexNode(m_v1);
|
||||
b3SoftBodyNode* n2 = m_body->GetVertexNode(m_v2);
|
||||
b3SoftBodyNode* n3 = m_body->GetVertexNode(m_v3);
|
||||
b3SoftBodyNode* n4 = m_body->GetVertexNode(m_v4);
|
||||
const b3SoftBodyMesh* mesh = m_body->GetMesh();
|
||||
const b3SoftBodyMeshTriangle* triangle = mesh->triangles + rayOut.triangle;
|
||||
|
||||
b3Vec3 v1 = n1->GetPosition();
|
||||
b3Vec3 v2 = n2->GetPosition();
|
||||
b3Vec3 v3 = n3->GetPosition();
|
||||
b3Vec3 v4 = n4->GetPosition();
|
||||
m_n1 = m_body->GetNode(triangle->v1);
|
||||
m_n2 = m_body->GetNode(triangle->v2);
|
||||
m_n3 = m_body->GetNode(triangle->v3);
|
||||
|
||||
b3Vec3 v1 = m_n1->GetPosition();
|
||||
b3Vec3 v2 = m_n2->GetPosition();
|
||||
b3Vec3 v3 = m_n3->GetPosition();
|
||||
|
||||
b3Vec3 B = GetPointB();
|
||||
|
||||
float32 wABCD[5];
|
||||
b3BarycentricCoordinates(wABCD, v1, v2, v3, v4, B);
|
||||
scalar wABC[4];
|
||||
b3BarycentricCoordinates(wABC, v1, v2, v3, B);
|
||||
|
||||
if (wABCD[4] > B3_EPSILON)
|
||||
if (wABC[3] > B3_EPSILON)
|
||||
{
|
||||
m_tu = wABCD[0] / wABCD[4];
|
||||
m_tv = wABCD[1] / wABCD[4];
|
||||
m_tw = wABCD[2] / wABCD[4];
|
||||
m_tx = wABCD[3] / wABCD[4];
|
||||
m_tu = wABC[0] / wABC[3];
|
||||
m_tv = wABC[1] / wABC[3];
|
||||
m_tw = wABC[2] / wABC[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_tu = m_tv = m_tw = m_tx = 0.0f;
|
||||
m_tu = m_tv = m_tw = 0.0f;
|
||||
}
|
||||
|
||||
m_t1 = m_n1->GetType();
|
||||
m_n1->SetType(e_staticSoftBodyNode);
|
||||
|
||||
m_t2 = m_n2->GetType();
|
||||
m_n2->SetType(e_staticSoftBodyNode);
|
||||
|
||||
m_t3 = m_n3->GetType();
|
||||
m_n3->SetType(e_staticSoftBodyNode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -87,38 +91,31 @@ void b3SoftBodyDragger::Drag()
|
||||
|
||||
b3Vec3 dx = B - A;
|
||||
|
||||
const float32 k = 100.0f;
|
||||
|
||||
b3Vec3 f = k * dx;
|
||||
|
||||
b3Vec3 f1 = m_tu * f;
|
||||
b3Vec3 f2 = m_tv * f;
|
||||
b3Vec3 f3 = m_tw * f;
|
||||
b3Vec3 f4 = m_tx * f;
|
||||
|
||||
m_body->GetVertexNode(m_v1)->ApplyForce(f1);
|
||||
m_body->GetVertexNode(m_v2)->ApplyForce(f2);
|
||||
m_body->GetVertexNode(m_v3)->ApplyForce(f3);
|
||||
m_body->GetVertexNode(m_v4)->ApplyForce(f4);
|
||||
m_n1->ApplyTranslation(dx);
|
||||
m_n2->ApplyTranslation(dx);
|
||||
m_n3->ApplyTranslation(dx);
|
||||
}
|
||||
|
||||
void b3SoftBodyDragger::StopDragging()
|
||||
{
|
||||
B3_ASSERT(IsDragging() == true);
|
||||
|
||||
m_tetrahedron = nullptr;
|
||||
m_n1->SetType(m_t1);
|
||||
m_n2->SetType(m_t2);
|
||||
m_n3->SetType(m_t3);
|
||||
|
||||
m_isDragging = false;
|
||||
}
|
||||
|
||||
b3Vec3 b3SoftBodyDragger::GetPointA() const
|
||||
{
|
||||
B3_ASSERT(IsDragging() == true);
|
||||
|
||||
b3Vec3 A = m_body->GetVertexNode(m_v1)->GetPosition();
|
||||
b3Vec3 B = m_body->GetVertexNode(m_v2)->GetPosition();
|
||||
b3Vec3 C = m_body->GetVertexNode(m_v3)->GetPosition();
|
||||
b3Vec3 D = m_body->GetVertexNode(m_v4)->GetPosition();
|
||||
b3Vec3 A = m_n1->GetPosition() + m_n1->GetTranslation();
|
||||
b3Vec3 B = m_n2->GetPosition() + m_n2->GetTranslation();
|
||||
b3Vec3 C = m_n3->GetPosition() + m_n3->GetTranslation();
|
||||
|
||||
return m_tu * A + m_tv * B + m_tw * C + m_tx * D;
|
||||
return m_tu * A + m_tv * B + m_tw * C;
|
||||
}
|
||||
|
||||
b3Vec3 b3SoftBodyDragger::GetPointB() const
|
||||
|
@ -44,18 +44,18 @@ public:
|
||||
b3Vec3 GetPointB() const;
|
||||
private:
|
||||
b3Ray3* m_ray;
|
||||
float32 m_x;
|
||||
|
||||
b3SoftBody* m_body;
|
||||
const b3SoftBodyMesh* m_mesh;
|
||||
const b3SoftBodyMeshTetrahedron* m_tetrahedron;
|
||||
u32 m_v1, m_v2, m_v3, m_v4;
|
||||
float32 m_tu, m_tv, m_tw, m_tx;
|
||||
|
||||
bool m_isDragging;
|
||||
scalar m_x;
|
||||
scalar m_tu, m_tv, m_tw;
|
||||
b3SoftBodyNode * m_n1, * m_n2, * m_n3;
|
||||
b3SoftBodyNodeType m_t1, m_t2, m_t3;
|
||||
};
|
||||
|
||||
inline bool b3SoftBodyDragger::IsDragging() const
|
||||
{
|
||||
return m_tetrahedron != nullptr;
|
||||
return m_isDragging;
|
||||
}
|
||||
|
||||
#endif
|
@ -17,8 +17,10 @@
|
||||
*/
|
||||
|
||||
#include <testbed/framework/test.h>
|
||||
#include <testbed/framework/profiler.h>
|
||||
#include <testbed/framework/profiler_st.h>
|
||||
#include <bounce/common/profiler.h>
|
||||
|
||||
extern b3FrameAllocator* g_frameAllocator;
|
||||
extern b3Profiler* g_profiler;
|
||||
|
||||
extern u32 b3_allocCalls, b3_maxAllocCalls;
|
||||
extern u32 b3_convexCalls, b3_convexCacheHits;
|
||||
@ -28,19 +30,18 @@ extern bool b3_convexCache;
|
||||
void b3BeginProfileScope(const char* name)
|
||||
{
|
||||
g_profiler->BeginScope(name);
|
||||
g_profilerSt->BeginScope(name);
|
||||
}
|
||||
|
||||
void b3EndProfileScope()
|
||||
{
|
||||
g_profiler->EndScope();
|
||||
g_profilerSt->EndScope();
|
||||
}
|
||||
|
||||
Test::Test() :
|
||||
m_bodyDragger(&m_ray, &m_world)
|
||||
{
|
||||
b3Draw_draw = g_draw;
|
||||
b3FrameAllocator_sparseAllocator = g_frameAllocator;
|
||||
b3_convexCache = g_testSettings->convexCache;
|
||||
|
||||
m_world.SetContactListener(this);
|
||||
@ -49,13 +50,16 @@ Test::Test() :
|
||||
m_ray.direction.Set(0.0f, 0.0f, -1.0f);
|
||||
m_ray.fraction = g_camera->m_zFar;
|
||||
|
||||
m_groundHull.Set(50.0f, 1.0f, 50.0f);
|
||||
m_groundHull.SetExtents(50.0f, 1.0f, 50.0f);
|
||||
|
||||
m_groundMesh.BuildTree();
|
||||
m_groundMesh.BuildAdjacency();
|
||||
}
|
||||
|
||||
Test::~Test()
|
||||
{
|
||||
b3Draw_draw = nullptr;
|
||||
b3FrameAllocator_sparseAllocator = nullptr;
|
||||
}
|
||||
|
||||
void Test::Step()
|
||||
@ -63,7 +67,7 @@ void Test::Step()
|
||||
b3_convexCache = g_testSettings->convexCache;
|
||||
|
||||
// Step
|
||||
float32 dt = g_testSettings->inv_hertz;
|
||||
scalar dt = g_testSettings->inv_hertz;
|
||||
|
||||
m_world.SetSleeping(g_testSettings->sleep);
|
||||
m_world.SetWarmStart(g_testSettings->warmStart);
|
||||
@ -97,19 +101,19 @@ void Test::Step()
|
||||
g_draw->DrawString(b3Color_white, "Joints %d", m_world.GetJointList().m_count);
|
||||
g_draw->DrawString(b3Color_white, "Contacts %d", m_world.GetContactList().m_count);
|
||||
|
||||
float32 avgGjkIters = 0.0f;
|
||||
scalar avgGjkIters = 0.0f;
|
||||
if (b3_gjkCalls > 0)
|
||||
{
|
||||
avgGjkIters = float32(b3_gjkIters) / float32(b3_gjkCalls);
|
||||
avgGjkIters = scalar(b3_gjkIters) / scalar(b3_gjkCalls);
|
||||
}
|
||||
|
||||
g_draw->DrawString(b3Color_white, "GJK Calls %d", b3_gjkCalls);
|
||||
g_draw->DrawString(b3Color_white, "GJK Iterations %d (%d) (%f)", b3_gjkIters, b3_gjkMaxIters, avgGjkIters);
|
||||
|
||||
float32 convexCacheHitRatio = 0.0f;
|
||||
scalar convexCacheHitRatio = 0.0f;
|
||||
if (b3_convexCalls > 0)
|
||||
{
|
||||
convexCacheHitRatio = float32(b3_convexCacheHits) / float32(b3_convexCalls);
|
||||
convexCacheHitRatio = scalar(b3_convexCacheHits) / scalar(b3_convexCalls);
|
||||
}
|
||||
|
||||
g_draw->DrawString(b3Color_white, "Convex Calls %d", b3_convexCalls);
|
||||
|
@ -24,15 +24,16 @@
|
||||
|
||||
#include <testbed/framework/body_dragger.h>
|
||||
#include <testbed/framework/cloth_dragger.h>
|
||||
#include <testbed/framework/softbody_dragger.h>
|
||||
|
||||
#include <testbed/framework/draw.h>
|
||||
#include <testbed/framework/view_model.h>
|
||||
|
||||
inline float32 RandomFloat(float32 a, float32 b)
|
||||
inline float RandomFloat(scalar a, scalar b)
|
||||
{
|
||||
float32 x = float32(rand()) / float32(RAND_MAX);
|
||||
float32 diff = b - a;
|
||||
float32 r = x * diff;
|
||||
float x = float(rand()) / float(RAND_MAX);
|
||||
float diff = b - a;
|
||||
float r = x * diff;
|
||||
return a + r;
|
||||
}
|
||||
|
||||
|
@ -20,12 +20,13 @@
|
||||
#include <testbed/tests/convex_hull.h>
|
||||
#include <testbed/tests/cluster.h>
|
||||
#include <testbed/tests/distance_test.h>
|
||||
#include <testbed/tests/shape_cast.h>
|
||||
#include <testbed/tests/linear_time_of_impact.h>
|
||||
#include <testbed/tests/time_of_impact.h>
|
||||
#include <testbed/tests/aabb_time_of_impact.h>
|
||||
#include <testbed/tests/collide_test.h>
|
||||
#include <testbed/tests/capsule_collision.h>
|
||||
#include <testbed/tests/hull_collision.h>
|
||||
#include <testbed/tests/deep_capsule.h>
|
||||
#include <testbed/tests/degenerate_capsule.h>
|
||||
#include <testbed/tests/box_face_contact.h>
|
||||
#include <testbed/tests/box_edge_contact.h>
|
||||
#include <testbed/tests/linear_motion.h>
|
||||
@ -35,14 +36,18 @@
|
||||
#include <testbed/tests/capsule_spin.h>
|
||||
#include <testbed/tests/quadric_shapes.h>
|
||||
#include <testbed/tests/compound_body.h>
|
||||
#include <testbed/tests/spring.h>
|
||||
#include <testbed/tests/spring_test.h>
|
||||
#include <testbed/tests/motor_test.h>
|
||||
#include <testbed/tests/weld_test.h>
|
||||
#include <testbed/tests/cone_test.h>
|
||||
#include <testbed/tests/hinge_motor.h>
|
||||
#include <testbed/tests/revolute_test.h>
|
||||
#include <testbed/tests/prismatic_test.h>
|
||||
#include <testbed/tests/wheel_test.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/triangle_contact_test.h>
|
||||
#include <testbed/tests/hull_contact_test.h>
|
||||
#include <testbed/tests/sphere_stack.h>
|
||||
#include <testbed/tests/capsule_stack.h>
|
||||
@ -53,46 +58,61 @@
|
||||
#include <testbed/tests/pyramid.h>
|
||||
#include <testbed/tests/pyramids.h>
|
||||
#include <testbed/tests/ray_cast.h>
|
||||
#include <testbed/tests/convex_cast.h>
|
||||
#include <testbed/tests/sensor_test.h>
|
||||
#include <testbed/tests/body_types.h>
|
||||
#include <testbed/tests/varying_friction.h>
|
||||
#include <testbed/tests/varying_restitution.h>
|
||||
#include <testbed/tests/tumbler.h>
|
||||
#include <testbed/tests/multiple_pendulum.h>
|
||||
#include <testbed/tests/conveyor_belt.h>
|
||||
#include <testbed/tests/table_cloth.h>
|
||||
#include <testbed/tests/cloth_sdf.h>
|
||||
#include <testbed/tests/pinned_cloth.h>
|
||||
#include <testbed/tests/particle_types.h>
|
||||
#include <testbed/tests/tension_mapping.h>
|
||||
#include <testbed/tests/cloth_self_collision.h>
|
||||
#include <testbed/tests/cape.h>
|
||||
#include <testbed/tests/cloth_tearing.h>
|
||||
#include <testbed/tests/cloth_element_test.h>
|
||||
#include <testbed/tests/rope_test.h>
|
||||
#include <testbed/tests/beam.h>
|
||||
#include <testbed/tests/sheet.h>
|
||||
#include <testbed/tests/node_types.h>
|
||||
#include <testbed/tests/pinned_softbody.h>
|
||||
#include <testbed/tests/softbody_anchor.h>
|
||||
#include <testbed/tests/smash_softbody.h>
|
||||
#include <testbed/tests/tetgen_softbody.h>
|
||||
|
||||
TestEntry g_tests[] =
|
||||
{
|
||||
{ "Convex Hull", &ConvexHull::Create },
|
||||
{ "Cluster", &Cluster::Create },
|
||||
{ "Distance", &Distance::Create },
|
||||
{ "Shape Cast", &ShapeCast::Create },
|
||||
{ "Linear Time of Impact", &LinearTimeOfImpact::Create },
|
||||
{ "Time of Impact", &TimeOfImpact::Create },
|
||||
{ "AABB Time of Impact", &AABBTimeOfImpact::Create },
|
||||
{ "Capsule Collision", &CapsuleCollision::Create },
|
||||
{ "Hull Collision", &HullCollision::Create },
|
||||
{ "Deep Capsule", &DeepCapsule::Create },
|
||||
{ "Degenerate Capsule", &DegenerateCapsule::Create },
|
||||
{ "Box Face Contact", &BoxFaceContact::Create },
|
||||
{ "Box Edge Contact", &BoxEdgeContact::Create },
|
||||
{ "Capsule Spin", &CapsuleSpin::Create },
|
||||
{ "Hull Contact Test", &HullContactTest::Create },
|
||||
{ "Triangle Contact Test", &TriangleContactTest::Create },
|
||||
{ "Mesh Contact Test", &MeshContactTest::Create },
|
||||
{ "Linear Motion", &LinearMotion::Create },
|
||||
{ "Angular Motion", &AngularMotion::Create },
|
||||
{ "Gyroscopic Motion", &GyroMotion::Create },
|
||||
{ "Compound Body", &CompoundBody::Create },
|
||||
{ "Quadric Shapes", &QuadricShapes::Create },
|
||||
{ "Springs", &Spring::Create },
|
||||
{ "Spring Test", &SpringTest::Create },
|
||||
{ "Prismatic Test", &PrismaticTest::Create },
|
||||
{ "Wheel Test", &WheelTest::Create },
|
||||
{ "Weld Test", &WeldTest::Create },
|
||||
{ "Cone Test", &ConeTest::Create },
|
||||
{ "Hinge Motor", &HingeMotor::Create },
|
||||
{ "Motor Test", &MotorTest::Create },
|
||||
{ "Revolute Test", &RevoluteTest::Create },
|
||||
{ "Hinge Chain", &HingeChain::Create },
|
||||
{ "Ragdoll", &Ragdoll::Create },
|
||||
{ "Newton's Cradle", &NewtonCradle::Create },
|
||||
@ -105,6 +125,7 @@ TestEntry g_tests[] =
|
||||
{ "Box Pyramid", &Pyramid::Create },
|
||||
{ "Box Pyramid Rows", &Pyramids::Create },
|
||||
{ "Ray Cast", &RayCast::Create },
|
||||
{ "Convex Cast", &ConvexCast::Create },
|
||||
{ "Sensor Test", &SensorTest::Create },
|
||||
{ "Body Types", &BodyTypes::Create },
|
||||
{ "Varying Friction", &VaryingFriction::Create },
|
||||
@ -112,14 +133,23 @@ TestEntry g_tests[] =
|
||||
{ "Tumbler", &Tumbler::Create },
|
||||
{ "Initial Overlap", &InitialOverlap::Create },
|
||||
{ "Multiple Pendulum", &MultiplePendulum::Create },
|
||||
{ "Conveyor Belt", &ConveyorBelt::Create },
|
||||
{ "Table Cloth", &TableCloth::Create },
|
||||
{ "Cloth SDF", &ClothSDF::Create },
|
||||
{ "Pinned Cloth", &PinnedCloth::Create },
|
||||
{ "Particle Types", &ParticleTypes::Create },
|
||||
{ "Tension Mapping", &TensionMapping::Create },
|
||||
{ "Cloth Self-Collision", &ClothSelfCollision::Create },
|
||||
{ "Cloth Tearing", &ClothTearing::Create },
|
||||
{ "Cloth Element Test", &ClothElementTest::Create },
|
||||
{ "Cape", &Cape::Create },
|
||||
{ "Beam", &Beam::Create },
|
||||
{ "Sheet", &Sheet::Create },
|
||||
{ "Node Types", &NodeTypes::Create },
|
||||
{ "Pinned Soft Body", &PinnedSoftBody::Create },
|
||||
{ "Soft Body Anchor", &SoftBodyAnchor::Create },
|
||||
{ "Smash Soft Body", &SmashSoftBody::Create },
|
||||
{ "TetGen Soft Body", &TetGenSoftBody::Create },
|
||||
{ "Rope", &Rope::Create },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
@ -19,14 +19,18 @@
|
||||
#include <testbed/framework/view.h>
|
||||
#include <testbed/framework/view_model.h>
|
||||
#include <testbed/framework/test.h>
|
||||
#include <testbed/framework/profiler.h>
|
||||
#include <testbed/framework/profiler_st.h>
|
||||
#include <bounce/common/profiler.h>
|
||||
|
||||
extern b3Profiler* g_profiler;
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include <imgui/imgui_impl_glfw.h>
|
||||
|
||||
#if defined (U_OPENGL_2)
|
||||
#include <imgui/imgui_impl_glfw_gl2.h>
|
||||
#include <imgui/imgui_impl_opengl2.h>
|
||||
#elif defined (U_OPENGL_4)
|
||||
#include <imgui/imgui_impl_glfw_gl3.h>
|
||||
#include <imgui/imgui_impl_opengl3.h>
|
||||
#else
|
||||
#endif
|
||||
|
||||
@ -39,16 +43,15 @@ static inline bool GetTestName(void* userData, int idx, const char** name)
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool ImGui_GLFW_GL_Init(GLFWwindow* w, bool install_callbacks)
|
||||
static inline bool ImGui_OpenGL_Init()
|
||||
{
|
||||
|
||||
#if defined(U_OPENGL_2)
|
||||
|
||||
return ImGui_ImplGlfwGL2_Init(w, install_callbacks);
|
||||
return ImGui_ImplOpenGL2_Init();
|
||||
|
||||
#elif defined(U_OPENGL_4)
|
||||
|
||||
return ImGui_ImplGlfwGL3_Init(w, install_callbacks);
|
||||
return ImGui_ImplOpenGL3_Init();
|
||||
|
||||
#else
|
||||
|
||||
@ -56,16 +59,16 @@ static inline bool ImGui_GLFW_GL_Init(GLFWwindow* w, bool install_callbacks)
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void ImGui_GLFW_GL_Shutdown()
|
||||
static inline void ImGui_OpenGL_Shutdown()
|
||||
{
|
||||
|
||||
#if defined(U_OPENGL_2)
|
||||
|
||||
ImGui_ImplGlfwGL2_Shutdown();
|
||||
ImGui_ImplOpenGL2_Shutdown();
|
||||
|
||||
#elif defined(U_OPENGL_4)
|
||||
|
||||
ImGui_ImplGlfwGL3_Shutdown();
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
|
||||
#else
|
||||
|
||||
@ -75,16 +78,16 @@ static inline void ImGui_GLFW_GL_Shutdown()
|
||||
|
||||
}
|
||||
|
||||
static inline void ImGui_GLFW_GL_NewFrame()
|
||||
static inline void ImGui_OpenGL_NewFrame()
|
||||
{
|
||||
|
||||
#if defined(U_OPENGL_2)
|
||||
|
||||
ImGui_ImplGlfwGL2_NewFrame();
|
||||
ImGui_ImplOpenGL2_NewFrame();
|
||||
|
||||
#elif defined(U_OPENGL_4)
|
||||
|
||||
ImGui_ImplGlfwGL3_NewFrame();
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
|
||||
#else
|
||||
|
||||
@ -94,16 +97,16 @@ static inline void ImGui_GLFW_GL_NewFrame()
|
||||
|
||||
}
|
||||
|
||||
static inline void ImGui_GLFW_GL_RenderDrawData(ImDrawData* draw_data)
|
||||
static inline void ImGui_OpenGL_RenderDrawData(ImDrawData* draw_data)
|
||||
{
|
||||
|
||||
#if defined(U_OPENGL_2)
|
||||
|
||||
ImGui_ImplGlfwGL2_RenderDrawData(draw_data);
|
||||
ImGui_ImplOpenGL2_RenderDrawData(draw_data);
|
||||
|
||||
#elif defined(U_OPENGL_4)
|
||||
|
||||
ImGui_ImplGlfwGL3_RenderDrawData(draw_data);
|
||||
ImGui_ImplOpenGL3_RenderDrawData(draw_data);
|
||||
|
||||
#else
|
||||
|
||||
@ -124,9 +127,9 @@ View::View(GLFWwindow* window)
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
io.IniFilename = NULL;
|
||||
io.Fonts[0].AddFontDefault();
|
||||
|
||||
ImGui_GLFW_GL_Init(m_window, false);
|
||||
ImGui_ImplGlfw_InitForOpenGL(m_window, false);
|
||||
ImGui_OpenGL_Init();
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
@ -136,7 +139,8 @@ View::View(GLFWwindow* window)
|
||||
View::~View()
|
||||
{
|
||||
// Destroy UI
|
||||
ImGui_GLFW_GL_Shutdown();
|
||||
ImGui_OpenGL_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
@ -145,7 +149,7 @@ b3Vec2 View::GetCursorPosition() const
|
||||
{
|
||||
double x, y;
|
||||
glfwGetCursorPos(m_window, &x, &y);
|
||||
return b3Vec2(float32(x), float32(y));
|
||||
return b3Vec2(scalar(x), scalar(y));
|
||||
}
|
||||
|
||||
void View::Event_SetWindowSize(int w, int h)
|
||||
@ -186,7 +190,9 @@ void View::Event_Scroll(float dx, float dy)
|
||||
|
||||
void View::BeginInterface()
|
||||
{
|
||||
ImGui_GLFW_GL_NewFrame();
|
||||
ImGui_OpenGL_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
||||
}
|
||||
@ -219,9 +225,8 @@ void View::Interface()
|
||||
|
||||
if (ImGui::BeginMenu("View"))
|
||||
{
|
||||
ImGui::MenuItem("Profile Tree", "", &settings.drawProfileTree);
|
||||
ImGui::MenuItem("Profile Tree Statistics", "", &settings.drawProfileTreeStats);
|
||||
ImGui::MenuItem("Statistics", "", &settings.drawStats);
|
||||
ImGui::MenuItem("Profiler", "", &settings.drawProfiler);
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
@ -403,54 +408,7 @@ void View::Interface()
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
static void TreeNode(ProfilerNode* node, u32& index)
|
||||
{
|
||||
ImGui::PushID(index);
|
||||
++index;
|
||||
|
||||
if (ImGui::TreeNode(node->name))
|
||||
{
|
||||
float64 elapsedTime = node->t1 - node->t0;
|
||||
ImGui::Text("%.4f [ms]", elapsedTime);
|
||||
|
||||
for (u32 i = 0; i < node->children.Count(); ++i)
|
||||
{
|
||||
TreeNode(node->children[i], index);
|
||||
}
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
void View::InterfaceProfileTree()
|
||||
{
|
||||
ImGui::Begin("Overlay", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar);
|
||||
ImVec2 ws = ImGui::GetWindowSize();
|
||||
ImVec2 wp = ImGui::GetWindowPos();
|
||||
ImGui::End();
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
||||
|
||||
ImGui::SetNextWindowBgAlpha(0.0f);
|
||||
ImGui::SetNextWindowPos(ImVec2(0.0f, wp.y + ws.y));
|
||||
ImGui::SetNextWindowSize(ImVec2(g_camera->m_width - 250.0f, 0.0f));
|
||||
|
||||
ImGui::Begin("Profile Tree", NULL, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
|
||||
ProfilerNode* root = g_profiler->GetRoot();
|
||||
if (root)
|
||||
{
|
||||
u32 index = 0;
|
||||
TreeNode(root, index);
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
static void TreeNode(ProfilerStNode* node, u32& index)
|
||||
static void TreeNode(b3ProfilerNode* node, u32& index)
|
||||
{
|
||||
ImGui::PushID(index);
|
||||
++index;
|
||||
@ -459,9 +417,11 @@ static void TreeNode(ProfilerStNode* node, u32& index)
|
||||
{
|
||||
ImGui::Text("%.4f (min = %.4f) (max = %.4f) (calls = %d) [ms]", node->elapsed, node->stat->minElapsed, node->stat->maxElapsed, node->callCount);
|
||||
|
||||
for (u32 i = 0; i < node->children.Count(); ++i)
|
||||
b3ProfilerNode* n = node->head;
|
||||
while(n)
|
||||
{
|
||||
TreeNode(node->children[i], index);
|
||||
TreeNode(n, index);
|
||||
n = n->next;
|
||||
}
|
||||
ImGui::TreePop();
|
||||
}
|
||||
@ -469,7 +429,7 @@ static void TreeNode(ProfilerStNode* node, u32& index)
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
void View::InterfaceProfileTreeStats()
|
||||
void View::InterfaceProfiler()
|
||||
{
|
||||
ImGui::Begin("Overlay", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar);
|
||||
ImVec2 wp = ImGui::GetWindowPos();
|
||||
@ -478,25 +438,15 @@ void View::InterfaceProfileTreeStats()
|
||||
|
||||
wp.y = wp.y + ws.y;
|
||||
|
||||
if (g_settings->drawProfileTree)
|
||||
{
|
||||
ImGui::Begin("Profile Tree", NULL, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
ImVec2 ptwp = ImGui::GetWindowPos();
|
||||
ImVec2 ptws = ImGui::GetWindowSize();
|
||||
ImGui::End();
|
||||
|
||||
wp.y = ptwp.y + ptws.y;
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
||||
|
||||
ImGui::SetNextWindowBgAlpha(0.0f);
|
||||
ImGui::SetNextWindowPos(ImVec2(0.0f, wp.y));
|
||||
ImGui::SetNextWindowSize(ImVec2(g_camera->m_width - 250.0f, 0.0f));
|
||||
|
||||
ImGui::Begin("Profile Tree Statistics", NULL, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
ImGui::Begin("Profiler", NULL, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
|
||||
ProfilerStNode* root = g_profilerSt->GetRoot();
|
||||
b3ProfilerNode* root = g_profiler->GetRoot();
|
||||
if (root)
|
||||
{
|
||||
u32 index = 0;
|
||||
@ -514,5 +464,5 @@ void View::EndInterface()
|
||||
|
||||
ImGui::Render();
|
||||
|
||||
ImGui_GLFW_GL_RenderDrawData(ImGui::GetDrawData());
|
||||
ImGui_OpenGL_RenderDrawData(ImGui::GetDrawData());
|
||||
}
|
@ -41,8 +41,7 @@ public:
|
||||
|
||||
void BeginInterface();
|
||||
void Interface();
|
||||
void InterfaceProfileTree();
|
||||
void InterfaceProfileTreeStats();
|
||||
void InterfaceProfiler();
|
||||
void EndInterface();
|
||||
private:
|
||||
friend class ViewModel;
|
||||
|
@ -84,7 +84,7 @@ void ViewModel::Action_ResetCamera()
|
||||
|
||||
void ViewModel::Event_SetWindowSize(int w, int h)
|
||||
{
|
||||
m_model->Command_ResizeCamera(float32(w), float32(h));
|
||||
m_model->Command_ResizeCamera(scalar(w), scalar(h));
|
||||
}
|
||||
|
||||
void ViewModel::Event_Press_Key(int button)
|
||||
@ -148,8 +148,7 @@ void ViewModel::Event_Move_Cursor(float x, float y)
|
||||
|
||||
b3Vec2 dp = ps - m_view->m_ps0;
|
||||
|
||||
float32 ndx = b3Clamp(dp.x, -1.0f, 1.0f);
|
||||
float32 ndy = b3Clamp(dp.y, -1.0f, 1.0f);
|
||||
b3Vec2 n = b3Normalize(dp);
|
||||
|
||||
bool shiftDown = glfwGetKey(m_view->m_window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS;
|
||||
bool leftDown = glfwGetMouseButton(m_view->m_window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS;
|
||||
@ -159,8 +158,8 @@ void ViewModel::Event_Move_Cursor(float x, float y)
|
||||
{
|
||||
if (leftDown)
|
||||
{
|
||||
float32 ax = -0.005f * B3_PI * ndx;
|
||||
float32 ay = -0.005f * B3_PI * ndy;
|
||||
scalar ax = -0.005f * B3_PI * n.x;
|
||||
scalar ay = -0.005f * B3_PI * n.y;
|
||||
|
||||
m_model->Command_RotateCameraY(ax);
|
||||
m_model->Command_RotateCameraX(ay);
|
||||
@ -168,8 +167,8 @@ void ViewModel::Event_Move_Cursor(float x, float y)
|
||||
|
||||
if (rightDown)
|
||||
{
|
||||
float32 tx = 0.2f * ndx;
|
||||
float32 ty = -0.2f * ndy;
|
||||
scalar tx = 0.2f * n.x;
|
||||
scalar ty = -0.2f * n.y;
|
||||
|
||||
m_model->Command_TranslateCameraX(tx);
|
||||
m_model->Command_TranslateCameraY(ty);
|
||||
@ -177,16 +176,18 @@ void ViewModel::Event_Move_Cursor(float x, float y)
|
||||
}
|
||||
else
|
||||
{
|
||||
m_model->Command_Move_Cursor(m_view->GetCursorPosition());
|
||||
m_model->Command_Move_Cursor(ps);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewModel::Event_Scroll(float dx, float dy)
|
||||
{
|
||||
b3Vec2 n(dx, dy);
|
||||
n.Normalize();
|
||||
|
||||
bool shiftDown = glfwGetKey(m_view->m_window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS;
|
||||
if (shiftDown)
|
||||
{
|
||||
float32 ny = b3Clamp(dy, -1.0f, 1.0f);
|
||||
m_model->Command_ZoomCamera(1.0f * ny);
|
||||
m_model->Command_ZoomCamera(1.0f * n.y);
|
||||
}
|
||||
}
|
||||
|
@ -32,9 +32,8 @@ struct Settings
|
||||
drawLines = true;
|
||||
drawTriangles = true;
|
||||
drawGrid = true;
|
||||
drawProfileTree = false;
|
||||
drawProfileTreeStats = false;
|
||||
drawStats = false;
|
||||
drawProfiler = false;
|
||||
}
|
||||
|
||||
int testID;
|
||||
@ -43,9 +42,8 @@ struct Settings
|
||||
bool drawLines;
|
||||
bool drawTriangles;
|
||||
bool drawGrid;
|
||||
bool drawProfileTree;
|
||||
bool drawProfileTreeStats;
|
||||
bool drawStats;
|
||||
bool drawProfiler;
|
||||
};
|
||||
|
||||
//
|
||||
|
Reference in New Issue
Block a user