Path: blob/master/scene/2d/physics/collision_polygon_2d.h
9906 views
/**************************************************************************/1/* collision_polygon_2d.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "scene/2d/node_2d.h"3334class CollisionObject2D;3536class CollisionPolygon2D : public Node2D {37GDCLASS(CollisionPolygon2D, Node2D);3839public:40enum BuildMode {41BUILD_SOLIDS,42BUILD_SEGMENTS,43};4445protected:46Rect2 aabb = Rect2(-10, -10, 20, 20);47BuildMode build_mode = BUILD_SOLIDS;48Vector<Point2> polygon;49uint32_t owner_id = 0;50CollisionObject2D *collision_object = nullptr;51bool disabled = false;52bool one_way_collision = false;53real_t one_way_collision_margin = 1.0;5455Vector<Vector<Vector2>> _decompose_in_convex();5657void _build_polygon();5859void _update_in_shape_owner(bool p_xform_only = false);6061protected:62void _notification(int p_what);63static void _bind_methods();6465public:66#ifdef DEBUG_ENABLED67virtual Rect2 _edit_get_rect() const override;68virtual bool _edit_use_rect() const override;69virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override;70#endif7172void set_build_mode(BuildMode p_mode);73BuildMode get_build_mode() const;7475void set_polygon(const Vector<Point2> &p_polygon);76Vector<Point2> get_polygon() const;7778PackedStringArray get_configuration_warnings() const override;7980void set_disabled(bool p_disabled);81bool is_disabled() const;8283void set_one_way_collision(bool p_enable);84bool is_one_way_collision_enabled() const;8586void set_one_way_collision_margin(real_t p_margin);87real_t get_one_way_collision_margin() const;8889CollisionPolygon2D();90};9192VARIANT_ENUM_CAST(CollisionPolygon2D::BuildMode);939495