当前位置: 首页>>代码示例>>C++>>正文


C++ Rect2::expand_to方法代码示例

本文整理汇总了C++中Rect2::expand_to方法的典型用法代码示例。如果您正苦于以下问题:C++ Rect2::expand_to方法的具体用法?C++ Rect2::expand_to怎么用?C++ Rect2::expand_to使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rect2的用法示例。


在下文中一共展示了Rect2::expand_to方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

Rect2 LineShape2D::get_rect() const {

	Vector2 point = get_d() * get_normal();

	Vector2 l1[2] = { point - get_normal().tangent() * 100, point + get_normal().tangent() * 100 };
	Vector2 l2[2] = { point, point + get_normal() * 30 };
	Rect2 rect;
	rect.pos = l1[0];
	rect.expand_to(l1[1]);
	rect.expand_to(l2[0]);
	rect.expand_to(l2[1]);
	return rect;
}
开发者ID:allkhor,项目名称:godot,代码行数:13,代码来源:shape_line_2d.cpp

示例2: _draw_cos_line

void GraphEdit::_draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color) {

	static const int steps = 20;

	Rect2 r;
	r.pos=p_from;
	r.expand_to(p_to);
	Vector2 sign=Vector2((p_from.x < p_to.x) ? 1 : -1,(p_from.y < p_to.y) ? 1 : -1);
	bool flip = sign.x * sign.y < 0;

	Vector2 prev;
	for(int i=0;i<=steps;i++) {

		float d = i/float(steps);
		float c=-Math::cos(d*Math_PI) * 0.5+0.5;
		if (flip)
			c=1.0-c;
		Vector2 p = r.pos+Vector2(d*r.size.width,c*r.size.height);

		if (i>0) {

			top_layer->draw_line(prev,p,p_color,2);
		}

		prev=p;
	}
}
开发者ID:Scrik,项目名称:godot,代码行数:27,代码来源:graph_edit.cpp

示例3:

void ConvexPolygonShape2DSW::set_data(const Variant& p_data) {

	ERR_FAIL_COND(p_data.get_type()!=Variant::VECTOR2_ARRAY && p_data.get_type()!=Variant::REAL_ARRAY);


	if (points)
		memdelete_arr(points);
	points=NULL;
	point_count=0;

	if (p_data.get_type()==Variant::VECTOR2_ARRAY) {
		DVector<Vector2> arr=p_data;
		ERR_FAIL_COND(arr.size()==0);
		point_count=arr.size();
		points = memnew_arr(Point,point_count);
		DVector<Vector2>::Read r = arr.read();

		for(int i=0;i<point_count;i++) {
			points[i].pos=r[i];
		}

		for(int i=0;i<point_count;i++) {

			Vector2 p = points[i].pos;
			Vector2 pn = points[(i+1)%point_count].pos;
			points[i].normal=(pn-p).tangent().normalized();
		}
	} else {

		DVector<real_t> dvr = p_data;
		point_count=dvr.size()/4;
		ERR_FAIL_COND(point_count==0);

		points = memnew_arr(Point,point_count);
		DVector<real_t>::Read r = dvr.read();

		for(int i=0;i<point_count;i++) {

			int idx=i<<2;
			points[i].pos.x=r[idx+0];
			points[i].pos.y=r[idx+1];
			points[i].normal.x=r[idx+2];
			points[i].normal.y=r[idx+3];

		}
	}


	ERR_FAIL_COND(point_count==0);
	Rect2 aabb;
	aabb.pos=points[0].pos;
	for(int i=1;i<point_count;i++)
		aabb.expand_to(points[i].pos);

	configure(aabb);
}
开发者ID:19Staceys,项目名称:godot,代码行数:56,代码来源:shape_2d_sw.cpp

示例4:

real_t ConvexPolygonShape2DSW::get_moment_of_inertia(float p_mass,const Vector2& p_scale) const {

	Rect2 aabb;
	aabb.pos=points[0].pos*p_scale;
	for(int i=0;i<point_count;i++) {

		aabb.expand_to(points[i].pos*p_scale);
	}

	return p_mass*aabb.size.dot(aabb.size)/12.0f + p_mass * (aabb.pos+aabb.size*0.5).length_squared();
}
开发者ID:03050903,项目名称:godot,代码行数:11,代码来源:shape_2d_sw.cpp

示例5:

