Exemplo n.º 1
0
/**
 * \brief Get the height of the element (before the scaling factor).
 */
bear::visual::size_type bear::visual::scene_element::get_element_height() const
{
  if ( get_scale_factor_y() == 0 )
    return get_bounding_box().height();
  else
    return get_bounding_box().height() / get_scale_factor_y();
} // scene_element::get_element_height()
Exemplo n.º 2
0
Arquivo: block.c Projeto: rvba/minuit
void drive_away( t_block *block, t_block *block_nearest, int dir)
{
	float box_block[8];
	float box_nearest[8];
	float margin = 5;

	get_bounding_box( block, margin ,box_block);
	get_bounding_box( block_nearest, margin, box_nearest);

	float *big;
	float *small;

	if( block->width >= block_nearest->width && block->height >= block_nearest->height)
	{
		big = box_block;
		small = box_nearest;
	}
	else
	{
		big = box_nearest;
		small = box_block;
	}

	int test = test_bounding_box( big, small);

	if( test)
	{
		displace( block, block_nearest, dir);
		drive_away( block, block_nearest, dir);
	}
}
Exemplo n.º 3
0
void FitRestraint::resample() const {
  //TODO - first check that the bounding box of the particles
  //match the one of the sampled ones.
  //resample the map containing all non rigid body particles
  //this map has all of the non rigid body particles.
  if (not_part_of_rb_.size()>0) {
    none_rb_model_dens_map_->resample();
    none_rb_model_dens_map_->calcRMS();
    model_dens_map_->copy_map(none_rb_model_dens_map_);
  }
  else{
    model_dens_map_->reset_data(0.);
  }
  for(unsigned int rb_i=0;rb_i<rbs_.size();rb_i++) {
    IMP_LOG(VERBOSE,"Rb model dens map size:"<<
        get_bounding_box(rb_model_dens_map_[rb_i],-1000.)<<
        "\n Target size:"<<get_bounding_box(target_dens_map_,-1000.)<<"\n");
    algebra::Transformation3D rb_t=
         algebra::get_transformation_from_first_to_second(
                                             rbs_orig_rf_[rb_i],
                                             rbs_[rb_i].get_reference_frame());
    Pointer<DensityMap> transformed = get_transformed(
                                                      rb_model_dens_map_[rb_i],
                                                      rb_t);
    IMP_LOG(VERBOSE,"transformed map size:"<<
                    get_bounding_box(transformed,-1000.)<<std::endl);
    model_dens_map_->add(transformed);
    transformed->set_was_used(true);
  }
}
Exemplo n.º 4
0
/**
 * \brief Do one iteration in the progression of the item.
 */
void bear::reflecting_decoration::progress( universe::time_type elapsed_time )
{
  super::progress(elapsed_time);

  m_items_list.clear();

  std::list<universe::physical_item*> items;

  if ( get_layer().has_world() )
    {
      bear::universe::item_picking_filter filter;
      filter.set_fixed_value(false);
      
      get_layer().get_world().pick_items_in_rectangle
        ( items, get_bounding_box(), filter);

      std::list<universe::physical_item*>::iterator it;
      for ( it = items.begin(); it != items.end(); ++it )
        {
          engine::base_item* item = dynamic_cast<engine::base_item*>(*it);

          if ( (item != NULL) && (item != this) )
            m_items_list.push_back(item_handle(*it));
        }
    }
} // reflecting_decoration::progress()
Exemplo n.º 5
0
void Bubble::do_draw(QPainter& painter) {
    draw_bubble(painter);
    painter.setPen(Qt::red);
    painter.setBrush(Qt::NoBrush);
    painter.setOpacity(1.0);
    painter.drawRect(get_bounding_box());
}
Exemplo n.º 6
0
static GeglRectangle
get_required_for_output (GeglOperation       *operation,
                         const gchar         *input_pad,
                         const GeglRectangle *roi)
{
  return get_bounding_box (operation);
}
Exemplo n.º 7
0
/* ---------------------------------------------------------------------------- */
void Model::draw(GLdouble angulo,GLdouble angulo_centro)
{
	glPushMatrix();
	aiVector3D *min = new aiVector3D(),*max = new aiVector3D();
	get_bounding_box(min,max);
	GLdouble largoMoto = (max->x-min->x);
	GLdouble altoMoto = (max->y-min->y);
	float escala = largoMoto > 1 ? 1/largoMoto : 1;

	//Muevo moto
	glTranslated(posX - largoMoto/2,posY ,0);
	glScalef(escala, escala, escala);
	//Roto moto
	glTranslated(-largoMoto/2+largoMoto*relLargoEjeTrasero,altoMoto*relAltoEjeTrasero,0);
	glRotated(angulo,0,0,1);
	glTranslated(largoMoto/2-largoMoto*relLargoEjeTrasero,-altoMoto*relAltoEjeTrasero,0);
	float centro_rot_x = largoMoto / 2;
	float centro_rot_y = altoMoto / 2;
	glColor3f(1,0,1);
	glTranslated(0,0,0);
	// centro de rotacion
	glBegin(GL_POINTS);
	glVertex3d(0, 0, 0);
	glEnd();
	glRotated(angulo_centro,0,0,1);
	glTranslated(0, 0,0);





	//Dibujo moto
	recursive_render(scene, scene->mRootNode);
	glPopMatrix();
}
Exemplo n.º 8
0
/**
 * \brief This function is called when the entity has just moved.
 *
 * If it is an NPC, its sprite's direction is updated.
 */
