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


C++ Matrix32::set_origin方法代码示例

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


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

示例1: if

Map<TileMap::PosKey,TileMap::Quadrant>::Element *TileMap::_create_quadrant(const PosKey& p_qk) {

	Matrix32 xform;
	//xform.set_origin(Point2(p_qk.x,p_qk.y)*cell_size*quadrant_size);
	Quadrant q;
	q.pos = _map_to_world(p_qk.x*_get_quadrant_size(),p_qk.y*_get_quadrant_size());
	q.pos+=get_cell_draw_offset();
	if (tile_origin==TILE_ORIGIN_CENTER)
		q.pos+=cell_size/2;
	else if (tile_origin==TILE_ORIGIN_BOTTOM_LEFT)
		q.pos.y+=cell_size.y;
	

	xform.set_origin( q.pos );
//	q.canvas_item = VisualServer::get_singleton()->canvas_item_create();
	q.body=Physics2DServer::get_singleton()->body_create(use_kinematic?Physics2DServer::BODY_MODE_KINEMATIC:Physics2DServer::BODY_MODE_STATIC);
	Physics2DServer::get_singleton()->body_attach_object_instance_ID(q.body,get_instance_ID());
	Physics2DServer::get_singleton()->body_set_layer_mask(q.body,collision_layer);
	Physics2DServer::get_singleton()->body_set_collision_mask(q.body,collision_mask);
	Physics2DServer::get_singleton()->body_set_param(q.body,Physics2DServer::BODY_PARAM_FRICTION,friction);
	Physics2DServer::get_singleton()->body_set_param(q.body,Physics2DServer::BODY_PARAM_BOUNCE,bounce);

	if (is_inside_tree()) {
		xform = get_global_transform() * xform;
		RID space = get_world_2d()->get_space();
		Physics2DServer::get_singleton()->body_set_space(q.body,space);
	}

	Physics2DServer::get_singleton()->body_set_state(q.body,Physics2DServer::BODY_STATE_TRANSFORM,xform);

	rect_cache_dirty=true;
	quadrant_order_dirty=true;
	return quadrant_map.insert(p_qk,q);
}
开发者ID:FEDE0D,项目名称:godot,代码行数:34,代码来源:tile_map.cpp

示例2: _update_quadrant_transform

void TileMap::_update_quadrant_transform() {

	if (!is_inside_tree())
		return;

	Matrix32 global_transform = get_global_transform();

	Matrix32 nav_rel;
	if (navigation)
		nav_rel = get_relative_transform_to_parent(navigation);

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

		Quadrant &q=E->get();
		Matrix32 xform;
		xform.set_origin( q.pos );
		xform = global_transform * xform;
		Physics2DServer::get_singleton()->body_set_state(q.body,Physics2DServer::BODY_STATE_TRANSFORM,xform);

		if (navigation) {
			for(Map<PosKey,Quadrant::NavPoly>::Element *E=q.navpoly_ids.front();E;E=E->next()) {

				navigation->navpoly_set_transform(E->get().id,nav_rel * E->get().xform);
			}
		}

		for(Map<PosKey,Quadrant::Occluder>::Element *E=q.occluder_instances.front();E;E=E->next()) {
			VS::get_singleton()->canvas_light_occluder_set_transform(E->get().id,global_transform * E->get().xform);
		}
	}
}
开发者ID:FEDE0D,项目名称:godot,代码行数:31,代码来源:tile_map.cpp

示例3: _update_quadrant_transform

void TileMap::_update_quadrant_transform() {

	if (!is_inside_scene())
		return;

	Matrix32 global_transform = get_global_transform();

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

		Quadrant &q=E->get();
		Matrix32 xform;
		xform.set_origin( q.pos );
		xform = global_transform * xform;
		Physics2DServer::get_singleton()->body_set_state(q.static_body,Physics2DServer::BODY_STATE_TRANSFORM,xform);
	}
}
开发者ID:hbiblia,项目名称:godot,代码行数:16,代码来源:tile_map.cpp

示例4:

Map<TileMap::PosKey,TileMap::Quadrant>::Element *TileMap::_create_quadrant(const PosKey& p_qk) {

	Matrix32 xform;
	xform.set_origin(Point2(p_qk.x,p_qk.y)*quadrant_size*cell_size);
	Quadrant q;
	q.canvas_item = VisualServer::get_singleton()->canvas_item_create();
	VisualServer::get_singleton()->canvas_item_set_parent( q.canvas_item, get_canvas_item() );
	VisualServer::get_singleton()->canvas_item_set_transform( q.canvas_item, xform );
	q.static_body=Physics2DServer::get_singleton()->body_create(Physics2DServer::BODY_MODE_STATIC);
	if (is_inside_scene()) {
		xform = get_global_transform() * xform;
		RID space = get_world_2d()->get_space();
		Physics2DServer::get_singleton()->body_set_space(q.static_body,space);
	}

	Physics2DServer::get_singleton()->body_set_state(q.static_body,Physics2DServer::BODY_STATE_TRANSFORM,xform);
	q.pos=Vector2(p_qk.x,p_qk.y)*quadrant_size*cell_size;

	rect_cache_dirty=true;
	return quadrant_map.insert(p_qk,q);
}
开发者ID:hbiblia,项目名称:godot,代码行数:21,代码来源:tile_map.cpp

