/*************************************************************************/ /* portal.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "portal.h" #include "servers/visual_server.h" #include "scene/resources/surface_tool.h" #include "globals.h" bool Portal::_set(const StringName& p_name, const Variant& p_value) { if (p_name=="shape") { DVector src_coords=p_value; Vector points; int src_coords_size = src_coords.size(); ERR_FAIL_COND_V(src_coords_size%2,false); points.resize(src_coords_size/2); for (int i=0;i points=get_shape(); DVector dst_coords; dst_coords.resize(points.size()*2); for (int i=0;i *p_list) const { p_list->push_back( PropertyInfo( Variant::REAL_ARRAY, "shape" ) ); p_list->push_back( PropertyInfo( Variant::BOOL, "enabled" ) ); p_list->push_back( PropertyInfo( Variant::REAL, "disable_distance",PROPERTY_HINT_RANGE,"0,4096,0.01" ) ); p_list->push_back( PropertyInfo( Variant::COLOR, "disabled_color") ); p_list->push_back( PropertyInfo( Variant::REAL, "connect_range",PROPERTY_HINT_RANGE,"0.1,4096,0.01" ) ); } AABB Portal::get_aabb() const { return aabb; } DVector Portal::get_faces(uint32_t p_usage_flags) const { if (!(p_usage_flags&FACES_ENCLOSING)) return DVector(); Vector shape = get_shape(); if (shape.size()==0) return DVector(); Vector2 center; for (int i=0;i ret; center/=shape.size(); for (int i=0;i& p_shape) { VisualServer::get_singleton()->portal_set_shape(portal, p_shape); shape=p_shape; update_gizmo(); } Vector Portal::get_shape() const { return shape; } void Portal::set_connect_range(float p_range) { connect_range=p_range; //VisualServer::get_singleton()->portal_set_connect_range(portal,p_range); } float Portal::get_connect_range() const { return connect_range; } void Portal::set_enabled(bool p_enabled) { enabled=p_enabled; VisualServer::get_singleton()->portal_set_enabled(portal,enabled); } bool Portal::is_enabled() const { return enabled; } void Portal::set_disable_distance(float p_distance) { disable_distance=p_distance; VisualServer::get_singleton()->portal_set_disable_distance(portal,disable_distance); } float Portal::get_disable_distance() const { return disable_distance; } void Portal::set_disabled_color(const Color& p_disabled_color) { disabled_color=p_disabled_color; VisualServer::get_singleton()->portal_set_disabled_color(portal,disabled_color); } Color Portal::get_disabled_color() const { return disabled_color; } void Portal::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_shape","points"),&Portal::set_shape); ObjectTypeDB::bind_method(_MD("get_shape"),&Portal::get_shape); ObjectTypeDB::bind_method(_MD("set_enabled","enable"),&Portal::set_enabled); ObjectTypeDB::bind_method(_MD("is_enabled"),&Portal::is_enabled); ObjectTypeDB::bind_method(_MD("set_disable_distance","distance"),&Portal::set_disable_distance); ObjectTypeDB::bind_method(_MD("get_disable_distance"),&Portal::get_disable_distance); ObjectTypeDB::bind_method(_MD("set_disabled_color","color"),&Portal::set_disabled_color); ObjectTypeDB::bind_method(_MD("get_disabled_color"),&Portal::get_disabled_color); ObjectTypeDB::bind_method(_MD("set_connect_range","range"),&Portal::set_connect_range); ObjectTypeDB::bind_method(_MD("get_connect_range"),&Portal::get_connect_range); } Portal::Portal() { portal = VisualServer::get_singleton()->portal_create(); Vector< Point2 > points; points.push_back( Point2( -1, 1 ) ); points.push_back( Point2( 1, 1 ) ); points.push_back( Point2( 1, -1 ) ); points.push_back( Point2( -1, -1 ) ); set_shape(points); // default shape set_connect_range(0.8); set_disable_distance(50); set_enabled(true); set_base(portal); } Portal::~Portal() { VisualServer::get_singleton()->free(portal); }