void Npc::notify_position_changed() {

  Entity::notify_position_changed();

  if (subtype == USUAL_NPC) {

    const SpritePtr& sprite = get_sprite();
    if (get_movement() != nullptr) {
      // The NPC is moving.
      if (sprite != nullptr) {
        if (sprite->get_current_animation() != "walking") {
          sprite->set_current_animation("walking");
        }
        int direction4 = get_movement()->get_displayed_direction4();
        sprite->set_current_direction(direction4);
      }
    }

    if (get_hero().get_facing_entity() == this &&
        get_commands_effects().get_action_key_effect() == CommandsEffects::ACTION_KEY_SPEAK &&
        !get_hero().is_facing_point_in(get_bounding_box())) {

      get_commands_effects().set_action_key_effect(CommandsEffects::ACTION_KEY_NONE);
    }
  }
}
Exemplo n.º 9
0
/**
 * \brief Returns whether a touching point of an entity
 * (in any of the four main directions)
 * is overlapping the detector's rectangle.
 *
 * This method is called by check_collision(Entity*) when the detector's collision
 * mode is COLLISION_TOUCHING_POINT.
 *
 * \param entity The entity.
 * \return \c true if a touching point of the entity is overlapping the
 * detector's rectangle.
 */
bool Detector::test_collision_touching(Entity& entity) {

  const Rectangle& bounding_box = get_bounding_box();
  return entity.is_touching_point_in(bounding_box, 0)
      || entity.is_touching_point_in(bounding_box, 1)
      || entity.is_touching_point_in(bounding_box, 2)
      || entity.is_touching_point_in(bounding_box, 3);
}
Exemplo n.º 10
0
/**
 * Initialize an infinite plane.
 * Initializes the underlying object structure and calculates the transformed
 * bounding box.
 */
void plane_init(struct object *o, const struct transform *t){
	object_init(o, t);

	get_bounding_box(t, &(o->boundingBox));

	o->get_intersection = get_intersection;
	o->get_normal = get_normal;
}
Exemplo n.º 11
0
/**
 * \brief Do one iteration in the progression of the item.
 */
void
ptb::hideout_revealing::progress( bear::universe::time_type elapsed_time )
{
  super::progress(elapsed_time);

  bool player_in_zone = false;

  if ( !m_current_revealed && !m_hideout_found )
    {
      search_players();

      if ( m_first_player != NULL )
        player_in_zone =
          m_first_player.get_bounding_box().intersects(get_bounding_box());

      if ( !player_in_zone && (m_second_player != NULL) )
        player_in_zone =
          m_second_player.get_bounding_box().intersects(get_bounding_box());

      if ( player_in_zone )
        {
          if ( !m_last_revealed )
            m_last_modification = 0;
          m_current_revealed = true;
          m_hideout_found = m_definitive_disclosure;
        }
    }

  if ( !m_hideout_found )
    {
      if ( !m_current_revealed && m_last_revealed )
        m_last_modification = 0;

      m_last_revealed = m_current_revealed;
      m_current_revealed = false;
    }

  if ( m_last_modification <= m_revelation_duration )
    {
       m_last_modification += elapsed_time;
       if ( player_in_zone || m_hideout_found  )
        reveal();
      else
        hide();
    }
} // hideout_revealing::progress()
Exemplo n.º 12
0
/**
 * \brief Add the hole block to kill the player if he collides while the switch
 *        moves.
 */
