Browse Source

math: remove some vector constants that were a bit too specific.

undefined
Sam Hocevar 10 years ago
parent
commit
76740f77bc
9 changed files with 49 additions and 193 deletions
  1. +1
    -1
      src/easymesh/easymesh-parser.y
  2. +1
    -1
      src/generated/easymesh-parser.cpp
  3. +1
    -0
      src/gpu/indexbuffer.cpp
  4. +8
    -8
      src/lol/algorithm/aabb_tree.h
  5. +16
    -16
      src/lol/algorithm/portal.h
  6. +0
    -77
      src/lol/math/vector.h
  7. +0
    -68
      src/math/constants.cpp
  8. +2
    -2
      test/meshviewer.cpp
  9. +20
    -20
      tools/lolremez/solver.cpp

+ 1
- 1
src/easymesh/easymesh-parser.y View File

@@ -133,7 +133,7 @@ doloop:
; ;


pre_brace_command: pre_brace_command:
T_DUPLICATE { mc.m_mesh.DupAndScale(vec3::one, true); }
T_DUPLICATE { mc.m_mesh.DupAndScale(vec3(1.f), true); }
; ;


mesh_open: mesh_open:


+ 1
- 1
src/generated/easymesh-parser.cpp View File

@@ -490,7 +490,7 @@ namespace lol {


/* Line 677 of lalr1.cc */ /* Line 677 of lalr1.cc */
#line 136 "easymesh/easymesh-parser.y" #line 136 "easymesh/easymesh-parser.y"
{ mc.m_mesh.DupAndScale(vec3::one, true); }
{ mc.m_mesh.DupAndScale(vec3(1.f), true); }
break; break;


case 22: case 22:


+ 1
- 0
src/gpu/indexbuffer.cpp View File

@@ -107,6 +107,7 @@ void *IndexBuffer::Lock(size_t offset, size_t size)
Abort(); Abort();
return ret; return ret;
#else #else
UNUSED(size);
return m_data->m_memory + offset; return m_data->m_memory + offset;
#endif #endif
} }


+ 8
- 8
src/lol/algorithm/aabb_tree.h View File

@@ -32,7 +32,7 @@ void DrawInner(TREE *tree, Array<TBB, vec4> &boxes,
Array<TE *, int, vec4> &elements, Array<TE *, int, vec4> &elements,
Array<int, TBB> &leaves, int children, vec4 color) Array<int, TBB> &leaves, int children, vec4 color)
{ {
boxes.Push(tree->GetAABB(), vec4::one);
boxes.Push(tree->GetAABB(), vec4(1.f));
leaves.Push(0, boxes.Last().m1); leaves.Push(0, boxes.Last().m1);
while (leaves.Count() > 0) while (leaves.Count() > 0)
{ {
@@ -49,7 +49,7 @@ void DrawInner(TREE *tree, Array<TBB, vec4> &boxes,
} }
} }
if (!done) if (!done)
elements.Push(tree->GetElements()[tree->GetTree()[leaves[0].m1].m_elements[j]].m_element, 1, vec4::v1001);
elements.Push(tree->GetElements()[tree->GetTree()[leaves[0].m1].m_elements[j]].m_element, 1, vec4(1, 0, 0, 1));
} }


for (int i = 0; i < children; i++) for (int i = 0; i < children; i++)
@@ -75,8 +75,8 @@ void Draw(Quadtree<TE>* tree, vec4 color)


DrawInner<Quadtree<TE>, TE, box2>(tree, boxes, elements, leaves, 4, color); DrawInner<Quadtree<TE>, TE, box2>(tree, boxes, elements, leaves, 4, color);


