Example #1
0
Vector3 Camera::project_ray_origin(const Point2& p_pos) const {

	if (!is_inside_tree()) {
		ERR_EXPLAIN("Camera is not inside scene.");
		ERR_FAIL_COND_V(!is_inside_tree(),Vector3());
	}

#if 0
	Size2 viewport_size = get_viewport()->get_visible_rect().size;
	Vector2 cpos = p_pos;
#else

	Size2 viewport_size = get_viewport()->get_camera_rect_size();
	Vector2 cpos = get_viewport()->get_camera_coords(p_pos);
#endif

	ERR_FAIL_COND_V( viewport_size.y == 0, Vector3() );
//	float aspect = viewport_size.x / viewport_size.y;

	if (mode == PROJECTION_PERSPECTIVE) {

		return get_camera_transform().origin;
	} else {

		Vector2 pos = cpos / viewport_size;
		float vsize,hsize;
		if (keep_aspect==KEEP_WIDTH) {
			vsize = size/viewport_size.get_aspect();
			hsize = size;
		} else {
			hsize = size*viewport_size.get_aspect();
			vsize = size;

		}



		Vector3 ray;
		ray.x = pos.x * (hsize) - hsize/2;
		ray.y = (1.0 - pos.y) * (vsize) - vsize/2;
		ray.z = -near;
		ray = get_camera_transform().xform(ray);
		return ray;
	};
};
Example #2
0
void Skeleton::set_bone_pose(int p_bone, const Transform &p_pose) {

	ERR_FAIL_INDEX(p_bone, bones.size());

	bones.write[p_bone].pose = p_pose;
	if (is_inside_tree()) {
		_make_dirty();
	}
}
Example #3
0
void Skeleton::set_bone_pose(int p_bone, const Transform& p_pose) {

	ERR_FAIL_INDEX( p_bone, bones.size() );
	ERR_FAIL_COND( !is_inside_tree() );


	bones[p_bone].pose=p_pose;
	_make_dirty();
}
Example #4
0
RID CanvasItem::get_canvas() const {

	ERR_FAIL_COND_V(!is_inside_tree(), RID());

	if (canvas_layer)
		return canvas_layer->get_world_2d()->get_canvas();
	else
		return get_viewport()->find_world_2d()->get_canvas();
}
Example #5
0
String ARVROrigin::get_configuration_warning() const {
	if (!is_visible() || !is_inside_tree())
		return String();

	if (tracked_camera == NULL)
		return TTR("ARVROrigin requires an ARVRCamera child node");

	return String();
};
Example #6
0
void Path::_curve_changed() {

	if (is_inside_tree() && Engine::get_singleton()->is_editor_hint())
		update_gizmo();
	if (is_inside_tree()) {
		emit_signal("curve_changed");
	}

	// update the configuration warnings of all children of type OrientedPathFollows
	if (is_inside_tree()) {
		for (int i = 0; i < get_child_count(); i++) {
			OrientedPathFollow *child = Object::cast_to<OrientedPathFollow>(get_child(i));
			if (child) {
				child->update_configuration_warning();
			}
		}
	}
}
Example #7
0
void CollisionShape::_update_body() {

	if (!is_inside_tree() || !can_update_body)
		return;
	if (!get_tree()->is_editor_hint())
		return;
	if (get_parent() && get_parent()->cast_to<CollisionObject>())
		get_parent()->cast_to<CollisionObject>()->_update_shapes_from_children();
}
Example #8
0
int Label::get_line_count() const {

	if (!is_inside_tree())
		return 1;
	if (word_cache_dirty)
		const_cast<Label*>(this)->regenerate_word_cache();

	return line_count;
}
Example #9
0
void Particles2D::set_use_local_coordinates(bool p_enable) {

	local_coords = p_enable;
	VS::get_singleton()->particles_set_use_local_coordinates(particles, local_coords);
	set_notify_transform(!p_enable);
	if (!p_enable && is_inside_tree()) {
		_update_particle_emission_transform();
	}
}
Example #10
0
void RayCast2D::set_enabled(bool p_enabled) {

	enabled=p_enabled;
	if (is_inside_tree() && !get_tree()->is_editor_hint())
		set_fixed_process(p_enabled);
	if (!p_enabled)
		collided=false;

}
Example #11
0
void ShaderEditor::_tab_changed(int p_which) {

	ShaderTextEditor *shader_editor = tab_container->get_tab_control(p_which)->cast_to<ShaderTextEditor>();

	if (shader_editor && is_inside_tree())
		shader_editor->get_text_edit()->grab_focus();

	ensure_select_current();
}
Example #12
0
void RichTextLabel::set_bbcode(const String& p_bbcode) {
	bbcode=p_bbcode;
	if (is_inside_tree() && use_bbcode)
		parse_bbcode(p_bbcode);
	else { // raw text
		clear();
		add_text(p_bbcode);
	}
}
Example #13
0
void Spatial::force_update_transform() {
	ERR_FAIL_COND(!is_inside_tree());
	if (!xform_change.in_list()) {
		return; //nothing to update
	}
	get_tree()->xform_change_list.remove(&xform_change);

	notification(NOTIFICATION_TRANSFORM_CHANGED);
}
Example #14
0
void Listener::make_current() {

	current = true;

	if (!is_inside_tree())
		return;

	get_viewport()->_listener_set(this);
}
Example #15
0
void CollisionShape2D::set_shape(const Ref<Shape2D>& p_shape) {

    if (shape.is_valid())
        shape->disconnect("changed",this,"_shape_changed");
    shape=p_shape;
    update();
    if (is_inside_tree() && can_update_body)
        _update_parent();
    if (is_inside_tree() && !can_update_body && update_shape_index>=0) {
        CollisionObject2D *co = get_parent()->cast_to<CollisionObject2D>();
        if (co) {
            co->set_shape(update_shape_index,p_shape);
        }
    }
    if (shape.is_valid())
        shape->connect("changed",this,"_shape_changed");

}
Example #16
0
void Container::_sort_children() {

	if (!is_inside_tree())
		return;

	notification(NOTIFICATION_SORT_CHILDREN);
	emit_signal(SceneStringNames::get_singleton()->sort_children);
	pending_sort = false;
}
Example #17
0
void RemoteTransform::_update_remote() {

	if (!is_inside_tree())
		return;

	if (!cache)
		return;

	Spatial *n = Object::cast_to<Spatial>(ObjectDB::get_instance(cache));
	if (!n)
		return;

	if (!n->is_inside_tree())
		return;

	//todo make faster
	if (use_global_coordinates) {

		if (update_remote_position && update_remote_rotation && update_remote_scale) {
			n->set_global_transform(get_global_transform());
		} else {
			Transform n_trans = n->get_global_transform();
			Transform our_trans = get_global_transform();

			if (!update_remote_position)
				our_trans.set_origin(n_trans.get_origin());

			n->set_global_transform(our_trans);

			if (!update_remote_rotation)
				n->set_rotation(n_trans.basis.get_rotation());

			if (!update_remote_scale)
				n->set_scale(n_trans.basis.get_scale());
		}

	} else {
		if (update_remote_position && update_remote_rotation && update_remote_scale) {
			n->set_global_transform(get_global_transform());
		} else {
			Transform n_trans = n->get_transform();
			Transform our_trans = get_transform();

			if (!update_remote_position)
				our_trans.set_origin(n_trans.get_origin());

			n->set_transform(our_trans);

			if (!update_remote_rotation)
				n->set_rotation(n_trans.basis.get_rotation());

			if (!update_remote_scale)
				n->set_scale(n_trans.basis.get_scale());
		}
	}
}
Example #18
0
void LineEdit::set_cursor_pos(int p_pos) {

if (p_pos>(int)text.length())
    p_pos=text.length();

if(p_pos<0)
    p_pos=0;



cursor_pos=p_pos;

if (!is_inside_tree()) {

    window_pos=cursor_pos;
    return;
}

Ref<StyleBox> style = get_stylebox("normal");
Ref<Font> font=get_font("font");

if (cursor_pos<window_pos) {
    /* Adjust window if cursor goes too much to the left */
    set_window_pos(cursor_pos);
} else if (cursor_pos>window_pos) {
    /* Adjust window if cursor goes too much to the right */
    int window_width=get_size().width-style->get_minimum_size().width;

    if (window_width<0)
        return;
    int wp=window_pos;

    if (font.is_valid()) {

        int accum_width=0;

        for(int i=cursor_pos; i>=window_pos; i--) {

            if (i>=text.length()) {
                accum_width=font->get_char_size(' ').width; //anything should do
            } else {
                accum_width+=font->get_char_size(text[i],i+1<text.length()?text[i+1]:0).width; //anything should do
            }
            if (accum_width>=window_width)
                break;

            wp=i;
        }
    }

    if (wp!=window_pos)
        set_window_pos( wp );

}
update();
}
Example #19
0
bool Camera::is_current() const {

	if (is_inside_tree()) {
		if (viewport_ptr)
			return viewport_ptr->get_camera()==this;
	} else
		return current;

	return false;
}
Example #20
0
void Path::_curve_changed() {

	if (is_inside_tree() && Engine::get_singleton()->is_editor_hint())
		update_gizmo();
	if (is_inside_tree()) {
		emit_signal("curve_changed");
	}

	// update the configuration warnings of all children of type PathFollow
	// previously used for PathFollowOriented (now enforced orientation is done in PathFollow)
	if (is_inside_tree()) {
		for (int i = 0; i < get_child_count(); i++) {
			PathFollow *child = Object::cast_to<PathFollow>(get_child(i));
			if (child) {
				child->update_configuration_warning();
			}
		}
	}
}
Example #21
0
void WorldEnvironment::set_environment(const Ref<Environment> &p_environment) {

	if (is_inside_tree() && environment.is_valid() && get_viewport()->find_world()->get_environment() == environment) {
		get_viewport()->find_world()->set_environment(Ref<Environment>());
		remove_from_group("_world_environment_" + itos(get_viewport()->find_world()->get_scenario().get_id()));
		//clean up
	}

	environment = p_environment;
	if (is_inside_tree() && environment.is_valid()) {
		if (get_viewport()->find_world()->get_environment().is_valid()) {
			WARN_PRINT("World already has an environment (Another WorldEnvironment?), overriding.");
		}
		get_viewport()->find_world()->set_environment(environment);
		add_to_group("_world_environment_" + itos(get_viewport()->find_world()->get_scenario().get_id()));
	}

	update_configuration_warning();
}
Example #22
0
bool Camera::is_current() const {

	if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) {

		return get_viewport()->get_camera()==this;
	} else
		return current;

	return false;
}
Example #23
0
void CanvasItem::_toplevel_raise_self() {

	if (!is_inside_tree())
		return;

	if (canvas_layer)
		VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, canvas_layer->get_sort_index());
	else
		VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_viewport()->gui_get_canvas_sort_index());
}
Example #24
0
Matrix32 CanvasItem::get_canvas_transform() const {

	ERR_FAIL_COND_V(!is_inside_tree(),Matrix32());

	if (canvas_layer)
		return canvas_layer->get_transform();
	else
		return get_viewport()->get_canvas_transform();

}
Example #25
0
void RemoteTransform2D::set_remote_node(const NodePath &p_remote_node) {

	remote_node = p_remote_node;
	if (is_inside_tree()) {
		_update_cache();
		_update_remote();
	}

	update_configuration_warning();
}
Example #26
0
void ReferenceRect::_notification(int p_what) {

	if (p_what == NOTIFICATION_DRAW) {

		if (!is_inside_tree())
			return;
		if (Engine::get_singleton()->is_editor_hint())
			draw_rect(Rect2(Point2(), get_size()), border_color, false);
	}
}
Example #27
0
void StreamPlayer::_set_play(bool p_play) {

	_play=p_play;
	if (is_inside_tree()) {
		if(_play)
			play();
		else
			stop();
	}

}
Example #28
0
void ColorPicker::set_edit_alpha(bool p_show) {

	edit_alpha = p_show;
	_update_controls();

	if (!is_inside_tree())
		return;

	_update_color();
	sample->update();
}
Example #29
0
void EventPlayer::stop() {

	if (!is_inside_tree())
		return;
	if (playback.is_null())
		return;

	AudioServer::get_singleton()->lock();
	playback->stop();
	AudioServer::get_singleton()->unlock();
}
Example #30
0
void Camera::make_current() {

	current=true;

	if (!is_inside_tree())
		return;

	get_viewport()->_camera_set(this);

	//get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,camera_group,"_camera_make_current",this);
}