void rp::switching::init_hole_block()
{
  CLAW_PRECOND( m_hole == NULL );

  m_hole = new hole();
  m_hole->set_bounding_box(get_bounding_box());

  new_item(*m_hole);
} // switching::init_hole_block()
Exemplo n.º 13
0
/**
 * @brief This function is called when the entity has just moved.
 */
void Bomb::notify_position_changed() {

  if (get_hero().get_facing_entity() == this
      && get_keys_effect().get_action_key_effect() == KeysEffect::ACTION_KEY_LIFT
      && !get_hero().is_facing_point_in(get_bounding_box())) {

    get_keys_effect().set_action_key_effect(KeysEffect::ACTION_KEY_NONE);
  }
}
Exemplo n.º 14
0
/**
 * \brief This function is called when the entity has just moved.
 */
void Bomb::notify_position_changed() {

  Entity::notify_position_changed();

  if (get_hero().get_facing_entity() == this
      && get_commands_effects().get_action_key_effect() == CommandsEffects::ACTION_KEY_LIFT
      && !get_hero().is_facing_point_in(get_bounding_box())) {

    get_commands_effects().set_action_key_effect(CommandsEffects::ACTION_KEY_NONE);
  }
}
Exemplo n.º 15
0
IMPALGEBRA_BEGIN_NAMESPACE

Sphere3D get_enclosing_sphere(const Sphere3Ds &ss) {
  IMP_USAGE_CHECK(!ss.empty(),
                  "Must pass some spheres to have a bounding sphere");
#ifdef IMP_ALGEBRA_USE_IMP_CGAL
  return cgal::internal::get_enclosing_sphere(ss);
#else
  BoundingBox3D bb = get_bounding_box(ss[0]);
  for (unsigned int i = 1; i < ss.size(); ++i) {
    bb += get_bounding_box(ss[i]);
  }
  Vector3D c = .5 * (bb.get_corner(0) + bb.get_corner(1));
  double r = 0;
  for (unsigned int i = 0; i < ss.size(); ++i) {
    double d = (c - ss[i].get_center()).get_magnitude();
    d += ss[i].get_radius();
    r = std::max(r, d);
  }
  return Sphere3D(c, r);
#endif
}
Exemplo n.º 16
0
Arquivo: block.c Projeto: rvba/minuit
void get_branch_bounding_box( t_block *block, t_lst *lst, float *box_tree, int dir)
{
	t_link *l;
	t_block *block_leaf;
	float box_leaf[8];
	float margin = 0;
	for( l = lst->first; l; l = l->next)
	{
		block_leaf = l->data;
		get_bounding_box( block_leaf, margin, box_leaf);
		get_bigger_box( box_tree, box_leaf);
	}
}
Exemplo n.º 17
0
/**
 * \brief Notifies this detector that the player is interacting with it by
 * pressing the action command.
 *
 * This function is called when the player presses the action command
 * while the hero is facing this detector, and the action command effect lets
 * him do this.
 * The hero lifts the bomb if possible.
 */
