Skip to content

Commit

Permalink
ADDED solid bbox to placeable.h.
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederico authored and Frederico committed Oct 29, 2009
1 parent 551cec8 commit f2b9157
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/world/character.cc
Expand Up @@ -239,7 +239,7 @@ bool character::get_state (base::flat & file)

// load shadow
std::string shadow_file = entity.get_string ("shadow");
MyShadow = new shadow (shadow_file, this, CurPos);
MyShadow = new shadow (shadow_file, this, EntireCurPos);

return file.success ();
}
Expand Down
88 changes: 54 additions & 34 deletions src/world/placeable.cc
@@ -1,6 +1,4 @@
/*
$Id: placeable.cc,v 1.10 2009/04/26 18:52:59 ksterker Exp $
Copyright (C) 2002 Alexandre Courbot <alexandrecourbot@linuxgames.com>
Part of the Adonthell Project http://adonthell.linuxgames.com
Expand Down Expand Up @@ -38,9 +36,9 @@ using world::placeable;
#define MI16 32767

// ctor
placeable::placeable(world::area & mymap) : MaxSize(), Mymap(mymap)
placeable::placeable(world::area & mymap) : SolidMaxSize(), Mymap(mymap)
{
MinPos.set (MI16, MI16, MI16);
SolidMinPos.set (MI16, MI16, MI16);
Type = UNKNOWN;
Solid = true;
State = "";
Expand Down Expand Up @@ -77,9 +75,17 @@ void placeable::set_state (const std::string & state)
const placeable_shape *shape = (*i)->current_shape ();
if (shape != NULL)
{
CurSize.set (shape->length(), shape->width(), shape->height());
CurPos.set (shape->x(), shape->y(), shape->z());
if (shape->is_solid()) Solid = true;

if (shape->is_solid())
{
SolidCurSize.set (shape->length(), shape->width(), shape->height());
SolidCurPos.set (shape->x(), shape->y(), shape->z());

Solid = true; // set this object as solid
}

EntireCurSize.set (shape->length(), shape->width(), shape->height());
EntireCurPos.set (shape->x(), shape->y(), shape->z());
}

// update shape and size of composite placeables
Expand All @@ -89,15 +95,26 @@ void placeable::set_state (const std::string & state)
const placeable_shape *shape = (*i)->current_shape ();
if (shape != NULL)
{
CurSize.set_x (std::max (CurSize.x(), shape->length()));
CurSize.set_y (std::max (CurSize.y(), shape->width()));
CurSize.set_z (std::max (CurSize.z(), shape->height()));
if (shape->is_solid())
{
SolidCurSize.set_x (std::max (SolidCurSize.x(), shape->length()));
SolidCurSize.set_y (std::max (SolidCurSize.y(), shape->width()));
SolidCurSize.set_z (std::max (SolidCurSize.z(), shape->height()));

SolidCurPos.set_x (std::min (SolidCurPos.x(), shape->x()));
SolidCurPos.set_y (std::min (SolidCurPos.y(), shape->y()));
SolidCurPos.set_z (std::min (SolidCurPos.z(), shape->z()));

Solid = true;
}

CurPos.set_x (std::min (CurPos.x(), shape->x()));
CurPos.set_y (std::min (CurPos.y(), shape->y()));
CurPos.set_z (std::min (CurPos.z(), shape->z()));

if (shape->is_solid()) Solid = true;
EntireCurSize.set_x (std::max (EntireCurSize.x(), shape->length()));
EntireCurSize.set_y (std::max (EntireCurSize.y(), shape->width()));
EntireCurSize.set_z (std::max (EntireCurSize.z(), shape->height()));

EntireCurPos.set_x (std::min (EntireCurPos.x(), shape->x()));
EntireCurPos.set_y (std::min (EntireCurPos.y(), shape->y()));
EntireCurPos.set_z (std::min (EntireCurPos.z(), shape->z()));
}
}

Expand All @@ -106,19 +123,8 @@ void placeable::set_state (const std::string & state)

// get z position of the object's surface
s_int32 placeable::get_surface_pos () const
{
s_int32 surface = 0;

for (std::vector<world::placeable_model*>::const_iterator i = Model.begin(); i != Model.end(); i++)
{
const placeable_shape *shape = (*i)->current_shape ();
if (shape != NULL && shape->is_solid())
{
surface = std::max (surface, shape->z() + shape->height());
}
}

return surface;
{
return SolidCurSize.z() + SolidCurPos.z();
}

// get terrain type of placeable
Expand Down Expand Up @@ -146,13 +152,27 @@ void placeable::add_model (world::placeable_model * model)
// update bounding box, using the extend of the largest shape
for (placeable_model::iterator shape = model->begin(); shape != model->end(); shape++)
{
MaxSize.set_x (std::max (MaxSize.x(), shape->second.length()));
MaxSize.set_y (std::max (MaxSize.y(), shape->second.width()));
MaxSize.set_z (std::max (MaxSize.z(), shape->second.height()));
// only accounts for solid shapes
if ((*shape).second.is_solid()) {
SolidMaxSize.set_x (std::max (SolidMaxSize.x(), shape->second.length()));
SolidMaxSize.set_y (std::max (SolidMaxSize.y(), shape->second.width()));
SolidMaxSize.set_z (std::max (SolidMaxSize.z(), shape->second.height()));

SolidMinPos.set_x (std::min (SolidMinPos.x(), shape->second.x()));
SolidMinPos.set_y (std::min (SolidMinPos.y(), shape->second.y()));
SolidMinPos.set_z (std::min (SolidMinPos.z(), shape->second.z()));

}

// add regardless of being solid or not
EntireMaxSize.set_x (std::max (EntireMaxSize.x(), shape->second.length()));
EntireMaxSize.set_y (std::max (EntireMaxSize.y(), shape->second.width()));
EntireMaxSize.set_z (std::max (EntireMaxSize.z(), shape->second.height()));

EntireMinPos.set_x (std::min (EntireMinPos.x(), shape->second.x()));
EntireMinPos.set_y (std::min (EntireMinPos.y(), shape->second.y()));
EntireMinPos.set_z (std::min (EntireMinPos.z(), shape->second.z()));

MinPos.set_x (std::min (MinPos.x(), shape->second.x()));
MinPos.set_y (std::min (MinPos.y(), shape->second.y()));
MinPos.set_z (std::min (MinPos.z(), shape->second.z()));
}
}

Expand Down
86 changes: 68 additions & 18 deletions src/world/placeable.h
Expand Up @@ -149,43 +149,85 @@ namespace world
* Get maximum placeable length.
* @return max extension of placeable in x direction.
*/
u_int16 max_length () const { return MaxSize.x(); }
u_int16 max_length () const { return SolidMaxSize.x(); }
/**
* Get maximum placeable width.
* @return max extension of placeable in y direction.
*/
u_int16 max_width () const { return MaxSize.y(); }
u_int16 max_width () const { return SolidMaxSize.y(); }
/**
* Get maximum placeable height.
* @return max extension of placeable in z direction.
*/
u_int16 max_height () const { return MaxSize.z(); }
u_int16 max_height () const { return SolidMaxSize.z(); }

