draw, camera, test
Remove an unecessary function that draws a triangle using per-vertex coloring Cut camera implementation and paste into draw.cpp Use per-triangle tension mapping
This commit is contained in:
@ -52,17 +52,7 @@ inline b3Vec3 Ray3::B() const
|
||||
class Camera
|
||||
{
|
||||
public:
|
||||
Camera()
|
||||
{
|
||||
m_center.SetZero();
|
||||
m_q.SetIdentity();
|
||||
m_width = 1024.0f;
|
||||
m_height = 768.0f;
|
||||
m_zNear = 1.0f;
|
||||
m_zFar = 1000.0f;
|
||||
m_fovy = 0.25f * B3_PI;
|
||||
m_zoom = 10.0f;
|
||||
}
|
||||
Camera();
|
||||
|
||||
b3Mat44 BuildProjectionMatrix() const;
|
||||
b3Mat44 BuildViewMatrix() const;
|
||||
@ -91,82 +81,6 @@ inline b3Mat44 MakeMat44(const b3Transform& T)
|
||||
b3Vec4(T.position.x, T.position.y, T.position.z, 1.0f));
|
||||
}
|
||||
|
||||
inline b3Mat44 Camera::BuildProjectionMatrix() const
|
||||
{
|
||||
float32 t = tan(0.5f * m_fovy);
|
||||
float32 sy = 1.0f / t;
|
||||
|
||||
float32 aspect = m_width / m_height;
|
||||
float32 sx = 1.0f / (aspect * t);
|
||||
|
||||
float32 invRange = 1.0f / (m_zNear - m_zFar);
|
||||
float32 sz = invRange * (m_zNear + m_zFar);
|
||||
float32 tz = invRange * m_zNear * m_zFar;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
inline b3Transform Camera::BuildWorldTransform() const
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.rotation = b3QuatMat33(m_q);
|
||||
xf.position = (m_zoom * xf.rotation.z) - m_center;
|
||||
return xf;
|
||||
}
|
||||
|
||||
inline b3Mat44 Camera::BuildWorldMatrix() const
|
||||
{
|
||||
b3Transform xf = BuildWorldTransform();
|
||||
return MakeMat44(xf);
|
||||
}
|
||||
|
||||
inline b3Transform Camera::BuildViewTransform() const
|
||||
{
|
||||
b3Transform xf;
|
||||
xf.rotation = b3QuatMat33(m_q);
|
||||
xf.position = (m_zoom * xf.rotation.z) - m_center;
|
||||
return b3Inverse(xf);
|
||||
}
|
||||
|
||||
inline b3Mat44 Camera::BuildViewMatrix() const
|
||||
{
|
||||
b3Transform xf = BuildViewTransform();
|
||||
return MakeMat44(xf);
|
||||
}
|
||||
|
||||
inline b3Vec2 Camera::ConvertWorldToScreen(const b3Vec3& pw) const
|
||||
{
|
||||
b3Vec2 ps;
|
||||
ps.SetZero();
|
||||
return ps;
|
||||
}
|
||||
|
||||
inline Ray3 Camera::ConvertScreenToWorld(const b3Vec2& ps) const
|
||||
{
|
||||
// Essential Math, page 250.
|
||||
float32 t = tan(0.5f * m_fovy);
|
||||
float32 aspect = m_width / m_height;
|
||||
|
||||
b3Vec3 pv;
|
||||
pv.x = 2.0f * aspect * ps.x / m_width - aspect;
|
||||
pv.y = -2.0f * ps.y / m_height + 1.0f;
|
||||
pv.z = -1.0f / t;
|
||||
|
||||
b3Transform xf = BuildWorldTransform();
|
||||
b3Vec3 pw = xf * pv;
|
||||
|
||||
Ray3 rw;
|
||||
rw.direction = b3Normalize(pw - xf.position);
|
||||
rw.origin = xf.position;
|
||||
rw.fraction = m_zFar;
|
||||
return rw;
|
||||
}
|
||||
|
||||
//
|
||||
enum DrawFlags
|
||||
{
|
||||
@ -189,8 +103,6 @@ public:
|
||||
|
||||
void DrawSolidTriangle(const b3Vec3& normal, const b3Vec3& p1, const b3Vec3& p2, const b3Vec3& p3, const b3Color& color);
|
||||
|
||||
void DrawSolidTriangle(const b3Vec3& normal, const b3Vec3& p1, const b3Color& color1, const b3Vec3& p2, const b3Color& color2, const b3Vec3& p3, const b3Color& color3);
|
||||
|
||||
void DrawPolygon(const b3Vec3* vertices, u32 count, const b3Color& color);
|
||||
|
||||
void DrawSolidPolygon(const b3Vec3& normal, const b3Vec3* vertices, u32 count, const b3Color& color);
|
||||
@ -210,9 +122,13 @@ public:
|
||||
void DrawAABB(const b3AABB3& aabb, const b3Color& color);
|
||||
|
||||
void DrawTransform(const b3Transform& xf);
|
||||
|
||||
void DrawString(const b3Color& color, const b3Vec2& ps, const char* string, ...);
|
||||
|
||||
void DrawString(const b3Color& color, const b3Vec3& pw, const char* string, ...);
|
||||
|
||||
void DrawString(const b3Color& color, const char* string, ...);
|
||||
|
||||
|
||||
void DrawSolidSphere(const b3SphereShape* s, const b3Color& c, const b3Transform& xf);
|
||||
|
||||
void DrawSolidCapsule(const b3CapsuleShape* s, const b3Color& c, const b3Transform& xf);
|
||||
|
Reference in New Issue
Block a user