void Bomb::notify_action_command_pressed() {

  KeysEffect::ActionKeyEffect effect = get_keys_effect().get_action_key_effect();

  if (effect == KeysEffect::ACTION_KEY_LIFT
      && get_hero().get_facing_entity() == this
      && get_hero().is_facing_point_in(get_bounding_box())) {

    get_hero().start_lifting(new CarriedItem(get_hero(), *this,
	"entities/bomb", "", 0, explosion_date));
    Sound::play("lift");
    remove_from_map();
  }
}
Exemplo n.º 18
0
int AssimpSimpleModelLoader::loadasset (const char* path)
{
	// we are taking one of the postprocessing presets to avoid
	// spelling out 20+ single postprocessing flags here.
	this->scene = aiImportFile(path,aiProcessPreset_TargetRealtime_MaxQuality);
	if (this->scene) {
		get_bounding_box(&(this->scene_min),&(this->scene_max));
		this->scene_center.x = (this->scene_min.x + this->scene_max.x) / 2.0f;
		this->scene_center.y = (this->scene_min.y + this->scene_max.y) / 2.0f;
		this->scene_center.z = (this->scene_min.z + this->scene_max.z) / 2.0f;
		return 0;
	}
	return 1;
}
Exemplo n.º 19
0
/**
 * \brief Test if the item is in a given environment.
 * \param e The considered environment.
 */
bool bear::universe::physical_item::is_in_environment
(const universe::environment_type e) const
{
  bool result = false;

  if ( has_owner() )
    {
      std::set<universe::environment_type> environments;
      get_owner().get_environments(get_bounding_box(), environments);
      result = ( environments.find(e) != environments.end());
    }

  return result;
} // physical_item::is_in_environment()
Exemplo n.º 20
0
static PlanarBBoxObject *
BBox_new_from_shapes(PyTypeObject *type, PyObject *shapes) 
{
    PlanarBBoxObject *result, *bbox = NULL;
    Py_ssize_t size;
    PyObject **item;

    assert(PyType_IsSubtype(type, &PlanarBBoxType));
    result = (PlanarBBoxObject *)type->tp_alloc(type, 0);
    shapes = PySequence_Fast(shapes, "expected iterable of bounded shapes");
    if (result == NULL || shapes == NULL) {
        goto error;
    }
    size = PySequence_Fast_GET_SIZE(shapes);
    if (size < 1) {
        PyErr_SetString(PyExc_ValueError,
            "Cannot construct a BoundingBox without at least one shape");
        goto error;
    }
    result->min.x = result->min.y = DBL_MAX;
    result->max.x = result->max.y = -DBL_MAX;
    item = PySequence_Fast_ITEMS(shapes);
    while (size--) {
        bbox = get_bounding_box(*(item++));
        if (bbox == NULL) {
            goto error;
        }
        if (bbox->min.x < result->min.x) {
            result->min.x = bbox->min.x;
        }
        if (bbox->min.y < result->min.y) {
            result->min.y = bbox->min.y;
        }
        if (bbox->max.x > result->max.x) {
            result->max.x = bbox->max.x;
        }
        if (bbox->max.y > result->max.y) {
            result->max.y = bbox->max.y;
        }
        Py_CLEAR(bbox);
    }
    Py_DECREF(shapes);
    return result;
    
error:
    Py_XDECREF(bbox);
    Py_XDECREF(result);
    Py_XDECREF(shapes);
    return NULL;
}
Exemplo n.º 21
0
RenderObject::RenderObject(std::string model, bool normalize_scale, unsigned int aiOptions)
	: MovableObject()
	, normalization_matrix_(1.0f)
	, scene(nullptr)
	, name(model)
	, scale(1.0f) {

	std::string real_path = model;

	importer.SetIOHandler(new AssimpDataImport());

	scene = importer.ReadFile(real_path,
		aiProcess_Triangulate | aiProcess_GenSmoothNormals |
		aiProcess_JoinIdenticalVertices |
		aiProcess_OptimizeMeshes | aiProcess_OptimizeGraph  |
		aiProcess_ImproveCacheLocality | aiProcess_GenUVCoords |
		aiProcess_ValidateDataStructure | aiProcess_FixInfacingNormals |
		aiProcess_SortByPType |
		aiProcess_CalcTangentSpace | aiOptions
		);

	if ( !scene ) {
		printf("Failed to load model `%s': %s\n", real_path.c_str(), importer.GetErrorString());
		return;
	}

	fprintf(verbose, "Loaded model %s:\n"
	        "  Meshes: %d\n"
	        "  Textures: %d\n"
	        "  Materials: %d\n",
	        model.c_str(), scene->mNumMeshes, scene->mNumTextures, scene->mNumMaterials);

	//Get bounds:
	aiVector3D s_min, s_max;
	get_bounding_box(&s_min, &s_max);
	scene_min = glm::make_vec3((float*)&s_min);
	scene_max = glm::make_vec3((float*)&s_max);
	scene_center  = (scene_min+scene_max)/2.0f;

	//Calculate normalization matrix
	if(normalize_scale) {
		const glm::vec3 size = scene_max - scene_min;
		float tmp = std::max(size.x, size.y);
		tmp = std::max(tmp, size.z);
		normalization_matrix_ = glm::scale(normalization_matrix_, glm::vec3(1.f/tmp));
	}

	pre_render();
}
Exemplo n.º 22
0
static PyObject *
BBox_fit(PlanarBBoxObject *self, PyObject *shape)
{
    double w_ratio, h_ratio, scale, half_width, half_height;
    double ox, oy, cx, cy;
    PlanarBBoxObject *bbox;
    PlanarAffineObject *xform;

    assert(PlanarBBox_Check(self));
    cx = (self->max.x + self->min.x) * 0.5;
    cy = (self->max.y + self->min.y) * 0.5;
    if (PlanarBBox_Check(shape)) {
        bbox = (PlanarBBoxObject *)shape;
        w_ratio = (self->max.x - self->min.x) / (bbox->max.x - bbox->min.x);
        h_ratio = (self->max.y - self->min.y) / (bbox->max.y - bbox->min.y);
        scale = (w_ratio < h_ratio ? w_ratio : h_ratio) * 0.5;
        half_width = (bbox->max.x - bbox->min.x) * scale;
        half_height = (bbox->max.y - bbox->min.y) * scale;
        bbox = (PlanarBBoxObject *)PlanarBBoxType.tp_alloc(
            &PlanarBBoxType, 0);
        if (bbox != NULL) {
            bbox->min.x = cx - half_width;
            bbox->max.x = cx + half_width;
            bbox->min.y = cy - half_height;
            bbox->max.y = cy + half_height;
        }
        return (PyObject *)bbox;
    } else {
        bbox = get_bounding_box(shape);
        if (bbox == NULL) {
            return NULL;
        }
        ox = cx - (bbox->max.x + bbox->min.x) * 0.5;
        oy = cy - (bbox->max.y + bbox->min.y) * 0.5;
        w_ratio = (self->max.x - self->min.x) / (bbox->max.x - bbox->min.x);
        h_ratio = (self->max.y - self->min.y) / (bbox->max.y - bbox->min.y);
        scale = w_ratio < h_ratio ? w_ratio : h_ratio;
        Py_DECREF(bbox);
        xform = PlanarAffine_FromDoubles(
            scale,   0.0,  ox, 
              0.0, scale,  oy);
        if (xform == NULL) {
            return NULL;
        }
        shape = PyNumber_Multiply(shape, (PyObject *)xform);
        Py_DECREF(xform);
        return shape;
    }
}
Exemplo n.º 23
0
/**
 * \brief Test if the item is only in a given environment.
 * \param e The considered environment.
 */