s_int16 min_x () const { return MinPos.x(); }
s_int16 min_y () const { return MinPos.y(); }
s_int16 min_z () const { return MinPos.z(); }
s_int16 min_x () const { return SolidMinPos.x(); }
s_int16 min_y () const { return SolidMinPos.y(); }
s_int16 min_z () const { return SolidMinPos.z(); }

/**
* Get placeable's current length.
* @return actual extension of placeable in x direction.
*/
u_int16 length () const { return CurSize.x(); }
u_int16 length () const { return SolidCurSize.x(); }
/**
* Get placeable's current width.
* @return actual extension of placeable in y direction.
*/
u_int16 width () const { return CurSize.y(); }
u_int16 width () const { return SolidCurSize.y(); }
/**
* Get placeable's current height.
* @return actual extension of placeable in z direction.
*/
u_int16 height () const { return CurSize.z(); }
u_int16 height () const { return SolidCurSize.z(); }
//@}

s_int16 cur_x () const { return CurPos.x(); }
s_int16 cur_y () const { return CurPos.y(); }
s_int16 cur_z () const { return CurPos.z(); }
s_int16 cur_x () const { return SolidCurPos.x(); }
s_int16 cur_y () const { return SolidCurPos.y(); }
s_int16 cur_z () const { return SolidCurPos.z(); }


