Skip to content

Commit

Permalink
UPDATED rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
ksterker committed Jun 18, 2010
1 parent 54820d0 commit ac42ece
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 70 deletions.
26 changes: 7 additions & 19 deletions src/world/renderer.cc
@@ -1,7 +1,7 @@
/*
$Id: renderer.cc,v 1.9 2009/03/21 11:59:47 ksterker Exp $
Copyright (C) 2008/2009 Kai Sterker <kaisterker@linuxgames.com>
Copyright (C) 2008/2009/2010 Kai Sterker <kaisterker@linuxgames.com>
Part of the Adonthell Project http://adonthell.linuxgames.com
Adonthell is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -271,31 +271,27 @@ bool default_renderer::is_object_below (const render_info & obj, const render_in
}
}

// A B C D E
// ZT YB YT ZB 0
// _______
// | | ---|--- | | | |
// |-|--- | ___|___ ---|-| ---|---
// | | | ---'--- | | |

int res = 0;
// fprintf (stderr, "3. %i >= %i && %i <= %i && %i >= %i\n", obj.y(), min_y, obj.y(), max_y, obj.y() + obj.Shape->width(), max_y);
if (obj.y() >= min_y && obj.y() <= max_y && obj.y() + obj.Shape->width() >= max_y) // C
if (obj.y() >= min_y && obj.y() <= max_y && obj.y() + obj.Shape->width() >= max_y)
{
res += YT; // obj in front of obj2
}
// fprintf (stderr, "4. %i <= %i && %i >= %i && %i <= %i\n", obj.y() + obj.Shape->width(), max_y, obj.y() + obj.Shape->width(), min_y, obj.y(), min_y);
else if (obj.y() + obj.Shape->width() <= max_y && obj.y() + obj.Shape->width() >= min_y && obj.y() <= min_y) // B
else if (obj.y() + obj.Shape->width() <= max_y && obj.y() + obj.Shape->width() >= min_y && obj.y() <= min_y)
{
res += YB; // obj behind obj2
}

// fprintf (stderr, "2. %i >= %i && %i <= %i && %i >= %i\n", obj.z(), min_z, obj.z(), max_z, obj.z() + obj.Shape->height(), max_z);
if (obj.z() >= min_z && obj.z() <= max_z && obj.z() + obj.Shape->height() >= max_z) // A
if (obj.z() >= min_z && obj.z() <= max_z && obj.z() + obj.Shape->height() >= max_z)
{
res += ZT; // obj on top obj2
}
// fprintf (stderr, "1. %i <= %i && %i >= %i && %i <= %i\n", obj.z() + obj.Shape->height(), max_z, obj.z() + obj.Shape->height(), min_z, obj.z(), min_z);
else if (obj.z() + obj.Shape->height() <= max_z && obj.z() + obj.Shape->height() >= min_z && obj.z() <= min_z) // D
else if (obj.z() + obj.Shape->height() <= max_z && obj.z() + obj.Shape->height() >= min_z && obj.z() <= min_z)
{
res += ZB; // obj below obj2
}
Expand Down Expand Up @@ -330,26 +326,18 @@ bool default_renderer::is_object_below (const render_info & obj, const render_in
case YT|ZT:
{
return false;
// fprintf (stderr, "YT|ZT %s!\n", obj2.Shape->is_flat() ? "true" : "false"); // E
// return obj2.Shape->is_flat();
}
case YT|ZB:
{
return false;
// fprintf (stderr, "YT|ZB %s!\n", obj2.Shape->is_flat() ? "true" : "false"); // E
// return obj2.Shape->is_flat();
return true;
}
case YB|ZT:
{
return false;
// fprintf (stderr, "YB|ZT %s!\n", obj2.Shape->is_flat() ? "true" : "false"); // E
// return obj2.Shape->is_flat();
}
case YB|ZB:
{
return true;
// fprintf (stderr, "YB|ZB %s!\n", obj.Shape->is_flat() ? "true" : "false"); // E
// return obj.Shape->is_flat();
}
}
}
Expand Down
104 changes: 53 additions & 51 deletions src/world/test_renderer.cc
Expand Up @@ -40,84 +40,86 @@ namespace world

virtual void SetUp()
{
// Code here will be called immediately after the constructor (right
// before each test).
cube3 *c1 = new cube3 (vector3<s_int16>(0, 0, -5), vector3<s_int16>(128, 96, 0));
cube3 *c2 = new cube3 (vector3<s_int16>(0, 0, 0), vector3<s_int16>(128, 12, 100));

s1.add_part (c1);
s2.add_part (c2);
}

virtual void TearDown()
{
// Code here will be called immediately after each test (right
// before the destructor).
}
}

placeable_shape s1;
placeable_shape s2;
}; // class{}

TEST_F(renderer_Test, is_object_below_1)
{
cube3 c1 (vector3<s_int16>(0, 0, 0), vector3<s_int16>(12, 43, 100));
cube3 c2 (vector3<s_int16>(0, 0, -5), vector3<s_int16>(128, 96, 0));

placeable_shape s1;
s1.add_part (&c1);

placeable_shape s2;
s2.add_part (&c2);
render_info obj1 (&s1, NULL, vector3<s_int32>(-256, 192, 0), NULL);
render_info obj2 (&s2, NULL, vector3<s_int32>(-256, 224, -100), NULL);

render_info obj1 (&s1, NULL, vector3<s_int32>(250, 341, -100), NULL);
render_info obj2 (&s2, NULL, vector3<s_int32>(256, 288, 0), NULL);

EXPECT_EQ(true, is_object_below (obj1, obj2));
EXPECT_EQ(false, is_object_below (obj2, obj1));
EXPECT_EQ(false, is_object_below (obj1, obj2));
EXPECT_EQ(true, is_object_below (obj2, obj1));
}

TEST_F(renderer_Test, is_object_below_2)
{
cube3 c1 (vector3<s_int16>(0, 0, 0), vector3<s_int16>(40, 25, 80));
cube3 c2 (vector3<s_int16>(0, 43, 0), vector3<s_int16>(70, 53, 100));
cube3 c3 (vector3<s_int16>(0, 0, 0), vector3<s_int16>(128, 48, 12));
render_info obj1 (&s1, NULL, vector3<s_int32>(-256, 192, 0), NULL);
render_info obj2 (&s2, NULL, vector3<s_int32>(-256, 280, -100), NULL);

placeable_shape s1; s1.add_part (&c1);
placeable_shape s2; s2.add_part (&c2);
placeable_shape s3; s3.add_part (&c3);
EXPECT_EQ(false, is_object_below (obj1, obj2));
EXPECT_EQ(true, is_object_below (obj2, obj1));
}

render_info obj1 (&s1, NULL, vector3<s_int32>(1085, 522, 88), NULL);
render_info obj2 (&s2, NULL, vector3<s_int32>(1023, 430, 100), NULL);
render_info obj3 (&s3, NULL, vector3<s_int32>(1024, 478, 100), NULL);
TEST_F(renderer_Test, is_object_below_3)
{
render_info obj1 (&s1, NULL, vector3<s_int32>(-256, 192, 0), NULL);
render_info obj2 (&s2, NULL, vector3<s_int32>(-256, 196, -100), NULL);

EXPECT_EQ(false, is_object_below (obj1, obj2));
EXPECT_EQ(true, is_object_below (obj2, obj1));
EXPECT_EQ(false, is_object_below (obj2, obj3));
EXPECT_EQ(true, is_object_below (obj3, obj2));
EXPECT_EQ(false, is_object_below (obj1, obj3));
EXPECT_EQ(true, is_object_below (obj3, obj1));
}

TEST_F(renderer_Test, is_object_below_3)
TEST_F(renderer_Test, is_object_below_4)
{
cube3 c1 (vector3<s_int16>(0, 0, -5), vector3<s_int16>(128, 96, 0));
cube3 c2 (vector3<s_int16>(0, 0, 0), vector3<s_int16>(12, 43, 100));
cube3 c3 (vector3<s_int16>(0, 0, 0), vector3<s_int16>(128, 53, 100));
cube3 c4 (vector3<s_int16>(0, 0, 0), vector3<s_int16>(40, 25, 80));
render_info obj1 (&s1, NULL, vector3<s_int32>(-256, 192, 0), NULL);
render_info obj2 (&s2, NULL, vector3<s_int32>(-256, 182, -5), NULL);

placeable_shape s1; s1.add_part (&c1);
placeable_shape s2; s2.add_part (&c2);
placeable_shape s3; s3.add_part (&c3);
placeable_shape s4; s4.add_part (&c4);
EXPECT_EQ(true, is_object_below (obj1, obj2));
EXPECT_EQ(false, is_object_below (obj2, obj1));
}

TEST_F(renderer_Test, is_object_below_5)
{
render_info obj1 (&s1, NULL, vector3<s_int32>(-256, 192, 0), NULL);
render_info obj2 (&s2, NULL, vector3<s_int32>(-256, 280, -5), NULL);

render_info obj1 (&s1, NULL, vector3<s_int32>(384, 96, 0), NULL);
render_info obj2 (&s2, NULL, vector3<s_int32>(506, 149, -100), NULL);
render_info obj3 (&s3, NULL, vector3<s_int32>(448, 96, -100), NULL);
render_info obj4 (&s4, NULL, vector3<s_int32>(499, 121, -1), NULL);
EXPECT_EQ(true, is_object_below (obj1, obj2));
EXPECT_EQ(false, is_object_below (obj2, obj1));
}

TEST_F(renderer_Test, is_object_below_6)
{
render_info obj1 (&s1, NULL, vector3<s_int32>(-256, 192, 0), NULL);
render_info obj2 (&s2, NULL, vector3<s_int32>(-256, 224, -5), NULL);

EXPECT_EQ(false, is_object_below (obj1, obj2));
EXPECT_EQ(true, is_object_below (obj2, obj1));
EXPECT_EQ(false, is_object_below (obj2, obj3));
EXPECT_EQ(true, is_object_below (obj3, obj2));
EXPECT_EQ(false, is_object_below (obj3, obj4));
EXPECT_EQ(true, is_object_below (obj4, obj3));
EXPECT_EQ(true, is_object_below (obj4, obj1));
EXPECT_EQ(false, is_object_below (obj1, obj4));
EXPECT_EQ(true, is_object_below (obj1, obj2));
EXPECT_EQ(false, is_object_below (obj2, obj1));
}
/*
TEST_F(renderer_Test, is_object_below_7)
{
render_info obj1 (&s1, NULL, vector3<s_int32>(-256, 192, 0), NULL);
render_info obj2 (&s2, NULL, vector3<s_int32>(-256, 224, -100), NULL);
EXPECT_EQ(true, is_object_below (obj1, obj2));
EXPECT_EQ(false, is_object_below (obj2, obj1));
}

*/
} // namespace{}


Expand Down

0 comments on commit ac42ece

Please sign in to comment.