Rect2 Line2D::_edit_get_rect() const {

	if (_points.size() == 0)
		return Rect2(0, 0, 0, 0);
	Vector2 d = Vector2(_width, _width);
	Rect2 aabb = Rect2(_points[0] - d, 2 * d);
	for (int i = 1; i < _points.size(); i++) {
		aabb.expand_to(_points[i] - d);
		aabb.expand_to(_points[i] + d);
	}
	return aabb;
}
开发者ID:KellyThomas,项目名称:godot,代码行数:12,代码来源:line_2d.cpp

示例6:

Rect2 ConvexPolygonShape2D::get_rect() const {

	Rect2 rect;
	for (int i = 0; i < points.size(); i++) {
		if (i == 0)
			rect.position = points[i];
		else
			rect.expand_to(points[i]);
	}

	return rect;
}
开发者ID:KellyThomas,项目名称:godot,代码行数:12,代码来源:convex_polygon_shape_2d.cpp

示例7: _draw_cos_line

void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color) {

#if 1

	//cubic bezier code
	float diff = p_to.x - p_from.x;
	float cp_offset;
	int cp_len = get_constant("bezier_len_pos");
	int cp_neg_len = get_constant("bezier_len_neg");

	if (diff > 0) {
		cp_offset = MAX(cp_len, diff * 0.5);
	} else {
		cp_offset = MAX(MIN(cp_len - diff, cp_neg_len), -diff * 0.5);
	}

	Vector2 c1 = Vector2(cp_offset * zoom, 0);
	Vector2 c2 = Vector2(-cp_offset * zoom, 0);

	int lines = 0;
	_bake_segment2d(p_where, 0, 1, p_from, c1, p_to, c2, 0, 3, 9, 8, p_color, p_to_color, lines);

#else

	static const int steps = 20;

	//old cosine code
	Rect2 r;
	r.pos = p_from;
	r.expand_to(p_to);
	Vector2 sign = Vector2((p_from.x < p_to.x) ? 1 : -1, (p_from.y < p_to.y) ? 1 : -1);
	bool flip = sign.x * sign.y < 0;

	Vector2 prev;
	for (int i = 0; i <= steps; i++) {

		float d = i / float(steps);
		float c = -Math::cos(d * Math_PI) * 0.5 + 0.5;
		if (flip)
			c = 1.0 - c;
		Vector2 p = r.pos + Vector2(d * r.size.width, c * r.size.height);

		if (i > 0) {

			p_where->draw_line(prev, p, p_color.linear_interpolate(p_to_color, d), 2);
		}

		prev = p;
	}
#endif
}
开发者ID:MattUV,项目名称:godot,代码行数:51,代码来源:graph_edit.cpp

示例8: _recompute_rect_cache

void TileMap::_recompute_rect_cache() {


#ifdef DEBUG_ENABLED

	if (!rect_cache_dirty)
		return;

	Rect2 r_total;
	for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {


		Rect2 r;
		r.pos=_map_to_world(E->key().x*_get_quadrant_size(), E->key().y*_get_quadrant_size());
		r.expand_to( _map_to_world(E->key().x*_get_quadrant_size()+_get_quadrant_size(), E->key().y*_get_quadrant_size()) );
		r.expand_to( _map_to_world(E->key().x*_get_quadrant_size()+_get_quadrant_size(), E->key().y*_get_quadrant_size()+_get_quadrant_size()) );
		r.expand_to( _map_to_world(E->key().x*_get_quadrant_size(), E->key().y*_get_quadrant_size()+_get_quadrant_size()) );
		if (E==quadrant_map.front())
			r_total=r;
		else
			r_total=r_total.merge(r);

	}

	if (r_total==Rect2()) {
		rect_cache=Rect2(-10,-10,20,20);
	} else {
		rect_cache=r_total.grow(MAX(cell_size.x,cell_size.y)*_get_quadrant_size());
	}

	item_rect_changed();

	rect_cache_dirty=false;
#endif


}
开发者ID:FEDE0D,项目名称:godot,代码行数:37,代码来源:tile_map.cpp

示例9:

Rect2 ConcavePolygonShape2D::get_rect() const {

	PoolVector<Vector2> s = get_segments();
	int len = s.size();
	if (len == 0)
		return Rect2();

	Rect2 rect;

	PoolVector<Vector2>::Read r = s.read();
	for (int i = 0; i < len; i++) {
		if (i == 0)
			rect.position = r[i];
		else
			rect.expand_to(r[i]);
	}

	return rect;
}
开发者ID:KelinciFX,项目名称:godot,代码行数:19,代码来源:concave_polygon_shape_2d.cpp