vec3 off = vec3::v010 * .1f;
vec3 add = vec3::v010 * .1f;
vec3 off = vec3(0.0f, 0.1f, 0.0f);
//vec3 add = vec3(0.0f, 0.1f, 0.0f);
while (boxes.Count() > 0) while (boxes.Count() > 0)
{ {
Debug::DrawBox(vec3(boxes[0].m1.A.x, tree->m_debug_y_offset, boxes[0].m1.A.y), Debug::DrawBox(vec3(boxes[0].m1.A.x, tree->m_debug_y_offset, boxes[0].m1.A.y),
@@ -106,11 +106,11 @@ void Draw(Octree<TE>* tree, vec4 color)


DrawInner<Octree<TE>, TE, box3>(tree, boxes, elements, leaves, 8, color); DrawInner<Octree<TE>, TE, box3>(tree, boxes, elements, leaves, 8, color);


vec3 off = vec3::v010 * .1f;
vec3 add = vec3::v010 * .1f;
vec3 off = vec3(0.0f, 0.1f, 0.0f);
//vec3 add = vec3(0.0f, 0.1f, 0.0f);
while (boxes.Count() > 0) while (boxes.Count() > 0)
{ {
float size = boxes[0].m1.B.x - boxes[0].m1.A.x;
//float size = boxes[0].m1.B.x - boxes[0].m1.A.x;
Debug::DrawBox(vec3(boxes[0].m1.A.x, boxes[0].m1.A.y, boxes[0].m1.A.z) /* + off * (m_size.x / size) */, Debug::DrawBox(vec3(boxes[0].m1.A.x, boxes[0].m1.A.y, boxes[0].m1.A.z) /* + off * (m_size.x / size) */,
vec3(boxes[0].m1.B.x, boxes[0].m1.B.y, boxes[0].m1.B.z) /* + off * (m_size.x / size) */, vec3(boxes[0].m1.B.x, boxes[0].m1.B.y, boxes[0].m1.B.z) /* + off * (m_size.x / size) */,
boxes[0].m2); boxes[0].m2);
@@ -328,7 +328,7 @@ public:
TV v(GetSubOffset(sub)); TV v(GetSubOffset(sub));
TV half_vec = (bbox.B - bbox.A) * .5f; TV half_vec = (bbox.B - bbox.A) * .5f;
return TB(bbox.A + half_vec * v, return TB(bbox.A + half_vec * v,
bbox.A + half_vec * (v + TV::one));
bbox.A + half_vec * (v + TV(1.f)));
} }


//-- //--


+ 16
- 16
src/lol/algorithm/portal.h View File

@@ -32,11 +32,11 @@ void Draw(PortalDoor<TE>& port, vec4 color)
{ {
vec3 points[4]; port.GetPoints(points); vec3 points[4]; port.GetPoints(points);


//Draw normal
// Draw normal
vec3 p = port.m_center + port.m_up * port.m_size.y * .5f; vec3 p = port.m_center + port.m_up * port.m_size.y * .5f;
Debug::DrawLine(p, p + port.m_normal, vec4::v1001);
Debug::DrawLine(p, p + port.m_up, vec4::v0101);
//draw door
Debug::DrawLine(p, p + port.m_normal, vec4(1, 0, 0, 1));
Debug::DrawLine(p, p + port.m_up, vec4(0, 1, 0, 1));
// Draw door
for (int l = 0; l < 4; l++) for (int l = 0; l < 4; l++)
Debug::DrawLine(points[l], points[(l + 1) % 4], color); Debug::DrawLine(points[l], points[(l + 1) % 4], color);
Debug::DrawLine(points[0], points[2], color); Debug::DrawLine(points[0], points[2], color);
@@ -135,11 +135,11 @@ public:
mat4 cam_mx = proj * view; mat4 cam_mx = proj * view;
mat4 inv_proj_mx = inverse(proj); mat4 inv_proj_mx = inverse(proj);


//First: Check normal dot
if (lol::abs(dot((inverse(view) * vec4::v0010).xyz, m_normal)) < .00001f)
// First: Check normal dot
if (lol::abs(dot(mat3(inverse(view)) * vec3(0.f, 0.f, 1.f), m_normal)) < .00001f)
return false; return false;


//Second: convert in screen
// Second: convert to screen coordinates
vec3 port_2d[2] = { vec3(FLT_MAX), vec3(-FLT_MAX) }; vec3 port_2d[2] = { vec3(FLT_MAX), vec3(-FLT_MAX) };
vec3 door_points[4]; vec3 door_points[4];
vec4 proj_p[4]; vec4 proj_p[4];
@@ -155,8 +155,8 @@ public:
//Clamp points within screen //Clamp points within screen
port_2d[0] = lol::min(proj_p[i].xyz, port_2d[0]); port_2d[0] = lol::min(proj_p[i].xyz, port_2d[0]);
port_2d[1] = lol::max(proj_p[i].xyz, port_2d[1]); port_2d[1] = lol::max(proj_p[i].xyz, port_2d[1]);
port_2d[0] = vec3(lol::clamp(port_2d[0].xy, vec2::onen, vec2::one), port_2d[0].z);
port_2d[1] = vec3(lol::clamp(port_2d[1].xy, vec2::onen, vec2::one), port_2d[1].z);
port_2d[0] = vec3(lol::clamp(port_2d[0].xy, vec2(-1.f), vec2(1.f)), port_2d[0].z);
port_2d[1] = vec3(lol::clamp(port_2d[1].xy, vec2(-1.f), vec2(1.f)), port_2d[1].z);
} }


//Quit if door not within the screen //Quit if door not within the screen
@@ -165,8 +165,8 @@ public:
return false; return false;


//Third: Convert back to view //Third: Convert back to view
ivec2 j[4] = { ivec2::v00, ivec2::v01, ivec2::v11, ivec2::v10 };
vec3 frust[2] = { vec3::one * FLT_MAX, vec3::one * -FLT_MAX };
ivec2 j[4] = { ivec2(0), ivec2(0, 1), ivec2(1), ivec2(1, 0) };
vec3 frust[2] = { vec3(FLT_MAX), vec3(-FLT_MAX) };
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
int k = i % 4; int k = i % 4;
@@ -219,7 +219,7 @@ public:
return true; return true;


//Add points on test stuff //Add points on test stuff
pos_test += ivec3(lol::clamp(res_points[i], vec3::onen * 1.1f, vec3::one * 1.1f));
pos_test += ivec3(lol::clamp(res_points[i], vec3(-1.1f), vec3(1.1f)));
} }


return false; return false;
@@ -308,17 +308,17 @@ public:
for (int i = 0; i < visible_rooms[j]->m_doors.Count(); i++) for (int i = 0; i < visible_rooms[j]->m_doors.Count(); i++)
{ {
PortalDoor<TE>* port = visible_rooms[j]->m_doors[i]; PortalDoor<TE>* port = visible_rooms[j]->m_doors[i];
Debug::Draw(*port, vec4::v0111);
Debug::Draw(*port, vec4(0, 1, 1, 1));
tmp += vec4(port->m_center, 1.f); tmp += vec4(port->m_center, 1.f);
} }
tmp /= tmp.w; tmp /= tmp.w;
Debug::DrawBox(tmp.xyz-vec3::one,tmp.xyz+vec3::one,vec4::v1101);
Debug::DrawBox(tmp.xyz - vec3(1.f), tmp.xyz + vec3(1.f), vec4(1, 1, 0, 1));
} }
for (int i = 0; i < ignore_doors.Count(); i++) for (int i = 0; i < ignore_doors.Count(); i++)
{ {
PortalDoor<TE>* port = ignore_doors[i]; PortalDoor<TE>* port = ignore_doors[i];
Debug::Draw(*port, vec4::v1011);
Debug::DrawViewProj(port->m_view, port->m_proj, vec4::v1011);
Debug::Draw(*port, vec4(1, 0, 1, 1));
Debug::DrawViewProj(port->m_view, port->m_proj, vec4(1, 0, 1, 1));
} }
#endif //LOL_BUILD_DEBUG #endif //LOL_BUILD_DEBUG
} }