/**
* Get maximum placeable length accounting for both solid and non-solid shapes.
* @return max extension of placeable in x direction.
*/
u_int16 entire_max_length () const { return EntireMaxSize.x(); }
/**
* Get maximum placeable width accounting for both solid and non-solid shapes.
* @return max extension of placeable in y direction.
*/
u_int16 entire_max_width () const { return EntireMaxSize.y(); }
/**
* Get maximum placeable height accounting for both solid and non-solid shapes.
* @return max extension of placeable in z direction.
*/
u_int16 entire_max_height () const { return EntireMaxSize.z(); }

s_int16 entire_min_x () const { return EntireMinPos.x(); }
s_int16 entire_min_y () const { return EntireMinPos.y(); }
s_int16 entire_min_z () const { return EntireMinPos.z(); }

/**
* Get placeable's current length accounting for both solid and non-solid shapes.
* @return actual extension of placeable in x direction.
*/
u_int16 entire_length () const { return EntireCurSize.x(); }
/**
* Get placeable's current width accounting for both solid and non-solid shapes.
* @return actual extension of placeable in y direction.
*/
u_int16 entire_width () const { return EntireCurSize.y(); }
/**
* Get placeable's current height accounting for both solid and non-solid shapes.
* @return actual extension of placeable in z direction.
*/
u_int16 entire_height () const { return EntireCurSize.z(); }
//@}

s_int16 entire_cur_x () const { return EntireCurPos.x(); }
s_int16 entire_cur_y () const { return EntireCurPos.y(); }
s_int16 entire_cur_z () const { return EntireCurPos.z(); }

/**
* Get placeable's map
* @return map where the placeable exists
Expand Down Expand Up @@ -290,14 +332,22 @@ namespace world
std::string Filename;
/// representation of the placeable
std::vector<world::placeable_model*> Model;
/// bounding box of this placeable. It's updated when adding shapes.
vector3<u_int16> MaxSize;
/// bounding box of this placeable. It's updated when adding shapes. Only takes into account solid shapes.
vector3<u_int16> SolidMaxSize;
/// bounding box of this placeable. Takes into account both solid and non-solid shapes.
vector3<u_int16> EntireMaxSize;
/// position of this placeable. It's calculated when adding shapes.
vector3<s_int16> MinPos;
/// bounding box of this placeable. It's calculated when the state changes.
vector3<u_int16> CurSize;
vector3<s_int16> SolidMinPos;
/// position of this placeable. It's calculated when adding shapes.
vector3<s_int16> EntireMinPos;
/// bounding box of this placeable. It's calculated when the state changes only from the solid shapes.
vector3<u_int16> SolidCurSize;
/// bounding box of this placeable. It's calculated when the state changes from both solid and non-solid shapes.
vector3<u_int16> EntireCurSize;
/// position of this placeable. It's calculated when the state changes.
vector3<s_int16> SolidCurPos;
/// position of this placeable. It's calculated when the state changes.
vector3<s_int16> CurPos;
vector3<s_int16> EntireCurPos;
/// the placeables current state
std::string State;
/// whether placeable is character, scenery or item
Expand Down

0 comments on commit f2b9157

Please sign in to comment.