示例5: _update_dirty_quadrants

void TileMap::_update_dirty_quadrants() {

	if (!pending_update)
		return;
	if (!is_inside_scene())
		return;
	if (!tile_set.is_valid())
		return;

	VisualServer *vs = VisualServer::get_singleton();
	Physics2DServer *ps = Physics2DServer::get_singleton();

	while (dirty_quadrant_list.first()) {

		Quadrant &q = *dirty_quadrant_list.first()->self();

		vs->canvas_item_clear(q.canvas_item);
		ps->body_clear_shapes(q.static_body);

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

			Map<PosKey,Cell>::Element *E=tile_map.find( q.cells[i] );
			Cell &c=E->get();
			//moment of truth
			if (!tile_set->has_tile(c.id))
				continue;
			Ref<Texture> tex = tile_set->tile_get_texture(c.id);
			Vector2 tile_ofs = tile_set->tile_get_texture_offset(c.id);

			Vector2 offset = Point2( E->key().x, E->key().y )*cell_size - q.pos;

			if (!tex.is_valid())
				continue;


			Rect2 r = tile_set->tile_get_region(c.id);
			Size2 s = tex->get_size();

			if (r==Rect2())
				s = tex->get_size();
			else {
				s = r.size;
				r.pos.x+=fp_adjust;
				r.pos.y+=fp_adjust;
				r.size.x-=fp_adjust*2.0;
				r.size.y-=fp_adjust*2.0;
			}

			Rect2 rect;
			rect.pos=offset.floor();
			rect.size=s;

			rect.size.x+=fp_adjust;
			rect.size.y+=fp_adjust;

			if (c.flip_h)
				rect.size.x=-rect.size.x;
			if (c.flip_v)
				rect.size.y=-rect.size.y;


			rect.pos+=tile_ofs;
			if (r==Rect2()) {

				tex->draw_rect(q.canvas_item,rect);
			} else {

				tex->draw_rect_region(q.canvas_item,rect,r);
			}

			Vector< Ref<Shape2D> > shapes = tile_set->tile_get_shapes(c.id);


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

				Ref<Shape2D> shape = shapes[i];
				if (shape.is_valid()) {

					Vector2 shape_ofs = tile_set->tile_get_shape_offset(c.id);
					Matrix32 xform;
					xform.set_origin(offset.floor()+shape_ofs);
					if (c.flip_h) {
						xform.elements[0]=-xform.elements[0];
						xform.elements[2].x+=s.x;
					}
					if (c.flip_v) {
						xform.elements[1]=-xform.elements[1];
						xform.elements[2].y+=s.y;
					}


					ps->body_add_shape(q.static_body,shape->get_rid(),xform);
				}
			}
		}

		dirty_quadrant_list.remove( dirty_quadrant_list.first() );
	}


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

示例6: screen_rect


//.........这里部分代码省略.........
				camera_pos.y = MAX( camera_pos.y, (new_camera_pos.y - screen_size.y * 0.5 * drag_margin[MARGIN_TOP]));

			} else {

				if (v_ofs<0) {
					camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_TOP] * v_ofs;
				} else {
					camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs;
				}
			}

		} else if (anchor_mode==ANCHOR_MODE_FIXED_TOP_LEFT){

			camera_pos=new_camera_pos;
		}



		if (smoothing_enabled && !get_tree()->is_editor_hint()) {

			float c = smoothing*get_fixed_process_delta_time();
			smoothed_camera_pos = ((camera_pos-smoothed_camera_pos)*c)+smoothed_camera_pos;
			ret_camera_pos=smoothed_camera_pos;
			//			camera_pos=camera_pos*(1.0-smoothing)+new_camera_pos*smoothing;
		} else {

			ret_camera_pos=smoothed_camera_pos=camera_pos;

		}



	} else {
		ret_camera_pos=smoothed_camera_pos=camera_pos=new_camera_pos;
		first=false;
	}


	Point2 screen_offset = (anchor_mode==ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom) : Point2());

	float angle = get_global_transform().get_rotation();
	if(rotating){
		screen_offset = screen_offset.rotated(angle);
	}

	Rect2 screen_rect(-screen_offset+ret_camera_pos,screen_size*zoom);
	if (screen_rect.pos.x + screen_rect.size.x > limit[MARGIN_RIGHT])
		screen_rect.pos.x = limit[MARGIN_RIGHT] - screen_rect.size.x;

	if (screen_rect.pos.y + screen_rect.size.y > limit[MARGIN_BOTTOM])
		screen_rect.pos.y = limit[MARGIN_BOTTOM] - screen_rect.size.y;


	if (screen_rect.pos.x < limit[MARGIN_LEFT])
		screen_rect.pos.x=limit[MARGIN_LEFT];

	if (screen_rect.pos.y < limit[MARGIN_TOP])
		screen_rect.pos.y =limit[MARGIN_TOP];

	if (offset!=Vector2()) {

		screen_rect.pos+=offset;
		if (screen_rect.pos.x + screen_rect.size.x > limit[MARGIN_RIGHT])
			screen_rect.pos.x = limit[MARGIN_RIGHT] - screen_rect.size.x;

		if (screen_rect.pos.y + screen_rect.size.y > limit[MARGIN_BOTTOM])
			screen_rect.pos.y = limit[MARGIN_BOTTOM] - screen_rect.size.y;


		if (screen_rect.pos.x < limit[MARGIN_LEFT])
			screen_rect.pos.x=limit[MARGIN_LEFT];

		if (screen_rect.pos.y < limit[MARGIN_TOP])
			screen_rect.pos.y =limit[MARGIN_TOP];

	}

	camera_screen_center=screen_rect.pos+screen_rect.size*0.5;

	Matrix32 xform;
	if(rotating){
		xform.set_rotation(angle);
	}
	xform.scale_basis(zoom);
	xform.set_origin(screen_rect.pos/*.floor()*/);