+ 0
- 77
src/lol/math/vector.h View File

@@ -251,23 +251,9 @@ template <typename T> struct Vec2 : BVec2<T>


LOL_MEMBER_OPS(Vec2, x) LOL_MEMBER_OPS(Vec2, x)


//Constants: n post-fix is negative values
static const Vec2<T> onen;
static const Vec2<T> one;
static const Vec2<T> zero; static const Vec2<T> zero;
static const Vec2<T> axis_x; static const Vec2<T> axis_x;
static const Vec2<T> axis_y; static const Vec2<T> axis_y;
static const Vec2<T> axis_xn;
static const Vec2<T> axis_yn;
//Pos values
static const Vec2<T> v11;
static const Vec2<T> v00;
static const Vec2<T> v01;
static const Vec2<T> v10;
//Neg values
static const Vec2<T> v00n;
static const Vec2<T> v01n;
static const Vec2<T> v10n;


template<typename U> template<typename U>
friend std::ostream &operator<<(std::ostream &stream, Vec2<U> const &v); friend std::ostream &operator<<(std::ostream &stream, Vec2<U> const &v);
@@ -538,33 +524,10 @@ template <typename T> struct Vec3 : BVec3<T>


LOL_MEMBER_OPS(Vec3, x) LOL_MEMBER_OPS(Vec3, x)


