Merge changes from The Witness.
This commit is contained in:
@ -77,6 +77,9 @@ namespace nv
|
||||
Vector4 row(uint i) const;
|
||||
Vector4 column(uint i) const;
|
||||
|
||||
void zero();
|
||||
void identity();
|
||||
|
||||
void scale(float s);
|
||||
void scale(Vector3::Arg s);
|
||||
void translate(Vector3::Arg t);
|
||||
|
@ -323,6 +323,22 @@ namespace nv
|
||||
return Vector4(get(0, i), get(1, i), get(2, i), get(3, i));
|
||||
}
|
||||
|
||||
inline void Matrix::zero()
|
||||
{
|
||||
m_data[0] = 0; m_data[1] = 0; m_data[2] = 0; m_data[3] = 0;
|
||||
m_data[4] = 0; m_data[5] = 0; m_data[6] = 0; m_data[7] = 0;
|
||||
m_data[8] = 0; m_data[9] = 0; m_data[10] = 0; m_data[11] = 0;
|
||||
m_data[12] = 0; m_data[13] = 0; m_data[14] = 0; m_data[15] = 0;
|
||||
}
|
||||
|
||||
inline void Matrix::identity()
|
||||
{
|
||||
m_data[0] = 1; m_data[1] = 0; m_data[2] = 0; m_data[3] = 0;
|
||||
m_data[4] = 0; m_data[5] = 1; m_data[6] = 0; m_data[7] = 0;
|
||||
m_data[8] = 0; m_data[9] = 0; m_data[10] = 1; m_data[11] = 0;
|
||||
m_data[12] = 0; m_data[13] = 0; m_data[14] = 0; m_data[15] = 1;
|
||||
}
|
||||
|
||||
// Apply scale.
|
||||
inline void Matrix::scale(float s)
|
||||
{
|
||||
|
@ -446,8 +446,18 @@ namespace nv
|
||||
}
|
||||
inline float triangleArea(Vector2::Arg a, Vector2::Arg b, Vector2::Arg c)
|
||||
{
|
||||
return (c.x * a.y + a.x * b.y + b.x * c.y - b.x * a.y - c.x * b.y - a.x * c.y); // * 0.5f;
|
||||
//return triangleArea(a-c, b-c);
|
||||
// IC: While it may be appealing to use the following expression:
|
||||
//return (c.x * a.y + a.x * b.y + b.x * c.y - b.x * a.y - c.x * b.y - a.x * c.y); // * 0.5f;
|
||||
|
||||
// That's actually a terrible idea. Small triangles far from the origin can end up producing fairly large floating point
|
||||
// numbers and the results becomes very unstable and dependent on the order of the factors.
|
||||
|
||||
// Instead, it's preferable to substract the vertices first, and multiply the resulting small values together. The result
|
||||
// in this case is always much more accurate (as long as the triangle is small) and less dependent of the location of
|
||||
// the triangle.
|
||||
|
||||
//return ((a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x)); // * 0.5f;
|
||||
return triangleArea(a-c, b-c);
|
||||
}
|
||||
|
||||
|
||||
|
@ -255,9 +255,10 @@ namespace nv
|
||||
|
||||
inline int sign(float a)
|
||||
{
|
||||
if (a > 0.0f) return 1;
|
||||
if (a < 0.0f) return -1;
|
||||
return 0;
|
||||
return (a > 0) - (a < 0);
|
||||
//if (a > 0.0f) return 1;
|
||||
//if (a < 0.0f) return -1;
|
||||
//return 0;
|
||||
}
|
||||
|
||||
union Float754 {
|
||||
|
Reference in New Issue
Block a user