/*
	if (0) {

		xform = get_global_transform() * xform;
	} else {

		xform.elements[2]+=get_global_transform().get_origin();
	}
*/


	return (xform).affine_inverse();
}
开发者ID:FoxKyong,项目名称:godot,代码行数:101,代码来源:camera_2d.cpp

示例7: _update_dirty_quadrants

void TileMap::_update_dirty_quadrants() {

	if (!pending_update)
		return;
	if (!is_inside_tree())
		return;
	if (!tile_set.is_valid())
		return;

	VisualServer *vs = VisualServer::get_singleton();
	Physics2DServer *ps = Physics2DServer::get_singleton();
	Vector2 tofs = get_cell_draw_offset();
	Vector2 tcenter = cell_size/2;
	Matrix32 nav_rel;
	if (navigation)
		nav_rel = get_relative_transform_to_parent(navigation);

	Vector2 qofs;

	SceneTree *st=SceneTree::get_singleton();
	Color debug_collision_color;

	bool debug_shapes = st && st->is_debugging_collisions_hint();
	if (debug_shapes) {
		debug_collision_color=st->get_debug_collisions_color();
	}

	while (dirty_quadrant_list.first()) {

		Quadrant &q = *dirty_quadrant_list.first()->self();

		for (List<RID>::Element *E=q.canvas_items.front();E;E=E->next()) {

			vs->free(E->get());
		}

		q.canvas_items.clear();

		ps->body_clear_shapes(q.body);
		int shape_idx=0;

		if (navigation) {
			for(Map<PosKey,Quadrant::NavPoly>::Element *E=q.navpoly_ids.front();E;E=E->next()) {

				navigation->navpoly_remove(E->get().id);
			}
			q.navpoly_ids.clear();
		}

		for(Map<PosKey,Quadrant::Occluder>::Element *E=q.occluder_instances.front();E;E=E->next()) {
			VS::get_singleton()->free(E->get().id);
		}
		q.occluder_instances.clear();
		Ref<CanvasItemMaterial> prev_material;
		RID prev_canvas_item;
		RID prev_debug_canvas_item;

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

			Map<PosKey,Cell>::Element *E=tile_map.find( q.cells[i] );
			Cell &c=E->get();
			//moment of truth
			if (!tile_set->has_tile(c.id))
				continue;
			Ref<Texture> tex = tile_set->tile_get_texture(c.id);
			Vector2 tile_ofs = tile_set->tile_get_texture_offset(c.id);

			Vector2 wofs = _map_to_world(E->key().x, E->key().y);
			Vector2 offset = wofs - q.pos + tofs;

			if (!tex.is_valid())
				continue;

			Ref<CanvasItemMaterial> mat = tile_set->tile_get_material(c.id);

			RID canvas_item;
			RID debug_canvas_item;

			if (prev_canvas_item==RID() || prev_material!=mat) {

				canvas_item=vs->canvas_item_create();
				if (mat.is_valid())
					vs->canvas_item_set_material(canvas_item,mat->get_rid());
				vs->canvas_item_set_parent( canvas_item, get_canvas_item() );
				Matrix32 xform;
				xform.set_origin( q.pos );
				vs->canvas_item_set_transform( canvas_item, xform );
				vs->canvas_item_set_light_mask(canvas_item,get_light_mask());
				vs->canvas_item_set_blend_mode(canvas_item,VS::MaterialBlendMode(get_blend_mode()));

				q.canvas_items.push_back(canvas_item);

				if (debug_shapes) {

					debug_canvas_item=vs->canvas_item_create();
					vs->canvas_item_set_parent( debug_canvas_item, canvas_item );
					vs->canvas_item_set_z_as_relative_to_parent(debug_canvas_item,false);
					vs->canvas_item_set_z(debug_canvas_item,VS::CANVAS_ITEM_Z_MAX-1);
					q.canvas_items.push_back(debug_canvas_item);
					prev_debug_canvas_item=debug_canvas_item;
//.........这里部分代码省略.........
开发者ID:FEDE0D,项目名称:godot,代码行数:101,代码来源:tile_map.cpp


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