//Constants: n post-fix is negative values
static const Vec3<T> onen;
static const Vec3<T> one;
static const Vec3<T> zero; static const Vec3<T> zero;
static const Vec3<T> axis_x; static const Vec3<T> axis_x;
static const Vec3<T> axis_y; static const Vec3<T> axis_y;
static const Vec3<T> axis_z; static const Vec3<T> axis_z;
static const Vec3<T> axis_xn;
static const Vec3<T> axis_yn;
static const Vec3<T> axis_zn;
//Pos values
static const Vec3<T> v111;
static const Vec3<T> v000;
static const Vec3<T> v100;
static const Vec3<T> v010;
static const Vec3<T> v001;
static const Vec3<T> v110;
static const Vec3<T> v101;
static const Vec3<T> v011;
//Neg values
static const Vec3<T> v000n;
static const Vec3<T> v100n;
static const Vec3<T> v010n;
static const Vec3<T> v001n;
static const Vec3<T> v110n;
static const Vec3<T> v101n;
static const Vec3<T> v011n;


template<typename U> template<typename U>
friend std::ostream &operator<<(std::ostream &stream, Vec3<U> const &v); friend std::ostream &operator<<(std::ostream &stream, Vec3<U> const &v);
@@ -983,51 +946,11 @@ template <typename T> struct Vec4 : BVec4<T>


LOL_MEMBER_OPS(Vec4, x) LOL_MEMBER_OPS(Vec4, x)


//Constants: n post-fix is negative values
static const Vec4<T> onen;
static const Vec4<T> one;
static const Vec4<T> zero; static const Vec4<T> zero;
static const Vec4<T> axis_x; static const Vec4<T> axis_x;
static const Vec4<T> axis_y; static const Vec4<T> axis_y;
static const Vec4<T> axis_z; static const Vec4<T> axis_z;
static const Vec4<T> axis_w; static const Vec4<T> axis_w;
static const Vec4<T> axis_xn;
static const Vec4<T> axis_yn;
static const Vec4<T> axis_zn;
static const Vec4<T> axis_wn;
//Pos values
static const Vec4<T> v1111; //( 1, 1, 1, 1)
static const Vec4<T> v0000; //( 0, 0, 0, 0)
static const Vec4<T> v1000; //( 1, 0, 0, 0)
static const Vec4<T> v0100; //( 0, 1, 0, 0)
static const Vec4<T> v0010; //( 0, 0, 1, 0)
static const Vec4<T> v0001; //( 0, 0, 0, 1)
static const Vec4<T> v1100; //( 1, 1, 0, 0)
static const Vec4<T> v0110; //( 0, 1, 1, 0)
static const Vec4<T> v0011; //( 0, 0, 1, 1)
static const Vec4<T> v1010; //( 1, 0, 1, 0)
static const Vec4<T> v0101; //( 0, 1, 0, 1)
static const Vec4<T> v1001; //( 1, 0, 0, 1)
static const Vec4<T> v0111; //( 0, 1, 1, 1)
static const Vec4<T> v1011; //( 1, 0, 1, 1)
static const Vec4<T> v1101; //( 1, 1, 0, 1)
static const Vec4<T> v1110; //( 1, 1, 1, 0)
//Neg values
static const Vec4<T> v0000n;//(-1,-1,-1,-1)
static const Vec4<T> v1000n;//( 1,-1,-1,-1)
static const Vec4<T> v0100n;//(-1, 1,-1,-1)
static const Vec4<T> v0010n;//(-1,-1, 1,-1)
static const Vec4<T> v0001n;//(-1,-1,-1, 1)
static const Vec4<T> v1100n;//( 1, 1,-1,-1)
static const Vec4<T> v0110n;//(-1, 1, 1,-1)
static const Vec4<T> v0011n;//(-1,-1, 1, 1)
static const Vec4<T> v1010n;//( 1,-1, 1,-1)
static const Vec4<T> v0101n;//(-1, 1,-1, 1)
static const Vec4<T> v1001n;//( 1,-1,-1, 1)
static const Vec4<T> v0111n;//(-1, 1, 1, 1)
static const Vec4<T> v1011n;//( 1,-1, 1, 1)
static const Vec4<T> v1101n;//( 1, 1,-1, 1)
static const Vec4<T> v1110n;//( 1, 1, 1,-1)