示例10:

Rect2 Path2D::_edit_get_rect() const {

	if (!curve.is_valid() || curve->get_point_count() == 0)
		return Rect2(0, 0, 0, 0);

	Rect2 aabb = Rect2(curve->get_point_position(0), Vector2(0, 0));

	for (int i = 0; i < curve->get_point_count(); i++) {

		for (int j = 0; j <= 8; j++) {

			real_t frac = j / 8.0;
			Vector2 p = curve->interpolate(i, frac);
			aabb.expand_to(p);
		}
	}

	return aabb;
}
开发者ID:SaracenOne,项目名称:godot,代码行数:19,代码来源:path_2d.cpp

示例11: texmat

void Polygon2D::_notification(int p_what) {


	switch(p_what) {

		case NOTIFICATION_DRAW: {

			if (polygon.size()<3)
				return;

			Vector<Vector2> points;
			Vector<Vector2> uvs;

			points.resize(polygon.size());

			int len = points.size();
			{

				DVector<Vector2>::Read polyr =polygon.read();
				for(int i=0;i<len;i++) {
					points[i]=polyr[i]+offset;
				}
			}

			if (invert) {

				Rect2 bounds;
				int highest_idx=-1;
				float highest_y=-1e20;
				float sum=0;

				for(int i=0;i<len;i++) {
					if (i==0)
						bounds.pos=points[i];
					else
						bounds.expand_to(points[i]);
					if (points[i].y>highest_y) {
						highest_idx=i;
						highest_y=points[i].y;
					}
					int ni=(i+1)%len;
					sum+=(points[ni].x-points[i].x)*(points[ni].y+points[i].y);
				}

				bounds=bounds.grow(invert_border);

				Vector2 ep[7]={
					Vector2(points[highest_idx].x,points[highest_idx].y+invert_border),
					Vector2(bounds.pos+bounds.size),
					Vector2(bounds.pos+Vector2(bounds.size.x,0)),
					Vector2(bounds.pos),
					Vector2(bounds.pos+Vector2(0,bounds.size.y)),
					Vector2(points[highest_idx].x-CMP_EPSILON,points[highest_idx].y+invert_border),
					Vector2(points[highest_idx].x-CMP_EPSILON,points[highest_idx].y),
				};


				if (sum>0) {
					SWAP(ep[1],ep[4]);
					SWAP(ep[2],ep[3]);
					SWAP(ep[5],ep[0]);
					SWAP(ep[6],points[highest_idx]);
				}

				points.resize(points.size()+7);
				for(int i=points.size()-1;i>=highest_idx+7;i--) {

					points[i]=points[i-7];
				}

				for(int i=0;i<7;i++) {

					points[highest_idx+i+1]=ep[i];
				}


				len=points.size();

			}

			if (texture.is_valid()) {

				Matrix32 texmat(tex_rot,tex_ofs);
				texmat.scale(tex_scale);
				Size2 tex_size=Vector2(1,1);

				tex_size=texture->get_size();
				uvs.resize(points.size());

				if (points.size()==uv.size()) {

					DVector<Vector2>::Read uvr = uv.read();

					for(int i=0;i<len;i++) {
						uvs[i]=texmat.xform(uvr[i])/tex_size;
					}

				} else {
					for(int i=0;i<len;i++) {
						uvs[i]=texmat.xform(points[i])/tex_size;
//.........这里部分代码省略.........
开发者ID:AMG194,项目名称:godot,代码行数:101,代码来源:polygon_2d.cpp

示例12: _canvas_draw

void TileMapEditor::_canvas_draw() {

	if (!node)
		return;

	Matrix32 cell_xf = node->get_cell_transform();

	Matrix32 xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform();
	Matrix32 xform_inv = xform.affine_inverse();


	Size2 screen_size=canvas_item_editor->get_size();
	{
		Rect2 aabb;
		aabb.pos=node->world_to_map(xform_inv.xform(Vector2()));
		aabb.expand_to(node->world_to_map(xform_inv.xform(Vector2(0,screen_size.height))));
		aabb.expand_to(node->world_to_map(xform_inv.xform(Vector2(screen_size.width,0))));
		aabb.expand_to(node->world_to_map(xform_inv.xform(screen_size)));
		Rect2i si=aabb.grow(1.0);

		if (node->get_half_offset()!=TileMap::HALF_OFFSET_X) {

			int max_lines=2000; //avoid crash if size too smal

			for (int i=(si.pos.x)-1;i<=(si.pos.x+si.size.x);i++) {

				Vector2 from = xform.xform(node->map_to_world(Vector2(i,si.pos.y)));
				Vector2 to = xform.xform(node->map_to_world(Vector2(i,si.pos.y+si.size.y+1)));

				Color col=i==0?Color(1,0.8,0.2,0.5):Color(1,0.3,0.1,0.2);
				canvas_item_editor->draw_line(from,to,col,1);
				if (max_lines--==0)
					break;
			}
		} else {

			int max_lines=10000; //avoid crash if size too smal

			for (int i=(si.pos.x)-1;i<=(si.pos.x+si.size.x);i++) {

				for (int j=(si.pos.y)-1;j<=(si.pos.y+si.size.y);j++) {

					Vector2 ofs;
					if (ABS(j)&1) {
						ofs=cell_xf[0]*0.5;
					}

					Vector2 from = xform.xform(node->map_to_world(Vector2(i,j),true)+ofs);
					Vector2 to = xform.xform(node->map_to_world(Vector2(i,j+1),true)+ofs);
					Color col=i==0?Color(1,0.8,0.2,0.5):Color(1,0.3,0.1,0.2);
					canvas_item_editor->draw_line(from,to,col,1);

					if (max_lines--==0)
						break;

				}

			}
		}

		int max_lines=10000; //avoid crash if size too smal

		if (node->get_half_offset()!=TileMap::HALF_OFFSET_Y) {

			for (int i=(si.pos.y)-1;i<=(si.pos.y+si.size.y);i++) {

				Vector2 from = xform.xform(node->map_to_world(Vector2(si.pos.x,i)));
				Vector2 to = xform.xform(node->map_to_world(Vector2(si.pos.x+si.size.x+1,i)));

				Color col=i==0?Color(1,0.8,0.2,0.5):Color(1,0.3,0.1,0.2);
				canvas_item_editor->draw_line(from,to,col,1);

				if (max_lines--==0)
					break;

			}
		} else {


			for (int i=(si.pos.y)-1;i<=(si.pos.y+si.size.y);i++) {

				for (int j=(si.pos.x)-1;j<=(si.pos.x+si.size.x);j++) {

					Vector2 ofs;
					if (ABS(j)&1) {
						ofs=cell_xf[1]*0.5;
					}

					Vector2 from = xform.xform(node->map_to_world(Vector2(j,i),true)+ofs);
					Vector2 to = xform.xform(node->map_to_world(Vector2(j+1,i),true)+ofs);
					Color col=i==0?Color(1,0.8,0.2,0.5):Color(1,0.3,0.1,0.2);
					canvas_item_editor->draw_line(from,to,col,1);

					if (max_lines--==0)
						break;

				}
			}
		}
	}
//.........这里部分代码省略.........
开发者ID:baifang,项目名称:godot,代码行数:101,代码来源:tile_map_editor_plugin.cpp

示例13: _canvas_draw

void TileMapEditor::_canvas_draw() {

	if (!node)
		return;

	Size2 cell_size=node->get_cell_size();
	Matrix32 cell_xf = node->get_cell_transform();

	Matrix32 xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform();
	Matrix32 xform_inv = xform.affine_inverse();


	Size2 screen_size=canvas_item_editor->get_size();
	{
		Rect2 aabb;
		aabb.pos=node->world_to_map(xform_inv.xform(Vector2()));
		aabb.expand_to(node->world_to_map(xform_inv.xform(Vector2(0,screen_size.height))));
		aabb.expand_to(node->world_to_map(xform_inv.xform(Vector2(screen_size.width,0))));
		aabb.expand_to(node->world_to_map(xform_inv.xform(screen_size)));
		Rect2i si=aabb.grow(1.0);

		if (node->get_half_offset()!=TileMap::HALF_OFFSET_X) {

			for(int i=(si.pos.x)-1;i<=(si.pos.x+si.size.x);i++) {

				Vector2 from = xform.xform(node->map_to_world(Vector2(i,si.pos.y)));
				Vector2 to = xform.xform(node->map_to_world(Vector2(i,si.pos.y+si.size.y+1)));

				Color col=i==0?Color(1,0.8,0.2,0.5):Color(1,0.3,0.1,0.2);
				canvas_item_editor->draw_line(from,to,col,1);

			}
		} else {


			for(int i=(si.pos.x)-1;i<=(si.pos.x+si.size.x);i++) {

				for(int j=(si.pos.y)-1;j<=(si.pos.y+si.size.y);j++) {

					Vector2 ofs;
					if (ABS(j)&1) {
						ofs=cell_xf[0]*0.5;
					}

					Vector2 from = xform.xform(node->map_to_world(Vector2(i,j),true)+ofs);
					Vector2 to = xform.xform(node->map_to_world(Vector2(i,j+1),true)+ofs);
					Color col=i==0?Color(1,0.8,0.2,0.5):Color(1,0.3,0.1,0.2);
					canvas_item_editor->draw_line(from,to,col,1);
				}

			}
		}

		if (node->get_half_offset()!=TileMap::HALF_OFFSET_Y) {

			for(int i=(si.pos.y)-1;i<=(si.pos.y+si.size.y);i++) {

				Vector2 from = xform.xform(node->map_to_world(Vector2(si.pos.x,i)));
				Vector2 to = xform.xform(node->map_to_world(Vector2(si.pos.x+si.size.x+1,i)));

				Color col=i==0?Color(1,0.8,0.2,0.5):Color(1,0.3,0.1,0.2);
				canvas_item_editor->draw_line(from,to,col,1);

			}
		} else {


			for(int i=(si.pos.y)-1;i<=(si.pos.y+si.size.y);i++) {

				for(int j=(si.pos.x)-1;j<=(si.pos.x+si.size.x);j++) {

					Vector2 ofs;
					if (ABS(j)&1) {
						ofs=cell_xf[1]*0.5;
					}

					Vector2 from = xform.xform(node->map_to_world(Vector2(j,i),true)+ofs);
					Vector2 to = xform.xform(node->map_to_world(Vector2(j+1,i),true)+ofs);
					Color col=i==0?Color(1,0.8,0.2,0.5):Color(1,0.3,0.1,0.2);
					canvas_item_editor->draw_line(from,to,col,1);
				}

			}



		}
/*
	for(int i=(si.pos.y/cell_size.y)-1;i<=(si.pos.y+si.size.y)/cell_size.y;i++) {

		int ofs = i*cell_size.y;
		Color col=i==0?Color(1,0.8,0.2,0.5):Color(1,0.3,0.1,0.2);
		canvas_item_editor->draw_line(xform.xform(Point2(si.pos.x,ofs)),xform.xform(Point2(si.pos.x+si.size.x,ofs)),col,1);*/
	}


	if (selection_active) {

		Vector<Vector2> points;
		points.push_back( xform.xform( node->map_to_world(( selection.pos ) )));
//.........这里部分代码省略.........
开发者ID:AMG194,项目名称:godot,代码行数:101,代码来源:tile_map_editor_plugin.cpp

示例14: _polygon_draw

void CollisionPolygonEditor::_polygon_draw() {

	if (!node)
		return;

	Vector<Vector2> poly;

	if (wip_active)
		poly=wip;
	else
		poly=node->get_polygon();



	int len = poly.size();
	float depth = node->get_depth()*0.5;

	imgeom->clear();
	imgeom->set_material_override(line_material);
	imgeom->begin(Mesh::PRIMITIVE_LINES,Ref<Texture>());


	Rect2 rect;

	for(int i=0;i<poly.size();i++) {


		Vector2 p,p2;
		p = i==edited_point ? edited_point_pos : poly[i];
		if ((wip_active && i==poly.size()-1) || (((i+1)%poly.size())==edited_point))
			p2=edited_point_pos;
		else
			p2 = poly[(i+1)%poly.size()];

		if (i==0)
			rect.pos=p;
		else
			rect.expand_to(p);

		Vector3 point = Vector3(p.x,p.y,depth);
		Vector3 next_point = Vector3(p2.x,p2.y,depth);

		imgeom->set_color(Color(1,0.3,0.1,0.8));
		imgeom->add_vertex(point);
		imgeom->set_color(Color(1,0.3,0.1,0.8));
		imgeom->add_vertex(next_point);

		//Color col=Color(1,0.3,0.1,0.8);
		//vpc->draw_line(point,next_point,col,2);
		//vpc->draw_texture(handle,point-handle->get_size()*0.5);
	}

	rect=rect.grow(1);

	AABB r;
	r.pos.x=rect.pos.x;
	r.pos.y=rect.pos.y;
	r.pos.z=depth;
	r.size.x=rect.size.x;
	r.size.y=rect.size.y;
	r.size.z=0;

	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos);
	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos+Vector3(0.3,0,0));
	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos);
	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos+Vector3(0.0,0.3,0));

	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos+Vector3(r.size.x,0,0));
	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos+Vector3(r.size.x,0,0)-Vector3(0.3,0,0));
	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos+Vector3(r.size.x,0,0));
	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos+Vector3(r.size.x,0,0)+Vector3(0,0.3,0));

	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos+Vector3(0,r.size.y,0));
	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos+Vector3(0,r.size.y,0)-Vector3(0,0.3,0));
	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos+Vector3(0,r.size.y,0));
	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos+Vector3(0,r.size.y,0)+Vector3(0.3,0,0));

	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos+r.size);
	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos+r.size-Vector3(0.3,0,0));
	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos+r.size);
	imgeom->set_color(Color(0.8,0.8,0.8,0.2));
	imgeom->add_vertex(r.pos+r.size-Vector3(0.0,0.3,0));

	imgeom->end();

//.........这里部分代码省略.........
开发者ID:a12n,项目名称:godot,代码行数:101,代码来源:collision_polygon_editor_plugin.cpp

示例15: texmat

void Polygon2D::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_DRAW: {

			if (polygon.size() < 3)
				return;

			Skeleton2D *skeleton_node = NULL;
			if (has_node(skeleton)) {
				skeleton_node = Object::cast_to<Skeleton2D>(get_node(skeleton));
			}

			ObjectID new_skeleton_id = 0;

			if (skeleton_node) {
				VS::get_singleton()->canvas_item_attach_skeleton(get_canvas_item(), skeleton_node->get_skeleton());
				new_skeleton_id = skeleton_node->get_instance_id();
			} else {
				VS::get_singleton()->canvas_item_attach_skeleton(get_canvas_item(), RID());
			}

			if (new_skeleton_id != current_skeleton_id) {
				Object *old_skeleton = ObjectDB::get_instance(current_skeleton_id);
				if (old_skeleton) {
					old_skeleton->disconnect("bone_setup_changed", this, "_skeleton_bone_setup_changed");
				}

				if (skeleton_node) {
					skeleton_node->connect("bone_setup_changed", this, "_skeleton_bone_setup_changed");
				}

				current_skeleton_id = new_skeleton_id;
			}

			Vector<Vector2> points;
			Vector<Vector2> uvs;
			Vector<int> bones;
			Vector<float> weights;

			int len = polygon.size();
			if ((invert || polygons.size() == 0) && internal_vertices > 0) {
				//if no polygons are around, internal vertices must not be drawn, else let them be
				len -= internal_vertices;
			}

			if (len <= 0) {
				return;
			}
			points.resize(len);

			{

				PoolVector<Vector2>::Read polyr = polygon.read();
				for (int i = 0; i < len; i++) {
					points.write[i] = polyr[i] + offset;
				}
			}

			if (invert) {

				Rect2 bounds;
				int highest_idx = -1;
				float highest_y = -1e20;
				float sum = 0;

				for (int i = 0; i < len; i++) {
					if (i == 0)
						bounds.position = points[i];
					else
						bounds.expand_to(points[i]);
					if (points[i].y > highest_y) {
						highest_idx = i;
						highest_y = points[i].y;
					}
					int ni = (i + 1) % len;
					sum += (points[ni].x - points[i].x) * (points[ni].y + points[i].y);
				}

				bounds = bounds.grow(invert_border);

				Vector2 ep[7] = {
					Vector2(points[highest_idx].x, points[highest_idx].y + invert_border),
					Vector2(bounds.position + bounds.size),
					Vector2(bounds.position + Vector2(bounds.size.x, 0)),
					Vector2(bounds.position),
					Vector2(bounds.position + Vector2(0, bounds.size.y)),
					Vector2(points[highest_idx].x - CMP_EPSILON, points[highest_idx].y + invert_border),
					Vector2(points[highest_idx].x - CMP_EPSILON, points[highest_idx].y),
				};

				if (sum > 0) {
					SWAP(ep[1], ep[4]);
					SWAP(ep[2], ep[3]);
					SWAP(ep[5], ep[0]);
					SWAP(ep[6], points.write[highest_idx]);
				}

				points.resize(points.size() + 7);
//.........这里部分代码省略.........
开发者ID:timoschwarzer,项目名称:godot,代码行数:101,代码来源:polygon_2d.cpp


注:本文中的Rect2::expand_to方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。