bool bear::universe::physical_item::is_only_in_environment
(const universe::environment_type e) const
{
  bool result = false;

  if ( has_owner() )
    {
      std::set<universe::environment_type> environments;
      get_owner().get_environments(get_bounding_box(), environments);
      if ( environments.size() == 1 )
        result = ( *(environments.begin()) == e );
    }

  return result;
} // physical_item::is_only_in_environment()
Exemplo n.º 24
0
void Model3D::loadModel(const char* fileName) {
    std::string fn(fileName);
    foldername = fn.substr(0, fn.find_last_of("/\\") + 1);
    //printf("%s foldername\n", foldername.c_str());
    scene = aiImportFile(fileName, aiProcessPreset_TargetRealtime_Quality);
    recursiveTextureLoad(scene, scene->mRootNode);

    get_bounding_box(&min, &max);
    if ((max.x - min.x > max.y - min.y) && (max.x - min.x > max.z - min.z))
        scale = max.x - min.x;
    else if ((max.y - min.y > max.x - min.x) && (max.y - min.y > max.z - min.z))
        scale = max.y - min.y;
    else if ((max.z - min.z > max.y - min.y) && (max.z - min.z > max.x - min.x))
        scale = max.z - min.z;
}
Exemplo n.º 25
0
int loadasset (const char* path, struct myScene *work)
{
	// we are taking one of the postprocessing presets to avoid
	// writing 20 single postprocessing flags here.
	work->scene = aiImportFile(path,aiProcessPreset_TargetRealtime_Quality);
    
	if (work->scene) {
		get_bounding_box(work->scene, &work->scene_min,&work->scene_max);
		work->scene_center.x = (work->scene_min.x + work->scene_max.x) / 2.0f;
		work->scene_center.y = (work->scene_min.y + work->scene_max.y) / 2.0f;
		work->scene_center.z = (work->scene_min.z + work->scene_max.z) / 2.0f;
		return 0;
	}
	return 1;
}
Exemplo n.º 26
0
/* ---------------------------------------------------------------------------- */
int loadasset (const char* path)
{
	/* we are taking one of the postprocessing presets to avoid
	   spelling out 20+ single postprocessing flags here. */
	scene = aiImportFile(path,aiProcessPreset_TargetRealtime_MaxQuality);

	if (scene) {
		get_bounding_box(&scene_min,&scene_max);
		scene_center.x = (scene_min.x + scene_max.x) / 2.0f;
		scene_center.y = (scene_min.y + scene_max.y) / 2.0f;
		scene_center.z = (scene_min.z + scene_max.z) / 2.0f;
		return 0;
	}
	return 1;
}
Exemplo n.º 27
0
	bool RStarTreeNode::check_nodes() const
	{
		Uint32 i;

		for (i = 0; i < get_count(); i++)
		{
			if (!get_bounding_box().contains(get_element_bounding_box(i)))
			{
				return false;
			}

			if (!get_leaf())
			{
				if (!get_node(i)->check_nodes())
				{
					return false;
				}
			}
		}

		return true;
	}
