Vector3 HeightMapShapeSW::get_support(const Vector3& p_normal) const { //not very useful, but not very used either return get_aabb().get_support(p_normal); }
Vector3 ConvexPolygonShapeSW::get_moment_of_inertia(real_t p_mass) const { // use crappy AABB approximation Vector3 extents = get_aabb().size * 0.5; return Vector3( (p_mass / 3.0) * (extents.y * extents.y + extents.z * extents.z), (p_mass / 3.0) * (extents.x * extents.x + extents.z * extents.z), (p_mass / 3.0) * (extents.y * extents.y + extents.y * extents.y)); }
Vector3 HeightMapShapeSW::get_moment_of_inertia(float p_mass) const { // use crappy AABB approximation Vector3 extents=get_aabb().size*0.5; return Vector3( (p_mass/3.0) * (extents.y*extents.y + extents.z*extents.z), (p_mass/3.0) * (extents.x*extents.x + extents.z*extents.z), (p_mass/3.0) * (extents.y*extents.y + extents.y*extents.y) ); }
void layer::add_line(const line &l) { auto bb = get_aabb(l); auto r = std::make_shared<record>(0, l); for (auto y = bb.m_miny; y <= bb.m_maxy; ++y) { for (auto x = bb.m_minx; x <= bb.m_maxx; ++x) { m_buckets[y*m_width + x].push_back(r); } } }
void layer::sub_line(const line &l) { auto bb = get_aabb(l); for (auto y = bb.m_miny; y <= bb.m_maxy; ++y) { for (auto x = bb.m_minx; x <= bb.m_maxx; ++x) { auto b = &m_buckets[y*m_width + x]; auto itr = std::find_if(b->begin(), b->end(), [&] (auto &e) { return e->m_line == l; }); if (itr != b->end()) b->erase(itr); } } }
bool layer::hit_line(const line &l) { m_test += 1; auto bb = get_aabb(l); for (auto y = bb.m_miny; y <= bb.m_maxy; ++y) { for (auto x = bb.m_minx; x <= bb.m_maxx; ++x) { for (auto &record : m_buckets[y*m_width+x]) { if (record->m_id == m_test) continue; record->m_id = m_test; if (collide_thick_lines_2d(l.m_p1, l.m_p2, record->m_line.m_p1, record->m_line.m_p2, l.m_radius + record->m_line.m_radius + std::max(l.m_gap, record->m_line.m_gap))) return true; } } } return false; }
void HeightMapShapeSW::project_range(const Vector3& p_normal, const Transform& p_transform, real_t &r_min, real_t &r_max) const { //not very useful, but not very used either p_transform.xform(get_aabb()).project_range_in_plane( Plane(p_normal,0),r_min,r_max ); }
AABB VisualInstance::get_transformed_aabb() const { return get_global_transform().xform( get_aabb() ); }
void dump_graph_to_png_file(const AdjacencyList &adjacency_list, const VertexList &vertex_list, const char *png_filename) { auto bbox = get_aabb(vertex_list); double width = bbox.maxx - bbox.minx; double height = bbox.maxy - bbox.miny; auto surface = std::shared_ptr<cairo_surface_t>( cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height), cairo_surface_destroy); check_cairo_surface_status(surface.get()); auto cr = std::shared_ptr<cairo_t>( cairo_create(surface.get()), cairo_destroy); check_cairo_status(cr.get()); cairo_set_line_width(cr.get(), 1.0); for (const auto &edge: adjacency_list) { auto u = vertex_list.find(std::get<0>(edge)); if (u == vertex_list.end()) { std::cout << "[WARNING] reference to non-existing vertex " << std::get<0>(edge) << std::endl; continue; } for (const auto &way: std::get<1>(edge)) { auto v = vertex_list.find(way.destination); if (v == vertex_list.end()) { std::cout << "[WARNING] reference to non-existing vertex " << way.destination << std::endl; continue; } switch (way.type) { case 0: cairo_set_source_rgb(cr.get(), 1.0, 0.0, 0.0); break; case 1: cairo_set_source_rgb(cr.get(), 0.0, 1.0, 0.0); break; case 2: cairo_set_source_rgb(cr.get(), 0.0, 0.0, 1.0); break; default: std::cout << "[WARNING] Wrong type of arc" << std::endl; } cairo_move_to(cr.get(), u->second.x - bbox.minx, height - (u->second.y - bbox.miny)); cairo_line_to(cr.get(), v->second.x - bbox.minx, height - (v->second.y - bbox.miny)); cairo_stroke(cr.get()); } } { auto status = cairo_surface_write_to_png(surface.get(), png_filename); cairo_status_to_exception(status); } }
bool RectangleShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const { return get_aabb().intersects_segment(p_begin,p_end,&r_point,&r_normal); }
rects::ltrb<float> item_button::iterate_children_attachments(bool draw, std::vector<vertex_triangle>* target, augs::rgba border_col) { auto item_sprite = item->get<components::sprite>(); const auto& gui_def = resource_manager.find(item_sprite.tex)->gui_sprite_def; item_sprite.flip_horizontally = gui_def.flip_horizontally; item_sprite.flip_vertically = gui_def.flip_vertically; item_sprite.rotation_offset = gui_def.rotation_offset; item_sprite.color.a = border_col.a; shared::state_for_drawing_renderable state; state.screen_space_mode = true; state.overridden_target_buffer = target; auto expanded_size = rc.get_size() - with_attachments_bbox.get_size(); state.renderable_transform.pos = get_absolute_xy() - with_attachments_bbox.get_position() + expanded_size/2 + vec2(1, 1); rects::ltrb<float> button_bbox = item_sprite.get_aabb(components::transform(), true); if (!is_container_open) { for_each_descendant(item, [this, draw, &item_sprite, &state, &button_bbox](augs::entity_id desc) { if (desc == item) return; auto parent_slot = desc->get<components::item>().current_slot; if (parent_slot.should_item_inside_keep_physical_body(item)) { auto attachment_sprite = desc->get<components::sprite>(); attachment_sprite.flip_horizontally = item_sprite.flip_horizontally; attachment_sprite.flip_vertically = item_sprite.flip_vertically; attachment_sprite.rotation_offset = item_sprite.rotation_offset; attachment_sprite.color.a = item_sprite.color.a; shared::state_for_drawing_renderable attachment_state = state; auto offset = parent_slot.sum_attachment_offsets_of_parents(desc) - item->get<components::item>().current_slot.sum_attachment_offsets_of_parents(item); if (attachment_sprite.flip_horizontally) { offset.pos.x = -offset.pos.x; offset.flip_rotation(); } if (attachment_sprite.flip_vertically) { offset.pos.y = -offset.pos.y; offset.flip_rotation(); } offset += item_sprite.size / 2; offset += -attachment_sprite.size / 2; attachment_state.renderable_transform += offset; if (draw) attachment_sprite.draw(attachment_state); rects::ltrb<float> attachment_bbox = attachment_sprite.get_aabb(offset, true); button_bbox.contain(attachment_bbox); } }); } if(draw) item_sprite.draw(state); return button_bbox; }
ltrb basic_renderable_mixin<C, D>::get_aabb(const interpolation_system& interp, const renderable_positioning_type type) const { const auto handle = *static_cast<const D*>(this); return get_aabb(handle.viewing_transform(interp, true), type); }
ltrb basic_renderable_mixin<C, D>::get_aabb(const renderable_positioning_type type) const { const auto handle = *static_cast<const D*>(this); return get_aabb(handle.logic_transform(), type); }