template<typename U> template<typename U>
friend std::ostream &operator<<(std::ostream &stream, Vec4<U> const &v); friend std::ostream &operator<<(std::ostream &stream, Vec4<U> const &v);


+ 0
- 68
src/math/constants.cpp View File

@@ -39,88 +39,20 @@ namespace lol {
Mat4<type> const Mat4<type>::name = Mat4<type>((type)a); Mat4<type> const Mat4<type>::name = Mat4<type>((type)a);


#define LOL_ALL_CONST_INNER(type) \ #define LOL_ALL_CONST_INNER(type) \
LOL_VEC_2_CONST(type, one, 1, 1) \
LOL_VEC_2_CONST(type, onen, -1,-1) \
LOL_VEC_2_CONST(type, zero, 0, 0) \ LOL_VEC_2_CONST(type, zero, 0, 0) \
LOL_VEC_2_CONST(type, axis_x, 1, 0) \ LOL_VEC_2_CONST(type, axis_x, 1, 0) \
LOL_VEC_2_CONST(type, axis_y, 0, 1) \ LOL_VEC_2_CONST(type, axis_y, 0, 1) \
LOL_VEC_2_CONST(type, axis_xn, 1,-1) \
LOL_VEC_2_CONST(type, axis_yn, -1, 1) \
LOL_VEC_2_CONST(type, v11, 1, 1) \
LOL_VEC_2_CONST(type, v00, 0, 0) \
LOL_VEC_2_CONST(type, v01, 0, 1) \
LOL_VEC_2_CONST(type, v10, 1, 0) \
LOL_VEC_2_CONST(type, v00n, -1,-1) \
LOL_VEC_2_CONST(type, v01n, -1, 1) \
LOL_VEC_2_CONST(type, v10n, 1,-1) \
\ \
LOL_VEC_3_CONST(type, one, 1, 1, 1) \
LOL_VEC_3_CONST(type, onen, -1,-1,-1) \
LOL_VEC_3_CONST(type, zero, 0, 0, 0) \ LOL_VEC_3_CONST(type, zero, 0, 0, 0) \
LOL_VEC_3_CONST(type, axis_x, 1, 0, 0) \ LOL_VEC_3_CONST(type, axis_x, 1, 0, 0) \
LOL_VEC_3_CONST(type, axis_y, 0, 1, 0) \ LOL_VEC_3_CONST(type, axis_y, 0, 1, 0) \
LOL_VEC_3_CONST(type, axis_z, 0, 0, 1) \ LOL_VEC_3_CONST(type, axis_z, 0, 0, 1) \
LOL_VEC_3_CONST(type, axis_xn, -1, 0, 0) \
LOL_VEC_3_CONST(type, axis_yn, 0,-1, 0) \
LOL_VEC_3_CONST(type, axis_zn, 0, 0,-1) \
LOL_VEC_3_CONST(type, v111, 1, 1, 1) \
LOL_VEC_3_CONST(type, v000, 0, 0, 0) \
LOL_VEC_3_CONST(type, v100, 1, 0, 0) \
LOL_VEC_3_CONST(type, v010, 0, 1, 0) \
LOL_VEC_3_CONST(type, v001, 0, 0, 1) \
LOL_VEC_3_CONST(type, v110, 1, 1, 0) \
LOL_VEC_3_CONST(type, v101, 1, 0, 1) \
LOL_VEC_3_CONST(type, v011, 0, 1, 1) \
LOL_VEC_3_CONST(type, v000n, -1,-1,-1) \
LOL_VEC_3_CONST(type, v100n, 1,-1,-1) \
LOL_VEC_3_CONST(type, v010n, -1, 1,-1) \
LOL_VEC_3_CONST(type, v001n, -1,-1, 1) \
LOL_VEC_3_CONST(type, v110n, 1, 1,-1) \
LOL_VEC_3_CONST(type, v101n, 1,-1, 1) \
LOL_VEC_3_CONST(type, v011n, -1, 1, 1) \
\ \
LOL_VEC_4_CONST(type, one, 1, 1, 1, 1) \
LOL_VEC_4_CONST(type, onen, -1,-1,-1,-1) \
LOL_VEC_4_CONST(type, zero, 0, 0, 0, 0) \ LOL_VEC_4_CONST(type, zero, 0, 0, 0, 0) \
LOL_VEC_4_CONST(type, axis_x, 1, 0, 0, 0) \ LOL_VEC_4_CONST(type, axis_x, 1, 0, 0, 0) \
LOL_VEC_4_CONST(type, axis_y, 0, 1, 0, 0) \ LOL_VEC_4_CONST(type, axis_y, 0, 1, 0, 0) \
LOL_VEC_4_CONST(type, axis_z, 0, 0, 1, 0) \ LOL_VEC_4_CONST(type, axis_z, 0, 0, 1, 0) \
LOL_VEC_4_CONST(type, axis_w, 0, 0, 0, 1) \ LOL_VEC_4_CONST(type, axis_w, 0, 0, 0, 1) \
LOL_VEC_4_CONST(type, axis_xn, -1, 0, 0, 0) \
LOL_VEC_4_CONST(type, axis_yn, 0,-1, 0, 0) \
LOL_VEC_4_CONST(type, axis_zn, 0, 0,-1, 0) \
LOL_VEC_4_CONST(type, axis_wn, 0, 0, 0,-1) \
LOL_VEC_4_CONST(type, v1111, 1, 1, 1, 1) \
LOL_VEC_4_CONST(type, v0000, 0, 0, 0, 0) \
LOL_VEC_4_CONST(type, v1000, 1, 0, 0, 0) \
LOL_VEC_4_CONST(type, v0100, 0, 1, 0, 0) \
LOL_VEC_4_CONST(type, v0010, 0, 0, 1, 0) \
LOL_VEC_4_CONST(type, v0001, 0, 0, 0, 1) \
LOL_VEC_4_CONST(type, v1100, 1, 1, 0, 0) \
LOL_VEC_4_CONST(type, v0110, 0, 1, 1, 0) \
LOL_VEC_4_CONST(type, v0011, 0, 0, 1, 1) \
LOL_VEC_4_CONST(type, v1010, 1, 0, 1, 0) \
LOL_VEC_4_CONST(type, v0101, 0, 1, 0, 1) \
LOL_VEC_4_CONST(type, v1001, 1, 0, 0, 1) \
LOL_VEC_4_CONST(type, v0111, 0, 1, 1, 1) \
LOL_VEC_4_CONST(type, v1011, 1, 0, 1, 1) \
LOL_VEC_4_CONST(type, v1101, 1, 1, 0, 1) \
LOL_VEC_4_CONST(type, v1110, 1, 1, 1, 0) \
LOL_VEC_4_CONST(type, v0000n, -1,-1,-1,-1) \
LOL_VEC_4_CONST(type, v1000n, 1,-1,-1,-1) \
LOL_VEC_4_CONST(type, v0100n, -1, 1,-1,-1) \
LOL_VEC_4_CONST(type, v0010n, -1,-1, 1,-1) \
LOL_VEC_4_CONST(type, v0001n, -1,-1,-1, 1) \
LOL_VEC_4_CONST(type, v1100n, 1, 1,-1,-1) \
LOL_VEC_4_CONST(type, v0110n, -1, 1, 1,-1) \
LOL_VEC_4_CONST(type, v0011n, -1,-1, 1, 1) \
LOL_VEC_4_CONST(type, v1010n, 1,-1, 1,-1) \
LOL_VEC_4_CONST(type, v0101n, -1, 1,-1, 1) \
LOL_VEC_4_CONST(type, v1001n, 1,-1,-1, 1) \
LOL_VEC_4_CONST(type, v0111n, -1, 1, 1, 1) \
LOL_VEC_4_CONST(type, v1011n, 1,-1, 1, 1) \
LOL_VEC_4_CONST(type, v1101n, 1, 1,-1, 1) \
LOL_VEC_4_CONST(type, v1110n, 1, 1, 1,-1) \
\ \
LOL_MAT_CONST(type, identity, 1) LOL_MAT_CONST(type, identity, 1)




+ 2
- 2
test/meshviewer.cpp View File

@@ -495,13 +495,13 @@ public:
if (m_meshes.Count() && m_mesh_id >= 0) if (m_meshes.Count() && m_mesh_id >= 0)
for (int i = 0; i < m_meshes[m_mesh_id].m1->GetVertexCount(); i++) for (int i = 0; i < m_meshes[m_mesh_id].m1->GetVertexCount(); i++)
tc.AddTarget((m_mat * mat4::translate(m_meshes[m_mesh_id].m1->GetVertexLocation(i))).v3.xyz); tc.AddTarget((m_mat * mat4::translate(m_meshes[m_mesh_id].m1->GetVertexLocation(i))).v3.xyz);
tc.AddTarget(box3(vec3::zero, vec3::one));
tc.AddTarget(box3(vec3(0.f), vec3(1.f)));
for (int k = 0; k < m_ssetup->m_lights.Count() && m_ssetup->m_show_lights; ++k) for (int k = 0; k < m_ssetup->m_lights.Count() && m_ssetup->m_show_lights; ++k)
{ {
vec3 light_pos = m_ssetup->m_lights[k]->GetPosition(); vec3 light_pos = m_ssetup->m_lights[k]->GetPosition();
mat4 world_cam = m_camera->GetView(); mat4 world_cam = m_camera->GetView();
light_pos = (inverse(world_cam) * vec4((world_cam * vec4(light_pos, 1.0f)).xyz * vec3::axis_z, 1.0f)).xyz; light_pos = (inverse(world_cam) * vec4((world_cam * vec4(light_pos, 1.0f)).xyz * vec3::axis_z, 1.0f)).xyz;
tc.AddTarget(box3(vec3::onen, vec3::one) + light_pos *
tc.AddTarget(box3(vec3(-1.f), vec3(1.f)) + light_pos *
((m_ssetup->m_lights[k]->GetType() == LightType::Directional)?(-1.f):(1.f))); ((m_ssetup->m_lights[k]->GetType() == LightType::Directional)?(-1.f):(1.f)));
} }




+ 20
- 20
tools/lolremez/solver.cpp View File

@@ -96,11 +96,11 @@ void RemezSolver::Init()
m_control.Resize(m_order + 2); m_control.Resize(m_order + 2);


/* Pick up x_i where error will be 0 and compute f(x_i) */ /* Pick up x_i where error will be 0 and compute f(x_i) */
real fxn[m_order + 1];
Array<real> fxn;
for (int i = 0; i < m_order + 1; i++) for (int i = 0; i < m_order + 1; i++)
{ {
m_zeroes[i] = (real)(2 * i - m_order) / (real)(m_order + 1); m_zeroes[i] = (real)(2 * i - m_order) / (real)(m_order + 1);
fxn[i] = EvalFunc(m_zeroes[i]);
fxn.Push(EvalFunc(m_zeroes[i]));
} }


/* We build a matrix of Chebishev evaluations: row i contains the /* We build a matrix of Chebishev evaluations: row i contains the
@@ -109,10 +109,10 @@ void RemezSolver::Init()
for (int i = 0; i < m_order + 1; i++) for (int i = 0; i < m_order + 1; i++)
{ {
/* Compute the powers of x_i */ /* Compute the powers of x_i */
real powers[m_order + 1];
powers[0] = 1.0;
Array<real> powers;
powers.Push(real(1.0));
for (int n = 1; n < m_order + 1; n++) for (int n = 1; n < m_order + 1; n++)
powers[n] = powers[n - 1] * m_zeroes[i];
powers.Push(powers.Last() * m_zeroes[i]);


/* Compute the Chebishev evaluations at x_i */ /* Compute the Chebishev evaluations at x_i */
for (int n = 0; n < m_order + 1; n++) for (int n = 0; n < m_order + 1; n++)
@@ -239,9 +239,9 @@ real RemezSolver::FindExtrema()
void RemezSolver::Step() void RemezSolver::Step()
{ {
/* Pick up x_i where error will be 0 and compute f(x_i) */ /* Pick up x_i where error will be 0 and compute f(x_i) */
real fxn[m_order + 2];
Array<real> fxn;
for (int i = 0; i < m_order + 2; i++) for (int i = 0; i < m_order + 2; i++)
fxn[i] = EvalFunc(m_control[i]);
fxn.Push(EvalFunc(m_control[i]));


/* We build a matrix of Chebishev evaluations: row i contains the /* We build a matrix of Chebishev evaluations: row i contains the
* evaluations of x_i for polynomial order n = 0, 1, ... */ * evaluations of x_i for polynomial order n = 0, 1, ... */
@@ -249,10 +249,10 @@ void RemezSolver::Step()
for (int i = 0; i < m_order + 2; i++) for (int i = 0; i < m_order + 2; i++)
{ {
/* Compute the powers of x_i */ /* Compute the powers of x_i */
real powers[m_order + 1];
powers[0] = 1.0;
Array<real> powers;
powers.Push(real(1.0));
for (int n = 1; n < m_order + 1; n++) for (int n = 1; n < m_order + 1; n++)
powers[n] = powers[n - 1] * m_control[i];
powers.Push(powers.Last() * m_control[i]);


/* Compute the Chebishev evaluations at x_i */ /* Compute the Chebishev evaluations at x_i */
for (int n = 0; n < m_order + 1; n++) for (int n = 0; n < m_order + 1; n++)
@@ -307,32 +307,32 @@ void RemezSolver::PrintPoly()


/* Transform Chebyshev polynomial weights into powers of X^i /* Transform Chebyshev polynomial weights into powers of X^i
* in the [-1..1] range. */ * in the [-1..1] range. */
real bn[m_order + 1];
Array<real> bn;


for (int i = 0; i < m_order + 1; i++) for (int i = 0; i < m_order + 1; i++)
{ {
bn[i] = 0;
real tmp = 0;
for (int j = 0; j < m_order + 1; j++) for (int j = 0; j < m_order + 1; j++)
bn[i] += m_coeff[j] * (real)Cheby(j, i);
tmp += m_coeff[j] * (real)Cheby(j, i);
bn.Push(tmp);
} }


/* Transform a polynomial in the [-1..1] range into a polynomial /* Transform a polynomial in the [-1..1] range into a polynomial
* in the [a..b] range. */ * in the [a..b] range. */
real k1p[m_order + 1], k2p[m_order + 1];
real an[m_order + 1];
Array<real> k1p, k2p, an;


for (int i = 0; i < m_order + 1; i++) for (int i = 0; i < m_order + 1; i++)
{ {
k1p[i] = i ? k1p[i - 1] * m_invk1 : (real)1;
k2p[i] = i ? k2p[i - 1] * m_invk2 : (real)1;
k1p.Push(i ? k1p[i - 1] * m_invk1 : (real)1);
k2p.Push(i ? k2p[i - 1] * m_invk2 : (real)1);
} }


for (int i = 0; i < m_order + 1; i++) for (int i = 0; i < m_order + 1; i++)
{ {
an[i] = 0;
real tmp = 0;
for (int j = i; j < m_order + 1; j++) for (int j = i; j < m_order + 1; j++)
an[i] += (real)Comb(j, i) * k1p[j - i] * bn[j];
an[i] *= k2p[i];
tmp += (real)Comb(j, i) * k1p[j - i] * bn[j];
an.Push(tmp * k2p[i]);
} }


printf("Polynomial estimate: "); printf("Polynomial estimate: ");


Loading…
Cancel
Save