Exemplo n.º 28
0
/* ---------------------------------------------------------------------------- */
int Model::loadasset (const char* path)
{

	math::Clock clock;
	math::tick_t t1 = clock.Tick();
	/* we are taking one of the postprocessing presets to avoid
	   spelling out 20+ single postprocessing flags here. */
	scene = aiImportFile(path,aiProcessPreset_TargetRealtime_MaxQuality);

	if (scene) {
		get_bounding_box(&scene_min,&scene_max);
		scene_center.x = (scene_min.x + scene_max.x) / 2.0f;
		scene_center.y = (scene_min.y + scene_max.y) / 2.0f;
		scene_center.z = (scene_min.z + scene_max.z) / 2.0f;
		std::cout << "ms loadasset: " << path <<  "  " << clock.MillisecondsSinceF(t1) << " ms\n";
		recursiveTextureLoad(scene, scene->mRootNode);

		return 1;
	}
	std::cout << "ms loadasset failed: " << clock.MillisecondsSinceF(t1) << " ms\n";
	return 0;
}
Exemplo n.º 29
0
static GeglRectangle
get_required_for_output (GeglOperation        *operation,
                         const gchar         *input_pad,
                         const GeglRectangle *region)
{
  GeglOperationAreaFilter *area = GEGL_OPERATION_AREA_FILTER (operation);
  GeglRectangle            rect;
  GeglRectangle            defined;

  defined = get_bounding_box (operation);
  gegl_rectangle_intersect (&rect, region, &defined);

  if (rect.width  != 0 &&
      rect.height != 0)
    {
      rect.x -= area->left;
      rect.y -= area->top;
      rect.width  += area->left + area->right;
      rect.height  += area->top + area->bottom;
    }

  return rect;
}
Exemplo n.º 30
0
/**
 * \copydoc Entity::notify_action_command_pressed
 */
bool Bomb::notify_action_command_pressed() {

  CommandsEffects::ActionKeyEffect effect = get_commands_effects().get_action_key_effect();

  if (effect == CommandsEffects::ACTION_KEY_LIFT
      && get_hero().get_facing_entity() == this
      && get_hero().is_facing_point_in(get_bounding_box())) {

    get_hero().start_lifting(std::make_shared<CarriedObject>(
        get_hero(),
        *this,
        "entities/bomb",
        "",
        0,
        explosion_date)
    );
    Sound::play("lift");
    remove_from_map();
    return true;
  }

  return false;
}