Skip to content

Commit

Permalink
Clean up code that subtracts out entire_min, hopefully made it more c…
Browse files Browse the repository at this point in the history
…lear about what it's doing
  • Loading branch information
tnielsen committed Apr 3, 2010
1 parent eae6151 commit c25edf9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
22 changes: 18 additions & 4 deletions src/world/chunk_info.h
Expand Up @@ -97,7 +97,7 @@ namespace world
vector3<s_int32> real_min () const
{
const placeable *object = Entity->get_object();
return Min + vector3<s_int32>(object->min_x(), object->min_y(), object->min_z());
return center_min() + object->entire_min();
}

/**
Expand All @@ -106,8 +106,10 @@ namespace world
*/
vector3<s_int32> real_max () const
{
const placeable *object = Entity->get_object();
return Max + vector3<s_int32>(object->min_x(), object->min_y(), object->min_z());
const placeable *object = Entity->get_object();
//Subtracting object->entire_min to get the [0, 0, 0] location
//I'm leaving the comment on the next line so it's obvious why it's not needed.
return Max/*- object->entire_min() + object->entire_min()*/;
}

/**
Expand All @@ -117,7 +119,7 @@ namespace world
vector3<s_int32> solid_min () const
{
const placeable *object = Entity->get_object();
return Min - object->entire_min() + object->solid_min();
return center_min() + object->solid_min();
}

/**
Expand All @@ -127,8 +129,20 @@ namespace world
vector3<s_int32> solid_max () const
{
const placeable *object = Entity->get_object();
//Subtracting object->entire_min to get the [0, 0, 0] location
return SolidMax - object->entire_min() + object->solid_min();
}

/**
* Return "real" position, but adjusted so it points to the [0, 0, 0] portion of the object.
* This is needed because SolidMinPos and EntireMinPos are relative to the [0, 0, 0] location, not the position.
* @return position of the [0, 0, 0] of the object
*/
vector3<s_int32> center_min () const
{
const placeable *object = Entity->get_object();
return Min - object->entire_min();
}

/**
* @name Object shadow
Expand Down
6 changes: 3 additions & 3 deletions src/world/moving.cc
Expand Up @@ -145,10 +145,10 @@ bool moving::collide_with_objects (collision *collisionData)
// get the model's current shape, ...
const placeable_shape * shape = (*model)->current_shape ();

VLOG(1) << " shape " << (*i)->Min-(*i)->get_object()->entire_min() + shape->get_min() << " - " << (*i)->Min-(*i)->get_object()->entire_min() + shape->get_max();
VLOG(1) << " shape " << (*i)->center_min() + shape->get_min() << " - " << (*i)->center_min() + shape->get_max();

// ... and check if collision occurs
shape->collide (collisionData, (*i)->Min-(*i)->get_object()->entire_min());
shape->collide (collisionData, (*i)->center_min());
}
}

Expand Down Expand Up @@ -349,7 +349,7 @@ void moving::calculate_ground_pos ()

// the topmost object will be our ground pos
ci = ground_tiles.begin();
GroundPos = (*ci)->Min.z() - (*ci)->get_object()->min_z() + (*ci)->get_object()->get_surface_pos ();
GroundPos = (*ci)->center_min().z() + (*ci)->get_object()->get_surface_pos ();

// get the terrain, if any
Terrain = (*ci)->get_object()->get_terrain();
Expand Down
2 changes: 1 addition & 1 deletion src/world/renderer.cc
Expand Up @@ -73,7 +73,7 @@ void default_renderer::render (const s_int16 & x, const s_int16 & y, const std::

for (placeable::iterator obj = object->begin(); obj != object->end(); obj++)
{
render_queue.push_back (render_info ((*obj)->current_shape(), (*obj)->get_sprite(), (*i)->Min-object->entire_min(), (*i)->get_shadow()));
render_queue.push_back (render_info ((*obj)->current_shape(), (*obj)->get_sprite(), (*i)->center_min(), (*i)->get_shadow()));
}
}

Expand Down

0 comments on commit c25edf9

Please sign in to comment.