本文整理汇总了C++中AABB::expand_to方法的典型用法代码示例。如果您正苦于以下问题:C++ AABB::expand_to方法的具体用法?C++ AABB::expand_to怎么用?C++ AABB::expand_to使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AABB
的用法示例。
在下文中一共展示了AABB::expand_to方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _setup
void HeightMapShapeSW::_setup(DVector<real_t> p_heights,int p_width,int p_depth,real_t p_cell_size) {
heights=p_heights;
width=p_width;
depth=p_depth;;
cell_size=p_cell_size;
DVector<real_t>::Read r = heights. read();
AABB aabb;
for(int i=0;i<depth;i++) {
for(int j=0;j<width;j++) {
float h = r[i*width+j];
Vector3 pos( j*cell_size, h, i*cell_size );
if (i==0 || j==0)
aabb.pos=pos;
else
aabb.expand_to(pos);
}
}
configure(aabb);
}
示例2: add_surface_from_mesh_data
void ArrayMesh::add_surface_from_mesh_data(const Geometry::MeshData &p_mesh_data) {
VisualServer::get_singleton()->mesh_add_surface_from_mesh_data(mesh, p_mesh_data);
AABB aabb;
for (int i = 0; i < p_mesh_data.vertices.size(); i++) {
if (i == 0)
aabb.position = p_mesh_data.vertices[i];
else
aabb.expand_to(p_mesh_data.vertices[i]);
}
Surface s;
s.aabb = aabb;
if (surfaces.size() == 0)
aabb = s.aabb;
else
aabb.merge_with(s.aabb);
_clear_triangle_mesh();
surfaces.push_back(s);
_change_notify();
emit_changed();
}
示例3: add_surface
void Mesh::add_surface(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes,bool p_alphasort) {
ERR_FAIL_COND(p_arrays.size()!=ARRAY_MAX);
Surface s;
VisualServer::get_singleton()->mesh_add_surface(mesh,(VisualServer::PrimitiveType)p_primitive, p_arrays,p_blend_shapes,p_alphasort);
surfaces.push_back(s);
/* make aABB? */ {
DVector<Vector3> vertices=p_arrays[ARRAY_VERTEX];
int len=vertices.size();
ERR_FAIL_COND(len==0);
DVector<Vector3>::Read r=vertices.read();
const Vector3 *vtx=r.ptr();
// check AABB
AABB aabb;
for (int i=0;i<len;i++) {
if (i==0)
aabb.pos=vtx[i];
else
aabb.expand_to(vtx[i]);
}
surfaces[surfaces.size()-1].aabb=aabb;
surfaces[surfaces.size()-1].alphasort=p_alphasort;
_recompute_aabb();
}
triangle_mesh=Ref<TriangleMesh>();
_change_notify();
}
示例4: add_surface_from_arrays
void ArrayMesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, uint32_t p_flags) {
ERR_FAIL_COND(p_arrays.size() != ARRAY_MAX);
Surface s;
VisualServer::get_singleton()->mesh_add_surface_from_arrays(mesh, (VisualServer::PrimitiveType)p_primitive, p_arrays, p_blend_shapes, p_flags);
surfaces.push_back(s);
/* make aABB? */ {
Variant arr = p_arrays[ARRAY_VERTEX];
PoolVector<Vector3> vertices = arr;
int len = vertices.size();
ERR_FAIL_COND(len == 0);
PoolVector<Vector3>::Read r = vertices.read();
const Vector3 *vtx = r.ptr();
// check AABB
AABB aabb;
for (int i = 0; i < len; i++) {
if (i == 0)
aabb.position = vtx[i];
else
aabb.expand_to(vtx[i]);
}
surfaces[surfaces.size() - 1].aabb = aabb;
surfaces[surfaces.size() - 1].is_2d = arr.get_type() == Variant::POOL_VECTOR2_ARRAY;
_recompute_aabb();
}
_clear_triangle_mesh();
_change_notify();
emit_changed();
}
示例5: dst_rect
//.........这里部分代码省略.........
Rect2i src_rect;
src_rect.size=s;
Point2i ofs=get_offset();
if (is_centered())
ofs-=s/2;
Rect2i dst_rect(ofs,s);
Rect2 final_rect;
Rect2 final_src_rect;
if (!texture->get_rect_region(dst_rect,src_rect,final_rect,final_src_rect))
return;
if (final_rect.size.x==0 || final_rect.size.y==0)
return;
Color color=_get_color_accum();
color.a*=get_opacity();
float pixel_size=get_pixel_size();
Vector2 vertices[4]={
(final_rect.pos+Vector2(0,final_rect.size.y)) * pixel_size,
(final_rect.pos+final_rect.size) * pixel_size,
(final_rect.pos+Vector2(final_rect.size.x,0)) * pixel_size,
final_rect.pos * pixel_size,
};
Vector2 uvs[4]={
final_src_rect.pos / tsize,
(final_src_rect.pos+Vector2(final_src_rect.size.x,0)) / tsize,
(final_src_rect.pos+final_src_rect.size) / tsize,
(final_src_rect.pos+Vector2(0,final_src_rect.size.y)) / tsize,
};
if (is_flipped_h()) {
SWAP(uvs[0],uvs[1]);
SWAP(uvs[2],uvs[3]);
}
if (is_flipped_v()) {
SWAP(uvs[0],uvs[3]);
SWAP(uvs[1],uvs[2]);
}
Vector3 normal;
int axis = get_axis();
normal[axis]=1.0;
RID mat = VS::get_singleton()->material_2d_get(get_draw_flag(FLAG_SHADED),get_draw_flag(FLAG_TRANSPARENT),get_alpha_cut_mode()==ALPHA_CUT_DISCARD,get_alpha_cut_mode()==ALPHA_CUT_OPAQUE_PREPASS);
VS::get_singleton()->immediate_set_material(immediate,mat);
VS::get_singleton()->immediate_begin(immediate,VS::PRIMITIVE_TRIANGLE_FAN,texture->get_rid());
int x_axis = ((axis + 1) % 3);
int y_axis = ((axis + 2) % 3);
if (axis!=Vector3::AXIS_Z) {
SWAP(x_axis,y_axis);
for(int i=0;i<4;i++) {
//uvs[i] = Vector2(1.0,1.0)-uvs[i];
//SWAP(vertices[i].x,vertices[i].y);
if (axis==Vector3::AXIS_Y) {
vertices[i].y = - vertices[i].y;
} else if (axis==Vector3::AXIS_X) {
vertices[i].x = - vertices[i].x;
}
}
}
AABB aabb;
for(int i=0;i<4;i++) {
VS::get_singleton()->immediate_normal(immediate,normal);
VS::get_singleton()->immediate_color(immediate,color);
VS::get_singleton()->immediate_uv(immediate,uvs[i]);
Vector3 vtx;
vtx[x_axis]=vertices[i][0];
vtx[y_axis]=vertices[i][1];
VS::get_singleton()->immediate_vertex(immediate,vtx);
if (i==0) {
aabb.pos=vtx;
aabb.size=Vector3();
} else {
aabb.expand_to(vtx);
}
}
set_aabb(aabb);
VS::get_singleton()->immediate_end(immediate);
}
示例6: dst_rect
//.........这里部分代码省略.........
Size2i s;
Rect2i src_rect;
if (region) {
s=region_rect.size;
src_rect=region_rect;
} else {
s = texture->get_size();
s=s/Size2i(hframes,vframes);
src_rect.size=s;
src_rect.pos.x+=(frame%hframes)*s.x;
src_rect.pos.y+=(frame/hframes)*s.y;
}
Point2i ofs=get_offset();
if (is_centered())
ofs-=s/2;
Rect2i dst_rect(ofs,s);
Rect2 final_rect;
Rect2 final_src_rect;
if (!texture->get_rect_region(dst_rect,src_rect,final_rect,final_src_rect))
return;
if (final_rect.size.x==0 || final_rect.size.y==0)
return;
Color color=_get_color_accum();
color.a*=get_opacity();
float pixel_size=get_pixel_size();
Vector2 vertices[4]={
(final_rect.pos+Vector2(0,final_rect.size.y)) * pixel_size,
(final_rect.pos+final_rect.size) * pixel_size,
(final_rect.pos+Vector2(final_rect.size.x,0)) * pixel_size,
final_rect.pos * pixel_size,
};
Vector2 uvs[4]={
final_src_rect.pos / tsize,
(final_src_rect.pos+Vector2(final_src_rect.size.x,0)) / tsize,
(final_src_rect.pos+final_src_rect.size) / tsize,
(final_src_rect.pos+Vector2(0,final_src_rect.size.y)) / tsize,
};
if (is_flipped_h()) {
SWAP(uvs[0],uvs[1]);
SWAP(uvs[2],uvs[3]);
}
if (is_flipped_v()) {
SWAP(uvs[0],uvs[3]);
SWAP(uvs[1],uvs[2]);
}
Vector3 normal;
int axis = get_axis();
normal[axis]=1.0;
RID mat = VS::get_singleton()->material_2d_get(get_draw_flag(FLAG_SHADED),get_draw_flag(FLAG_TRANSPARENT),get_alpha_cut_mode()==ALPHA_CUT_DISCARD,get_alpha_cut_mode()==ALPHA_CUT_OPAQUE_PREPASS);
VS::get_singleton()->immediate_set_material(immediate,mat);
VS::get_singleton()->immediate_begin(immediate,VS::PRIMITIVE_TRIANGLE_FAN,texture->get_rid());
int x_axis = ((axis + 1) % 3);
int y_axis = ((axis + 2) % 3);
AABB aabb;
for(int i=0;i<4;i++) {
VS::get_singleton()->immediate_normal(immediate,normal);
VS::get_singleton()->immediate_color(immediate,color);
VS::get_singleton()->immediate_uv(immediate,uvs[i]);
Vector3 vtx;
vtx[x_axis]=vertices[i][x_axis];
vtx[y_axis]=vertices[i][y_axis];
VS::get_singleton()->immediate_vertex(immediate,vtx);
if (i==0) {
aabb.pos=vtx;
aabb.size=Vector3();
} else {
aabb.expand_to(vtx);
}
}
set_aabb(aabb);
VS::get_singleton()->immediate_end(immediate);
}
示例7: dst_rect
//.........这里部分代码省略.........
if (is_centered())
ofs -= s / 2;
Rect2i dst_rect(ofs, s);
Rect2 final_rect;
Rect2 final_src_rect;
if (!texture->get_rect_region(dst_rect, src_rect, final_rect, final_src_rect))
return;
if (final_rect.size.x == 0 || final_rect.size.y == 0)
return;
Color color = _get_color_accum();
color.a *= get_opacity();
float pixel_size = get_pixel_size();
Vector2 vertices[4] = {
(final_rect.position + Vector2(0, final_rect.size.y)) * pixel_size,
(final_rect.position + final_rect.size) * pixel_size,
(final_rect.position + Vector2(final_rect.size.x, 0)) * pixel_size,
final_rect.position * pixel_size,
};
Vector2 src_tsize = tsize;
// Properly setup UVs for impostor textures (AtlasTexture).
Ref<AtlasTexture> atlas_tex = texture;
if (atlas_tex != NULL) {
src_tsize[0] = atlas_tex->get_atlas()->get_width();
src_tsize[1] = atlas_tex->get_atlas()->get_height();
}
Vector2 uvs[4] = {
final_src_rect.position / src_tsize,
(final_src_rect.position + Vector2(final_src_rect.size.x, 0)) / src_tsize,
(final_src_rect.position + final_src_rect.size) / src_tsize,
(final_src_rect.position + Vector2(0, final_src_rect.size.y)) / src_tsize,
};
if (is_flipped_h()) {
SWAP(uvs[0], uvs[1]);
SWAP(uvs[2], uvs[3]);
}
if (is_flipped_v()) {
SWAP(uvs[0], uvs[3]);
SWAP(uvs[1], uvs[2]);
}
Vector3 normal;
int axis = get_axis();
normal[axis] = 1.0;
RID mat = SpatialMaterial::get_material_rid_for_2d(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_draw_flag(FLAG_DOUBLE_SIDED), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS);
VS::get_singleton()->immediate_set_material(immediate, mat);
VS::get_singleton()->immediate_begin(immediate, VS::PRIMITIVE_TRIANGLE_FAN, texture->get_rid());
int x_axis = ((axis + 1) % 3);
int y_axis = ((axis + 2) % 3);
if (axis != Vector3::AXIS_Z) {
SWAP(x_axis, y_axis);
for (int i = 0; i < 4; i++) {
//uvs[i] = Vector2(1.0,1.0)-uvs[i];
//SWAP(vertices[i].x,vertices[i].y);
if (axis == Vector3::AXIS_Y) {
vertices[i].y = -vertices[i].y;
} else if (axis == Vector3::AXIS_X) {
vertices[i].x = -vertices[i].x;
}
}
}
AABB aabb;
for (int i = 0; i < 4; i++) {
VS::get_singleton()->immediate_normal(immediate, normal);
VS::get_singleton()->immediate_color(immediate, color);
VS::get_singleton()->immediate_uv(immediate, uvs[i]);
Vector3 vtx;
vtx[x_axis] = vertices[i][0];
vtx[y_axis] = vertices[i][1];
VS::get_singleton()->immediate_vertex(immediate, vtx);
if (i == 0) {
aabb.position = vtx;
aabb.size = Vector3();
} else {
aabb.expand_to(vtx);
}
}
set_aabb(aabb);
VS::get_singleton()->immediate_end(immediate);
}
示例8: build
Error QuickHull::build(const Vector<Vector3> &p_points, Geometry::MeshData &r_mesh) {
static const real_t over_tolerance = 0.0001;
/* CREATE AABB VOLUME */
AABB aabb;
for (int i = 0; i < p_points.size(); i++) {
if (i == 0) {
aabb.pos = p_points[i];
} else {
aabb.expand_to(p_points[i]);
}
}
if (aabb.size == Vector3()) {
return ERR_CANT_CREATE;
}
Vector<bool> valid_points;
valid_points.resize(p_points.size());
Set<Vector3> valid_cache;
for (int i = 0; i < p_points.size(); i++) {
Vector3 sp = p_points[i].snapped(0.0001);
if (valid_cache.has(sp)) {
valid_points[i] = false;
//print_line("INVALIDATED: "+itos(i));
} else {
valid_points[i] = true;
valid_cache.insert(sp);
}
}
/* CREATE INITIAL SIMPLEX */
int longest_axis = aabb.get_longest_axis_index();
//first two vertices are the most distant
int simplex[4];
{
real_t max, min;
for (int i = 0; i < p_points.size(); i++) {
if (!valid_points[i])
continue;
float d = p_points[i][longest_axis];
if (i == 0 || d < min) {
simplex[0] = i;
min = d;
}
if (i == 0 || d > max) {
simplex[1] = i;
max = d;
}
}
}
//third vertex is one most further away from the line
{
float maxd;
Vector3 rel12 = p_points[simplex[0]] - p_points[simplex[1]];
for (int i = 0; i < p_points.size(); i++) {
if (!valid_points[i])
continue;
Vector3 n = rel12.cross(p_points[simplex[0]] - p_points[i]).cross(rel12).normalized();
real_t d = Math::abs(n.dot(p_points[simplex[0]]) - n.dot(p_points[i]));
if (i == 0 || d > maxd) {
maxd = d;
simplex[2] = i;
}
}
}
//fourth vertex is the one most further away from the plane
{
float maxd;
Plane p(p_points[simplex[0]], p_points[simplex[1]], p_points[simplex[2]]);
for (int i = 0; i < p_points.size(); i++) {
if (!valid_points[i])
continue;
real_t d = Math::abs(p.distance_to(p_points[i]));
if (i == 0 || d > maxd) {
//.........这里部分代码省略.........