Implementing clang-format and applying it to all classes
parent
0a6f5d052a
commit
fc20fa3fce
|
@ -0,0 +1,126 @@
|
||||||
|
# Commented out parameters are those with the same value as base LLVM style
|
||||||
|
# We can uncomment them if we want to change their value, or enforce the
|
||||||
|
# chosen value in case the base style changes (last sync: Clang 6.0.1).
|
||||||
|
---
|
||||||
|
### General config, applies to all languages ###
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
AlignAfterOpenBracket: DontAlign
|
||||||
|
# AlignConsecutiveAssignments: false
|
||||||
|
# AlignConsecutiveDeclarations: false
|
||||||
|
# AlignEscapedNewlines: Right
|
||||||
|
# AlignOperands: true
|
||||||
|
AlignTrailingComments: false
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
# AllowShortBlocksOnASingleLine: false
|
||||||
|
AllowShortCaseLabelsOnASingleLine: true
|
||||||
|
AllowShortFunctionsOnASingleLine: Inline
|
||||||
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
|
# AllowShortLoopsOnASingleLine: false
|
||||||
|
# AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
# AlwaysBreakAfterReturnType: None
|
||||||
|
# AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
# AlwaysBreakTemplateDeclarations: false
|
||||||
|
# BinPackArguments: true
|
||||||
|
# BinPackParameters: true
|
||||||
|
# BraceWrapping:
|
||||||
|
# AfterClass: false
|
||||||
|
# AfterControlStatement: false
|
||||||
|
# AfterEnum: false
|
||||||
|
# AfterFunction: false
|
||||||
|
# AfterNamespace: false
|
||||||
|
# AfterObjCDeclaration: false
|
||||||
|
# AfterStruct: false
|
||||||
|
# AfterUnion: false
|
||||||
|
# AfterExternBlock: false
|
||||||
|
# BeforeCatch: false
|
||||||
|
# BeforeElse: false
|
||||||
|
# IndentBraces: false
|
||||||
|
# SplitEmptyFunction: true
|
||||||
|
# SplitEmptyRecord: true
|
||||||
|
# SplitEmptyNamespace: true
|
||||||
|
# BreakBeforeBinaryOperators: None
|
||||||
|
# BreakBeforeBraces: Attach
|
||||||
|
# BreakBeforeInheritanceComma: false
|
||||||
|
BreakBeforeTernaryOperators: false
|
||||||
|
# BreakConstructorInitializersBeforeComma: false
|
||||||
|
BreakConstructorInitializers: AfterColon
|
||||||
|
# BreakStringLiterals: true
|
||||||
|
ColumnLimit: 0
|
||||||
|
# CommentPragmas: '^ IWYU pragma:'
|
||||||
|
# CompactNamespaces: false
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||||
|
ConstructorInitializerIndentWidth: 8
|
||||||
|
ContinuationIndentWidth: 8
|
||||||
|
Cpp11BracedListStyle: false
|
||||||
|
# DerivePointerAlignment: false
|
||||||
|
# DisableFormat: false
|
||||||
|
# ExperimentalAutoDetectBinPacking: false
|
||||||
|
# FixNamespaceComments: true
|
||||||
|
# ForEachMacros:
|
||||||
|
# - foreach
|
||||||
|
# - Q_FOREACH
|
||||||
|
# - BOOST_FOREACH
|
||||||
|
# IncludeBlocks: Preserve
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '".*"'
|
||||||
|
Priority: 1
|
||||||
|
- Regex: '^<.*\.h>'
|
||||||
|
Priority: 2
|
||||||
|
- Regex: '^<.*'
|
||||||
|
Priority: 3
|
||||||
|
# IncludeIsMainRegex: '(Test)?$'
|
||||||
|
IndentCaseLabels: true
|
||||||
|
# IndentPPDirectives: None
|
||||||
|
IndentWidth: 4
|
||||||
|
# IndentWrappedFunctionNames: false
|
||||||
|
# JavaScriptQuotes: Leave
|
||||||
|
# JavaScriptWrapImports: true
|
||||||
|
# KeepEmptyLinesAtTheStartOfBlocks: true
|
||||||
|
# MacroBlockBegin: ''
|
||||||
|
# MacroBlockEnd: ''
|
||||||
|
# MaxEmptyLinesToKeep: 1
|
||||||
|
# NamespaceIndentation: None
|
||||||
|
# PenaltyBreakAssignment: 2
|
||||||
|
# PenaltyBreakBeforeFirstCallParameter: 19
|
||||||
|
# PenaltyBreakComment: 300
|
||||||
|
# PenaltyBreakFirstLessLess: 120
|
||||||
|
# PenaltyBreakString: 1000
|
||||||
|
# PenaltyExcessCharacter: 1000000
|
||||||
|
# PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
|
# PointerAlignment: Right
|
||||||
|
# RawStringFormats:
|
||||||
|
# - Delimiter: pb
|
||||||
|
# Language: TextProto
|
||||||
|
# BasedOnStyle: google
|
||||||
|
# ReflowComments: true
|
||||||
|
# SortIncludes: true
|
||||||
|
# SortUsingDeclarations: true
|
||||||
|
# SpaceAfterCStyleCast: false
|
||||||
|
# SpaceAfterTemplateKeyword: true
|
||||||
|
# SpaceBeforeAssignmentOperators: true
|
||||||
|
# SpaceBeforeParens: ControlStatements
|
||||||
|
# SpaceInEmptyParentheses: false
|
||||||
|
# SpacesBeforeTrailingComments: 1
|
||||||
|
# SpacesInAngles: false
|
||||||
|
# SpacesInContainerLiterals: true
|
||||||
|
# SpacesInCStyleCastParentheses: false
|
||||||
|
# SpacesInParentheses: false
|
||||||
|
# SpacesInSquareBrackets: false
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: Always
|
||||||
|
---
|
||||||
|
### C++ specific config ###
|
||||||
|
Language: Cpp
|
||||||
|
Standard: Cpp03
|
||||||
|
---
|
||||||
|
### ObjC specific config ###
|
||||||
|
Language: ObjC
|
||||||
|
ObjCBlockIndentWidth: 4
|
||||||
|
# ObjCSpaceAfterProperty: false
|
||||||
|
# ObjCSpaceBeforeProtocolList: true
|
||||||
|
---
|
||||||
|
### Java specific config ###
|
||||||
|
Language: Java
|
||||||
|
# BreakAfterJavaFieldAnnotations: false
|
||||||
|
...
|
|
@ -9,9 +9,18 @@ Version | Branch
|
||||||
**Godot 3.1 Nativescript 1.0** | [nativescript-1.0](https://github.com/GodotNativeTools/godot-cpp/tree/nativescript-1.0)
|
**Godot 3.1 Nativescript 1.0** | [nativescript-1.0](https://github.com/GodotNativeTools/godot-cpp/tree/nativescript-1.0)
|
||||||
|
|
||||||
Index:
|
Index:
|
||||||
|
- [**Contributing**](#contributing)
|
||||||
- [**Getting Started**](#getting-started)
|
- [**Getting Started**](#getting-started)
|
||||||
- [**Creating a simple class**](#creating-a-simple-class)
|
- [**Creating a simple class**](#creating-a-simple-class)
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
We greatly appreciate help in maintaining and extending this project.
|
||||||
|
If you wish to help out ensure you have an account on Github and create a "fork" of the this repo.
|
||||||
|
Rémi "Akien" Verschelde wrote an excellent bit of documentation for the main Godot project on this:
|
||||||
|
https://docs.godotengine.org/en/3.0/community/contributing/pr_workflow.html
|
||||||
|
|
||||||
|
It is advisible to also install clang-format and copy the files in `misc/hooks` into `.git/hooks` so format checking is done before your changes are submitted.
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
| **Build latest version of Godot** | [**GitHub**](https://github.com/godotengine/godot) | [**Docs**](https://godot.readthedocs.io/en/latest/development/compiling/index.html) |
|
| **Build latest version of Godot** | [**GitHub**](https://github.com/godotengine/godot) | [**Docs**](https://godot.readthedocs.io/en/latest/development/compiling/index.html) |
|
||||||
|
|
|
@ -17,40 +17,38 @@ public:
|
||||||
real_t get_area() const; /// get area
|
real_t get_area() const; /// get area
|
||||||
inline bool has_no_area() const {
|
inline bool has_no_area() const {
|
||||||
|
|
||||||
return (size.x<=CMP_EPSILON || size.y<=CMP_EPSILON || size.z<=CMP_EPSILON);
|
return (size.x <= CMP_EPSILON || size.y <= CMP_EPSILON || size.z <= CMP_EPSILON);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool has_no_surface() const {
|
inline bool has_no_surface() const {
|
||||||
|
|
||||||
return (size.x<=CMP_EPSILON && size.y<=CMP_EPSILON && size.z<=CMP_EPSILON);
|
return (size.x <= CMP_EPSILON && size.y <= CMP_EPSILON && size.z <= CMP_EPSILON);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Vector3& get_position() const { return position; }
|
inline const Vector3 &get_position() const { return position; }
|
||||||
inline void set_position(const Vector3& p_position) { position=p_position; }
|
inline void set_position(const Vector3 &p_position) { position = p_position; }
|
||||||
inline const Vector3& get_size() const { return size; }
|
inline const Vector3 &get_size() const { return size; }
|
||||||
inline void set_size(const Vector3& p_size) { size=p_size; }
|
inline void set_size(const Vector3 &p_size) { size = p_size; }
|
||||||
|
|
||||||
|
bool operator==(const AABB &p_rval) const;
|
||||||
|
bool operator!=(const AABB &p_rval) const;
|
||||||
|
|
||||||
bool operator==(const AABB& p_rval) const;
|
bool intersects(const AABB &p_aabb) const; /// Both AABBs overlap
|
||||||
bool operator!=(const AABB& p_rval) const;
|
bool intersects_inclusive(const AABB &p_aabb) const; /// Both AABBs (or their faces) overlap
|
||||||
|
bool encloses(const AABB &p_aabb) const; /// p_aabb is completely inside this
|
||||||
|
|
||||||
bool intersects(const AABB& p_aabb) const; /// Both AABBs overlap
|
AABB merge(const AABB &p_with) const;
|
||||||
bool intersects_inclusive(const AABB& p_aabb) const; /// Both AABBs (or their faces) overlap
|
void merge_with(const AABB &p_aabb); ///merge with another AABB
|
||||||
bool encloses(const AABB & p_aabb) const; /// p_aabb is completely inside this
|
AABB intersection(const AABB &p_aabb) const; ///get box where two intersect, empty if no intersection occurs
|
||||||
|
bool intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip = nullptr, Vector3 *r_normal = nullptr) const;
|
||||||
AABB merge(const AABB& p_with) const;
|
bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip = nullptr, Vector3 *r_normal = nullptr) const;
|
||||||
void merge_with(const AABB& p_aabb); ///merge with another AABB
|
bool smits_intersect_ray(const Vector3 &from, const Vector3 &p_dir, real_t t0, real_t t1) const;
|
||||||
AABB intersection(const AABB& p_aabb) const; ///get box where two intersect, empty if no intersection occurs
|
|
||||||
bool intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3* r_clip=nullptr,Vector3* r_normal=nullptr) const;
|
|
||||||
bool intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r_clip=nullptr,Vector3* r_normal=nullptr) const;
|
|
||||||
bool smits_intersect_ray(const Vector3 &from,const Vector3& p_dir, real_t t0, real_t t1) const;
|
|
||||||
|
|
||||||
bool intersects_convex_shape(const Plane *p_plane, int p_plane_count) const;
|
bool intersects_convex_shape(const Plane *p_plane, int p_plane_count) const;
|
||||||
bool intersects_plane(const Plane &p_plane) const;
|
bool intersects_plane(const Plane &p_plane) const;
|
||||||
|
|
||||||
bool has_point(const Vector3& p_point) const;
|
bool has_point(const Vector3 &p_point) const;
|
||||||
Vector3 get_support(const Vector3& p_normal) const;
|
Vector3 get_support(const Vector3 &p_normal) const;
|
||||||
|
|
||||||
|
|
||||||
Vector3 get_longest_axis() const;
|
Vector3 get_longest_axis() const;
|
||||||
int get_longest_axis_index() const;
|
int get_longest_axis_index() const;
|
||||||
|
@ -63,21 +61,22 @@ public:
|
||||||
AABB grow(real_t p_by) const;
|
AABB grow(real_t p_by) const;
|
||||||
void grow_by(real_t p_amount);
|
void grow_by(real_t p_amount);
|
||||||
|
|
||||||
void get_edge(int p_edge,Vector3& r_from,Vector3& r_to) const;
|
void get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const;
|
||||||
Vector3 get_endpoint(int p_point) const;
|
Vector3 get_endpoint(int p_point) const;
|
||||||
|
|
||||||
AABB expand(const Vector3& p_vector) const;
|
AABB expand(const Vector3 &p_vector) const;
|
||||||
void project_range_in_plane(const Plane& p_plane,real_t &r_min,real_t& r_max) const;
|
void project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const;
|
||||||
void expand_to(const Vector3& p_vector); /** expand to contain a point if necesary */
|
void expand_to(const Vector3 &p_vector); /** expand to contain a point if necesary */
|
||||||
|
|
||||||
operator String() const;
|
operator String() const;
|
||||||
|
|
||||||
inline AABB() {}
|
inline AABB() {}
|
||||||
inline AABB(const Vector3 &p_pos,const Vector3& p_size) { position=p_pos; size=p_size; }
|
inline AABB(const Vector3 &p_pos, const Vector3 &p_size) {
|
||||||
|
position = p_pos;
|
||||||
|
size = p_size;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif // RECT3_H
|
#endif // RECT3_H
|
||||||
|
|
|
@ -21,57 +21,58 @@ class Object;
|
||||||
|
|
||||||
class Array {
|
class Array {
|
||||||
godot_array _godot_array;
|
godot_array _godot_array;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Array();
|
Array();
|
||||||
Array(const Array & other);
|
Array(const Array &other);
|
||||||
Array & operator=(const Array & other);
|
Array &operator=(const Array &other);
|
||||||
|
|
||||||
Array(const PoolByteArray& a);
|
Array(const PoolByteArray &a);
|
||||||
|
|
||||||
Array(const PoolIntArray& a);
|
Array(const PoolIntArray &a);
|
||||||
|
|
||||||
Array(const PoolRealArray& a);
|
Array(const PoolRealArray &a);
|
||||||
|
|
||||||
Array(const PoolStringArray& a);
|
Array(const PoolStringArray &a);
|
||||||
|
|
||||||
Array(const PoolVector2Array& a);
|
Array(const PoolVector2Array &a);
|
||||||
|
|
||||||
Array(const PoolVector3Array& a);
|
Array(const PoolVector3Array &a);
|
||||||
|
|
||||||
Array(const PoolColorArray& a);
|
Array(const PoolColorArray &a);
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
static Array make(Args... args) {
|
static Array make(Args... args) {
|
||||||
return helpers::append_all(Array(), args...);
|
return helpers::append_all(Array(), args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant& operator [](const int idx);
|
Variant &operator[](const int idx);
|
||||||
|
|
||||||
Variant operator [](const int idx) const;
|
Variant operator[](const int idx) const;
|
||||||
|
|
||||||
void append(const Variant& v);
|
void append(const Variant &v);
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
int count(const Variant& v);
|
int count(const Variant &v);
|
||||||
|
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
|
|
||||||
void erase(const Variant& v);
|
void erase(const Variant &v);
|
||||||
|
|
||||||
Variant front() const;
|
Variant front() const;
|
||||||
|
|
||||||
Variant back() const;
|
Variant back() const;
|
||||||
|
|
||||||
int find(const Variant& what, const int from = 0);
|
int find(const Variant &what, const int from = 0);
|
||||||
|
|
||||||
int find_last(const Variant& what);
|
int find_last(const Variant &what);
|
||||||
|
|
||||||
bool has(const Variant& what) const;
|
bool has(const Variant &what) const;
|
||||||
|
|
||||||
uint32_t hash() const;
|
uint32_t hash() const;
|
||||||
|
|
||||||
void insert(const int pos, const Variant& value);
|
void insert(const int pos, const Variant &value);
|
||||||
|
|
||||||
void invert();
|
void invert();
|
||||||
|
|
||||||
|
@ -81,9 +82,9 @@ public:
|
||||||
|
|
||||||
Variant pop_front();
|
Variant pop_front();
|
||||||
|
|
||||||
void push_back(const Variant& v);
|
void push_back(const Variant &v);
|
||||||
|
|
||||||
void push_front(const Variant& v);
|
void push_front(const Variant &v);
|
||||||
|
|
||||||
void remove(const int idx);
|
void remove(const int idx);
|
||||||
|
|
||||||
|
@ -91,16 +92,15 @@ public:
|
||||||
|
|
||||||
void resize(const int size);
|
void resize(const int size);
|
||||||
|
|
||||||
int rfind(const Variant& what, const int from = -1);
|
int rfind(const Variant &what, const int from = -1);
|
||||||
|
|
||||||
void sort();
|
void sort();
|
||||||
|
|
||||||
void sort_custom(Object *obj, const String& func);
|
void sort_custom(Object *obj, const String &func);
|
||||||
|
|
||||||
~Array();
|
~Array();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif // ARRAY_H
|
#endif // ARRAY_H
|
||||||
|
|
|
@ -16,27 +16,22 @@ public:
|
||||||
Vector3 x, y, z;
|
Vector3 x, y, z;
|
||||||
};
|
};
|
||||||
|
|
||||||
Basis(const Quat& p_quat); // euler
|
Basis(const Quat &p_quat); // euler
|
||||||
Basis(const Vector3& p_euler); // euler
|
Basis(const Vector3 &p_euler); // euler
|
||||||
Basis(const Vector3& p_axis, real_t p_phi);
|
Basis(const Vector3 &p_axis, real_t p_phi);
|
||||||
|
|
||||||
Basis(const Vector3& row0, const Vector3& row1, const Vector3& row2);
|
Basis(const Vector3 &row0, const Vector3 &row1, const Vector3 &row2);
|
||||||
|
|
||||||
Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz);
|
Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz);
|
||||||
|
|
||||||
Basis();
|
Basis();
|
||||||
|
|
||||||
|
const Vector3 &operator[](int axis) const;
|
||||||
|
Vector3 &operator[](int axis);
|
||||||
|
|
||||||
|
|
||||||
const Vector3& operator[](int axis) const;
|
|
||||||
Vector3& operator[](int axis);
|
|
||||||
|
|
||||||
void invert();
|
void invert();
|
||||||
|
|
||||||
bool isequal_approx(const Basis& a, const Basis& b) const;
|
bool isequal_approx(const Basis &a, const Basis &b) const;
|
||||||
|
|
||||||
|
|
||||||
bool is_orthogonal() const;
|
bool is_orthogonal() const;
|
||||||
|
|
||||||
|
@ -52,15 +47,15 @@ public:
|
||||||
|
|
||||||
Vector3 get_axis(int p_axis) const;
|
Vector3 get_axis(int p_axis) const;
|
||||||
|
|
||||||
void set_axis(int p_axis, const Vector3& p_value);
|
void set_axis(int p_axis, const Vector3 &p_value);
|
||||||
|
|
||||||
void rotate(const Vector3& p_axis, real_t p_phi);
|
void rotate(const Vector3 &p_axis, real_t p_phi);
|
||||||
|
|
||||||
Basis rotated(const Vector3& p_axis, real_t p_phi) const;
|
Basis rotated(const Vector3 &p_axis, real_t p_phi) const;
|
||||||
|
|
||||||
void scale( const Vector3& p_scale );
|
void scale(const Vector3 &p_scale);
|
||||||
|
|
||||||
Basis scaled( const Vector3& p_scale ) const;
|
Basis scaled(const Vector3 &p_scale) const;
|
||||||
|
|
||||||
Vector3 get_scale() const;
|
Vector3 get_scale() const;
|
||||||
|
|
||||||
|
@ -70,32 +65,31 @@ public:
|
||||||
void set_euler_yxz(const Vector3 &p_euler);
|
void set_euler_yxz(const Vector3 &p_euler);
|
||||||
|
|
||||||
inline Vector3 get_euler() const { return get_euler_yxz(); }
|
inline Vector3 get_euler() const { return get_euler_yxz(); }
|
||||||
inline void set_euler(const Vector3& p_euler) { set_euler_yxz(p_euler); }
|
inline void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); }
|
||||||
|
|
||||||
// transposed dot products
|
// transposed dot products
|
||||||
real_t tdotx(const Vector3& v) const;
|
real_t tdotx(const Vector3 &v) const;
|
||||||
real_t tdoty(const Vector3& v) const;
|
real_t tdoty(const Vector3 &v) const;
|
||||||
real_t tdotz(const Vector3& v) const;
|
real_t tdotz(const Vector3 &v) const;
|
||||||
|
|
||||||
bool operator==(const Basis& p_matrix) const;
|
bool operator==(const Basis &p_matrix) const;
|
||||||
|
|
||||||
bool operator!=(const Basis& p_matrix) const;
|
bool operator!=(const Basis &p_matrix) const;
|
||||||
|
|
||||||
Vector3 xform(const Vector3& p_vector) const;
|
Vector3 xform(const Vector3 &p_vector) const;
|
||||||
|
|
||||||
Vector3 xform_inv(const Vector3& p_vector) const;
|
Vector3 xform_inv(const Vector3 &p_vector) const;
|
||||||
void operator*=(const Basis& p_matrix);
|
void operator*=(const Basis &p_matrix);
|
||||||
|
|
||||||
Basis operator*(const Basis& p_matrix) const;
|
Basis operator*(const Basis &p_matrix) const;
|
||||||
|
|
||||||
|
void operator+=(const Basis &p_matrix);
|
||||||
|
|
||||||
void operator+=(const Basis& p_matrix);
|
Basis operator+(const Basis &p_matrix) const;
|
||||||
|
|
||||||
Basis operator+(const Basis& p_matrix) const;
|
void operator-=(const Basis &p_matrix);
|
||||||
|
|
||||||
void operator-=(const Basis& p_matrix);
|
Basis operator-(const Basis &p_matrix) const;
|
||||||
|
|
||||||
Basis operator-(const Basis& p_matrix) const;
|
|
||||||
|
|
||||||
void operator*=(real_t p_val);
|
void operator*=(real_t p_val);
|
||||||
|
|
||||||
|
@ -105,14 +99,12 @@ public:
|
||||||
|
|
||||||
void set_orthogonal_index(int p_index); // down below
|
void set_orthogonal_index(int p_index); // down below
|
||||||
|
|
||||||
|
|
||||||
operator String() const;
|
operator String() const;
|
||||||
|
|
||||||
void get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const;
|
void get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const;
|
||||||
|
|
||||||
/* create / set */
|
/* create / set */
|
||||||
|
|
||||||
|
|
||||||
void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz);
|
void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz);
|
||||||
|
|
||||||
Vector3 get_column(int i) const;
|
Vector3 get_column(int i) const;
|
||||||
|
@ -120,9 +112,9 @@ public:
|
||||||
Vector3 get_row(int i) const;
|
Vector3 get_row(int i) const;
|
||||||
Vector3 get_main_diagonal() const;
|
Vector3 get_main_diagonal() const;
|
||||||
|
|
||||||
void set_row(int i, const Vector3& p_row);
|
void set_row(int i, const Vector3 &p_row);
|
||||||
|
|
||||||
Basis transpose_xform(const Basis& m) const;
|
Basis transpose_xform(const Basis &m) const;
|
||||||
|
|
||||||
void orthonormalize();
|
void orthonormalize();
|
||||||
|
|
||||||
|
@ -133,10 +125,8 @@ public:
|
||||||
Basis diagonalize();
|
Basis diagonalize();
|
||||||
|
|
||||||
operator Quat() const;
|
operator Quat() const;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif // BASIS_H
|
#endif // BASIS_H
|
||||||
|
|
|
@ -9,14 +9,11 @@
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
|
|
||||||
struct Color {
|
struct Color {
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// static float _parse_col(const String& p_str, int p_ofs);
|
// static float _parse_col(const String& p_str, int p_ofs);
|
||||||
public:
|
public:
|
||||||
|
|
||||||
union {
|
union {
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
@ -28,8 +25,8 @@ public:
|
||||||
float components[4];
|
float components[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const Color &p_color) const { return (r==p_color.r && g==p_color.g && b==p_color.b && a==p_color.a ); }
|
inline bool operator==(const Color &p_color) const { return (r == p_color.r && g == p_color.g && b == p_color.b && a == p_color.a); }
|
||||||
inline bool operator!=(const Color &p_color) const { return (r!=p_color.r || g!=p_color.g || b!=p_color.b || a!=p_color.a ); }
|
inline bool operator!=(const Color &p_color) const { return (r != p_color.r || g != p_color.g || b != p_color.b || a != p_color.a); }
|
||||||
|
|
||||||
uint32_t to_32() const;
|
uint32_t to_32() const;
|
||||||
|
|
||||||
|
@ -43,12 +40,12 @@ public:
|
||||||
|
|
||||||
float get_v() const;
|
float get_v() const;
|
||||||
|
|
||||||
void set_hsv(float p_h, float p_s, float p_v, float p_alpha=1.0);
|
void set_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0);
|
||||||
|
|
||||||
inline float& operator[](int idx) {
|
inline float &operator[](int idx) {
|
||||||
return components[idx];
|
return components[idx];
|
||||||
}
|
}
|
||||||
inline const float& operator[](int idx) const {
|
inline const float &operator[](int idx) const {
|
||||||
return components[idx];
|
return components[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,21 +57,21 @@ public:
|
||||||
|
|
||||||
Color contrasted() const;
|
Color contrasted() const;
|
||||||
|
|
||||||
Color linear_interpolate(const Color& p_b, float p_t) const;
|
Color linear_interpolate(const Color &p_b, float p_t) const;
|
||||||
|
|
||||||
Color blend(const Color& p_over) const;
|
Color blend(const Color &p_over) const;
|
||||||
|
|
||||||
Color to_linear() const;
|
Color to_linear() const;
|
||||||
|
|
||||||
static Color hex(uint32_t p_hex);
|
static Color hex(uint32_t p_hex);
|
||||||
|
|
||||||
static Color html(const String& p_color);
|
static Color html(const String &p_color);
|
||||||
|
|
||||||
static bool html_is_valid(const String& p_color);
|
static bool html_is_valid(const String &p_color);
|
||||||
|
|
||||||
String to_html(bool p_alpha=true) const;
|
String to_html(bool p_alpha = true) const;
|
||||||
|
|
||||||
bool operator<(const Color& p_color) const; //used in set keys
|
bool operator<(const Color &p_color) const; //used in set keys
|
||||||
|
|
||||||
operator String() const;
|
operator String() const;
|
||||||
|
|
||||||
|
@ -82,15 +79,23 @@ public:
|
||||||
* No construct parameters, r=0, g=0, b=0. a=255
|
* No construct parameters, r=0, g=0, b=0. a=255
|
||||||
*/
|
*/
|
||||||
inline Color() {
|
inline Color() {
|
||||||
r=0; g=0; b=0; a=1.0;
|
r = 0;
|
||||||
|
g = 0;
|
||||||
|
b = 0;
|
||||||
|
a = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RGB / RGBA construct parameters. Alpha is optional, but defaults to 1.0
|
* RGB / RGBA construct parameters. Alpha is optional, but defaults to 1.0
|
||||||
*/
|
*/
|
||||||
inline Color(float p_r,float p_g,float p_b,float p_a=1.0) { r=p_r; g=p_g; b=p_b; a=p_a; }
|
inline Color(float p_r, float p_g, float p_b, float p_a = 1.0) {
|
||||||
|
r = p_r;
|
||||||
|
g = p_g;
|
||||||
|
b = p_b;
|
||||||
|
a = p_a;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif // COLOR_H
|
#endif // COLOR_H
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
#include "Plane.hpp"
|
#include "Plane.hpp"
|
||||||
#include "PoolArrays.hpp"
|
#include "PoolArrays.hpp"
|
||||||
#include "Quat.hpp"
|
#include "Quat.hpp"
|
||||||
#include "Rect2.hpp"
|
|
||||||
#include "RID.hpp"
|
#include "RID.hpp"
|
||||||
|
#include "Rect2.hpp"
|
||||||
#include "String.hpp"
|
#include "String.hpp"
|
||||||
#include "Transform.hpp"
|
#include "Transform.hpp"
|
||||||
#include "Transform2D.hpp"
|
#include "Transform2D.hpp"
|
||||||
|
@ -23,5 +23,4 @@
|
||||||
|
|
||||||
#include "Wrapped.hpp"
|
#include "Wrapped.hpp"
|
||||||
|
|
||||||
|
|
||||||
#endif // CORETYPES_H
|
#endif // CORETYPES_H
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef DEFS_H
|
#ifndef DEFS_H
|
||||||
#define DEFS_H
|
#define DEFS_H
|
||||||
|
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
enum class Error {
|
enum class Error {
|
||||||
|
@ -58,50 +57,50 @@ enum class Error {
|
||||||
ERR_WTF = ERR_OMFG_THIS_IS_VERY_VERY_BAD ///< short version of the above
|
ERR_WTF = ERR_OMFG_THIS_IS_VERY_VERY_BAD ///< short version of the above
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace helpers {
|
namespace helpers {
|
||||||
template <typename T, typename ValueT>
|
template <typename T, typename ValueT>
|
||||||
T append_all (T appendable, ValueT value) {
|
T append_all(T appendable, ValueT value) {
|
||||||
appendable.append(value);
|
appendable.append(value);
|
||||||
return appendable;
|
return appendable;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename ValueT, typename... Args>
|
template <typename T, typename ValueT, typename... Args>
|
||||||
T append_all (T appendable, ValueT value, Args... args) {
|
T append_all(T appendable, ValueT value, Args... args) {
|
||||||
appendable.append(value);
|
appendable.append(value);
|
||||||
return append_all(appendable, args...);
|
return append_all(appendable, args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T append_all (T appendable) {
|
T append_all(T appendable) {
|
||||||
return appendable;
|
return appendable;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename KV, typename KeyT, typename ValueT>
|
template <typename KV, typename KeyT, typename ValueT>
|
||||||
KV add_all (KV kv, KeyT key, ValueT value) {
|
KV add_all(KV kv, KeyT key, ValueT value) {
|
||||||
kv[key] = value;
|
kv[key] = value;
|
||||||
return kv;
|
return kv;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename KV, typename KeyT, typename ValueT, typename... Args>
|
template <typename KV, typename KeyT, typename ValueT, typename... Args>
|
||||||
KV add_all (KV kv, KeyT key, ValueT value, Args... args) {
|
KV add_all(KV kv, KeyT key, ValueT value, Args... args) {
|
||||||
kv[key] = value;
|
kv[key] = value;
|
||||||
return add_all(kv, args...);
|
return add_all(kv, args...);
|
||||||
}
|
|
||||||
|
|
||||||
template <typename KV>
|
|
||||||
KV add_all (KV kv) {
|
|
||||||
return kv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename KV>
|
||||||
|
KV add_all(KV kv) {
|
||||||
|
return kv;
|
||||||
|
}
|
||||||
|
} // namespace helpers
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
typedef float real_t;
|
typedef float real_t;
|
||||||
|
|
||||||
#define CMP_EPSILON 0.00001
|
#define CMP_EPSILON 0.00001
|
||||||
#define CMP_EPSILON2 (CMP_EPSILON*CMP_EPSILON)
|
#define CMP_EPSILON2 (CMP_EPSILON * CMP_EPSILON)
|
||||||
#define Math_PI 3.14159265358979323846
|
#define Math_PI 3.14159265358979323846
|
||||||
|
|
||||||
#define _PLANE_EQ_DOT_EPSILON 0.999
|
#define _PLANE_EQ_DOT_EPSILON 0.999
|
||||||
|
@ -109,7 +108,9 @@ typedef float real_t;
|
||||||
|
|
||||||
// ERR/WARN macros
|
// ERR/WARN macros
|
||||||
#ifndef WARN_PRINT
|
#ifndef WARN_PRINT
|
||||||
#define WARN_PRINT(msg) fprintf(stdout, "ERROR: %s\n", msg); fflush(stdout)
|
#define WARN_PRINT(msg) \
|
||||||
|
fprintf(stdout, "ERROR: %s\n", msg); \
|
||||||
|
fflush(stdout)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WARN_PRINTS
|
#ifndef WARN_PRINTS
|
||||||
|
@ -129,24 +130,51 @@ typedef float real_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ERR_FAIL_V
|
#ifndef ERR_FAIL_V
|
||||||
#define ERR_FAIL_V(a) { ERR_FAIL(); return a; }
|
#define ERR_FAIL_V(a) \
|
||||||
|
{ \
|
||||||
|
ERR_FAIL(); \
|
||||||
|
return a; \
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ERR_FAIL_COND
|
#ifndef ERR_FAIL_COND
|
||||||
#define ERR_FAIL_COND(a) do { if (a) { ERR_PRINT(#a); return; } } while(0)
|
#define ERR_FAIL_COND(a) \
|
||||||
|
do { \
|
||||||
|
if (a) { \
|
||||||
|
ERR_PRINT(#a); \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ERR_FAIL_COND_V
|
#ifndef ERR_FAIL_COND_V
|
||||||
#define ERR_FAIL_COND_V(cond, ret) do { if (cond) { ERR_PRINT(#cond); return ret; } } while(0)
|
#define ERR_FAIL_COND_V(cond, ret) \
|
||||||
|
do { \
|
||||||
|
if (cond) { \
|
||||||
|
ERR_PRINT(#cond); \
|
||||||
|
return ret; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ERR_FAIL_INDEX
|
#ifndef ERR_FAIL_INDEX
|
||||||
#define ERR_FAIL_INDEX(a, b) do { if (a < 0 || a >= b) { ERR_FAIL(); return; } } while(0)
|
#define ERR_FAIL_INDEX(a, b) \
|
||||||
|
do { \
|
||||||
|
if (a < 0 || a >= b) { \
|
||||||
|
ERR_FAIL(); \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ERR_FAIL_INDEX_V
|
#ifndef ERR_FAIL_INDEX_V
|
||||||
#define ERR_FAIL_INDEX_V(a, b, c) do { if (a < 0 || a >= b) { ERR_FAIL(); return c; } } while(0)
|
#define ERR_FAIL_INDEX_V(a, b, c) \
|
||||||
|
do { \
|
||||||
|
if (a < 0 || a >= b) { \
|
||||||
|
ERR_FAIL(); \
|
||||||
|
return c; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif // DEFS_H
|
#endif // DEFS_H
|
||||||
|
|
|
@ -11,10 +11,11 @@ namespace godot {
|
||||||
|
|
||||||
class Dictionary {
|
class Dictionary {
|
||||||
godot_dictionary _godot_dictionary;
|
godot_dictionary _godot_dictionary;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Dictionary();
|
Dictionary();
|
||||||
Dictionary(const Dictionary & other);
|
Dictionary(const Dictionary &other);
|
||||||
Dictionary & operator=(const Dictionary & other);
|
Dictionary &operator=(const Dictionary &other);
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
static Dictionary make(Args... args) {
|
static Dictionary make(Args... args) {
|
||||||
|
@ -25,19 +26,19 @@ public:
|
||||||
|
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
|
|
||||||
void erase(const Variant& key);
|
void erase(const Variant &key);
|
||||||
|
|
||||||
bool has(const Variant& key) const;
|
bool has(const Variant &key) const;
|
||||||
|
|
||||||
bool has_all(const Array& keys) const;
|
bool has_all(const Array &keys) const;
|
||||||
|
|
||||||
uint32_t hash() const;
|
uint32_t hash() const;
|
||||||
|
|
||||||
Array keys() const;
|
Array keys() const;
|
||||||
|
|
||||||
Variant &operator [](const Variant& key);
|
Variant &operator[](const Variant &key);
|
||||||
|
|
||||||
const Variant &operator [](const Variant& key) const;
|
const Variant &operator[](const Variant &key) const;
|
||||||
|
|
||||||
int size() const;
|
int size() const;
|
||||||
|
|
||||||
|
@ -46,9 +47,8 @@ public:
|
||||||
Array values() const;
|
Array values() const;
|
||||||
|
|
||||||
~Dictionary();
|
~Dictionary();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif // DICTIONARY_H
|
#endif // DICTIONARY_H
|
||||||
|
|
|
@ -9,82 +9,90 @@
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
|
||||||
#include "CoreTypes.hpp"
|
#include "CoreTypes.hpp"
|
||||||
#include "Variant.hpp"
|
|
||||||
#include "Ref.hpp"
|
#include "Ref.hpp"
|
||||||
#include "TagDB.hpp"
|
#include "TagDB.hpp"
|
||||||
|
#include "Variant.hpp"
|
||||||
|
|
||||||
#include "Object.hpp"
|
#include "Object.hpp"
|
||||||
|
|
||||||
#include "GodotGlobal.hpp"
|
#include "GodotGlobal.hpp"
|
||||||
|
|
||||||
#include <NativeScript.hpp>
|
|
||||||
#include <GDNativeLibrary.hpp>
|
#include <GDNativeLibrary.hpp>
|
||||||
|
#include <NativeScript.hpp>
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
|
template <class T>
|
||||||
template<class T>
|
T *as(const Object *obj) {
|
||||||
T *as(const Object *obj)
|
return (T *)godot::nativescript_api->godot_nativescript_get_userdata(obj->_owner);
|
||||||
{
|
|
||||||
return (T *) godot::nativescript_api->godot_nativescript_get_userdata(obj->_owner);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
T *get_wrapper(godot_object *obj)
|
T *get_wrapper(godot_object *obj) {
|
||||||
{
|
return (T *)godot::nativescript_1_1_api->godot_nativescript_get_instance_binding_data(godot::_RegisterState::language_index, obj);
|
||||||
return (T *) godot::nativescript_1_1_api->godot_nativescript_get_instance_binding_data(godot::_RegisterState::language_index, obj);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define GODOT_CLASS(Name, Base) \
|
#define GODOT_CLASS(Name, Base) \
|
||||||
public: inline static const char *___get_type_name() { return static_cast<const char *>(#Name); } \
|
\
|
||||||
enum { ___CLASS_IS_SCRIPT = 1, }; \
|
public: \
|
||||||
inline static Name *_new() { godot::NativeScript *script = godot::NativeScript::_new(); script->set_library(godot::get_wrapper<godot::GDNativeLibrary>((godot_object *) godot::gdnlib)); script->set_class_name(#Name); Name *instance = godot::as<Name>(script->new_()); return instance; } \
|
inline static const char *___get_type_name() { return static_cast<const char *>(#Name); } \
|
||||||
|
enum { ___CLASS_IS_SCRIPT = 1, \
|
||||||
|
}; \
|
||||||
|
inline static Name *_new() { \
|
||||||
|
godot::NativeScript *script = godot::NativeScript::_new(); \
|
||||||
|
script->set_library(godot::get_wrapper<godot::GDNativeLibrary>((godot_object *)godot::gdnlib)); \
|
||||||
|
script->set_class_name(#Name); \
|
||||||
|
Name *instance = godot::as<Name>(script->new_()); \
|
||||||
|
return instance; \
|
||||||
|
} \
|
||||||
inline static const char *___get_base_type_name() { return Base::___get_class_name(); } \
|
inline static const char *___get_base_type_name() { return Base::___get_class_name(); } \
|
||||||
inline static Object *___get_from_variant(godot::Variant a) { return (godot::Object *) godot::as<Name>(godot::Object::___get_from_variant(a)); } \
|
inline static Object *___get_from_variant(godot::Variant a) { return (godot::Object *)godot::as<Name>(godot::Object::___get_from_variant(a)); } \
|
||||||
private:
|
\
|
||||||
|
private:
|
||||||
|
|
||||||
#define GODOT_SUBCLASS(Name, Base) \
|
#define GODOT_SUBCLASS(Name, Base) \
|
||||||
public: inline static const char *___get_type_name() { return static_cast<const char *>(#Name); } \
|
\
|
||||||
enum { ___CLASS_IS_SCRIPT = 1, }; \
|
public: \
|
||||||
inline static Name *_new() { godot::NativeScript *script = godot::NativeScript::_new(); script->set_library(godot::get_wrapper<godot::GDNativeLibrary>((godot_object *) godot::gdnlib)); script->set_class_name(#Name); Name *instance = godot::as<Name>(script->new_()); return instance; } \
|
inline static const char *___get_type_name() { return static_cast<const char *>(#Name); } \
|
||||||
|
enum { ___CLASS_IS_SCRIPT = 1, \
|
||||||
|
}; \
|
||||||
|
inline static Name *_new() { \
|
||||||
|
godot::NativeScript *script = godot::NativeScript::_new(); \
|
||||||
|
script->set_library(godot::get_wrapper<godot::GDNativeLibrary>((godot_object *)godot::gdnlib)); \
|
||||||
|
script->set_class_name(#Name); \
|
||||||
|
Name *instance = godot::as<Name>(script->new_()); \
|
||||||
|
return instance; \
|
||||||
|
} \
|
||||||
inline static const char *___get_base_type_name() { return #Base; } \
|
inline static const char *___get_base_type_name() { return #Base; } \
|
||||||
inline static Object *___get_from_variant(godot::Variant a) { return (godot::Object *) godot::as<Name>(godot::Object::___get_from_variant(a)); } \
|
inline static Object *___get_from_variant(godot::Variant a) { return (godot::Object *)godot::as<Name>(godot::Object::___get_from_variant(a)); } \
|
||||||
private:
|
\
|
||||||
|
private:
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
struct _ArgCast {
|
struct _ArgCast {
|
||||||
static T _arg_cast(Variant a)
|
static T _arg_cast(Variant a) {
|
||||||
{
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
struct _ArgCast<T*> {
|
struct _ArgCast<T *> {
|
||||||
static T *_arg_cast(Variant a)
|
static T *_arg_cast(Variant a) {
|
||||||
{
|
return (T *)T::___get_from_variant(a);
|
||||||
return (T *) T::___get_from_variant(a);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template <>
|
||||||
struct _ArgCast<Variant> {
|
struct _ArgCast<Variant> {
|
||||||
static Variant _arg_cast(Variant a)
|
static Variant _arg_cast(Variant a) {
|
||||||
{
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// instance and destroy funcs
|
// instance and destroy funcs
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
void *_godot_class_instance_func(godot_object *p, void *method_data)
|
void *_godot_class_instance_func(godot_object *p, void *method_data) {
|
||||||
{
|
|
||||||
T *d = new T();
|
T *d = new T();
|
||||||
d->_owner = p;
|
d->_owner = p;
|
||||||
d->_type_tag = typeid(T).hash_code();
|
d->_type_tag = typeid(T).hash_code();
|
||||||
|
@ -92,17 +100,14 @@ void *_godot_class_instance_func(godot_object *p, void *method_data)
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
void _godot_class_destroy_func(godot_object *p, void *method_data, void *data)
|
void _godot_class_destroy_func(godot_object *p, void *method_data, void *data) {
|
||||||
{
|
T *d = (T *)data;
|
||||||
T *d = (T *) data;
|
|
||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
template<class T>
|
void register_class() {
|
||||||
void register_class()
|
|
||||||
{
|
|
||||||
godot_instance_create_func create = {};
|
godot_instance_create_func create = {};
|
||||||
create.create_func = _godot_class_instance_func<T>;
|
create.create_func = _godot_class_instance_func<T>;
|
||||||
|
|
||||||
|
@ -112,13 +117,12 @@ void register_class()
|
||||||
_TagDB::register_type(typeid(T).hash_code(), typeid(T).hash_code());
|
_TagDB::register_type(typeid(T).hash_code(), typeid(T).hash_code());
|
||||||
|
|
||||||
godot::nativescript_api->godot_nativescript_register_class(godot::_RegisterState::nativescript_handle, T::___get_type_name(), T::___get_base_type_name(), create, destroy);
|
godot::nativescript_api->godot_nativescript_register_class(godot::_RegisterState::nativescript_handle, T::___get_type_name(), T::___get_base_type_name(), create, destroy);
|
||||||
godot::nativescript_1_1_api->godot_nativescript_set_type_tag(godot::_RegisterState::nativescript_handle, T::___get_type_name(), (const void *) typeid(T).hash_code());
|
godot::nativescript_1_1_api->godot_nativescript_set_type_tag(godot::_RegisterState::nativescript_handle, T::___get_type_name(), (const void *)typeid(T).hash_code());
|
||||||
T::_register_methods();
|
T::_register_methods();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
void register_tool_class()
|
void register_tool_class() {
|
||||||
{
|
|
||||||
godot_instance_create_func create = {};
|
godot_instance_create_func create = {};
|
||||||
create.create_func = _godot_class_instance_func<T>;
|
create.create_func = _godot_class_instance_func<T>;
|
||||||
|
|
||||||
|
@ -128,155 +132,109 @@ void register_tool_class()
|
||||||
_TagDB::register_type(typeid(T).hash_code(), typeid(T).hash_code());
|
_TagDB::register_type(typeid(T).hash_code(), typeid(T).hash_code());
|
||||||
|
|
||||||
godot::nativescript_api->godot_nativescript_register_tool_class(godot::_RegisterState::nativescript_handle, T::___get_type_name(), T::___get_base_type_name(), create, destroy);
|
godot::nativescript_api->godot_nativescript_register_tool_class(godot::_RegisterState::nativescript_handle, T::___get_type_name(), T::___get_base_type_name(), create, destroy);
|
||||||
godot::nativescript_1_1_api->godot_nativescript_set_type_tag(godot::_RegisterState::nativescript_handle, T::___get_type_name(), (const void *) typeid(T).hash_code());
|
godot::nativescript_1_1_api->godot_nativescript_set_type_tag(godot::_RegisterState::nativescript_handle, T::___get_type_name(), (const void *)typeid(T).hash_code());
|
||||||
T::_register_methods();
|
T::_register_methods();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// method registering
|
// method registering
|
||||||
|
|
||||||
typedef godot_variant (*__godot_wrapper_method)(godot_object *, void *, void *, int, godot_variant **);
|
typedef godot_variant (*__godot_wrapper_method)(godot_object *, void *, void *, int, godot_variant **);
|
||||||
|
|
||||||
|
template <class T, class R, class... args>
|
||||||
template<class T, class R, class ...args>
|
const char *___get_method_class_name(R (T::*p)(args... a)) {
|
||||||
const char *___get_method_class_name(R (T::*p)(args... a))
|
|
||||||
{
|
|
||||||
return T::___get_type_name();
|
return T::___get_type_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class R, class ...args>
|
template <class T, class R, class... args>
|
||||||
const char *___get_method_class_name(R (T::*p)(args... a) const)
|
const char *___get_method_class_name(R (T::*p)(args... a) const) {
|
||||||
{
|
|
||||||
return T::___get_type_name();
|
return T::___get_type_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Okay, time for some template magic.
|
// Okay, time for some template magic.
|
||||||
// Many thanks to manpat from the GDL Discord Server.
|
// Many thanks to manpat from the GDL Discord Server.
|
||||||
|
|
||||||
|
|
||||||
// This is stuff that's available in C++14 I think, but whatever.
|
// This is stuff that's available in C++14 I think, but whatever.
|
||||||
|
|
||||||
template<int... I>
|
template <int... I>
|
||||||
struct __Sequence{};
|
struct __Sequence {};
|
||||||
|
|
||||||
template<int N, int... I>
|
template <int N, int... I>
|
||||||
struct __construct_sequence {
|
struct __construct_sequence {
|
||||||
using type = typename __construct_sequence<N-1, N-1, I...>::type;
|
using type = typename __construct_sequence<N - 1, N - 1, I...>::type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<int... I>
|
template <int... I>
|
||||||
struct __construct_sequence<0, I...> {
|
struct __construct_sequence<0, I...> {
|
||||||
using type = __Sequence<I...>;
|
using type = __Sequence<I...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Now the wrapping part.
|
// Now the wrapping part.
|
||||||
template<class T, class R, class... As>
|
template <class T, class R, class... As>
|
||||||
struct _WrappedMethod {
|
struct _WrappedMethod {
|
||||||
R (T::*f)(As...);
|
R(T::*f)
|
||||||
|
(As...);
|
||||||
|
|
||||||
template<int... I>
|
template <int... I>
|
||||||
void apply(Variant* ret, T* obj, Variant** args, __Sequence<I...>) {
|
void apply(Variant *ret, T *obj, Variant **args, __Sequence<I...>) {
|
||||||
*ret = (obj->*f)( _ArgCast<As>::_arg_cast(*args[I])... );
|
*ret = (obj->*f)(_ArgCast<As>::_arg_cast(*args[I])...);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T, class... As>
|
template <class T, class... As>
|
||||||
struct _WrappedMethod<T, void, As...> {
|
struct _WrappedMethod<T, void, As...> {
|
||||||
void (T::*f)(As...);
|
void (T::*f)(As...);
|
||||||
|
|
||||||
template<int... I>
|
template <int... I>
|
||||||
void apply(Variant* ret, T* obj, Variant** args, __Sequence<I...>) {
|
void apply(Variant *ret, T *obj, Variant **args, __Sequence<I...>) {
|
||||||
(obj->*f)( _ArgCast<As>::_arg_cast(*args[I])... );
|
(obj->*f)(_ArgCast<As>::_arg_cast(*args[I])...);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class T, class R, class... As>
|
||||||
template<class T, class R, class... As>
|
godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args) {
|
||||||
godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args)
|
|
||||||
{
|
|
||||||
godot_variant v;
|
godot_variant v;
|
||||||
godot::api->godot_variant_new_nil(&v);
|
godot::api->godot_variant_new_nil(&v);
|
||||||
|
|
||||||
T *obj = (T *) user_data;
|
T *obj = (T *)user_data;
|
||||||
_WrappedMethod<T, R, As...> *method = (_WrappedMethod<T, R, As...>*) method_data;
|
_WrappedMethod<T, R, As...> *method = (_WrappedMethod<T, R, As...> *)method_data;
|
||||||
|
|
||||||
Variant *var = (Variant *) &v;
|
Variant *var = (Variant *)&v;
|
||||||
Variant **arg = (Variant **) args;
|
Variant **arg = (Variant **)args;
|
||||||
|
|
||||||
method->apply(var, obj, arg, typename __construct_sequence<sizeof...(As)>::type {});
|
method->apply(var, obj, arg, typename __construct_sequence<sizeof...(As)>::type{});
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class R, class... As>
|
template <class T, class R, class... As>
|
||||||
void *___make_wrapper_function(R (T::*f)(As...))
|
void *___make_wrapper_function(R (T::*f)(As...)) {
|
||||||
{
|
|
||||||
using MethodType = _WrappedMethod<T, R, As...>;
|
using MethodType = _WrappedMethod<T, R, As...>;
|
||||||
MethodType *p = (MethodType *) godot::api->godot_alloc(sizeof(MethodType));
|
MethodType *p = (MethodType *)godot::api->godot_alloc(sizeof(MethodType));
|
||||||
p->f = f;
|
p->f = f;
|
||||||
return (void *) p;
|
return (void *)p;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class R, class... As>
|
template <class T, class R, class... As>
|
||||||
__godot_wrapper_method ___get_wrapper_function(R (T::*f)(As...))
|
__godot_wrapper_method ___get_wrapper_function(R (T::*f)(As...)) {
|
||||||
{
|
return (__godot_wrapper_method)&__wrapped_method<T, R, As...>;
|
||||||
return (__godot_wrapper_method) &__wrapped_method<T, R, As...>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T, class R, class... A>
|
||||||
|
void *___make_wrapper_function(R (T::*f)(A...) const) {
|
||||||
|
return ___make_wrapper_function((R(T::*)(A...))f);
|
||||||
|
|
||||||
template<class T, class R, class ...A>
|
|
||||||
void *___make_wrapper_function(R (T::*f)(A...) const)
|
|
||||||
{
|
|
||||||
return ___make_wrapper_function((R (T::*)(A...)) f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T, class R, class... A>
|
||||||
template<class T, class R, class ...A>
|
__godot_wrapper_method ___get_wrapper_function(R (T::*f)(A...) const) {
|
||||||
__godot_wrapper_method ___get_wrapper_function(R (T::*f)(A...) const)
|
return ___get_wrapper_function((R(T::*)(A...))f);
|
||||||
{
|
|
||||||
return ___get_wrapper_function((R (T::*)(A...)) f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class M>
|
||||||
|
void register_method(const char *name, M method_ptr, godot_method_rpc_mode rpc_type = GODOT_METHOD_RPC_MODE_DISABLED) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class M>
|
|
||||||
void register_method(const char *name, M method_ptr, godot_method_rpc_mode rpc_type = GODOT_METHOD_RPC_MODE_DISABLED)
|
|
||||||
{
|
|
||||||
godot_instance_method method = {};
|
godot_instance_method method = {};
|
||||||
method.method_data = ___make_wrapper_function(method_ptr);
|
method.method_data = ___make_wrapper_function(method_ptr);
|
||||||
method.free_func = godot::api->godot_free;
|
method.free_func = godot::api->godot_free;
|
||||||
method.method = (__godot_wrapper_method) ___get_wrapper_function(method_ptr);
|
method.method = (__godot_wrapper_method)___get_wrapper_function(method_ptr);
|
||||||
|
|
||||||
|
|
||||||
godot_method_attributes attr = {};
|
godot_method_attributes attr = {};
|
||||||
attr.rpc_type = rpc_type;
|
attr.rpc_type = rpc_type;
|
||||||
|
@ -284,34 +242,31 @@ void register_method(const char *name, M method_ptr, godot_method_rpc_mode rpc_t
|
||||||
godot::nativescript_api->godot_nativescript_register_method(godot::_RegisterState::nativescript_handle, ___get_method_class_name(method_ptr), name, attr, method);
|
godot::nativescript_api->godot_nativescript_register_method(godot::_RegisterState::nativescript_handle, ___get_method_class_name(method_ptr), name, attr, method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T, class P>
|
||||||
|
|
||||||
template<class T, class P>
|
|
||||||
struct _PropertySetFunc {
|
struct _PropertySetFunc {
|
||||||
void (T::*f)(P);
|
void (T::*f)(P);
|
||||||
static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant *value)
|
static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant *value) {
|
||||||
{
|
_PropertySetFunc<T, P> *set_func = (_PropertySetFunc<T, P> *)method_data;
|
||||||
_PropertySetFunc<T, P> *set_func = (_PropertySetFunc<T, P> *) method_data;
|
T *obj = (T *)user_data;
|
||||||
T *obj = (T *) user_data;
|
|
||||||
|
|
||||||
Variant *v = (Variant *) value;
|
Variant *v = (Variant *)value;
|
||||||
|
|
||||||
(obj->*(set_func->f))(_ArgCast<P>::_arg_cast(*v));
|
(obj->*(set_func->f))(_ArgCast<P>::_arg_cast(*v));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T, class P>
|
template <class T, class P>
|
||||||
struct _PropertyGetFunc {
|
struct _PropertyGetFunc {
|
||||||
P (T::*f)();
|
P(T::*f)
|
||||||
static godot_variant _wrapped_getter(godot_object *object, void *method_data, void *user_data)
|
();
|
||||||
{
|
static godot_variant _wrapped_getter(godot_object *object, void *method_data, void *user_data) {
|
||||||
_PropertyGetFunc<T, P> *get_func = (_PropertyGetFunc<T, P> *) method_data;
|
_PropertyGetFunc<T, P> *get_func = (_PropertyGetFunc<T, P> *)method_data;
|
||||||
T *obj = (T *) user_data;
|
T *obj = (T *)user_data;
|
||||||
|
|
||||||
godot_variant var;
|
godot_variant var;
|
||||||
godot::api->godot_variant_new_nil(&var);
|
godot::api->godot_variant_new_nil(&var);
|
||||||
|
|
||||||
Variant *v = (Variant *) &var;
|
Variant *v = (Variant *)&var;
|
||||||
|
|
||||||
*v = (obj->*(get_func->f))();
|
*v = (obj->*(get_func->f))();
|
||||||
|
|
||||||
|
@ -319,37 +274,30 @@ struct _PropertyGetFunc {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class T, class P>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class T, class P>
|
|
||||||
struct _PropertyDefaultSetFunc {
|
struct _PropertyDefaultSetFunc {
|
||||||
P (T::*f);
|
P(T::*f);
|
||||||
static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant *value)
|
static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant *value) {
|
||||||
{
|
_PropertyDefaultSetFunc<T, P> *set_func = (_PropertyDefaultSetFunc<T, P> *)method_data;
|
||||||
_PropertyDefaultSetFunc<T, P> *set_func = (_PropertyDefaultSetFunc<T, P> *) method_data;
|
T *obj = (T *)user_data;
|
||||||
T *obj = (T *) user_data;
|
|
||||||
|
|
||||||
Variant *v = (Variant *) value;
|
Variant *v = (Variant *)value;
|
||||||
|
|
||||||
(obj->*(set_func->f)) = _ArgCast<P>::_arg_cast(*v);
|
(obj->*(set_func->f)) = _ArgCast<P>::_arg_cast(*v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T, class P>
|
template <class T, class P>
|
||||||
struct _PropertyDefaultGetFunc {
|
struct _PropertyDefaultGetFunc {
|
||||||
P (T::*f);
|
P(T::*f);
|
||||||
static godot_variant _wrapped_getter(godot_object *object, void *method_data, void *user_data)
|
static godot_variant _wrapped_getter(godot_object *object, void *method_data, void *user_data) {
|
||||||
{
|
_PropertyDefaultGetFunc<T, P> *get_func = (_PropertyDefaultGetFunc<T, P> *)method_data;
|
||||||
_PropertyDefaultGetFunc<T, P> *get_func = (_PropertyDefaultGetFunc<T, P> *) method_data;
|
T *obj = (T *)user_data;
|
||||||
T *obj = (T *) user_data;
|
|
||||||
|
|
||||||
godot_variant var;
|
godot_variant var;
|
||||||
godot::api->godot_variant_new_nil(&var);
|
godot::api->godot_variant_new_nil(&var);
|
||||||
|
|
||||||
Variant *v = (Variant *) &var;
|
Variant *v = (Variant *)&var;
|
||||||
|
|
||||||
*v = (obj->*(get_func->f));
|
*v = (obj->*(get_func->f));
|
||||||
|
|
||||||
|
@ -357,27 +305,25 @@ struct _PropertyDefaultGetFunc {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class T, class P>
|
||||||
template<class T, class P>
|
void register_property(const char *name, P(T::*var), P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") {
|
||||||
void register_property(const char *name, P (T::*var), P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "")
|
|
||||||
{
|
|
||||||
Variant def_val = default_value;
|
Variant def_val = default_value;
|
||||||
|
|
||||||
usage = (godot_property_usage_flags) ((int) usage | GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE);
|
usage = (godot_property_usage_flags)((int)usage | GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE);
|
||||||
|
|
||||||
if (def_val.get_type() == Variant::OBJECT) {
|
if (def_val.get_type() == Variant::OBJECT) {
|
||||||
Object *o = get_wrapper<Object>(def_val.operator godot_object*());
|
Object *o = get_wrapper<Object>(def_val.operator godot_object *());
|
||||||
if (o && o->is_class("Resource")) {
|
if (o && o->is_class("Resource")) {
|
||||||
hint = (godot_property_hint) ((int) hint | GODOT_PROPERTY_HINT_RESOURCE_TYPE);
|
hint = (godot_property_hint)((int)hint | GODOT_PROPERTY_HINT_RESOURCE_TYPE);
|
||||||
hint_string = o->get_class();
|
hint_string = o->get_class();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
godot_string *_hint_string = (godot_string*) &hint_string;
|
godot_string *_hint_string = (godot_string *)&hint_string;
|
||||||
|
|
||||||
godot_property_attributes attr = {};
|
godot_property_attributes attr = {};
|
||||||
attr.type = def_val.get_type();
|
attr.type = def_val.get_type();
|
||||||
attr.default_value = *(godot_variant *) &def_val;
|
attr.default_value = *(godot_variant *)&def_val;
|
||||||
attr.hint = hint;
|
attr.hint = hint;
|
||||||
attr.rset_type = rpc_mode;
|
attr.rset_type = rpc_mode;
|
||||||
attr.usage = usage;
|
attr.usage = usage;
|
||||||
|
@ -386,75 +332,68 @@ void register_property(const char *name, P (T::*var), P default_value, godot_met
|
||||||
_PropertyDefaultSetFunc<T, P> *wrapped_set = (_PropertyDefaultSetFunc<T, P> *)godot::api->godot_alloc(sizeof(_PropertyDefaultSetFunc<T, P>));
|
_PropertyDefaultSetFunc<T, P> *wrapped_set = (_PropertyDefaultSetFunc<T, P> *)godot::api->godot_alloc(sizeof(_PropertyDefaultSetFunc<T, P>));
|
||||||
wrapped_set->f = var;
|
wrapped_set->f = var;
|
||||||
|
|
||||||
_PropertyDefaultGetFunc<T, P> *wrapped_get = (_PropertyDefaultGetFunc<T, P> *) godot::api->godot_alloc(sizeof(_PropertyDefaultGetFunc<T, P>));
|
_PropertyDefaultGetFunc<T, P> *wrapped_get = (_PropertyDefaultGetFunc<T, P> *)godot::api->godot_alloc(sizeof(_PropertyDefaultGetFunc<T, P>));
|
||||||
wrapped_get->f = var;
|
wrapped_get->f = var;
|
||||||
|
|
||||||
godot_property_set_func set_func = {};
|
godot_property_set_func set_func = {};
|
||||||
set_func.method_data = (void *) wrapped_set;
|
set_func.method_data = (void *)wrapped_set;
|
||||||
set_func.free_func = godot::api->godot_free;
|
set_func.free_func = godot::api->godot_free;
|
||||||
set_func.set_func = &_PropertyDefaultSetFunc<T, P>::_wrapped_setter;
|
set_func.set_func = &_PropertyDefaultSetFunc<T, P>::_wrapped_setter;
|
||||||
|
|
||||||
godot_property_get_func get_func = {};
|
godot_property_get_func get_func = {};
|
||||||
get_func.method_data = (void *) wrapped_get;
|
get_func.method_data = (void *)wrapped_get;
|
||||||
get_func.free_func = godot::api->godot_free;
|
get_func.free_func = godot::api->godot_free;
|
||||||
get_func.get_func = &_PropertyDefaultGetFunc<T, P>::_wrapped_getter;
|
get_func.get_func = &_PropertyDefaultGetFunc<T, P>::_wrapped_getter;
|
||||||
|
|
||||||
godot::nativescript_api->godot_nativescript_register_property(godot::_RegisterState::nativescript_handle, T::___get_type_name(), name, &attr, set_func, get_func);
|
godot::nativescript_api->godot_nativescript_register_property(godot::_RegisterState::nativescript_handle, T::___get_type_name(), name, &attr, set_func, get_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T, class P>
|
||||||
|
void register_property(const char *name, void (T::*setter)(P), P (T::*getter)(), P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") {
|
||||||
|
|
||||||
template<class T, class P>
|
|
||||||
void register_property(const char *name, void (T::*setter)(P), P (T::*getter)(), P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "")
|
|
||||||
{
|
|
||||||
Variant def_val = default_value;
|
Variant def_val = default_value;
|
||||||
|
|
||||||
godot_property_attributes attr = {};
|
godot_property_attributes attr = {};
|
||||||
attr.type = def_val.get_type();
|
attr.type = def_val.get_type();
|
||||||
attr.default_value = *(godot_variant *) &def_val;
|
attr.default_value = *(godot_variant *)&def_val;
|
||||||
attr.hint = hint;
|
attr.hint = hint;
|
||||||
attr.rset_type = rpc_mode;
|
attr.rset_type = rpc_mode;
|
||||||
attr.usage = usage;
|
attr.usage = usage;
|
||||||
|
|
||||||
_PropertySetFunc<T, P> *wrapped_set = (_PropertySetFunc<T, P> *) godot::api->godot_alloc(sizeof(_PropertySetFunc<T, P>));
|
_PropertySetFunc<T, P> *wrapped_set = (_PropertySetFunc<T, P> *)godot::api->godot_alloc(sizeof(_PropertySetFunc<T, P>));
|
||||||
wrapped_set->f = setter;
|
wrapped_set->f = setter;
|
||||||
|
|
||||||
_PropertyGetFunc<T, P> *wrapped_get = (_PropertyGetFunc<T, P> *) godot::api->godot_alloc(sizeof(_PropertyGetFunc<T, P>));
|
_PropertyGetFunc<T, P> *wrapped_get = (_PropertyGetFunc<T, P> *)godot::api->godot_alloc(sizeof(_PropertyGetFunc<T, P>));
|
||||||
wrapped_get->f = getter;
|
wrapped_get->f = getter;
|
||||||
|
|
||||||
godot_property_set_func set_func = {};
|
godot_property_set_func set_func = {};
|
||||||
set_func.method_data = (void *) wrapped_set;
|
set_func.method_data = (void *)wrapped_set;
|
||||||
set_func.free_func = godot::api->godot_free;
|
set_func.free_func = godot::api->godot_free;
|
||||||
set_func.set_func = &_PropertySetFunc<T, P>::_wrapped_setter;
|
set_func.set_func = &_PropertySetFunc<T, P>::_wrapped_setter;
|
||||||
|
|
||||||
godot_property_get_func get_func = {};
|
godot_property_get_func get_func = {};
|
||||||
get_func.method_data = (void *) wrapped_get;
|
get_func.method_data = (void *)wrapped_get;
|
||||||
get_func.free_func = godot::api->godot_free;
|
get_func.free_func = godot::api->godot_free;
|
||||||
get_func.get_func = &_PropertyGetFunc<T, P>::_wrapped_getter;
|
get_func.get_func = &_PropertyGetFunc<T, P>::_wrapped_getter;
|
||||||
|
|
||||||
godot::nativescript_api->godot_nativescript_register_property(godot::_RegisterState::nativescript_handle, T::___get_type_name(), name, &attr, set_func, get_func);
|
godot::nativescript_api->godot_nativescript_register_property(godot::_RegisterState::nativescript_handle, T::___get_type_name(), name, &attr, set_func, get_func);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class P>
|
template <class T, class P>
|
||||||
void register_property(const char *name, void (T::*setter)(P), P (T::*getter)() const, P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "")
|
void register_property(const char *name, void (T::*setter)(P), P (T::*getter)() const, P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") {
|
||||||
{
|
register_property(name, setter, (P(T::*)())getter, default_value, rpc_mode, usage, hint, hint_string);
|
||||||
register_property(name, setter, (P (T::*)()) getter, default_value, rpc_mode, usage, hint, hint_string);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template <class T>
|
||||||
void register_signal(String name, Dictionary args = Dictionary())
|
void register_signal(String name, Dictionary args = Dictionary()) {
|
||||||
{
|
|
||||||
godot_signal signal = {};
|
godot_signal signal = {};
|
||||||
signal.name = *(godot_string *)&name;
|
signal.name = *(godot_string *)&name;
|
||||||
signal.num_args = args.size();
|
signal.num_args = args.size();
|
||||||
signal.num_default_args = 0;
|
signal.num_default_args = 0;
|
||||||
|
|
||||||
// Need to check because malloc(0) is platform-dependent. Zero arguments will leave args to nullptr.
|
// Need to check because malloc(0) is platform-dependent. Zero arguments will leave args to nullptr.
|
||||||
if(signal.num_args != 0) {
|
if (signal.num_args != 0) {
|
||||||
signal.args = (godot_signal_argument*) godot::api->godot_alloc(sizeof(godot_signal_argument) * signal.num_args);
|
signal.args = (godot_signal_argument *)godot::api->godot_alloc(sizeof(godot_signal_argument) * signal.num_args);
|
||||||
memset((void *) signal.args, 0, sizeof(godot_signal_argument) * signal.num_args);
|
memset((void *)signal.args, 0, sizeof(godot_signal_argument) * signal.num_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < signal.num_args; i++) {
|
for (int i = 0; i < signal.num_args; i++) {
|
||||||
|
@ -476,29 +415,23 @@ void register_signal(String name, Dictionary args = Dictionary())
|
||||||
godot::api->godot_string_destroy(&signal.args[i].name);
|
godot::api->godot_string_destroy(&signal.args[i].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(signal.args) {
|
if (signal.args) {
|
||||||
godot::api->godot_free(signal.args);
|
godot::api->godot_free(signal.args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class... Args>
|
template <class T, class... Args>
|
||||||
void register_signal(String name, Args... varargs)
|
void register_signal(String name, Args... varargs) {
|
||||||
{
|
|
||||||
register_signal<T>(name, Dictionary::make(varargs...));
|
register_signal<T>(name, Dictionary::make(varargs...));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef GODOT_CPP_NO_OBJECT_CAST
|
#ifndef GODOT_CPP_NO_OBJECT_CAST
|
||||||
template<class T>
|
template <class T>
|
||||||
T *Object::cast_to(const Object *obj)
|
T *Object::cast_to(const Object *obj) {
|
||||||
{
|
size_t have_tag = (size_t)godot::nativescript_1_1_api->godot_nativescript_get_type_tag(obj->_owner);
|
||||||
size_t have_tag = (size_t) godot::nativescript_1_1_api->godot_nativescript_get_type_tag(obj->_owner);
|
|
||||||
|
|
||||||
if (have_tag) {
|
if (have_tag) {
|
||||||
if (!godot::_TagDB::is_type_known((size_t) have_tag)) {
|
if (!godot::_TagDB::is_type_known((size_t)have_tag)) {
|
||||||
have_tag = 0;
|
have_tag = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -508,14 +441,13 @@ T *Object::cast_to(const Object *obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (godot::_TagDB::is_type_compatible(typeid(T).hash_code(), have_tag)) {
|
if (godot::_TagDB::is_type_compatible(typeid(T).hash_code(), have_tag)) {
|
||||||
return (T::___CLASS_IS_SCRIPT) ? godot::as<T>(obj) : (T *) obj;
|
return (T::___CLASS_IS_SCRIPT) ? godot::as<T>(obj) : (T *)obj;
|
||||||
} else {
|
} else {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
}
|
|
||||||
|
|
||||||
#endif // GODOT_H
|
#endif // GODOT_H
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#ifndef GODOT_GLOBAL_HPP
|
#ifndef GODOT_GLOBAL_HPP
|
||||||
#define GODOT_GLOBAL_HPP
|
#define GODOT_GLOBAL_HPP
|
||||||
|
|
||||||
#include <gdnative_api_struct.gen.h>
|
|
||||||
#include "String.hpp"
|
|
||||||
#include "Array.hpp"
|
#include "Array.hpp"
|
||||||
|
#include "String.hpp"
|
||||||
|
#include <gdnative_api_struct.gen.h>
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ extern "C" const void *gdnlib;
|
||||||
class Godot {
|
class Godot {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void print(const String& message);
|
static void print(const String &message);
|
||||||
static void print_warning(const String& description, const String& function, const String& file, int line);
|
static void print_warning(const String &description, const String &function, const String &file, int line);
|
||||||
static void print_error(const String& description, const String& function, const String& file, int line);
|
static void print_error(const String &description, const String &function, const String &file, int line);
|
||||||
|
|
||||||
static void gdnative_init(godot_gdnative_init_options *o);
|
static void gdnative_init(godot_gdnative_init_options *o);
|
||||||
static void gdnative_terminate(godot_gdnative_terminate_options *o);
|
static void gdnative_terminate(godot_gdnative_terminate_options *o);
|
||||||
|
@ -26,18 +26,16 @@ public:
|
||||||
static void nativescript_terminate(void *handle);
|
static void nativescript_terminate(void *handle);
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
static void print(const String& fmt, Args... values) {
|
static void print(const String &fmt, Args... values) {
|
||||||
print(fmt.format(Array::make(values...)));
|
print(fmt.format(Array::make(values...)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct _RegisterState {
|
struct _RegisterState {
|
||||||
static void *nativescript_handle;
|
static void *nativescript_handle;
|
||||||
static int language_index;
|
static int language_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,16 +7,15 @@
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
|
class NodePath {
|
||||||
class NodePath
|
|
||||||
{
|
|
||||||
godot_node_path _node_path;
|
godot_node_path _node_path;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NodePath();
|
NodePath();
|
||||||
|
|
||||||
NodePath(const NodePath &other);
|
NodePath(const NodePath &other);
|
||||||
|
|
||||||
NodePath(const String& from);
|
NodePath(const String &from);
|
||||||
|
|
||||||
NodePath(const char *contents);
|
NodePath(const char *contents);
|
||||||
|
|
||||||
|
@ -34,15 +33,13 @@ public:
|
||||||
|
|
||||||
operator String() const;
|
operator String() const;
|
||||||
|
|
||||||
void operator =(const NodePath& other);
|
void operator=(const NodePath &other);
|
||||||
|
|
||||||
bool operator ==(const NodePath& other);
|
bool operator==(const NodePath &other);
|
||||||
|
|
||||||
~NodePath();
|
~NodePath();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // NODEPATH_H
|
#endif // NODEPATH_H
|
||||||
|
|
|
@ -5,10 +5,8 @@
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
|
|
||||||
enum ClockDirection {
|
enum ClockDirection {
|
||||||
|
|
||||||
CLOCKWISE,
|
CLOCKWISE,
|
||||||
|
@ -20,7 +18,7 @@ public:
|
||||||
Vector3 normal;
|
Vector3 normal;
|
||||||
real_t d;
|
real_t d;
|
||||||
|
|
||||||
void set_normal(const Vector3& p_normal);
|
void set_normal(const Vector3 &p_normal);
|
||||||
|
|
||||||
inline Vector3 get_normal() const { return normal; } ///Point is coplanar, CMP_EPSILON for precision
|
inline Vector3 get_normal() const { return normal; } ///Point is coplanar, CMP_EPSILON for precision
|
||||||
|
|
||||||
|
@ -30,40 +28,41 @@ public:
|
||||||
|
|
||||||
/* Plane-Point operations */
|
/* Plane-Point operations */
|
||||||
|
|
||||||
inline Vector3 center() const { return normal*d; }
|
inline Vector3 center() const { return normal * d; }
|
||||||
Vector3 get_any_point() const;
|
Vector3 get_any_point() const;
|
||||||
Vector3 get_any_perpendicular_normal() const;
|
Vector3 get_any_perpendicular_normal() const;
|
||||||
|
|
||||||
bool is_point_over(const Vector3 &p_point) const; ///< Point is over plane
|
bool is_point_over(const Vector3 &p_point) const; ///< Point is over plane
|
||||||
real_t distance_to(const Vector3 &p_point) const;
|
real_t distance_to(const Vector3 &p_point) const;
|
||||||
bool has_point(const Vector3 &p_point,real_t _epsilon=CMP_EPSILON) const;
|
bool has_point(const Vector3 &p_point, real_t _epsilon = CMP_EPSILON) const;
|
||||||
|
|
||||||
/* intersections */
|
/* intersections */
|
||||||
|
|
||||||
bool intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result=0) const;
|
bool intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result = 0) const;
|
||||||
bool intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3* p_intersection) const;
|
bool intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersection) const;
|
||||||
bool intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3* p_intersection) const;
|
bool intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3 *p_intersection) const;
|
||||||
|
|
||||||
Vector3 project(const Vector3& p_point) const;
|
Vector3 project(const Vector3 &p_point) const;
|
||||||
|
|
||||||
/* misc */
|
/* misc */
|
||||||
|
|
||||||
inline Plane operator-() const { return Plane(-normal,-d); }
|
inline Plane operator-() const { return Plane(-normal, -d); }
|
||||||
bool is_almost_like(const Plane& p_plane) const;
|
bool is_almost_like(const Plane &p_plane) const;
|
||||||
|
|
||||||
bool operator==(const Plane& p_plane) const;
|
bool operator==(const Plane &p_plane) const;
|
||||||
bool operator!=(const Plane& p_plane) const;
|
bool operator!=(const Plane &p_plane) const;
|
||||||
operator String() const;
|
operator String() const;
|
||||||
|
|
||||||
inline Plane() { d=0; }
|
inline Plane() { d = 0; }
|
||||||
inline Plane(real_t p_a, real_t p_b, real_t p_c, real_t p_d) : normal(p_a,p_b,p_c), d(p_d) { }
|
inline Plane(real_t p_a, real_t p_b, real_t p_c, real_t p_d) :
|
||||||
|
normal(p_a, p_b, p_c),
|
||||||
|
d(p_d) {}
|
||||||
|
|
||||||
Plane(const Vector3 &p_normal, real_t p_d);
|
Plane(const Vector3 &p_normal, real_t p_d);
|
||||||
Plane(const Vector3 &p_point, const Vector3& p_normal);
|
Plane(const Vector3 &p_point, const Vector3 &p_normal);
|
||||||
Plane(const Vector3 &p_point1, const Vector3 &p_point2,const Vector3 &p_point3,ClockDirection p_dir = CLOCKWISE);
|
Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_point3, ClockDirection p_dir = CLOCKWISE);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif // PLANE_H
|
#endif // PLANE_H
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
|
|
||||||
#include "Defs.hpp"
|
#include "Defs.hpp"
|
||||||
|
|
||||||
#include "String.hpp"
|
|
||||||
#include "Color.hpp"
|
#include "Color.hpp"
|
||||||
|
#include "GodotGlobal.hpp"
|
||||||
|
#include "String.hpp"
|
||||||
#include "Vector2.hpp"
|
#include "Vector2.hpp"
|
||||||
#include "Vector3.hpp"
|
#include "Vector3.hpp"
|
||||||
#include "GodotGlobal.hpp"
|
|
||||||
|
|
||||||
#include <gdnative/pool_arrays.h>
|
#include <gdnative/pool_arrays.h>
|
||||||
|
|
||||||
|
@ -17,18 +17,19 @@ class Array;
|
||||||
|
|
||||||
class PoolByteArray {
|
class PoolByteArray {
|
||||||
godot_pool_byte_array _godot_array;
|
godot_pool_byte_array _godot_array;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
class Read {
|
class Read {
|
||||||
|
|
||||||
friend class PoolByteArray;
|
friend class PoolByteArray;
|
||||||
godot_pool_byte_array_read_access *_read_access;
|
godot_pool_byte_array_read_access *_read_access;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Read() {
|
inline Read() {
|
||||||
_read_access = nullptr;
|
_read_access = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Read(const Read & p_other) {
|
inline Read(const Read &p_other) {
|
||||||
_read_access = godot::api->godot_pool_byte_array_read_access_copy(p_other._read_access);
|
_read_access = godot::api->godot_pool_byte_array_read_access_copy(p_other._read_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ public:
|
||||||
return ptr()[p_idx];
|
return ptr()[p_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator=(const Read& p_other) {
|
inline void operator=(const Read &p_other) {
|
||||||
godot::api->godot_pool_byte_array_read_access_operator_assign(_read_access, p_other._read_access);
|
godot::api->godot_pool_byte_array_read_access_operator_assign(_read_access, p_other._read_access);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -52,12 +53,13 @@ public:
|
||||||
class Write {
|
class Write {
|
||||||
friend class PoolByteArray;
|
friend class PoolByteArray;
|
||||||
godot_pool_byte_array_write_access *_write_access;
|
godot_pool_byte_array_write_access *_write_access;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Write() {
|
inline Write() {
|
||||||
_write_access = nullptr;
|
_write_access = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Write(const Write & p_other) {
|
inline Write(const Write &p_other) {
|
||||||
_write_access = godot::api->godot_pool_byte_array_write_access_copy(p_other._write_access);
|
_write_access = godot::api->godot_pool_byte_array_write_access_copy(p_other._write_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,16 +75,16 @@ public:
|
||||||
return ptr()[p_idx];
|
return ptr()[p_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator=(const Write& p_other) {
|
inline void operator=(const Write &p_other) {
|
||||||
godot::api->godot_pool_byte_array_write_access_operator_assign(_write_access, p_other._write_access);
|
godot::api->godot_pool_byte_array_write_access_operator_assign(_write_access, p_other._write_access);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
PoolByteArray();
|
PoolByteArray();
|
||||||
PoolByteArray(const PoolByteArray &p_other);
|
PoolByteArray(const PoolByteArray &p_other);
|
||||||
PoolByteArray &operator=(const PoolByteArray & p_other);
|
PoolByteArray &operator=(const PoolByteArray &p_other);
|
||||||
|
|
||||||
PoolByteArray(const Array& array);
|
PoolByteArray(const Array &array);
|
||||||
|
|
||||||
Read read() const;
|
Read read() const;
|
||||||
|
|
||||||
|
@ -90,7 +92,7 @@ public:
|
||||||
|
|
||||||
void append(const uint8_t data);
|
void append(const uint8_t data);
|
||||||
|
|
||||||
void append_array(const PoolByteArray& array);
|
void append_array(const PoolByteArray &array);
|
||||||
|
|
||||||
int insert(const int idx, const uint8_t data);
|
int insert(const int idx, const uint8_t data);
|
||||||
|
|
||||||
|
@ -104,27 +106,27 @@ public:
|
||||||
|
|
||||||
void set(const int idx, const uint8_t data);
|
void set(const int idx, const uint8_t data);
|
||||||
|
|
||||||
uint8_t operator [](const int idx);
|
uint8_t operator[](const int idx);
|
||||||
|
|
||||||
int size() const;
|
int size() const;
|
||||||
|
|
||||||
~PoolByteArray();
|
~PoolByteArray();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class PoolIntArray {
|
class PoolIntArray {
|
||||||
godot_pool_int_array _godot_array;
|
godot_pool_int_array _godot_array;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
class Read {
|
class Read {
|
||||||
friend class PoolIntArray;
|
friend class PoolIntArray;
|
||||||
godot_pool_int_array_read_access *_read_access;
|
godot_pool_int_array_read_access *_read_access;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Read() {
|
inline Read() {
|
||||||
_read_access = nullptr;
|
_read_access = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Read(const Read & p_other) {
|
inline Read(const Read &p_other) {
|
||||||
_read_access = godot::api->godot_pool_int_array_read_access_copy(p_other._read_access);
|
_read_access = godot::api->godot_pool_int_array_read_access_copy(p_other._read_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +142,7 @@ public:
|
||||||
return ptr()[p_idx];
|
return ptr()[p_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator=(const Read& p_other) {
|
inline void operator=(const Read &p_other) {
|
||||||
godot::api->godot_pool_int_array_read_access_operator_assign(_read_access, p_other._read_access);
|
godot::api->godot_pool_int_array_read_access_operator_assign(_read_access, p_other._read_access);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -148,12 +150,13 @@ public:
|
||||||
class Write {
|
class Write {
|
||||||
friend class PoolIntArray;
|
friend class PoolIntArray;
|
||||||
godot_pool_int_array_write_access *_write_access;
|
godot_pool_int_array_write_access *_write_access;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Write() {
|
inline Write() {
|
||||||
_write_access = nullptr;
|
_write_access = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Write(const Write & p_other) {
|
inline Write(const Write &p_other) {
|
||||||
_write_access = godot::api->godot_pool_int_array_write_access_copy(p_other._write_access);
|
_write_access = godot::api->godot_pool_int_array_write_access_copy(p_other._write_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +172,7 @@ public:
|
||||||
return ptr()[p_idx];
|
return ptr()[p_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator=(const Write& p_other) {
|
inline void operator=(const Write &p_other) {
|
||||||
godot::api->godot_pool_int_array_write_access_operator_assign(_write_access, p_other._write_access);
|
godot::api->godot_pool_int_array_write_access_operator_assign(_write_access, p_other._write_access);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -178,7 +181,7 @@ public:
|
||||||
PoolIntArray(const PoolIntArray &p_other);
|
PoolIntArray(const PoolIntArray &p_other);
|
||||||
PoolIntArray &operator=(const PoolIntArray &p_other);
|
PoolIntArray &operator=(const PoolIntArray &p_other);
|
||||||
|
|
||||||
PoolIntArray(const Array& array);
|
PoolIntArray(const Array &array);
|
||||||
|
|
||||||
Read read() const;
|
Read read() const;
|
||||||
|
|
||||||
|
@ -186,7 +189,7 @@ public:
|
||||||
|
|
||||||
void append(const int data);
|
void append(const int data);
|
||||||
|
|
||||||
void append_array(const PoolIntArray& array);
|
void append_array(const PoolIntArray &array);
|
||||||
|
|
||||||
int insert(const int idx, const int data);
|
int insert(const int idx, const int data);
|
||||||
|
|
||||||
|
@ -200,27 +203,27 @@ public:
|
||||||
|
|
||||||
void set(const int idx, const int data);
|
void set(const int idx, const int data);
|
||||||
|
|
||||||
int operator [](const int idx);
|
int operator[](const int idx);
|
||||||
|
|
||||||
int size() const;
|
int size() const;
|
||||||
|
|
||||||
~PoolIntArray();
|
~PoolIntArray();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class PoolRealArray {
|
class PoolRealArray {
|
||||||
godot_pool_real_array _godot_array;
|
godot_pool_real_array _godot_array;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
class Read {
|
class Read {
|
||||||
friend class PoolRealArray;
|
friend class PoolRealArray;
|
||||||
godot_pool_real_array_read_access *_read_access;
|
godot_pool_real_array_read_access *_read_access;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Read() {
|
inline Read() {
|
||||||
_read_access = nullptr;
|
_read_access = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Read(const Read & p_other) {
|
inline Read(const Read &p_other) {
|
||||||
_read_access = godot::api->godot_pool_real_array_read_access_copy(p_other._read_access);
|
_read_access = godot::api->godot_pool_real_array_read_access_copy(p_other._read_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +239,7 @@ public:
|
||||||
return ptr()[p_idx];
|
return ptr()[p_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator=(const Read& p_other) {
|
inline void operator=(const Read &p_other) {
|
||||||
godot::api->godot_pool_real_array_read_access_operator_assign(_read_access, p_other._read_access);
|
godot::api->godot_pool_real_array_read_access_operator_assign(_read_access, p_other._read_access);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -244,12 +247,13 @@ public:
|
||||||
class Write {
|
class Write {
|
||||||
friend class PoolRealArray;
|
friend class PoolRealArray;
|
||||||
godot_pool_real_array_write_access *_write_access;
|
godot_pool_real_array_write_access *_write_access;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Write() {
|
inline Write() {
|
||||||
_write_access = nullptr;
|
_write_access = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Write(const Write & p_other) {
|
inline Write(const Write &p_other) {
|
||||||
_write_access = godot::api->godot_pool_real_array_write_access_copy(p_other._write_access);
|
_write_access = godot::api->godot_pool_real_array_write_access_copy(p_other._write_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +269,7 @@ public:
|
||||||
return ptr()[p_idx];
|
return ptr()[p_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator=(const Write& p_other) {
|
inline void operator=(const Write &p_other) {
|
||||||
godot::api->godot_pool_real_array_write_access_operator_assign(_write_access, p_other._write_access);
|
godot::api->godot_pool_real_array_write_access_operator_assign(_write_access, p_other._write_access);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -274,7 +278,7 @@ public:
|
||||||
PoolRealArray(const PoolRealArray &p_other);
|
PoolRealArray(const PoolRealArray &p_other);
|
||||||
PoolRealArray &operator=(const PoolRealArray &p_other);
|
PoolRealArray &operator=(const PoolRealArray &p_other);
|
||||||
|
|
||||||
PoolRealArray(const Array& array);
|
PoolRealArray(const Array &array);
|
||||||
|
|
||||||
Read read() const;
|
Read read() const;
|
||||||
|
|
||||||
|
@ -282,7 +286,7 @@ public:
|
||||||
|
|
||||||
void append(const real_t data);
|
void append(const real_t data);
|
||||||
|
|
||||||
void append_array(const PoolRealArray& array);
|
void append_array(const PoolRealArray &array);
|
||||||
|
|
||||||
int insert(const int idx, const real_t data);
|
int insert(const int idx, const real_t data);
|
||||||
|
|
||||||
|
@ -296,27 +300,27 @@ public:
|
||||||
|
|
||||||
void set(const int idx, const real_t data);
|
void set(const int idx, const real_t data);
|
||||||
|
|
||||||
real_t operator [](const int idx);
|
real_t operator[](const int idx);
|
||||||
|
|
||||||
int size() const;
|
int size() const;
|
||||||
|
|
||||||
~PoolRealArray();
|
~PoolRealArray();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class PoolStringArray {
|
class PoolStringArray {
|
||||||
godot_pool_string_array _godot_array;
|
godot_pool_string_array _godot_array;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
class Read {
|
class Read {
|
||||||
friend class PoolStringArray;
|
friend class PoolStringArray;
|
||||||
godot_pool_string_array_read_access *_read_access;
|
godot_pool_string_array_read_access *_read_access;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Read() {
|
inline Read() {
|
||||||
_read_access = nullptr;
|
_read_access = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Read(const Read & p_other) {
|
inline Read(const Read &p_other) {
|
||||||
_read_access = godot::api->godot_pool_string_array_read_access_copy(p_other._read_access);
|
_read_access = godot::api->godot_pool_string_array_read_access_copy(p_other._read_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,14 +329,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const String *ptr() const {
|
inline const String *ptr() const {
|
||||||
return (const String *) godot::api->godot_pool_string_array_read_access_ptr(_read_access);
|
return (const String *)godot::api->godot_pool_string_array_read_access_ptr(_read_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const String &operator[](int p_idx) const {
|
inline const String &operator[](int p_idx) const {
|
||||||
return ptr()[p_idx];
|
return ptr()[p_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator=(const Read& p_other) {
|
inline void operator=(const Read &p_other) {
|
||||||
godot::api->godot_pool_string_array_read_access_operator_assign(_read_access, p_other._read_access);
|
godot::api->godot_pool_string_array_read_access_operator_assign(_read_access, p_other._read_access);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -340,12 +344,13 @@ public:
|
||||||
class Write {
|
class Write {
|
||||||
friend class PoolStringArray;
|
friend class PoolStringArray;
|
||||||
godot_pool_string_array_write_access *_write_access;
|
godot_pool_string_array_write_access *_write_access;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Write() {
|
inline Write() {
|
||||||
_write_access = nullptr;
|
_write_access = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Write(const Write & p_other) {
|
inline Write(const Write &p_other) {
|
||||||
_write_access = godot::api->godot_pool_string_array_write_access_copy(p_other._write_access);
|
_write_access = godot::api->godot_pool_string_array_write_access_copy(p_other._write_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,14 +359,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
inline String *ptr() const {
|
inline String *ptr() const {
|
||||||
return (String *) godot::api->godot_pool_string_array_write_access_ptr(_write_access);
|
return (String *)godot::api->godot_pool_string_array_write_access_ptr(_write_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline String &operator[](int p_idx) const {
|
inline String &operator[](int p_idx) const {
|
||||||
return ptr()[p_idx];
|
return ptr()[p_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator=(const Write& p_other) {
|
inline void operator=(const Write &p_other) {
|
||||||
godot::api->godot_pool_string_array_write_access_operator_assign(_write_access, p_other._write_access);
|
godot::api->godot_pool_string_array_write_access_operator_assign(_write_access, p_other._write_access);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -370,50 +375,49 @@ public:
|
||||||
PoolStringArray(const PoolStringArray &p_other);
|
PoolStringArray(const PoolStringArray &p_other);
|
||||||
PoolStringArray &operator=(const PoolStringArray &p_other);
|
PoolStringArray &operator=(const PoolStringArray &p_other);
|
||||||
|
|
||||||
PoolStringArray(const Array& array);
|
PoolStringArray(const Array &array);
|
||||||
|
|
||||||
Read read() const;
|
Read read() const;
|
||||||
|
|
||||||
Write write();
|
Write write();
|
||||||
|
|
||||||
void append(const String& data);
|
void append(const String &data);
|
||||||
|
|
||||||
void append_array(const PoolStringArray& array);
|
void append_array(const PoolStringArray &array);
|
||||||
|
|
||||||
int insert(const int idx, const String& data);
|
int insert(const int idx, const String &data);
|
||||||
|
|
||||||
void invert();
|
void invert();
|
||||||
|
|
||||||
void push_back(const String& data);
|
void push_back(const String &data);
|
||||||
|
|
||||||
void remove(const int idx);
|
void remove(const int idx);
|
||||||
|
|
||||||
void resize(const int size);
|
void resize(const int size);
|
||||||
|
|
||||||
void set(const int idx, const String& data);
|
void set(const int idx, const String &data);
|
||||||
|
|
||||||
const String operator [](const int idx);
|
const String operator[](const int idx);
|
||||||
|
|
||||||
int size() const;
|
int size() const;
|
||||||
|
|
||||||
~PoolStringArray();
|
~PoolStringArray();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PoolVector2Array {
|
class PoolVector2Array {
|
||||||
godot_pool_vector2_array _godot_array;
|
godot_pool_vector2_array _godot_array;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
class Read {
|
class Read {
|
||||||
friend class PoolVector2Array;
|
friend class PoolVector2Array;
|
||||||
godot_pool_vector2_array_read_access *_read_access;
|
godot_pool_vector2_array_read_access *_read_access;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Read() {
|
inline Read() {
|
||||||
_read_access = nullptr;
|
_read_access = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Read(const Read & p_other) {
|
inline Read(const Read &p_other) {
|
||||||
_read_access = godot::api->godot_pool_vector2_array_read_access_copy(p_other._read_access);
|
_read_access = godot::api->godot_pool_vector2_array_read_access_copy(p_other._read_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,14 +426,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Vector2 *ptr() const {
|
inline const Vector2 *ptr() const {
|
||||||
return (const Vector2 *) godot::api->godot_pool_vector2_array_read_access_ptr(_read_access);
|
return (const Vector2 *)godot::api->godot_pool_vector2_array_read_access_ptr(_read_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Vector2 &operator[](int p_idx) const {
|
inline const Vector2 &operator[](int p_idx) const {
|
||||||
return ptr()[p_idx];
|
return ptr()[p_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator=(const Read& p_other) {
|
inline void operator=(const Read &p_other) {
|
||||||
godot::api->godot_pool_vector2_array_read_access_operator_assign(_read_access, p_other._read_access);
|
godot::api->godot_pool_vector2_array_read_access_operator_assign(_read_access, p_other._read_access);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -437,12 +441,13 @@ public:
|
||||||
class Write {
|
class Write {
|
||||||
friend class PoolVector2Array;
|
friend class PoolVector2Array;
|
||||||
godot_pool_vector2_array_write_access *_write_access;
|
godot_pool_vector2_array_write_access *_write_access;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Write() {
|
inline Write() {
|
||||||
_write_access = nullptr;
|
_write_access = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Write(const Write & p_other) {
|
inline Write(const Write &p_other) {
|
||||||
_write_access = godot::api->godot_pool_vector2_array_write_access_copy(p_other._write_access);
|
_write_access = godot::api->godot_pool_vector2_array_write_access_copy(p_other._write_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,14 +456,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Vector2 *ptr() const {
|
inline Vector2 *ptr() const {
|
||||||
return (Vector2 *) godot::api->godot_pool_vector2_array_write_access_ptr(_write_access);
|
return (Vector2 *)godot::api->godot_pool_vector2_array_write_access_ptr(_write_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Vector2 &operator[](int p_idx) const {
|
inline Vector2 &operator[](int p_idx) const {
|
||||||
return ptr()[p_idx];
|
return ptr()[p_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator=(const Write& p_other) {
|
inline void operator=(const Write &p_other) {
|
||||||
godot::api->godot_pool_vector2_array_write_access_operator_assign(_write_access, p_other._write_access);
|
godot::api->godot_pool_vector2_array_write_access_operator_assign(_write_access, p_other._write_access);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -467,49 +472,49 @@ public:
|
||||||
PoolVector2Array(const PoolVector2Array &p_other);
|
PoolVector2Array(const PoolVector2Array &p_other);
|
||||||
PoolVector2Array &operator=(const PoolVector2Array &p_other);
|
PoolVector2Array &operator=(const PoolVector2Array &p_other);
|
||||||
|
|
||||||
PoolVector2Array(const Array& array);
|
PoolVector2Array(const Array &array);
|
||||||
|
|
||||||
Read read() const;
|
Read read() const;
|
||||||
|
|
||||||
Write write();
|
Write write();
|
||||||
|
|
||||||
void append(const Vector2& data);
|
void append(const Vector2 &data);
|
||||||
|
|
||||||
void append_array(const PoolVector2Array& array);
|
void append_array(const PoolVector2Array &array);
|
||||||
|
|
||||||
int insert(const int idx, const Vector2& data);
|
int insert(const int idx, const Vector2 &data);
|
||||||
|
|
||||||
void invert();
|
void invert();
|
||||||
|
|
||||||
void push_back(const Vector2& data);
|
void push_back(const Vector2 &data);
|
||||||
|
|
||||||
void remove(const int idx);
|
void remove(const int idx);
|
||||||
|
|
||||||
void resize(const int size);
|
void resize(const int size);
|
||||||
|
|
||||||
void set(const int idx, const Vector2& data);
|
void set(const int idx, const Vector2 &data);
|
||||||
|
|
||||||
const Vector2 operator [](const int idx);
|
const Vector2 operator[](const int idx);
|
||||||
|
|
||||||
int size() const;
|
int size() const;
|
||||||
|
|
||||||
~PoolVector2Array();
|
~PoolVector2Array();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class PoolVector3Array {
|
class PoolVector3Array {
|
||||||
godot_pool_vector3_array _godot_array;
|
godot_pool_vector3_array _godot_array;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
class Read {
|
class Read {
|
||||||
friend class PoolVector3Array;
|
friend class PoolVector3Array;
|
||||||
godot_pool_vector3_array_read_access *_read_access;
|
godot_pool_vector3_array_read_access *_read_access;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Read() {
|
inline Read() {
|
||||||
_read_access = nullptr;
|
_read_access = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Read(const Read & p_other) {
|
inline Read(const Read &p_other) {
|
||||||
_read_access = godot::api->godot_pool_vector3_array_read_access_copy(p_other._read_access);
|
_read_access = godot::api->godot_pool_vector3_array_read_access_copy(p_other._read_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -518,14 +523,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Vector3 *ptr() const {
|
inline const Vector3 *ptr() const {
|
||||||
return (const Vector3 *) godot::api->godot_pool_vector3_array_read_access_ptr(_read_access);
|
return (const Vector3 *)godot::api->godot_pool_vector3_array_read_access_ptr(_read_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Vector3 &operator[](int p_idx) const {
|
inline const Vector3 &operator[](int p_idx) const {
|
||||||
return ptr()[p_idx];
|
return ptr()[p_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator=(const Read& p_other) {
|
inline void operator=(const Read &p_other) {
|
||||||
godot::api->godot_pool_vector3_array_read_access_operator_assign(_read_access, p_other._read_access);
|
godot::api->godot_pool_vector3_array_read_access_operator_assign(_read_access, p_other._read_access);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -533,12 +538,13 @@ public:
|
||||||
class Write {
|
class Write {
|
||||||
friend class PoolVector3Array;
|
friend class PoolVector3Array;
|
||||||
godot_pool_vector3_array_write_access *_write_access;
|
godot_pool_vector3_array_write_access *_write_access;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Write() {
|
inline Write() {
|
||||||
_write_access = nullptr;
|
_write_access = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Write(const Write & p_other) {
|
inline Write(const Write &p_other) {
|
||||||
_write_access = godot::api->godot_pool_vector3_array_write_access_copy(p_other._write_access);
|
_write_access = godot::api->godot_pool_vector3_array_write_access_copy(p_other._write_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,14 +553,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Vector3 *ptr() const {
|
inline Vector3 *ptr() const {
|
||||||
return (Vector3 *) godot::api->godot_pool_vector3_array_write_access_ptr(_write_access);
|
return (Vector3 *)godot::api->godot_pool_vector3_array_write_access_ptr(_write_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Vector3 &operator[](int p_idx) const {
|
inline Vector3 &operator[](int p_idx) const {
|
||||||
return ptr()[p_idx];
|
return ptr()[p_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator=(const Write& p_other) {
|
inline void operator=(const Write &p_other) {
|
||||||
godot::api->godot_pool_vector3_array_write_access_operator_assign(_write_access, p_other._write_access);
|
godot::api->godot_pool_vector3_array_write_access_operator_assign(_write_access, p_other._write_access);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -563,49 +569,49 @@ public:
|
||||||
PoolVector3Array(const PoolVector3Array &p_other);
|
PoolVector3Array(const PoolVector3Array &p_other);
|
||||||
PoolVector3Array &operator=(const PoolVector3Array &p_other);
|
PoolVector3Array &operator=(const PoolVector3Array &p_other);
|
||||||
|
|
||||||
PoolVector3Array(const Array& array);
|
PoolVector3Array(const Array &array);
|
||||||
|
|
||||||
Read read() const;
|
Read read() const;
|
||||||
|
|
||||||
Write write();
|
Write write();
|
||||||
|
|
||||||
void append(const Vector3& data);
|
void append(const Vector3 &data);
|
||||||
|
|
||||||
void append_array(const PoolVector3Array& array);
|
void append_array(const PoolVector3Array &array);
|
||||||
|
|
||||||
int insert(const int idx, const Vector3& data);
|
int insert(const int idx, const Vector3 &data);
|
||||||
|
|
||||||
void invert();
|
void invert();
|
||||||
|
|
||||||
void push_back(const Vector3& data);
|
void push_back(const Vector3 &data);
|
||||||
|
|
||||||
void remove(const int idx);
|
void remove(const int idx);
|
||||||
|
|
||||||
void resize(const int size);
|
void resize(const int size);
|
||||||
|
|
||||||
void set(const int idx, const Vector3& data);
|
void set(const int idx, const Vector3 &data);
|
||||||
|
|
||||||
const Vector3 operator [](const int idx);
|
const Vector3 operator[](const int idx);
|
||||||
|
|
||||||
int size() const;
|
int size() const;
|
||||||
|
|
||||||
~PoolVector3Array();
|
~PoolVector3Array();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class PoolColorArray {
|
class PoolColorArray {
|
||||||
godot_pool_color_array _godot_array;
|
godot_pool_color_array _godot_array;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
class Read {
|
class Read {
|
||||||
friend class PoolColorArray;
|
friend class PoolColorArray;
|
||||||
godot_pool_color_array_read_access *_read_access;
|
godot_pool_color_array_read_access *_read_access;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Read() {
|
inline Read() {
|
||||||
_read_access = nullptr;
|
_read_access = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Read(const Read & p_other) {
|
inline Read(const Read &p_other) {
|
||||||
_read_access = godot::api->godot_pool_color_array_read_access_copy(p_other._read_access);
|
_read_access = godot::api->godot_pool_color_array_read_access_copy(p_other._read_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -614,14 +620,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Color *ptr() const {
|
inline const Color *ptr() const {
|
||||||
return (const Color *) godot::api->godot_pool_color_array_read_access_ptr(_read_access);
|
return (const Color *)godot::api->godot_pool_color_array_read_access_ptr(_read_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Color &operator[](int p_idx) const {
|
inline const Color &operator[](int p_idx) const {
|
||||||
return ptr()[p_idx];
|
return ptr()[p_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator=(const Read& p_other) {
|
inline void operator=(const Read &p_other) {
|
||||||
godot::api->godot_pool_color_array_read_access_operator_assign(_read_access, p_other._read_access);
|
godot::api->godot_pool_color_array_read_access_operator_assign(_read_access, p_other._read_access);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -629,12 +635,13 @@ public:
|
||||||
class Write {
|
class Write {
|
||||||
friend class PoolColorArray;
|
friend class PoolColorArray;
|
||||||
godot_pool_color_array_write_access *_write_access;
|
godot_pool_color_array_write_access *_write_access;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline Write() {
|
inline Write() {
|
||||||
_write_access = nullptr;
|
_write_access = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Write(const Write & p_other) {
|
inline Write(const Write &p_other) {
|
||||||
_write_access = godot::api->godot_pool_color_array_write_access_copy(p_other._write_access);
|
_write_access = godot::api->godot_pool_color_array_write_access_copy(p_other._write_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -643,14 +650,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Color *ptr() const {
|
inline Color *ptr() const {
|
||||||
return (Color *) godot::api->godot_pool_color_array_write_access_ptr(_write_access);
|
return (Color *)godot::api->godot_pool_color_array_write_access_ptr(_write_access);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Color &operator[](int p_idx) const {
|
inline Color &operator[](int p_idx) const {
|
||||||
return ptr()[p_idx];
|
return ptr()[p_idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void operator=(const Write& p_other) {
|
inline void operator=(const Write &p_other) {
|
||||||
godot::api->godot_pool_color_array_write_access_operator_assign(_write_access, p_other._write_access);
|
godot::api->godot_pool_color_array_write_access_operator_assign(_write_access, p_other._write_access);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -659,38 +666,35 @@ public:
|
||||||
PoolColorArray(const PoolColorArray &p_other);
|
PoolColorArray(const PoolColorArray &p_other);
|
||||||
PoolColorArray &operator=(const PoolColorArray &p_other);
|
PoolColorArray &operator=(const PoolColorArray &p_other);
|
||||||
|
|
||||||
PoolColorArray(const Array& array);
|
PoolColorArray(const Array &array);
|
||||||
|
|
||||||
Read read() const;
|
Read read() const;
|
||||||
|
|
||||||
Write write();
|
Write write();
|
||||||
|
|
||||||
void append(const Color& data);
|
void append(const Color &data);
|
||||||
|
|
||||||
void append_array(const PoolColorArray& array);
|
void append_array(const PoolColorArray &array);
|
||||||
|
|
||||||
int insert(const int idx, const Color& data);
|
int insert(const int idx, const Color &data);
|
||||||
|
|
||||||
void invert();
|
void invert();
|
||||||
|
|
||||||
void push_back(const Color& data);
|
void push_back(const Color &data);
|
||||||
|
|
||||||
void remove(const int idx);
|
void remove(const int idx);
|
||||||
|
|
||||||
void resize(const int size);
|
void resize(const int size);
|
||||||
|
|
||||||
void set(const int idx, const Color& data);
|
void set(const int idx, const Color &data);
|
||||||
|
|
||||||
const Color operator [](const int idx);
|
const Color operator[](const int idx);
|
||||||
|
|
||||||
int size() const;
|
int size() const;
|
||||||
|
|
||||||
~PoolColorArray();
|
~PoolColorArray();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // POOLARRAYS_H
|
#endif // POOLARRAYS_H
|
||||||
|
|
|
@ -9,10 +9,9 @@
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
class Quat{
|
class Quat {
|
||||||
public:
|
public:
|
||||||
|
real_t x, y, z, w;
|
||||||
real_t x,y,z,w;
|
|
||||||
|
|
||||||
real_t length_squared() const;
|
real_t length_squared() const;
|
||||||
real_t length() const;
|
real_t length() const;
|
||||||
|
@ -23,65 +22,68 @@ public:
|
||||||
|
|
||||||
Quat inverse() const;
|
Quat inverse() const;
|
||||||
|
|
||||||
void set_euler_xyz(const Vector3& p_euler);
|
void set_euler_xyz(const Vector3 &p_euler);
|
||||||
Vector3 get_euler_xyz() const;
|
Vector3 get_euler_xyz() const;
|
||||||
void set_euler_yxz(const Vector3& p_euler);
|
void set_euler_yxz(const Vector3 &p_euler);
|
||||||
Vector3 get_euler_yxz() const;
|
Vector3 get_euler_yxz() const;
|
||||||
|
|
||||||
inline void set_euler(const Vector3& p_euler) { set_euler_yxz(p_euler); }
|
inline void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); }
|
||||||
inline Vector3 get_euler() const { return get_euler_yxz(); }
|
inline Vector3 get_euler() const { return get_euler_yxz(); }
|
||||||
|
|
||||||
real_t dot(const Quat& q) const;
|
real_t dot(const Quat &q) const;
|
||||||
|
|
||||||
Quat slerp(const Quat& q, const real_t& t) const;
|
Quat slerp(const Quat &q, const real_t &t) const;
|
||||||
|
|
||||||
Quat slerpni(const Quat& q, const real_t& t) const;
|
Quat slerpni(const Quat &q, const real_t &t) const;
|
||||||
|
|
||||||
Quat cubic_slerp(const Quat& q, const Quat& prep, const Quat& postq,const real_t& t) const;
|
Quat cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const;
|
||||||
|
|
||||||
void get_axis_and_angle(Vector3& r_axis, real_t &r_angle) const;
|
void get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const;
|
||||||
|
|
||||||
void operator*=(const Quat& q);
|
void operator*=(const Quat &q);
|
||||||
Quat operator*(const Quat& q) const;
|
Quat operator*(const Quat &q) const;
|
||||||
|
|
||||||
|
Quat operator*(const Vector3 &v) const;
|
||||||
|
|
||||||
|
Vector3 xform(const Vector3 &v) const;
|
||||||
|
|
||||||
Quat operator*(const Vector3& v) const;
|
void operator+=(const Quat &q);
|
||||||
|
void operator-=(const Quat &q);
|
||||||
Vector3 xform(const Vector3& v) const;
|
void operator*=(const real_t &s);
|
||||||
|
void operator/=(const real_t &s);
|
||||||
|
Quat operator+(const Quat &q2) const;
|
||||||
void operator+=(const Quat& q);
|
Quat operator-(const Quat &q2) const;
|
||||||
void operator-=(const Quat& q);
|
|
||||||
void operator*=(const real_t& s);
|
|
||||||
void operator/=(const real_t& s);
|
|
||||||
Quat operator+(const Quat& q2) const;
|
|
||||||
Quat operator-(const Quat& q2) const;
|
|
||||||
Quat operator-() const;
|
Quat operator-() const;
|
||||||
Quat operator*(const real_t& s) const;
|
Quat operator*(const real_t &s) const;
|
||||||
Quat operator/(const real_t& s) const;
|
Quat operator/(const real_t &s) const;
|
||||||
|
|
||||||
|
bool operator==(const Quat &p_quat) const;
|
||||||
bool operator==(const Quat& p_quat) const;
|
bool operator!=(const Quat &p_quat) const;
|
||||||
bool operator!=(const Quat& p_quat) const;
|
|
||||||
|
|
||||||
operator String() const;
|
operator String() const;
|
||||||
|
|
||||||
inline void set( real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
|
inline void set(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
|
||||||
x=p_x; y=p_y; z=p_z; w=p_w;
|
x = p_x;
|
||||||
|
y = p_y;
|
||||||
|
z = p_z;
|
||||||
|
w = p_w;
|
||||||
}
|
}
|
||||||
inline Quat(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
|
inline Quat(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
|
||||||
x=p_x; y=p_y; z=p_z; w=p_w;
|
x = p_x;
|
||||||
|
y = p_y;
|
||||||
|
z = p_z;
|
||||||
|
w = p_w;
|
||||||
}
|
}
|
||||||
Quat(const Vector3& axis, const real_t& angle);
|
Quat(const Vector3 &axis, const real_t &angle);
|
||||||
|
|
||||||
Quat(const Vector3& v0, const Vector3& v1) ;
|
Quat(const Vector3 &v0, const Vector3 &v1);
|
||||||
|
|
||||||
inline Quat() {x=y=z=0; w=1; }
|
|
||||||
|
|
||||||
|
inline Quat() {
|
||||||
|
x = y = z = 0;
|
||||||
|
w = 1;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
}
|
|
||||||
|
|
||||||
#endif // QUAT_H
|
#endif // QUAT_H
|
||||||
|
|
|
@ -9,8 +9,8 @@ class Object;
|
||||||
|
|
||||||
class RID {
|
class RID {
|
||||||
godot_rid _godot_rid;
|
godot_rid _godot_rid;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
RID();
|
RID();
|
||||||
|
|
||||||
RID(Object *p);
|
RID(Object *p);
|
||||||
|
@ -22,15 +22,14 @@ public:
|
||||||
return *this != RID();
|
return *this != RID();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const RID & p_other) const;
|
bool operator==(const RID &p_other) const;
|
||||||
bool operator!=(const RID & p_other) const;
|
bool operator!=(const RID &p_other) const;
|
||||||
bool operator<(const RID & p_other) const;
|
bool operator<(const RID &p_other) const;
|
||||||
bool operator>(const RID & p_other) const;
|
bool operator>(const RID &p_other) const;
|
||||||
bool operator<=(const RID & p_other) const;
|
bool operator<=(const RID &p_other) const;
|
||||||
bool operator>=(const RID & p_other) const;
|
bool operator>=(const RID &p_other) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif // RID_H
|
#endif // RID_H
|
||||||
|
|
|
@ -21,113 +21,115 @@ struct Rect2 {
|
||||||
Point2 pos;
|
Point2 pos;
|
||||||
Size2 size;
|
Size2 size;
|
||||||
|
|
||||||
inline const Vector2& get_pos() const { return pos; }
|
inline const Vector2 &get_pos() const { return pos; }
|
||||||
inline void set_pos(const Vector2& p_pos) { pos=p_pos; }
|
inline void set_pos(const Vector2 &p_pos) { pos = p_pos; }
|
||||||
inline const Vector2& get_size() const { return size; }
|
inline const Vector2 &get_size() const { return size; }
|
||||||
inline void set_size(const Vector2& p_size) { size=p_size; }
|
inline void set_size(const Vector2 &p_size) { size = p_size; }
|
||||||
|
|
||||||
inline real_t get_area() const { return size.width*size.height; }
|
inline real_t get_area() const { return size.width * size.height; }
|
||||||
|
|
||||||
inline bool intersects(const Rect2& p_rect) const {
|
inline bool intersects(const Rect2 &p_rect) const {
|
||||||
if ( pos.x >= (p_rect.pos.x + p_rect.size.width) )
|
if (pos.x >= (p_rect.pos.x + p_rect.size.width))
|
||||||
return false;
|
return false;
|
||||||
if ( (pos.x+size.width) <= p_rect.pos.x )
|
if ((pos.x + size.width) <= p_rect.pos.x)
|
||||||
return false;
|
return false;
|
||||||
if ( pos.y >= (p_rect.pos.y + p_rect.size.height) )
|
if (pos.y >= (p_rect.pos.y + p_rect.size.height))
|
||||||
return false;
|
return false;
|
||||||
if ( (pos.y+size.height) <= p_rect.pos.y )
|
if ((pos.y + size.height) <= p_rect.pos.y)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t distance_to(const Vector2& p_point) const;
|
real_t distance_to(const Vector2 &p_point) const;
|
||||||
|
|
||||||
bool intersects_transformed(const Transform2D& p_xform, const Rect2& p_rect) const;
|
bool intersects_transformed(const Transform2D &p_xform, const Rect2 &p_rect) const;
|
||||||
|
|
||||||
bool intersects_segment(const Point2& p_from, const Point2& p_to, Point2* r_pos=nullptr, Point2* r_normal=nullptr) const;
|
bool intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos = nullptr, Point2 *r_normal = nullptr) const;
|
||||||
|
|
||||||
inline bool encloses(const Rect2& p_rect) const {
|
inline bool encloses(const Rect2 &p_rect) const {
|
||||||
|
|
||||||
return (p_rect.pos.x>=pos.x) && (p_rect.pos.y>=pos.y) &&
|
|
||||||
((p_rect.pos.x+p_rect.size.x)<(pos.x+size.x)) &&
|
|
||||||
((p_rect.pos.y+p_rect.size.y)<(pos.y+size.y));
|
|
||||||
|
|
||||||
|
return (p_rect.pos.x >= pos.x) && (p_rect.pos.y >= pos.y) &&
|
||||||
|
((p_rect.pos.x + p_rect.size.x) < (pos.x + size.x)) &&
|
||||||
|
((p_rect.pos.y + p_rect.size.y) < (pos.y + size.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool has_no_area() const {
|
inline bool has_no_area() const {
|
||||||
|
|
||||||
return (size.x<=0 || size.y<=0);
|
return (size.x <= 0 || size.y <= 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
Rect2 clip(const Rect2& p_rect) const;
|
Rect2 clip(const Rect2 &p_rect) const;
|
||||||
|
|
||||||
Rect2 merge(const Rect2& p_rect) const;
|
Rect2 merge(const Rect2 &p_rect) const;
|
||||||
|
|
||||||
inline bool has_point(const Point2& p_point) const {
|
inline bool has_point(const Point2 &p_point) const {
|
||||||
if (p_point.x < pos.x)
|
if (p_point.x < pos.x)
|
||||||
return false;
|
return false;
|
||||||
if (p_point.y < pos.y)
|
if (p_point.y < pos.y)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (p_point.x >= (pos.x+size.x) )
|
if (p_point.x >= (pos.x + size.x))
|
||||||
return false;
|
return false;
|
||||||
if (p_point.y >= (pos.y+size.y) )
|
if (p_point.y >= (pos.y + size.y))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool no_area() const { return (size.width<=0 || size.height<=0 ); }
|
inline bool no_area() const { return (size.width <= 0 || size.height <= 0); }
|
||||||
|
|
||||||
inline bool operator==(const Rect2& p_rect) const { return pos==p_rect.pos && size==p_rect.size; }
|
inline bool operator==(const Rect2 &p_rect) const { return pos == p_rect.pos && size == p_rect.size; }
|
||||||
inline bool operator!=(const Rect2& p_rect) const { return pos!=p_rect.pos || size!=p_rect.size; }
|
inline bool operator!=(const Rect2 &p_rect) const { return pos != p_rect.pos || size != p_rect.size; }
|
||||||
|
|
||||||
inline Rect2 grow(real_t p_by) const {
|
inline Rect2 grow(real_t p_by) const {
|
||||||
|
|
||||||
Rect2 g=*this;
|
Rect2 g = *this;
|
||||||
g.pos.x-=p_by;
|
g.pos.x -= p_by;
|
||||||
g.pos.y-=p_by;
|
g.pos.y -= p_by;
|
||||||
g.size.width+=p_by*2;
|
g.size.width += p_by * 2;
|
||||||
g.size.height+=p_by*2;
|
g.size.height += p_by * 2;
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Rect2 expand(const Vector2& p_vector) const {
|
inline Rect2 expand(const Vector2 &p_vector) const {
|
||||||
|
|
||||||
Rect2 r = *this;
|
Rect2 r = *this;
|
||||||
r.expand_to(p_vector);
|
r.expand_to(p_vector);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void expand_to(const Vector2& p_vector) { //in place function for speed
|
inline void expand_to(const Vector2 &p_vector) { //in place function for speed
|
||||||
|
|
||||||
Vector2 begin=pos;
|
Vector2 begin = pos;
|
||||||
Vector2 end=pos+size;
|
Vector2 end = pos + size;
|
||||||
|
|
||||||
if (p_vector.x<begin.x)
|
if (p_vector.x < begin.x)
|
||||||
begin.x=p_vector.x;
|
begin.x = p_vector.x;
|
||||||
if (p_vector.y<begin.y)
|
if (p_vector.y < begin.y)
|
||||||
begin.y=p_vector.y;
|
begin.y = p_vector.y;
|
||||||
|
|
||||||
if (p_vector.x>end.x)
|
if (p_vector.x > end.x)
|
||||||
end.x=p_vector.x;
|
end.x = p_vector.x;
|
||||||
if (p_vector.y>end.y)
|
if (p_vector.y > end.y)
|
||||||
end.y=p_vector.y;
|
end.y = p_vector.y;
|
||||||
|
|
||||||
pos=begin;
|
pos = begin;
|
||||||
size=end-begin;
|
size = end - begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
operator String() const;
|
operator String() const;
|
||||||
|
|
||||||
inline Rect2() {}
|
inline Rect2() {}
|
||||||
inline Rect2( real_t p_x, real_t p_y, real_t p_width, real_t p_height) { pos=Point2(p_x,p_y); size=Size2( p_width, p_height ); }
|
inline Rect2(real_t p_x, real_t p_y, real_t p_width, real_t p_height) {
|
||||||
inline Rect2( const Point2& p_pos, const Size2& p_size ) { pos=p_pos; size=p_size; }
|
pos = Point2(p_x, p_y);
|
||||||
|
size = Size2(p_width, p_height);
|
||||||
|
}
|
||||||
|
inline Rect2(const Point2 &p_pos, const Size2 &p_size) {
|
||||||
|
pos = p_pos;
|
||||||
|
size = p_size;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
}
|
|
||||||
|
|
||||||
#endif // RECT2_H
|
#endif // RECT2_H
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#ifndef REF_H
|
#ifndef REF_H
|
||||||
#define REF_H
|
#define REF_H
|
||||||
|
|
||||||
#include "Variant.hpp"
|
|
||||||
#include "GodotGlobal.hpp"
|
#include "GodotGlobal.hpp"
|
||||||
#include "Reference.hpp"
|
#include "Reference.hpp"
|
||||||
|
#include "Variant.hpp"
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ public:
|
||||||
operator Variant() const {
|
operator Variant() const {
|
||||||
// Note: the C API handles the cases where the object is a Reference,
|
// Note: the C API handles the cases where the object is a Reference,
|
||||||
// so the Variant will be correctly constructed with a RefPtr engine-side
|
// so the Variant will be correctly constructed with a RefPtr engine-side
|
||||||
return Variant((Object*)reference);
|
return Variant((Object *)reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator=(const Ref &p_from) {
|
void operator=(const Ref &p_from) {
|
||||||
|
@ -99,7 +99,7 @@ public:
|
||||||
}
|
}
|
||||||
Ref r;
|
Ref r;
|
||||||
//r.reference = Object::cast_to<T>(refb);
|
//r.reference = Object::cast_to<T>(refb);
|
||||||
r.reference = (T*)refb;
|
r.reference = (T *)refb;
|
||||||
ref(r);
|
ref(r);
|
||||||
r.reference = nullptr;
|
r.reference = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ public:
|
||||||
void operator=(const Variant &p_variant) {
|
void operator=(const Variant &p_variant) {
|
||||||
|
|
||||||
// TODO We need a safe cast
|
// TODO We need a safe cast
|
||||||
Reference *refb = (Reference *) T::___get_from_variant(p_variant);
|
Reference *refb = (Reference *)T::___get_from_variant(p_variant);
|
||||||
if (!refb) {
|
if (!refb) {
|
||||||
unref();
|
unref();
|
||||||
return;
|
return;
|
||||||
|
@ -156,7 +156,7 @@ public:
|
||||||
|
|
||||||
reference = nullptr;
|
reference = nullptr;
|
||||||
// TODO We need a safe cast
|
// TODO We need a safe cast
|
||||||
Reference *refb = (Reference *) T::___get_from_variant(p_variant);
|
Reference *refb = (Reference *)T::___get_from_variant(p_variant);
|
||||||
if (!refb) {
|
if (!refb) {
|
||||||
unref();
|
unref();
|
||||||
return;
|
return;
|
||||||
|
@ -202,14 +202,13 @@ public:
|
||||||
|
|
||||||
// Used exclusively in the bindings to recreate the Ref Godot encapsulates in return values,
|
// Used exclusively in the bindings to recreate the Ref Godot encapsulates in return values,
|
||||||
// without adding to the refcount.
|
// without adding to the refcount.
|
||||||
inline static Ref<T> __internal_constructor(Object *obj)
|
inline static Ref<T> __internal_constructor(Object *obj) {
|
||||||
{
|
|
||||||
Ref<T> r;
|
Ref<T> r;
|
||||||
r.reference = (T*)obj;
|
r.reference = (T *)obj;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -132,12 +132,11 @@ public:
|
||||||
signed char casecmp_to(String p_str) const;
|
signed char casecmp_to(String p_str) const;
|
||||||
signed char nocasecmp_to(String p_str) const;
|
signed char nocasecmp_to(String p_str) const;
|
||||||
signed char naturalnocasecmp_to(String p_str) const;
|
signed char naturalnocasecmp_to(String p_str) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
String operator+(const char *a, const String &b);
|
String operator+(const char *a, const String &b);
|
||||||
String operator+(const wchar_t *a, const String &b);
|
String operator+(const wchar_t *a, const String &b);
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif // STRING_H
|
#endif // STRING_H
|
||||||
|
|
|
@ -12,8 +12,8 @@ bool is_type_known(size_t type_tag);
|
||||||
void register_global_type(const char *name, size_t type_tag, size_t base_type_tag);
|
void register_global_type(const char *name, size_t type_tag, size_t base_type_tag);
|
||||||
bool is_type_compatible(size_t type_tag, size_t base_type_tag);
|
bool is_type_compatible(size_t type_tag, size_t base_type_tag);
|
||||||
|
|
||||||
}
|
} // namespace _TagDB
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif // TAGDB_HPP
|
#endif // TAGDB_HPP
|
||||||
|
|
|
@ -3,14 +3,13 @@
|
||||||
|
|
||||||
#include "Basis.hpp"
|
#include "Basis.hpp"
|
||||||
|
|
||||||
#include "Plane.hpp"
|
|
||||||
#include "AABB.hpp"
|
#include "AABB.hpp"
|
||||||
|
#include "Plane.hpp"
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
class Transform {
|
class Transform {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Basis basis;
|
Basis basis;
|
||||||
Vector3 origin;
|
Vector3 origin;
|
||||||
|
|
||||||
|
@ -20,62 +19,61 @@ public:
|
||||||
void affine_invert();
|
void affine_invert();
|
||||||
Transform affine_inverse() const;
|
Transform affine_inverse() const;
|
||||||
|
|
||||||
Transform rotated(const Vector3& p_axis,real_t p_phi) const;
|
Transform rotated(const Vector3 &p_axis, real_t p_phi) const;
|
||||||
|
|
||||||
void rotate(const Vector3& p_axis,real_t p_phi);
|
void rotate(const Vector3 &p_axis, real_t p_phi);
|
||||||
void rotate_basis(const Vector3& p_axis,real_t p_phi);
|
void rotate_basis(const Vector3 &p_axis, real_t p_phi);
|
||||||
|
|
||||||
void set_look_at( const Vector3& p_eye, const Vector3& p_target, const Vector3& p_up );
|
void set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const Vector3 &p_up);
|
||||||
Transform looking_at( const Vector3& p_target, const Vector3& p_up ) const;
|
Transform looking_at(const Vector3 &p_target, const Vector3 &p_up) const;
|
||||||
|
|
||||||
void scale(const Vector3& p_scale);
|
void scale(const Vector3 &p_scale);
|
||||||
Transform scaled(const Vector3& p_scale) const;
|
Transform scaled(const Vector3 &p_scale) const;
|
||||||
void scale_basis(const Vector3& p_scale);
|
void scale_basis(const Vector3 &p_scale);
|
||||||
void translate( real_t p_tx, real_t p_ty, real_t p_tz );
|
void translate(real_t p_tx, real_t p_ty, real_t p_tz);
|
||||||
void translate( const Vector3& p_translation );
|
void translate(const Vector3 &p_translation);
|
||||||
Transform translated( const Vector3& p_translation ) const;
|
Transform translated(const Vector3 &p_translation) const;
|
||||||
|
|
||||||
inline const Basis& get_basis() const { return basis; }
|
inline const Basis &get_basis() const { return basis; }
|
||||||
inline void set_basis(const Basis& p_basis) { basis=p_basis; }
|
inline void set_basis(const Basis &p_basis) { basis = p_basis; }
|
||||||
|
|
||||||
inline const Vector3& get_origin() const { return origin; }
|
inline const Vector3 &get_origin() const { return origin; }
|
||||||
inline void set_origin(const Vector3& p_origin) { origin=p_origin; }
|
inline void set_origin(const Vector3 &p_origin) { origin = p_origin; }
|
||||||
|
|
||||||
void orthonormalize();
|
void orthonormalize();
|
||||||
Transform orthonormalized() const;
|
Transform orthonormalized() const;
|
||||||
|
|
||||||
bool operator==(const Transform& p_transform) const;
|
bool operator==(const Transform &p_transform) const;
|
||||||
bool operator!=(const Transform& p_transform) const;
|
bool operator!=(const Transform &p_transform) const;
|
||||||
|
|
||||||
Vector3 xform(const Vector3& p_vector) const;
|
Vector3 xform(const Vector3 &p_vector) const;
|
||||||
Vector3 xform_inv(const Vector3& p_vector) const;
|
Vector3 xform_inv(const Vector3 &p_vector) const;
|
||||||
|
|
||||||
Plane xform(const Plane& p_plane) const;
|
Plane xform(const Plane &p_plane) const;
|
||||||
Plane xform_inv(const Plane& p_plane) const;
|
Plane xform_inv(const Plane &p_plane) const;
|
||||||
|
|
||||||
AABB xform(const AABB& p_aabb) const;
|
AABB xform(const AABB &p_aabb) const;
|
||||||
AABB xform_inv(const AABB& p_aabb) const;
|
AABB xform_inv(const AABB &p_aabb) const;
|
||||||
|
|
||||||
void operator*=(const Transform& p_transform);
|
void operator*=(const Transform &p_transform);
|
||||||
Transform operator*(const Transform& p_transform) const;
|
Transform operator*(const Transform &p_transform) const;
|
||||||
|
|
||||||
Transform interpolate_with(const Transform& p_transform, real_t p_c) const;
|
Transform interpolate_with(const Transform &p_transform, real_t p_c) const;
|
||||||
|
|
||||||
Transform inverse_xform(const Transform& t) const;
|
Transform inverse_xform(const Transform &t) const;
|
||||||
|
|
||||||
void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz,real_t tx, real_t ty, real_t tz);
|
void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t tx, real_t ty, real_t tz);
|
||||||
|
|
||||||
operator String() const;
|
operator String() const;
|
||||||
|
|
||||||
inline Transform(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz,real_t tx, real_t ty, real_t tz) {
|
inline Transform(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t tx, real_t ty, real_t tz) {
|
||||||
set(xx, xy, xz, yx, yy, yz, zx, zy, zz,tx, ty, tz);
|
set(xx, xy, xz, yx, yy, yz, zx, zy, zz, tx, ty, tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform(const Basis& p_basis, const Vector3& p_origin=Vector3());
|
Transform(const Basis &p_basis, const Vector3 &p_origin = Vector3());
|
||||||
inline Transform() {}
|
inline Transform() {}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif // TRANSFORM_H
|
#endif // TRANSFORM_H
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "Vector2.hpp"
|
#include "Vector2.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
typedef Vector2 Size2;
|
typedef Vector2 Size2;
|
||||||
|
@ -24,14 +23,20 @@ struct Transform2D {
|
||||||
|
|
||||||
Vector2 elements[3];
|
Vector2 elements[3];
|
||||||
|
|
||||||
inline real_t tdotx(const Vector2& v) const { return elements[0][0] * v.x + elements[1][0] * v.y; }
|
inline real_t tdotx(const Vector2 &v) const { return elements[0][0] * v.x + elements[1][0] * v.y; }
|
||||||
inline real_t tdoty(const Vector2& v) const { return elements[0][1] * v.x + elements[1][1] * v.y; }
|
inline real_t tdoty(const Vector2 &v) const { return elements[0][1] * v.x + elements[1][1] * v.y; }
|
||||||
|
|
||||||
inline const Vector2& operator[](int p_idx) const { return elements[p_idx]; }
|
inline const Vector2 &operator[](int p_idx) const { return elements[p_idx]; }
|
||||||
inline Vector2& operator[](int p_idx) { return elements[p_idx]; }
|
inline Vector2 &operator[](int p_idx) { return elements[p_idx]; }
|
||||||
|
|
||||||
inline Vector2 get_axis(int p_axis) const { ERR_FAIL_INDEX_V(p_axis,3,Vector2()); return elements[p_axis]; }
|
inline Vector2 get_axis(int p_axis) const {
|
||||||
inline void set_axis(int p_axis,const Vector2& p_vec) { ERR_FAIL_INDEX(p_axis,3); elements[p_axis]=p_vec; }
|
ERR_FAIL_INDEX_V(p_axis, 3, Vector2());
|
||||||
|
return elements[p_axis];
|
||||||
|
}
|
||||||
|
inline void set_axis(int p_axis, const Vector2 &p_vec) {
|
||||||
|
ERR_FAIL_INDEX(p_axis, 3);
|
||||||
|
elements[p_axis] = p_vec;
|
||||||
|
}
|
||||||
|
|
||||||
void invert();
|
void invert();
|
||||||
Transform2D inverse() const;
|
Transform2D inverse() const;
|
||||||
|
@ -41,24 +46,24 @@ struct Transform2D {
|
||||||
|
|
||||||
void set_rotation(real_t p_phi);
|
void set_rotation(real_t p_phi);
|
||||||
real_t get_rotation() const;
|
real_t get_rotation() const;
|
||||||
void set_rotation_and_scale(real_t p_phi,const Size2& p_scale);
|
void set_rotation_and_scale(real_t p_phi, const Size2 &p_scale);
|
||||||
void rotate(real_t p_phi);
|
void rotate(real_t p_phi);
|
||||||
|
|
||||||
void scale(const Size2& p_scale);
|
void scale(const Size2 &p_scale);
|
||||||
void scale_basis(const Size2& p_scale);
|
void scale_basis(const Size2 &p_scale);
|
||||||
void translate( real_t p_tx, real_t p_ty);
|
void translate(real_t p_tx, real_t p_ty);
|
||||||
void translate( const Vector2& p_translation );
|
void translate(const Vector2 &p_translation);
|
||||||
|
|
||||||
real_t basis_determinant() const;
|
real_t basis_determinant() const;
|
||||||
|
|
||||||
Size2 get_scale() const;
|
Size2 get_scale() const;
|
||||||
|
|
||||||
inline const Vector2& get_origin() const { return elements[2]; }
|
inline const Vector2 &get_origin() const { return elements[2]; }
|
||||||
inline void set_origin(const Vector2& p_origin) { elements[2]=p_origin; }
|
inline void set_origin(const Vector2 &p_origin) { elements[2] = p_origin; }
|
||||||
|
|
||||||
Transform2D scaled(const Size2& p_scale) const;
|
Transform2D scaled(const Size2 &p_scale) const;
|
||||||
Transform2D basis_scaled(const Size2& p_scale) const;
|
Transform2D basis_scaled(const Size2 &p_scale) const;
|
||||||
Transform2D translated(const Vector2& p_offset) const;
|
Transform2D translated(const Vector2 &p_offset) const;
|
||||||
Transform2D rotated(real_t p_phi) const;
|
Transform2D rotated(real_t p_phi) const;
|
||||||
|
|
||||||
Transform2D untranslated() const;
|
Transform2D untranslated() const;
|
||||||
|
@ -66,29 +71,32 @@ struct Transform2D {
|
||||||
void orthonormalize();
|
void orthonormalize();
|
||||||
Transform2D orthonormalized() const;
|
Transform2D orthonormalized() const;
|
||||||
|
|
||||||
bool operator==(const Transform2D& p_transform) const;
|
bool operator==(const Transform2D &p_transform) const;
|
||||||
bool operator!=(const Transform2D& p_transform) const;
|
bool operator!=(const Transform2D &p_transform) const;
|
||||||
|
|
||||||
void operator*=(const Transform2D& p_transform);
|
void operator*=(const Transform2D &p_transform);
|
||||||
Transform2D operator*(const Transform2D& p_transform) const;
|
Transform2D operator*(const Transform2D &p_transform) const;
|
||||||
|
|
||||||
Transform2D interpolate_with(const Transform2D& p_transform, real_t p_c) const;
|
Transform2D interpolate_with(const Transform2D &p_transform, real_t p_c) const;
|
||||||
|
|
||||||
Vector2 basis_xform(const Vector2& p_vec) const;
|
Vector2 basis_xform(const Vector2 &p_vec) const;
|
||||||
Vector2 basis_xform_inv(const Vector2& p_vec) const;
|
Vector2 basis_xform_inv(const Vector2 &p_vec) const;
|
||||||
Vector2 xform(const Vector2& p_vec) const;
|
Vector2 xform(const Vector2 &p_vec) const;
|
||||||
Vector2 xform_inv(const Vector2& p_vec) const;
|
Vector2 xform_inv(const Vector2 &p_vec) const;
|
||||||
Rect2 xform(const Rect2& p_vec) const;
|
Rect2 xform(const Rect2 &p_vec) const;
|
||||||
Rect2 xform_inv(const Rect2& p_vec) const;
|
Rect2 xform_inv(const Rect2 &p_vec) const;
|
||||||
|
|
||||||
operator String() const;
|
operator String() const;
|
||||||
|
|
||||||
Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy);
|
Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy);
|
||||||
|
|
||||||
Transform2D(real_t p_rot, const Vector2& p_pos);
|
Transform2D(real_t p_rot, const Vector2 &p_pos);
|
||||||
inline Transform2D() { elements[0][0]=1.0; elements[1][1]=1.0; }
|
inline Transform2D() {
|
||||||
|
elements[0][0] = 1.0;
|
||||||
|
elements[1][1] = 1.0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif // TRANSFORM2D_H
|
#endif // TRANSFORM2D_H
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
#include "Plane.hpp"
|
#include "Plane.hpp"
|
||||||
#include "PoolArrays.hpp"
|
#include "PoolArrays.hpp"
|
||||||
#include "Quat.hpp"
|
#include "Quat.hpp"
|
||||||
#include "Rect2.hpp"
|
|
||||||
#include "RID.hpp"
|
#include "RID.hpp"
|
||||||
|
#include "Rect2.hpp"
|
||||||
#include "String.hpp"
|
#include "String.hpp"
|
||||||
#include "Transform.hpp"
|
#include "Transform.hpp"
|
||||||
#include "Transform2D.hpp"
|
#include "Transform2D.hpp"
|
||||||
|
@ -30,6 +30,7 @@ class Array;
|
||||||
|
|
||||||
class Variant {
|
class Variant {
|
||||||
godot_variant _godot_variant;
|
godot_variant _godot_variant;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Type {
|
enum Type {
|
||||||
|
|
||||||
|
@ -116,7 +117,7 @@ public:
|
||||||
|
|
||||||
Variant();
|
Variant();
|
||||||
|
|
||||||
Variant(const Variant& v);
|
Variant(const Variant &v);
|
||||||
|
|
||||||
Variant(bool p_bool);
|
Variant(bool p_bool);
|
||||||
|
|
||||||
|
@ -126,11 +127,14 @@ public:
|
||||||
|
|
||||||
Variant(signed short p_short);
|
Variant(signed short p_short);
|
||||||
|
|
||||||
inline Variant(unsigned short p_short) : Variant((unsigned int) p_short) {}
|
inline Variant(unsigned short p_short) :
|
||||||
|
Variant((unsigned int)p_short) {}
|
||||||
|
|
||||||
inline Variant(signed char p_char) : Variant((signed int) p_char) {}
|
inline Variant(signed char p_char) :
|
||||||
|
Variant((signed int)p_char) {}
|
||||||
|
|
||||||
inline Variant(unsigned char p_char) : Variant((unsigned int) p_char) {}
|
inline Variant(unsigned char p_char) :
|
||||||
|
Variant((unsigned int)p_char) {}
|
||||||
Variant(int64_t p_char);
|
Variant(int64_t p_char);
|
||||||
|
|
||||||
Variant(uint64_t p_char);
|
Variant(uint64_t p_char);
|
||||||
|
@ -139,64 +143,61 @@ public:
|
||||||
|
|
||||||
Variant(double p_double);
|
Variant(double p_double);
|
||||||
|
|
||||||
Variant(const String& p_string);
|
Variant(const String &p_string);
|
||||||
|
|
||||||
Variant(const char * const p_cstring);
|
Variant(const char *const p_cstring);
|
||||||
|
|
||||||
Variant(const wchar_t * p_wstring);
|
Variant(const wchar_t *p_wstring);
|
||||||
|
|
||||||
Variant(const Vector2& p_vector2);
|
Variant(const Vector2 &p_vector2);
|
||||||
|
|
||||||
Variant(const Rect2& p_rect2);
|
Variant(const Rect2 &p_rect2);
|
||||||
|
|
||||||
Variant(const Vector3& p_vector3);
|
Variant(const Vector3 &p_vector3);
|
||||||
|
|
||||||
Variant(const Plane& p_plane);
|
Variant(const Plane &p_plane);
|
||||||
|
|
||||||
|
Variant(const AABB &p_aabb);
|
||||||
|
|
||||||
Variant(const AABB& p_aabb);
|
Variant(const Quat &p_quat);
|
||||||
|
|
||||||
Variant(const Quat& p_quat);
|
Variant(const Basis &p_transform);
|
||||||
|
|
||||||
Variant(const Basis& p_transform);
|
Variant(const Transform2D &p_transform);
|
||||||
|
|
||||||
Variant(const Transform2D& p_transform);
|
Variant(const Transform &p_transform);
|
||||||
|
|
||||||
Variant(const Transform& p_transform);
|
Variant(const Color &p_color);
|
||||||
|
|
||||||
Variant(const Color& p_color);
|
Variant(const NodePath &p_path);
|
||||||
|
|
||||||
Variant(const NodePath& p_path);
|
Variant(const RID &p_rid);
|
||||||
|
|
||||||
Variant(const RID& p_rid);
|
Variant(const Object *p_object);
|
||||||
|
|
||||||
Variant(const Object* p_object);
|
Variant(const Dictionary &p_dictionary);
|
||||||
|
|
||||||
Variant(const Dictionary& p_dictionary);
|
Variant(const Array &p_array);
|
||||||
|
|
||||||
Variant(const Array& p_array);
|
Variant(const PoolByteArray &p_raw_array);
|
||||||
|
|
||||||
Variant(const PoolByteArray& p_raw_array);
|
Variant(const PoolIntArray &p_int_array);
|
||||||
|
|
||||||
Variant(const PoolIntArray& p_int_array);
|
Variant(const PoolRealArray &p_real_array);
|
||||||
|
|
||||||
Variant(const PoolRealArray& p_real_array);
|
Variant(const PoolStringArray &p_string_array);
|
||||||
|
|
||||||
Variant(const PoolStringArray& p_string_array);
|
Variant(const PoolVector2Array &p_vector2_array);
|
||||||
|
|
||||||
Variant(const PoolVector2Array& p_vector2_array);
|
Variant(const PoolVector3Array &p_vector3_array);
|
||||||
|
|
||||||
Variant(const PoolVector3Array& p_vector3_array);
|
Variant(const PoolColorArray &p_color_array);
|
||||||
|
|
||||||
Variant(const PoolColorArray& p_color_array);
|
|
||||||
|
|
||||||
|
|
||||||
Variant &operator =(const Variant& v);
|
|
||||||
|
|
||||||
|
Variant &operator=(const Variant &v);
|
||||||
|
|
||||||
operator bool() const;
|
operator bool() const;
|
||||||
operator signed int() const;
|
operator signed int() const;
|
||||||
operator unsigned int() const ;
|
operator unsigned int() const;
|
||||||
operator signed short() const;
|
operator signed short() const;
|
||||||
operator unsigned short() const;
|
operator unsigned short() const;
|
||||||
operator signed char() const;
|
operator signed char() const;
|
||||||
|
@ -204,7 +205,6 @@ public:
|
||||||
operator int64_t() const;
|
operator int64_t() const;
|
||||||
operator uint64_t() const;
|
operator uint64_t() const;
|
||||||
|
|
||||||
|
|
||||||
operator wchar_t() const;
|
operator wchar_t() const;
|
||||||
|
|
||||||
operator float() const;
|
operator float() const;
|
||||||
|
@ -225,7 +225,7 @@ public:
|
||||||
|
|
||||||
operator NodePath() const;
|
operator NodePath() const;
|
||||||
operator RID() const;
|
operator RID() const;
|
||||||
operator godot_object*() const;
|
operator godot_object *() const;
|
||||||
|
|
||||||
operator Dictionary() const;
|
operator Dictionary() const;
|
||||||
operator Array() const;
|
operator Array() const;
|
||||||
|
@ -240,32 +240,29 @@ public:
|
||||||
|
|
||||||
Type get_type() const;
|
Type get_type() const;
|
||||||
|
|
||||||
|
Variant call(const String &method, const Variant **args, const int arg_count);
|
||||||
|
|
||||||
Variant call(const String& method, const Variant **args, const int arg_count);
|
bool has_method(const String &method);
|
||||||
|
|
||||||
bool has_method(const String& method);
|
bool operator==(const Variant &b) const;
|
||||||
|
|
||||||
bool operator ==(const Variant& b) const;
|
bool operator!=(const Variant &b) const;
|
||||||
|
|
||||||
bool operator !=(const Variant& b) const;
|
bool operator<(const Variant &b) const;
|
||||||
|
|
||||||
bool operator <(const Variant& b) const;
|
bool operator<=(const Variant &b) const;
|
||||||
|
|
||||||
bool operator <=(const Variant& b) const;
|
bool operator>(const Variant &b) const;
|
||||||
|
|
||||||
bool operator >(const Variant& b) const;
|
bool operator>=(const Variant &b) const;
|
||||||
|
|
||||||
bool operator >=(const Variant& b) const;
|
bool hash_compare(const Variant &b) const;
|
||||||
|
|
||||||
bool hash_compare(const Variant& b) const;
|
|
||||||
|
|
||||||
bool booleanize() const;
|
bool booleanize() const;
|
||||||
|
|
||||||
~Variant();
|
~Variant();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif // VARIANT_H
|
#endif // VARIANT_H
|
||||||
|
|
|
@ -20,21 +20,20 @@ struct Vector2 {
|
||||||
real_t height;
|
real_t height;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline real_t &operator[](int p_idx) {
|
||||||
inline real_t& operator[](int p_idx) {
|
return p_idx ? y : x;
|
||||||
return p_idx?y:x;
|
|
||||||
}
|
}
|
||||||
inline const real_t& operator[](int p_idx) const {
|
inline const real_t &operator[](int p_idx) const {
|
||||||
return p_idx?y:x;
|
return p_idx ? y : x;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 operator+(const Vector2& p_v) const;
|
Vector2 operator+(const Vector2 &p_v) const;
|
||||||
|
|
||||||
void operator+=(const Vector2& p_v);
|
void operator+=(const Vector2 &p_v);
|
||||||
|
|
||||||
Vector2 operator-(const Vector2& p_v) const;
|
Vector2 operator-(const Vector2 &p_v) const;
|
||||||
|
|
||||||
void operator-=(const Vector2& p_v);
|
void operator-=(const Vector2 &p_v);
|
||||||
|
|
||||||
Vector2 operator*(const Vector2 &p_v1) const;
|
Vector2 operator*(const Vector2 &p_v1) const;
|
||||||
|
|
||||||
|
@ -52,13 +51,12 @@ struct Vector2 {
|
||||||
|
|
||||||
Vector2 operator-() const;
|
Vector2 operator-() const;
|
||||||
|
|
||||||
bool operator==(const Vector2& p_vec2) const;
|
bool operator==(const Vector2 &p_vec2) const;
|
||||||
|
|
||||||
bool operator!=(const Vector2& p_vec2) const;
|
bool operator!=(const Vector2 &p_vec2) const;
|
||||||
|
|
||||||
inline bool operator<(const Vector2& p_vec2) const { return (x==p_vec2.x)?(y<p_vec2.y):(x<p_vec2.x); }
|
|
||||||
inline bool operator<=(const Vector2& p_vec2) const { return (x==p_vec2.x)?(y<=p_vec2.y):(x<=p_vec2.x); }
|
|
||||||
|
|
||||||
|
inline bool operator<(const Vector2 &p_vec2) const { return (x == p_vec2.x) ? (y < p_vec2.y) : (x < p_vec2.x); }
|
||||||
|
inline bool operator<=(const Vector2 &p_vec2) const { return (x == p_vec2.x) ? (y <= p_vec2.y) : (x <= p_vec2.x); }
|
||||||
|
|
||||||
void normalize();
|
void normalize();
|
||||||
|
|
||||||
|
@ -67,32 +65,31 @@ struct Vector2 {
|
||||||
real_t length() const;
|
real_t length() const;
|
||||||
real_t length_squared() const;
|
real_t length_squared() const;
|
||||||
|
|
||||||
real_t distance_to(const Vector2& p_vector2) const;
|
real_t distance_to(const Vector2 &p_vector2) const;
|
||||||
real_t distance_squared_to(const Vector2& p_vector2) const;
|
real_t distance_squared_to(const Vector2 &p_vector2) const;
|
||||||
|
|
||||||
real_t angle_to(const Vector2& p_vector2) const;
|
real_t angle_to(const Vector2 &p_vector2) const;
|
||||||
real_t angle_to_point(const Vector2& p_vector2) const;
|
real_t angle_to_point(const Vector2 &p_vector2) const;
|
||||||
|
|
||||||
real_t dot(const Vector2& p_other) const;
|
real_t dot(const Vector2 &p_other) const;
|
||||||
|
|
||||||
real_t cross(const Vector2& p_other) const;
|
real_t cross(const Vector2 &p_other) const;
|
||||||
Vector2 cross(real_t p_other) const;
|
Vector2 cross(real_t p_other) const;
|
||||||
|
|
||||||
Vector2 project(const Vector2& p_vec) const;
|
Vector2 project(const Vector2 &p_vec) const;
|
||||||
|
|
||||||
Vector2 plane_project(real_t p_d, const Vector2& p_vec) const;
|
Vector2 plane_project(real_t p_d, const Vector2 &p_vec) const;
|
||||||
|
|
||||||
Vector2 clamped(real_t p_len) const;
|
Vector2 clamped(real_t p_len) const;
|
||||||
|
|
||||||
static Vector2 linear_interpolate(const Vector2& p_a, const Vector2& p_b,real_t p_t);
|
static Vector2 linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_t);
|
||||||
|
|
||||||
Vector2 linear_interpolate(const Vector2& p_b,real_t p_t) const;
|
Vector2 linear_interpolate(const Vector2 &p_b, real_t p_t) const;
|
||||||
Vector2 cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, const Vector2& p_post_b,real_t p_t) const;
|
Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const;
|
||||||
|
|
||||||
|
Vector2 slide(const Vector2 &p_vec) const;
|
||||||
|
|
||||||
Vector2 slide(const Vector2& p_vec) const;
|
Vector2 reflect(const Vector2 &p_vec) const;
|
||||||
|
|
||||||
Vector2 reflect(const Vector2& p_vec) const;
|
|
||||||
|
|
||||||
real_t angle() const;
|
real_t angle() const;
|
||||||
|
|
||||||
|
@ -105,24 +102,25 @@ struct Vector2 {
|
||||||
|
|
||||||
Vector2 floor() const;
|
Vector2 floor() const;
|
||||||
|
|
||||||
Vector2 snapped(const Vector2& p_by) const;
|
Vector2 snapped(const Vector2 &p_by) const;
|
||||||
inline real_t aspect() const { return width/height; }
|
inline real_t aspect() const { return width / height; }
|
||||||
|
|
||||||
|
|
||||||
operator String() const;
|
operator String() const;
|
||||||
|
|
||||||
inline Vector2(real_t p_x,real_t p_y) { x=p_x; y=p_y; }
|
inline Vector2(real_t p_x, real_t p_y) {
|
||||||
inline Vector2() { x=0; y=0; }
|
x = p_x;
|
||||||
|
y = p_y;
|
||||||
|
}
|
||||||
|
inline Vector2() {
|
||||||
|
x = 0;
|
||||||
|
y = 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline Vector2 operator*(real_t p_scalar, const Vector2 &p_vec) {
|
||||||
inline Vector2 operator*(real_t p_scalar, const Vector2& p_vec)
|
return p_vec * p_scalar;
|
||||||
{
|
|
||||||
return p_vec*p_scalar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // VECTOR2_H
|
#endif // VECTOR2_H
|
||||||
|
|
|
@ -31,68 +31,67 @@ struct Vector3 {
|
||||||
|
|
||||||
Vector3();
|
Vector3();
|
||||||
|
|
||||||
const real_t& operator[](int p_axis) const;
|
const real_t &operator[](int p_axis) const;
|
||||||
|
|
||||||
real_t& operator[](int p_axis);
|
real_t &operator[](int p_axis);
|
||||||
|
|
||||||
Vector3& operator+=(const Vector3& p_v);
|
Vector3 &operator+=(const Vector3 &p_v);
|
||||||
|
|
||||||
Vector3 operator+(const Vector3& p_v) const;
|
Vector3 operator+(const Vector3 &p_v) const;
|
||||||
|
|
||||||
Vector3& operator-=(const Vector3& p_v);
|
Vector3 &operator-=(const Vector3 &p_v);
|
||||||
|
|
||||||
Vector3 operator-(const Vector3& p_v) const;
|
Vector3 operator-(const Vector3 &p_v) const;
|
||||||
|
|
||||||
Vector3& operator*=(const Vector3& p_v);
|
Vector3 &operator*=(const Vector3 &p_v);
|
||||||
|
|
||||||
Vector3 operator*(const Vector3& p_v) const;
|
Vector3 operator*(const Vector3 &p_v) const;
|
||||||
|
|
||||||
Vector3& operator/=(const Vector3& p_v);
|
Vector3 &operator/=(const Vector3 &p_v);
|
||||||
|
|
||||||
Vector3 operator/(const Vector3& p_v) const;
|
Vector3 operator/(const Vector3 &p_v) const;
|
||||||
|
|
||||||
|
Vector3 &operator*=(real_t p_scalar);
|
||||||
Vector3& operator*=(real_t p_scalar);
|
|
||||||
|
|
||||||
Vector3 operator*(real_t p_scalar) const;
|
Vector3 operator*(real_t p_scalar) const;
|
||||||
|
|
||||||
Vector3& operator/=(real_t p_scalar);
|
Vector3 &operator/=(real_t p_scalar);
|
||||||
|
|
||||||
Vector3 operator/(real_t p_scalar) const;
|
Vector3 operator/(real_t p_scalar) const;
|
||||||
|
|
||||||
Vector3 operator-() const;
|
Vector3 operator-() const;
|
||||||
|
|
||||||
bool operator==(const Vector3& p_v) const;
|
bool operator==(const Vector3 &p_v) const;
|
||||||
|
|
||||||
bool operator!=(const Vector3& p_v) const;
|
bool operator!=(const Vector3 &p_v) const;
|
||||||
|
|
||||||
bool operator<(const Vector3& p_v) const;
|
bool operator<(const Vector3 &p_v) const;
|
||||||
|
|
||||||
bool operator<=(const Vector3& p_v) const;
|
bool operator<=(const Vector3 &p_v) const;
|
||||||
|
|
||||||
Vector3 abs() const;
|
Vector3 abs() const;
|
||||||
|
|
||||||
Vector3 ceil() const;
|
Vector3 ceil() const;
|
||||||
|
|
||||||
Vector3 cross(const Vector3& b) const;
|
Vector3 cross(const Vector3 &b) const;
|
||||||
|
|
||||||
Vector3 linear_interpolate(const Vector3& p_b,real_t p_t) const;
|
Vector3 linear_interpolate(const Vector3 &p_b, real_t p_t) const;
|
||||||
|
|
||||||
Vector3 cubic_interpolate(const Vector3& b, const Vector3& pre_a, const Vector3& post_b, const real_t t) const;
|
Vector3 cubic_interpolate(const Vector3 &b, const Vector3 &pre_a, const Vector3 &post_b, const real_t t) const;
|
||||||
|
|
||||||
Vector3 bounce(const Vector3& p_normal) const;
|
Vector3 bounce(const Vector3 &p_normal) const;
|
||||||
|
|
||||||
real_t length() const;
|
real_t length() const;
|
||||||
|
|
||||||
real_t length_squared() const;
|
real_t length_squared() const;
|
||||||
|
|
||||||
real_t distance_squared_to(const Vector3& b) const;
|
real_t distance_squared_to(const Vector3 &b) const;
|
||||||
|
|
||||||
real_t distance_to(const Vector3& b) const;
|
real_t distance_to(const Vector3 &b) const;
|
||||||
|
|
||||||
real_t dot(const Vector3& b) const;
|
real_t dot(const Vector3 &b) const;
|
||||||
|
|
||||||
real_t angle_to(const Vector3& b) const;
|
real_t angle_to(const Vector3 &b) const;
|
||||||
|
|
||||||
Vector3 floor() const;
|
Vector3 floor() const;
|
||||||
|
|
||||||
|
@ -100,9 +99,7 @@ struct Vector3 {
|
||||||
|
|
||||||
bool is_normalized() const;
|
bool is_normalized() const;
|
||||||
|
|
||||||
Basis outer(const Vector3& b) const;
|
Basis outer(const Vector3 &b) const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int max_axis() const;
|
int max_axis() const;
|
||||||
|
|
||||||
|
@ -112,13 +109,13 @@ struct Vector3 {
|
||||||
|
|
||||||
Vector3 normalized() const;
|
Vector3 normalized() const;
|
||||||
|
|
||||||
Vector3 reflect(const Vector3& by) const;
|
Vector3 reflect(const Vector3 &by) const;
|
||||||
|
|
||||||
Vector3 rotated(const Vector3& axis, const real_t phi) const;
|
Vector3 rotated(const Vector3 &axis, const real_t phi) const;
|
||||||
|
|
||||||
void rotate(const Vector3& p_axis,real_t p_phi);
|
void rotate(const Vector3 &p_axis, real_t p_phi);
|
||||||
|
|
||||||
Vector3 slide(const Vector3& by) const;
|
Vector3 slide(const Vector3 &by) const;
|
||||||
|
|
||||||
void snap(real_t p_val);
|
void snap(real_t p_val);
|
||||||
|
|
||||||
|
@ -127,16 +124,15 @@ struct Vector3 {
|
||||||
operator String() const;
|
operator String() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Vector3 operator*(real_t p_scalar, const Vector3& p_vec)
|
inline Vector3 operator*(real_t p_scalar, const Vector3 &p_vec) {
|
||||||
{
|
|
||||||
return p_vec * p_scalar;
|
return p_vec * p_scalar;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Vector3 vec3_cross(const Vector3& p_a, const Vector3& p_b) {
|
inline Vector3 vec3_cross(const Vector3 &p_a, const Vector3 &p_b) {
|
||||||
|
|
||||||
return p_a.cross(p_b);
|
return p_a.cross(p_b);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif // VECTOR3_H
|
#endif // VECTOR3_H
|
||||||
|
|
|
@ -11,6 +11,6 @@ public:
|
||||||
size_t _type_tag;
|
size_t _type_tag;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#endif // WRAPPED_HPP
|
#endif // WRAPPED_HPP
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Git hooks for Godot Engine
|
||||||
|
|
||||||
|
This folder contains git hooks meant to be installed locally by Godot Engine
|
||||||
|
contributors to make sure they comply with our requirements.
|
||||||
|
|
||||||
|
## List of hooks
|
||||||
|
|
||||||
|
- Pre-commit hook for clang-format: Applies clang-format to the staged files
|
||||||
|
before accepting a commit; blocks the commit and generates a patch if the
|
||||||
|
style is not respected.
|
||||||
|
Should work on Linux and macOS. You may need to edit the file if your
|
||||||
|
clang-format binary is not in the $PATH, or if you want to enable colored
|
||||||
|
output with pygmentize.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Copy all the files from this folder into your .git/hooks folder, and make sure
|
||||||
|
the hooks and helper scripts are executable.
|
|
@ -0,0 +1,48 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Provide the canonicalize filename (physical filename with out any symlinks)
|
||||||
|
# like the GNU version readlink with the -f option regardless of the version of
|
||||||
|
# readlink (GNU or BSD).
|
||||||
|
|
||||||
|
# This file is part of a set of unofficial pre-commit hooks available
|
||||||
|
# at github.
|
||||||
|
# Link: https://github.com/githubbrowser/Pre-commit-hooks
|
||||||
|
# Contact: David Martin, david.martin.mailbox@googlemail.com
|
||||||
|
|
||||||
|
###########################################################
|
||||||
|
# There should be no need to change anything below this line.
|
||||||
|
|
||||||
|
# Canonicalize by recursively following every symlink in every component of the
|
||||||
|
# specified filename. This should reproduce the results of the GNU version of
|
||||||
|
# readlink with the -f option.
|
||||||
|
#
|
||||||
|
# Reference: http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
|
||||||
|
canonicalize_filename () {
|
||||||
|
local target_file="$1"
|
||||||
|
local physical_directory=""
|
||||||
|
local result=""
|
||||||
|
|
||||||
|
# Need to restore the working directory after work.
|
||||||
|
local working_dir="`pwd`"
|
||||||
|
|
||||||
|
cd -- "$(dirname -- "$target_file")"
|
||||||
|
target_file="$(basename -- "$target_file")"
|
||||||
|
|
||||||
|
# Iterate down a (possible) chain of symlinks
|
||||||
|
while [ -L "$target_file" ]
|
||||||
|
do
|
||||||
|
target_file="$(readlink -- "$target_file")"
|
||||||
|
cd -- "$(dirname -- "$target_file")"
|
||||||
|
target_file="$(basename -- "$target_file")"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Compute the canonicalized name by finding the physical path
|
||||||
|
# for the directory we're in and appending the target file.
|
||||||
|
physical_directory="`pwd -P`"
|
||||||
|
result="$physical_directory/$target_file"
|
||||||
|
|
||||||
|
# restore the working directory after work.
|
||||||
|
cd -- "$working_dir"
|
||||||
|
|
||||||
|
echo "$result"
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Git pre-commit hook that runs multiple hooks specified in $HOOKS.
|
||||||
|
# Make sure this script is executable. Bypass hooks with git commit --no-verify.
|
||||||
|
|
||||||
|
# This file is part of a set of unofficial pre-commit hooks available
|
||||||
|
# at github.
|
||||||
|
# Link: https://github.com/githubbrowser/Pre-commit-hooks
|
||||||
|
# Contact: David Martin, david.martin.mailbox@googlemail.com
|
||||||
|
|
||||||
|
|
||||||
|
###########################################################
|
||||||
|
# CONFIGURATION:
|
||||||
|
# pre-commit hooks to be executed. They should be in the same .git/hooks/ folder
|
||||||
|
# as this script. Hooks should return 0 if successful and nonzero to cancel the
|
||||||
|
# commit. They are executed in the order in which they are listed.
|
||||||
|
#HOOKS="pre-commit-compile pre-commit-uncrustify"
|
||||||
|
HOOKS="pre-commit-clang-format"
|
||||||
|
###########################################################
|
||||||
|
# There should be no need to change anything below this line.
|
||||||
|
|
||||||
|
. "$(dirname -- "$0")/canonicalize_filename.sh"
|
||||||
|
|
||||||
|
# exit on error
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Absolute path to this script, e.g. /home/user/bin/foo.sh
|
||||||
|
SCRIPT="$(canonicalize_filename "$0")"
|
||||||
|
|
||||||
|
# Absolute path this script is in, thus /home/user/bin
|
||||||
|
SCRIPTPATH="$(dirname -- "$SCRIPT")"
|
||||||
|
|
||||||
|
|
||||||
|
for hook in $HOOKS
|
||||||
|
do
|
||||||
|
echo "Running hook: $hook"
|
||||||
|
# run hook if it exists
|
||||||
|
# if it returns with nonzero exit with 1 and thus abort the commit
|
||||||
|
if [ -f "$SCRIPTPATH/$hook" ]; then
|
||||||
|
"$SCRIPTPATH/$hook"
|
||||||
|
if [ $? != 0 ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Error: file $hook not found."
|
||||||
|
echo "Aborting commit. Make sure the hook is in $SCRIPTPATH and executable."
|
||||||
|
echo "You can disable it by removing it from the list in $SCRIPT."
|
||||||
|
echo "You can skip all pre-commit hooks with --no-verify (not recommended)."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
|
@ -0,0 +1,147 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# git pre-commit hook that runs a clang-format stylecheck.
|
||||||
|
# Features:
|
||||||
|
# - abort commit when commit does not comply with the style guidelines
|
||||||
|
# - create a patch of the proposed style changes
|
||||||
|
# Modifications for clang-format by rene.milk@wwu.de
|
||||||
|
|
||||||
|
# This file is part of a set of unofficial pre-commit hooks available
|
||||||
|
# at github.
|
||||||
|
# Link: https://github.com/githubbrowser/Pre-commit-hooks
|
||||||
|
# Contact: David Martin, david.martin.mailbox@googlemail.com
|
||||||
|
|
||||||
|
# Some quality of life modifications made for Godot Engine.
|
||||||
|
|
||||||
|
##################################################################
|
||||||
|
# SETTINGS
|
||||||
|
# Set path to clang-format binary
|
||||||
|
# CLANG_FORMAT="/usr/bin/clang-format"
|
||||||
|
CLANG_FORMAT=`which clang-format`
|
||||||
|
|
||||||
|
# Remove any older patches from previous commits. Set to true or false.
|
||||||
|
# DELETE_OLD_PATCHES=false
|
||||||
|
DELETE_OLD_PATCHES=false
|
||||||
|
|
||||||
|
# Only parse files with the extensions in FILE_EXTS. Set to true or false.
|
||||||
|
# If false every changed file in the commit will be parsed with clang-format.
|
||||||
|
# If true only files matching one of the extensions are parsed with clang-format.
|
||||||
|
# PARSE_EXTS=true
|
||||||
|
PARSE_EXTS=true
|
||||||
|
|
||||||
|
# File types to parse. Only effective when PARSE_EXTS is true.
|
||||||
|
# FILE_EXTS=".c .h .cpp .hpp"
|
||||||
|
FILE_EXTS=".c .h .cpp .hpp .cc .hh .cxx .m .mm .inc .java .glsl"
|
||||||
|
|
||||||
|
# Use pygmentize instead of cat to parse diff with highlighting.
|
||||||
|
# Install it with `pip install pygments` (Linux) or `easy_install Pygments` (Mac)
|
||||||
|
# READER="pygmentize -l diff"
|
||||||
|
READER=cat
|
||||||
|
|
||||||
|
##################################################################
|
||||||
|
# There should be no need to change anything below this line.
|
||||||
|
|
||||||
|
. "$(dirname -- "$0")/canonicalize_filename.sh"
|
||||||
|
|
||||||
|
# exit on error
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# check whether the given file matches any of the set extensions
|
||||||
|
matches_extension() {
|
||||||
|
local filename=$(basename "$1")
|
||||||
|
local extension=".${filename##*.}"
|
||||||
|
local ext
|
||||||
|
|
||||||
|
for ext in $FILE_EXTS; do [[ "$ext" == "$extension" ]] && return 0; done
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# necessary check for initial commit
|
||||||
|
if git rev-parse --verify HEAD >/dev/null 2>&1 ; then
|
||||||
|
against=HEAD
|
||||||
|
else
|
||||||
|
# Initial commit: diff against an empty tree object
|
||||||
|
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -x "$CLANG_FORMAT" ] ; then
|
||||||
|
printf "Error: clang-format executable not found.\n"
|
||||||
|
printf "Set the correct path in $(canonicalize_filename "$0").\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# create a random filename to store our generated patch
|
||||||
|
prefix="pre-commit-clang-format"
|
||||||
|
suffix="$(date +%s)"
|
||||||
|
patch="/tmp/$prefix-$suffix.patch"
|
||||||
|
|
||||||
|
# clean up any older clang-format patches
|
||||||
|
$DELETE_OLD_PATCHES && rm -f /tmp/$prefix*.patch
|
||||||
|
|
||||||
|
# create one patch containing all changes to the files
|
||||||
|
git diff-index --cached --diff-filter=ACMR --name-only $against -- | while read file;
|
||||||
|
do
|
||||||
|
# ignore thirdparty files
|
||||||
|
if grep -q "thirdparty" <<< $file; then
|
||||||
|
continue;
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ignore file if we do check for file extensions and the file
|
||||||
|
# does not match any of the extensions specified in $FILE_EXTS
|
||||||
|
if $PARSE_EXTS && ! matches_extension "$file"; then
|
||||||
|
continue;
|
||||||
|
fi
|
||||||
|
|
||||||
|
# clang-format our sourcefile, create a patch with diff and append it to our $patch
|
||||||
|
# The sed call is necessary to transform the patch from
|
||||||
|
# --- $file timestamp
|
||||||
|
# +++ - timestamp
|
||||||
|
# to both lines working on the same file and having a/ and b/ prefix.
|
||||||
|
# Else it can not be applied with 'git apply'.
|
||||||
|
"$CLANG_FORMAT" -style=file "$file" | \
|
||||||
|
diff -u "$file" - | \
|
||||||
|
sed -e "1s|--- |--- a/|" -e "2s|+++ -|+++ b/$file|" >> "$patch"
|
||||||
|
done
|
||||||
|
|
||||||
|
# if no patch has been generated all is ok, clean up the file stub and exit
|
||||||
|
if [ ! -s "$patch" ] ; then
|
||||||
|
printf "Files in this commit comply with the clang-format rules.\n"
|
||||||
|
rm -f "$patch"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# a patch has been created, notify the user and exit
|
||||||
|
printf "\nThe following differences were found between the code to commit "
|
||||||
|
printf "and the clang-format rules:\n\n"
|
||||||
|
$READER "$patch"
|
||||||
|
printf "\n"
|
||||||
|
|
||||||
|
# Allows us to read user input below, assigns stdin to keyboard
|
||||||
|
exec < /dev/tty
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
read -p "Do you want to apply that patch (Y - Apply, N - Do not apply, S - Apply and stage files)? [Y/N/S] " yn
|
||||||
|
case $yn in
|
||||||
|
[Yy] ) git apply $patch;
|
||||||
|
printf "The patch was applied. You can now stage the changes and commit again.\n\n";
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
[Nn] ) printf "\nYou can apply these changes with:\n git apply $patch\n";
|
||||||
|
printf "(may need to be called from the root directory of your repository)\n";
|
||||||
|
printf "Aborting commit. Apply changes and commit again or skip checking with";
|
||||||
|
printf " --no-verify (not recommended).\n\n";
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
[Ss] ) git apply $patch;
|
||||||
|
git diff-index --cached --diff-filter=ACMR --name-only $against -- | while read file;
|
||||||
|
do git add $file;
|
||||||
|
done
|
||||||
|
printf "The patch was applied and the changed files staged. You can now commit.\n\n";
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
* ) echo "Please answer yes or no."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
exit 1 # we don't commit in any case
|
|
@ -1,53 +1,53 @@
|
||||||
#include "AABB.hpp"
|
#include "AABB.hpp"
|
||||||
#include "Vector3.hpp"
|
|
||||||
#include "Plane.hpp"
|
#include "Plane.hpp"
|
||||||
|
#include "Vector3.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
bool AABB::intersects(const AABB& p_aabb) const {
|
bool AABB::intersects(const AABB &p_aabb) const {
|
||||||
|
|
||||||
if ( position.x >= (p_aabb.position.x + p_aabb.size.x) )
|
if (position.x >= (p_aabb.position.x + p_aabb.size.x))
|
||||||
return false;
|
return false;
|
||||||
if ( (position.x+size.x) <= p_aabb.position.x )
|
if ((position.x + size.x) <= p_aabb.position.x)
|
||||||
return false;
|
return false;
|
||||||
if ( position.y >= (p_aabb.position.y + p_aabb.size.y) )
|
if (position.y >= (p_aabb.position.y + p_aabb.size.y))
|
||||||
return false;
|
return false;
|
||||||
if ( (position.y+size.y) <= p_aabb.position.y )
|
if ((position.y + size.y) <= p_aabb.position.y)
|
||||||
return false;
|
return false;
|
||||||
if ( position.z >= (p_aabb.position.z + p_aabb.size.z) )
|
if (position.z >= (p_aabb.position.z + p_aabb.size.z))
|
||||||
return false;
|
return false;
|
||||||
if ( (position.z+size.z) <= p_aabb.position.z )
|
if ((position.z + size.z) <= p_aabb.position.z)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AABB::intersects_inclusive(const AABB& p_aabb) const {
|
bool AABB::intersects_inclusive(const AABB &p_aabb) const {
|
||||||
|
|
||||||
if ( position.x > (p_aabb.position.x + p_aabb.size.x) )
|
if (position.x > (p_aabb.position.x + p_aabb.size.x))
|
||||||
return false;
|
return false;
|
||||||
if ( (position.x+size.x) < p_aabb.position.x )
|
if ((position.x + size.x) < p_aabb.position.x)
|
||||||
return false;
|
return false;
|
||||||
if ( position.y > (p_aabb.position.y + p_aabb.size.y) )
|
if (position.y > (p_aabb.position.y + p_aabb.size.y))
|
||||||
return false;
|
return false;
|
||||||
if ( (position.y+size.y) < p_aabb.position.y )
|
if ((position.y + size.y) < p_aabb.position.y)
|
||||||
return false;
|
return false;
|
||||||
if ( position.z > (p_aabb.position.z + p_aabb.size.z) )
|
if (position.z > (p_aabb.position.z + p_aabb.size.z))
|
||||||
return false;
|
return false;
|
||||||
if ( (position.z+size.z) < p_aabb.position.z )
|
if ((position.z + size.z) < p_aabb.position.z)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AABB::encloses(const AABB & p_aabb) const {
|
bool AABB::encloses(const AABB &p_aabb) const {
|
||||||
|
|
||||||
Vector3 src_min=position;
|
Vector3 src_min = position;
|
||||||
Vector3 src_max=position+size;
|
Vector3 src_max = position + size;
|
||||||
Vector3 dst_min=p_aabb.position;
|
Vector3 dst_min = p_aabb.position;
|
||||||
Vector3 dst_max=p_aabb.position+p_aabb.size;
|
Vector3 dst_max = p_aabb.position + p_aabb.size;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(src_min.x <= dst_min.x) &&
|
(src_min.x <= dst_min.x) &&
|
||||||
|
@ -55,34 +55,32 @@ bool AABB::encloses(const AABB & p_aabb) const {
|
||||||
(src_min.y <= dst_min.y) &&
|
(src_min.y <= dst_min.y) &&
|
||||||
(src_max.y > dst_max.y) &&
|
(src_max.y > dst_max.y) &&
|
||||||
(src_min.z <= dst_min.z) &&
|
(src_min.z <= dst_min.z) &&
|
||||||
(src_max.z > dst_max.z) );
|
(src_max.z > dst_max.z));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 AABB::get_support(const Vector3& p_normal) const {
|
Vector3 AABB::get_support(const Vector3 &p_normal) const {
|
||||||
|
|
||||||
Vector3 half_extents = size * 0.5;
|
Vector3 half_extents = size * 0.5;
|
||||||
Vector3 ofs = position + half_extents;
|
Vector3 ofs = position + half_extents;
|
||||||
|
|
||||||
return Vector3(
|
return Vector3(
|
||||||
(p_normal.x>0) ? -half_extents.x : half_extents.x,
|
(p_normal.x > 0) ? -half_extents.x : half_extents.x,
|
||||||
(p_normal.y>0) ? -half_extents.y : half_extents.y,
|
(p_normal.y > 0) ? -half_extents.y : half_extents.y,
|
||||||
(p_normal.z>0) ? -half_extents.z : half_extents.z
|
(p_normal.z > 0) ? -half_extents.z : half_extents.z) +
|
||||||
)+ofs;
|
ofs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Vector3 AABB::get_endpoint(int p_point) const {
|
Vector3 AABB::get_endpoint(int p_point) const {
|
||||||
|
|
||||||
switch(p_point) {
|
switch (p_point) {
|
||||||
case 0: return Vector3( position.x , position.y , position.z );
|
case 0: return Vector3(position.x, position.y, position.z);
|
||||||
case 1: return Vector3( position.x , position.y , position.z+size.z );
|
case 1: return Vector3(position.x, position.y, position.z + size.z);
|
||||||
case 2: return Vector3( position.x , position.y+size.y , position.z );
|
case 2: return Vector3(position.x, position.y + size.y, position.z);
|
||||||
case 3: return Vector3( position.x , position.y+size.y , position.z+size.z );
|
case 3: return Vector3(position.x, position.y + size.y, position.z + size.z);
|
||||||
case 4: return Vector3( position.x+size.x , position.y , position.z );
|
case 4: return Vector3(position.x + size.x, position.y, position.z);
|
||||||
case 5: return Vector3( position.x+size.x , position.y , position.z+size.z );
|
case 5: return Vector3(position.x + size.x, position.y, position.z + size.z);
|
||||||
case 6: return Vector3( position.x+size.x , position.y+size.y , position.z );
|
case 6: return Vector3(position.x + size.x, position.y + size.y, position.z);
|
||||||
case 7: return Vector3( position.x+size.x , position.y+size.y , position.z+size.z );
|
case 7: return Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
|
||||||
};
|
};
|
||||||
|
|
||||||
ERR_FAIL_V(Vector3());
|
ERR_FAIL_V(Vector3());
|
||||||
|
@ -93,14 +91,13 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count) con
|
||||||
Vector3 half_extents = size * 0.5;
|
Vector3 half_extents = size * 0.5;
|
||||||
Vector3 ofs = position + half_extents;
|
Vector3 ofs = position + half_extents;
|
||||||
|
|
||||||
for(int i=0;i<p_plane_count;i++) {
|
for (int i = 0; i < p_plane_count; i++) {
|
||||||
const Plane &p=p_planes[i];
|
const Plane &p = p_planes[i];
|
||||||
Vector3 point(
|
Vector3 point(
|
||||||
(p.normal.x>0) ? -half_extents.x : half_extents.x,
|
(p.normal.x > 0) ? -half_extents.x : half_extents.x,
|
||||||
(p.normal.y>0) ? -half_extents.y : half_extents.y,
|
(p.normal.y > 0) ? -half_extents.y : half_extents.y,
|
||||||
(p.normal.z>0) ? -half_extents.z : half_extents.z
|
(p.normal.z > 0) ? -half_extents.z : half_extents.z);
|
||||||
);
|
point += ofs;
|
||||||
point+=ofs;
|
|
||||||
if (p.is_point_over(point))
|
if (p.is_point_over(point))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -108,69 +105,68 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count) con
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AABB::has_point(const Vector3& p_point) const {
|
bool AABB::has_point(const Vector3 &p_point) const {
|
||||||
|
|
||||||
if (p_point.x<position.x)
|
if (p_point.x < position.x)
|
||||||
return false;
|
return false;
|
||||||
if (p_point.y<position.y)
|
if (p_point.y < position.y)
|
||||||
return false;
|
return false;
|
||||||
if (p_point.z<position.z)
|
if (p_point.z < position.z)
|
||||||
return false;
|
return false;
|
||||||
if (p_point.x>position.x+size.x)
|
if (p_point.x > position.x + size.x)
|
||||||
return false;
|
return false;
|
||||||
if (p_point.y>position.y+size.y)
|
if (p_point.y > position.y + size.y)
|
||||||
return false;
|
return false;
|
||||||
if (p_point.z>position.z+size.z)
|
if (p_point.z > position.z + size.z)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AABB::expand_to(const Vector3 &p_vector) {
|
||||||
|
|
||||||
void AABB::expand_to(const Vector3& p_vector) {
|
Vector3 begin = position;
|
||||||
|
Vector3 end = position + size;
|
||||||
|
|
||||||
Vector3 begin=position;
|
if (p_vector.x < begin.x)
|
||||||
Vector3 end=position+size;
|
begin.x = p_vector.x;
|
||||||
|
if (p_vector.y < begin.y)
|
||||||
|
begin.y = p_vector.y;
|
||||||
|
if (p_vector.z < begin.z)
|
||||||
|
begin.z = p_vector.z;
|
||||||
|
|
||||||
if (p_vector.x<begin.x)
|
if (p_vector.x > end.x)
|
||||||
begin.x=p_vector.x;
|
end.x = p_vector.x;
|
||||||
if (p_vector.y<begin.y)
|
if (p_vector.y > end.y)
|
||||||
begin.y=p_vector.y;
|
end.y = p_vector.y;
|
||||||
if (p_vector.z<begin.z)
|
if (p_vector.z > end.z)
|
||||||
begin.z=p_vector.z;
|
end.z = p_vector.z;
|
||||||
|
|
||||||
if (p_vector.x>end.x)
|
position = begin;
|
||||||
end.x=p_vector.x;
|
size = end - begin;
|
||||||
if (p_vector.y>end.y)
|
|
||||||
end.y=p_vector.y;
|
|
||||||
if (p_vector.z>end.z)
|
|
||||||
end.z=p_vector.z;
|
|
||||||
|
|
||||||
position=begin;
|
|
||||||
size=end-begin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AABB::project_range_in_plane(const Plane& p_plane,real_t &r_min,real_t& r_max) const {
|
void AABB::project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const {
|
||||||
|
|
||||||
Vector3 half_extents( size.x * 0.5, size.y * 0.5, size.z * 0.5 );
|
Vector3 half_extents(size.x * 0.5, size.y * 0.5, size.z * 0.5);
|
||||||
Vector3 center( position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z );
|
Vector3 center(position.x + half_extents.x, position.y + half_extents.y, position.z + half_extents.z);
|
||||||
|
|
||||||
real_t length = p_plane.normal.abs().dot(half_extents);
|
real_t length = p_plane.normal.abs().dot(half_extents);
|
||||||
real_t distance = p_plane.distance_to( center );
|
real_t distance = p_plane.distance_to(center);
|
||||||
r_min = distance - length;
|
r_min = distance - length;
|
||||||
r_max = distance + length;
|
r_max = distance + length;
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t AABB::get_longest_axis_size() const {
|
real_t AABB::get_longest_axis_size() const {
|
||||||
|
|
||||||
real_t max_size=size.x;
|
real_t max_size = size.x;
|
||||||
|
|
||||||
if (size.y > max_size ) {
|
if (size.y > max_size) {
|
||||||
max_size=size.y;
|
max_size = size.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size.z > max_size ) {
|
if (size.z > max_size) {
|
||||||
max_size=size.z;
|
max_size = size.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
return max_size;
|
return max_size;
|
||||||
|
@ -178,44 +174,42 @@ real_t AABB::get_longest_axis_size() const {
|
||||||
|
|
||||||
real_t AABB::get_shortest_axis_size() const {
|
real_t AABB::get_shortest_axis_size() const {
|
||||||
|
|
||||||
real_t max_size=size.x;
|
real_t max_size = size.x;
|
||||||
|
|
||||||
if (size.y < max_size ) {
|
if (size.y < max_size) {
|
||||||
max_size=size.y;
|
max_size = size.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size.z < max_size ) {
|
if (size.z < max_size) {
|
||||||
max_size=size.z;
|
max_size = size.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
return max_size;
|
return max_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AABB::smits_intersect_ray(const Vector3 &from,const Vector3& dir, real_t t0, real_t t1) const {
|
bool AABB::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t t0, real_t t1) const {
|
||||||
|
|
||||||
real_t divx=1.0/dir.x;
|
real_t divx = 1.0 / dir.x;
|
||||||
real_t divy=1.0/dir.y;
|
real_t divy = 1.0 / dir.y;
|
||||||
real_t divz=1.0/dir.z;
|
real_t divz = 1.0 / dir.z;
|
||||||
|
|
||||||
Vector3 upbound=position+size;
|
Vector3 upbound = position + size;
|
||||||
real_t tmin, tmax, tymin, tymax, tzmin, tzmax;
|
real_t tmin, tmax, tymin, tymax, tzmin, tzmax;
|
||||||
if (dir.x >= 0) {
|
if (dir.x >= 0) {
|
||||||
tmin = (position.x - from.x) * divx;
|
tmin = (position.x - from.x) * divx;
|
||||||
tmax = (upbound.x - from.x) * divx;
|
tmax = (upbound.x - from.x) * divx;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
tmin = (upbound.x - from.x) * divx;
|
tmin = (upbound.x - from.x) * divx;
|
||||||
tmax = (position.x - from.x) * divx;
|
tmax = (position.x - from.x) * divx;
|
||||||
}
|
}
|
||||||
if (dir.y >= 0) {
|
if (dir.y >= 0) {
|
||||||
tymin = (position.y - from.y) * divy;
|
tymin = (position.y - from.y) * divy;
|
||||||
tymax = (upbound.y - from.y) * divy;
|
tymax = (upbound.y - from.y) * divy;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
tymin = (upbound.y - from.y) * divy;
|
tymin = (upbound.y - from.y) * divy;
|
||||||
tymax = (position.y - from.y) * divy;
|
tymax = (position.y - from.y) * divy;
|
||||||
}
|
}
|
||||||
if ( (tmin > tymax) || (tymin > tmax) )
|
if ((tmin > tymax) || (tymin > tmax))
|
||||||
return false;
|
return false;
|
||||||
if (tymin > tmin)
|
if (tymin > tmin)
|
||||||
tmin = tymin;
|
tmin = tymin;
|
||||||
|
@ -224,121 +218,112 @@ bool AABB::smits_intersect_ray(const Vector3 &from,const Vector3& dir, real_t t0
|
||||||
if (dir.z >= 0) {
|
if (dir.z >= 0) {
|
||||||
tzmin = (position.z - from.z) * divz;
|
tzmin = (position.z - from.z) * divz;
|
||||||
tzmax = (upbound.z - from.z) * divz;
|
tzmax = (upbound.z - from.z) * divz;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
tzmin = (upbound.z - from.z) * divz;
|
tzmin = (upbound.z - from.z) * divz;
|
||||||
tzmax = (position.z - from.z) * divz;
|
tzmax = (position.z - from.z) * divz;
|
||||||
}
|
}
|
||||||
if ( (tmin > tzmax) || (tzmin > tmax) )
|
if ((tmin > tzmax) || (tzmin > tmax))
|
||||||
return false;
|
return false;
|
||||||
if (tzmin > tmin)
|
if (tzmin > tmin)
|
||||||
tmin = tzmin;
|
tmin = tzmin;
|
||||||
if (tzmax < tmax)
|
if (tzmax < tmax)
|
||||||
tmax = tzmax;
|
tmax = tzmax;
|
||||||
return ( (tmin < t1) && (tmax > t0) );
|
return ((tmin < t1) && (tmax > t0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AABB::grow_by(real_t p_amount) {
|
void AABB::grow_by(real_t p_amount) {
|
||||||
|
|
||||||
position.x-=p_amount;
|
position.x -= p_amount;
|
||||||
position.y-=p_amount;
|
position.y -= p_amount;
|
||||||
position.z-=p_amount;
|
position.z -= p_amount;
|
||||||
size.x+=2.0*p_amount;
|
size.x += 2.0 * p_amount;
|
||||||
size.y+=2.0*p_amount;
|
size.y += 2.0 * p_amount;
|
||||||
size.z+=2.0*p_amount;
|
size.z += 2.0 * p_amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
real_t AABB::get_area() const {
|
real_t AABB::get_area() const {
|
||||||
|
|
||||||
return size.x*size.y*size.z;
|
return size.x * size.y * size.z;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AABB::operator==(const AABB& p_rval) const {
|
bool AABB::operator==(const AABB &p_rval) const {
|
||||||
|
|
||||||
return ((position==p_rval.position) && (size==p_rval.size));
|
|
||||||
|
|
||||||
|
return ((position == p_rval.position) && (size == p_rval.size));
|
||||||
}
|
}
|
||||||
bool AABB::operator!=(const AABB& p_rval) const {
|
bool AABB::operator!=(const AABB &p_rval) const {
|
||||||
|
|
||||||
return ((position!=p_rval.position) || (size!=p_rval.size));
|
|
||||||
|
|
||||||
|
return ((position != p_rval.position) || (size != p_rval.size));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AABB::merge_with(const AABB& p_aabb) {
|
void AABB::merge_with(const AABB &p_aabb) {
|
||||||
|
|
||||||
Vector3 beg_1,beg_2;
|
Vector3 beg_1, beg_2;
|
||||||
Vector3 end_1,end_2;
|
Vector3 end_1, end_2;
|
||||||
Vector3 min,max;
|
Vector3 min, max;
|
||||||
|
|
||||||
beg_1=position;
|
beg_1 = position;
|
||||||
beg_2=p_aabb.position;
|
beg_2 = p_aabb.position;
|
||||||
end_1=Vector3(size.x,size.y,size.z)+beg_1;
|
end_1 = Vector3(size.x, size.y, size.z) + beg_1;
|
||||||
end_2=Vector3(p_aabb.size.x,p_aabb.size.y,p_aabb.size.z)+beg_2;
|
end_2 = Vector3(p_aabb.size.x, p_aabb.size.y, p_aabb.size.z) + beg_2;
|
||||||
|
|
||||||
min.x=(beg_1.x<beg_2.x)?beg_1.x:beg_2.x;
|
min.x = (beg_1.x < beg_2.x) ? beg_1.x : beg_2.x;
|
||||||
min.y=(beg_1.y<beg_2.y)?beg_1.y:beg_2.y;
|
min.y = (beg_1.y < beg_2.y) ? beg_1.y : beg_2.y;
|
||||||
min.z=(beg_1.z<beg_2.z)?beg_1.z:beg_2.z;
|
min.z = (beg_1.z < beg_2.z) ? beg_1.z : beg_2.z;
|
||||||
|
|
||||||
max.x=(end_1.x>end_2.x)?end_1.x:end_2.x;
|
max.x = (end_1.x > end_2.x) ? end_1.x : end_2.x;
|
||||||
max.y=(end_1.y>end_2.y)?end_1.y:end_2.y;
|
max.y = (end_1.y > end_2.y) ? end_1.y : end_2.y;
|
||||||
max.z=(end_1.z>end_2.z)?end_1.z:end_2.z;
|
max.z = (end_1.z > end_2.z) ? end_1.z : end_2.z;
|
||||||
|
|
||||||
position=min;
|
position = min;
|
||||||
size=max-min;
|
size = max - min;
|
||||||
}
|
}
|
||||||
|
|
||||||
AABB AABB::intersection(const AABB& p_aabb) const {
|
AABB AABB::intersection(const AABB &p_aabb) const {
|
||||||
|
|
||||||
Vector3 src_min=position;
|
Vector3 src_min = position;
|
||||||
Vector3 src_max=position+size;
|
Vector3 src_max = position + size;
|
||||||
Vector3 dst_min=p_aabb.position;
|
Vector3 dst_min = p_aabb.position;
|
||||||
Vector3 dst_max=p_aabb.position+p_aabb.size;
|
Vector3 dst_max = p_aabb.position + p_aabb.size;
|
||||||
|
|
||||||
Vector3 min,max;
|
Vector3 min, max;
|
||||||
|
|
||||||
if (src_min.x > dst_max.x || src_max.x < dst_min.x )
|
if (src_min.x > dst_max.x || src_max.x < dst_min.x)
|
||||||
return AABB();
|
return AABB();
|
||||||
else {
|
else {
|
||||||
|
|
||||||
min.x= ( src_min.x > dst_min.x ) ? src_min.x :dst_min.x;
|
min.x = (src_min.x > dst_min.x) ? src_min.x : dst_min.x;
|
||||||
max.x= ( src_max.x < dst_max.x ) ? src_max.x :dst_max.x;
|
max.x = (src_max.x < dst_max.x) ? src_max.x : dst_max.x;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src_min.y > dst_max.y || src_max.y < dst_min.y )
|
if (src_min.y > dst_max.y || src_max.y < dst_min.y)
|
||||||
return AABB();
|
return AABB();
|
||||||
else {
|
else {
|
||||||
|
|
||||||
min.y= ( src_min.y > dst_min.y ) ? src_min.y :dst_min.y;
|
min.y = (src_min.y > dst_min.y) ? src_min.y : dst_min.y;
|
||||||
max.y= ( src_max.y < dst_max.y ) ? src_max.y :dst_max.y;
|
max.y = (src_max.y < dst_max.y) ? src_max.y : dst_max.y;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src_min.z > dst_max.z || src_max.z < dst_min.z )
|
if (src_min.z > dst_max.z || src_max.z < dst_min.z)
|
||||||
return AABB();
|
return AABB();
|
||||||
else {
|
else {
|
||||||
|
|
||||||
min.z= ( src_min.z > dst_min.z ) ? src_min.z :dst_min.z;
|
min.z = (src_min.z > dst_min.z) ? src_min.z : dst_min.z;
|
||||||
max.z= ( src_max.z < dst_max.z ) ? src_max.z :dst_max.z;
|
max.z = (src_max.z < dst_max.z) ? src_max.z : dst_max.z;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return AABB(min, max - min);
|
||||||
return AABB( min, max-min );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AABB::intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r_clip,Vector3* r_normal) const {
|
bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip, Vector3 *r_normal) const {
|
||||||
|
|
||||||
Vector3 c1, c2;
|
Vector3 c1, c2;
|
||||||
Vector3 end = position+size;
|
Vector3 end = position + size;
|
||||||
real_t near=-1e20;
|
real_t near = -1e20;
|
||||||
real_t far=1e20;
|
real_t far = 1e20;
|
||||||
int axis=0;
|
int axis = 0;
|
||||||
|
|
||||||
for (int i=0;i<3;i++){
|
for (int i = 0; i < 3; i++) {
|
||||||
if (p_dir[i] == 0){
|
if (p_dir[i] == 0) {
|
||||||
if ((p_from[i] < position[i]) || (p_from[i] > end[i])) {
|
if ((p_from[i] < position[i]) || (p_from[i] > end[i])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -346,71 +331,69 @@ bool AABB::intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r
|
||||||
c1[i] = (position[i] - p_from[i]) / p_dir[i];
|
c1[i] = (position[i] - p_from[i]) / p_dir[i];
|
||||||
c2[i] = (end[i] - p_from[i]) / p_dir[i];
|
c2[i] = (end[i] - p_from[i]) / p_dir[i];
|
||||||
|
|
||||||
if(c1[i] > c2[i]){
|
if (c1[i] > c2[i]) {
|
||||||
std::swap(c1,c2);
|
std::swap(c1, c2);
|
||||||
}
|
}
|
||||||
if (c1[i] > near){
|
if (c1[i] > near) {
|
||||||
near = c1[i];
|
near = c1[i];
|
||||||
axis=i;
|
axis = i;
|
||||||
}
|
}
|
||||||
if (c2[i] < far){
|
if (c2[i] < far) {
|
||||||
far = c2[i];
|
far = c2[i];
|
||||||
}
|
}
|
||||||
if( (near > far) || (far < 0) ){
|
if ((near > far) || (far < 0)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r_clip)
|
if (r_clip)
|
||||||
*r_clip=c1;
|
*r_clip = c1;
|
||||||
if (r_normal) {
|
if (r_normal) {
|
||||||
*r_normal=Vector3();
|
*r_normal = Vector3();
|
||||||
(*r_normal)[axis]=p_dir[axis]?-1:1;
|
(*r_normal)[axis] = p_dir[axis] ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip, Vector3 *r_normal) const {
|
||||||
|
|
||||||
bool AABB::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3* r_clip,Vector3* r_normal) const {
|
real_t min = 0, max = 1;
|
||||||
|
int axis = 0;
|
||||||
|
real_t sign = 0;
|
||||||
|
|
||||||
real_t min=0,max=1;
|
for (int i = 0; i < 3; i++) {
|
||||||
int axis=0;
|
real_t seg_from = p_from[i];
|
||||||
real_t sign=0;
|
real_t seg_to = p_to[i];
|
||||||
|
real_t box_begin = position[i];
|
||||||
for(int i=0;i<3;i++) {
|
real_t box_end = box_begin + size[i];
|
||||||
real_t seg_from=p_from[i];
|
real_t cmin, cmax;
|
||||||
real_t seg_to=p_to[i];
|
|
||||||
real_t box_begin=position[i];
|
|
||||||
real_t box_end=box_begin+size[i];
|
|
||||||
real_t cmin,cmax;
|
|
||||||
real_t csign;
|
real_t csign;
|
||||||
|
|
||||||
if (seg_from < seg_to) {
|
if (seg_from < seg_to) {
|
||||||
|
|
||||||
if (seg_from > box_end || seg_to < box_begin)
|
if (seg_from > box_end || seg_to < box_begin)
|
||||||
return false;
|
return false;
|
||||||
real_t length=seg_to-seg_from;
|
real_t length = seg_to - seg_from;
|
||||||
cmin = (seg_from < box_begin)?((box_begin - seg_from)/length):0;
|
cmin = (seg_from < box_begin) ? ((box_begin - seg_from) / length) : 0;
|
||||||
cmax = (seg_to > box_end)?((box_end - seg_from)/length):1;
|
cmax = (seg_to > box_end) ? ((box_end - seg_from) / length) : 1;
|
||||||
csign=-1.0;
|
csign = -1.0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (seg_to > box_end || seg_from < box_begin)
|
if (seg_to > box_end || seg_from < box_begin)
|
||||||
return false;
|
return false;
|
||||||
real_t length=seg_to-seg_from;
|
real_t length = seg_to - seg_from;
|
||||||
cmin = (seg_from > box_end)?(box_end - seg_from)/length:0;
|
cmin = (seg_from > box_end) ? (box_end - seg_from) / length : 0;
|
||||||
cmax = (seg_to < box_begin)?(box_begin - seg_from)/length:1;
|
cmax = (seg_to < box_begin) ? (box_begin - seg_from) / length : 1;
|
||||||
csign=1.0;
|
csign = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmin > min) {
|
if (cmin > min) {
|
||||||
min = cmin;
|
min = cmin;
|
||||||
axis=i;
|
axis = i;
|
||||||
sign=csign;
|
sign = csign;
|
||||||
}
|
}
|
||||||
if (cmax < max)
|
if (cmax < max)
|
||||||
max = cmax;
|
max = cmax;
|
||||||
|
@ -418,217 +401,207 @@ bool AABB::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3 rel = p_to - p_from;
|
||||||
Vector3 rel=p_to-p_from;
|
|
||||||
|
|
||||||
if (r_normal) {
|
if (r_normal) {
|
||||||
Vector3 normal;
|
Vector3 normal;
|
||||||
normal[axis]=sign;
|
normal[axis] = sign;
|
||||||
*r_normal=normal;
|
*r_normal = normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r_clip)
|
if (r_clip)
|
||||||
*r_clip=p_from+rel*min;
|
*r_clip = p_from + rel * min;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool AABB::intersects_plane(const Plane &p_plane) const {
|
bool AABB::intersects_plane(const Plane &p_plane) const {
|
||||||
|
|
||||||
Vector3 points[8] = {
|
Vector3 points[8] = {
|
||||||
Vector3( position.x , position.y , position.z ),
|
Vector3(position.x, position.y, position.z),
|
||||||
Vector3( position.x , position.y , position.z+size.z ),
|
Vector3(position.x, position.y, position.z + size.z),
|
||||||
Vector3( position.x , position.y+size.y , position.z ),
|
Vector3(position.x, position.y + size.y, position.z),
|
||||||
Vector3( position.x , position.y+size.y , position.z+size.z ),
|
Vector3(position.x, position.y + size.y, position.z + size.z),
|
||||||
Vector3( position.x+size.x , position.y , position.z ),
|
Vector3(position.x + size.x, position.y, position.z),
|
||||||
Vector3( position.x+size.x , position.y , position.z+size.z ),
|
Vector3(position.x + size.x, position.y, position.z + size.z),
|
||||||
Vector3( position.x+size.x , position.y+size.y , position.z ),
|
Vector3(position.x + size.x, position.y + size.y, position.z),
|
||||||
Vector3( position.x+size.x , position.y+size.y , position.z+size.z ),
|
Vector3(position.x + size.x, position.y + size.y, position.z + size.z),
|
||||||
};
|
};
|
||||||
|
|
||||||
bool over=false;
|
bool over = false;
|
||||||
bool under=false;
|
bool under = false;
|
||||||
|
|
||||||
for (int i=0;i<8;i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
|
|
||||||
if (p_plane.distance_to(points[i])>0)
|
if (p_plane.distance_to(points[i]) > 0)
|
||||||
over=true;
|
over = true;
|
||||||
else
|
else
|
||||||
under=true;
|
under = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return under && over;
|
return under && over;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Vector3 AABB::get_longest_axis() const {
|
Vector3 AABB::get_longest_axis() const {
|
||||||
|
|
||||||
Vector3 axis(1,0,0);
|
Vector3 axis(1, 0, 0);
|
||||||
real_t max_size=size.x;
|
real_t max_size = size.x;
|
||||||
|
|
||||||
if (size.y > max_size ) {
|
if (size.y > max_size) {
|
||||||
axis=Vector3(0,1,0);
|
axis = Vector3(0, 1, 0);
|
||||||
max_size=size.y;
|
max_size = size.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size.z > max_size ) {
|
if (size.z > max_size) {
|
||||||
axis=Vector3(0,0,1);
|
axis = Vector3(0, 0, 1);
|
||||||
max_size=size.z;
|
max_size = size.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
return axis;
|
return axis;
|
||||||
}
|
}
|
||||||
int AABB::get_longest_axis_index() const {
|
int AABB::get_longest_axis_index() const {
|
||||||
|
|
||||||
int axis=0;
|
int axis = 0;
|
||||||
real_t max_size=size.x;
|
real_t max_size = size.x;
|
||||||
|
|
||||||
if (size.y > max_size ) {
|
if (size.y > max_size) {
|
||||||
axis=1;
|
axis = 1;
|
||||||
max_size=size.y;
|
max_size = size.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size.z > max_size ) {
|
if (size.z > max_size) {
|
||||||
axis=2;
|
axis = 2;
|
||||||
max_size=size.z;
|
max_size = size.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
return axis;
|
return axis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Vector3 AABB::get_shortest_axis() const {
|
Vector3 AABB::get_shortest_axis() const {
|
||||||
|
|
||||||
Vector3 axis(1,0,0);
|
Vector3 axis(1, 0, 0);
|
||||||
real_t max_size=size.x;
|
real_t max_size = size.x;
|
||||||
|
|
||||||
if (size.y < max_size ) {
|
if (size.y < max_size) {
|
||||||
axis=Vector3(0,1,0);
|
axis = Vector3(0, 1, 0);
|
||||||
max_size=size.y;
|
max_size = size.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size.z < max_size ) {
|
if (size.z < max_size) {
|
||||||
axis=Vector3(0,0,1);
|
axis = Vector3(0, 0, 1);
|
||||||
max_size=size.z;
|
max_size = size.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
return axis;
|
return axis;
|
||||||
}
|
}
|
||||||
int AABB::get_shortest_axis_index() const {
|
int AABB::get_shortest_axis_index() const {
|
||||||
|
|
||||||
int axis=0;
|
int axis = 0;
|
||||||
real_t max_size=size.x;
|
real_t max_size = size.x;
|
||||||
|
|
||||||
if (size.y < max_size ) {
|
if (size.y < max_size) {
|
||||||
axis=1;
|
axis = 1;
|
||||||
max_size=size.y;
|
max_size = size.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size.z < max_size ) {
|
if (size.z < max_size) {
|
||||||
axis=2;
|
axis = 2;
|
||||||
max_size=size.z;
|
max_size = size.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
return axis;
|
return axis;
|
||||||
}
|
}
|
||||||
|
|
||||||
AABB AABB::merge(const AABB& p_with) const {
|
AABB AABB::merge(const AABB &p_with) const {
|
||||||
|
|
||||||
AABB aabb=*this;
|
AABB aabb = *this;
|
||||||
aabb.merge_with(p_with);
|
aabb.merge_with(p_with);
|
||||||
return aabb;
|
return aabb;
|
||||||
}
|
}
|
||||||
AABB AABB::expand(const Vector3& p_vector) const {
|
AABB AABB::expand(const Vector3 &p_vector) const {
|
||||||
AABB aabb=*this;
|
AABB aabb = *this;
|
||||||
aabb.expand_to(p_vector);
|
aabb.expand_to(p_vector);
|
||||||
return aabb;
|
return aabb;
|
||||||
|
|
||||||
}
|
}
|
||||||
AABB AABB::grow(real_t p_by) const {
|
AABB AABB::grow(real_t p_by) const {
|
||||||
|
|
||||||
AABB aabb=*this;
|
AABB aabb = *this;
|
||||||
aabb.grow_by(p_by);
|
aabb.grow_by(p_by);
|
||||||
return aabb;
|
return aabb;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AABB::get_edge(int p_edge,Vector3& r_from,Vector3& r_to) const {
|
void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
|
||||||
|
|
||||||
ERR_FAIL_INDEX(p_edge,12);
|
ERR_FAIL_INDEX(p_edge, 12);
|
||||||
switch(p_edge) {
|
switch (p_edge) {
|
||||||
|
|
||||||
case 0:{
|
case 0: {
|
||||||
|
|
||||||
r_from=Vector3( position.x+size.x , position.y , position.z );
|
r_from = Vector3(position.x + size.x, position.y, position.z);
|
||||||
r_to=Vector3( position.x , position.y , position.z );
|
r_to = Vector3(position.x, position.y, position.z);
|
||||||
} break;
|
} break;
|
||||||
case 1:{
|
case 1: {
|
||||||
|
|
||||||
r_from=Vector3( position.x+size.x , position.y , position.z+size.z );
|
r_from = Vector3(position.x + size.x, position.y, position.z + size.z);
|
||||||
r_to=Vector3( position.x+size.x , position.y , position.z );
|
r_to = Vector3(position.x + size.x, position.y, position.z);
|
||||||
} break;
|
} break;
|
||||||
case 2:{
|
case 2: {
|
||||||
r_from=Vector3( position.x , position.y , position.z+size.z );
|
r_from = Vector3(position.x, position.y, position.z + size.z);
|
||||||
r_to=Vector3( position.x+size.x , position.y , position.z+size.z );
|
r_to = Vector3(position.x + size.x, position.y, position.z + size.z);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case 3:{
|
case 3: {
|
||||||
|
|
||||||
r_from=Vector3( position.x , position.y , position.z );
|
r_from = Vector3(position.x, position.y, position.z);
|
||||||
r_to=Vector3( position.x , position.y , position.z+size.z );
|
r_to = Vector3(position.x, position.y, position.z + size.z);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case 4:{
|
case 4: {
|
||||||
|
|
||||||
r_from=Vector3( position.x , position.y+size.y , position.z );
|
r_from = Vector3(position.x, position.y + size.y, position.z);
|
||||||
r_to=Vector3( position.x+size.x , position.y+size.y , position.z );
|
r_to = Vector3(position.x + size.x, position.y + size.y, position.z);
|
||||||
} break;
|
} break;
|
||||||
case 5:{
|
case 5: {
|
||||||
|
|
||||||
r_from=Vector3( position.x+size.x , position.y+size.y , position.z );
|
r_from = Vector3(position.x + size.x, position.y + size.y, position.z);
|
||||||
r_to=Vector3( position.x+size.x , position.y+size.y , position.z+size.z );
|
r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
|
||||||
} break;
|
} break;
|
||||||
case 6:{
|
case 6: {
|
||||||
r_from=Vector3( position.x+size.x , position.y+size.y , position.z+size.z );
|
r_from = Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
|
||||||
r_to=Vector3( position.x , position.y+size.y , position.z+size.z );
|
r_to = Vector3(position.x, position.y + size.y, position.z + size.z);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case 7:{
|
case 7: {
|
||||||
|
|
||||||
r_from=Vector3( position.x , position.y+size.y , position.z+size.z );
|
r_from = Vector3(position.x, position.y + size.y, position.z + size.z);
|
||||||
r_to=Vector3( position.x , position.y+size.y , position.z );
|
r_to = Vector3(position.x, position.y + size.y, position.z);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case 8:{
|
case 8: {
|
||||||
|
|
||||||
r_from=Vector3( position.x , position.y , position.z+size.z );
|
r_from = Vector3(position.x, position.y, position.z + size.z);
|
||||||
r_to=Vector3( position.x , position.y+size.y , position.z+size.z );
|
r_to = Vector3(position.x, position.y + size.y, position.z + size.z);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case 9:{
|
case 9: {
|
||||||
|
|
||||||
r_from=Vector3( position.x , position.y , position.z );
|
r_from = Vector3(position.x, position.y, position.z);
|
||||||
r_to=Vector3( position.x , position.y+size.y , position.z );
|
r_to = Vector3(position.x, position.y + size.y, position.z);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case 10:{
|
case 10: {
|
||||||
|
|
||||||
r_from=Vector3( position.x+size.x , position.y , position.z );
|
r_from = Vector3(position.x + size.x, position.y, position.z);
|
||||||
r_to=Vector3( position.x+size.x , position.y+size.y , position.z );
|
r_to = Vector3(position.x + size.x, position.y + size.y, position.z);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case 11:{
|
case 11: {
|
||||||
|
|
||||||
r_from=Vector3( position.x+size.x , position.y , position.z+size.z );
|
r_from = Vector3(position.x + size.x, position.y, position.z + size.z);
|
||||||
r_to=Vector3( position.x+size.x , position.y+size.y , position.z+size.z );
|
r_to = Vector3(position.x + size.x, position.y + size.y, position.z + size.z);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AABB::operator String() const {
|
AABB::operator String() const {
|
||||||
|
@ -636,4 +609,4 @@ AABB::operator String() const {
|
||||||
return String() + position + " - " + size;
|
return String() + position + " - " + size;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "Array.hpp"
|
#include "Array.hpp"
|
||||||
#include "Variant.hpp"
|
|
||||||
#include "GodotGlobal.hpp"
|
#include "GodotGlobal.hpp"
|
||||||
|
#include "Variant.hpp"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
@ -8,194 +8,158 @@ namespace godot {
|
||||||
|
|
||||||
class Object;
|
class Object;
|
||||||
|
|
||||||
Array::Array()
|
Array::Array() {
|
||||||
{
|
|
||||||
godot::api->godot_array_new(&_godot_array);
|
godot::api->godot_array_new(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Array(const Array & other)
|
Array::Array(const Array &other) {
|
||||||
{
|
|
||||||
godot::api->godot_array_new_copy(&_godot_array, &other._godot_array);
|
godot::api->godot_array_new_copy(&_godot_array, &other._godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
Array & Array::operator=(const Array & other)
|
Array &Array::operator=(const Array &other) {
|
||||||
{
|
|
||||||
godot::api->godot_array_destroy(&_godot_array);
|
godot::api->godot_array_destroy(&_godot_array);
|
||||||
godot::api->godot_array_new_copy(&_godot_array, &other._godot_array);
|
godot::api->godot_array_new_copy(&_godot_array, &other._godot_array);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Array(const PoolByteArray& a)
|
Array::Array(const PoolByteArray &a) {
|
||||||
{
|
godot::api->godot_array_new_pool_byte_array(&_godot_array, (godot_pool_byte_array *)&a);
|
||||||
godot::api->godot_array_new_pool_byte_array(&_godot_array, (godot_pool_byte_array *) &a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Array(const PoolIntArray& a)
|
Array::Array(const PoolIntArray &a) {
|
||||||
{
|
godot::api->godot_array_new_pool_int_array(&_godot_array, (godot_pool_int_array *)&a);
|
||||||
godot::api->godot_array_new_pool_int_array(&_godot_array, (godot_pool_int_array *) &a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Array(const PoolRealArray& a)
|
Array::Array(const PoolRealArray &a) {
|
||||||
{
|
godot::api->godot_array_new_pool_real_array(&_godot_array, (godot_pool_real_array *)&a);
|
||||||
godot::api->godot_array_new_pool_real_array(&_godot_array, (godot_pool_real_array *) &a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Array(const PoolStringArray& a)
|
Array::Array(const PoolStringArray &a) {
|
||||||
{
|
godot::api->godot_array_new_pool_string_array(&_godot_array, (godot_pool_string_array *)&a);
|
||||||
godot::api->godot_array_new_pool_string_array(&_godot_array, (godot_pool_string_array *) &a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Array(const PoolVector2Array& a)
|
Array::Array(const PoolVector2Array &a) {
|
||||||
{
|
godot::api->godot_array_new_pool_vector2_array(&_godot_array, (godot_pool_vector2_array *)&a);
|
||||||
godot::api->godot_array_new_pool_vector2_array(&_godot_array, (godot_pool_vector2_array *) &a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Array(const PoolVector3Array& a)
|
Array::Array(const PoolVector3Array &a) {
|
||||||
{
|
godot::api->godot_array_new_pool_vector3_array(&_godot_array, (godot_pool_vector3_array *)&a);
|
||||||
godot::api->godot_array_new_pool_vector3_array(&_godot_array, (godot_pool_vector3_array *) &a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Array(const PoolColorArray& a)
|
Array::Array(const PoolColorArray &a) {
|
||||||
{
|
godot::api->godot_array_new_pool_color_array(&_godot_array, (godot_pool_color_array *)&a);
|
||||||
godot::api->godot_array_new_pool_color_array(&_godot_array, (godot_pool_color_array *) &a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant& Array::operator [](const int idx)
|
Variant &Array::operator[](const int idx) {
|
||||||
{
|
|
||||||
godot_variant *v = godot::api->godot_array_operator_index(&_godot_array, idx);
|
godot_variant *v = godot::api->godot_array_operator_index(&_godot_array, idx);
|
||||||
return *(Variant *) v;
|
return *(Variant *)v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant Array::operator [](const int idx) const
|
Variant Array::operator[](const int idx) const {
|
||||||
{
|
|
||||||
// Yes, I'm casting away the const... you can hate me now.
|
// Yes, I'm casting away the const... you can hate me now.
|
||||||
// since the result is
|
// since the result is
|
||||||
godot_variant *v = godot::api->godot_array_operator_index((godot_array *) &_godot_array, idx);
|
godot_variant *v = godot::api->godot_array_operator_index((godot_array *)&_godot_array, idx);
|
||||||
return *(Variant *) v;
|
return *(Variant *)v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Array::append(const Variant& v)
|
void Array::append(const Variant &v) {
|
||||||
{
|
godot::api->godot_array_append(&_godot_array, (godot_variant *)&v);
|
||||||
godot::api->godot_array_append(&_godot_array, (godot_variant *) &v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Array::clear()
|
void Array::clear() {
|
||||||
{
|
|
||||||
godot::api->godot_array_clear(&_godot_array);
|
godot::api->godot_array_clear(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Array::count(const Variant& v)
|
int Array::count(const Variant &v) {
|
||||||
{
|
return godot::api->godot_array_count(&_godot_array, (godot_variant *)&v);
|
||||||
return godot::api->godot_array_count(&_godot_array, (godot_variant *) &v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Array::empty() const
|
bool Array::empty() const {
|
||||||
{
|
|
||||||
return godot::api->godot_array_empty(&_godot_array);
|
return godot::api->godot_array_empty(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Array::erase(const Variant& v)
|
void Array::erase(const Variant &v) {
|
||||||
{
|
godot::api->godot_array_erase(&_godot_array, (godot_variant *)&v);
|
||||||
godot::api->godot_array_erase(&_godot_array, (godot_variant *) &v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant Array::front() const
|
Variant Array::front() const {
|
||||||
{
|
|
||||||
godot_variant v = godot::api->godot_array_front(&_godot_array);
|
godot_variant v = godot::api->godot_array_front(&_godot_array);
|
||||||
return *(Variant *) &v;
|
return *(Variant *)&v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant Array::back() const
|
Variant Array::back() const {
|
||||||
{
|
|
||||||
godot_variant v = godot::api->godot_array_back(&_godot_array);
|
godot_variant v = godot::api->godot_array_back(&_godot_array);
|
||||||
return *(Variant *) &v;
|
return *(Variant *)&v;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Array::find(const Variant& what, const int from)
|
int Array::find(const Variant &what, const int from) {
|
||||||
{
|
return godot::api->godot_array_find(&_godot_array, (godot_variant *)&what, from);
|
||||||
return godot::api->godot_array_find(&_godot_array, (godot_variant *) &what, from);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Array::find_last(const Variant& what)
|
int Array::find_last(const Variant &what) {
|
||||||
{
|
return godot::api->godot_array_find_last(&_godot_array, (godot_variant *)&what);
|
||||||
return godot::api->godot_array_find_last(&_godot_array, (godot_variant *) &what);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Array::has(const Variant& what) const
|
bool Array::has(const Variant &what) const {
|
||||||
{
|
return godot::api->godot_array_has(&_godot_array, (godot_variant *)&what);
|
||||||
return godot::api->godot_array_has(&_godot_array, (godot_variant *) &what);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Array::hash() const
|
uint32_t Array::hash() const {
|
||||||
{
|
|
||||||
return godot::api->godot_array_hash(&_godot_array);
|
return godot::api->godot_array_hash(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Array::insert(const int pos, const Variant& value)
|
void Array::insert(const int pos, const Variant &value) {
|
||||||
{
|
godot::api->godot_array_insert(&_godot_array, pos, (godot_variant *)&value);
|
||||||
godot::api->godot_array_insert(&_godot_array, pos, (godot_variant *) &value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Array::invert()
|
void Array::invert() {
|
||||||
{
|
|
||||||
godot::api->godot_array_invert(&_godot_array);
|
godot::api->godot_array_invert(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant Array::pop_back()
|
Variant Array::pop_back() {
|
||||||
{
|
|
||||||
godot_variant v = godot::api->godot_array_pop_back(&_godot_array);
|
godot_variant v = godot::api->godot_array_pop_back(&_godot_array);
|
||||||
return *(Variant *) &v;
|
return *(Variant *)&v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant Array::pop_front()
|
Variant Array::pop_front() {
|
||||||
{
|
|
||||||
godot_variant v = godot::api->godot_array_pop_front(&_godot_array);
|
godot_variant v = godot::api->godot_array_pop_front(&_godot_array);
|
||||||
return *(Variant *) &v;
|
return *(Variant *)&v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Array::push_back(const Variant& v)
|
void Array::push_back(const Variant &v) {
|
||||||
{
|
godot::api->godot_array_push_back(&_godot_array, (godot_variant *)&v);
|
||||||
godot::api->godot_array_push_back(&_godot_array, (godot_variant *) &v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Array::push_front(const Variant& v)
|
void Array::push_front(const Variant &v) {
|
||||||
{
|
godot::api->godot_array_push_front(&_godot_array, (godot_variant *)&v);
|
||||||
godot::api->godot_array_push_front(&_godot_array, (godot_variant *) &v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Array::remove(const int idx)
|
void Array::remove(const int idx) {
|
||||||
{
|
|
||||||
godot::api->godot_array_remove(&_godot_array, idx);
|
godot::api->godot_array_remove(&_godot_array, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Array::size() const
|
int Array::size() const {
|
||||||
{
|
|
||||||
return godot::api->godot_array_size(&_godot_array);
|
return godot::api->godot_array_size(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Array::resize(const int size)
|
void Array::resize(const int size) {
|
||||||
{
|
|
||||||
godot::api->godot_array_resize(&_godot_array, size);
|
godot::api->godot_array_resize(&_godot_array, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Array::rfind(const Variant& what, const int from)
|
int Array::rfind(const Variant &what, const int from) {
|
||||||
{
|
return godot::api->godot_array_rfind(&_godot_array, (godot_variant *)&what, from);
|
||||||
return godot::api->godot_array_rfind(&_godot_array, (godot_variant *) &what, from);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Array::sort()
|
void Array::sort() {
|
||||||
{
|
|
||||||
godot::api->godot_array_sort(&_godot_array);
|
godot::api->godot_array_sort(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Array::sort_custom(Object *obj, const String& func)
|
void Array::sort_custom(Object *obj, const String &func) {
|
||||||
{
|
godot::api->godot_array_sort_custom(&_godot_array, (godot_object *)obj, (godot_string *)&func);
|
||||||
godot::api->godot_array_sort_custom(&_godot_array, (godot_object *) obj, (godot_string *) &func);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::~Array()
|
Array::~Array() {
|
||||||
{
|
|
||||||
godot::api->godot_array_destroy(&_godot_array);
|
godot::api->godot_array_destroy(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
#include "Basis.hpp"
|
#include "Basis.hpp"
|
||||||
#include "Defs.hpp"
|
#include "Defs.hpp"
|
||||||
#include "Vector3.hpp"
|
|
||||||
#include "Quat.hpp"
|
#include "Quat.hpp"
|
||||||
|
#include "Vector3.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
|
Basis::Basis(const Vector3 &row0, const Vector3 &row1, const Vector3 &row2) {
|
||||||
Basis::Basis(const Vector3& row0, const Vector3& row1, const Vector3& row2)
|
elements[0] = row0;
|
||||||
{
|
elements[1] = row1;
|
||||||
elements[0]=row0;
|
elements[2] = row2;
|
||||||
elements[1]=row1;
|
|
||||||
elements[2]=row2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis::Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
|
Basis::Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
|
||||||
|
@ -22,58 +20,52 @@ Basis::Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, r
|
||||||
|
|
||||||
Basis::Basis() {
|
Basis::Basis() {
|
||||||
|
|
||||||
elements[0][0]=1;
|
elements[0][0] = 1;
|
||||||
elements[0][1]=0;
|
elements[0][1] = 0;
|
||||||
elements[0][2]=0;
|
elements[0][2] = 0;
|
||||||
elements[1][0]=0;
|
elements[1][0] = 0;
|
||||||
elements[1][1]=1;
|
elements[1][1] = 1;
|
||||||
elements[1][2]=0;
|
elements[1][2] = 0;
|
||||||
elements[2][0]=0;
|
elements[2][0] = 0;
|
||||||
elements[2][1]=0;
|
elements[2][1] = 0;
|
||||||
elements[2][2]=1;
|
elements[2][2] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Vector3 &Basis::operator[](int axis) const {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const Vector3& Basis::operator[](int axis) const {
|
|
||||||
|
|
||||||
return elements[axis];
|
return elements[axis];
|
||||||
}
|
}
|
||||||
Vector3&Basis:: operator[](int axis) {
|
Vector3 &Basis::operator[](int axis) {
|
||||||
|
|
||||||
return elements[axis];
|
return elements[axis];
|
||||||
}
|
}
|
||||||
|
|
||||||
#define cofac(row1,col1, row2, col2)\
|
#define cofac(row1, col1, row2, col2) \
|
||||||
(elements[row1][col1] * elements[row2][col2] - elements[row1][col2] * elements[row2][col1])
|
(elements[row1][col1] * elements[row2][col2] - elements[row1][col2] * elements[row2][col1])
|
||||||
|
|
||||||
void Basis::invert()
|
void Basis::invert() {
|
||||||
{
|
real_t co[3] = {
|
||||||
real_t co[3]={
|
|
||||||
cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1)
|
cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1)
|
||||||
};
|
};
|
||||||
real_t det = elements[0][0] * co[0]+
|
real_t det = elements[0][0] * co[0] +
|
||||||
elements[0][1] * co[1]+
|
elements[0][1] * co[1] +
|
||||||
elements[0][2] * co[2];
|
elements[0][2] * co[2];
|
||||||
|
|
||||||
|
|
||||||
ERR_FAIL_COND(det == 0);
|
ERR_FAIL_COND(det == 0);
|
||||||
|
|
||||||
real_t s = 1.0/det;
|
real_t s = 1.0 / det;
|
||||||
|
|
||||||
set( co[0]*s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s,
|
set(co[0] * s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s,
|
||||||
co[1]*s, cofac(0, 0, 2, 2) * s, cofac(0, 2, 1, 0) * s,
|
co[1] * s, cofac(0, 0, 2, 2) * s, cofac(0, 2, 1, 0) * s,
|
||||||
co[2]*s, cofac(0, 1, 2, 0) * s, cofac(0, 0, 1, 1) * s );
|
co[2] * s, cofac(0, 1, 2, 0) * s, cofac(0, 0, 1, 1) * s);
|
||||||
}
|
}
|
||||||
#undef cofac
|
#undef cofac
|
||||||
|
|
||||||
bool Basis::isequal_approx(const Basis& a, const Basis& b) const {
|
bool Basis::isequal_approx(const Basis &a, const Basis &b) const {
|
||||||
|
|
||||||
for (int i=0;i<3;i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
for (int j=0;j<3;j++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
if ((::fabs(a.elements[i][j]-b.elements[i][j]) < CMP_EPSILON) == false)
|
if ((::fabs(a.elements[i][j] - b.elements[i][j]) < CMP_EPSILON) == false)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,102 +73,89 @@ bool Basis::isequal_approx(const Basis& a, const Basis& b) const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Basis::is_orthogonal() const {
|
||||||
bool Basis::is_orthogonal() const
|
|
||||||
{
|
|
||||||
Basis id;
|
Basis id;
|
||||||
Basis m = (*this)*transposed();
|
Basis m = (*this) * transposed();
|
||||||
|
|
||||||
return isequal_approx(id,m);
|
return isequal_approx(id, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Basis::is_rotation() const
|
bool Basis::is_rotation() const {
|
||||||
{
|
return ::fabs(determinant() - 1) < CMP_EPSILON && is_orthogonal();
|
||||||
return ::fabs(determinant()-1) < CMP_EPSILON && is_orthogonal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Basis::transpose()
|
void Basis::transpose() {
|
||||||
{
|
std::swap(elements[0][1], elements[1][0]);
|
||||||
std::swap(elements[0][1],elements[1][0]);
|
std::swap(elements[0][2], elements[2][0]);
|
||||||
std::swap(elements[0][2],elements[2][0]);
|
std::swap(elements[1][2], elements[2][1]);
|
||||||
std::swap(elements[1][2],elements[2][1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis Basis::inverse() const
|
Basis Basis::inverse() const {
|
||||||
{
|
|
||||||
Basis b = *this;
|
Basis b = *this;
|
||||||
b.invert();
|
b.invert();
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis Basis::transposed() const
|
Basis Basis::transposed() const {
|
||||||
{
|
|
||||||
Basis b = *this;
|
Basis b = *this;
|
||||||
b.transpose();
|
b.transpose();
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Basis::determinant() const
|
real_t Basis::determinant() const {
|
||||||
{
|
return elements[0][0] * (elements[1][1] * elements[2][2] - elements[2][1] * elements[1][2]) -
|
||||||
return elements[0][0]*(elements[1][1]*elements[2][2] - elements[2][1]*elements[1][2]) -
|
elements[1][0] * (elements[0][1] * elements[2][2] - elements[2][1] * elements[0][2]) +
|
||||||
elements[1][0]*(elements[0][1]*elements[2][2] - elements[2][1]*elements[0][2]) +
|
elements[2][0] * (elements[0][1] * elements[1][2] - elements[1][1] * elements[0][2]);
|
||||||
elements[2][0]*(elements[0][1]*elements[1][2] - elements[1][1]*elements[0][2]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Basis::get_axis(int p_axis) const {
|
Vector3 Basis::get_axis(int p_axis) const {
|
||||||
// get actual basis axis (elements is transposed for performance)
|
// get actual basis axis (elements is transposed for performance)
|
||||||
return Vector3( elements[0][p_axis], elements[1][p_axis], elements[2][p_axis] );
|
return Vector3(elements[0][p_axis], elements[1][p_axis], elements[2][p_axis]);
|
||||||
}
|
}
|
||||||
void Basis::set_axis(int p_axis, const Vector3& p_value) {
|
void Basis::set_axis(int p_axis, const Vector3 &p_value) {
|
||||||
// get actual basis axis (elements is transposed for performance)
|
// get actual basis axis (elements is transposed for performance)
|
||||||
elements[0][p_axis]=p_value.x;
|
elements[0][p_axis] = p_value.x;
|
||||||
elements[1][p_axis]=p_value.y;
|
elements[1][p_axis] = p_value.y;
|
||||||
elements[2][p_axis]=p_value.z;
|
elements[2][p_axis] = p_value.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Basis::rotate(const Vector3& p_axis, real_t p_phi)
|
void Basis::rotate(const Vector3 &p_axis, real_t p_phi) {
|
||||||
{
|
|
||||||
*this = rotated(p_axis, p_phi);
|
*this = rotated(p_axis, p_phi);
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis Basis::rotated(const Vector3& p_axis, real_t p_phi) const
|
Basis Basis::rotated(const Vector3 &p_axis, real_t p_phi) const {
|
||||||
{
|
|
||||||
return Basis(p_axis, p_phi) * (*this);
|
return Basis(p_axis, p_phi) * (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Basis::scale( const Vector3& p_scale )
|
void Basis::scale(const Vector3 &p_scale) {
|
||||||
{
|
elements[0][0] *= p_scale.x;
|
||||||
elements[0][0]*=p_scale.x;
|
elements[0][1] *= p_scale.x;
|
||||||
elements[0][1]*=p_scale.x;
|
elements[0][2] *= p_scale.x;
|
||||||
elements[0][2]*=p_scale.x;
|
elements[1][0] *= p_scale.y;
|
||||||
elements[1][0]*=p_scale.y;
|
elements[1][1] *= p_scale.y;
|
||||||
elements[1][1]*=p_scale.y;
|
elements[1][2] *= p_scale.y;
|
||||||
elements[1][2]*=p_scale.y;
|
elements[2][0] *= p_scale.z;
|
||||||
elements[2][0]*=p_scale.z;
|
elements[2][1] *= p_scale.z;
|
||||||
elements[2][1]*=p_scale.z;
|
elements[2][2] *= p_scale.z;
|
||||||
elements[2][2]*=p_scale.z;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis Basis::scaled( const Vector3& p_scale ) const
|
Basis Basis::scaled(const Vector3 &p_scale) const {
|
||||||
{
|
|
||||||
Basis b = *this;
|
Basis b = *this;
|
||||||
b.scale(p_scale);
|
b.scale(p_scale);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Basis::get_scale() const
|
Vector3 Basis::get_scale() const {
|
||||||
{
|
|
||||||
// We are assuming M = R.S, and performing a polar decomposition to extract R and S.
|
// We are assuming M = R.S, and performing a polar decomposition to extract R and S.
|
||||||
// FIXME: We eventually need a proper polar decomposition.
|
// FIXME: We eventually need a proper polar decomposition.
|
||||||
// As a cheap workaround until then, to ensure that R is a proper rotation matrix with determinant +1
|
// As a cheap workaround until then, to ensure that R is a proper rotation matrix with determinant +1
|
||||||
// (such that it can be represented by a Quat or Euler angles), we absorb the sign flip into the scaling matrix.
|
// (such that it can be represented by a Quat or Euler angles), we absorb the sign flip into the scaling matrix.
|
||||||
// As such, it works in conjuction with get_rotation().
|
// As such, it works in conjuction with get_rotation().
|
||||||
real_t det_sign = determinant() > 0 ? 1 : -1;
|
real_t det_sign = determinant() > 0 ? 1 : -1;
|
||||||
return det_sign*Vector3(
|
return det_sign * Vector3(
|
||||||
Vector3(elements[0][0],elements[1][0],elements[2][0]).length(),
|
Vector3(elements[0][0], elements[1][0], elements[2][0]).length(),
|
||||||
Vector3(elements[0][1],elements[1][1],elements[2][1]).length(),
|
Vector3(elements[0][1], elements[1][1], elements[2][1]).length(),
|
||||||
Vector3(elements[0][2],elements[1][2],elements[2][2]).length()
|
Vector3(elements[0][2], elements[1][2], elements[2][2]).length());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get_euler_xyz returns a vector containing the Euler angles in the format
|
// get_euler_xyz returns a vector containing the Euler angles in the format
|
||||||
|
@ -322,23 +301,20 @@ void Basis::set_euler_yxz(const Vector3 &p_euler) {
|
||||||
*this = ymat * xmat * zmat;
|
*this = ymat * xmat * zmat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// transposed dot products
|
// transposed dot products
|
||||||
real_t Basis::tdotx(const Vector3& v) const {
|
real_t Basis::tdotx(const Vector3 &v) const {
|
||||||
return elements[0][0] * v[0] + elements[1][0] * v[1] + elements[2][0] * v[2];
|
return elements[0][0] * v[0] + elements[1][0] * v[1] + elements[2][0] * v[2];
|
||||||
}
|
}
|
||||||
real_t Basis::tdoty(const Vector3& v) const {
|
real_t Basis::tdoty(const Vector3 &v) const {
|
||||||
return elements[0][1] * v[0] + elements[1][1] * v[1] + elements[2][1] * v[2];
|
return elements[0][1] * v[0] + elements[1][1] * v[1] + elements[2][1] * v[2];
|
||||||
}
|
}
|
||||||
real_t Basis::tdotz(const Vector3& v) const {
|
real_t Basis::tdotz(const Vector3 &v) const {
|
||||||
return elements[0][2] * v[0] + elements[1][2] * v[1] + elements[2][2] * v[2];
|
return elements[0][2] * v[0] + elements[1][2] * v[1] + elements[2][2] * v[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Basis::operator==(const Basis& p_matrix) const
|
bool Basis::operator==(const Basis &p_matrix) const {
|
||||||
{
|
for (int i = 0; i < 3; i++) {
|
||||||
for (int i=0;i<3;i++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
for (int j=0;j<3;j++) {
|
|
||||||
if (elements[i][j] != p_matrix.elements[i][j])
|
if (elements[i][j] != p_matrix.elements[i][j])
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -347,69 +323,61 @@ bool Basis::operator==(const Basis& p_matrix) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Basis::operator!=(const Basis& p_matrix) const
|
bool Basis::operator!=(const Basis &p_matrix) const {
|
||||||
{
|
return (!(*this == p_matrix));
|
||||||
return (!(*this==p_matrix));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Basis::xform(const Vector3& p_vector) const {
|
Vector3 Basis::xform(const Vector3 &p_vector) const {
|
||||||
|
|
||||||
return Vector3(
|
return Vector3(
|
||||||
elements[0].dot(p_vector),
|
elements[0].dot(p_vector),
|
||||||
elements[1].dot(p_vector),
|
elements[1].dot(p_vector),
|
||||||
elements[2].dot(p_vector)
|
elements[2].dot(p_vector));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Basis::xform_inv(const Vector3& p_vector) const {
|
Vector3 Basis::xform_inv(const Vector3 &p_vector) const {
|
||||||
|
|
||||||
return Vector3(
|
return Vector3(
|
||||||
(elements[0][0]*p_vector.x ) + ( elements[1][0]*p_vector.y ) + ( elements[2][0]*p_vector.z ),
|
(elements[0][0] * p_vector.x) + (elements[1][0] * p_vector.y) + (elements[2][0] * p_vector.z),
|
||||||
(elements[0][1]*p_vector.x ) + ( elements[1][1]*p_vector.y ) + ( elements[2][1]*p_vector.z ),
|
(elements[0][1] * p_vector.x) + (elements[1][1] * p_vector.y) + (elements[2][1] * p_vector.z),
|
||||||
(elements[0][2]*p_vector.x ) + ( elements[1][2]*p_vector.y ) + ( elements[2][2]*p_vector.z )
|
(elements[0][2] * p_vector.x) + (elements[1][2] * p_vector.y) + (elements[2][2] * p_vector.z));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
void Basis::operator*=(const Basis& p_matrix)
|
void Basis::operator*=(const Basis &p_matrix) {
|
||||||
{
|
|
||||||
set(
|
set(
|
||||||
p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]),
|
p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]),
|
||||||
p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]),
|
p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]),
|
||||||
p_matrix.tdotx(elements[2]), p_matrix.tdoty(elements[2]), p_matrix.tdotz(elements[2]));
|
p_matrix.tdotx(elements[2]), p_matrix.tdoty(elements[2]), p_matrix.tdotz(elements[2]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis Basis::operator*(const Basis& p_matrix) const
|
Basis Basis::operator*(const Basis &p_matrix) const {
|
||||||
{
|
|
||||||
return Basis(
|
return Basis(
|
||||||
p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]),
|
p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]),
|
||||||
p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]),
|
p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]),
|
||||||
p_matrix.tdotx(elements[2]), p_matrix.tdoty(elements[2]), p_matrix.tdotz(elements[2]) );
|
p_matrix.tdotx(elements[2]), p_matrix.tdoty(elements[2]), p_matrix.tdotz(elements[2]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Basis::operator+=(const Basis &p_matrix) {
|
||||||
void Basis::operator+=(const Basis& p_matrix) {
|
|
||||||
|
|
||||||
elements[0] += p_matrix.elements[0];
|
elements[0] += p_matrix.elements[0];
|
||||||
elements[1] += p_matrix.elements[1];
|
elements[1] += p_matrix.elements[1];
|
||||||
elements[2] += p_matrix.elements[2];
|
elements[2] += p_matrix.elements[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis Basis::operator+(const Basis& p_matrix) const {
|
Basis Basis::operator+(const Basis &p_matrix) const {
|
||||||
|
|
||||||
Basis ret(*this);
|
Basis ret(*this);
|
||||||
ret += p_matrix;
|
ret += p_matrix;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Basis::operator-=(const Basis& p_matrix) {
|
void Basis::operator-=(const Basis &p_matrix) {
|
||||||
|
|
||||||
elements[0] -= p_matrix.elements[0];
|
elements[0] -= p_matrix.elements[0];
|
||||||
elements[1] -= p_matrix.elements[1];
|
elements[1] -= p_matrix.elements[1];
|
||||||
elements[2] -= p_matrix.elements[2];
|
elements[2] -= p_matrix.elements[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis Basis::operator-(const Basis& p_matrix) const {
|
Basis Basis::operator-(const Basis &p_matrix) const {
|
||||||
|
|
||||||
Basis ret(*this);
|
Basis ret(*this);
|
||||||
ret -= p_matrix;
|
ret -= p_matrix;
|
||||||
|
@ -418,9 +386,9 @@ Basis Basis::operator-(const Basis& p_matrix) const {
|
||||||
|
|
||||||
void Basis::operator*=(real_t p_val) {
|
void Basis::operator*=(real_t p_val) {
|
||||||
|
|
||||||
elements[0]*=p_val;
|
elements[0] *= p_val;
|
||||||
elements[1]*=p_val;
|
elements[1] *= p_val;
|
||||||
elements[2]*=p_val;
|
elements[2] *= p_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis Basis::operator*(real_t p_val) const {
|
Basis Basis::operator*(real_t p_val) const {
|
||||||
|
@ -430,9 +398,7 @@ Basis Basis::operator*(real_t p_val) const {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Basis::operator String() const {
|
||||||
Basis::operator String() const
|
|
||||||
{
|
|
||||||
String s;
|
String s;
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
|
||||||
|
@ -449,40 +415,38 @@ Basis::operator String() const
|
||||||
|
|
||||||
/* create / set */
|
/* create / set */
|
||||||
|
|
||||||
|
|
||||||
void Basis::set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
|
void Basis::set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
|
||||||
|
|
||||||
elements[0][0]=xx;
|
elements[0][0] = xx;
|
||||||
elements[0][1]=xy;
|
elements[0][1] = xy;
|
||||||
elements[0][2]=xz;
|
elements[0][2] = xz;
|
||||||
elements[1][0]=yx;
|
elements[1][0] = yx;
|
||||||
elements[1][1]=yy;
|
elements[1][1] = yy;
|
||||||
elements[1][2]=yz;
|
elements[1][2] = yz;
|
||||||
elements[2][0]=zx;
|
elements[2][0] = zx;
|
||||||
elements[2][1]=zy;
|
elements[2][1] = zy;
|
||||||
elements[2][2]=zz;
|
elements[2][2] = zz;
|
||||||
}
|
}
|
||||||
Vector3 Basis::get_column(int i) const {
|
Vector3 Basis::get_column(int i) const {
|
||||||
|
|
||||||
return Vector3(elements[0][i],elements[1][i],elements[2][i]);
|
return Vector3(elements[0][i], elements[1][i], elements[2][i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Basis::get_row(int i) const {
|
Vector3 Basis::get_row(int i) const {
|
||||||
|
|
||||||
return Vector3(elements[i][0],elements[i][1],elements[i][2]);
|
return Vector3(elements[i][0], elements[i][1], elements[i][2]);
|
||||||
}
|
}
|
||||||
Vector3 Basis::get_main_diagonal() const {
|
Vector3 Basis::get_main_diagonal() const {
|
||||||
return Vector3(elements[0][0],elements[1][1],elements[2][2]);
|
return Vector3(elements[0][0], elements[1][1], elements[2][2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Basis::set_row(int i, const Vector3& p_row) {
|
void Basis::set_row(int i, const Vector3 &p_row) {
|
||||||
elements[i][0]=p_row.x;
|
elements[i][0] = p_row.x;
|
||||||
elements[i][1]=p_row.y;
|
elements[i][1] = p_row.y;
|
||||||
elements[i][2]=p_row.z;
|
elements[i][2] = p_row.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis Basis::transpose_xform(const Basis& m) const
|
Basis Basis::transpose_xform(const Basis &m) const {
|
||||||
{
|
|
||||||
return Basis(
|
return Basis(
|
||||||
elements[0].x * m[0].x + elements[1].x * m[1].x + elements[2].x * m[2].x,
|
elements[0].x * m[0].x + elements[1].x * m[1].x + elements[2].x * m[2].x,
|
||||||
elements[0].x * m[0].y + elements[1].x * m[1].y + elements[2].x * m[2].y,
|
elements[0].x * m[0].y + elements[1].x * m[1].y + elements[2].x * m[2].y,
|
||||||
|
@ -495,36 +459,33 @@ Basis Basis::transpose_xform(const Basis& m) const
|
||||||
elements[0].z * m[0].z + elements[1].z * m[1].z + elements[2].z * m[2].z);
|
elements[0].z * m[0].z + elements[1].z * m[1].z + elements[2].z * m[2].z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Basis::orthonormalize()
|
void Basis::orthonormalize() {
|
||||||
{
|
|
||||||
ERR_FAIL_COND(determinant() == 0);
|
ERR_FAIL_COND(determinant() == 0);
|
||||||
|
|
||||||
// Gram-Schmidt Process
|
// Gram-Schmidt Process
|
||||||
|
|
||||||
Vector3 x=get_axis(0);
|
Vector3 x = get_axis(0);
|
||||||
Vector3 y=get_axis(1);
|
Vector3 y = get_axis(1);
|
||||||
Vector3 z=get_axis(2);
|
Vector3 z = get_axis(2);
|
||||||
|
|
||||||
x.normalize();
|
x.normalize();
|
||||||
y = (y-x*(x.dot(y)));
|
y = (y - x * (x.dot(y)));
|
||||||
y.normalize();
|
y.normalize();
|
||||||
z = (z-x*(x.dot(z))-y*(y.dot(z)));
|
z = (z - x * (x.dot(z)) - y * (y.dot(z)));
|
||||||
z.normalize();
|
z.normalize();
|
||||||
|
|
||||||
set_axis(0,x);
|
set_axis(0, x);
|
||||||
set_axis(1,y);
|
set_axis(1, y);
|
||||||
set_axis(2,z);
|
set_axis(2, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis Basis::orthonormalized() const
|
Basis Basis::orthonormalized() const {
|
||||||
{
|
|
||||||
Basis b = *this;
|
Basis b = *this;
|
||||||
b.orthonormalize();
|
b.orthonormalize();
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Basis::is_symmetric() const
|
bool Basis::is_symmetric() const {
|
||||||
{
|
|
||||||
if (::fabs(elements[0][1] - elements[1][0]) > CMP_EPSILON)
|
if (::fabs(elements[0][1] - elements[1][0]) > CMP_EPSILON)
|
||||||
return false;
|
return false;
|
||||||
if (::fabs(elements[0][2] - elements[2][0]) > CMP_EPSILON)
|
if (::fabs(elements[0][2] - elements[2][0]) > CMP_EPSILON)
|
||||||
|
@ -535,8 +496,7 @@ bool Basis::is_symmetric() const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis Basis::diagonalize()
|
Basis Basis::diagonalize() {
|
||||||
{
|
|
||||||
// I love copy paste
|
// I love copy paste
|
||||||
|
|
||||||
if (!is_symmetric())
|
if (!is_symmetric())
|
||||||
|
@ -548,7 +508,7 @@ Basis Basis::diagonalize()
|
||||||
|
|
||||||
int ite = 0;
|
int ite = 0;
|
||||||
Basis acc_rot;
|
Basis acc_rot;
|
||||||
while (off_matrix_norm_2 > CMP_EPSILON2 && ite++ < ite_max ) {
|
while (off_matrix_norm_2 > CMP_EPSILON2 && ite++ < ite_max) {
|
||||||
real_t el01_2 = elements[0][1] * elements[0][1];
|
real_t el01_2 = elements[0][1] * elements[0][1];
|
||||||
real_t el02_2 = elements[0][2] * elements[0][2];
|
real_t el02_2 = elements[0][2] * elements[0][2];
|
||||||
real_t el12_2 = elements[1][2] * elements[1][2];
|
real_t el12_2 = elements[1][2] * elements[1][2];
|
||||||
|
@ -583,7 +543,7 @@ Basis Basis::diagonalize()
|
||||||
// Compute the rotation matrix
|
// Compute the rotation matrix
|
||||||
Basis rot;
|
Basis rot;
|
||||||
rot.elements[i][i] = rot.elements[j][j] = ::cos(angle);
|
rot.elements[i][i] = rot.elements[j][j] = ::cos(angle);
|
||||||
rot.elements[i][j] = - (rot.elements[j][i] = ::sin(angle));
|
rot.elements[i][j] = -(rot.elements[j][i] = ::sin(angle));
|
||||||
|
|
||||||
// Update the off matrix norm
|
// Update the off matrix norm
|
||||||
off_matrix_norm_2 -= elements[i][j] * elements[i][j];
|
off_matrix_norm_2 -= elements[i][j] * elements[i][j];
|
||||||
|
@ -596,8 +556,7 @@ Basis Basis::diagonalize()
|
||||||
return acc_rot;
|
return acc_rot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const Basis _ortho_bases[24] = {
|
||||||
static const Basis _ortho_bases[24]={
|
|
||||||
Basis(1, 0, 0, 0, 1, 0, 0, 0, 1),
|
Basis(1, 0, 0, 0, 1, 0, 0, 0, 1),
|
||||||
Basis(0, -1, 0, 1, 0, 0, 0, 0, 1),
|
Basis(0, -1, 0, 1, 0, 0, 0, 0, 1),
|
||||||
Basis(-1, 0, 0, 0, -1, 0, 0, 0, 1),
|
Basis(-1, 0, 0, 0, -1, 0, 0, 0, 1),
|
||||||
|
@ -624,62 +583,53 @@ static const Basis _ortho_bases[24]={
|
||||||
Basis(0, -1, 0, 0, 0, -1, 1, 0, 0)
|
Basis(0, -1, 0, 0, 0, -1, 1, 0, 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int Basis::get_orthogonal_index() const {
|
||||||
int Basis::get_orthogonal_index() const
|
|
||||||
{
|
|
||||||
//could be sped up if i come up with a way
|
//could be sped up if i come up with a way
|
||||||
Basis orth=*this;
|
Basis orth = *this;
|
||||||
for(int i=0;i<3;i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
for(int j=0;j<3;j++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
|
|
||||||
real_t v = orth[i][j];
|
real_t v = orth[i][j];
|
||||||
if (v>0.5)
|
if (v > 0.5)
|
||||||
v=1.0;
|
v = 1.0;
|
||||||
else if (v<-0.5)
|
else if (v < -0.5)
|
||||||
v=-1.0;
|
v = -1.0;
|
||||||
else
|
else
|
||||||
v=0;
|
v = 0;
|
||||||
|
|
||||||
orth[i][j]=v;
|
orth[i][j] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0;i<24;i++) {
|
for (int i = 0; i < 24; i++) {
|
||||||
|
|
||||||
if (_ortho_bases[i]==orth)
|
if (_ortho_bases[i] == orth)
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Basis::set_orthogonal_index(int p_index) {
|
||||||
void Basis::set_orthogonal_index(int p_index){
|
|
||||||
|
|
||||||
//there only exist 24 orthogonal bases in r3
|
//there only exist 24 orthogonal bases in r3
|
||||||
ERR_FAIL_COND(p_index >= 24);
|
ERR_FAIL_COND(p_index >= 24);
|
||||||
|
|
||||||
*this=_ortho_bases[p_index];
|
*this = _ortho_bases[p_index];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Basis::Basis(const Vector3 &p_euler) {
|
||||||
|
|
||||||
|
set_euler(p_euler);
|
||||||
Basis::Basis(const Vector3& p_euler) {
|
|
||||||
|
|
||||||
set_euler( p_euler );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
||||||
#include "Quat.hpp"
|
#include "Quat.hpp"
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
Basis::Basis(const Quat& p_quat) {
|
Basis::Basis(const Quat &p_quat) {
|
||||||
|
|
||||||
real_t d = p_quat.length_squared();
|
real_t d = p_quat.length_squared();
|
||||||
real_t s = 2.0 / d;
|
real_t s = 2.0 / d;
|
||||||
|
@ -687,32 +637,30 @@ Basis::Basis(const Quat& p_quat) {
|
||||||
real_t wx = p_quat.w * xs, wy = p_quat.w * ys, wz = p_quat.w * zs;
|
real_t wx = p_quat.w * xs, wy = p_quat.w * ys, wz = p_quat.w * zs;
|
||||||
real_t xx = p_quat.x * xs, xy = p_quat.x * ys, xz = p_quat.x * zs;
|
real_t xx = p_quat.x * xs, xy = p_quat.x * ys, xz = p_quat.x * zs;
|
||||||
real_t yy = p_quat.y * ys, yz = p_quat.y * zs, zz = p_quat.z * zs;
|
real_t yy = p_quat.y * ys, yz = p_quat.y * zs, zz = p_quat.z * zs;
|
||||||
set( 1.0 - (yy + zz), xy - wz, xz + wy,
|
set(1.0 - (yy + zz), xy - wz, xz + wy,
|
||||||
xy + wz, 1.0 - (xx + zz), yz - wx,
|
xy + wz, 1.0 - (xx + zz), yz - wx,
|
||||||
xz - wy, yz + wx, 1.0 - (xx + yy)) ;
|
xz - wy, yz + wx, 1.0 - (xx + yy));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis::Basis(const Vector3& p_axis, real_t p_phi) {
|
Basis::Basis(const Vector3 &p_axis, real_t p_phi) {
|
||||||
// Rotation matrix from axis and angle, see https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle
|
// Rotation matrix from axis and angle, see https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle
|
||||||
|
|
||||||
Vector3 axis_sq(p_axis.x*p_axis.x,p_axis.y*p_axis.y,p_axis.z*p_axis.z);
|
Vector3 axis_sq(p_axis.x * p_axis.x, p_axis.y * p_axis.y, p_axis.z * p_axis.z);
|
||||||
|
|
||||||
real_t cosine= ::cos(p_phi);
|
real_t cosine = ::cos(p_phi);
|
||||||
real_t sine= ::sin(p_phi);
|
real_t sine = ::sin(p_phi);
|
||||||
|
|
||||||
elements[0][0] = axis_sq.x + cosine * ( 1.0 - axis_sq.x );
|
elements[0][0] = axis_sq.x + cosine * (1.0 - axis_sq.x);
|
||||||
elements[0][1] = p_axis.x * p_axis.y * ( 1.0 - cosine ) - p_axis.z * sine;
|
elements[0][1] = p_axis.x * p_axis.y * (1.0 - cosine) - p_axis.z * sine;
|
||||||
elements[0][2] = p_axis.z * p_axis.x * ( 1.0 - cosine ) + p_axis.y * sine;
|
elements[0][2] = p_axis.z * p_axis.x * (1.0 - cosine) + p_axis.y * sine;
|
||||||
|
|
||||||
elements[1][0] = p_axis.x * p_axis.y * ( 1.0 - cosine ) + p_axis.z * sine;
|
elements[1][0] = p_axis.x * p_axis.y * (1.0 - cosine) + p_axis.z * sine;
|
||||||
elements[1][1] = axis_sq.y + cosine * ( 1.0 - axis_sq.y );
|
elements[1][1] = axis_sq.y + cosine * (1.0 - axis_sq.y);
|
||||||
elements[1][2] = p_axis.y * p_axis.z * ( 1.0 - cosine ) - p_axis.x * sine;
|
elements[1][2] = p_axis.y * p_axis.z * (1.0 - cosine) - p_axis.x * sine;
|
||||||
|
|
||||||
elements[2][0] = p_axis.z * p_axis.x * ( 1.0 - cosine ) - p_axis.y * sine;
|
|
||||||
elements[2][1] = p_axis.y * p_axis.z * ( 1.0 - cosine ) + p_axis.x * sine;
|
|
||||||
elements[2][2] = axis_sq.z + cosine * ( 1.0 - axis_sq.z );
|
|
||||||
|
|
||||||
|
elements[2][0] = p_axis.z * p_axis.x * (1.0 - cosine) - p_axis.y * sine;
|
||||||
|
elements[2][1] = p_axis.y * p_axis.z * (1.0 - cosine) + p_axis.x * sine;
|
||||||
|
elements[2][2] = axis_sq.z + cosine * (1.0 - axis_sq.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis::operator Quat() const {
|
Basis::operator Quat() const {
|
||||||
|
@ -722,18 +670,15 @@ Basis::operator Quat() const {
|
||||||
real_t trace = elements[0][0] + elements[1][1] + elements[2][2];
|
real_t trace = elements[0][0] + elements[1][1] + elements[2][2];
|
||||||
real_t temp[4];
|
real_t temp[4];
|
||||||
|
|
||||||
if (trace > 0.0)
|
if (trace > 0.0) {
|
||||||
{
|
|
||||||
real_t s = ::sqrt(trace + 1.0);
|
real_t s = ::sqrt(trace + 1.0);
|
||||||
temp[3]=(s * 0.5);
|
temp[3] = (s * 0.5);
|
||||||
s = 0.5 / s;
|
s = 0.5 / s;
|
||||||
|
|
||||||
temp[0]=((elements[2][1] - elements[1][2]) * s);
|
temp[0] = ((elements[2][1] - elements[1][2]) * s);
|
||||||
temp[1]=((elements[0][2] - elements[2][0]) * s);
|
temp[1] = ((elements[0][2] - elements[2][0]) * s);
|
||||||
temp[2]=((elements[1][0] - elements[0][1]) * s);
|
temp[2] = ((elements[1][0] - elements[0][1]) * s);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
int i = elements[0][0] < elements[1][1] ?
|
int i = elements[0][0] < elements[1][1] ?
|
||||||
(elements[1][1] < elements[2][2] ? 2 : 1) :
|
(elements[1][1] < elements[2][2] ? 2 : 1) :
|
||||||
(elements[0][0] < elements[2][2] ? 2 : 0);
|
(elements[0][0] < elements[2][2] ? 2 : 0);
|
||||||
|
@ -749,11 +694,7 @@ Basis::operator Quat() const {
|
||||||
temp[k] = (elements[k][i] + elements[i][k]) * s;
|
temp[k] = (elements[k][i] + elements[i][k]) * s;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Quat(temp[0],temp[1],temp[2],temp[3]);
|
return Quat(temp[0], temp[1], temp[2], temp[3]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,138 +12,128 @@ namespace godot {
|
||||||
|
|
||||||
static String _to_hex(float p_val);
|
static String _to_hex(float p_val);
|
||||||
|
|
||||||
static float _parse_col(const String& p_str, int p_ofs) {
|
static float _parse_col(const String &p_str, int p_ofs) {
|
||||||
|
|
||||||
int ig=0;
|
int ig = 0;
|
||||||
|
|
||||||
for(int i=0;i<2;i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
|
|
||||||
int c= (int) (wchar_t) p_str[i+p_ofs];
|
int c = (int)(wchar_t)p_str[i + p_ofs];
|
||||||
int v=0;
|
int v = 0;
|
||||||
|
|
||||||
if (c>='0' && c<='9') {
|
if (c >= '0' && c <= '9') {
|
||||||
v=c-'0';
|
v = c - '0';
|
||||||
} else if (c>='a' && c<='f') {
|
} else if (c >= 'a' && c <= 'f') {
|
||||||
v=c-'a';
|
v = c - 'a';
|
||||||
v+=10;
|
v += 10;
|
||||||
} else if (c>='A' && c<='F') {
|
} else if (c >= 'A' && c <= 'F') {
|
||||||
v=c-'A';
|
v = c - 'A';
|
||||||
v+=10;
|
v += 10;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i==0)
|
if (i == 0)
|
||||||
ig+=v*16;
|
ig += v * 16;
|
||||||
else
|
else
|
||||||
ig+=v;
|
ig += v;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ig;
|
return ig;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Color::to_32() const
|
uint32_t Color::to_32() const {
|
||||||
{
|
|
||||||
|
|
||||||
uint32_t c=(uint8_t)(a*255);
|
uint32_t c = (uint8_t)(a * 255);
|
||||||
c<<=8;
|
c <<= 8;
|
||||||
c|=(uint8_t)(r*255);
|
c |= (uint8_t)(r * 255);
|
||||||
c<<=8;
|
c <<= 8;
|
||||||
c|=(uint8_t)(g*255);
|
c |= (uint8_t)(g * 255);
|
||||||
c<<=8;
|
c <<= 8;
|
||||||
c|=(uint8_t)(b*255);
|
c |= (uint8_t)(b * 255);
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Color::to_ARGB32() const
|
uint32_t Color::to_ARGB32() const {
|
||||||
{
|
uint32_t c = (uint8_t)(a * 255);
|
||||||
uint32_t c=(uint8_t)(a*255);
|
c <<= 8;
|
||||||
c<<=8;
|
c |= (uint8_t)(r * 255);
|
||||||
c|=(uint8_t)(r*255);
|
c <<= 8;
|
||||||
c<<=8;
|
c |= (uint8_t)(g * 255);
|
||||||
c|=(uint8_t)(g*255);
|
c <<= 8;
|
||||||
c<<=8;
|
c |= (uint8_t)(b * 255);
|
||||||
c|=(uint8_t)(b*255);
|
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Color::gray() const
|
float Color::gray() const {
|
||||||
{
|
return (r + g + b) / 3.0;
|
||||||
return (r+g+b)/3.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float Color::get_h() const
|
float Color::get_h() const {
|
||||||
{
|
|
||||||
|
|
||||||
float min = MIN( r, g );
|
float min = MIN(r, g);
|
||||||
min = MIN( min, b );
|
min = MIN(min, b);
|
||||||
float max = MAX( r, g );
|
float max = MAX(r, g);
|
||||||
max = MAX( max, b );
|
max = MAX(max, b);
|
||||||
|
|
||||||
float delta = max - min;
|
float delta = max - min;
|
||||||
|
|
||||||
if( delta == 0 )
|
if (delta == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
float h;
|
float h;
|
||||||
if( r == max )
|
if (r == max)
|
||||||
h = ( g - b ) / delta; // between yellow & magenta
|
h = (g - b) / delta; // between yellow & magenta
|
||||||
else if( g == max )
|
else if (g == max)
|
||||||
h = 2 + ( b - r ) / delta; // between cyan & yellow
|
h = 2 + (b - r) / delta; // between cyan & yellow
|
||||||
else
|
else
|
||||||
h = 4 + ( r - g ) / delta; // between magenta & cyan
|
h = 4 + (r - g) / delta; // between magenta & cyan
|
||||||
|
|
||||||
h/=6.0;
|
h /= 6.0;
|
||||||
if (h<0)
|
if (h < 0)
|
||||||
h+=1.0;
|
h += 1.0;
|
||||||
|
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Color::get_s() const
|
float Color::get_s() const {
|
||||||
{
|
float min = MIN(r, g);
|
||||||
float min = MIN( r, g );
|
min = MIN(min, b);
|
||||||
min = MIN( min, b );
|
float max = MAX(r, g);
|
||||||
float max = MAX( r, g );
|
max = MAX(max, b);
|
||||||
max = MAX( max, b );
|
|
||||||
float delta = max - min;
|
float delta = max - min;
|
||||||
return (max!=0) ? (delta / max) : 0;
|
return (max != 0) ? (delta / max) : 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float Color::get_v() const
|
float Color::get_v() const {
|
||||||
{
|
float max = MAX(r, g);
|
||||||
float max = MAX( r, g );
|
max = MAX(max, b);
|
||||||
max = MAX( max, b );
|
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha)
|
void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
float f, p, q, t;
|
float f, p, q, t;
|
||||||
a=p_alpha;
|
a = p_alpha;
|
||||||
|
|
||||||
if( p_s == 0 ) {
|
if (p_s == 0) {
|
||||||
// acp_hromatic (grey)
|
// acp_hromatic (grey)
|
||||||
r = g = b = p_v;
|
r = g = b = p_v;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
p_h *=6.0;
|
p_h *= 6.0;
|
||||||
p_h = ::fmod(p_h,6);
|
p_h = ::fmod(p_h, 6);
|
||||||
i = ::floor( p_h );
|
i = ::floor(p_h);
|
||||||
|
|
||||||
f = p_h - i;
|
f = p_h - i;
|
||||||
p = p_v * ( 1 - p_s );
|
p = p_v * (1 - p_s);
|
||||||
q = p_v * ( 1 - p_s * f );
|
q = p_v * (1 - p_s * f);
|
||||||
t = p_v * ( 1 - p_s * ( 1 - f ) );
|
t = p_v * (1 - p_s * (1 - f));
|
||||||
|
|
||||||
switch( i ) {
|
switch (i) {
|
||||||
case 0: // Red is the dominant color
|
case 0: // Red is the dominant color
|
||||||
r = p_v;
|
r = p_v;
|
||||||
g = t;
|
g = t;
|
||||||
|
@ -177,56 +167,51 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Color::invert()
|
void Color::invert() {
|
||||||
{
|
r = 1.0 - r;
|
||||||
r=1.0-r;
|
g = 1.0 - g;
|
||||||
g=1.0-g;
|
b = 1.0 - b;
|
||||||
b=1.0-b;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Color::contrast()
|
void Color::contrast() {
|
||||||
{
|
r = ::fmod(r + 0.5, 1.0);
|
||||||
r=::fmod(r+0.5,1.0);
|
g = ::fmod(g + 0.5, 1.0);
|
||||||
g=::fmod(g+0.5,1.0);
|
b = ::fmod(b + 0.5, 1.0);
|
||||||
b=::fmod(b+0.5,1.0);
|
|
||||||
}
|
}
|
||||||
Color Color::inverted() const
|
Color Color::inverted() const {
|
||||||
{
|
Color c = *this;
|
||||||
Color c=*this;
|
|
||||||
c.invert();
|
c.invert();
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
Color Color::contrasted() const
|
Color Color::contrasted() const {
|
||||||
{
|
Color c = *this;
|
||||||
Color c=*this;
|
|
||||||
c.contrast();
|
c.contrast();
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color Color::linear_interpolate(const Color& p_b, float p_t) const {
|
Color Color::linear_interpolate(const Color &p_b, float p_t) const {
|
||||||
|
|
||||||
Color res=*this;
|
Color res = *this;
|
||||||
|
|
||||||
res.r+= (p_t * (p_b.r-r));
|
res.r += (p_t * (p_b.r - r));
|
||||||
res.g+= (p_t * (p_b.g-g));
|
res.g += (p_t * (p_b.g - g));
|
||||||
res.b+= (p_t * (p_b.b-b));
|
res.b += (p_t * (p_b.b - b));
|
||||||
res.a+= (p_t * (p_b.a-a));
|
res.a += (p_t * (p_b.a - a));
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color Color::blend(const Color& p_over) const {
|
Color Color::blend(const Color &p_over) const {
|
||||||
|
|
||||||
|
|
||||||
Color res;
|
Color res;
|
||||||
float sa = 1.0 - p_over.a;
|
float sa = 1.0 - p_over.a;
|
||||||
res.a = a*sa+p_over.a;
|
res.a = a * sa + p_over.a;
|
||||||
if (res.a==0) {
|
if (res.a == 0) {
|
||||||
return Color(0,0,0,0);
|
return Color(0, 0, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
res.r = (r*a*sa + p_over.r * p_over.a)/res.a;
|
res.r = (r * a * sa + p_over.r * p_over.a) / res.a;
|
||||||
res.g = (g*a*sa + p_over.g * p_over.a)/res.a;
|
res.g = (g * a * sa + p_over.g * p_over.a) / res.a;
|
||||||
res.b = (b*a*sa + p_over.b * p_over.a)/res.a;
|
res.b = (b * a * sa + p_over.b * p_over.a) / res.a;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -234,114 +219,110 @@ Color Color::blend(const Color& p_over) const {
|
||||||
Color Color::to_linear() const {
|
Color Color::to_linear() const {
|
||||||
|
|
||||||
return Color(
|
return Color(
|
||||||
r<0.04045 ? r * (1.0 / 12.92) : ::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4),
|
r < 0.04045 ? r * (1.0 / 12.92) : ::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4),
|
||||||
g<0.04045 ? g * (1.0 / 12.92) : ::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4),
|
g < 0.04045 ? g * (1.0 / 12.92) : ::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4),
|
||||||
b<0.04045 ? b * (1.0 / 12.92) : ::pow((b + 0.055) * (1.0 / (1 + 0.055)), 2.4),
|
b < 0.04045 ? b * (1.0 / 12.92) : ::pow((b + 0.055) * (1.0 / (1 + 0.055)), 2.4),
|
||||||
a
|
a);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Color Color::hex(uint32_t p_hex)
|
Color Color::hex(uint32_t p_hex) {
|
||||||
{
|
float a = (p_hex & 0xFF) / 255.0;
|
||||||
float a = (p_hex&0xFF)/255.0;
|
p_hex >>= 8;
|
||||||
p_hex>>=8;
|
float b = (p_hex & 0xFF) / 255.0;
|
||||||
float b = (p_hex&0xFF)/255.0;
|
p_hex >>= 8;
|
||||||
p_hex>>=8;
|
float g = (p_hex & 0xFF) / 255.0;
|
||||||
float g = (p_hex&0xFF)/255.0;
|
p_hex >>= 8;
|
||||||
p_hex>>=8;
|
float r = (p_hex & 0xFF) / 255.0;
|
||||||
float r = (p_hex&0xFF)/255.0;
|
|
||||||
|
|
||||||
return Color(r,g,b,a);
|
return Color(r, g, b, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
Color Color::html(const String& p_color)
|
Color Color::html(const String &p_color) {
|
||||||
{
|
|
||||||
String color = p_color;
|
String color = p_color;
|
||||||
if (color.length()==0)
|
if (color.length() == 0)
|
||||||
return Color();
|
return Color();
|
||||||
if (color[0]=='#')
|
if (color[0] == '#')
|
||||||
color=color.substr(1,color.length()-1);
|
color = color.substr(1, color.length() - 1);
|
||||||
|
|
||||||
bool alpha=false;
|
bool alpha = false;
|
||||||
|
|
||||||
if (color.length()==8) {
|
if (color.length() == 8) {
|
||||||
alpha=true;
|
alpha = true;
|
||||||
} else if (color.length()==6) {
|
} else if (color.length() == 6) {
|
||||||
alpha=false;
|
alpha = false;
|
||||||
} else {
|
} else {
|
||||||
ERR_PRINTS(String("Invalid Color Code: ") + p_color);
|
ERR_PRINTS(String("Invalid Color Code: ") + p_color);
|
||||||
ERR_FAIL_V(Color());
|
ERR_FAIL_V(Color());
|
||||||
}
|
}
|
||||||
|
|
||||||
int a=255;
|
int a = 255;
|
||||||
if (alpha) {
|
if (alpha) {
|
||||||
a=_parse_col(color,0);
|
a = _parse_col(color, 0);
|
||||||
if (a<0) {
|
if (a < 0) {
|
||||||
ERR_PRINTS(String("Invalid Color Code: ") + p_color);
|
ERR_PRINTS(String("Invalid Color Code: ") + p_color);
|
||||||
ERR_FAIL_V(Color());
|
ERR_FAIL_V(Color());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int from=alpha?2:0;
|
int from = alpha ? 2 : 0;
|
||||||
|
|
||||||
int r=_parse_col(color,from+0);
|
int r = _parse_col(color, from + 0);
|
||||||
if (r<0) {
|
if (r < 0) {
|
||||||
ERR_PRINTS(String("Invalid Color Code: ") + p_color);
|
ERR_PRINTS(String("Invalid Color Code: ") + p_color);
|
||||||
ERR_FAIL_V(Color());
|
ERR_FAIL_V(Color());
|
||||||
}
|
}
|
||||||
int g=_parse_col(color,from+2);
|
int g = _parse_col(color, from + 2);
|
||||||
if (g<0) {
|
if (g < 0) {
|
||||||
ERR_PRINTS(String("Invalid Color Code: ") + p_color);
|
ERR_PRINTS(String("Invalid Color Code: ") + p_color);
|
||||||
ERR_FAIL_V(Color());
|
ERR_FAIL_V(Color());
|
||||||
}
|
}
|
||||||
int b=_parse_col(color,from+4);
|
int b = _parse_col(color, from + 4);
|
||||||
if (b<0) {
|
if (b < 0) {
|
||||||
ERR_PRINTS(String("Invalid Color Code: ") + p_color);
|
ERR_PRINTS(String("Invalid Color Code: ") + p_color);
|
||||||
ERR_FAIL_V(Color());
|
ERR_FAIL_V(Color());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Color(r/255.0,g/255.0,b/255.0,a/255.0);
|
return Color(r / 255.0, g / 255.0, b / 255.0, a / 255.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Color::html_is_valid(const String& p_color)
|
bool Color::html_is_valid(const String &p_color) {
|
||||||
{
|
|
||||||
String color = p_color;
|
String color = p_color;
|
||||||
|
|
||||||
if (color.length()==0)
|
if (color.length() == 0)
|
||||||
return false;
|
return false;
|
||||||
if (color[0]=='#')
|
if (color[0] == '#')
|
||||||
color=color.substr(1,color.length()-1);
|
color = color.substr(1, color.length() - 1);
|
||||||
|
|
||||||
bool alpha=false;
|
bool alpha = false;
|
||||||
|
|
||||||
if (color.length()==8) {
|
if (color.length() == 8) {
|
||||||
alpha=true;
|
alpha = true;
|
||||||
} else if (color.length()==6) {
|
} else if (color.length() == 6) {
|
||||||
alpha=false;
|
alpha = false;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int a=255;
|
int a = 255;
|
||||||
if (alpha) {
|
if (alpha) {
|
||||||
a=_parse_col(color,0);
|
a = _parse_col(color, 0);
|
||||||
if (a<0) {
|
if (a < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int from=alpha?2:0;
|
int from = alpha ? 2 : 0;
|
||||||
|
|
||||||
int r=_parse_col(color,from+0);
|
int r = _parse_col(color, from + 0);
|
||||||
if (r<0) {
|
if (r < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int g=_parse_col(color,from+2);
|
int g = _parse_col(color, from + 2);
|
||||||
if (g<0) {
|
if (g < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int b=_parse_col(color,from+4);
|
int b = _parse_col(color, from + 4);
|
||||||
if (b<0) {
|
if (b < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,62 +330,57 @@ bool Color::html_is_valid(const String& p_color)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CLAMP
|
#ifndef CLAMP
|
||||||
#define CLAMP(m_a,m_min,m_max) (((m_a)<(m_min))?(m_min):(((m_a)>(m_max))?m_max:m_a))
|
#define CLAMP(m_a, m_min, m_max) (((m_a) < (m_min)) ? (m_min) : (((m_a) > (m_max)) ? m_max : m_a))
|
||||||
#endif
|
#endif
|
||||||
static String _to_hex(float p_val) {
|
static String _to_hex(float p_val) {
|
||||||
|
|
||||||
int v = p_val * 255;
|
int v = p_val * 255;
|
||||||
v = CLAMP(v,0,255);
|
v = CLAMP(v, 0, 255);
|
||||||
String ret;
|
String ret;
|
||||||
|
|
||||||
for(int i=0;i<2;i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
|
|
||||||
wchar_t c[2]={0,0};
|
wchar_t c[2] = { 0, 0 };
|
||||||
int lv = v&0xF;
|
int lv = v & 0xF;
|
||||||
if (lv<10)
|
if (lv < 10)
|
||||||
c[0]='0'+lv;
|
c[0] = '0' + lv;
|
||||||
else
|
else
|
||||||
c[0]='a'+lv-10;
|
c[0] = 'a' + lv - 10;
|
||||||
|
|
||||||
v>>=4;
|
v >>= 4;
|
||||||
String cs=(const wchar_t*)c;
|
String cs = (const wchar_t *)c;
|
||||||
ret = cs + ret;
|
ret = cs + ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String Color::to_html(bool p_alpha) const
|
String Color::to_html(bool p_alpha) const {
|
||||||
{
|
|
||||||
String txt;
|
String txt;
|
||||||
txt+=_to_hex(r);
|
txt += _to_hex(r);
|
||||||
txt+=_to_hex(g);
|
txt += _to_hex(g);
|
||||||
txt+=_to_hex(b);
|
txt += _to_hex(b);
|
||||||
if (p_alpha)
|
if (p_alpha)
|
||||||
txt=_to_hex(a)+txt;
|
txt = _to_hex(a) + txt;
|
||||||
return txt;
|
return txt;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color::operator String() const
|
Color::operator String() const {
|
||||||
{
|
|
||||||
return String::num(r) + ", " + String::num(g) + ", " + String::num(b) + ", " + String::num(a);
|
return String::num(r) + ", " + String::num(g) + ", " + String::num(b) + ", " + String::num(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Color::operator<(const Color &p_color) const {
|
||||||
|
|
||||||
bool Color::operator<(const Color& p_color) const {
|
if (r == p_color.r) {
|
||||||
|
if (g == p_color.g) {
|
||||||
if (r==p_color.r) {
|
if (b == p_color.b) {
|
||||||
if (g==p_color.g) {
|
return (a < p_color.a);
|
||||||
if(b==p_color.b) {
|
|
||||||
return (a<p_color.a);
|
|
||||||
} else
|
} else
|
||||||
return (b<p_color.b);
|
return (b < p_color.b);
|
||||||
} else
|
} else
|
||||||
return g<p_color.g;
|
return g < p_color.g;
|
||||||
} else
|
} else
|
||||||
return r<p_color.r;
|
return r < p_color.r;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
|
@ -1,95 +1,78 @@
|
||||||
#include "Dictionary.hpp"
|
#include "Dictionary.hpp"
|
||||||
#include "Variant.hpp"
|
|
||||||
#include "Array.hpp"
|
#include "Array.hpp"
|
||||||
#include "GodotGlobal.hpp"
|
#include "GodotGlobal.hpp"
|
||||||
|
#include "Variant.hpp"
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
Dictionary::Dictionary()
|
Dictionary::Dictionary() {
|
||||||
{
|
|
||||||
godot::api->godot_dictionary_new(&_godot_dictionary);
|
godot::api->godot_dictionary_new(&_godot_dictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Dictionary(const Dictionary & other)
|
Dictionary::Dictionary(const Dictionary &other) {
|
||||||
{
|
|
||||||
godot::api->godot_dictionary_new_copy(&_godot_dictionary, &other._godot_dictionary);
|
godot::api->godot_dictionary_new_copy(&_godot_dictionary, &other._godot_dictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary & Dictionary::operator=(const Dictionary & other)
|
Dictionary &Dictionary::operator=(const Dictionary &other) {
|
||||||
{
|
|
||||||
godot::api->godot_dictionary_destroy(&_godot_dictionary);
|
godot::api->godot_dictionary_destroy(&_godot_dictionary);
|
||||||
godot::api->godot_dictionary_new_copy(&_godot_dictionary, &other._godot_dictionary);
|
godot::api->godot_dictionary_new_copy(&_godot_dictionary, &other._godot_dictionary);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dictionary::clear()
|
void Dictionary::clear() {
|
||||||
{
|
|
||||||
godot::api->godot_dictionary_clear(&_godot_dictionary);
|
godot::api->godot_dictionary_clear(&_godot_dictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Dictionary::empty() const
|
bool Dictionary::empty() const {
|
||||||
{
|
|
||||||
return godot::api->godot_dictionary_empty(&_godot_dictionary);
|
return godot::api->godot_dictionary_empty(&_godot_dictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dictionary::erase(const Variant& key)
|
void Dictionary::erase(const Variant &key) {
|
||||||
{
|
godot::api->godot_dictionary_erase(&_godot_dictionary, (godot_variant *)&key);
|
||||||
godot::api->godot_dictionary_erase(&_godot_dictionary, (godot_variant *) &key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Dictionary::has(const Variant& key) const
|
bool Dictionary::has(const Variant &key) const {
|
||||||
{
|
return godot::api->godot_dictionary_has(&_godot_dictionary, (godot_variant *)&key);
|
||||||
return godot::api->godot_dictionary_has(&_godot_dictionary, (godot_variant *) &key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Dictionary::has_all(const Array& keys) const
|
bool Dictionary::has_all(const Array &keys) const {
|
||||||
{
|
return godot::api->godot_dictionary_has_all(&_godot_dictionary, (godot_array *)&keys);
|
||||||
return godot::api->godot_dictionary_has_all(&_godot_dictionary, (godot_array *) &keys);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Dictionary::hash() const
|
uint32_t Dictionary::hash() const {
|
||||||
{
|
|
||||||
return godot::api->godot_dictionary_hash(&_godot_dictionary);
|
return godot::api->godot_dictionary_hash(&_godot_dictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
Array Dictionary::keys() const
|
Array Dictionary::keys() const {
|
||||||
{
|
|
||||||
godot_array a = godot::api->godot_dictionary_keys(&_godot_dictionary);
|
godot_array a = godot::api->godot_dictionary_keys(&_godot_dictionary);
|
||||||
return *(Array *) &a;
|
return *(Array *)&a;
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant &Dictionary::operator [](const Variant& key)
|
Variant &Dictionary::operator[](const Variant &key) {
|
||||||
{
|
return *(Variant *)godot::api->godot_dictionary_operator_index(&_godot_dictionary, (godot_variant *)&key);
|
||||||
return *(Variant *) godot::api->godot_dictionary_operator_index(&_godot_dictionary, (godot_variant *) &key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Variant &Dictionary::operator [](const Variant& key) const
|
const Variant &Dictionary::operator[](const Variant &key) const {
|
||||||
{
|
|
||||||
// oops I did it again
|
// oops I did it again
|
||||||
return *(Variant *) godot::api->godot_dictionary_operator_index((godot_dictionary *) &_godot_dictionary, (godot_variant *) &key);
|
return *(Variant *)godot::api->godot_dictionary_operator_index((godot_dictionary *)&_godot_dictionary, (godot_variant *)&key);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Dictionary::size() const
|
int Dictionary::size() const {
|
||||||
{
|
|
||||||
return godot::api->godot_dictionary_size(&_godot_dictionary);
|
return godot::api->godot_dictionary_size(&_godot_dictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
String Dictionary::to_json() const
|
String Dictionary::to_json() const {
|
||||||
{
|
|
||||||
godot_string s = godot::api->godot_dictionary_to_json(&_godot_dictionary);
|
godot_string s = godot::api->godot_dictionary_to_json(&_godot_dictionary);
|
||||||
return *(String *) &s;
|
return *(String *)&s;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array Dictionary::values() const
|
Array Dictionary::values() const {
|
||||||
{
|
|
||||||
godot_array a = godot::api->godot_dictionary_values(&_godot_dictionary);
|
godot_array a = godot::api->godot_dictionary_values(&_godot_dictionary);
|
||||||
return *(Array *) &a;
|
return *(Array *)&a;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::~Dictionary()
|
Dictionary::~Dictionary() {
|
||||||
{
|
|
||||||
godot::api->godot_dictionary_destroy(&_godot_dictionary);
|
godot::api->godot_dictionary_destroy(&_godot_dictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
}
|
|
||||||
|
|
|
@ -4,20 +4,18 @@
|
||||||
|
|
||||||
#include "Wrapped.hpp"
|
#include "Wrapped.hpp"
|
||||||
|
|
||||||
static GDCALLINGCONV void *wrapper_create(void *data, const void *type_tag, godot_object *instance)
|
static GDCALLINGCONV void *wrapper_create(void *data, const void *type_tag, godot_object *instance) {
|
||||||
{
|
godot::_Wrapped *wrapper_memory = (godot::_Wrapped *)godot::api->godot_alloc(sizeof(godot::_Wrapped));
|
||||||
godot::_Wrapped *wrapper_memory = (godot::_Wrapped *) godot::api->godot_alloc(sizeof(godot::_Wrapped));
|
|
||||||
|
|
||||||
if (!wrapper_memory)
|
if (!wrapper_memory)
|
||||||
return NULL;
|
return NULL;
|
||||||
wrapper_memory->_owner = instance;
|
wrapper_memory->_owner = instance;
|
||||||
wrapper_memory->_type_tag = (size_t) type_tag;
|
wrapper_memory->_type_tag = (size_t)type_tag;
|
||||||
|
|
||||||
return (void *) wrapper_memory;
|
return (void *)wrapper_memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GDCALLINGCONV void wrapper_destroy(void *data, void *wrapper)
|
static GDCALLINGCONV void wrapper_destroy(void *data, void *wrapper) {
|
||||||
{
|
|
||||||
if (wrapper)
|
if (wrapper)
|
||||||
godot::api->godot_free(wrapper);
|
godot::api->godot_free(wrapper);
|
||||||
}
|
}
|
||||||
|
@ -32,20 +30,18 @@ const godot_gdnative_ext_nativescript_1_1_api_struct *nativescript_1_1_api = nul
|
||||||
|
|
||||||
const void *gdnlib = NULL;
|
const void *gdnlib = NULL;
|
||||||
|
|
||||||
void Godot::print(const String& message)
|
void Godot::print(const String &message) {
|
||||||
{
|
godot::api->godot_print((godot_string *)&message);
|
||||||
godot::api->godot_print((godot_string *) &message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Godot::print_warning(const String& description, const String& function, const String& file, int line)
|
void Godot::print_warning(const String &description, const String &function, const String &file, int line) {
|
||||||
{
|
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
char * c_desc = description.alloc_c_string();
|
char *c_desc = description.alloc_c_string();
|
||||||
char * c_func = function.alloc_c_string();
|
char *c_func = function.alloc_c_string();
|
||||||
char * c_file = file.alloc_c_string();
|
char *c_file = file.alloc_c_string();
|
||||||
|
|
||||||
if (c_desc != nullptr && c_func !=nullptr && c_file != nullptr) {
|
if (c_desc != nullptr && c_func != nullptr && c_file != nullptr) {
|
||||||
godot::api->godot_print_warning(c_desc, c_func, c_file, line);
|
godot::api->godot_print_warning(c_desc, c_func, c_file, line);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -54,15 +50,14 @@ void Godot::print_warning(const String& description, const String& function, con
|
||||||
if (c_file != nullptr) godot::api->godot_free(c_file);
|
if (c_file != nullptr) godot::api->godot_free(c_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Godot::print_error(const String& description, const String& function, const String& file, int line)
|
void Godot::print_error(const String &description, const String &function, const String &file, int line) {
|
||||||
{
|
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
char * c_desc = description.alloc_c_string();
|
char *c_desc = description.alloc_c_string();
|
||||||
char * c_func = function.alloc_c_string();
|
char *c_func = function.alloc_c_string();
|
||||||
char * c_file = file.alloc_c_string();
|
char *c_file = file.alloc_c_string();
|
||||||
|
|
||||||
if (c_desc != nullptr && c_func !=nullptr && c_file != nullptr) {
|
if (c_desc != nullptr && c_func != nullptr && c_file != nullptr) {
|
||||||
godot::api->godot_print_error(c_desc, c_func, c_file, line);
|
godot::api->godot_print_error(c_desc, c_func, c_file, line);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,8 +68,7 @@ void Godot::print_error(const String& description, const String& function, const
|
||||||
|
|
||||||
void ___register_types();
|
void ___register_types();
|
||||||
|
|
||||||
void Godot::gdnative_init(godot_gdnative_init_options *options)
|
void Godot::gdnative_init(godot_gdnative_init_options *options) {
|
||||||
{
|
|
||||||
godot::api = options->api_struct;
|
godot::api = options->api_struct;
|
||||||
godot::gdnlib = options->gd_native_library;
|
godot::gdnlib = options->gd_native_library;
|
||||||
|
|
||||||
|
@ -88,7 +82,7 @@ void Godot::gdnative_init(godot_gdnative_init_options *options)
|
||||||
|
|
||||||
while (extension) {
|
while (extension) {
|
||||||
if (extension->version.major == 1 && extension->version.minor == 1) {
|
if (extension->version.major == 1 && extension->version.minor == 1) {
|
||||||
godot::nativescript_1_1_api = (const godot_gdnative_ext_nativescript_1_1_api_struct *) extension;
|
godot::nativescript_1_1_api = (const godot_gdnative_ext_nativescript_1_1_api_struct *)extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
extension = extension->next;
|
extension = extension->next;
|
||||||
|
@ -97,16 +91,13 @@ void Godot::gdnative_init(godot_gdnative_init_options *options)
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Godot::gdnative_terminate(godot_gdnative_terminate_options *options)
|
void Godot::gdnative_terminate(godot_gdnative_terminate_options *options) {
|
||||||
{
|
|
||||||
// reserved for future use.
|
// reserved for future use.
|
||||||
}
|
}
|
||||||
|
|
||||||
void Godot::nativescript_init(void *handle)
|
void Godot::nativescript_init(void *handle) {
|
||||||
{
|
|
||||||
godot::_RegisterState::nativescript_handle = handle;
|
godot::_RegisterState::nativescript_handle = handle;
|
||||||
|
|
||||||
godot_instance_binding_functions binding_funcs = {};
|
godot_instance_binding_functions binding_funcs = {};
|
||||||
|
@ -118,9 +109,8 @@ void Godot::nativescript_init(void *handle)
|
||||||
___register_types();
|
___register_types();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Godot::nativescript_terminate(void *handle)
|
void Godot::nativescript_terminate(void *handle) {
|
||||||
{
|
|
||||||
godot::nativescript_1_1_api->godot_nativescript_unregister_instance_binding_data_functions(godot::_RegisterState::language_index);
|
godot::nativescript_1_1_api->godot_nativescript_unregister_instance_binding_data_functions(godot::_RegisterState::language_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
|
@ -1,94 +1,77 @@
|
||||||
#include "NodePath.hpp"
|
#include "NodePath.hpp"
|
||||||
#include "String.hpp"
|
|
||||||
#include "GodotGlobal.hpp"
|
#include "GodotGlobal.hpp"
|
||||||
|
#include "String.hpp"
|
||||||
|
|
||||||
#include <gdnative/node_path.h>
|
#include <gdnative/node_path.h>
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
|
NodePath::NodePath() {
|
||||||
NodePath::NodePath()
|
|
||||||
{
|
|
||||||
String from = "";
|
String from = "";
|
||||||
godot::api->godot_node_path_new(&_node_path, (godot_string *) &from);
|
godot::api->godot_node_path_new(&_node_path, (godot_string *)&from);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodePath::NodePath(const NodePath &other)
|
NodePath::NodePath(const NodePath &other) {
|
||||||
{
|
|
||||||
String from = other;
|
String from = other;
|
||||||
godot::api->godot_node_path_new(&_node_path, (godot_string *) &from);
|
godot::api->godot_node_path_new(&_node_path, (godot_string *)&from);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodePath::NodePath(const String &from)
|
NodePath::NodePath(const String &from) {
|
||||||
{
|
godot::api->godot_node_path_new(&_node_path, (godot_string *)&from);
|
||||||
godot::api->godot_node_path_new(&_node_path, (godot_string *) &from);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NodePath::NodePath(const char *contents)
|
NodePath::NodePath(const char *contents) {
|
||||||
{
|
|
||||||
String from = contents;
|
String from = contents;
|
||||||
godot::api->godot_node_path_new(&_node_path, (godot_string *) &from);
|
godot::api->godot_node_path_new(&_node_path, (godot_string *)&from);
|
||||||
}
|
}
|
||||||
|
|
||||||
String NodePath::get_name(const int idx) const
|
String NodePath::get_name(const int idx) const {
|
||||||
{
|
|
||||||
godot_string str = godot::api->godot_node_path_get_name(&_node_path, idx);
|
godot_string str = godot::api->godot_node_path_get_name(&_node_path, idx);
|
||||||
|
|
||||||
return *(String *) &str;
|
return *(String *)&str;
|
||||||
}
|
}
|
||||||
|
|
||||||
int NodePath::get_name_count() const
|
int NodePath::get_name_count() const {
|
||||||
{
|
|
||||||
return godot::api->godot_node_path_get_name_count(&_node_path);
|
return godot::api->godot_node_path_get_name_count(&_node_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
String NodePath::get_subname(const int idx) const
|
String NodePath::get_subname(const int idx) const {
|
||||||
{
|
|
||||||
godot_string str = godot::api->godot_node_path_get_subname(&_node_path, idx);
|
godot_string str = godot::api->godot_node_path_get_subname(&_node_path, idx);
|
||||||
return *(String *) &str;
|
return *(String *)&str;
|
||||||
}
|
}
|
||||||
|
|
||||||
int NodePath::get_subname_count() const
|
int NodePath::get_subname_count() const {
|
||||||
{
|
|
||||||
return godot::api->godot_node_path_get_subname_count(&_node_path);
|
return godot::api->godot_node_path_get_subname_count(&_node_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NodePath::is_absolute() const
|
bool NodePath::is_absolute() const {
|
||||||
{
|
|
||||||
return godot::api->godot_node_path_is_absolute(&_node_path);
|
return godot::api->godot_node_path_is_absolute(&_node_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NodePath::is_empty() const
|
bool NodePath::is_empty() const {
|
||||||
{
|
|
||||||
return godot::api->godot_node_path_is_empty(&_node_path);
|
return godot::api->godot_node_path_is_empty(&_node_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodePath::operator String() const
|
NodePath::operator String() const {
|
||||||
{
|
|
||||||
godot_string str = godot::api->godot_node_path_as_string(&_node_path);
|
godot_string str = godot::api->godot_node_path_as_string(&_node_path);
|
||||||
|
|
||||||
return *(String *) &str;
|
return *(String *)&str;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NodePath::operator ==(const NodePath& other)
|
bool NodePath::operator==(const NodePath &other) {
|
||||||
{
|
|
||||||
return godot::api->godot_node_path_operator_equal(&_node_path, &other._node_path);
|
return godot::api->godot_node_path_operator_equal(&_node_path, &other._node_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodePath::operator =(const NodePath& other)
|
void NodePath::operator=(const NodePath &other) {
|
||||||
{
|
|
||||||
godot::api->godot_node_path_destroy(&_node_path);
|
godot::api->godot_node_path_destroy(&_node_path);
|
||||||
|
|
||||||
String other_string = (String) other;
|
String other_string = (String)other;
|
||||||
|
|
||||||
godot::api->godot_node_path_new(&_node_path, (godot_string *) &other_string);
|
godot::api->godot_node_path_new(&_node_path, (godot_string *)&other_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodePath::~NodePath()
|
NodePath::~NodePath() {
|
||||||
{
|
|
||||||
godot::api->godot_node_path_destroy(&_node_path);
|
godot::api->godot_node_path_destroy(&_node_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,27 +5,24 @@
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
|
void Plane::set_normal(const Vector3 &p_normal) {
|
||||||
void Plane::set_normal(const Vector3& p_normal)
|
|
||||||
{
|
|
||||||
this->normal = p_normal;
|
this->normal = p_normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Plane::project(const Vector3& p_point) const {
|
Vector3 Plane::project(const Vector3 &p_point) const {
|
||||||
|
|
||||||
return p_point - normal * distance_to(p_point);
|
return p_point - normal * distance_to(p_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plane::normalize() {
|
void Plane::normalize() {
|
||||||
|
|
||||||
real_t l = normal.length();
|
real_t l = normal.length();
|
||||||
if (l==0) {
|
if (l == 0) {
|
||||||
*this=Plane(0,0,0,0);
|
*this = Plane(0, 0, 0, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
normal/=l;
|
normal /= l;
|
||||||
d/=l;
|
d /= l;
|
||||||
}
|
}
|
||||||
|
|
||||||
Plane Plane::normalized() const {
|
Plane Plane::normalized() const {
|
||||||
|
@ -37,96 +34,95 @@ Plane Plane::normalized() const {
|
||||||
|
|
||||||
Vector3 Plane::get_any_point() const {
|
Vector3 Plane::get_any_point() const {
|
||||||
|
|
||||||
return get_normal()*d;
|
return get_normal() * d;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Plane::get_any_perpendicular_normal() const {
|
Vector3 Plane::get_any_perpendicular_normal() const {
|
||||||
|
|
||||||
static const Vector3 p1 = Vector3(1,0,0);
|
static const Vector3 p1 = Vector3(1, 0, 0);
|
||||||
static const Vector3 p2 = Vector3(0,1,0);
|
static const Vector3 p2 = Vector3(0, 1, 0);
|
||||||
Vector3 p;
|
Vector3 p;
|
||||||
|
|
||||||
if (::fabs(normal.dot(p1)) > 0.99) // if too similar to p1
|
if (::fabs(normal.dot(p1)) > 0.99) // if too similar to p1
|
||||||
p=p2; // use p2
|
p = p2; // use p2
|
||||||
else
|
else
|
||||||
p=p1; // use p1
|
p = p1; // use p1
|
||||||
|
|
||||||
p-=normal * normal.dot(p);
|
p -= normal * normal.dot(p);
|
||||||
p.normalize();
|
p.normalize();
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* intersections */
|
/* intersections */
|
||||||
|
|
||||||
bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result) const {
|
bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result) const {
|
||||||
|
|
||||||
const Plane &p_plane0=*this;
|
const Plane &p_plane0 = *this;
|
||||||
Vector3 normal0=p_plane0.normal;
|
Vector3 normal0 = p_plane0.normal;
|
||||||
Vector3 normal1=p_plane1.normal;
|
Vector3 normal1 = p_plane1.normal;
|
||||||
Vector3 normal2=p_plane2.normal;
|
Vector3 normal2 = p_plane2.normal;
|
||||||
|
|
||||||
real_t denom=vec3_cross(normal0,normal1).dot(normal2);
|
real_t denom = vec3_cross(normal0, normal1).dot(normal2);
|
||||||
|
|
||||||
if (::fabs(denom)<=CMP_EPSILON)
|
if (::fabs(denom) <= CMP_EPSILON)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (r_result) {
|
if (r_result) {
|
||||||
*r_result = ( (vec3_cross(normal1, normal2) * p_plane0.d) +
|
*r_result = ((vec3_cross(normal1, normal2) * p_plane0.d) +
|
||||||
(vec3_cross(normal2, normal0) * p_plane1.d) +
|
(vec3_cross(normal2, normal0) * p_plane1.d) +
|
||||||
(vec3_cross(normal0, normal1) * p_plane2.d) )/denom;
|
(vec3_cross(normal0, normal1) * p_plane2.d)) /
|
||||||
|
denom;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Plane::intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersection) const {
|
||||||
|
|
||||||
bool Plane::intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3* p_intersection) const {
|
Vector3 segment = p_dir;
|
||||||
|
real_t den = normal.dot(segment);
|
||||||
Vector3 segment=p_dir;
|
|
||||||
real_t den=normal.dot( segment );
|
|
||||||
|
|
||||||
//printf("den is %i\n",den);
|
//printf("den is %i\n",den);
|
||||||
if (::fabs(den)<=CMP_EPSILON) {
|
if (::fabs(den) <= CMP_EPSILON) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t dist=(normal.dot( p_from ) - d) / den;
|
real_t dist = (normal.dot(p_from) - d) / den;
|
||||||
//printf("dist is %i\n",dist);
|
//printf("dist is %i\n",dist);
|
||||||
|
|
||||||
if (dist>CMP_EPSILON) { //this is a ray, before the emiting pos (p_from) doesnt exist
|
if (dist > CMP_EPSILON) { //this is a ray, before the emiting pos (p_from) doesnt exist
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dist=-dist;
|
dist = -dist;
|
||||||
*p_intersection = p_from + segment * dist;
|
*p_intersection = p_from + segment * dist;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Plane::intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3* p_intersection) const {
|
bool Plane::intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3 *p_intersection) const {
|
||||||
|
|
||||||
Vector3 segment= p_begin - p_end;
|
Vector3 segment = p_begin - p_end;
|
||||||
real_t den=normal.dot( segment );
|
real_t den = normal.dot(segment);
|
||||||
|
|
||||||
//printf("den is %i\n",den);
|
//printf("den is %i\n",den);
|
||||||
if (::fabs(den)<=CMP_EPSILON) {
|
if (::fabs(den) <= CMP_EPSILON) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t dist=(normal.dot( p_begin ) - d) / den;
|
real_t dist = (normal.dot(p_begin) - d) / den;
|
||||||
//printf("dist is %i\n",dist);
|
//printf("dist is %i\n",dist);
|
||||||
|
|
||||||
if (dist<-CMP_EPSILON || dist > (1.0 +CMP_EPSILON)) {
|
if (dist < -CMP_EPSILON || dist > (1.0 + CMP_EPSILON)) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dist=-dist;
|
dist = -dist;
|
||||||
*p_intersection = p_begin + segment * dist;
|
*p_intersection = p_begin + segment * dist;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -134,20 +130,17 @@ bool Plane::intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3* p_inters
|
||||||
|
|
||||||
/* misc */
|
/* misc */
|
||||||
|
|
||||||
bool Plane::is_almost_like(const Plane& p_plane) const {
|
bool Plane::is_almost_like(const Plane &p_plane) const {
|
||||||
|
|
||||||
return (normal.dot( p_plane.normal ) > _PLANE_EQ_DOT_EPSILON && ::fabs(d-p_plane.d) < _PLANE_EQ_D_EPSILON);
|
return (normal.dot(p_plane.normal) > _PLANE_EQ_DOT_EPSILON && ::fabs(d - p_plane.d) < _PLANE_EQ_D_EPSILON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Plane::operator String() const {
|
Plane::operator String() const {
|
||||||
|
|
||||||
// return normal.operator String() + ", " + rtos(d);
|
// return normal.operator String() + ", " + rtos(d);
|
||||||
return String(); // @Todo
|
return String(); // @Todo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Plane::is_point_over(const Vector3 &p_point) const {
|
bool Plane::is_point_over(const Vector3 &p_point) const {
|
||||||
|
|
||||||
return (normal.dot(p_point) > d);
|
return (normal.dot(p_point) > d);
|
||||||
|
@ -155,55 +148,47 @@ bool Plane::is_point_over(const Vector3 &p_point) const {
|
||||||
|
|
||||||
real_t Plane::distance_to(const Vector3 &p_point) const {
|
real_t Plane::distance_to(const Vector3 &p_point) const {
|
||||||
|
|
||||||
return (normal.dot(p_point)-d);
|
return (normal.dot(p_point) - d);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Plane::has_point(const Vector3 &p_point,real_t _epsilon) const {
|
bool Plane::has_point(const Vector3 &p_point, real_t _epsilon) const {
|
||||||
|
|
||||||
real_t dist=normal.dot(p_point) - d;
|
|
||||||
dist=::fabs(dist);
|
|
||||||
return ( dist <= _epsilon);
|
|
||||||
|
|
||||||
|
real_t dist = normal.dot(p_point) - d;
|
||||||
|
dist = ::fabs(dist);
|
||||||
|
return (dist <= _epsilon);
|
||||||
}
|
}
|
||||||
|
|
||||||
Plane::Plane(const Vector3 &p_normal, real_t p_d) {
|
Plane::Plane(const Vector3 &p_normal, real_t p_d) {
|
||||||
|
|
||||||
normal=p_normal;
|
normal = p_normal;
|
||||||
d=p_d;
|
d = p_d;
|
||||||
}
|
}
|
||||||
|
|
||||||
Plane::Plane(const Vector3 &p_point, const Vector3& p_normal) {
|
Plane::Plane(const Vector3 &p_point, const Vector3 &p_normal) {
|
||||||
|
|
||||||
normal=p_normal;
|
normal = p_normal;
|
||||||
d=p_normal.dot(p_point);
|
d = p_normal.dot(p_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
Plane::Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_point3,ClockDirection p_dir) {
|
Plane::Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_point3, ClockDirection p_dir) {
|
||||||
|
|
||||||
if (p_dir == CLOCKWISE)
|
if (p_dir == CLOCKWISE)
|
||||||
normal=(p_point1-p_point3).cross(p_point1-p_point2);
|
normal = (p_point1 - p_point3).cross(p_point1 - p_point2);
|
||||||
else
|
else
|
||||||
normal=(p_point1-p_point2).cross(p_point1-p_point3);
|
normal = (p_point1 - p_point2).cross(p_point1 - p_point3);
|
||||||
|
|
||||||
|
|
||||||
normal.normalize();
|
normal.normalize();
|
||||||
d = normal.dot(p_point1);
|
d = normal.dot(p_point1);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Plane::operator==(const Plane& p_plane) const {
|
bool Plane::operator==(const Plane &p_plane) const {
|
||||||
|
|
||||||
return normal==p_plane.normal && d == p_plane.d;
|
return normal == p_plane.normal && d == p_plane.d;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Plane::operator!=(const Plane& p_plane) const {
|
bool Plane::operator!=(const Plane &p_plane) const {
|
||||||
|
|
||||||
return normal!=p_plane.normal || d != p_plane.d;
|
|
||||||
|
|
||||||
|
return normal != p_plane.normal || d != p_plane.d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,679 +1,541 @@
|
||||||
#include "PoolArrays.hpp"
|
#include "PoolArrays.hpp"
|
||||||
#include "Defs.hpp"
|
|
||||||
#include "String.hpp"
|
|
||||||
#include "Color.hpp"
|
#include "Color.hpp"
|
||||||
|
#include "Defs.hpp"
|
||||||
|
#include "GodotGlobal.hpp"
|
||||||
|
#include "String.hpp"
|
||||||
#include "Vector2.hpp"
|
#include "Vector2.hpp"
|
||||||
#include "Vector3.hpp"
|
#include "Vector3.hpp"
|
||||||
#include "GodotGlobal.hpp"
|
|
||||||
|
|
||||||
#include <gdnative/pool_arrays.h>
|
#include <gdnative/pool_arrays.h>
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
PoolByteArray::PoolByteArray()
|
PoolByteArray::PoolByteArray() {
|
||||||
{
|
|
||||||
godot::api->godot_pool_byte_array_new(&_godot_array);
|
godot::api->godot_pool_byte_array_new(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolByteArray::PoolByteArray(const PoolByteArray &p_other)
|
PoolByteArray::PoolByteArray(const PoolByteArray &p_other) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_byte_array_new_copy(&_godot_array, &p_other._godot_array);
|
godot::api->godot_pool_byte_array_new_copy(&_godot_array, &p_other._godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolByteArray &PoolByteArray::operator=(const PoolByteArray & p_other)
|
PoolByteArray &PoolByteArray::operator=(const PoolByteArray &p_other) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_byte_array_destroy(&_godot_array);
|
godot::api->godot_pool_byte_array_destroy(&_godot_array);
|
||||||
godot::api->godot_pool_byte_array_new_copy(&_godot_array, &p_other._godot_array);
|
godot::api->godot_pool_byte_array_new_copy(&_godot_array, &p_other._godot_array);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolByteArray::PoolByteArray(const Array& array)
|
PoolByteArray::PoolByteArray(const Array &array) {
|
||||||
{
|
godot::api->godot_pool_byte_array_new_with_array(&_godot_array, (godot_array *)&array);
|
||||||
godot::api->godot_pool_byte_array_new_with_array(&_godot_array, (godot_array *) &array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolByteArray::Read PoolByteArray::read() const
|
PoolByteArray::Read PoolByteArray::read() const {
|
||||||
{
|
|
||||||
Read read;
|
Read read;
|
||||||
read._read_access = godot::api->godot_pool_byte_array_read(&_godot_array);
|
read._read_access = godot::api->godot_pool_byte_array_read(&_godot_array);
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolByteArray::Write PoolByteArray::write()
|
PoolByteArray::Write PoolByteArray::write() {
|
||||||
{
|
|
||||||
Write write;
|
Write write;
|
||||||
write._write_access = godot::api->godot_pool_byte_array_write(&_godot_array);
|
write._write_access = godot::api->godot_pool_byte_array_write(&_godot_array);
|
||||||
return write;
|
return write;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolByteArray::append(const uint8_t data)
|
void PoolByteArray::append(const uint8_t data) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_byte_array_append(&_godot_array, data);
|
godot::api->godot_pool_byte_array_append(&_godot_array, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolByteArray::append_array(const PoolByteArray& array)
|
void PoolByteArray::append_array(const PoolByteArray &array) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_byte_array_append_array(&_godot_array, &array._godot_array);
|
godot::api->godot_pool_byte_array_append_array(&_godot_array, &array._godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolByteArray::insert(const int idx, const uint8_t data)
|
int PoolByteArray::insert(const int idx, const uint8_t data) {
|
||||||
{
|
|
||||||
return godot::api->godot_pool_byte_array_insert(&_godot_array, idx, data);
|
return godot::api->godot_pool_byte_array_insert(&_godot_array, idx, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolByteArray::invert()
|
void PoolByteArray::invert() {
|
||||||
{
|
|
||||||
godot::api->godot_pool_byte_array_invert(&_godot_array);
|
godot::api->godot_pool_byte_array_invert(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolByteArray::push_back(const uint8_t data)
|
void PoolByteArray::push_back(const uint8_t data) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_byte_array_push_back(&_godot_array, data);
|
godot::api->godot_pool_byte_array_push_back(&_godot_array, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolByteArray::remove(const int idx)
|
void PoolByteArray::remove(const int idx) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_byte_array_remove(&_godot_array, idx);
|
godot::api->godot_pool_byte_array_remove(&_godot_array, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolByteArray::resize(const int size)
|
void PoolByteArray::resize(const int size) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_byte_array_resize(&_godot_array, size);
|
godot::api->godot_pool_byte_array_resize(&_godot_array, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolByteArray::set(const int idx, const uint8_t data)
|
void PoolByteArray::set(const int idx, const uint8_t data) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_byte_array_set(&_godot_array, idx, data);
|
godot::api->godot_pool_byte_array_set(&_godot_array, idx, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t PoolByteArray::operator [](const int idx)
|
uint8_t PoolByteArray::operator[](const int idx) {
|
||||||
{
|
|
||||||
return godot::api->godot_pool_byte_array_get(&_godot_array, idx);
|
return godot::api->godot_pool_byte_array_get(&_godot_array, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolByteArray::size() const
|
int PoolByteArray::size() const {
|
||||||
{
|
|
||||||
return godot::api->godot_pool_byte_array_size(&_godot_array);
|
return godot::api->godot_pool_byte_array_size(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolByteArray::~PoolByteArray() {
|
||||||
PoolByteArray::~PoolByteArray()
|
|
||||||
{
|
|
||||||
godot::api->godot_pool_byte_array_destroy(&_godot_array);
|
godot::api->godot_pool_byte_array_destroy(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolIntArray::PoolIntArray() {
|
||||||
|
|
||||||
PoolIntArray::PoolIntArray()
|
|
||||||
{
|
|
||||||
godot::api->godot_pool_int_array_new(&_godot_array);
|
godot::api->godot_pool_int_array_new(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolIntArray::PoolIntArray(const PoolIntArray &p_other)
|
PoolIntArray::PoolIntArray(const PoolIntArray &p_other) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_int_array_new_copy(&_godot_array, &p_other._godot_array);
|
godot::api->godot_pool_int_array_new_copy(&_godot_array, &p_other._godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolIntArray &PoolIntArray::operator=(const PoolIntArray &p_other)
|
PoolIntArray &PoolIntArray::operator=(const PoolIntArray &p_other) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_int_array_destroy(&_godot_array);
|
godot::api->godot_pool_int_array_destroy(&_godot_array);
|
||||||
godot::api->godot_pool_int_array_new_copy(&_godot_array, &p_other._godot_array);
|
godot::api->godot_pool_int_array_new_copy(&_godot_array, &p_other._godot_array);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolIntArray::PoolIntArray(const Array& array)
|
PoolIntArray::PoolIntArray(const Array &array) {
|
||||||
{
|
godot::api->godot_pool_int_array_new_with_array(&_godot_array, (godot_array *)&array);
|
||||||
godot::api->godot_pool_int_array_new_with_array(&_godot_array, (godot_array *) &array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolIntArray::Read PoolIntArray::read() const
|
PoolIntArray::Read PoolIntArray::read() const {
|
||||||
{
|
|
||||||
Read read;
|
Read read;
|
||||||
read._read_access = godot::api->godot_pool_int_array_read(&_godot_array);
|
read._read_access = godot::api->godot_pool_int_array_read(&_godot_array);
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolIntArray::Write PoolIntArray::write()
|
PoolIntArray::Write PoolIntArray::write() {
|
||||||
{
|
|
||||||
Write write;
|
Write write;
|
||||||
write._write_access = godot::api->godot_pool_int_array_write(&_godot_array);
|
write._write_access = godot::api->godot_pool_int_array_write(&_godot_array);
|
||||||
return write;
|
return write;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolIntArray::append(const int data)
|
void PoolIntArray::append(const int data) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_int_array_append(&_godot_array, data);
|
godot::api->godot_pool_int_array_append(&_godot_array, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolIntArray::append_array(const PoolIntArray& array)
|
void PoolIntArray::append_array(const PoolIntArray &array) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_int_array_append_array(&_godot_array, &array._godot_array);
|
godot::api->godot_pool_int_array_append_array(&_godot_array, &array._godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolIntArray::insert(const int idx, const int data)
|
int PoolIntArray::insert(const int idx, const int data) {
|
||||||
{
|
|
||||||
return godot::api->godot_pool_int_array_insert(&_godot_array, idx, data);
|
return godot::api->godot_pool_int_array_insert(&_godot_array, idx, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolIntArray::invert()
|
void PoolIntArray::invert() {
|
||||||
{
|
|
||||||
godot::api->godot_pool_int_array_invert(&_godot_array);
|
godot::api->godot_pool_int_array_invert(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolIntArray::push_back(const int data)
|
void PoolIntArray::push_back(const int data) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_int_array_push_back(&_godot_array, data);
|
godot::api->godot_pool_int_array_push_back(&_godot_array, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolIntArray::remove(const int idx)
|
void PoolIntArray::remove(const int idx) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_int_array_remove(&_godot_array, idx);
|
godot::api->godot_pool_int_array_remove(&_godot_array, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolIntArray::resize(const int size)
|
void PoolIntArray::resize(const int size) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_int_array_resize(&_godot_array, size);
|
godot::api->godot_pool_int_array_resize(&_godot_array, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolIntArray::set(const int idx, const int data)
|
void PoolIntArray::set(const int idx, const int data) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_int_array_set(&_godot_array, idx, data);
|
godot::api->godot_pool_int_array_set(&_godot_array, idx, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolIntArray::operator [](const int idx)
|
int PoolIntArray::operator[](const int idx) {
|
||||||
{
|
|
||||||
return godot::api->godot_pool_int_array_get(&_godot_array, idx);
|
return godot::api->godot_pool_int_array_get(&_godot_array, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolIntArray::size() const
|
int PoolIntArray::size() const {
|
||||||
{
|
|
||||||
return godot::api->godot_pool_int_array_size(&_godot_array);
|
return godot::api->godot_pool_int_array_size(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolIntArray::~PoolIntArray() {
|
||||||
PoolIntArray::~PoolIntArray()
|
|
||||||
{
|
|
||||||
godot::api->godot_pool_int_array_destroy(&_godot_array);
|
godot::api->godot_pool_int_array_destroy(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolRealArray::PoolRealArray() {
|
||||||
PoolRealArray::PoolRealArray()
|
|
||||||
{
|
|
||||||
godot::api->godot_pool_real_array_new(&_godot_array);
|
godot::api->godot_pool_real_array_new(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolRealArray::PoolRealArray(const PoolRealArray &p_other)
|
PoolRealArray::PoolRealArray(const PoolRealArray &p_other) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_real_array_new_copy(&_godot_array, &p_other._godot_array);
|
godot::api->godot_pool_real_array_new_copy(&_godot_array, &p_other._godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolRealArray &PoolRealArray::operator=(const PoolRealArray &p_other)
|
PoolRealArray &PoolRealArray::operator=(const PoolRealArray &p_other) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_real_array_destroy(&_godot_array);
|
godot::api->godot_pool_real_array_destroy(&_godot_array);
|
||||||
godot::api->godot_pool_real_array_new_copy(&_godot_array, &p_other._godot_array);
|
godot::api->godot_pool_real_array_new_copy(&_godot_array, &p_other._godot_array);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolRealArray::Read PoolRealArray::read() const
|
PoolRealArray::Read PoolRealArray::read() const {
|
||||||
{
|
|
||||||
Read read;
|
Read read;
|
||||||
read._read_access = godot::api->godot_pool_real_array_read(&_godot_array);
|
read._read_access = godot::api->godot_pool_real_array_read(&_godot_array);
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolRealArray::Write PoolRealArray::write()
|
PoolRealArray::Write PoolRealArray::write() {
|
||||||
{
|
|
||||||
Write write;
|
Write write;
|
||||||
write._write_access = godot::api->godot_pool_real_array_write(&_godot_array);
|
write._write_access = godot::api->godot_pool_real_array_write(&_godot_array);
|
||||||
return write;
|
return write;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolRealArray::PoolRealArray(const Array& array)
|
PoolRealArray::PoolRealArray(const Array &array) {
|
||||||
{
|
godot::api->godot_pool_real_array_new_with_array(&_godot_array, (godot_array *)&array);
|
||||||
godot::api->godot_pool_real_array_new_with_array(&_godot_array, (godot_array *) &array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolRealArray::append(const real_t data)
|
void PoolRealArray::append(const real_t data) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_real_array_append(&_godot_array, data);
|
godot::api->godot_pool_real_array_append(&_godot_array, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolRealArray::append_array(const PoolRealArray& array)
|
void PoolRealArray::append_array(const PoolRealArray &array) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_real_array_append_array(&_godot_array, &array._godot_array);
|
godot::api->godot_pool_real_array_append_array(&_godot_array, &array._godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolRealArray::insert(const int idx, const real_t data)
|
int PoolRealArray::insert(const int idx, const real_t data) {
|
||||||
{
|
|
||||||
return godot::api->godot_pool_real_array_insert(&_godot_array, idx, data);
|
return godot::api->godot_pool_real_array_insert(&_godot_array, idx, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolRealArray::invert()
|
void PoolRealArray::invert() {
|
||||||
{
|
|
||||||
godot::api->godot_pool_real_array_invert(&_godot_array);
|
godot::api->godot_pool_real_array_invert(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolRealArray::push_back(const real_t data)
|
void PoolRealArray::push_back(const real_t data) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_real_array_push_back(&_godot_array, data);
|
godot::api->godot_pool_real_array_push_back(&_godot_array, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolRealArray::remove(const int idx)
|
void PoolRealArray::remove(const int idx) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_real_array_remove(&_godot_array, idx);
|
godot::api->godot_pool_real_array_remove(&_godot_array, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolRealArray::resize(const int size)
|
void PoolRealArray::resize(const int size) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_real_array_resize(&_godot_array, size);
|
godot::api->godot_pool_real_array_resize(&_godot_array, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolRealArray::set(const int idx, const real_t data)
|
void PoolRealArray::set(const int idx, const real_t data) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_real_array_set(&_godot_array, idx, data);
|
godot::api->godot_pool_real_array_set(&_godot_array, idx, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t PoolRealArray::operator [](const int idx)
|
real_t PoolRealArray::operator[](const int idx) {
|
||||||
{
|
|
||||||
return godot::api->godot_pool_real_array_get(&_godot_array, idx);
|
return godot::api->godot_pool_real_array_get(&_godot_array, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolRealArray::size() const
|
int PoolRealArray::size() const {
|
||||||
{
|
|
||||||
return godot::api->godot_pool_real_array_size(&_godot_array);
|
return godot::api->godot_pool_real_array_size(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolRealArray::~PoolRealArray() {
|
||||||
PoolRealArray::~PoolRealArray()
|
|
||||||
{
|
|
||||||
godot::api->godot_pool_real_array_destroy(&_godot_array);
|
godot::api->godot_pool_real_array_destroy(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolStringArray::PoolStringArray() {
|
||||||
|
|
||||||
PoolStringArray::PoolStringArray()
|
|
||||||
{
|
|
||||||
godot::api->godot_pool_string_array_new(&_godot_array);
|
godot::api->godot_pool_string_array_new(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolStringArray::PoolStringArray(const PoolStringArray &p_other)
|
PoolStringArray::PoolStringArray(const PoolStringArray &p_other) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_string_array_new_copy(&_godot_array, &p_other._godot_array);
|
godot::api->godot_pool_string_array_new_copy(&_godot_array, &p_other._godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolStringArray &PoolStringArray::operator=(const PoolStringArray &p_other)
|
PoolStringArray &PoolStringArray::operator=(const PoolStringArray &p_other) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_string_array_destroy(&_godot_array);
|
godot::api->godot_pool_string_array_destroy(&_godot_array);
|
||||||
godot::api->godot_pool_string_array_new_copy(&_godot_array, &p_other._godot_array);
|
godot::api->godot_pool_string_array_new_copy(&_godot_array, &p_other._godot_array);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolStringArray::PoolStringArray(const Array& array)
|
PoolStringArray::PoolStringArray(const Array &array) {
|
||||||
{
|
godot::api->godot_pool_string_array_new_with_array(&_godot_array, (godot_array *)&array);
|
||||||
godot::api->godot_pool_string_array_new_with_array(&_godot_array, (godot_array *) &array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolStringArray::Read PoolStringArray::read() const
|
PoolStringArray::Read PoolStringArray::read() const {
|
||||||
{
|
|
||||||
Read read;
|
Read read;
|
||||||
read._read_access = godot::api->godot_pool_string_array_read(&_godot_array);
|
read._read_access = godot::api->godot_pool_string_array_read(&_godot_array);
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolStringArray::Write PoolStringArray::write()
|
PoolStringArray::Write PoolStringArray::write() {
|
||||||
{
|
|
||||||
Write write;
|
Write write;
|
||||||
write._write_access = godot::api->godot_pool_string_array_write(&_godot_array);
|
write._write_access = godot::api->godot_pool_string_array_write(&_godot_array);
|
||||||
return write;
|
return write;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolStringArray::append(const String& data)
|
void PoolStringArray::append(const String &data) {
|
||||||
{
|
godot::api->godot_pool_string_array_append(&_godot_array, (godot_string *)&data);
|
||||||
godot::api->godot_pool_string_array_append(&_godot_array, (godot_string *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolStringArray::append_array(const PoolStringArray& array)
|
void PoolStringArray::append_array(const PoolStringArray &array) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_string_array_append_array(&_godot_array, &array._godot_array);
|
godot::api->godot_pool_string_array_append_array(&_godot_array, &array._godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolStringArray::insert(const int idx, const String& data)
|
int PoolStringArray::insert(const int idx, const String &data) {
|
||||||
{
|
return godot::api->godot_pool_string_array_insert(&_godot_array, idx, (godot_string *)&data);
|
||||||
return godot::api->godot_pool_string_array_insert(&_godot_array, idx, (godot_string *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolStringArray::invert()
|
void PoolStringArray::invert() {
|
||||||
{
|
|
||||||
godot::api->godot_pool_string_array_invert(&_godot_array);
|
godot::api->godot_pool_string_array_invert(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolStringArray::push_back(const String& data)
|
void PoolStringArray::push_back(const String &data) {
|
||||||
{
|
godot::api->godot_pool_string_array_push_back(&_godot_array, (godot_string *)&data);
|
||||||
godot::api->godot_pool_string_array_push_back(&_godot_array, (godot_string *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolStringArray::remove(const int idx)
|
void PoolStringArray::remove(const int idx) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_string_array_remove(&_godot_array, idx);
|
godot::api->godot_pool_string_array_remove(&_godot_array, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolStringArray::resize(const int size)
|
void PoolStringArray::resize(const int size) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_string_array_resize(&_godot_array, size);
|
godot::api->godot_pool_string_array_resize(&_godot_array, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolStringArray::set(const int idx, const String& data)
|
void PoolStringArray::set(const int idx, const String &data) {
|
||||||
{
|
godot::api->godot_pool_string_array_set(&_godot_array, idx, (godot_string *)&data);
|
||||||
godot::api->godot_pool_string_array_set(&_godot_array, idx, (godot_string *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const String PoolStringArray::operator [](const int idx)
|
const String PoolStringArray::operator[](const int idx) {
|
||||||
{
|
|
||||||
String s;
|
String s;
|
||||||
godot_string str = godot::api->godot_pool_string_array_get(&_godot_array, idx);
|
godot_string str = godot::api->godot_pool_string_array_get(&_godot_array, idx);
|
||||||
godot::api->godot_string_new_copy((godot_string *) &s, &str);
|
godot::api->godot_string_new_copy((godot_string *)&s, &str);
|
||||||
godot::api->godot_string_destroy(&str);
|
godot::api->godot_string_destroy(&str);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolStringArray::size() const
|
int PoolStringArray::size() const {
|
||||||
{
|
|
||||||
return godot::api->godot_pool_string_array_size(&_godot_array);
|
return godot::api->godot_pool_string_array_size(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolStringArray::~PoolStringArray() {
|
||||||
PoolStringArray::~PoolStringArray()
|
|
||||||
{
|
|
||||||
godot::api->godot_pool_string_array_destroy(&_godot_array);
|
godot::api->godot_pool_string_array_destroy(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolVector2Array::PoolVector2Array() {
|
||||||
|
|
||||||
PoolVector2Array::PoolVector2Array()
|
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector2_array_new(&_godot_array);
|
godot::api->godot_pool_vector2_array_new(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolVector2Array::PoolVector2Array(const PoolVector2Array &p_other)
|
PoolVector2Array::PoolVector2Array(const PoolVector2Array &p_other) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector2_array_new_copy(&_godot_array, &p_other._godot_array);
|
godot::api->godot_pool_vector2_array_new_copy(&_godot_array, &p_other._godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolVector2Array &PoolVector2Array::operator=(const PoolVector2Array &p_other)
|
PoolVector2Array &PoolVector2Array::operator=(const PoolVector2Array &p_other) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector2_array_destroy(&_godot_array);
|
godot::api->godot_pool_vector2_array_destroy(&_godot_array);
|
||||||
godot::api->godot_pool_vector2_array_new_copy(&_godot_array, &p_other._godot_array);
|
godot::api->godot_pool_vector2_array_new_copy(&_godot_array, &p_other._godot_array);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolVector2Array::PoolVector2Array(const Array& array)
|
PoolVector2Array::PoolVector2Array(const Array &array) {
|
||||||
{
|
godot::api->godot_pool_vector2_array_new_with_array(&_godot_array, (godot_array *)&array);
|
||||||
godot::api->godot_pool_vector2_array_new_with_array(&_godot_array, (godot_array *) &array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolVector2Array::Read PoolVector2Array::read() const
|
PoolVector2Array::Read PoolVector2Array::read() const {
|
||||||
{
|
|
||||||
Read read;
|
Read read;
|
||||||
read._read_access = godot::api->godot_pool_vector2_array_read(&_godot_array);
|
read._read_access = godot::api->godot_pool_vector2_array_read(&_godot_array);
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolVector2Array::Write PoolVector2Array::write()
|
PoolVector2Array::Write PoolVector2Array::write() {
|
||||||
{
|
|
||||||
Write write;
|
Write write;
|
||||||
write._write_access = godot::api->godot_pool_vector2_array_write(&_godot_array);
|
write._write_access = godot::api->godot_pool_vector2_array_write(&_godot_array);
|
||||||
return write;
|
return write;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolVector2Array::append(const Vector2& data)
|
void PoolVector2Array::append(const Vector2 &data) {
|
||||||
{
|
godot::api->godot_pool_vector2_array_append(&_godot_array, (godot_vector2 *)&data);
|
||||||
godot::api->godot_pool_vector2_array_append(&_godot_array, (godot_vector2 *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolVector2Array::append_array(const PoolVector2Array& array)
|
void PoolVector2Array::append_array(const PoolVector2Array &array) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector2_array_append_array(&_godot_array, &array._godot_array);
|
godot::api->godot_pool_vector2_array_append_array(&_godot_array, &array._godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolVector2Array::insert(const int idx, const Vector2& data)
|
int PoolVector2Array::insert(const int idx, const Vector2 &data) {
|
||||||
{
|
return godot::api->godot_pool_vector2_array_insert(&_godot_array, idx, (godot_vector2 *)&data);
|
||||||
return godot::api->godot_pool_vector2_array_insert(&_godot_array, idx, (godot_vector2 *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolVector2Array::invert()
|
void PoolVector2Array::invert() {
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector2_array_invert(&_godot_array);
|
godot::api->godot_pool_vector2_array_invert(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolVector2Array::push_back(const Vector2& data)
|
void PoolVector2Array::push_back(const Vector2 &data) {
|
||||||
{
|
godot::api->godot_pool_vector2_array_push_back(&_godot_array, (godot_vector2 *)&data);
|
||||||
godot::api->godot_pool_vector2_array_push_back(&_godot_array, (godot_vector2 *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolVector2Array::remove(const int idx)
|
void PoolVector2Array::remove(const int idx) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector2_array_remove(&_godot_array, idx);
|
godot::api->godot_pool_vector2_array_remove(&_godot_array, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolVector2Array::resize(const int size)
|
void PoolVector2Array::resize(const int size) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector2_array_resize(&_godot_array, size);
|
godot::api->godot_pool_vector2_array_resize(&_godot_array, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolVector2Array::set(const int idx, const Vector2& data)
|
void PoolVector2Array::set(const int idx, const Vector2 &data) {
|
||||||
{
|
godot::api->godot_pool_vector2_array_set(&_godot_array, idx, (godot_vector2 *)&data);
|
||||||
godot::api->godot_pool_vector2_array_set(&_godot_array, idx, (godot_vector2 *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector2 PoolVector2Array::operator [](const int idx)
|
const Vector2 PoolVector2Array::operator[](const int idx) {
|
||||||
{
|
|
||||||
Vector2 v;
|
Vector2 v;
|
||||||
*(godot_vector2 *) &v = godot::api->godot_pool_vector2_array_get(&_godot_array, idx);
|
*(godot_vector2 *)&v = godot::api->godot_pool_vector2_array_get(&_godot_array, idx);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolVector2Array::size() const
|
int PoolVector2Array::size() const {
|
||||||
{
|
|
||||||
return godot::api->godot_pool_vector2_array_size(&_godot_array);
|
return godot::api->godot_pool_vector2_array_size(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolVector2Array::~PoolVector2Array() {
|
||||||
PoolVector2Array::~PoolVector2Array()
|
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector2_array_destroy(&_godot_array);
|
godot::api->godot_pool_vector2_array_destroy(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolVector3Array::PoolVector3Array() {
|
||||||
|
|
||||||
PoolVector3Array::PoolVector3Array()
|
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector3_array_new(&_godot_array);
|
godot::api->godot_pool_vector3_array_new(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolVector3Array::PoolVector3Array(const PoolVector3Array &p_other)
|
PoolVector3Array::PoolVector3Array(const PoolVector3Array &p_other) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector3_array_new_copy(&_godot_array, &p_other._godot_array);
|
godot::api->godot_pool_vector3_array_new_copy(&_godot_array, &p_other._godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolVector3Array &PoolVector3Array::operator=(const PoolVector3Array &p_other)
|
PoolVector3Array &PoolVector3Array::operator=(const PoolVector3Array &p_other) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector3_array_destroy(&_godot_array);
|
godot::api->godot_pool_vector3_array_destroy(&_godot_array);
|
||||||
godot::api->godot_pool_vector3_array_new_copy(&_godot_array, &p_other._godot_array);
|
godot::api->godot_pool_vector3_array_new_copy(&_godot_array, &p_other._godot_array);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolVector3Array::PoolVector3Array(const Array& array)
|
PoolVector3Array::PoolVector3Array(const Array &array) {
|
||||||
{
|
godot::api->godot_pool_vector3_array_new_with_array(&_godot_array, (godot_array *)&array);
|
||||||
godot::api->godot_pool_vector3_array_new_with_array(&_godot_array, (godot_array *) &array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolVector3Array::Read PoolVector3Array::read() const
|
PoolVector3Array::Read PoolVector3Array::read() const {
|
||||||
{
|
|
||||||
Read read;
|
Read read;
|
||||||
read._read_access = godot::api->godot_pool_vector3_array_read(&_godot_array);
|
read._read_access = godot::api->godot_pool_vector3_array_read(&_godot_array);
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolVector3Array::Write PoolVector3Array::write()
|
PoolVector3Array::Write PoolVector3Array::write() {
|
||||||
{
|
|
||||||
Write write;
|
Write write;
|
||||||
write._write_access = godot::api->godot_pool_vector3_array_write(&_godot_array);
|
write._write_access = godot::api->godot_pool_vector3_array_write(&_godot_array);
|
||||||
return write;
|
return write;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolVector3Array::append(const Vector3& data)
|
void PoolVector3Array::append(const Vector3 &data) {
|
||||||
{
|
godot::api->godot_pool_vector3_array_append(&_godot_array, (godot_vector3 *)&data);
|
||||||
godot::api->godot_pool_vector3_array_append(&_godot_array, (godot_vector3 *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolVector3Array::append_array(const PoolVector3Array& array)
|
void PoolVector3Array::append_array(const PoolVector3Array &array) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector3_array_append_array(&_godot_array, &array._godot_array);
|
godot::api->godot_pool_vector3_array_append_array(&_godot_array, &array._godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolVector3Array::insert(const int idx, const Vector3& data)
|
int PoolVector3Array::insert(const int idx, const Vector3 &data) {
|
||||||
{
|
return godot::api->godot_pool_vector3_array_insert(&_godot_array, idx, (godot_vector3 *)&data);
|
||||||
return godot::api->godot_pool_vector3_array_insert(&_godot_array, idx, (godot_vector3 *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolVector3Array::invert()
|
void PoolVector3Array::invert() {
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector3_array_invert(&_godot_array);
|
godot::api->godot_pool_vector3_array_invert(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolVector3Array::push_back(const Vector3& data)
|
void PoolVector3Array::push_back(const Vector3 &data) {
|
||||||
{
|
godot::api->godot_pool_vector3_array_push_back(&_godot_array, (godot_vector3 *)&data);
|
||||||
godot::api->godot_pool_vector3_array_push_back(&_godot_array, (godot_vector3 *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolVector3Array::remove(const int idx)
|
void PoolVector3Array::remove(const int idx) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector3_array_remove(&_godot_array, idx);
|
godot::api->godot_pool_vector3_array_remove(&_godot_array, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolVector3Array::resize(const int size)
|
void PoolVector3Array::resize(const int size) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector3_array_resize(&_godot_array, size);
|
godot::api->godot_pool_vector3_array_resize(&_godot_array, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolVector3Array::set(const int idx, const Vector3& data)
|
void PoolVector3Array::set(const int idx, const Vector3 &data) {
|
||||||
{
|
godot::api->godot_pool_vector3_array_set(&_godot_array, idx, (godot_vector3 *)&data);
|
||||||
godot::api->godot_pool_vector3_array_set(&_godot_array, idx, (godot_vector3 *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Vector3 PoolVector3Array::operator [](const int idx)
|
const Vector3 PoolVector3Array::operator[](const int idx) {
|
||||||
{
|
|
||||||
Vector3 v;
|
Vector3 v;
|
||||||
*(godot_vector3 *) &v = godot::api->godot_pool_vector3_array_get(&_godot_array, idx);
|
*(godot_vector3 *)&v = godot::api->godot_pool_vector3_array_get(&_godot_array, idx);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolVector3Array::size() const
|
int PoolVector3Array::size() const {
|
||||||
{
|
|
||||||
return godot::api->godot_pool_vector3_array_size(&_godot_array);
|
return godot::api->godot_pool_vector3_array_size(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolVector3Array::~PoolVector3Array() {
|
||||||
PoolVector3Array::~PoolVector3Array()
|
|
||||||
{
|
|
||||||
godot::api->godot_pool_vector3_array_destroy(&_godot_array);
|
godot::api->godot_pool_vector3_array_destroy(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolColorArray::PoolColorArray() {
|
||||||
PoolColorArray::PoolColorArray()
|
|
||||||
{
|
|
||||||
godot::api->godot_pool_color_array_new(&_godot_array);
|
godot::api->godot_pool_color_array_new(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolColorArray::PoolColorArray(const PoolColorArray &p_other)
|
PoolColorArray::PoolColorArray(const PoolColorArray &p_other) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_color_array_new_copy(&_godot_array, &p_other._godot_array);
|
godot::api->godot_pool_color_array_new_copy(&_godot_array, &p_other._godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolColorArray &PoolColorArray::operator=(const PoolColorArray &p_other)
|
PoolColorArray &PoolColorArray::operator=(const PoolColorArray &p_other) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_color_array_destroy(&_godot_array);
|
godot::api->godot_pool_color_array_destroy(&_godot_array);
|
||||||
godot::api->godot_pool_color_array_new_copy(&_godot_array, &p_other._godot_array);
|
godot::api->godot_pool_color_array_new_copy(&_godot_array, &p_other._godot_array);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolColorArray::PoolColorArray(const Array& array)
|
PoolColorArray::PoolColorArray(const Array &array) {
|
||||||
{
|
godot::api->godot_pool_color_array_new_with_array(&_godot_array, (godot_array *)&array);
|
||||||
godot::api->godot_pool_color_array_new_with_array(&_godot_array, (godot_array *) &array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolColorArray::Read PoolColorArray::read() const
|
PoolColorArray::Read PoolColorArray::read() const {
|
||||||
{
|
|
||||||
Read read;
|
Read read;
|
||||||
read._read_access = godot::api->godot_pool_color_array_read(&_godot_array);
|
read._read_access = godot::api->godot_pool_color_array_read(&_godot_array);
|
||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
PoolColorArray::Write PoolColorArray::write()
|
PoolColorArray::Write PoolColorArray::write() {
|
||||||
{
|
|
||||||
Write write;
|
Write write;
|
||||||
write._write_access = godot::api->godot_pool_color_array_write(&_godot_array);
|
write._write_access = godot::api->godot_pool_color_array_write(&_godot_array);
|
||||||
return write;
|
return write;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolColorArray::append(const Color& data)
|
void PoolColorArray::append(const Color &data) {
|
||||||
{
|
godot::api->godot_pool_color_array_append(&_godot_array, (godot_color *)&data);
|
||||||
godot::api->godot_pool_color_array_append(&_godot_array, (godot_color *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolColorArray::append_array(const PoolColorArray& array)
|
void PoolColorArray::append_array(const PoolColorArray &array) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_color_array_append_array(&_godot_array, &array._godot_array);
|
godot::api->godot_pool_color_array_append_array(&_godot_array, &array._godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolColorArray::insert(const int idx, const Color& data)
|
int PoolColorArray::insert(const int idx, const Color &data) {
|
||||||
{
|
return godot::api->godot_pool_color_array_insert(&_godot_array, idx, (godot_color *)&data);
|
||||||
return godot::api->godot_pool_color_array_insert(&_godot_array, idx, (godot_color *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolColorArray::invert()
|
void PoolColorArray::invert() {
|
||||||
{
|
|
||||||
godot::api->godot_pool_color_array_invert(&_godot_array);
|
godot::api->godot_pool_color_array_invert(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolColorArray::push_back(const Color& data)
|
void PoolColorArray::push_back(const Color &data) {
|
||||||
{
|
godot::api->godot_pool_color_array_push_back(&_godot_array, (godot_color *)&data);
|
||||||
godot::api->godot_pool_color_array_push_back(&_godot_array, (godot_color *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolColorArray::remove(const int idx)
|
void PoolColorArray::remove(const int idx) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_color_array_remove(&_godot_array, idx);
|
godot::api->godot_pool_color_array_remove(&_godot_array, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolColorArray::resize(const int size)
|
void PoolColorArray::resize(const int size) {
|
||||||
{
|
|
||||||
godot::api->godot_pool_color_array_resize(&_godot_array, size);
|
godot::api->godot_pool_color_array_resize(&_godot_array, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PoolColorArray::set(const int idx, const Color& data)
|
void PoolColorArray::set(const int idx, const Color &data) {
|
||||||
{
|
godot::api->godot_pool_color_array_set(&_godot_array, idx, (godot_color *)&data);
|
||||||
godot::api->godot_pool_color_array_set(&_godot_array, idx, (godot_color *) &data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Color PoolColorArray::operator [](const int idx)
|
const Color PoolColorArray::operator[](const int idx) {
|
||||||
{
|
|
||||||
Color v;
|
Color v;
|
||||||
*(godot_color *) &v = godot::api->godot_pool_color_array_get(&_godot_array, idx);
|
*(godot_color *)&v = godot::api->godot_pool_color_array_get(&_godot_array, idx);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PoolColorArray::size() const
|
int PoolColorArray::size() const {
|
||||||
{
|
|
||||||
return godot::api->godot_pool_color_array_size(&_godot_array);
|
return godot::api->godot_pool_color_array_size(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PoolColorArray::~PoolColorArray() {
|
||||||
PoolColorArray::~PoolColorArray()
|
|
||||||
{
|
|
||||||
godot::api->godot_pool_color_array_destroy(&_godot_array);
|
godot::api->godot_pool_color_array_destroy(&_godot_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "Quat.hpp"
|
#include "Quat.hpp"
|
||||||
|
#include "Basis.hpp"
|
||||||
#include "Defs.hpp"
|
#include "Defs.hpp"
|
||||||
#include "Vector3.hpp"
|
#include "Vector3.hpp"
|
||||||
#include "Basis.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
@ -77,42 +77,37 @@ Vector3 Quat::get_euler_yxz() const {
|
||||||
return m.get_euler_yxz();
|
return m.get_euler_yxz();
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Quat::length() const
|
real_t Quat::length() const {
|
||||||
{
|
|
||||||
return ::sqrt(length_squared());
|
return ::sqrt(length_squared());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quat::normalize()
|
void Quat::normalize() {
|
||||||
{
|
|
||||||
*this /= length();
|
*this /= length();
|
||||||
}
|
}
|
||||||
|
|
||||||
Quat Quat::normalized() const
|
Quat Quat::normalized() const {
|
||||||
{
|
|
||||||
return *this / length();
|
return *this / length();
|
||||||
}
|
}
|
||||||
|
|
||||||
Quat Quat::inverse() const
|
Quat Quat::inverse() const {
|
||||||
{
|
return Quat(-x, -y, -z, w);
|
||||||
return Quat( -x, -y, -z, w );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Quat Quat::slerp(const Quat& q, const real_t& t) const {
|
Quat Quat::slerp(const Quat &q, const real_t &t) const {
|
||||||
|
|
||||||
Quat to1;
|
Quat to1;
|
||||||
real_t omega, cosom, sinom, scale0, scale1;
|
real_t omega, cosom, sinom, scale0, scale1;
|
||||||
|
|
||||||
|
|
||||||
// calc cosine
|
// calc cosine
|
||||||
cosom = dot(q);
|
cosom = dot(q);
|
||||||
|
|
||||||
// adjust signs (if necessary)
|
// adjust signs (if necessary)
|
||||||
if ( cosom <0.0 ) {
|
if (cosom < 0.0) {
|
||||||
cosom = -cosom;
|
cosom = -cosom;
|
||||||
to1.x = - q.x;
|
to1.x = -q.x;
|
||||||
to1.y = - q.y;
|
to1.y = -q.y;
|
||||||
to1.z = - q.z;
|
to1.z = -q.z;
|
||||||
to1.w = - q.w;
|
to1.w = -q.w;
|
||||||
} else {
|
} else {
|
||||||
to1.x = q.x;
|
to1.x = q.x;
|
||||||
to1.y = q.y;
|
to1.y = q.y;
|
||||||
|
@ -120,10 +115,9 @@ Quat Quat::slerp(const Quat& q, const real_t& t) const {
|
||||||
to1.w = q.w;
|
to1.w = q.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// calculate coefficients
|
// calculate coefficients
|
||||||
|
|
||||||
if ( (1.0 - cosom) > CMP_EPSILON ) {
|
if ((1.0 - cosom) > CMP_EPSILON) {
|
||||||
// standard case (slerp)
|
// standard case (slerp)
|
||||||
omega = ::acos(cosom);
|
omega = ::acos(cosom);
|
||||||
sinom = ::sin(omega);
|
sinom = ::sin(omega);
|
||||||
|
@ -140,11 +134,10 @@ Quat Quat::slerp(const Quat& q, const real_t& t) const {
|
||||||
scale0 * x + scale1 * to1.x,
|
scale0 * x + scale1 * to1.x,
|
||||||
scale0 * y + scale1 * to1.y,
|
scale0 * y + scale1 * to1.y,
|
||||||
scale0 * z + scale1 * to1.z,
|
scale0 * z + scale1 * to1.z,
|
||||||
scale0 * w + scale1 * to1.w
|
scale0 * w + scale1 * to1.w);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Quat Quat::slerpni(const Quat& q, const real_t& t) const {
|
Quat Quat::slerpni(const Quat &q, const real_t &t) const {
|
||||||
|
|
||||||
const Quat &from = *this;
|
const Quat &from = *this;
|
||||||
|
|
||||||
|
@ -163,51 +156,43 @@ Quat Quat::slerpni(const Quat& q, const real_t& t) const {
|
||||||
invFactor * from.w + newFactor * q.w);
|
invFactor * from.w + newFactor * q.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
Quat Quat::cubic_slerp(const Quat& q, const Quat& prep, const Quat& postq,const real_t& t) const
|
Quat Quat::cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const {
|
||||||
{
|
|
||||||
//the only way to do slerp :|
|
//the only way to do slerp :|
|
||||||
real_t t2 = (1.0-t)*t*2;
|
real_t t2 = (1.0 - t) * t * 2;
|
||||||
Quat sp = this->slerp(q,t);
|
Quat sp = this->slerp(q, t);
|
||||||
Quat sq = prep.slerpni(postq,t);
|
Quat sq = prep.slerpni(postq, t);
|
||||||
return sp.slerpni(sq,t2);
|
return sp.slerpni(sq, t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quat::get_axis_and_angle(Vector3& r_axis, real_t &r_angle) const {
|
void Quat::get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const {
|
||||||
r_angle = 2 * ::acos(w);
|
r_angle = 2 * ::acos(w);
|
||||||
r_axis.x = x / ::sqrt(1-w*w);
|
r_axis.x = x / ::sqrt(1 - w * w);
|
||||||
r_axis.y = y / ::sqrt(1-w*w);
|
r_axis.y = y / ::sqrt(1 - w * w);
|
||||||
r_axis.z = z / ::sqrt(1-w*w);
|
r_axis.z = z / ::sqrt(1 - w * w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Quat Quat::operator*(const Vector3 &v) const {
|
||||||
|
return Quat(w * v.x + y * v.z - z * v.y,
|
||||||
Quat Quat::operator*(const Vector3& v) const
|
|
||||||
{
|
|
||||||
return Quat( w * v.x + y * v.z - z * v.y,
|
|
||||||
w * v.y + z * v.x - x * v.z,
|
w * v.y + z * v.x - x * v.z,
|
||||||
w * v.z + x * v.y - y * v.x,
|
w * v.z + x * v.y - y * v.x,
|
||||||
-x * v.x - y * v.y - z * v.z);
|
-x * v.x - y * v.y - z * v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Quat::xform(const Vector3& v) const {
|
Vector3 Quat::xform(const Vector3 &v) const {
|
||||||
|
|
||||||
Quat q = *this * v;
|
Quat q = *this * v;
|
||||||
q *= this->inverse();
|
q *= this->inverse();
|
||||||
return Vector3(q.x,q.y,q.z);
|
return Vector3(q.x, q.y, q.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Quat::operator String() const {
|
||||||
Quat::operator String() const
|
|
||||||
{
|
|
||||||
return String(); // @Todo
|
return String(); // @Todo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Quat::Quat(const Vector3 &axis, const real_t &angle) {
|
||||||
Quat::Quat(const Vector3& axis, const real_t& angle)
|
|
||||||
{
|
|
||||||
real_t d = axis.length();
|
real_t d = axis.length();
|
||||||
if (d==0)
|
if (d == 0)
|
||||||
set(0,0,0,0);
|
set(0, 0, 0, 0);
|
||||||
else {
|
else {
|
||||||
real_t sin_angle = ::sin(angle * 0.5);
|
real_t sin_angle = ::sin(angle * 0.5);
|
||||||
real_t cos_angle = ::cos(angle * 0.5);
|
real_t cos_angle = ::cos(angle * 0.5);
|
||||||
|
@ -217,97 +202,104 @@ Quat::Quat(const Vector3& axis, const real_t& angle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Quat::Quat(const Vector3& v0, const Vector3& v1) // shortest arc
|
Quat::Quat(const Vector3 &v0, const Vector3 &v1) // shortest arc
|
||||||
{
|
{
|
||||||
Vector3 c = v0.cross(v1);
|
Vector3 c = v0.cross(v1);
|
||||||
real_t d = v0.dot(v1);
|
real_t d = v0.dot(v1);
|
||||||
|
|
||||||
if (d < -1.0 + CMP_EPSILON) {
|
if (d < -1.0 + CMP_EPSILON) {
|
||||||
x=0;
|
x = 0;
|
||||||
y=1;
|
y = 1;
|
||||||
z=0;
|
z = 0;
|
||||||
w=0;
|
w = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
real_t s = ::sqrt((1.0 + d) * 2.0);
|
real_t s = ::sqrt((1.0 + d) * 2.0);
|
||||||
real_t rs = 1.0 / s;
|
real_t rs = 1.0 / s;
|
||||||
|
|
||||||
x=c.x*rs;
|
x = c.x * rs;
|
||||||
y=c.y*rs;
|
y = c.y * rs;
|
||||||
z=c.z*rs;
|
z = c.z * rs;
|
||||||
w=s * 0.5;
|
w = s * 0.5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
real_t Quat::dot(const Quat &q) const {
|
||||||
real_t Quat::dot(const Quat& q) const {
|
return x * q.x + y * q.y + z * q.z + w * q.w;
|
||||||
return x * q.x+y * q.y+z * q.z+w * q.w;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Quat::length_squared() const {
|
real_t Quat::length_squared() const {
|
||||||
return dot(*this);
|
return dot(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quat::operator+=(const Quat& q) {
|
void Quat::operator+=(const Quat &q) {
|
||||||
x += q.x; y += q.y; z += q.z; w += q.w;
|
x += q.x;
|
||||||
|
y += q.y;
|
||||||
|
z += q.z;
|
||||||
|
w += q.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quat::operator-=(const Quat& q) {
|
void Quat::operator-=(const Quat &q) {
|
||||||
x -= q.x; y -= q.y; z -= q.z; w -= q.w;
|
x -= q.x;
|
||||||
|
y -= q.y;
|
||||||
|
z -= q.z;
|
||||||
|
w -= q.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Quat::operator*=(const Quat& q) {
|
void Quat::operator*=(const Quat &q) {
|
||||||
x *= q.x; y *= q.y; z *= q.z; w *= q.w;
|
x *= q.x;
|
||||||
|
y *= q.y;
|
||||||
|
z *= q.z;
|
||||||
|
w *= q.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Quat::operator*=(const real_t &s) {
|
||||||
void Quat::operator*=(const real_t& s) {
|
x *= s;
|
||||||
x *= s; y *= s; z *= s; w *= s;
|
y *= s;
|
||||||
|
z *= s;
|
||||||
|
w *= s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Quat::operator/=(const real_t &s) {
|
||||||
void Quat::operator/=(const real_t& s) {
|
|
||||||
|
|
||||||
*this *= 1.0 / s;
|
*this *= 1.0 / s;
|
||||||
}
|
}
|
||||||
|
|
||||||
Quat Quat::operator+(const Quat& q2) const {
|
Quat Quat::operator+(const Quat &q2) const {
|
||||||
const Quat& q1 = *this;
|
const Quat &q1 = *this;
|
||||||
return Quat( q1.x+q2.x, q1.y+q2.y, q1.z+q2.z, q1.w+q2.w );
|
return Quat(q1.x + q2.x, q1.y + q2.y, q1.z + q2.z, q1.w + q2.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
Quat Quat::operator-(const Quat& q2) const {
|
Quat Quat::operator-(const Quat &q2) const {
|
||||||
const Quat& q1 = *this;
|
const Quat &q1 = *this;
|
||||||
return Quat( q1.x-q2.x, q1.y-q2.y, q1.z-q2.z, q1.w-q2.w);
|
return Quat(q1.x - q2.x, q1.y - q2.y, q1.z - q2.z, q1.w - q2.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
Quat Quat::operator*(const Quat& q2) const {
|
Quat Quat::operator*(const Quat &q2) const {
|
||||||
Quat q1 = *this;
|
Quat q1 = *this;
|
||||||
q1 *= q2;
|
q1 *= q2;
|
||||||
return q1;
|
return q1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Quat Quat::operator-() const {
|
Quat Quat::operator-() const {
|
||||||
const Quat& q2 = *this;
|
const Quat &q2 = *this;
|
||||||
return Quat( -q2.x, -q2.y, -q2.z, -q2.w);
|
return Quat(-q2.x, -q2.y, -q2.z, -q2.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
Quat Quat::operator*(const real_t& s) const {
|
Quat Quat::operator*(const real_t &s) const {
|
||||||
return Quat(x * s, y * s, z * s, w * s);
|
return Quat(x * s, y * s, z * s, w * s);
|
||||||
}
|
}
|
||||||
|
|
||||||
Quat Quat::operator/(const real_t& s) const {
|
Quat Quat::operator/(const real_t &s) const {
|
||||||
return *this * (1.0 / s);
|
return *this * (1.0 / s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Quat::operator==(const Quat &p_quat) const {
|
||||||
bool Quat::operator==(const Quat& p_quat) const {
|
return x == p_quat.x && y == p_quat.y && z == p_quat.z && w == p_quat.w;
|
||||||
return x==p_quat.x && y==p_quat.y && z==p_quat.z && w==p_quat.w;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Quat::operator!=(const Quat& p_quat) const {
|
bool Quat::operator!=(const Quat &p_quat) const {
|
||||||
return x!=p_quat.x || y!=p_quat.y || z!=p_quat.z || w!=p_quat.w;
|
return x != p_quat.x || y != p_quat.y || z != p_quat.z || w != p_quat.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
|
@ -6,50 +6,40 @@
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
RID::RID()
|
RID::RID() {
|
||||||
{
|
|
||||||
godot::api->godot_rid_new(&_godot_rid);
|
godot::api->godot_rid_new(&_godot_rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
RID::RID(Object *p)
|
RID::RID(Object *p) {
|
||||||
{
|
godot::api->godot_rid_new_with_resource(&_godot_rid, (const godot_object *)p);
|
||||||
godot::api->godot_rid_new_with_resource(&_godot_rid, (const godot_object *) p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t RID::get_rid() const
|
int32_t RID::get_rid() const {
|
||||||
{
|
|
||||||
return godot::api->godot_rid_get_id(&_godot_rid);
|
return godot::api->godot_rid_get_id(&_godot_rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RID::operator==(const RID & p_other) const
|
bool RID::operator==(const RID &p_other) const {
|
||||||
{
|
|
||||||
return godot::api->godot_rid_operator_equal(&_godot_rid, &p_other._godot_rid);
|
return godot::api->godot_rid_operator_equal(&_godot_rid, &p_other._godot_rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RID::operator!=(const RID & p_other) const
|
bool RID::operator!=(const RID &p_other) const {
|
||||||
{
|
|
||||||
return !(*this == p_other);
|
return !(*this == p_other);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RID::operator<(const RID & p_other) const
|
bool RID::operator<(const RID &p_other) const {
|
||||||
{
|
|
||||||
return godot::api->godot_rid_operator_less(&_godot_rid, &p_other._godot_rid);
|
return godot::api->godot_rid_operator_less(&_godot_rid, &p_other._godot_rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RID::operator>(const RID & p_other) const
|
bool RID::operator>(const RID &p_other) const {
|
||||||
{
|
|
||||||
return !(*this < p_other) && *this != p_other;
|
return !(*this < p_other) && *this != p_other;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RID::operator<=(const RID & p_other) const
|
bool RID::operator<=(const RID &p_other) const {
|
||||||
{
|
|
||||||
return (*this < p_other) || *this == p_other;
|
return (*this < p_other) || *this == p_other;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RID::operator>=(const RID & p_other) const
|
bool RID::operator>=(const RID &p_other) const {
|
||||||
{
|
|
||||||
return !(*this < p_other);
|
return !(*this < p_other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "Rect2.hpp"
|
#include "Rect2.hpp"
|
||||||
#include "Vector2.hpp"
|
|
||||||
#include "String.hpp"
|
#include "String.hpp"
|
||||||
#include "Transform2D.hpp"
|
#include "Transform2D.hpp"
|
||||||
|
#include "Vector2.hpp"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
@ -15,110 +15,104 @@ namespace godot {
|
||||||
#define MIN(a, b) (a < b ? a : b)
|
#define MIN(a, b) (a < b ? a : b)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
real_t Rect2::distance_to(const Vector2 &p_point) const {
|
||||||
real_t Rect2::distance_to(const Vector2& p_point) const {
|
|
||||||
|
|
||||||
real_t dist = 1e20;
|
real_t dist = 1e20;
|
||||||
|
|
||||||
if (p_point.x < pos.x) {
|
if (p_point.x < pos.x) {
|
||||||
dist=MIN(dist,pos.x-p_point.x);
|
dist = MIN(dist, pos.x - p_point.x);
|
||||||
}
|
}
|
||||||
if (p_point.y < pos.y) {
|
if (p_point.y < pos.y) {
|
||||||
dist=MIN(dist,pos.y-p_point.y);
|
dist = MIN(dist, pos.y - p_point.y);
|
||||||
}
|
}
|
||||||
if (p_point.x >= (pos.x+size.x) ) {
|
if (p_point.x >= (pos.x + size.x)) {
|
||||||
dist=MIN(p_point.x-(pos.x+size.x),dist);
|
dist = MIN(p_point.x - (pos.x + size.x), dist);
|
||||||
}
|
}
|
||||||
if (p_point.y >= (pos.y+size.y) ) {
|
if (p_point.y >= (pos.y + size.y)) {
|
||||||
dist=MIN(p_point.y-(pos.y+size.y),dist);
|
dist = MIN(p_point.y - (pos.y + size.y), dist);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dist==1e20)
|
if (dist == 1e20)
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
return dist;
|
return dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect2 Rect2::clip(const Rect2& p_rect) const { /// return a clipped rect
|
Rect2 Rect2::clip(const Rect2 &p_rect) const { /// return a clipped rect
|
||||||
|
|
||||||
Rect2 new_rect=p_rect;
|
Rect2 new_rect = p_rect;
|
||||||
|
|
||||||
if (!intersects( new_rect ))
|
if (!intersects(new_rect))
|
||||||
return Rect2();
|
return Rect2();
|
||||||
|
|
||||||
new_rect.pos.x = MAX( p_rect.pos.x , pos.x );
|
new_rect.pos.x = MAX(p_rect.pos.x, pos.x);
|
||||||
new_rect.pos.y = MAX( p_rect.pos.y , pos.y );
|
new_rect.pos.y = MAX(p_rect.pos.y, pos.y);
|
||||||
|
|
||||||
Point2 p_rect_end=p_rect.pos+p_rect.size;
|
Point2 p_rect_end = p_rect.pos + p_rect.size;
|
||||||
Point2 end=pos+size;
|
Point2 end = pos + size;
|
||||||
|
|
||||||
new_rect.size.x=MIN(p_rect_end.x,end.x) - new_rect.pos.x;
|
new_rect.size.x = MIN(p_rect_end.x, end.x) - new_rect.pos.x;
|
||||||
new_rect.size.y=MIN(p_rect_end.y,end.y) - new_rect.pos.y;
|
new_rect.size.y = MIN(p_rect_end.y, end.y) - new_rect.pos.y;
|
||||||
|
|
||||||
return new_rect;
|
return new_rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect2 Rect2::merge(const Rect2& p_rect) const { ///< return a merged rect
|
Rect2 Rect2::merge(const Rect2 &p_rect) const { ///< return a merged rect
|
||||||
|
|
||||||
Rect2 new_rect;
|
Rect2 new_rect;
|
||||||
|
|
||||||
new_rect.pos.x=MIN( p_rect.pos.x , pos.x );
|
new_rect.pos.x = MIN(p_rect.pos.x, pos.x);
|
||||||
new_rect.pos.y=MIN( p_rect.pos.y , pos.y );
|
new_rect.pos.y = MIN(p_rect.pos.y, pos.y);
|
||||||
|
|
||||||
|
new_rect.size.x = MAX(p_rect.pos.x + p_rect.size.x, pos.x + size.x);
|
||||||
new_rect.size.x = MAX( p_rect.pos.x+p_rect.size.x , pos.x+size.x );
|
new_rect.size.y = MAX(p_rect.pos.y + p_rect.size.y, pos.y + size.y);
|
||||||
new_rect.size.y = MAX( p_rect.pos.y+p_rect.size.y , pos.y+size.y );
|
|
||||||
|
|
||||||
new_rect.size = new_rect.size - new_rect.pos; //make relative again
|
new_rect.size = new_rect.size - new_rect.pos; //make relative again
|
||||||
|
|
||||||
return new_rect;
|
return new_rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rect2::operator String() const {
|
||||||
|
return String(pos) + ", " + String(size);
|
||||||
Rect2::operator String() const
|
|
||||||
{
|
|
||||||
return String(pos)+", "+String(size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos, Point2 *r_normal) const {
|
||||||
|
|
||||||
bool Rect2::intersects_segment(const Point2& p_from, const Point2& p_to, Point2* r_pos,Point2* r_normal) const {
|
real_t min = 0, max = 1;
|
||||||
|
int axis = 0;
|
||||||
|
real_t sign = 0;
|
||||||
|
|
||||||
real_t min=0,max=1;
|
for (int i = 0; i < 2; i++) {
|
||||||
int axis=0;
|
real_t seg_from = p_from[i];
|
||||||
real_t sign=0;
|
real_t seg_to = p_to[i];
|
||||||
|
real_t box_begin = pos[i];
|
||||||
for(int i=0;i<2;i++) {
|
real_t box_end = box_begin + size[i];
|
||||||
real_t seg_from=p_from[i];
|
real_t cmin, cmax;
|
||||||
real_t seg_to=p_to[i];
|
|
||||||
real_t box_begin=pos[i];
|
|
||||||
real_t box_end=box_begin+size[i];
|
|
||||||
real_t cmin,cmax;
|
|
||||||
real_t csign;
|
real_t csign;
|
||||||
|
|
||||||
if (seg_from < seg_to) {
|
if (seg_from < seg_to) {
|
||||||
|
|
||||||
if (seg_from > box_end || seg_to < box_begin)
|
if (seg_from > box_end || seg_to < box_begin)
|
||||||
return false;
|
return false;
|
||||||
real_t length=seg_to-seg_from;
|
real_t length = seg_to - seg_from;
|
||||||
cmin = (seg_from < box_begin)?((box_begin - seg_from)/length):0;
|
cmin = (seg_from < box_begin) ? ((box_begin - seg_from) / length) : 0;
|
||||||
cmax = (seg_to > box_end)?((box_end - seg_from)/length):1;
|
cmax = (seg_to > box_end) ? ((box_end - seg_from) / length) : 1;
|
||||||
csign=-1.0;
|
csign = -1.0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (seg_to > box_end || seg_from < box_begin)
|
if (seg_to > box_end || seg_from < box_begin)
|
||||||
return false;
|
return false;
|
||||||
real_t length=seg_to-seg_from;
|
real_t length = seg_to - seg_from;
|
||||||
cmin = (seg_from > box_end)?(box_end - seg_from)/length:0;
|
cmin = (seg_from > box_end) ? (box_end - seg_from) / length : 0;
|
||||||
cmax = (seg_to < box_begin)?(box_begin - seg_from)/length:1;
|
cmax = (seg_to < box_begin) ? (box_begin - seg_from) / length : 1;
|
||||||
csign=1.0;
|
csign = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmin > min) {
|
if (cmin > min) {
|
||||||
min = cmin;
|
min = cmin;
|
||||||
axis=i;
|
axis = i;
|
||||||
sign=csign;
|
sign = csign;
|
||||||
}
|
}
|
||||||
if (cmax < max)
|
if (cmax < max)
|
||||||
max = cmax;
|
max = cmax;
|
||||||
|
@ -126,175 +120,169 @@ bool Rect2::intersects_segment(const Point2& p_from, const Point2& p_to, Point2*
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector2 rel = p_to - p_from;
|
||||||
Vector2 rel=p_to-p_from;
|
|
||||||
|
|
||||||
if (r_normal) {
|
if (r_normal) {
|
||||||
Vector2 normal;
|
Vector2 normal;
|
||||||
normal[axis]=sign;
|
normal[axis] = sign;
|
||||||
*r_normal=normal;
|
*r_normal = normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r_pos)
|
if (r_pos)
|
||||||
*r_pos=p_from+rel*min;
|
*r_pos = p_from + rel * min;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Rect2::intersects_transformed(const Transform2D &p_xform, const Rect2 &p_rect) const {
|
||||||
bool Rect2::intersects_transformed(const Transform2D& p_xform, const Rect2& p_rect) const {
|
|
||||||
|
|
||||||
//SAT intersection between local and transformed rect2
|
//SAT intersection between local and transformed rect2
|
||||||
|
|
||||||
Vector2 xf_points[4]={
|
Vector2 xf_points[4] = {
|
||||||
p_xform.xform(p_rect.pos),
|
p_xform.xform(p_rect.pos),
|
||||||
p_xform.xform(Vector2(p_rect.pos.x+p_rect.size.x,p_rect.pos.y)),
|
p_xform.xform(Vector2(p_rect.pos.x + p_rect.size.x, p_rect.pos.y)),
|
||||||
p_xform.xform(Vector2(p_rect.pos.x,p_rect.pos.y+p_rect.size.y)),
|
p_xform.xform(Vector2(p_rect.pos.x, p_rect.pos.y + p_rect.size.y)),
|
||||||
p_xform.xform(Vector2(p_rect.pos.x+p_rect.size.x,p_rect.pos.y+p_rect.size.y)),
|
p_xform.xform(Vector2(p_rect.pos.x + p_rect.size.x, p_rect.pos.y + p_rect.size.y)),
|
||||||
};
|
};
|
||||||
|
|
||||||
real_t low_limit;
|
real_t low_limit;
|
||||||
|
|
||||||
//base rect2 first (faster)
|
//base rect2 first (faster)
|
||||||
|
|
||||||
if (xf_points[0].y>pos.y)
|
if (xf_points[0].y > pos.y)
|
||||||
goto next1;
|
goto next1;
|
||||||
if (xf_points[1].y>pos.y)
|
if (xf_points[1].y > pos.y)
|
||||||
goto next1;
|
goto next1;
|
||||||
if (xf_points[2].y>pos.y)
|
if (xf_points[2].y > pos.y)
|
||||||
goto next1;
|
goto next1;
|
||||||
if (xf_points[3].y>pos.y)
|
if (xf_points[3].y > pos.y)
|
||||||
goto next1;
|
goto next1;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
next1:
|
next1:
|
||||||
|
|
||||||
low_limit=pos.y+size.y;
|
low_limit = pos.y + size.y;
|
||||||
|
|
||||||
if (xf_points[0].y<low_limit)
|
if (xf_points[0].y < low_limit)
|
||||||
goto next2;
|
goto next2;
|
||||||
if (xf_points[1].y<low_limit)
|
if (xf_points[1].y < low_limit)
|
||||||
goto next2;
|
goto next2;
|
||||||
if (xf_points[2].y<low_limit)
|
if (xf_points[2].y < low_limit)
|
||||||
goto next2;
|
goto next2;
|
||||||
if (xf_points[3].y<low_limit)
|
if (xf_points[3].y < low_limit)
|
||||||
goto next2;
|
goto next2;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
next2:
|
next2:
|
||||||
|
|
||||||
if (xf_points[0].x>pos.x)
|
if (xf_points[0].x > pos.x)
|
||||||
goto next3;
|
goto next3;
|
||||||
if (xf_points[1].x>pos.x)
|
if (xf_points[1].x > pos.x)
|
||||||
goto next3;
|
goto next3;
|
||||||
if (xf_points[2].x>pos.x)
|
if (xf_points[2].x > pos.x)
|
||||||
goto next3;
|
goto next3;
|
||||||
if (xf_points[3].x>pos.x)
|
if (xf_points[3].x > pos.x)
|
||||||
goto next3;
|
goto next3;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
next3:
|
next3:
|
||||||
|
|
||||||
low_limit=pos.x+size.x;
|
low_limit = pos.x + size.x;
|
||||||
|
|
||||||
if (xf_points[0].x<low_limit)
|
if (xf_points[0].x < low_limit)
|
||||||
goto next4;
|
goto next4;
|
||||||
if (xf_points[1].x<low_limit)
|
if (xf_points[1].x < low_limit)
|
||||||
goto next4;
|
goto next4;
|
||||||
if (xf_points[2].x<low_limit)
|
if (xf_points[2].x < low_limit)
|
||||||
goto next4;
|
goto next4;
|
||||||
if (xf_points[3].x<low_limit)
|
if (xf_points[3].x < low_limit)
|
||||||
goto next4;
|
goto next4;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
next4:
|
next4:
|
||||||
|
|
||||||
Vector2 xf_points2[4]={
|
Vector2 xf_points2[4] = {
|
||||||
pos,
|
pos,
|
||||||
Vector2(pos.x+size.x,pos.y),
|
Vector2(pos.x + size.x, pos.y),
|
||||||
Vector2(pos.x,pos.y+size.y),
|
Vector2(pos.x, pos.y + size.y),
|
||||||
Vector2(pos.x+size.x,pos.y+size.y),
|
Vector2(pos.x + size.x, pos.y + size.y),
|
||||||
};
|
};
|
||||||
|
|
||||||
real_t maxa=p_xform.elements[0].dot(xf_points2[0]);
|
real_t maxa = p_xform.elements[0].dot(xf_points2[0]);
|
||||||
real_t mina=maxa;
|
real_t mina = maxa;
|
||||||
|
|
||||||
real_t dp = p_xform.elements[0].dot(xf_points2[1]);
|
real_t dp = p_xform.elements[0].dot(xf_points2[1]);
|
||||||
maxa=MAX(dp,maxa);
|
maxa = MAX(dp, maxa);
|
||||||
mina=MIN(dp,mina);
|
mina = MIN(dp, mina);
|
||||||
|
|
||||||
dp = p_xform.elements[0].dot(xf_points2[2]);
|
dp = p_xform.elements[0].dot(xf_points2[2]);
|
||||||
maxa=MAX(dp,maxa);
|
maxa = MAX(dp, maxa);
|
||||||
mina=MIN(dp,mina);
|
mina = MIN(dp, mina);
|
||||||
|
|
||||||
dp = p_xform.elements[0].dot(xf_points2[3]);
|
dp = p_xform.elements[0].dot(xf_points2[3]);
|
||||||
maxa=MAX(dp,maxa);
|
maxa = MAX(dp, maxa);
|
||||||
mina=MIN(dp,mina);
|
mina = MIN(dp, mina);
|
||||||
|
|
||||||
real_t maxb=p_xform.elements[0].dot(xf_points[0]);
|
real_t maxb = p_xform.elements[0].dot(xf_points[0]);
|
||||||
real_t minb=maxb;
|
real_t minb = maxb;
|
||||||
|
|
||||||
dp = p_xform.elements[0].dot(xf_points[1]);
|
dp = p_xform.elements[0].dot(xf_points[1]);
|
||||||
maxb=MAX(dp,maxb);
|
maxb = MAX(dp, maxb);
|
||||||
minb=MIN(dp,minb);
|
minb = MIN(dp, minb);
|
||||||
|
|
||||||
dp = p_xform.elements[0].dot(xf_points[2]);
|
dp = p_xform.elements[0].dot(xf_points[2]);
|
||||||
maxb=MAX(dp,maxb);
|
maxb = MAX(dp, maxb);
|
||||||
minb=MIN(dp,minb);
|
minb = MIN(dp, minb);
|
||||||
|
|
||||||
dp = p_xform.elements[0].dot(xf_points[3]);
|
dp = p_xform.elements[0].dot(xf_points[3]);
|
||||||
maxb=MAX(dp,maxb);
|
maxb = MAX(dp, maxb);
|
||||||
minb=MIN(dp,minb);
|
minb = MIN(dp, minb);
|
||||||
|
|
||||||
|
if (mina > maxb)
|
||||||
if ( mina > maxb )
|
|
||||||
return false;
|
return false;
|
||||||
if ( minb > maxa )
|
if (minb > maxa)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
maxa=p_xform.elements[1].dot(xf_points2[0]);
|
maxa = p_xform.elements[1].dot(xf_points2[0]);
|
||||||
mina=maxa;
|
mina = maxa;
|
||||||
|
|
||||||
dp = p_xform.elements[1].dot(xf_points2[1]);
|
dp = p_xform.elements[1].dot(xf_points2[1]);
|
||||||
maxa=MAX(dp,maxa);
|
maxa = MAX(dp, maxa);
|
||||||
mina=MIN(dp,mina);
|
mina = MIN(dp, mina);
|
||||||
|
|
||||||
dp = p_xform.elements[1].dot(xf_points2[2]);
|
dp = p_xform.elements[1].dot(xf_points2[2]);
|
||||||
maxa=MAX(dp,maxa);
|
maxa = MAX(dp, maxa);
|
||||||
mina=MIN(dp,mina);
|
mina = MIN(dp, mina);
|
||||||
|
|
||||||
dp = p_xform.elements[1].dot(xf_points2[3]);
|
dp = p_xform.elements[1].dot(xf_points2[3]);
|
||||||
maxa=MAX(dp,maxa);
|
maxa = MAX(dp, maxa);
|
||||||
mina=MIN(dp,mina);
|
mina = MIN(dp, mina);
|
||||||
|
|
||||||
maxb=p_xform.elements[1].dot(xf_points[0]);
|
maxb = p_xform.elements[1].dot(xf_points[0]);
|
||||||
minb=maxb;
|
minb = maxb;
|
||||||
|
|
||||||
dp = p_xform.elements[1].dot(xf_points[1]);
|
dp = p_xform.elements[1].dot(xf_points[1]);
|
||||||
maxb=MAX(dp,maxb);
|
maxb = MAX(dp, maxb);
|
||||||
minb=MIN(dp,minb);
|
minb = MIN(dp, minb);
|
||||||
|
|
||||||
dp = p_xform.elements[1].dot(xf_points[2]);
|
dp = p_xform.elements[1].dot(xf_points[2]);
|
||||||
maxb=MAX(dp,maxb);
|
maxb = MAX(dp, maxb);
|
||||||
minb=MIN(dp,minb);
|
minb = MIN(dp, minb);
|
||||||
|
|
||||||
dp = p_xform.elements[1].dot(xf_points[3]);
|
dp = p_xform.elements[1].dot(xf_points[3]);
|
||||||
maxb=MAX(dp,maxb);
|
maxb = MAX(dp, maxb);
|
||||||
minb=MIN(dp,minb);
|
minb = MIN(dp, minb);
|
||||||
|
|
||||||
|
if (mina > maxb)
|
||||||
if ( mina > maxb )
|
|
||||||
return false;
|
return false;
|
||||||
if ( minb > maxa )
|
if (minb > maxa)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#include "String.hpp"
|
#include "String.hpp"
|
||||||
|
|
||||||
#include "Array.hpp"
|
#include "Array.hpp"
|
||||||
|
#include "GodotGlobal.hpp"
|
||||||
#include "NodePath.hpp"
|
#include "NodePath.hpp"
|
||||||
#include "PoolArrays.hpp"
|
#include "PoolArrays.hpp"
|
||||||
#include "Variant.hpp"
|
#include "Variant.hpp"
|
||||||
#include "GodotGlobal.hpp"
|
|
||||||
|
|
||||||
#include <gdnative/string.h>
|
#include <gdnative/string.h>
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ char *String::alloc_c_string() const {
|
||||||
|
|
||||||
int length = godot::api->godot_char_string_length(&contents);
|
int length = godot::api->godot_char_string_length(&contents);
|
||||||
|
|
||||||
char *result = (char *) godot::api->godot_alloc(length + 1);
|
char *result = (char *)godot::api->godot_alloc(length + 1);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
memcpy(result, godot::api->godot_char_string_get_data(&contents), length + 1);
|
memcpy(result, godot::api->godot_char_string_get_data(&contents), length + 1);
|
||||||
|
@ -549,11 +549,10 @@ signed char String::casecmp_to(String p_str) const {
|
||||||
|
|
||||||
signed char String::nocasecmp_to(String p_str) const {
|
signed char String::nocasecmp_to(String p_str) const {
|
||||||
return godot::api->godot_string_nocasecmp_to(&_godot_string, &p_str._godot_string);
|
return godot::api->godot_string_nocasecmp_to(&_godot_string, &p_str._godot_string);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
signed char String::naturalnocasecmp_to(String p_str) const {
|
signed char String::naturalnocasecmp_to(String p_str) const {
|
||||||
return godot::api->godot_string_naturalnocasecmp_to(&_godot_string, &p_str._godot_string);
|
return godot::api->godot_string_naturalnocasecmp_to(&_godot_string, &p_str._godot_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
|
@ -10,29 +10,25 @@ namespace _TagDB {
|
||||||
|
|
||||||
std::unordered_map<size_t, size_t> parent_to;
|
std::unordered_map<size_t, size_t> parent_to;
|
||||||
|
|
||||||
void register_type(size_t type_tag, size_t base_type_tag)
|
void register_type(size_t type_tag, size_t base_type_tag) {
|
||||||
{
|
|
||||||
if (type_tag == base_type_tag) {
|
if (type_tag == base_type_tag) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
parent_to[type_tag] = base_type_tag;
|
parent_to[type_tag] = base_type_tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_type_known(size_t type_tag)
|
bool is_type_known(size_t type_tag) {
|
||||||
{
|
|
||||||
return parent_to.find(type_tag) != parent_to.end();
|
return parent_to.find(type_tag) != parent_to.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_global_type(const char *name, size_t type_tag, size_t base_type_tag)
|
void register_global_type(const char *name, size_t type_tag, size_t base_type_tag) {
|
||||||
{
|
|
||||||
|
|
||||||
godot::nativescript_1_1_api->godot_nativescript_set_global_type_tag(godot::_RegisterState::language_index, name, (const void *) type_tag);
|
godot::nativescript_1_1_api->godot_nativescript_set_global_type_tag(godot::_RegisterState::language_index, name, (const void *)type_tag);
|
||||||
|
|
||||||
register_type(type_tag, base_type_tag);
|
register_type(type_tag, base_type_tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_type_compatible(size_t ask_tag, size_t have_tag)
|
bool is_type_compatible(size_t ask_tag, size_t have_tag) {
|
||||||
{
|
|
||||||
|
|
||||||
if (have_tag == 0)
|
if (have_tag == 0)
|
||||||
return false;
|
return false;
|
||||||
|
@ -49,7 +45,6 @@ bool is_type_compatible(size_t ask_tag, size_t have_tag)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace _TagDB
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
}
|
|
||||||
|
|
|
@ -2,134 +2,122 @@
|
||||||
|
|
||||||
#include "Basis.hpp"
|
#include "Basis.hpp"
|
||||||
|
|
||||||
#include "Plane.hpp"
|
|
||||||
#include "AABB.hpp"
|
#include "AABB.hpp"
|
||||||
|
#include "Plane.hpp"
|
||||||
|
|
||||||
#include "Quat.hpp"
|
#include "Quat.hpp"
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
|
Transform Transform::inverse_xform(const Transform &t) const {
|
||||||
|
|
||||||
Transform Transform::inverse_xform(const Transform& t) const {
|
|
||||||
|
|
||||||
Vector3 v = t.origin - origin;
|
Vector3 v = t.origin - origin;
|
||||||
return Transform(basis.transpose_xform(t.basis),
|
return Transform(basis.transpose_xform(t.basis),
|
||||||
basis.xform(v));
|
basis.xform(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform::set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz,real_t tx, real_t ty, real_t tz) {
|
void Transform::set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t tx, real_t ty, real_t tz) {
|
||||||
|
|
||||||
basis.elements[0][0]=xx;
|
basis.elements[0][0] = xx;
|
||||||
basis.elements[0][1]=xy;
|
basis.elements[0][1] = xy;
|
||||||
basis.elements[0][2]=xz;
|
basis.elements[0][2] = xz;
|
||||||
basis.elements[1][0]=yx;
|
basis.elements[1][0] = yx;
|
||||||
basis.elements[1][1]=yy;
|
basis.elements[1][1] = yy;
|
||||||
basis.elements[1][2]=yz;
|
basis.elements[1][2] = yz;
|
||||||
basis.elements[2][0]=zx;
|
basis.elements[2][0] = zx;
|
||||||
basis.elements[2][1]=zy;
|
basis.elements[2][1] = zy;
|
||||||
basis.elements[2][2]=zz;
|
basis.elements[2][2] = zz;
|
||||||
origin.x=tx;
|
origin.x = tx;
|
||||||
origin.y=ty;
|
origin.y = ty;
|
||||||
origin.z=tz;
|
origin.z = tz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3 Transform::xform(const Vector3 &p_vector) const {
|
||||||
|
|
||||||
Vector3 Transform::xform(const Vector3& p_vector) const {
|
|
||||||
|
|
||||||
return Vector3(
|
return Vector3(
|
||||||
basis[0].dot(p_vector)+origin.x,
|
basis[0].dot(p_vector) + origin.x,
|
||||||
basis[1].dot(p_vector)+origin.y,
|
basis[1].dot(p_vector) + origin.y,
|
||||||
basis[2].dot(p_vector)+origin.z
|
basis[2].dot(p_vector) + origin.z);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Vector3 Transform::xform_inv(const Vector3& p_vector) const {
|
Vector3 Transform::xform_inv(const Vector3 &p_vector) const {
|
||||||
|
|
||||||
Vector3 v = p_vector - origin;
|
Vector3 v = p_vector - origin;
|
||||||
|
|
||||||
return Vector3(
|
return Vector3(
|
||||||
(basis.elements[0][0]*v.x ) + ( basis.elements[1][0]*v.y ) + ( basis.elements[2][0]*v.z ),
|
(basis.elements[0][0] * v.x) + (basis.elements[1][0] * v.y) + (basis.elements[2][0] * v.z),
|
||||||
(basis.elements[0][1]*v.x ) + ( basis.elements[1][1]*v.y ) + ( basis.elements[2][1]*v.z ),
|
(basis.elements[0][1] * v.x) + (basis.elements[1][1] * v.y) + (basis.elements[2][1] * v.z),
|
||||||
(basis.elements[0][2]*v.x ) + ( basis.elements[1][2]*v.y ) + ( basis.elements[2][2]*v.z )
|
(basis.elements[0][2] * v.x) + (basis.elements[1][2] * v.y) + (basis.elements[2][2] * v.z));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Plane Transform::xform(const Plane& p_plane) const {
|
Plane Transform::xform(const Plane &p_plane) const {
|
||||||
|
|
||||||
|
Vector3 point = p_plane.normal * p_plane.d;
|
||||||
|
Vector3 point_dir = point + p_plane.normal;
|
||||||
|
point = xform(point);
|
||||||
|
point_dir = xform(point_dir);
|
||||||
|
|
||||||
Vector3 point=p_plane.normal*p_plane.d;
|
Vector3 normal = point_dir - point;
|
||||||
Vector3 point_dir=point+p_plane.normal;
|
|
||||||
point=xform(point);
|
|
||||||
point_dir=xform(point_dir);
|
|
||||||
|
|
||||||
Vector3 normal=point_dir-point;
|
|
||||||
normal.normalize();
|
normal.normalize();
|
||||||
real_t d=normal.dot(point);
|
real_t d = normal.dot(point);
|
||||||
|
|
||||||
return Plane(normal,d);
|
|
||||||
|
|
||||||
|
return Plane(normal, d);
|
||||||
}
|
}
|
||||||
Plane Transform::xform_inv(const Plane& p_plane) const {
|
Plane Transform::xform_inv(const Plane &p_plane) const {
|
||||||
|
|
||||||
Vector3 point=p_plane.normal*p_plane.d;
|
Vector3 point = p_plane.normal * p_plane.d;
|
||||||
Vector3 point_dir=point+p_plane.normal;
|
Vector3 point_dir = point + p_plane.normal;
|
||||||
point=xform_inv(point);
|
point = xform_inv(point);
|
||||||
point_dir=xform_inv(point_dir);
|
point_dir = xform_inv(point_dir);
|
||||||
|
|
||||||
Vector3 normal=point_dir-point;
|
Vector3 normal = point_dir - point;
|
||||||
normal.normalize();
|
normal.normalize();
|
||||||
real_t d=normal.dot(point);
|
real_t d = normal.dot(point);
|
||||||
|
|
||||||
return Plane(normal,d);
|
|
||||||
|
|
||||||
|
return Plane(normal, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
AABB Transform::xform(const AABB& p_aabb) const {
|
AABB Transform::xform(const AABB &p_aabb) const {
|
||||||
/* define vertices */
|
/* define vertices */
|
||||||
Vector3 x=basis.get_axis(0)*p_aabb.size.x;
|
Vector3 x = basis.get_axis(0) * p_aabb.size.x;
|
||||||
Vector3 y=basis.get_axis(1)*p_aabb.size.y;
|
Vector3 y = basis.get_axis(1) * p_aabb.size.y;
|
||||||
Vector3 z=basis.get_axis(2)*p_aabb.size.z;
|
Vector3 z = basis.get_axis(2) * p_aabb.size.z;
|
||||||
Vector3 pos = xform( p_aabb.position );
|
Vector3 pos = xform(p_aabb.position);
|
||||||
//could be even further optimized
|
//could be even further optimized
|
||||||
AABB new_aabb;
|
AABB new_aabb;
|
||||||
new_aabb.position=pos;
|
new_aabb.position = pos;
|
||||||
new_aabb.expand_to( pos+x );
|
new_aabb.expand_to(pos + x);
|
||||||
new_aabb.expand_to( pos+y );
|
new_aabb.expand_to(pos + y);
|
||||||
new_aabb.expand_to( pos+z );
|
new_aabb.expand_to(pos + z);
|
||||||
new_aabb.expand_to( pos+x+y );
|
new_aabb.expand_to(pos + x + y);
|
||||||
new_aabb.expand_to( pos+x+z );
|
new_aabb.expand_to(pos + x + z);
|
||||||
new_aabb.expand_to( pos+y+z );
|
new_aabb.expand_to(pos + y + z);
|
||||||
new_aabb.expand_to( pos+x+y+z );
|
new_aabb.expand_to(pos + x + y + z);
|
||||||
return new_aabb;
|
return new_aabb;
|
||||||
|
|
||||||
}
|
}
|
||||||
AABB Transform::xform_inv(const AABB& p_aabb) const {
|
AABB Transform::xform_inv(const AABB &p_aabb) const {
|
||||||
|
|
||||||
/* define vertices */
|
/* define vertices */
|
||||||
Vector3 vertices[8]={
|
Vector3 vertices[8] = {
|
||||||
Vector3(p_aabb.position.x+p_aabb.size.x, p_aabb.position.y+p_aabb.size.y, p_aabb.position.z+p_aabb.size.z),
|
Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z),
|
||||||
Vector3(p_aabb.position.x+p_aabb.size.x, p_aabb.position.y+p_aabb.size.y, p_aabb.position.z),
|
Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z),
|
||||||
Vector3(p_aabb.position.x+p_aabb.size.x, p_aabb.position.y, p_aabb.position.z+p_aabb.size.z),
|
Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z),
|
||||||
Vector3(p_aabb.position.x+p_aabb.size.x, p_aabb.position.y, p_aabb.position.z),
|
Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z),
|
||||||
Vector3(p_aabb.position.x, p_aabb.position.y+p_aabb.size.y, p_aabb.position.z+p_aabb.size.z),
|
Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z),
|
||||||
Vector3(p_aabb.position.x, p_aabb.position.y+p_aabb.size.y, p_aabb.position.z),
|
Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z),
|
||||||
Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z+p_aabb.size.z),
|
Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z),
|
||||||
Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z)
|
Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
AABB ret;
|
AABB ret;
|
||||||
|
|
||||||
ret.position=xform_inv(vertices[0]);
|
ret.position = xform_inv(vertices[0]);
|
||||||
|
|
||||||
for (int i=1;i<8;i++) {
|
for (int i = 1; i < 8; i++) {
|
||||||
|
|
||||||
ret.expand_to( xform_inv(vertices[i]) );
|
ret.expand_to(xform_inv(vertices[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform::affine_invert() {
|
void Transform::affine_invert() {
|
||||||
|
@ -140,13 +128,11 @@ void Transform::affine_invert() {
|
||||||
|
|
||||||
Transform Transform::affine_inverse() const {
|
Transform Transform::affine_inverse() const {
|
||||||
|
|
||||||
Transform ret=*this;
|
Transform ret = *this;
|
||||||
ret.affine_invert();
|
ret.affine_invert();
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Transform::invert() {
|
void Transform::invert() {
|
||||||
|
|
||||||
basis.transpose();
|
basis.transpose();
|
||||||
|
@ -156,35 +142,34 @@ void Transform::invert() {
|
||||||
Transform Transform::inverse() const {
|
Transform Transform::inverse() const {
|
||||||
// FIXME: this function assumes the basis is a rotation matrix, with no scaling.
|
// FIXME: this function assumes the basis is a rotation matrix, with no scaling.
|
||||||
// Transform::affine_inverse can handle matrices with scaling, so GDScript should eventually use that.
|
// Transform::affine_inverse can handle matrices with scaling, so GDScript should eventually use that.
|
||||||
Transform ret=*this;
|
Transform ret = *this;
|
||||||
ret.invert();
|
ret.invert();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Transform::rotate(const Vector3 &p_axis, real_t p_phi) {
|
||||||
void Transform::rotate(const Vector3& p_axis,real_t p_phi) {
|
|
||||||
|
|
||||||
*this = rotated(p_axis, p_phi);
|
*this = rotated(p_axis, p_phi);
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform Transform::rotated(const Vector3& p_axis,real_t p_phi) const{
|
Transform Transform::rotated(const Vector3 &p_axis, real_t p_phi) const {
|
||||||
|
|
||||||
return Transform(Basis( p_axis, p_phi ), Vector3()) * (*this);
|
return Transform(Basis(p_axis, p_phi), Vector3()) * (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform::rotate_basis(const Vector3& p_axis,real_t p_phi) {
|
void Transform::rotate_basis(const Vector3 &p_axis, real_t p_phi) {
|
||||||
|
|
||||||
basis.rotate(p_axis,p_phi);
|
basis.rotate(p_axis, p_phi);
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform Transform::looking_at( const Vector3& p_target, const Vector3& p_up ) const {
|
Transform Transform::looking_at(const Vector3 &p_target, const Vector3 &p_up) const {
|
||||||
|
|
||||||
Transform t = *this;
|
Transform t = *this;
|
||||||
t.set_look_at(origin,p_target,p_up);
|
t.set_look_at(origin, p_target, p_up);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform::set_look_at( const Vector3& p_eye, const Vector3& p_target, const Vector3& p_up ) {
|
void Transform::set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const Vector3 &p_up) {
|
||||||
|
|
||||||
// Reference: MESA source code
|
// Reference: MESA source code
|
||||||
Vector3 v_x, v_y, v_z;
|
Vector3 v_x, v_y, v_z;
|
||||||
|
@ -198,23 +183,21 @@ void Transform::set_look_at( const Vector3& p_eye, const Vector3& p_target, cons
|
||||||
|
|
||||||
v_y = p_up;
|
v_y = p_up;
|
||||||
|
|
||||||
|
v_x = v_y.cross(v_z);
|
||||||
v_x=v_y.cross(v_z);
|
|
||||||
|
|
||||||
/* Recompute Y = Z cross X */
|
/* Recompute Y = Z cross X */
|
||||||
v_y=v_z.cross(v_x);
|
v_y = v_z.cross(v_x);
|
||||||
|
|
||||||
v_x.normalize();
|
v_x.normalize();
|
||||||
v_y.normalize();
|
v_y.normalize();
|
||||||
|
|
||||||
basis.set_axis(0,v_x);
|
basis.set_axis(0, v_x);
|
||||||
basis.set_axis(1,v_y);
|
basis.set_axis(1, v_y);
|
||||||
basis.set_axis(2,v_z);
|
basis.set_axis(2, v_z);
|
||||||
origin=p_eye;
|
origin = p_eye;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform Transform::interpolate_with(const Transform& p_transform, real_t p_c) const {
|
Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c) const {
|
||||||
|
|
||||||
/* not sure if very "efficient" but good enough? */
|
/* not sure if very "efficient" but good enough? */
|
||||||
|
|
||||||
|
@ -227,45 +210,44 @@ Transform Transform::interpolate_with(const Transform& p_transform, real_t p_c)
|
||||||
Vector3 dst_loc = p_transform.origin;
|
Vector3 dst_loc = p_transform.origin;
|
||||||
|
|
||||||
Transform dst;
|
Transform dst;
|
||||||
dst.basis=src_rot.slerp(dst_rot,p_c);
|
dst.basis = src_rot.slerp(dst_rot, p_c);
|
||||||
dst.basis.scale(src_scale.linear_interpolate(dst_scale,p_c));
|
dst.basis.scale(src_scale.linear_interpolate(dst_scale, p_c));
|
||||||
dst.origin=src_loc.linear_interpolate(dst_loc,p_c);
|
dst.origin = src_loc.linear_interpolate(dst_loc, p_c);
|
||||||
|
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform::scale(const Vector3& p_scale) {
|
void Transform::scale(const Vector3 &p_scale) {
|
||||||
|
|
||||||
basis.scale(p_scale);
|
basis.scale(p_scale);
|
||||||
origin*=p_scale;
|
origin *= p_scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform Transform::scaled(const Vector3& p_scale) const {
|
Transform Transform::scaled(const Vector3 &p_scale) const {
|
||||||
|
|
||||||
Transform t = *this;
|
Transform t = *this;
|
||||||
t.scale(p_scale);
|
t.scale(p_scale);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform::scale_basis(const Vector3& p_scale) {
|
void Transform::scale_basis(const Vector3 &p_scale) {
|
||||||
|
|
||||||
basis.scale(p_scale);
|
basis.scale(p_scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform::translate( real_t p_tx, real_t p_ty, real_t p_tz) {
|
void Transform::translate(real_t p_tx, real_t p_ty, real_t p_tz) {
|
||||||
translate( Vector3(p_tx,p_ty,p_tz) );
|
translate(Vector3(p_tx, p_ty, p_tz));
|
||||||
|
|
||||||
}
|
}
|
||||||
void Transform::translate( const Vector3& p_translation ) {
|
void Transform::translate(const Vector3 &p_translation) {
|
||||||
|
|
||||||
for( int i = 0; i < 3; i++ ) {
|
for (int i = 0; i < 3; i++) {
|
||||||
origin[i] += basis[i].dot(p_translation);
|
origin[i] += basis[i].dot(p_translation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform Transform::translated( const Vector3& p_translation ) const {
|
Transform Transform::translated(const Vector3 &p_translation) const {
|
||||||
|
|
||||||
Transform t=*this;
|
Transform t = *this;
|
||||||
t.translate(p_translation);
|
t.translate(p_translation);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
@ -282,25 +264,25 @@ Transform Transform::orthonormalized() const {
|
||||||
return _copy;
|
return _copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Transform::operator==(const Transform& p_transform) const {
|
bool Transform::operator==(const Transform &p_transform) const {
|
||||||
|
|
||||||
return (basis==p_transform.basis && origin==p_transform.origin);
|
return (basis == p_transform.basis && origin == p_transform.origin);
|
||||||
}
|
}
|
||||||
bool Transform::operator!=(const Transform& p_transform) const {
|
bool Transform::operator!=(const Transform &p_transform) const {
|
||||||
|
|
||||||
return (basis!=p_transform.basis || origin!=p_transform.origin);
|
return (basis != p_transform.basis || origin != p_transform.origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform::operator*=(const Transform& p_transform) {
|
void Transform::operator*=(const Transform &p_transform) {
|
||||||
|
|
||||||
origin=xform(p_transform.origin);
|
origin = xform(p_transform.origin);
|
||||||
basis*=p_transform.basis;
|
basis *= p_transform.basis;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform Transform::operator*(const Transform& p_transform) const {
|
Transform Transform::operator*(const Transform &p_transform) const {
|
||||||
|
|
||||||
Transform t=*this;
|
Transform t = *this;
|
||||||
t*=p_transform;
|
t *= p_transform;
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,11 +291,10 @@ Transform::operator String() const {
|
||||||
return basis.operator String() + " - " + origin.operator String();
|
return basis.operator String() + " - " + origin.operator String();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Transform::Transform(const Basis &p_basis, const Vector3 &p_origin) {
|
||||||
|
|
||||||
Transform::Transform(const Basis& p_basis, const Vector3& p_origin) {
|
basis = p_basis;
|
||||||
|
origin = p_origin;
|
||||||
basis=p_basis;
|
|
||||||
origin=p_origin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "Transform2D.hpp"
|
#include "Transform2D.hpp"
|
||||||
#include "Vector2.hpp"
|
|
||||||
#include "String.hpp"
|
|
||||||
#include "Rect2.hpp"
|
#include "Rect2.hpp"
|
||||||
|
#include "String.hpp"
|
||||||
|
#include "Vector2.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
@ -17,75 +17,68 @@ Transform2D::Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox,
|
||||||
elements[2][1] = oy;
|
elements[2][1] = oy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector2 Transform2D::basis_xform(const Vector2 &v) const {
|
||||||
|
|
||||||
Vector2 Transform2D::basis_xform(const Vector2& v) const {
|
|
||||||
|
|
||||||
return Vector2(
|
return Vector2(
|
||||||
tdotx(v),
|
tdotx(v),
|
||||||
tdoty(v)
|
tdoty(v));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Transform2D::basis_xform_inv(const Vector2& v) const{
|
Vector2 Transform2D::basis_xform_inv(const Vector2 &v) const {
|
||||||
|
|
||||||
return Vector2(
|
return Vector2(
|
||||||
elements[0].dot(v),
|
elements[0].dot(v),
|
||||||
elements[1].dot(v)
|
elements[1].dot(v));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Transform2D::xform(const Vector2& v) const {
|
Vector2 Transform2D::xform(const Vector2 &v) const {
|
||||||
|
|
||||||
return Vector2(
|
return Vector2(
|
||||||
tdotx(v),
|
tdotx(v),
|
||||||
tdoty(v)
|
tdoty(v)) +
|
||||||
) + elements[2];
|
elements[2];
|
||||||
}
|
}
|
||||||
Vector2 Transform2D::xform_inv(const Vector2& p_vec) const {
|
Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const {
|
||||||
|
|
||||||
Vector2 v = p_vec - elements[2];
|
Vector2 v = p_vec - elements[2];
|
||||||
|
|
||||||
return Vector2(
|
return Vector2(
|
||||||
elements[0].dot(v),
|
elements[0].dot(v),
|
||||||
elements[1].dot(v)
|
elements[1].dot(v));
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Rect2 Transform2D::xform(const Rect2& p_rect) const {
|
Rect2 Transform2D::xform(const Rect2 &p_rect) const {
|
||||||
|
|
||||||
Vector2 x=elements[0]*p_rect.size.x;
|
Vector2 x = elements[0] * p_rect.size.x;
|
||||||
Vector2 y=elements[1]*p_rect.size.y;
|
Vector2 y = elements[1] * p_rect.size.y;
|
||||||
Vector2 pos = xform( p_rect.pos );
|
Vector2 pos = xform(p_rect.pos);
|
||||||
|
|
||||||
Rect2 new_rect;
|
Rect2 new_rect;
|
||||||
new_rect.pos=pos;
|
new_rect.pos = pos;
|
||||||
new_rect.expand_to( pos+x );
|
new_rect.expand_to(pos + x);
|
||||||
new_rect.expand_to( pos+y );
|
new_rect.expand_to(pos + y);
|
||||||
new_rect.expand_to( pos+x+y );
|
new_rect.expand_to(pos + x + y);
|
||||||
return new_rect;
|
return new_rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform2D::set_rotation_and_scale(real_t p_rot,const Size2& p_scale) {
|
void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) {
|
||||||
|
|
||||||
elements[0][0]=::cos(p_rot)*p_scale.x;
|
|
||||||
elements[1][1]=::cos(p_rot)*p_scale.y;
|
|
||||||
elements[1][0]=-::sin(p_rot)*p_scale.y;
|
|
||||||
elements[0][1]=::sin(p_rot)*p_scale.x;
|
|
||||||
|
|
||||||
|
elements[0][0] = ::cos(p_rot) * p_scale.x;
|
||||||
|
elements[1][1] = ::cos(p_rot) * p_scale.y;
|
||||||
|
elements[1][0] = -::sin(p_rot) * p_scale.y;
|
||||||
|
elements[0][1] = ::sin(p_rot) * p_scale.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect2 Transform2D::xform_inv(const Rect2& p_rect) const {
|
Rect2 Transform2D::xform_inv(const Rect2 &p_rect) const {
|
||||||
|
|
||||||
Vector2 ends[4]={
|
Vector2 ends[4] = {
|
||||||
xform_inv( p_rect.pos ),
|
xform_inv(p_rect.pos),
|
||||||
xform_inv( Vector2(p_rect.pos.x,p_rect.pos.y+p_rect.size.y ) ),
|
xform_inv(Vector2(p_rect.pos.x, p_rect.pos.y + p_rect.size.y)),
|
||||||
xform_inv( Vector2(p_rect.pos.x+p_rect.size.x,p_rect.pos.y+p_rect.size.y ) ),
|
xform_inv(Vector2(p_rect.pos.x + p_rect.size.x, p_rect.pos.y + p_rect.size.y)),
|
||||||
xform_inv( Vector2(p_rect.pos.x+p_rect.size.x,p_rect.pos.y ) )
|
xform_inv(Vector2(p_rect.pos.x + p_rect.size.x, p_rect.pos.y))
|
||||||
};
|
};
|
||||||
|
|
||||||
Rect2 new_rect;
|
Rect2 new_rect;
|
||||||
new_rect.pos=ends[0];
|
new_rect.pos = ends[0];
|
||||||
new_rect.expand_to(ends[1]);
|
new_rect.expand_to(ends[1]);
|
||||||
new_rect.expand_to(ends[2]);
|
new_rect.expand_to(ends[2]);
|
||||||
new_rect.expand_to(ends[3]);
|
new_rect.expand_to(ends[3]);
|
||||||
|
@ -96,205 +89,194 @@ Rect2 Transform2D::xform_inv(const Rect2& p_rect) const {
|
||||||
void Transform2D::invert() {
|
void Transform2D::invert() {
|
||||||
// FIXME: this function assumes the basis is a rotation matrix, with no scaling.
|
// FIXME: this function assumes the basis is a rotation matrix, with no scaling.
|
||||||
// Transform2D::affine_inverse can handle matrices with scaling, so GDScript should eventually use that.
|
// Transform2D::affine_inverse can handle matrices with scaling, so GDScript should eventually use that.
|
||||||
std::swap(elements[0][1],elements[1][0]);
|
std::swap(elements[0][1], elements[1][0]);
|
||||||
elements[2] = basis_xform(-elements[2]);
|
elements[2] = basis_xform(-elements[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform2D Transform2D::inverse() const {
|
Transform2D Transform2D::inverse() const {
|
||||||
|
|
||||||
Transform2D inv=*this;
|
Transform2D inv = *this;
|
||||||
inv.invert();
|
inv.invert();
|
||||||
return inv;
|
return inv;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform2D::affine_invert() {
|
void Transform2D::affine_invert() {
|
||||||
|
|
||||||
real_t det = basis_determinant();
|
real_t det = basis_determinant();
|
||||||
ERR_FAIL_COND(det==0);
|
ERR_FAIL_COND(det == 0);
|
||||||
real_t idet = 1.0 / det;
|
real_t idet = 1.0 / det;
|
||||||
|
|
||||||
std::swap( elements[0][0],elements[1][1] );
|
std::swap(elements[0][0], elements[1][1]);
|
||||||
elements[0]*=Vector2(idet,-idet);
|
elements[0] *= Vector2(idet, -idet);
|
||||||
elements[1]*=Vector2(-idet,idet);
|
elements[1] *= Vector2(-idet, idet);
|
||||||
|
|
||||||
elements[2] = basis_xform(-elements[2]);
|
elements[2] = basis_xform(-elements[2]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform2D Transform2D::affine_inverse() const {
|
Transform2D Transform2D::affine_inverse() const {
|
||||||
|
|
||||||
Transform2D inv=*this;
|
Transform2D inv = *this;
|
||||||
inv.affine_invert();
|
inv.affine_invert();
|
||||||
return inv;
|
return inv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform2D::rotate(real_t p_phi) {
|
void Transform2D::rotate(real_t p_phi) {
|
||||||
*this = Transform2D(p_phi,Vector2()) * (*this);
|
*this = Transform2D(p_phi, Vector2()) * (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Transform2D::get_rotation() const {
|
real_t Transform2D::get_rotation() const {
|
||||||
real_t det = basis_determinant();
|
real_t det = basis_determinant();
|
||||||
Transform2D m = orthonormalized();
|
Transform2D m = orthonormalized();
|
||||||
if (det < 0) {
|
if (det < 0) {
|
||||||
m.scale_basis(Size2(-1,-1));
|
m.scale_basis(Size2(-1, -1));
|
||||||
}
|
}
|
||||||
return ::atan2(m[0].y,m[0].x);
|
return ::atan2(m[0].y, m[0].x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform2D::set_rotation(real_t p_rot) {
|
void Transform2D::set_rotation(real_t p_rot) {
|
||||||
|
|
||||||
real_t cr = ::cos(p_rot);
|
real_t cr = ::cos(p_rot);
|
||||||
real_t sr = ::sin(p_rot);
|
real_t sr = ::sin(p_rot);
|
||||||
elements[0][0]=cr;
|
elements[0][0] = cr;
|
||||||
elements[0][1]=sr;
|
elements[0][1] = sr;
|
||||||
elements[1][0]=-sr;
|
elements[1][0] = -sr;
|
||||||
elements[1][1]=cr;
|
elements[1][1] = cr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform2D::Transform2D(real_t p_rot, const Vector2& p_pos) {
|
Transform2D::Transform2D(real_t p_rot, const Vector2 &p_pos) {
|
||||||
|
|
||||||
real_t cr = ::cos(p_rot);
|
real_t cr = ::cos(p_rot);
|
||||||
real_t sr = ::sin(p_rot);
|
real_t sr = ::sin(p_rot);
|
||||||
elements[0][0]=cr;
|
elements[0][0] = cr;
|
||||||
elements[0][1]=sr;
|
elements[0][1] = sr;
|
||||||
elements[1][0]=-sr;
|
elements[1][0] = -sr;
|
||||||
elements[1][1]=cr;
|
elements[1][1] = cr;
|
||||||
elements[2]=p_pos;
|
elements[2] = p_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
Size2 Transform2D::get_scale() const {
|
Size2 Transform2D::get_scale() const {
|
||||||
real_t det_sign = basis_determinant() > 0 ? 1 : -1;
|
real_t det_sign = basis_determinant() > 0 ? 1 : -1;
|
||||||
return det_sign * Size2( elements[0].length(), elements[1].length() );
|
return det_sign * Size2(elements[0].length(), elements[1].length());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform2D::scale(const Size2& p_scale) {
|
void Transform2D::scale(const Size2 &p_scale) {
|
||||||
scale_basis(p_scale);
|
scale_basis(p_scale);
|
||||||
elements[2]*=p_scale;
|
elements[2] *= p_scale;
|
||||||
}
|
}
|
||||||
void Transform2D::scale_basis(const Size2& p_scale) {
|
void Transform2D::scale_basis(const Size2 &p_scale) {
|
||||||
|
|
||||||
elements[0][0]*=p_scale.x;
|
|
||||||
elements[0][1]*=p_scale.y;
|
|
||||||
elements[1][0]*=p_scale.x;
|
|
||||||
elements[1][1]*=p_scale.y;
|
|
||||||
|
|
||||||
|
elements[0][0] *= p_scale.x;
|
||||||
|
elements[0][1] *= p_scale.y;
|
||||||
|
elements[1][0] *= p_scale.x;
|
||||||
|
elements[1][1] *= p_scale.y;
|
||||||
}
|
}
|
||||||
void Transform2D::translate( real_t p_tx, real_t p_ty) {
|
void Transform2D::translate(real_t p_tx, real_t p_ty) {
|
||||||
|
|
||||||
translate(Vector2(p_tx,p_ty));
|
translate(Vector2(p_tx, p_ty));
|
||||||
}
|
}
|
||||||
void Transform2D::translate( const Vector2& p_translation ) {
|
void Transform2D::translate(const Vector2 &p_translation) {
|
||||||
|
|
||||||
elements[2]+=basis_xform(p_translation);
|
elements[2] += basis_xform(p_translation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform2D::orthonormalize() {
|
void Transform2D::orthonormalize() {
|
||||||
|
|
||||||
// Gram-Schmidt Process
|
// Gram-Schmidt Process
|
||||||
|
|
||||||
Vector2 x=elements[0];
|
Vector2 x = elements[0];
|
||||||
Vector2 y=elements[1];
|
Vector2 y = elements[1];
|
||||||
|
|
||||||
x.normalize();
|
x.normalize();
|
||||||
y = (y-x*(x.dot(y)));
|
y = (y - x * (x.dot(y)));
|
||||||
y.normalize();
|
y.normalize();
|
||||||
|
|
||||||
elements[0]=x;
|
elements[0] = x;
|
||||||
elements[1]=y;
|
elements[1] = y;
|
||||||
}
|
}
|
||||||
Transform2D Transform2D::orthonormalized() const {
|
Transform2D Transform2D::orthonormalized() const {
|
||||||
|
|
||||||
Transform2D on=*this;
|
Transform2D on = *this;
|
||||||
on.orthonormalize();
|
on.orthonormalize();
|
||||||
return on;
|
return on;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Transform2D::operator==(const Transform2D& p_transform) const {
|
bool Transform2D::operator==(const Transform2D &p_transform) const {
|
||||||
|
|
||||||
for(int i=0;i<3;i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
if (elements[i]!=p_transform.elements[i])
|
if (elements[i] != p_transform.elements[i])
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Transform2D::operator!=(const Transform2D& p_transform) const {
|
bool Transform2D::operator!=(const Transform2D &p_transform) const {
|
||||||
|
|
||||||
for(int i=0;i<3;i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
if (elements[i]!=p_transform.elements[i])
|
if (elements[i] != p_transform.elements[i])
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform2D::operator*=(const Transform2D& p_transform) {
|
void Transform2D::operator*=(const Transform2D &p_transform) {
|
||||||
|
|
||||||
elements[2] = xform(p_transform.elements[2]);
|
elements[2] = xform(p_transform.elements[2]);
|
||||||
|
|
||||||
real_t x0,x1,y0,y1;
|
real_t x0, x1, y0, y1;
|
||||||
|
|
||||||
x0 = tdotx(p_transform.elements[0]);
|
x0 = tdotx(p_transform.elements[0]);
|
||||||
x1 = tdoty(p_transform.elements[0]);
|
x1 = tdoty(p_transform.elements[0]);
|
||||||
y0 = tdotx(p_transform.elements[1]);
|
y0 = tdotx(p_transform.elements[1]);
|
||||||
y1 = tdoty(p_transform.elements[1]);
|
y1 = tdoty(p_transform.elements[1]);
|
||||||
|
|
||||||
elements[0][0]=x0;
|
elements[0][0] = x0;
|
||||||
elements[0][1]=x1;
|
elements[0][1] = x1;
|
||||||
elements[1][0]=y0;
|
elements[1][0] = y0;
|
||||||
elements[1][1]=y1;
|
elements[1][1] = y1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Transform2D Transform2D::operator*(const Transform2D &p_transform) const {
|
||||||
Transform2D Transform2D::operator*(const Transform2D& p_transform) const {
|
|
||||||
|
|
||||||
Transform2D t = *this;
|
Transform2D t = *this;
|
||||||
t*=p_transform;
|
t *= p_transform;
|
||||||
return t;
|
return t;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform2D Transform2D::scaled(const Size2& p_scale) const {
|
Transform2D Transform2D::scaled(const Size2 &p_scale) const {
|
||||||
|
|
||||||
Transform2D copy=*this;
|
Transform2D copy = *this;
|
||||||
copy.scale(p_scale);
|
copy.scale(p_scale);
|
||||||
return copy;
|
return copy;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform2D Transform2D::basis_scaled(const Size2& p_scale) const {
|
Transform2D Transform2D::basis_scaled(const Size2 &p_scale) const {
|
||||||
|
|
||||||
Transform2D copy=*this;
|
Transform2D copy = *this;
|
||||||
copy.scale_basis(p_scale);
|
copy.scale_basis(p_scale);
|
||||||
return copy;
|
return copy;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform2D Transform2D::untranslated() const {
|
Transform2D Transform2D::untranslated() const {
|
||||||
|
|
||||||
Transform2D copy=*this;
|
Transform2D copy = *this;
|
||||||
copy.elements[2]=Vector2();
|
copy.elements[2] = Vector2();
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform2D Transform2D::translated(const Vector2& p_offset) const {
|
Transform2D Transform2D::translated(const Vector2 &p_offset) const {
|
||||||
|
|
||||||
Transform2D copy=*this;
|
Transform2D copy = *this;
|
||||||
copy.translate(p_offset);
|
copy.translate(p_offset);
|
||||||
return copy;
|
return copy;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform2D Transform2D::rotated(real_t p_phi) const {
|
Transform2D Transform2D::rotated(real_t p_phi) const {
|
||||||
|
|
||||||
Transform2D copy=*this;
|
Transform2D copy = *this;
|
||||||
copy.rotate(p_phi);
|
copy.rotate(p_phi);
|
||||||
return copy;
|
return copy;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Transform2D::basis_determinant() const {
|
real_t Transform2D::basis_determinant() const {
|
||||||
|
@ -302,7 +284,7 @@ real_t Transform2D::basis_determinant() const {
|
||||||
return elements[0].x * elements[1].y - elements[0].y * elements[1].x;
|
return elements[0].x * elements[1].y - elements[0].y * elements[1].x;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform2D Transform2D::interpolate_with(const Transform2D& p_transform, real_t p_c) const {
|
Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t p_c) const {
|
||||||
|
|
||||||
//extract parameters
|
//extract parameters
|
||||||
Vector2 p1 = get_origin();
|
Vector2 p1 = get_origin();
|
||||||
|
@ -327,9 +309,9 @@ Transform2D Transform2D::interpolate_with(const Transform2D& p_transform, real_t
|
||||||
if (dot > 0.9995) {
|
if (dot > 0.9995) {
|
||||||
v = Vector2::linear_interpolate(v1, v2, p_c).normalized(); //linearly interpolate to avoid numerical precision issues
|
v = Vector2::linear_interpolate(v1, v2, p_c).normalized(); //linearly interpolate to avoid numerical precision issues
|
||||||
} else {
|
} else {
|
||||||
real_t angle = p_c*::acos(dot);
|
real_t angle = p_c * ::acos(dot);
|
||||||
Vector2 v3 = (v2 - v1*dot).normalized();
|
Vector2 v3 = (v2 - v1 * dot).normalized();
|
||||||
v = v1*::cos(angle) + v3*::sin(angle);
|
v = v1 * ::cos(angle) + v3 * ::sin(angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
//construct matrix
|
//construct matrix
|
||||||
|
@ -343,4 +325,4 @@ Transform2D::operator String() const {
|
||||||
return String(String() + elements[0] + ", " + elements[1] + ", " + elements[2]);
|
return String(String() + elements[0] + ", " + elements[1] + ", " + elements[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace godot
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
#include <gdnative/variant.h>
|
#include <gdnative/variant.h>
|
||||||
|
|
||||||
#include "Defs.hpp"
|
|
||||||
#include "CoreTypes.hpp"
|
#include "CoreTypes.hpp"
|
||||||
|
#include "Defs.hpp"
|
||||||
#include "GodotGlobal.hpp"
|
#include "GodotGlobal.hpp"
|
||||||
#include "Object.hpp"
|
#include "Object.hpp"
|
||||||
|
|
||||||
|
@ -11,18 +11,15 @@
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
Variant::Variant()
|
Variant::Variant() {
|
||||||
{
|
|
||||||
godot::api->godot_variant_new_nil(&_godot_variant);
|
godot::api->godot_variant_new_nil(&_godot_variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const Variant& v)
|
Variant::Variant(const Variant &v) {
|
||||||
{
|
|
||||||
godot::api->godot_variant_new_copy(&_godot_variant, &v._godot_variant);
|
godot::api->godot_variant_new_copy(&_godot_variant, &v._godot_variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(bool p_bool)
|
Variant::Variant(bool p_bool) {
|
||||||
{
|
|
||||||
godot::api->godot_variant_new_bool(&_godot_variant, p_bool);
|
godot::api->godot_variant_new_bool(&_godot_variant, p_bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,410 +28,326 @@ Variant::Variant(signed int p_int) // real one
|
||||||
godot::api->godot_variant_new_int(&_godot_variant, p_int);
|
godot::api->godot_variant_new_int(&_godot_variant, p_int);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(unsigned int p_int)
|
Variant::Variant(unsigned int p_int) {
|
||||||
{
|
|
||||||
godot::api->godot_variant_new_uint(&_godot_variant, p_int);
|
godot::api->godot_variant_new_uint(&_godot_variant, p_int);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(signed short p_short) // real one
|
Variant::Variant(signed short p_short) // real one
|
||||||
{
|
{
|
||||||
godot::api->godot_variant_new_int(&_godot_variant, (int) p_short);
|
godot::api->godot_variant_new_int(&_godot_variant, (int)p_short);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Variant::Variant(int64_t p_char) // real one
|
Variant::Variant(int64_t p_char) // real one
|
||||||
{
|
{
|
||||||
godot::api->godot_variant_new_int(&_godot_variant, p_char);
|
godot::api->godot_variant_new_int(&_godot_variant, p_char);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(uint64_t p_char)
|
Variant::Variant(uint64_t p_char) {
|
||||||
{
|
|
||||||
godot::api->godot_variant_new_uint(&_godot_variant, p_char);
|
godot::api->godot_variant_new_uint(&_godot_variant, p_char);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(float p_float)
|
Variant::Variant(float p_float) {
|
||||||
{
|
|
||||||
godot::api->godot_variant_new_real(&_godot_variant, p_float);
|
godot::api->godot_variant_new_real(&_godot_variant, p_float);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(double p_double)
|
Variant::Variant(double p_double) {
|
||||||
{
|
|
||||||
godot::api->godot_variant_new_real(&_godot_variant, p_double);
|
godot::api->godot_variant_new_real(&_godot_variant, p_double);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const String& p_string)
|
Variant::Variant(const String &p_string) {
|
||||||
{
|
godot::api->godot_variant_new_string(&_godot_variant, (godot_string *)&p_string);
|
||||||
godot::api->godot_variant_new_string(&_godot_variant, (godot_string *) &p_string);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const char * const p_cstring)
|
Variant::Variant(const char *const p_cstring) {
|
||||||
{
|
|
||||||
String s = String(p_cstring);
|
String s = String(p_cstring);
|
||||||
godot::api->godot_variant_new_string(&_godot_variant, (godot_string *) &s);
|
godot::api->godot_variant_new_string(&_godot_variant, (godot_string *)&s);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const wchar_t * p_wstring)
|
Variant::Variant(const wchar_t *p_wstring) {
|
||||||
{
|
|
||||||
String s = p_wstring;
|
String s = p_wstring;
|
||||||
godot::api->godot_variant_new_string(&_godot_variant, (godot_string *) &s);
|
godot::api->godot_variant_new_string(&_godot_variant, (godot_string *)&s);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const Vector2& p_vector2)
|
Variant::Variant(const Vector2 &p_vector2) {
|
||||||
{
|
godot::api->godot_variant_new_vector2(&_godot_variant, (godot_vector2 *)&p_vector2);
|
||||||
godot::api->godot_variant_new_vector2(&_godot_variant, (godot_vector2 *) &p_vector2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const Rect2& p_rect2)
|
Variant::Variant(const Rect2 &p_rect2) {
|
||||||
{
|
godot::api->godot_variant_new_rect2(&_godot_variant, (godot_rect2 *)&p_rect2);
|
||||||
godot::api->godot_variant_new_rect2(&_godot_variant, (godot_rect2 *) &p_rect2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const Vector3& p_vector3)
|
Variant::Variant(const Vector3 &p_vector3) {
|
||||||
{
|
godot::api->godot_variant_new_vector3(&_godot_variant, (godot_vector3 *)&p_vector3);
|
||||||
godot::api->godot_variant_new_vector3(&_godot_variant, (godot_vector3 *) &p_vector3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const Plane& p_plane)
|
Variant::Variant(const Plane &p_plane) {
|
||||||
{
|
godot::api->godot_variant_new_plane(&_godot_variant, (godot_plane *)&p_plane);
|
||||||
godot::api->godot_variant_new_plane(&_godot_variant, (godot_plane *) &p_plane);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Variant::Variant(const AABB &p_aabb) {
|
||||||
Variant::Variant(const AABB& p_aabb)
|
godot::api->godot_variant_new_aabb(&_godot_variant, (godot_aabb *)&p_aabb);
|
||||||
{
|
|
||||||
godot::api->godot_variant_new_aabb(&_godot_variant, (godot_aabb *) &p_aabb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const Quat& p_quat)
|
Variant::Variant(const Quat &p_quat) {
|
||||||
{
|
godot::api->godot_variant_new_quat(&_godot_variant, (godot_quat *)&p_quat);
|
||||||
godot::api->godot_variant_new_quat(&_godot_variant, (godot_quat *) &p_quat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const Basis& p_transform)
|
Variant::Variant(const Basis &p_transform) {
|
||||||
{
|
godot::api->godot_variant_new_basis(&_godot_variant, (godot_basis *)&p_transform);
|
||||||
godot::api->godot_variant_new_basis(&_godot_variant, (godot_basis *) &p_transform);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const Transform2D& p_transform)
|
Variant::Variant(const Transform2D &p_transform) {
|
||||||
{
|
godot::api->godot_variant_new_transform2d(&_godot_variant, (godot_transform2d *)&p_transform);
|
||||||
godot::api->godot_variant_new_transform2d(&_godot_variant, (godot_transform2d *) &p_transform);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const Transform& p_transform)
|
Variant::Variant(const Transform &p_transform) {
|
||||||
{
|
godot::api->godot_variant_new_transform(&_godot_variant, (godot_transform *)&p_transform);
|
||||||
godot::api->godot_variant_new_transform(&_godot_variant, (godot_transform *) &p_transform);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const Color& p_color)
|
Variant::Variant(const Color &p_color) {
|
||||||
{
|
godot::api->godot_variant_new_color(&_godot_variant, (godot_color *)&p_color);
|
||||||
godot::api->godot_variant_new_color(&_godot_variant, (godot_color *) &p_color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const NodePath& p_path)
|
Variant::Variant(const NodePath &p_path) {
|
||||||
{
|
godot::api->godot_variant_new_node_path(&_godot_variant, (godot_node_path *)&p_path);
|
||||||
godot::api->godot_variant_new_node_path(&_godot_variant, (godot_node_path *) &p_path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const RID& p_rid)
|
Variant::Variant(const RID &p_rid) {
|
||||||
{
|
godot::api->godot_variant_new_rid(&_godot_variant, (godot_rid *)&p_rid);
|
||||||
godot::api->godot_variant_new_rid(&_godot_variant, (godot_rid *) &p_rid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const Object* p_object)
|
Variant::Variant(const Object *p_object) {
|
||||||
{
|
|
||||||
if (p_object)
|
if (p_object)
|
||||||
godot::api->godot_variant_new_object(&_godot_variant, p_object->_owner);
|
godot::api->godot_variant_new_object(&_godot_variant, p_object->_owner);
|
||||||
else
|
else
|
||||||
godot::api->godot_variant_new_nil(&_godot_variant);
|
godot::api->godot_variant_new_nil(&_godot_variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const Dictionary& p_dictionary)
|
Variant::Variant(const Dictionary &p_dictionary) {
|
||||||
{
|
godot::api->godot_variant_new_dictionary(&_godot_variant, (godot_dictionary *)&p_dictionary);
|
||||||
godot::api->godot_variant_new_dictionary(&_godot_variant, (godot_dictionary *) &p_dictionary);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const Array& p_array)
|
Variant::Variant(const Array &p_array) {
|
||||||
{
|
godot::api->godot_variant_new_array(&_godot_variant, (godot_array *)&p_array);
|
||||||
godot::api->godot_variant_new_array(&_godot_variant, (godot_array *) &p_array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const PoolByteArray& p_raw_array)
|
Variant::Variant(const PoolByteArray &p_raw_array) {
|
||||||
{
|
godot::api->godot_variant_new_pool_byte_array(&_godot_variant, (godot_pool_byte_array *)&p_raw_array);
|
||||||
godot::api->godot_variant_new_pool_byte_array(&_godot_variant, (godot_pool_byte_array *) &p_raw_array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const PoolIntArray& p_int_array)
|
Variant::Variant(const PoolIntArray &p_int_array) {
|
||||||
{
|
godot::api->godot_variant_new_pool_int_array(&_godot_variant, (godot_pool_int_array *)&p_int_array);
|
||||||
godot::api->godot_variant_new_pool_int_array(&_godot_variant, (godot_pool_int_array *) &p_int_array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const PoolRealArray& p_real_array)
|
Variant::Variant(const PoolRealArray &p_real_array) {
|
||||||
{
|
godot::api->godot_variant_new_pool_real_array(&_godot_variant, (godot_pool_real_array *)&p_real_array);
|
||||||
godot::api->godot_variant_new_pool_real_array(&_godot_variant, (godot_pool_real_array *) &p_real_array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const PoolStringArray& p_string_array)
|
Variant::Variant(const PoolStringArray &p_string_array) {
|
||||||
{
|
godot::api->godot_variant_new_pool_string_array(&_godot_variant, (godot_pool_string_array *)&p_string_array);
|
||||||
godot::api->godot_variant_new_pool_string_array(&_godot_variant, (godot_pool_string_array *) &p_string_array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const PoolVector2Array& p_vector2_array)
|
Variant::Variant(const PoolVector2Array &p_vector2_array) {
|
||||||
{
|
godot::api->godot_variant_new_pool_vector2_array(&_godot_variant, (godot_pool_vector2_array *)&p_vector2_array);
|
||||||
godot::api->godot_variant_new_pool_vector2_array(&_godot_variant, (godot_pool_vector2_array *) &p_vector2_array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const PoolVector3Array& p_vector3_array)
|
Variant::Variant(const PoolVector3Array &p_vector3_array) {
|
||||||
{
|
godot::api->godot_variant_new_pool_vector3_array(&_godot_variant, (godot_pool_vector3_array *)&p_vector3_array);
|
||||||
godot::api->godot_variant_new_pool_vector3_array(&_godot_variant, (godot_pool_vector3_array *) &p_vector3_array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Variant(const PoolColorArray& p_color_array)
|
Variant::Variant(const PoolColorArray &p_color_array) {
|
||||||
{
|
godot::api->godot_variant_new_pool_color_array(&_godot_variant, (godot_pool_color_array *)&p_color_array);
|
||||||
godot::api->godot_variant_new_pool_color_array(&_godot_variant, (godot_pool_color_array *) &p_color_array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Variant &Variant::operator=(const Variant &v) {
|
||||||
Variant &Variant::operator =(const Variant& v)
|
|
||||||
{
|
|
||||||
godot::api->godot_variant_new_copy(&_godot_variant, &v._godot_variant);
|
godot::api->godot_variant_new_copy(&_godot_variant, &v._godot_variant);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Variant::operator bool() const {
|
||||||
Variant::operator bool() const
|
|
||||||
{
|
|
||||||
return booleanize();
|
return booleanize();
|
||||||
}
|
}
|
||||||
Variant::operator signed int() const
|
Variant::operator signed int() const {
|
||||||
{
|
|
||||||
return godot::api->godot_variant_as_int(&_godot_variant);
|
return godot::api->godot_variant_as_int(&_godot_variant);
|
||||||
}
|
}
|
||||||
Variant::operator unsigned int() const // this is the real one
|
Variant::operator unsigned int() const // this is the real one
|
||||||
{
|
{
|
||||||
return godot::api->godot_variant_as_uint(&_godot_variant);
|
return godot::api->godot_variant_as_uint(&_godot_variant);
|
||||||
}
|
}
|
||||||
Variant::operator signed short() const
|
Variant::operator signed short() const {
|
||||||
{
|
|
||||||
return godot::api->godot_variant_as_int(&_godot_variant);
|
return godot::api->godot_variant_as_int(&_godot_variant);
|
||||||
}
|
}
|
||||||
Variant::operator unsigned short() const
|
Variant::operator unsigned short() const {
|
||||||
{
|
|
||||||
return godot::api->godot_variant_as_uint(&_godot_variant);
|
return godot::api->godot_variant_as_uint(&_godot_variant);
|
||||||
}
|
}
|
||||||
Variant::operator signed char() const
|
Variant::operator signed char() const {
|
||||||
{
|
|
||||||
return godot::api->godot_variant_as_int(&_godot_variant);
|
return godot::api->godot_variant_as_int(&_godot_variant);
|
||||||
}
|
}
|
||||||
Variant::operator unsigned char() const
|
Variant::operator unsigned char() const {
|
||||||
{
|
|
||||||
return godot::api->godot_variant_as_uint(&_godot_variant);
|
return godot::api->godot_variant_as_uint(&_godot_variant);
|
||||||
}
|
}
|
||||||
Variant::operator int64_t() const
|
Variant::operator int64_t() const {
|
||||||
{
|
|
||||||
return godot::api->godot_variant_as_int(&_godot_variant);
|
return godot::api->godot_variant_as_int(&_godot_variant);
|
||||||
}
|
}
|
||||||
Variant::operator uint64_t() const
|
Variant::operator uint64_t() const {
|
||||||
{
|
|
||||||
return godot::api->godot_variant_as_uint(&_godot_variant);
|
return godot::api->godot_variant_as_uint(&_godot_variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Variant::operator wchar_t() const {
|
||||||
Variant::operator wchar_t() const
|
|
||||||
{
|
|
||||||
return godot::api->godot_variant_as_int(&_godot_variant);
|
return godot::api->godot_variant_as_int(&_godot_variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::operator float() const
|
Variant::operator float() const {
|
||||||
{
|
|
||||||
return godot::api->godot_variant_as_real(&_godot_variant);
|
return godot::api->godot_variant_as_real(&_godot_variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::operator double() const
|
Variant::operator double() const {
|
||||||
{
|
|
||||||
return godot::api->godot_variant_as_real(&_godot_variant);
|
return godot::api->godot_variant_as_real(&_godot_variant);
|
||||||
}
|
}
|
||||||
Variant::operator String() const
|
Variant::operator String() const {
|
||||||
{
|
|
||||||
godot_string s = godot::api->godot_variant_as_string(&_godot_variant);
|
godot_string s = godot::api->godot_variant_as_string(&_godot_variant);
|
||||||
return *(String *) &s;
|
return *(String *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator Vector2() const
|
Variant::operator Vector2() const {
|
||||||
{
|
|
||||||
godot_vector2 s = godot::api->godot_variant_as_vector2(&_godot_variant);
|
godot_vector2 s = godot::api->godot_variant_as_vector2(&_godot_variant);
|
||||||
return *(Vector2 *) &s;
|
return *(Vector2 *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator Rect2() const
|
Variant::operator Rect2() const {
|
||||||
{
|
|
||||||
godot_rect2 s = godot::api->godot_variant_as_rect2(&_godot_variant);
|
godot_rect2 s = godot::api->godot_variant_as_rect2(&_godot_variant);
|
||||||
return *(Rect2 *) &s;
|
return *(Rect2 *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator Vector3() const
|
Variant::operator Vector3() const {
|
||||||
{
|
|
||||||
godot_vector3 s = godot::api->godot_variant_as_vector3(&_godot_variant);
|
godot_vector3 s = godot::api->godot_variant_as_vector3(&_godot_variant);
|
||||||
return *(Vector3 *) &s;
|
return *(Vector3 *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator Plane() const
|
Variant::operator Plane() const {
|
||||||
{
|
|
||||||
godot_plane s = godot::api->godot_variant_as_plane(&_godot_variant);
|
godot_plane s = godot::api->godot_variant_as_plane(&_godot_variant);
|
||||||
return *(Plane *) &s;
|
return *(Plane *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator AABB() const
|
Variant::operator AABB() const {
|
||||||
{
|
|
||||||
godot_aabb s = godot::api->godot_variant_as_aabb(&_godot_variant);
|
godot_aabb s = godot::api->godot_variant_as_aabb(&_godot_variant);
|
||||||
return *(AABB *) &s;
|
return *(AABB *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator Quat() const
|
Variant::operator Quat() const {
|
||||||
{
|
|
||||||
godot_quat s = godot::api->godot_variant_as_quat(&_godot_variant);
|
godot_quat s = godot::api->godot_variant_as_quat(&_godot_variant);
|
||||||
return *(Quat *) &s;
|
return *(Quat *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator Basis() const
|
Variant::operator Basis() const {
|
||||||
{
|
|
||||||
godot_basis s = godot::api->godot_variant_as_basis(&_godot_variant);
|
godot_basis s = godot::api->godot_variant_as_basis(&_godot_variant);
|
||||||
return *(Basis *) &s;
|
return *(Basis *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator Transform() const
|
Variant::operator Transform() const {
|
||||||
{
|
|
||||||
godot_transform s = godot::api->godot_variant_as_transform(&_godot_variant);
|
godot_transform s = godot::api->godot_variant_as_transform(&_godot_variant);
|
||||||
return *(Transform *) &s;
|
return *(Transform *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator Transform2D() const
|
Variant::operator Transform2D() const {
|
||||||
{
|
|
||||||
godot_transform2d s = godot::api->godot_variant_as_transform2d(&_godot_variant);
|
godot_transform2d s = godot::api->godot_variant_as_transform2d(&_godot_variant);
|
||||||
return *(Transform2D *) &s;
|
return *(Transform2D *)&s;
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::operator Color() const
|
Variant::operator Color() const {
|
||||||
{
|
|
||||||
godot_color s = godot::api->godot_variant_as_color(&_godot_variant);
|
godot_color s = godot::api->godot_variant_as_color(&_godot_variant);
|
||||||
return *(Color *) &s;
|
return *(Color *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator NodePath() const
|
Variant::operator NodePath() const {
|
||||||
{
|
|
||||||
godot_node_path s = godot::api->godot_variant_as_node_path(&_godot_variant);
|
godot_node_path s = godot::api->godot_variant_as_node_path(&_godot_variant);
|
||||||
return *(NodePath *) &s;
|
return *(NodePath *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator RID() const
|
Variant::operator RID() const {
|
||||||
{
|
|
||||||
godot_rid s = godot::api->godot_variant_as_rid(&_godot_variant);
|
godot_rid s = godot::api->godot_variant_as_rid(&_godot_variant);
|
||||||
return *(RID *) &s;
|
return *(RID *)&s;
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::operator Dictionary() const
|
Variant::operator Dictionary() const {
|
||||||
{
|
|
||||||
godot_dictionary d = godot::api->godot_variant_as_dictionary(&_godot_variant);
|
godot_dictionary d = godot::api->godot_variant_as_dictionary(&_godot_variant);
|
||||||
return *(Dictionary *) &d;
|
return *(Dictionary *)&d;
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::operator Array() const
|
Variant::operator Array() const {
|
||||||
{
|
|
||||||
godot_array s = godot::api->godot_variant_as_array(&_godot_variant);
|
godot_array s = godot::api->godot_variant_as_array(&_godot_variant);
|
||||||
return *(Array *) &s;
|
return *(Array *)&s;
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::operator PoolByteArray() const
|
Variant::operator PoolByteArray() const {
|
||||||
{
|
|
||||||
godot_pool_byte_array s = godot::api->godot_variant_as_pool_byte_array(&_godot_variant);
|
godot_pool_byte_array s = godot::api->godot_variant_as_pool_byte_array(&_godot_variant);
|
||||||
return *(PoolByteArray *) &s;
|
return *(PoolByteArray *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator PoolIntArray() const
|
Variant::operator PoolIntArray() const {
|
||||||
{
|
|
||||||
godot_pool_int_array s = godot::api->godot_variant_as_pool_int_array(&_godot_variant);
|
godot_pool_int_array s = godot::api->godot_variant_as_pool_int_array(&_godot_variant);
|
||||||
return *(PoolIntArray *) &s;
|
return *(PoolIntArray *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator PoolRealArray() const
|
Variant::operator PoolRealArray() const {
|
||||||
{
|
|
||||||
godot_pool_real_array s = godot::api->godot_variant_as_pool_real_array(&_godot_variant);
|
godot_pool_real_array s = godot::api->godot_variant_as_pool_real_array(&_godot_variant);
|
||||||
return *(PoolRealArray *) &s;
|
return *(PoolRealArray *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator PoolStringArray() const
|
Variant::operator PoolStringArray() const {
|
||||||
{
|
|
||||||
godot_pool_string_array s = godot::api->godot_variant_as_pool_string_array(&_godot_variant);
|
godot_pool_string_array s = godot::api->godot_variant_as_pool_string_array(&_godot_variant);
|
||||||
return *(PoolStringArray *) &s;
|
return *(PoolStringArray *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator PoolVector2Array() const
|
Variant::operator PoolVector2Array() const {
|
||||||
{
|
|
||||||
godot_pool_vector2_array s = godot::api->godot_variant_as_pool_vector2_array(&_godot_variant);
|
godot_pool_vector2_array s = godot::api->godot_variant_as_pool_vector2_array(&_godot_variant);
|
||||||
return *(PoolVector2Array *) &s;
|
return *(PoolVector2Array *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator PoolVector3Array() const
|
Variant::operator PoolVector3Array() const {
|
||||||
{
|
|
||||||
godot_pool_vector3_array s = godot::api->godot_variant_as_pool_vector3_array(&_godot_variant);
|
godot_pool_vector3_array s = godot::api->godot_variant_as_pool_vector3_array(&_godot_variant);
|
||||||
return *(PoolVector3Array *) &s;
|
return *(PoolVector3Array *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator PoolColorArray() const
|
Variant::operator PoolColorArray() const {
|
||||||
{
|
|
||||||
godot_pool_color_array s = godot::api->godot_variant_as_pool_color_array(&_godot_variant);
|
godot_pool_color_array s = godot::api->godot_variant_as_pool_color_array(&_godot_variant);
|
||||||
return *(PoolColorArray *) &s;
|
return *(PoolColorArray *)&s;
|
||||||
}
|
}
|
||||||
Variant::operator godot_object*() const {
|
Variant::operator godot_object *() const {
|
||||||
return godot::api->godot_variant_as_object(&_godot_variant);
|
return godot::api->godot_variant_as_object(&_godot_variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::Type Variant::get_type() const
|
Variant::Type Variant::get_type() const {
|
||||||
{
|
return (Type)godot::api->godot_variant_get_type(&_godot_variant);
|
||||||
return (Type) godot::api->godot_variant_get_type(&_godot_variant);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Variant Variant::call(const String &method, const Variant **args, const int arg_count) {
|
||||||
Variant Variant::call(const String& method, const Variant **args, const int arg_count)
|
|
||||||
{
|
|
||||||
Variant v;
|
Variant v;
|
||||||
*(godot_variant *) &v = godot::api->godot_variant_call(&_godot_variant, (godot_string *) &method, (const godot_variant **)args, arg_count, nullptr);
|
*(godot_variant *)&v = godot::api->godot_variant_call(&_godot_variant, (godot_string *)&method, (const godot_variant **)args, arg_count, nullptr);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Variant::has_method(const String& method)
|
bool Variant::has_method(const String &method) {
|
||||||
{
|
return godot::api->godot_variant_has_method(&_godot_variant, (godot_string *)&method);
|
||||||
return godot::api->godot_variant_has_method(&_godot_variant, (godot_string *) &method);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Variant::operator ==(const Variant& b) const
|
bool Variant::operator==(const Variant &b) const {
|
||||||
{
|
|
||||||
return godot::api->godot_variant_operator_equal(&_godot_variant, &b._godot_variant);
|
return godot::api->godot_variant_operator_equal(&_godot_variant, &b._godot_variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Variant::operator !=(const Variant& b) const
|
bool Variant::operator!=(const Variant &b) const {
|
||||||
{
|
|
||||||
return !(*this == b);
|
return !(*this == b);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Variant::operator <(const Variant& b) const
|
bool Variant::operator<(const Variant &b) const {
|
||||||
{
|
|
||||||
return godot::api->godot_variant_operator_less(&_godot_variant, &b._godot_variant);
|
return godot::api->godot_variant_operator_less(&_godot_variant, &b._godot_variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Variant::operator <=(const Variant& b) const
|
bool Variant::operator<=(const Variant &b) const {
|
||||||
{
|
|
||||||
return (*this < b) || (*this == b);
|
return (*this < b) || (*this == b);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Variant::operator >(const Variant& b) const
|
bool Variant::operator>(const Variant &b) const {
|
||||||
{
|
|
||||||
return !(*this <= b);
|
return !(*this <= b);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Variant::operator >=(const Variant& b) const
|
bool Variant::operator>=(const Variant &b) const {
|
||||||
{
|
|
||||||
return !(*this < b);
|
return !(*this < b);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Variant::hash_compare(const Variant& b) const
|
bool Variant::hash_compare(const Variant &b) const {
|
||||||
{
|
|
||||||
return godot::api->godot_variant_hash_compare(&_godot_variant, &b._godot_variant);
|
return godot::api->godot_variant_hash_compare(&_godot_variant, &b._godot_variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Variant::booleanize() const
|
bool Variant::booleanize() const {
|
||||||
{
|
|
||||||
return godot::api->godot_variant_booleanize(&_godot_variant);
|
return godot::api->godot_variant_booleanize(&_godot_variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::~Variant()
|
Variant::~Variant() {
|
||||||
{
|
|
||||||
godot::api->godot_variant_destroy(&_godot_variant);
|
godot::api->godot_variant_destroy(&_godot_variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -8,78 +8,64 @@
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
Vector2 Vector2::operator+(const Vector2& p_v) const
|
Vector2 Vector2::operator+(const Vector2 &p_v) const {
|
||||||
{
|
|
||||||
return Vector2(x + p_v.x, y + p_v.y);
|
return Vector2(x + p_v.x, y + p_v.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector2::operator+=(const Vector2& p_v)
|
void Vector2::operator+=(const Vector2 &p_v) {
|
||||||
{
|
|
||||||
x += p_v.x;
|
x += p_v.x;
|
||||||
y += p_v.y;
|
y += p_v.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::operator-(const Vector2& p_v) const
|
Vector2 Vector2::operator-(const Vector2 &p_v) const {
|
||||||
{
|
|
||||||
return Vector2(x - p_v.x, y - p_v.y);
|
return Vector2(x - p_v.x, y - p_v.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector2::operator-=(const Vector2& p_v)
|
void Vector2::operator-=(const Vector2 &p_v) {
|
||||||
{
|
|
||||||
x -= p_v.x;
|
x -= p_v.x;
|
||||||
y -= p_v.y;
|
y -= p_v.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::operator*(const Vector2 &p_v1) const
|
Vector2 Vector2::operator*(const Vector2 &p_v1) const {
|
||||||
{
|
|
||||||
return Vector2(x * p_v1.x, y * p_v1.y);
|
return Vector2(x * p_v1.x, y * p_v1.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::operator*(const real_t &rvalue) const
|
Vector2 Vector2::operator*(const real_t &rvalue) const {
|
||||||
{
|
|
||||||
return Vector2(x * rvalue, y * rvalue);
|
return Vector2(x * rvalue, y * rvalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector2::operator*=(const real_t &rvalue)
|
void Vector2::operator*=(const real_t &rvalue) {
|
||||||
{
|
|
||||||
x *= rvalue;
|
x *= rvalue;
|
||||||
y *= rvalue;
|
y *= rvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::operator/(const Vector2 &p_v1) const
|
Vector2 Vector2::operator/(const Vector2 &p_v1) const {
|
||||||
{
|
|
||||||
return Vector2(x / p_v1.x, y / p_v1.y);
|
return Vector2(x / p_v1.x, y / p_v1.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::operator/(const real_t &rvalue) const
|
Vector2 Vector2::operator/(const real_t &rvalue) const {
|
||||||
{
|
|
||||||
return Vector2(x / rvalue, y / rvalue);
|
return Vector2(x / rvalue, y / rvalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector2::operator/=(const real_t &rvalue)
|
void Vector2::operator/=(const real_t &rvalue) {
|
||||||
{
|
|
||||||
x /= rvalue;
|
x /= rvalue;
|
||||||
y /= rvalue;
|
y /= rvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::operator-() const
|
Vector2 Vector2::operator-() const {
|
||||||
{
|
|
||||||
return Vector2(-x, -y);
|
return Vector2(-x, -y);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector2::operator==(const Vector2& p_vec2) const
|
bool Vector2::operator==(const Vector2 &p_vec2) const {
|
||||||
{
|
|
||||||
return x == p_vec2.x && y == p_vec2.y;
|
return x == p_vec2.x && y == p_vec2.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector2::operator!=(const Vector2& p_vec2) const
|
bool Vector2::operator!=(const Vector2 &p_vec2) const {
|
||||||
{
|
|
||||||
return x != p_vec2.x || y != p_vec2.y;
|
return x != p_vec2.x || y != p_vec2.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector2::normalize()
|
void Vector2::normalize() {
|
||||||
{
|
real_t l = x * x + y * y;
|
||||||
real_t l = x*x + y*y;
|
|
||||||
if (l != 0) {
|
if (l != 0) {
|
||||||
l = sqrt(l);
|
l = sqrt(l);
|
||||||
x /= l;
|
x /= l;
|
||||||
|
@ -87,71 +73,58 @@ void Vector2::normalize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::normalized() const
|
Vector2 Vector2::normalized() const {
|
||||||
{
|
|
||||||
Vector2 v = *this;
|
Vector2 v = *this;
|
||||||
v.normalize();
|
v.normalize();
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Vector2::length() const
|
real_t Vector2::length() const {
|
||||||
{
|
return sqrt(x * x + y * y);
|
||||||
return sqrt(x*x + y*y);
|
|
||||||
}
|
}
|
||||||
real_t Vector2::length_squared() const
|
real_t Vector2::length_squared() const {
|
||||||
{
|
return x * x + y * y;
|
||||||
return x*x + y*y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Vector2::distance_to(const Vector2& p_vector2) const
|
real_t Vector2::distance_to(const Vector2 &p_vector2) const {
|
||||||
{
|
|
||||||
return sqrt((x - p_vector2.x) * (x - p_vector2.x) + (y - p_vector2.y) * (y - p_vector2.y));
|
return sqrt((x - p_vector2.x) * (x - p_vector2.x) + (y - p_vector2.y) * (y - p_vector2.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Vector2::distance_squared_to(const Vector2& p_vector2) const
|
real_t Vector2::distance_squared_to(const Vector2 &p_vector2) const {
|
||||||
{
|
|
||||||
return (x - p_vector2.x) * (x - p_vector2.x) + (y - p_vector2.y) * (y - p_vector2.y);
|
return (x - p_vector2.x) * (x - p_vector2.x) + (y - p_vector2.y) * (y - p_vector2.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Vector2::angle_to(const Vector2& p_vector2) const
|
real_t Vector2::angle_to(const Vector2 &p_vector2) const {
|
||||||
{
|
|
||||||
return atan2(cross(p_vector2), dot(p_vector2));
|
return atan2(cross(p_vector2), dot(p_vector2));
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Vector2::angle_to_point(const Vector2& p_vector2) const
|
real_t Vector2::angle_to_point(const Vector2 &p_vector2) const {
|
||||||
{
|
return atan2(y - p_vector2.y, x - p_vector2.x);
|
||||||
return atan2(y - p_vector2.y, x-p_vector2.x);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Vector2::dot(const Vector2& p_other) const
|
real_t Vector2::dot(const Vector2 &p_other) const {
|
||||||
{
|
|
||||||
return x * p_other.x + y * p_other.y;
|
return x * p_other.x + y * p_other.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Vector2::cross(const Vector2& p_other) const
|
real_t Vector2::cross(const Vector2 &p_other) const {
|
||||||
{
|
|
||||||
return x * p_other.y - y * p_other.x;
|
return x * p_other.y - y * p_other.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::cross(real_t p_other) const
|
Vector2 Vector2::cross(real_t p_other) const {
|
||||||
{
|
|
||||||
return Vector2(p_other * y, -p_other * x);
|
return Vector2(p_other * y, -p_other * x);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::project(const Vector2& p_vec) const
|
Vector2 Vector2::project(const Vector2 &p_vec) const {
|
||||||
{
|
|
||||||
Vector2 v1 = p_vec;
|
Vector2 v1 = p_vec;
|
||||||
Vector2 v2 = *this;
|
Vector2 v2 = *this;
|
||||||
return v2 * (v1.dot(v2) / v2.dot(v2));
|
return v2 * (v1.dot(v2) / v2.dot(v2));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::plane_project(real_t p_d, const Vector2& p_vec) const
|
Vector2 Vector2::plane_project(real_t p_d, const Vector2 &p_vec) const {
|
||||||
{
|
return p_vec - *this * (dot(p_vec) - p_d);
|
||||||
return p_vec - *this * ( dot(p_vec) -p_d);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::clamped(real_t p_len) const
|
Vector2 Vector2::clamped(real_t p_len) const {
|
||||||
{
|
|
||||||
real_t l = length();
|
real_t l = length();
|
||||||
Vector2 v = *this;
|
Vector2 v = *this;
|
||||||
if (l > 0 && p_len < l) {
|
if (l > 0 && p_len < l) {
|
||||||
|
@ -161,55 +134,48 @@ Vector2 Vector2::clamped(real_t p_len) const
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::linear_interpolate(const Vector2& p_a, const Vector2& p_b,real_t p_t)
|
Vector2 Vector2::linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_t) {
|
||||||
{
|
Vector2 res = p_a;
|
||||||
Vector2 res=p_a;
|
res.x += (p_t * (p_b.x - p_a.x));
|
||||||
res.x+= (p_t * (p_b.x-p_a.x));
|
res.y += (p_t * (p_b.y - p_a.y));
|
||||||
res.y+= (p_t * (p_b.y-p_a.y));
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::linear_interpolate(const Vector2& p_b,real_t p_t) const
|
Vector2 Vector2::linear_interpolate(const Vector2 &p_b, real_t p_t) const {
|
||||||
{
|
Vector2 res = *this;
|
||||||
Vector2 res=*this;
|
res.x += (p_t * (p_b.x - x));
|
||||||
res.x+= (p_t * (p_b.x-x));
|
res.y += (p_t * (p_b.y - y));
|
||||||
res.y+= (p_t * (p_b.y-y));
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
}
|
}
|
||||||
Vector2 Vector2::cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, const Vector2& p_post_b,real_t p_t) const
|
Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const {
|
||||||
{
|
Vector2 p0 = p_pre_a;
|
||||||
Vector2 p0=p_pre_a;
|
Vector2 p1 = *this;
|
||||||
Vector2 p1=*this;
|
Vector2 p2 = p_b;
|
||||||
Vector2 p2=p_b;
|
Vector2 p3 = p_post_b;
|
||||||
Vector2 p3=p_post_b;
|
|
||||||
|
|
||||||
real_t t = p_t;
|
real_t t = p_t;
|
||||||
real_t t2 = t * t;
|
real_t t2 = t * t;
|
||||||
real_t t3 = t2 * t;
|
real_t t3 = t2 * t;
|
||||||
|
|
||||||
Vector2 out;
|
Vector2 out;
|
||||||
out = ( ( p1 * 2.0) +
|
out = ((p1 * 2.0) +
|
||||||
( -p0 + p2 ) * t +
|
(-p0 + p2) * t +
|
||||||
( p0 * 2.0 - p1 * 5.0 + p2 * 4 - p3 ) * t2 +
|
(p0 * 2.0 - p1 * 5.0 + p2 * 4 - p3) * t2 +
|
||||||
( -p0 + p1 * 3.0 - p2 * 3.0 + p3 ) * t3 ) * 0.5;
|
(-p0 + p1 * 3.0 - p2 * 3.0 + p3) * t3) *
|
||||||
|
0.5;
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector2 Vector2::slide(const Vector2 &p_vec) const {
|
||||||
Vector2 Vector2::slide(const Vector2& p_vec) const
|
|
||||||
{
|
|
||||||
return p_vec - *this * this->dot(p_vec);
|
return p_vec - *this * this->dot(p_vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::reflect(const Vector2& p_vec) const
|
Vector2 Vector2::reflect(const Vector2 &p_vec) const {
|
||||||
{
|
|
||||||
return p_vec - *this * this->dot(p_vec) * 2.0;
|
return p_vec - *this * this->dot(p_vec) * 2.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Vector2::angle() const
|
real_t Vector2::angle() const {
|
||||||
{
|
|
||||||
return atan2(y, x);
|
return atan2(y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,11 +187,10 @@ void Vector2::set_rotation(real_t p_radians) {
|
||||||
|
|
||||||
Vector2 Vector2::abs() const {
|
Vector2 Vector2::abs() const {
|
||||||
|
|
||||||
return Vector2( fabs(x), fabs(y) );
|
return Vector2(fabs(x), fabs(y));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::rotated(real_t p_by) const
|
Vector2 Vector2::rotated(real_t p_by) const {
|
||||||
{
|
|
||||||
Vector2 v;
|
Vector2 v;
|
||||||
v.set_rotation(angle() + p_by);
|
v.set_rotation(angle() + p_by);
|
||||||
v *= length();
|
v *= length();
|
||||||
|
@ -234,26 +199,21 @@ Vector2 Vector2::rotated(real_t p_by) const
|
||||||
|
|
||||||
Vector2 Vector2::tangent() const {
|
Vector2 Vector2::tangent() const {
|
||||||
|
|
||||||
return Vector2(y,-x);
|
return Vector2(y, -x);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::floor() const
|
Vector2 Vector2::floor() const {
|
||||||
{
|
|
||||||
return Vector2(::floor(x), ::floor(y));
|
return Vector2(::floor(x), ::floor(y));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Vector2::snapped(const Vector2& p_by) const
|
Vector2 Vector2::snapped(const Vector2 &p_by) const {
|
||||||
{
|
|
||||||
return Vector2(
|
return Vector2(
|
||||||
p_by.x != 0 ? ::floor(x / p_by.x + 0.5) * p_by.x : x,
|
p_by.x != 0 ? ::floor(x / p_by.x + 0.5) * p_by.x : x,
|
||||||
p_by.y != 0 ? ::floor(y / p_by.y + 0.5) * p_by.y : y
|
p_by.y != 0 ? ::floor(y / p_by.y + 0.5) * p_by.y : y);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2::operator String() const
|
Vector2::operator String() const {
|
||||||
{
|
|
||||||
return String::num(x) + ", " + String::num(y);
|
return String::num(x) + ", " + String::num(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
}
|
|
||||||
|
|
|
@ -10,346 +10,293 @@
|
||||||
|
|
||||||
namespace godot {
|
namespace godot {
|
||||||
|
|
||||||
Vector3::Vector3(real_t x, real_t y, real_t z)
|
Vector3::Vector3(real_t x, real_t y, real_t z) {
|
||||||
{
|
|
||||||
this->x = x;
|
this->x = x;
|
||||||
this->y = y;
|
this->y = y;
|
||||||
this->z = z;
|
this->z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3::Vector3()
|
Vector3::Vector3() {
|
||||||
{
|
|
||||||
this->x = 0;
|
this->x = 0;
|
||||||
this->y = 0;
|
this->y = 0;
|
||||||
this->z = 0;
|
this->z = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const real_t& Vector3::operator[](int p_axis) const
|
const real_t &Vector3::operator[](int p_axis) const {
|
||||||
{
|
|
||||||
return coord[p_axis];
|
return coord[p_axis];
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t& Vector3::operator[](int p_axis)
|
real_t &Vector3::operator[](int p_axis) {
|
||||||
{
|
|
||||||
return coord[p_axis];
|
return coord[p_axis];
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3& Vector3::operator+=(const Vector3& p_v)
|
Vector3 &Vector3::operator+=(const Vector3 &p_v) {
|
||||||
{
|
|
||||||
x += p_v.x;
|
x += p_v.x;
|
||||||
y += p_v.y;
|
y += p_v.y;
|
||||||
z += p_v.z;
|
z += p_v.z;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::operator+(const Vector3& p_v) const
|
Vector3 Vector3::operator+(const Vector3 &p_v) const {
|
||||||
{
|
|
||||||
Vector3 v = *this;
|
Vector3 v = *this;
|
||||||
v += p_v;
|
v += p_v;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3& Vector3::operator-=(const Vector3& p_v)
|
Vector3 &Vector3::operator-=(const Vector3 &p_v) {
|
||||||
{
|
|
||||||
x -= p_v.x;
|
x -= p_v.x;
|
||||||
y -= p_v.y;
|
y -= p_v.y;
|
||||||
z -= p_v.z;
|
z -= p_v.z;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::operator-(const Vector3& p_v) const
|
Vector3 Vector3::operator-(const Vector3 &p_v) const {
|
||||||
{
|
|
||||||
Vector3 v = *this;
|
Vector3 v = *this;
|
||||||
v -= p_v;
|
v -= p_v;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3& Vector3::operator*=(const Vector3& p_v)
|
Vector3 &Vector3::operator*=(const Vector3 &p_v) {
|
||||||
{
|
|
||||||
x *= p_v.x;
|
x *= p_v.x;
|
||||||
y *= p_v.y;
|
y *= p_v.y;
|
||||||
z *= p_v.z;
|
z *= p_v.z;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::operator*(const Vector3& p_v) const
|
Vector3 Vector3::operator*(const Vector3 &p_v) const {
|
||||||
{
|
|
||||||
Vector3 v = *this;
|
Vector3 v = *this;
|
||||||
v *= p_v;
|
v *= p_v;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3& Vector3::operator/=(const Vector3& p_v)
|
Vector3 &Vector3::operator/=(const Vector3 &p_v) {
|
||||||
{
|
|
||||||
x /= p_v.x;
|
x /= p_v.x;
|
||||||
y /= p_v.y;
|
y /= p_v.y;
|
||||||
z /= p_v.z;
|
z /= p_v.z;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::operator/(const Vector3& p_v) const
|
Vector3 Vector3::operator/(const Vector3 &p_v) const {
|
||||||
{
|
|
||||||
Vector3 v = *this;
|
Vector3 v = *this;
|
||||||
v /= p_v;
|
v /= p_v;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3 &Vector3::operator*=(real_t p_scalar) {
|
||||||
Vector3& Vector3::operator*=(real_t p_scalar)
|
|
||||||
{
|
|
||||||
*this *= Vector3(p_scalar, p_scalar, p_scalar);
|
*this *= Vector3(p_scalar, p_scalar, p_scalar);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::operator*(real_t p_scalar) const
|
Vector3 Vector3::operator*(real_t p_scalar) const {
|
||||||
{
|
|
||||||
Vector3 v = *this;
|
Vector3 v = *this;
|
||||||
v *= p_scalar;
|
v *= p_scalar;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3& Vector3::operator/=(real_t p_scalar)
|
Vector3 &Vector3::operator/=(real_t p_scalar) {
|
||||||
{
|
|
||||||
*this /= Vector3(p_scalar, p_scalar, p_scalar);
|
*this /= Vector3(p_scalar, p_scalar, p_scalar);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::operator/(real_t p_scalar) const
|
Vector3 Vector3::operator/(real_t p_scalar) const {
|
||||||
{
|
|
||||||
Vector3 v = *this;
|
Vector3 v = *this;
|
||||||
v /= p_scalar;
|
v /= p_scalar;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::operator-() const
|
Vector3 Vector3::operator-() const {
|
||||||
{
|
|
||||||
return Vector3(-x, -y, -z);
|
return Vector3(-x, -y, -z);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector3::operator==(const Vector3& p_v) const
|
bool Vector3::operator==(const Vector3 &p_v) const {
|
||||||
{
|
return (x == p_v.x && y == p_v.y && z == p_v.z);
|
||||||
return (x==p_v.x && y==p_v.y && z==p_v.z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector3::operator!=(const Vector3& p_v) const
|
bool Vector3::operator!=(const Vector3 &p_v) const {
|
||||||
{
|
return (x != p_v.x || y != p_v.y || z != p_v.z);
|
||||||
return (x!=p_v.x || y!=p_v.y || z!=p_v.z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector3::operator<(const Vector3& p_v) const
|
bool Vector3::operator<(const Vector3 &p_v) const {
|
||||||
{
|
if (x == p_v.x) {
|
||||||
if (x==p_v.x) {
|
if (y == p_v.y)
|
||||||
if (y==p_v.y)
|
return z < p_v.z;
|
||||||
return z<p_v.z;
|
|
||||||
else
|
else
|
||||||
return y<p_v.y;
|
return y < p_v.y;
|
||||||
} else {
|
} else {
|
||||||
return x<p_v.x;
|
return x < p_v.x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector3::operator<=(const Vector3& p_v) const
|
bool Vector3::operator<=(const Vector3 &p_v) const {
|
||||||
{
|
if (x == p_v.x) {
|
||||||
if (x==p_v.x) {
|
if (y == p_v.y)
|
||||||
if (y==p_v.y)
|
return z <= p_v.z;
|
||||||
return z<=p_v.z;
|
|
||||||
else
|
else
|
||||||
return y<p_v.y;
|
return y < p_v.y;
|
||||||
} else {
|
} else {
|
||||||
return x<p_v.x;
|
return x < p_v.x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::abs() const
|
Vector3 Vector3::abs() const {
|
||||||
{
|
|
||||||
return Vector3(::fabs(x), ::fabs(y), ::fabs(z));
|
return Vector3(::fabs(x), ::fabs(y), ::fabs(z));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::ceil() const
|
Vector3 Vector3::ceil() const {
|
||||||
{
|
|
||||||
return Vector3(::ceil(x), ::ceil(y), ::ceil(z));
|
return Vector3(::ceil(x), ::ceil(y), ::ceil(z));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::cross(const Vector3& b) const
|
Vector3 Vector3::cross(const Vector3 &b) const {
|
||||||
{
|
Vector3 ret(
|
||||||
Vector3 ret (
|
|
||||||
(y * b.z) - (z * b.y),
|
(y * b.z) - (z * b.y),
|
||||||
(z * b.x) - (x * b.z),
|
(z * b.x) - (x * b.z),
|
||||||
(x * b.y) - (y * b.x)
|
(x * b.y) - (y * b.x));
|
||||||
);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::linear_interpolate(const Vector3& p_b,real_t p_t) const
|
Vector3 Vector3::linear_interpolate(const Vector3 &p_b, real_t p_t) const {
|
||||||
{
|
|
||||||
return Vector3(
|
return Vector3(
|
||||||
x+(p_t * (p_b.x-x)),
|
x + (p_t * (p_b.x - x)),
|
||||||
y+(p_t * (p_b.y-y)),
|
y + (p_t * (p_b.y - y)),
|
||||||
z+(p_t * (p_b.z-z))
|
z + (p_t * (p_b.z - z)));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::cubic_interpolate(const Vector3& b, const Vector3& pre_a, const Vector3& post_b, const real_t t) const
|
Vector3 Vector3::cubic_interpolate(const Vector3 &b, const Vector3 &pre_a, const Vector3 &post_b, const real_t t) const {
|
||||||
{
|
Vector3 p0 = pre_a;
|
||||||
Vector3 p0=pre_a;
|
Vector3 p1 = *this;
|
||||||
Vector3 p1=*this;
|
Vector3 p2 = b;
|
||||||
Vector3 p2=b;
|
Vector3 p3 = post_b;
|
||||||
Vector3 p3=post_b;
|
|
||||||
|
|
||||||
real_t t2 = t * t;
|
real_t t2 = t * t;
|
||||||
real_t t3 = t2 * t;
|
real_t t3 = t2 * t;
|
||||||
|
|
||||||
Vector3 out;
|
Vector3 out;
|
||||||
out = ( ( p1 * 2.0) +
|
out = ((p1 * 2.0) +
|
||||||
( -p0 + p2 ) * t +
|
(-p0 + p2) * t +
|
||||||
( p0 * 2.0 - p1 * 5.0 + p2 * 4 - p3 ) * t2 +
|
(p0 * 2.0 - p1 * 5.0 + p2 * 4 - p3) * t2 +
|
||||||
( -p0 + p1 * 3.0 - p2 * 3.0 + p3 ) * t3 ) * 0.5;
|
(-p0 + p1 * 3.0 - p2 * 3.0 + p3) * t3) *
|
||||||
|
0.5;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::bounce(const Vector3& p_normal) const
|
Vector3 Vector3::bounce(const Vector3 &p_normal) const {
|
||||||
{
|
|
||||||
return -reflect(p_normal);
|
return -reflect(p_normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Vector3::length() const
|
real_t Vector3::length() const {
|
||||||
{
|
real_t x2 = x * x;
|
||||||
real_t x2=x*x;
|
real_t y2 = y * y;
|
||||||
real_t y2=y*y;
|
real_t z2 = z * z;
|
||||||
real_t z2=z*z;
|
|
||||||
|
|
||||||
return ::sqrt(x2+y2+z2);
|
return ::sqrt(x2 + y2 + z2);
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Vector3::length_squared() const
|
real_t Vector3::length_squared() const {
|
||||||
{
|
real_t x2 = x * x;
|
||||||
real_t x2=x*x;
|
real_t y2 = y * y;
|
||||||
real_t y2=y*y;
|
real_t z2 = z * z;
|
||||||
real_t z2=z*z;
|
|
||||||
|
|
||||||
return x2+y2+z2;
|
return x2 + y2 + z2;
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Vector3::distance_squared_to(const Vector3& b) const
|
real_t Vector3::distance_squared_to(const Vector3 &b) const {
|
||||||
{
|
return (b - *this).length_squared();
|
||||||
return (b-*this).length_squared();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Vector3::distance_to(const Vector3& b) const
|
real_t Vector3::distance_to(const Vector3 &b) const {
|
||||||
{
|
return (b - *this).length();
|
||||||
return (b-*this).length();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Vector3::dot(const Vector3& b) const
|
real_t Vector3::dot(const Vector3 &b) const {
|
||||||
{
|
return x * b.x + y * b.y + z * b.z;
|
||||||
return x*b.x + y*b.y + z*b.z;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
real_t Vector3::angle_to(const Vector3& b) const
|
real_t Vector3::angle_to(const Vector3 &b) const {
|
||||||
{
|
|
||||||
return std::atan2(cross(b).length(), dot(b));
|
return std::atan2(cross(b).length(), dot(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::floor() const
|
Vector3 Vector3::floor() const {
|
||||||
{
|
|
||||||
return Vector3(::floor(x), ::floor(y), ::floor(z));
|
return Vector3(::floor(x), ::floor(y), ::floor(z));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::inverse() const
|
Vector3 Vector3::inverse() const {
|
||||||
{
|
return Vector3(1.0 / x, 1.0 / y, 1.0 / z);
|
||||||
return Vector3( 1.0/x, 1.0/y, 1.0/z );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Vector3::is_normalized() const
|
bool Vector3::is_normalized() const {
|
||||||
{
|
|
||||||
return std::abs(length_squared() - 1.0) < 0.00001;
|
return std::abs(length_squared() - 1.0) < 0.00001;
|
||||||
}
|
}
|
||||||
|
|
||||||
Basis Vector3::outer(const Vector3& b) const
|
Basis Vector3::outer(const Vector3 &b) const {
|
||||||
{
|
|
||||||
Vector3 row0(x * b.x, x * b.y, x * b.z);
|
Vector3 row0(x * b.x, x * b.y, x * b.z);
|
||||||
Vector3 row1(y * b.x, y * b.y, y * b.z);
|
Vector3 row1(y * b.x, y * b.y, y * b.z);
|
||||||
Vector3 row2(z * b.x, z * b.y, z * b.z);
|
Vector3 row2(z * b.x, z * b.y, z * b.z);
|
||||||
return Basis(row0, row1, row2);
|
return Basis(row0, row1, row2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Vector3::max_axis() const {
|
||||||
int Vector3::max_axis() const
|
|
||||||
{
|
|
||||||
return x < y ? (y < z ? 2 : 1) : (x < z ? 2 : 0);
|
return x < y ? (y < z ? 2 : 1) : (x < z ? 2 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Vector3::min_axis() const
|
int Vector3::min_axis() const {
|
||||||
{
|
|
||||||
return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2);
|
return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector3::normalize()
|
void Vector3::normalize() {
|
||||||
{
|
real_t l = length();
|
||||||
real_t l=length();
|
if (l == 0) {
|
||||||
if (l==0) {
|
x = y = z = 0;
|
||||||
x=y=z=0;
|
|
||||||
} else {
|
} else {
|
||||||
x/=l;
|
x /= l;
|
||||||
y/=l;
|
y /= l;
|
||||||
z/=l;
|
z /= l;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::normalized() const
|
Vector3 Vector3::normalized() const {
|
||||||
{
|
|
||||||
Vector3 v = *this;
|
Vector3 v = *this;
|
||||||
v.normalize();
|
v.normalize();
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::reflect(const Vector3& by) const
|
Vector3 Vector3::reflect(const Vector3 &by) const {
|
||||||
{
|
|
||||||
return by - *this * this->dot(by) * 2.0;
|
return by - *this * this->dot(by) * 2.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::rotated(const Vector3& axis, const real_t phi) const
|
Vector3 Vector3::rotated(const Vector3 &axis, const real_t phi) const {
|
||||||
{
|
|
||||||
Vector3 v = *this;
|
Vector3 v = *this;
|
||||||
v.rotate(axis, phi);
|
v.rotate(axis, phi);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector3::rotate(const Vector3& p_axis,real_t p_phi)
|
void Vector3::rotate(const Vector3 &p_axis, real_t p_phi) {
|
||||||
{
|
*this = Basis(p_axis, p_phi).xform(*this);
|
||||||
*this=Basis(p_axis,p_phi).xform(*this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::slide(const Vector3& by) const
|
Vector3 Vector3::slide(const Vector3 &by) const {
|
||||||
{
|
|
||||||
return by - *this * this->dot(by);
|
return by - *this * this->dot(by);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is ugly as well, but hey, I'm a simple man
|
// this is ugly as well, but hey, I'm a simple man
|
||||||
#define _ugly_stepify(val, step) (step != 0 ? ::floor(val / step + 0.5) * step : val)
|
#define _ugly_stepify(val, step) (step != 0 ? ::floor(val / step + 0.5) * step : val)
|
||||||
|
|
||||||
void Vector3::snap(real_t p_val)
|
void Vector3::snap(real_t p_val) {
|
||||||
{
|
x = _ugly_stepify(x, p_val);
|
||||||
x = _ugly_stepify(x,p_val);
|
y = _ugly_stepify(y, p_val);
|
||||||
y = _ugly_stepify(y,p_val);
|
z = _ugly_stepify(z, p_val);
|
||||||
z = _ugly_stepify(z,p_val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef _ugly_stepify
|
#undef _ugly_stepify
|
||||||
|
|
||||||
Vector3 Vector3::snapped(const float by)
|
Vector3 Vector3::snapped(const float by) {
|
||||||
{
|
|
||||||
Vector3 v = *this;
|
Vector3 v = *this;
|
||||||
v.snap(by);
|
v.snap(by);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3::operator String() const
|
Vector3::operator String() const {
|
||||||
{
|
|
||||||
return String::num(x) + ", " + String::num(y) + ", " + String::num(z);
|
return String::num(x) + ", " + String::num(y) + ", " + String::num(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace godot
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue