示例#1
0
void Viewport::set_world(const Ref<World>& p_world) {

	if (world==p_world)
		return;

	if (is_inside_scene())
		_propagate_exit_world(this);

#ifndef _3D_DISABLED
	if (find_world().is_valid() && camera)
		camera->notification(Camera::NOTIFICATION_LOST_CURRENT);
#endif

	world=p_world;

	if (is_inside_scene())
		_propagate_enter_world(this);

#ifndef _3D_DISABLED
	if (find_world().is_valid() && camera)
		camera->notification(Camera::NOTIFICATION_BECAME_CURRENT);
#endif

	//propagate exit

	if (is_inside_scene()) {
		VisualServer::get_singleton()->viewport_set_scenario(viewport,find_world()->get_scenario());
	}

	_update_listener();

}
示例#2
0
void Viewport::set_as_audio_listener(bool p_enable) {

	if (p_enable==audio_listener)
		return;

	audio_listener=p_enable;
	_update_listener();

}
示例#3
0
void Viewport::set_use_own_world(bool p_world) {

	if (p_world==own_world.is_valid())
		return;


	if (is_inside_scene())
		_propagate_exit_world(this);

#ifndef _3D_DISABLED
	if (find_world().is_valid() && camera)
		camera->notification(Camera::NOTIFICATION_LOST_CURRENT);
#endif

	if (!p_world)
		own_world=Ref<World>();
	else
		own_world=Ref<World>( memnew( World ));

	if (is_inside_scene())
		_propagate_enter_world(this);

#ifndef _3D_DISABLED
	if (find_world().is_valid() && camera)
		camera->notification(Camera::NOTIFICATION_BECAME_CURRENT);
#endif

	//propagate exit

	if (is_inside_scene()) {
		VisualServer::get_singleton()->viewport_set_scenario(viewport,find_world()->get_scenario());
	}

	_update_listener();


}
示例#4
0
void Viewport::_set_camera(Camera* p_camera) {

#ifndef _3D_DISABLED

	if (camera==p_camera)
		return;

	if (camera && find_world().is_valid()) {
		camera->notification(Camera::NOTIFICATION_LOST_CURRENT);
	}
	camera=p_camera;
	if (camera)
		VisualServer::get_singleton()->viewport_attach_camera(viewport,camera->get_camera());
	else
		VisualServer::get_singleton()->viewport_attach_camera(viewport,RID());

	if (camera && find_world().is_valid()) {
		camera->notification(Camera::NOTIFICATION_BECAME_CURRENT);
	}

	_update_listener();
	_camera_transform_changed_notify();
#endif
}
示例#5
0
void Viewport::_notification(int p_what) {
	

	switch( p_what ) {
		
		case NOTIFICATION_ENTER_SCENE: {


			if (!render_target)
				_vp_enter_scene();

			this->parent=NULL;
			Node *parent=get_parent();

			if (parent) {


				while(parent && !(this->parent=parent->cast_to<Viewport>())) {

					parent=parent->get_parent();
				}
			}

			current_canvas=find_world_2d()->get_canvas();
			VisualServer::get_singleton()->viewport_set_scenario(viewport,find_world()->get_scenario());
			VisualServer::get_singleton()->viewport_attach_canvas(viewport,current_canvas);

			_update_listener();
			_update_listener_2d();
			_update_rect();

			if (world_2d.is_valid()) {
				find_world_2d()->_register_viewport(this,Rect2());
//best to defer this and not do it here, as it can annoy a lot of setup logic if user
//adds a node and then moves it, will get enter/exit screen/viewport notifications
//unnecesarily
//				update_worlds();
			}

			add_to_group("_viewports");

		} break;
		case NOTIFICATION_READY: {
#ifndef _3D_DISABLED
			if (cameras.size() && !camera) {
				//there are cameras but no current camera, pick first in tree and make it current
				Camera *first=NULL;
				for(Set<Camera*>::Element *E=cameras.front();E;E=E->next()) {

					if (first==NULL || first->is_greater_than(E->get())) {
						first=E->get();
					}
				}

				if (first)
					first->make_current();
			}
#endif
		} break;
		case NOTIFICATION_EXIT_SCENE: {



			if (world_2d.is_valid())
				world_2d->_remove_viewport(this);

			if (!render_target)
				_vp_exit_scene();

			VisualServer::get_singleton()->viewport_set_scenario(viewport,RID());
			SpatialSoundServer::get_singleton()->listener_set_space(listener,RID());
			VisualServer::get_singleton()->viewport_remove_canvas(viewport,current_canvas);
			remove_from_group("_viewports");

		} break;
	}
}
示例#6
0
文件: listener.cpp 项目: 93i/godot
void Listener::_request_listener_update() {

	_update_listener();
}