1 /*************************************************************************/
2 /*  path.h                                                               */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */
10 /*                                                                       */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the       */
13 /* "Software"), to deal in the Software without restriction, including   */
14 /* without limitation the rights to use, copy, modify, merge, publish,   */
15 /* distribute, sublicense, and/or sell copies of the Software, and to    */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions:                                             */
18 /*                                                                       */
19 /* The above copyright notice and this permission notice shall be        */
20 /* included in all copies or substantial portions of the Software.       */
21 /*                                                                       */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
29 /*************************************************************************/
30 
31 #ifndef PATH_H
32 #define PATH_H
33 
34 #include "scene/3d/spatial.h"
35 #include "scene/resources/curve.h"
36 
37 class Path : public Spatial {
38 
39 	GDCLASS(Path, Spatial);
40 
41 	Ref<Curve3D> curve;
42 
43 	void _curve_changed();
44 
45 protected:
46 	void _notification(int p_what);
47 	static void _bind_methods();
48 
49 public:
50 	void set_curve(const Ref<Curve3D> &p_curve);
51 	Ref<Curve3D> get_curve() const;
52 
53 	Path();
54 };
55 
56 class PathFollow : public Spatial {
57 
58 	GDCLASS(PathFollow, Spatial);
59 
60 public:
61 	enum RotationMode {
62 
63 		ROTATION_NONE,
64 		ROTATION_Y,
65 		ROTATION_XY,
66 		ROTATION_XYZ,
67 		ROTATION_ORIENTED
68 	};
69 
70 private:
71 	Path *path;
72 	real_t delta_offset; // change in offset since last _update_transform
73 	real_t offset;
74 	real_t h_offset;
75 	real_t v_offset;
76 	bool cubic;
77 	bool loop;
78 	RotationMode rotation_mode;
79 
80 	void _update_transform(bool p_update_xyz_rot = true);
81 
82 protected:
83 	virtual void _validate_property(PropertyInfo &property) const;
84 
85 	void _notification(int p_what);
86 	static void _bind_methods();
87 
88 public:
89 	void set_offset(float p_offset);
90 	float get_offset() const;
91 
92 	void set_h_offset(float p_h_offset);
93 	float get_h_offset() const;
94 
95 	void set_v_offset(float p_v_offset);
96 	float get_v_offset() const;
97 
98 	void set_unit_offset(float p_unit_offset);
99 	float get_unit_offset() const;
100 
101 	void set_loop(bool p_loop);
102 	bool has_loop() const;
103 
104 	void set_rotation_mode(RotationMode p_rotation_mode);
105 	RotationMode get_rotation_mode() const;
106 
107 	void set_cubic_interpolation(bool p_enable);
108 	bool get_cubic_interpolation() const;
109 
110 	String get_configuration_warning() const;
111 
112 	PathFollow();
113 };
114 
115 VARIANT_ENUM_CAST(PathFollow::RotationMode);
116 
117 #endif // PATH_H
118