int BroadPhaseBasic::cull_segment(const Vector3 &p_from, const Vector3 &p_to, CollisionObjectSW **p_results, int p_max_results, int *p_result_indices) { int rc = 0; for (Map<ID, Element>::Element *E = element_map.front(); E; E = E->next()) { const Rect3 aabb = E->get().aabb; if (aabb.intersects_segment(p_from, p_to)) { p_results[rc] = E->get().owner; p_result_indices[rc] = E->get().subindex; rc++; if (rc >= p_max_results) break; } } return rc; }
bool GridMapEditor::forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event) { if (!node) { return false; } if (edit_mode->get_selected()==0) { // regular click switch (p_event.type) { case InputEvent::MOUSE_BUTTON: { if (p_event.mouse_button.button_index==BUTTON_WHEEL_UP && (p_event.mouse_button.mod.command || p_event.mouse_button.mod.shift)) { if (p_event.mouse_button.pressed) floor->set_value( floor->get_value() +1); return true; //eaten } else if (p_event.mouse_button.button_index==BUTTON_WHEEL_DOWN && (p_event.mouse_button.mod.command || p_event.mouse_button.mod.shift)) { if (p_event.mouse_button.pressed) floor->set_value( floor->get_value() -1); return true; } if (p_event.mouse_button.pressed) { if (p_event.mouse_button.button_index==BUTTON_LEFT) { if (input_action==INPUT_DUPLICATE) { //paste _duplicate_paste(); input_action=INPUT_NONE; _update_duplicate_indicator(); } else if (p_event.mouse_button.mod.shift) { input_action=INPUT_SELECT; } else if (p_event.mouse_button.mod.command) input_action=INPUT_COPY; else { input_action=INPUT_PAINT; set_items.clear(); } } else if (p_event.mouse_button.button_index==BUTTON_RIGHT) if (input_action==INPUT_DUPLICATE) { input_action=INPUT_NONE; _update_duplicate_indicator(); } else { input_action=INPUT_ERASE; set_items.clear(); } else return false; return do_input_action(p_camera,Point2(p_event.mouse_button.x,p_event.mouse_button.y),true); } else { if ( (p_event.mouse_button.button_index==BUTTON_RIGHT && input_action==INPUT_ERASE) || (p_event.mouse_button.button_index==BUTTON_LEFT && input_action==INPUT_PAINT) ) { if (set_items.size()) { undo_redo->create_action("GridMap Paint"); for(List<SetItem>::Element *E=set_items.front();E;E=E->next()) { const SetItem &si=E->get(); undo_redo->add_do_method(node,"set_cell_item",si.pos.x,si.pos.y,si.pos.z,si.new_value,si.new_orientation); } for(List<SetItem>::Element *E=set_items.back();E;E=E->prev()) { const SetItem &si=E->get(); undo_redo->add_undo_method(node,"set_cell_item",si.pos.x,si.pos.y,si.pos.z,si.old_value,si.old_orientation); } undo_redo->commit_action(); } set_items.clear(); input_action=INPUT_NONE; return true; } if (p_event.mouse_button.button_index==BUTTON_LEFT && input_action!=INPUT_NONE) { set_items.clear(); input_action=INPUT_NONE; return true; } if (p_event.mouse_button.button_index==BUTTON_RIGHT && (input_action==INPUT_ERASE || input_action==INPUT_DUPLICATE)) { input_action=INPUT_NONE; return true; } } } break; case InputEvent::MOUSE_MOTION: { return do_input_action(p_camera,Point2(p_event.mouse_motion.x,p_event.mouse_motion.y),false); } break; } } else if (edit_mode->get_selected()==1) { //area mode, select an area switch (p_event.type) { case InputEvent::MOUSE_BUTTON: { if (p_event.mouse_button.button_index==BUTTON_LEFT && p_event.mouse_button.pressed) { Point2 point = Point2(p_event.mouse_motion.x,p_event.mouse_motion.y); Camera *camera = p_camera; Vector3 from = camera->project_ray_origin(point); Vector3 normal = camera->project_ray_normal(point); Transform local_xform = node->get_global_transform().affine_inverse(); from=local_xform.xform(from); normal=local_xform.basis.xform(normal).normalized(); List<int> areas; node->get_area_list(&areas); float min_d=1e10; int min_area=-1; for(List<int>::Element *E=areas.front();E;E=E->next()) { int area = E->get(); Rect3 aabb = node->area_get_bounds(area); aabb.pos*=node->get_cell_size(); aabb.size*=node->get_cell_size(); Vector3 rclip,rnormal; if (!aabb.intersects_segment(from,from+normal*10000,&rclip,&rnormal)) continue; float d = normal.dot(rclip); if (d<min_d) { min_d=d; min_area=area; } } selected_area=min_area; update_areas(); } } break; } } return false; }