diff options
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/aabb.cpp | 48 | ||||
-rw-r--r-- | core/math/aabb.h | 53 | ||||
-rw-r--r-- | core/math/bsp_tree.cpp | 8 | ||||
-rw-r--r-- | core/math/bsp_tree.h | 8 | ||||
-rw-r--r-- | core/math/camera_matrix.cpp | 2 | ||||
-rw-r--r-- | core/math/camera_matrix.h | 2 | ||||
-rw-r--r-- | core/math/face3.cpp | 2 | ||||
-rw-r--r-- | core/math/face3.h | 10 | ||||
-rw-r--r-- | core/math/geometry.cpp | 4 | ||||
-rw-r--r-- | core/math/math_2d.cpp | 80 | ||||
-rw-r--r-- | core/math/math_2d.h | 56 | ||||
-rw-r--r-- | core/math/matrix3.cpp | 150 | ||||
-rw-r--r-- | core/math/matrix3.h | 82 | ||||
-rw-r--r-- | core/math/octree.h | 36 | ||||
-rw-r--r-- | core/math/quat.cpp | 2 | ||||
-rw-r--r-- | core/math/quick_hull.cpp | 2 | ||||
-rw-r--r-- | core/math/transform.cpp | 4 | ||||
-rw-r--r-- | core/math/transform.h | 20 | ||||
-rw-r--r-- | core/math/triangle_mesh.cpp | 4 | ||||
-rw-r--r-- | core/math/triangle_mesh.h | 4 | ||||
-rw-r--r-- | core/math/vector3.cpp | 2 | ||||
-rw-r--r-- | core/math/vector3.h | 14 |
22 files changed, 296 insertions, 297 deletions
diff --git a/core/math/aabb.cpp b/core/math/aabb.cpp index d304d3e092..3518eea7ac 100644 --- a/core/math/aabb.cpp +++ b/core/math/aabb.cpp @@ -30,24 +30,24 @@ #include "print_string.h" -float AABB::get_area() const { +float Rect3::get_area() const { return size.x*size.y*size.z; } -bool AABB::operator==(const AABB& p_rval) const { +bool Rect3::operator==(const Rect3& p_rval) const { return ((pos==p_rval.pos) && (size==p_rval.size)); } -bool AABB::operator!=(const AABB& p_rval) const { +bool Rect3::operator!=(const Rect3& p_rval) const { return ((pos!=p_rval.pos) || (size!=p_rval.size)); } -void AABB::merge_with(const AABB& p_aabb) { +void Rect3::merge_with(const Rect3& p_aabb) { Vector3 beg_1,beg_2; Vector3 end_1,end_2; @@ -70,7 +70,7 @@ void AABB::merge_with(const AABB& p_aabb) { size=max-min; } -AABB AABB::intersection(const AABB& p_aabb) const { +Rect3 Rect3::intersection(const Rect3& p_aabb) const { Vector3 src_min=pos; Vector3 src_max=pos+size; @@ -80,7 +80,7 @@ AABB AABB::intersection(const AABB& p_aabb) const { Vector3 min,max; if (src_min.x > dst_max.x || src_max.x < dst_min.x ) - return AABB(); + return Rect3(); else { min.x= ( src_min.x > dst_min.x ) ? src_min.x :dst_min.x; @@ -89,7 +89,7 @@ AABB AABB::intersection(const AABB& p_aabb) const { } if (src_min.y > dst_max.y || src_max.y < dst_min.y ) - return AABB(); + return Rect3(); else { min.y= ( src_min.y > dst_min.y ) ? src_min.y :dst_min.y; @@ -98,7 +98,7 @@ AABB AABB::intersection(const AABB& p_aabb) const { } if (src_min.z > dst_max.z || src_max.z < dst_min.z ) - return AABB(); + return Rect3(); else { min.z= ( src_min.z > dst_min.z ) ? src_min.z :dst_min.z; @@ -107,10 +107,10 @@ AABB AABB::intersection(const AABB& p_aabb) const { } - return AABB( min, max-min ); + return Rect3( min, max-min ); } -bool AABB::intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r_clip,Vector3* r_normal) const { +bool Rect3::intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r_clip,Vector3* r_normal) const { Vector3 c1, c2; Vector3 end = pos+size; @@ -155,7 +155,7 @@ bool AABB::intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r } -bool AABB::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3* r_clip,Vector3* r_normal) const { +bool Rect3::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; @@ -216,7 +216,7 @@ bool AABB::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3 } -bool AABB::intersects_plane(const Plane &p_plane) const { +bool Rect3::intersects_plane(const Plane &p_plane) const { Vector3 points[8] = { Vector3( pos.x , pos.y , pos.z ), @@ -246,7 +246,7 @@ bool AABB::intersects_plane(const Plane &p_plane) const { -Vector3 AABB::get_longest_axis() const { +Vector3 Rect3::get_longest_axis() const { Vector3 axis(1,0,0); real_t max_size=size.x; @@ -263,7 +263,7 @@ Vector3 AABB::get_longest_axis() const { return axis; } -int AABB::get_longest_axis_index() const { +int Rect3::get_longest_axis_index() const { int axis=0; real_t max_size=size.x; @@ -282,7 +282,7 @@ int AABB::get_longest_axis_index() const { } -Vector3 AABB::get_shortest_axis() const { +Vector3 Rect3::get_shortest_axis() const { Vector3 axis(1,0,0); real_t max_size=size.x; @@ -299,7 +299,7 @@ Vector3 AABB::get_shortest_axis() const { return axis; } -int AABB::get_shortest_axis_index() const { +int Rect3::get_shortest_axis_index() const { int axis=0; real_t max_size=size.x; @@ -317,26 +317,26 @@ int AABB::get_shortest_axis_index() const { return axis; } -AABB AABB::merge(const AABB& p_with) const { +Rect3 Rect3::merge(const Rect3& p_with) const { - AABB aabb=*this; + Rect3 aabb=*this; aabb.merge_with(p_with); return aabb; } -AABB AABB::expand(const Vector3& p_vector) const { - AABB aabb=*this; +Rect3 Rect3::expand(const Vector3& p_vector) const { + Rect3 aabb=*this; aabb.expand_to(p_vector); return aabb; } -AABB AABB::grow(real_t p_by) const { +Rect3 Rect3::grow(real_t p_by) const { - AABB aabb=*this; + Rect3 aabb=*this; aabb.grow_by(p_by); return aabb; } -void AABB::get_edge(int p_edge,Vector3& r_from,Vector3& r_to) const { +void Rect3::get_edge(int p_edge,Vector3& r_from,Vector3& r_to) const { ERR_FAIL_INDEX(p_edge,12); switch(p_edge) { @@ -412,7 +412,7 @@ void AABB::get_edge(int p_edge,Vector3& r_from,Vector3& r_to) const { } -AABB::operator String() const { +Rect3::operator String() const { return String()+pos +" - "+ size; } diff --git a/core/math/aabb.h b/core/math/aabb.h index 1c0adf9012..2816d1f012 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -40,7 +40,7 @@ -class AABB { +class Rect3 { public: Vector3 pos; Vector3 size; @@ -62,16 +62,16 @@ public: 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 Rect3& p_rval) const; + bool operator!=(const Rect3& p_rval) const; - _FORCE_INLINE_ bool intersects(const AABB& p_aabb) const; /// Both AABBs overlap - _FORCE_INLINE_ bool intersects_inclusive(const AABB& p_aabb) const; /// Both AABBs (or their faces) overlap - _FORCE_INLINE_ bool encloses(const AABB & p_aabb) const; /// p_aabb is completely inside this + _FORCE_INLINE_ bool intersects(const Rect3& p_aabb) const; /// Both AABBs overlap + _FORCE_INLINE_ bool intersects_inclusive(const Rect3& p_aabb) const; /// Both AABBs (or their faces) overlap + _FORCE_INLINE_ bool encloses(const Rect3 & p_aabb) const; /// p_aabb is completely inside this - AABB merge(const AABB& p_with) const; - void merge_with(const AABB& p_aabb); ///merge with another AABB - AABB intersection(const AABB& p_aabb) const; ///get box where two intersect, empty if no intersection occurs + Rect3 merge(const Rect3& p_with) const; + void merge_with(const Rect3& p_aabb); ///merge with another AABB + Rect3 intersection(const Rect3& 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=NULL,Vector3* r_normal=NULL) const; bool intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3* r_clip=NULL,Vector3* r_normal=NULL) const; _FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &from,const Vector3& p_dir, float t0, float t1) const; @@ -91,25 +91,25 @@ public: int get_shortest_axis_index() const; _FORCE_INLINE_ real_t get_shortest_axis_size() const; - AABB grow(real_t p_by) const; + Rect3 grow(real_t p_by) const; _FORCE_INLINE_ void grow_by(real_t p_amount); void get_edge(int p_edge,Vector3& r_from,Vector3& r_to) const; _FORCE_INLINE_ Vector3 get_endpoint(int p_point) const; - AABB expand(const Vector3& p_vector) const; + Rect3 expand(const Vector3& p_vector) const; _FORCE_INLINE_ void project_range_in_plane(const Plane& p_plane,float &r_min,float& r_max) const; _FORCE_INLINE_ void expand_to(const Vector3& p_vector); /** expand to contain a point if necesary */ operator String() const; - _FORCE_INLINE_ AABB() {} - inline AABB(const Vector3 &p_pos,const Vector3& p_size) { pos=p_pos; size=p_size; } + _FORCE_INLINE_ Rect3() {} + inline Rect3(const Vector3 &p_pos,const Vector3& p_size) { pos=p_pos; size=p_size; } }; -inline bool AABB::intersects(const AABB& p_aabb) const { +inline bool Rect3::intersects(const Rect3& p_aabb) const { if ( pos.x >= (p_aabb.pos.x + p_aabb.size.x) ) return false; @@ -127,7 +127,7 @@ inline bool AABB::intersects(const AABB& p_aabb) const { return true; } -inline bool AABB::intersects_inclusive(const AABB& p_aabb) const { +inline bool Rect3::intersects_inclusive(const Rect3& p_aabb) const { if ( pos.x > (p_aabb.pos.x + p_aabb.size.x) ) return false; @@ -145,7 +145,7 @@ inline bool AABB::intersects_inclusive(const AABB& p_aabb) const { return true; } -inline bool AABB::encloses(const AABB & p_aabb) const { +inline bool Rect3::encloses(const Rect3 & p_aabb) const { Vector3 src_min=pos; Vector3 src_max=pos+size; @@ -162,7 +162,7 @@ inline bool AABB::encloses(const AABB & p_aabb) const { } -Vector3 AABB::get_support(const Vector3& p_normal) const { +Vector3 Rect3::get_support(const Vector3& p_normal) const { Vector3 half_extents = size * 0.5; Vector3 ofs = pos + half_extents; @@ -175,7 +175,7 @@ Vector3 AABB::get_support(const Vector3& p_normal) const { } -Vector3 AABB::get_endpoint(int p_point) const { +Vector3 Rect3::get_endpoint(int p_point) const { switch(p_point) { case 0: return Vector3( pos.x , pos.y , pos.z ); @@ -191,7 +191,7 @@ Vector3 AABB::get_endpoint(int p_point) const { ERR_FAIL_V(Vector3()); } -bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count) const { +bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) const { #if 1 @@ -251,7 +251,7 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count) con #endif } -bool AABB::has_point(const Vector3& p_point) const { +bool Rect3::has_point(const Vector3& p_point) const { if (p_point.x<pos.x) return false; @@ -270,7 +270,7 @@ bool AABB::has_point(const Vector3& p_point) const { } -inline void AABB::expand_to(const Vector3& p_vector) { +inline void Rect3::expand_to(const Vector3& p_vector) { Vector3 begin=pos; Vector3 end=pos+size; @@ -293,7 +293,7 @@ inline void AABB::expand_to(const Vector3& p_vector) { size=end-begin; } -void AABB::project_range_in_plane(const Plane& p_plane,float &r_min,float& r_max) const { +void Rect3::project_range_in_plane(const Plane& p_plane,float &r_min,float& r_max) const { Vector3 half_extents( size.x * 0.5, size.y * 0.5, size.z * 0.5 ); Vector3 center( pos.x + half_extents.x, pos.y + half_extents.y, pos.z + half_extents.z ); @@ -304,7 +304,7 @@ void AABB::project_range_in_plane(const Plane& p_plane,float &r_min,float& r_max r_max = distance + length; } -inline real_t AABB::get_longest_axis_size() const { +inline real_t Rect3::get_longest_axis_size() const { real_t max_size=size.x; @@ -319,7 +319,7 @@ inline real_t AABB::get_longest_axis_size() const { return max_size; } -inline real_t AABB::get_shortest_axis_size() const { +inline real_t Rect3::get_shortest_axis_size() const { real_t max_size=size.x; @@ -334,7 +334,7 @@ inline real_t AABB::get_shortest_axis_size() const { return max_size; } -bool AABB::smits_intersect_ray(const Vector3 &from,const Vector3& dir, float t0, float t1) const { +bool Rect3::smits_intersect_ray(const Vector3 &from,const Vector3& dir, float t0, float t1) const { float divx=1.0/dir.x; float divy=1.0/dir.y; @@ -381,7 +381,7 @@ bool AABB::smits_intersect_ray(const Vector3 &from,const Vector3& dir, float t0, return ( (tmin < t1) && (tmax > t0) ); } -void AABB::grow_by(real_t p_amount) { +void Rect3::grow_by(real_t p_amount) { pos.x-=p_amount; pos.y-=p_amount; @@ -391,6 +391,5 @@ void AABB::grow_by(real_t p_amount) { size.z+=2.0*p_amount; } -typedef AABB Rect3; #endif // AABB_H diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp index b7194d7ffb..b888b6b56c 100644 --- a/core/math/bsp_tree.cpp +++ b/core/math/bsp_tree.cpp @@ -31,7 +31,7 @@ #include "print_string.h" -void BSP_Tree::from_aabb(const AABB& p_aabb) { +void BSP_Tree::from_aabb(const Rect3& p_aabb) { planes.clear(); @@ -67,7 +67,7 @@ Vector<Plane> BSP_Tree::get_planes() const { return planes; } -AABB BSP_Tree::get_aabb() const { +Rect3 BSP_Tree::get_aabb() const { return aabb; } @@ -518,7 +518,7 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) { ERR_FAIL_COND(src_nodes.size()%3); - if (d["planes"].get_type()==Variant::REAL_ARRAY) { + if (d["planes"].get_type()==Variant::POOL_REAL_ARRAY) { PoolVector<float> src_planes=d["planes"]; int plane_count=src_planes.size(); @@ -613,7 +613,7 @@ BSP_Tree::BSP_Tree(const PoolVector<Face3>& p_faces,float p_error_radius) { error_radius=p_error_radius; } -BSP_Tree::BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const AABB& p_aabb,float p_error_radius) { +BSP_Tree::BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,float p_error_radius) { nodes=p_nodes; planes=p_planes; diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h index 236b6e5ac2..e01df96555 100644 --- a/core/math/bsp_tree.h +++ b/core/math/bsp_tree.h @@ -65,7 +65,7 @@ private: Vector<Node> nodes; Vector<Plane> planes; - AABB aabb; + Rect3 aabb; float error_radius; int _get_points_inside(int p_node,const Vector3* p_points,int *p_indices, const Vector3& p_center,const Vector3& p_half_extents,int p_indices_count) const; @@ -78,7 +78,7 @@ public: bool is_empty() const { return nodes.size()==0; } Vector<Node> get_nodes() const; Vector<Plane> get_planes() const; - AABB get_aabb() const; + Rect3 get_aabb() const; bool point_is_inside(const Vector3& p_point) const; int get_points_inside(const Vector3* p_points, int p_point_count) const; @@ -87,12 +87,12 @@ public: operator Variant() const; - void from_aabb(const AABB& p_aabb); + void from_aabb(const Rect3& p_aabb); BSP_Tree(); BSP_Tree(const Variant& p_variant); BSP_Tree(const PoolVector<Face3>& p_faces,float p_error_radius=0); - BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const AABB& p_aabb,float p_error_radius=0); + BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,float p_error_radius=0); ~BSP_Tree(); }; diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index 7910f5fafc..c44ff4682a 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -564,7 +564,7 @@ void CameraMatrix::make_scale(const Vector3 &p_scale) { } -void CameraMatrix::scale_translate_to_fit(const AABB& p_aabb) { +void CameraMatrix::scale_translate_to_fit(const Rect3& p_aabb) { Vector3 min = p_aabb.pos; Vector3 max = p_aabb.pos+p_aabb.size; diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h index f9fb4837f1..952f1e8fb2 100644 --- a/core/math/camera_matrix.h +++ b/core/math/camera_matrix.h @@ -85,7 +85,7 @@ struct CameraMatrix { operator String() const; - void scale_translate_to_fit(const AABB& p_aabb); + void scale_translate_to_fit(const Rect3& p_aabb); void make_scale(const Vector3 &p_scale); int get_pixels_per_meter(int p_for_pixel_width) const; operator Transform() const; diff --git a/core/math/face3.cpp b/core/math/face3.cpp index 1024143ba1..faf124593e 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -205,7 +205,7 @@ ClockDirection Face3::get_clock_dir() const { } -bool Face3::intersects_aabb(const AABB& p_aabb) const { +bool Face3::intersects_aabb(const Rect3& p_aabb) const { /** TEST PLANE **/ if (!p_aabb.intersects_plane( get_plane() )) diff --git a/core/math/face3.h b/core/math/face3.h index 4eade1217d..f08eb227b1 100644 --- a/core/math/face3.h +++ b/core/math/face3.h @@ -78,16 +78,16 @@ public: void get_support(const Vector3& p_normal,const Transform& p_transform,Vector3 *p_vertices,int* p_count,int p_max) const; void project_range(const Vector3& p_normal,const Transform& p_transform,float& r_min, float& r_max) const; - AABB get_aabb() const { + Rect3 get_aabb() const { - AABB aabb( vertex[0], Vector3() ); + Rect3 aabb( vertex[0], Vector3() ); aabb.expand_to( vertex[1] ); aabb.expand_to( vertex[2] ); return aabb; } - bool intersects_aabb(const AABB& p_aabb) const; - _FORCE_INLINE_ bool intersects_aabb2(const AABB& p_aabb) const; + bool intersects_aabb(const Rect3& p_aabb) const; + _FORCE_INLINE_ bool intersects_aabb2(const Rect3& p_aabb) const; operator String() const; inline Face3() {} @@ -96,7 +96,7 @@ public: }; -bool Face3::intersects_aabb2(const AABB& p_aabb) const { +bool Face3::intersects_aabb2(const Rect3& p_aabb) const { Vector3 perp = (vertex[0]-vertex[2]).cross(vertex[0]-vertex[1]); diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index 3232d36262..bf3364a052 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -304,7 +304,7 @@ enum _CellFlags { static inline void _plot_face(uint8_t*** p_cell_status,int x,int y,int z,int len_x,int len_y,int len_z,const Vector3& voxelsize,const Face3& p_face) { - AABB aabb( Vector3(x,y,z),Vector3(len_x,len_y,len_z)); + Rect3 aabb( Vector3(x,y,z),Vector3(len_x,len_y,len_z)); aabb.pos=aabb.pos*voxelsize; aabb.size=aabb.size*voxelsize; @@ -589,7 +589,7 @@ PoolVector< Face3 > Geometry::wrap_geometry( PoolVector< Face3 > p_array,float * PoolVector<Face3>::Read facesr=p_array.read(); const Face3 *faces = facesr.ptr(); - AABB global_aabb; + Rect3 global_aabb; for(int i=0;i<face_count;i++) { diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp index df9383ed1b..c6860ba2e8 100644 --- a/core/math/math_2d.cpp +++ b/core/math/math_2d.cpp @@ -408,22 +408,22 @@ bool Point2i::operator!=(const Point2i& p_vec2) const { return x!=p_vec2.x || y!=p_vec2.y; } -void Matrix32::invert() { +void Transform2D::invert() { // FIXME: this function assumes the basis is a rotation matrix, with no scaling. - // Matrix32::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. SWAP(elements[0][1],elements[1][0]); elements[2] = basis_xform(-elements[2]); } -Matrix32 Matrix32::inverse() const { +Transform2D Transform2D::inverse() const { - Matrix32 inv=*this; + Transform2D inv=*this; inv.invert(); return inv; } -void Matrix32::affine_invert() { +void Transform2D::affine_invert() { real_t det = basis_determinant(); ERR_FAIL_COND(det==0); @@ -437,27 +437,27 @@ void Matrix32::affine_invert() { } -Matrix32 Matrix32::affine_inverse() const { +Transform2D Transform2D::affine_inverse() const { - Matrix32 inv=*this; + Transform2D inv=*this; inv.affine_invert(); return inv; } -void Matrix32::rotate(real_t p_phi) { - *this = Matrix32(p_phi,Vector2()) * (*this); +void Transform2D::rotate(real_t p_phi) { + *this = Transform2D(p_phi,Vector2()) * (*this); } -real_t Matrix32::get_rotation() const { +real_t Transform2D::get_rotation() const { real_t det = basis_determinant(); - Matrix32 m = orthonormalized(); + Transform2D m = orthonormalized(); if (det < 0) { m.scale_basis(Size2(-1,-1)); } return Math::atan2(m[0].y,m[0].x); } -void Matrix32::set_rotation(real_t p_rot) { +void Transform2D::set_rotation(real_t p_rot) { real_t cr = Math::cos(p_rot); real_t sr = Math::sin(p_rot); @@ -467,7 +467,7 @@ void Matrix32::set_rotation(real_t p_rot) { elements[1][1]=cr; } -Matrix32::Matrix32(real_t p_rot, const Vector2& p_pos) { +Transform2D::Transform2D(real_t p_rot, const Vector2& p_pos) { real_t cr = Math::cos(p_rot); real_t sr = Math::sin(p_rot); @@ -478,16 +478,16 @@ Matrix32::Matrix32(real_t p_rot, const Vector2& p_pos) { elements[2]=p_pos; } -Size2 Matrix32::get_scale() const { +Size2 Transform2D::get_scale() const { real_t det_sign = basis_determinant() > 0 ? 1 : -1; return det_sign * Size2( elements[0].length(), elements[1].length() ); } -void Matrix32::scale(const Size2& p_scale) { +void Transform2D::scale(const Size2& p_scale) { scale_basis(p_scale); elements[2]*=p_scale; } -void Matrix32::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; @@ -495,16 +495,16 @@ void Matrix32::scale_basis(const Size2& p_scale) { elements[1][1]*=p_scale.y; } -void Matrix32::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)); } -void Matrix32::translate( const Vector2& p_translation ) { +void Transform2D::translate( const Vector2& p_translation ) { elements[2]+=basis_xform(p_translation); } -void Matrix32::orthonormalize() { +void Transform2D::orthonormalize() { // Gram-Schmidt Process @@ -518,15 +518,15 @@ void Matrix32::orthonormalize() { elements[0]=x; elements[1]=y; } -Matrix32 Matrix32::orthonormalized() const { +Transform2D Transform2D::orthonormalized() const { - Matrix32 on=*this; + Transform2D on=*this; on.orthonormalize(); return on; } -bool Matrix32::operator==(const Matrix32& p_transform) const { +bool Transform2D::operator==(const Transform2D& p_transform) const { for(int i=0;i<3;i++) { if (elements[i]!=p_transform.elements[i]) @@ -536,7 +536,7 @@ bool Matrix32::operator==(const Matrix32& p_transform) const { return true; } -bool Matrix32::operator!=(const Matrix32& p_transform) const { +bool Transform2D::operator!=(const Transform2D& p_transform) const { for(int i=0;i<3;i++) { if (elements[i]!=p_transform.elements[i]) @@ -547,7 +547,7 @@ bool Matrix32::operator!=(const Matrix32& p_transform) const { } -void Matrix32::operator*=(const Matrix32& p_transform) { +void Transform2D::operator*=(const Transform2D& p_transform) { elements[2] = xform(p_transform.elements[2]); @@ -565,59 +565,59 @@ void Matrix32::operator*=(const Matrix32& p_transform) { } -Matrix32 Matrix32::operator*(const Matrix32& p_transform) const { +Transform2D Transform2D::operator*(const Transform2D& p_transform) const { - Matrix32 t = *this; + Transform2D t = *this; t*=p_transform; return t; } -Matrix32 Matrix32::scaled(const Size2& p_scale) const { +Transform2D Transform2D::scaled(const Size2& p_scale) const { - Matrix32 copy=*this; + Transform2D copy=*this; copy.scale(p_scale); return copy; } -Matrix32 Matrix32::basis_scaled(const Size2& p_scale) const { +Transform2D Transform2D::basis_scaled(const Size2& p_scale) const { - Matrix32 copy=*this; + Transform2D copy=*this; copy.scale_basis(p_scale); return copy; } -Matrix32 Matrix32::untranslated() const { +Transform2D Transform2D::untranslated() const { - Matrix32 copy=*this; + Transform2D copy=*this; copy.elements[2]=Vector2(); return copy; } -Matrix32 Matrix32::translated(const Vector2& p_offset) const { +Transform2D Transform2D::translated(const Vector2& p_offset) const { - Matrix32 copy=*this; + Transform2D copy=*this; copy.translate(p_offset); return copy; } -Matrix32 Matrix32::rotated(real_t p_phi) const { +Transform2D Transform2D::rotated(real_t p_phi) const { - Matrix32 copy=*this; + Transform2D copy=*this; copy.rotate(p_phi); return copy; } -real_t Matrix32::basis_determinant() const { +real_t Transform2D::basis_determinant() const { return elements[0].x * elements[1].y - elements[0].y * elements[1].x; } -Matrix32 Matrix32::interpolate_with(const Matrix32& p_transform, real_t p_c) const { +Transform2D Transform2D::interpolate_with(const Transform2D& p_transform, real_t p_c) const { //extract parameters Vector2 p1 = get_origin(); @@ -648,12 +648,12 @@ Matrix32 Matrix32::interpolate_with(const Matrix32& p_transform, real_t p_c) con } //construct matrix - Matrix32 res(Math::atan2(v.y, v.x), Vector2::linear_interpolate(p1, p2, p_c)); + Transform2D res(Math::atan2(v.y, v.x), Vector2::linear_interpolate(p1, p2, p_c)); res.scale_basis(Vector2::linear_interpolate(s1, s2, p_c)); return res; } -Matrix32::operator String() const { +Transform2D::operator String() const { return String(String()+elements[0]+", "+elements[1]+", "+elements[2]); } diff --git a/core/math/math_2d.h b/core/math/math_2d.h index adc23f01b1..7896299c24 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -198,7 +198,7 @@ Vector2 Vector2::linear_interpolate(const Vector2& p_a, const Vector2& p_b,real_ typedef Vector2 Size2; typedef Vector2 Point2; -struct Matrix32; +struct Transform2D; struct Rect2 { @@ -249,7 +249,7 @@ struct Rect2 { return dist; } - _FORCE_INLINE_ bool intersects_transformed(const Matrix32& p_xform, const Rect2& p_rect) const; + _FORCE_INLINE_ 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=NULL, Point2* r_normal=NULL) const; @@ -551,8 +551,8 @@ struct Rect2i { -struct Matrix32 { - // Warning #1: basis of Matrix32 is stored differently from Matrix3. In terms of elements array, the basis matrix looks like "on paper": +struct Transform2D { + // Warning #1: basis of Transform2D is stored differently from Basis. In terms of elements array, the basis matrix looks like "on paper": // M = (elements[0][0] elements[1][0]) // (elements[0][1] elements[1][1]) // This is such that the columns, which can be interpreted as basis vectors of the coordinate system "painted" on the object, can be accessed as elements[i]. @@ -575,10 +575,10 @@ struct Matrix32 { _FORCE_INLINE_ void set_axis(int p_axis,const Vector2& p_vec) { ERR_FAIL_INDEX(p_axis,3); elements[p_axis]=p_vec; } void invert(); - Matrix32 inverse() const; + Transform2D inverse() const; void affine_invert(); - Matrix32 affine_inverse() const; + Transform2D affine_inverse() const; void set_rotation(real_t p_phi); real_t get_rotation() const; @@ -597,23 +597,23 @@ struct Matrix32 { _FORCE_INLINE_ const Vector2& get_origin() const { return elements[2]; } _FORCE_INLINE_ void set_origin(const Vector2& p_origin) { elements[2]=p_origin; } - Matrix32 scaled(const Size2& p_scale) const; - Matrix32 basis_scaled(const Size2& p_scale) const; - Matrix32 translated(const Vector2& p_offset) const; - Matrix32 rotated(real_t p_phi) const; + Transform2D scaled(const Size2& p_scale) const; + Transform2D basis_scaled(const Size2& p_scale) const; + Transform2D translated(const Vector2& p_offset) const; + Transform2D rotated(real_t p_phi) const; - Matrix32 untranslated() const; + Transform2D untranslated() const; void orthonormalize(); - Matrix32 orthonormalized() const; + Transform2D orthonormalized() const; - bool operator==(const Matrix32& p_transform) const; - bool operator!=(const Matrix32& p_transform) const; + bool operator==(const Transform2D& p_transform) const; + bool operator!=(const Transform2D& p_transform) const; - void operator*=(const Matrix32& p_transform); - Matrix32 operator*(const Matrix32& p_transform) const; + void operator*=(const Transform2D& p_transform); + Transform2D operator*(const Transform2D& p_transform) const; - Matrix32 interpolate_with(const Matrix32& p_transform, real_t p_c) const; + Transform2D interpolate_with(const Transform2D& p_transform, real_t p_c) const; _FORCE_INLINE_ Vector2 basis_xform(const Vector2& p_vec) const; _FORCE_INLINE_ Vector2 basis_xform_inv(const Vector2& p_vec) const; @@ -624,7 +624,7 @@ struct Matrix32 { operator String() const; - Matrix32(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) { elements[0][0] = xx; elements[0][1] = xy; @@ -634,11 +634,11 @@ struct Matrix32 { elements[2][1] = oy; } - Matrix32(real_t p_rot, const Vector2& p_pos); - Matrix32() { elements[0][0]=1.0; elements[1][1]=1.0; } + Transform2D(real_t p_rot, const Vector2& p_pos); + Transform2D() { elements[0][0]=1.0; elements[1][1]=1.0; } }; -bool Rect2::intersects_transformed(const Matrix32& 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 @@ -793,7 +793,7 @@ bool Rect2::intersects_transformed(const Matrix32& p_xform, const Rect2& p_rect) } -Vector2 Matrix32::basis_xform(const Vector2& v) const { +Vector2 Transform2D::basis_xform(const Vector2& v) const { return Vector2( tdotx(v), @@ -801,7 +801,7 @@ Vector2 Matrix32::basis_xform(const Vector2& v) const { ); } -Vector2 Matrix32::basis_xform_inv(const Vector2& v) const{ +Vector2 Transform2D::basis_xform_inv(const Vector2& v) const{ return Vector2( elements[0].dot(v), @@ -809,14 +809,14 @@ Vector2 Matrix32::basis_xform_inv(const Vector2& v) const{ ); } -Vector2 Matrix32::xform(const Vector2& v) const { +Vector2 Transform2D::xform(const Vector2& v) const { return Vector2( tdotx(v), tdoty(v) ) + elements[2]; } -Vector2 Matrix32::xform_inv(const Vector2& p_vec) const { +Vector2 Transform2D::xform_inv(const Vector2& p_vec) const { Vector2 v = p_vec - elements[2]; @@ -826,7 +826,7 @@ Vector2 Matrix32::xform_inv(const Vector2& p_vec) const { ); } -Rect2 Matrix32::xform(const Rect2& p_rect) const { +Rect2 Transform2D::xform(const Rect2& p_rect) const { Vector2 x=elements[0]*p_rect.size.x; Vector2 y=elements[1]*p_rect.size.y; @@ -840,7 +840,7 @@ Rect2 Matrix32::xform(const Rect2& p_rect) const { return new_rect; } -void Matrix32::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]=Math::cos(p_rot)*p_scale.x; elements[1][1]=Math::cos(p_rot)*p_scale.y; @@ -849,7 +849,7 @@ void Matrix32::set_rotation_and_scale(real_t p_rot,const Size2& p_scale) { } -Rect2 Matrix32::xform_inv(const Rect2& p_rect) const { +Rect2 Transform2D::xform_inv(const Rect2& p_rect) const { Vector2 ends[4]={ xform_inv( p_rect.pos ), diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp index 44abf8cd36..e9c3442582 100644 --- a/core/math/matrix3.cpp +++ b/core/math/matrix3.cpp @@ -33,7 +33,7 @@ #define cofac(row1,col1, row2, col2)\ (elements[row1][col1] * elements[row2][col2] - elements[row1][col2] * elements[row2][col1]) -void Matrix3::from_z(const Vector3& p_z) { +void Basis::from_z(const Vector3& p_z) { if (Math::abs(p_z.z) > Math_SQRT12 ) { @@ -53,7 +53,7 @@ void Matrix3::from_z(const Vector3& p_z) { elements[2]=p_z; } -void Matrix3::invert() { +void Basis::invert() { real_t co[3]={ @@ -72,7 +72,7 @@ void Matrix3::invert() { } -void Matrix3::orthonormalize() { +void Basis::orthonormalize() { ERR_FAIL_COND(determinant() == 0); // Gram-Schmidt Process @@ -93,26 +93,26 @@ void Matrix3::orthonormalize() { } -Matrix3 Matrix3::orthonormalized() const { +Basis Basis::orthonormalized() const { - Matrix3 c = *this; + Basis c = *this; c.orthonormalize(); return c; } -bool Matrix3::is_orthogonal() const { - Matrix3 id; - Matrix3 m = (*this)*transposed(); +bool Basis::is_orthogonal() const { + Basis id; + Basis m = (*this)*transposed(); return isequal_approx(id,m); } -bool Matrix3::is_rotation() const { +bool Basis::is_rotation() const { return Math::isequal_approx(determinant(), 1) && is_orthogonal(); } -bool Matrix3::is_symmetric() const { +bool Basis::is_symmetric() const { if (Math::abs(elements[0][1] - elements[1][0]) > CMP_EPSILON) return false; @@ -125,19 +125,19 @@ bool Matrix3::is_symmetric() const { } -Matrix3 Matrix3::diagonalize() { +Basis Basis::diagonalize() { //NOTE: only implemented for symmetric matrices //with the Jacobi iterative method method - ERR_FAIL_COND_V(!is_symmetric(), Matrix3()); + ERR_FAIL_COND_V(!is_symmetric(), Basis()); const int ite_max = 1024; real_t off_matrix_norm_2 = elements[0][1] * elements[0][1] + elements[0][2] * elements[0][2] + elements[1][2] * elements[1][2]; int ite = 0; - Matrix3 acc_rot; + Basis acc_rot; while (off_matrix_norm_2 > CMP_EPSILON2 && ite++ < ite_max ) { real_t el01_2 = elements[0][1] * elements[0][1]; real_t el02_2 = elements[0][2] * elements[0][2]; @@ -171,7 +171,7 @@ Matrix3 Matrix3::diagonalize() { } // Compute the rotation matrix - Matrix3 rot; + Basis rot; rot.elements[i][i] = rot.elements[j][j] = Math::cos(angle); rot.elements[i][j] = - (rot.elements[j][i] = Math::sin(angle)); @@ -186,30 +186,30 @@ Matrix3 Matrix3::diagonalize() { return acc_rot; } -Matrix3 Matrix3::inverse() const { +Basis Basis::inverse() const { - Matrix3 inv=*this; + Basis inv=*this; inv.invert(); return inv; } -void Matrix3::transpose() { +void Basis::transpose() { SWAP(elements[0][1],elements[1][0]); SWAP(elements[0][2],elements[2][0]); SWAP(elements[1][2],elements[2][1]); } -Matrix3 Matrix3::transposed() const { +Basis Basis::transposed() const { - Matrix3 tr=*this; + Basis tr=*this; tr.transpose(); return tr; } // Multiplies the matrix from left by the scaling matrix: M -> S.M -// See the comment for Matrix3::rotated for further explanation. -void Matrix3::scale(const Vector3& p_scale) { +// See the comment for Basis::rotated for further explanation. +void Basis::scale(const Vector3& p_scale) { elements[0][0]*=p_scale.x; elements[0][1]*=p_scale.x; @@ -222,14 +222,14 @@ void Matrix3::scale(const Vector3& p_scale) { elements[2][2]*=p_scale.z; } -Matrix3 Matrix3::scaled( const Vector3& p_scale ) const { +Basis Basis::scaled( const Vector3& p_scale ) const { - Matrix3 m = *this; + Basis m = *this; m.scale(p_scale); return m; } -Vector3 Matrix3::get_scale() const { +Vector3 Basis::get_scale() const { // We are assuming M = R.S, and performing a polar decomposition to extract R and S. // 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 @@ -247,30 +247,30 @@ Vector3 Matrix3::get_scale() const { // Multiplies the matrix from left by the rotation matrix: M -> R.M // Note that this does *not* rotate the matrix itself. // -// The main use of Matrix3 is as Transform.basis, which is used a the transformation matrix +// The main use of Basis is as Transform.basis, which is used a the transformation matrix // of 3D object. Rotate here refers to rotation of the object (which is R * (*this)), // not the matrix itself (which is R * (*this) * R.transposed()). -Matrix3 Matrix3::rotated(const Vector3& p_axis, real_t p_phi) const { - return Matrix3(p_axis, p_phi) * (*this); +Basis Basis::rotated(const Vector3& p_axis, real_t p_phi) const { + return Basis(p_axis, p_phi) * (*this); } -void Matrix3::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); } -Matrix3 Matrix3::rotated(const Vector3& p_euler) const { - return Matrix3(p_euler) * (*this); +Basis Basis::rotated(const Vector3& p_euler) const { + return Basis(p_euler) * (*this); } -void Matrix3::rotate(const Vector3& p_euler) { +void Basis::rotate(const Vector3& p_euler) { *this = rotated(p_euler); } -Vector3 Matrix3::get_rotation() const { +Vector3 Basis::get_rotation() const { // Assumes that the matrix can be decomposed into a proper rotation and scaling matrix as M = R.S, // and returns the Euler angles corresponding to the rotation part, complementing get_scale(). // See the comment in get_scale() for further information. - Matrix3 m = orthonormalized(); + Basis m = orthonormalized(); real_t det = m.determinant(); if (det < 0) { // Ensure that the determinant is 1, such that result is a proper rotation matrix which can be represented by Euler angles. @@ -290,7 +290,7 @@ Vector3 Matrix3::get_rotation() const { // And thus, assuming the matrix is a rotation matrix, this function returns // the angles in the decomposition R = X(a1).Y(a2).Z(a3) where Z(a) rotates // around the z-axis by a and so on. -Vector3 Matrix3::get_euler() const { +Vector3 Basis::get_euler() const { // Euler angles in XYZ convention. // See https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix @@ -329,27 +329,27 @@ Vector3 Matrix3::get_euler() const { // set_euler expects a vector containing the Euler angles in the format // (c,b,a), where a is the angle of the first rotation, and c is the last. // The current implementation uses XYZ convention (Z is the first rotation). -void Matrix3::set_euler(const Vector3& p_euler) { +void Basis::set_euler(const Vector3& p_euler) { real_t c, s; c = Math::cos(p_euler.x); s = Math::sin(p_euler.x); - Matrix3 xmat(1.0,0.0,0.0,0.0,c,-s,0.0,s,c); + Basis xmat(1.0,0.0,0.0,0.0,c,-s,0.0,s,c); c = Math::cos(p_euler.y); s = Math::sin(p_euler.y); - Matrix3 ymat(c,0.0,s,0.0,1.0,0.0,-s,0.0,c); + Basis ymat(c,0.0,s,0.0,1.0,0.0,-s,0.0,c); c = Math::cos(p_euler.z); s = Math::sin(p_euler.z); - Matrix3 zmat(c,-s,0.0,s,c,0.0,0.0,0.0,1.0); + Basis zmat(c,-s,0.0,s,c,0.0,0.0,0.0,1.0); //optimizer will optimize away all this anyway *this = xmat*(ymat*zmat); } -bool Matrix3::isequal_approx(const Matrix3& a, const Matrix3& b) const { +bool Basis::isequal_approx(const Basis& a, const Basis& b) const { for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { @@ -361,7 +361,7 @@ bool Matrix3::isequal_approx(const Matrix3& a, const Matrix3& b) const { return true; } -bool Matrix3::operator==(const Matrix3& p_matrix) const { +bool Basis::operator==(const Basis& p_matrix) const { for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { @@ -373,12 +373,12 @@ bool Matrix3::operator==(const Matrix3& p_matrix) const { return true; } -bool Matrix3::operator!=(const Matrix3& p_matrix) const { +bool Basis::operator!=(const Basis& p_matrix) const { return (!(*this==p_matrix)); } -Matrix3::operator String() const { +Basis::operator String() const { String mtx; for (int i=0;i<3;i++) { @@ -395,7 +395,7 @@ Matrix3::operator String() const { return mtx; } -Matrix3::operator Quat() const { +Basis::operator Quat() const { ERR_FAIL_COND_V(is_rotation() == false, Quat()); real_t trace = elements[0][0] + elements[1][1] + elements[2][2]; @@ -432,37 +432,37 @@ Matrix3::operator Quat() const { } -static const Matrix3 _ortho_bases[24]={ - Matrix3(1, 0, 0, 0, 1, 0, 0, 0, 1), - Matrix3(0, -1, 0, 1, 0, 0, 0, 0, 1), - Matrix3(-1, 0, 0, 0, -1, 0, 0, 0, 1), - Matrix3(0, 1, 0, -1, 0, 0, 0, 0, 1), - Matrix3(1, 0, 0, 0, 0, -1, 0, 1, 0), - Matrix3(0, 0, 1, 1, 0, 0, 0, 1, 0), - Matrix3(-1, 0, 0, 0, 0, 1, 0, 1, 0), - Matrix3(0, 0, -1, -1, 0, 0, 0, 1, 0), - Matrix3(1, 0, 0, 0, -1, 0, 0, 0, -1), - Matrix3(0, 1, 0, 1, 0, 0, 0, 0, -1), - Matrix3(-1, 0, 0, 0, 1, 0, 0, 0, -1), - Matrix3(0, -1, 0, -1, 0, 0, 0, 0, -1), - Matrix3(1, 0, 0, 0, 0, 1, 0, -1, 0), - Matrix3(0, 0, -1, 1, 0, 0, 0, -1, 0), - Matrix3(-1, 0, 0, 0, 0, -1, 0, -1, 0), - Matrix3(0, 0, 1, -1, 0, 0, 0, -1, 0), - Matrix3(0, 0, 1, 0, 1, 0, -1, 0, 0), - Matrix3(0, -1, 0, 0, 0, 1, -1, 0, 0), - Matrix3(0, 0, -1, 0, -1, 0, -1, 0, 0), - Matrix3(0, 1, 0, 0, 0, -1, -1, 0, 0), - Matrix3(0, 0, 1, 0, -1, 0, 1, 0, 0), - Matrix3(0, 1, 0, 0, 0, 1, 1, 0, 0), - Matrix3(0, 0, -1, 0, 1, 0, 1, 0, 0), - Matrix3(0, -1, 0, 0, 0, -1, 1, 0, 0) +static const Basis _ortho_bases[24]={ + Basis(1, 0, 0, 0, 1, 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(0, 1, 0, -1, 0, 0, 0, 0, 1), + Basis(1, 0, 0, 0, 0, -1, 0, 1, 0), + Basis(0, 0, 1, 1, 0, 0, 0, 1, 0), + Basis(-1, 0, 0, 0, 0, 1, 0, 1, 0), + Basis(0, 0, -1, -1, 0, 0, 0, 1, 0), + Basis(1, 0, 0, 0, -1, 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(0, -1, 0, -1, 0, 0, 0, 0, -1), + Basis(1, 0, 0, 0, 0, 1, 0, -1, 0), + Basis(0, 0, -1, 1, 0, 0, 0, -1, 0), + Basis(-1, 0, 0, 0, 0, -1, 0, -1, 0), + Basis(0, 0, 1, -1, 0, 0, 0, -1, 0), + Basis(0, 0, 1, 0, 1, 0, -1, 0, 0), + Basis(0, -1, 0, 0, 0, 1, -1, 0, 0), + Basis(0, 0, -1, 0, -1, 0, -1, 0, 0), + Basis(0, 1, 0, 0, 0, -1, -1, 0, 0), + Basis(0, 0, 1, 0, -1, 0, 1, 0, 0), + Basis(0, 1, 0, 0, 0, 1, 1, 0, 0), + Basis(0, 0, -1, 0, 1, 0, 1, 0, 0), + Basis(0, -1, 0, 0, 0, -1, 1, 0, 0) }; -int Matrix3::get_orthogonal_index() const { +int Basis::get_orthogonal_index() const { //could be sped up if i come up with a way - Matrix3 orth=*this; + Basis orth=*this; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { @@ -489,7 +489,7 @@ int Matrix3::get_orthogonal_index() const { return 0; } -void Matrix3::set_orthogonal_index(int p_index){ +void Basis::set_orthogonal_index(int p_index){ //there only exist 24 orthogonal bases in r3 ERR_FAIL_INDEX(p_index,24); @@ -500,7 +500,7 @@ void Matrix3::set_orthogonal_index(int p_index){ } -void Matrix3::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const { +void Basis::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const { ERR_FAIL_COND(is_rotation() == false); @@ -581,13 +581,13 @@ void Matrix3::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const { r_angle=angle; } -Matrix3::Matrix3(const Vector3& p_euler) { +Basis::Basis(const Vector3& p_euler) { set_euler( p_euler ); } -Matrix3::Matrix3(const Quat& p_quat) { +Basis::Basis(const Quat& p_quat) { real_t d = p_quat.length_squared(); real_t s = 2.0 / d; @@ -601,7 +601,7 @@ Matrix3::Matrix3(const Quat& p_quat) { } -Matrix3::Matrix3(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 Vector3 axis_sq(p_axis.x*p_axis.x,p_axis.y*p_axis.y,p_axis.z*p_axis.z); diff --git a/core/math/matrix3.h b/core/math/matrix3.h index 0b61e3a56c..abce1ee45d 100644 --- a/core/math/matrix3.h +++ b/core/math/matrix3.h @@ -37,7 +37,7 @@ /** @author Juan Linietsky <reduzio@gmail.com> */ -class Matrix3 { +class Basis { public: Vector3 elements[3]; @@ -54,8 +54,8 @@ public: void invert(); void transpose(); - Matrix3 inverse() const; - Matrix3 transposed() const; + Basis inverse() const; + Basis transposed() const; _FORCE_INLINE_ real_t determinant() const; @@ -73,14 +73,14 @@ public: } void rotate(const Vector3& p_axis, real_t p_phi); - Matrix3 rotated(const Vector3& p_axis, real_t p_phi) const; + Basis rotated(const Vector3& p_axis, real_t p_phi) const; void rotate(const Vector3& p_euler); - Matrix3 rotated(const Vector3& p_euler) const; + Basis rotated(const Vector3& p_euler) const; Vector3 get_rotation() const; void scale( const Vector3& p_scale ); - Matrix3 scaled( const Vector3& p_scale ) const; + Basis scaled( const Vector3& p_scale ) const; Vector3 get_scale() const; Vector3 get_euler() const; @@ -97,21 +97,21 @@ public: return elements[0][2] * v[0] + elements[1][2] * v[1] + elements[2][2] * v[2]; } - bool isequal_approx(const Matrix3& a, const Matrix3& b) const; + bool isequal_approx(const Basis& a, const Basis& b) const; - bool operator==(const Matrix3& p_matrix) const; - bool operator!=(const Matrix3& p_matrix) const; + bool operator==(const Basis& p_matrix) const; + bool operator!=(const Basis& p_matrix) const; _FORCE_INLINE_ Vector3 xform(const Vector3& p_vector) const; _FORCE_INLINE_ Vector3 xform_inv(const Vector3& p_vector) const; - _FORCE_INLINE_ void operator*=(const Matrix3& p_matrix); - _FORCE_INLINE_ Matrix3 operator*(const Matrix3& p_matrix) const; - _FORCE_INLINE_ void operator+=(const Matrix3& p_matrix); - _FORCE_INLINE_ Matrix3 operator+(const Matrix3& p_matrix) const; - _FORCE_INLINE_ void operator-=(const Matrix3& p_matrix); - _FORCE_INLINE_ Matrix3 operator-(const Matrix3& p_matrix) const; + _FORCE_INLINE_ void operator*=(const Basis& p_matrix); + _FORCE_INLINE_ Basis operator*(const Basis& p_matrix) const; + _FORCE_INLINE_ void operator+=(const Basis& p_matrix); + _FORCE_INLINE_ Basis operator+(const Basis& p_matrix) const; + _FORCE_INLINE_ void operator-=(const Basis& p_matrix); + _FORCE_INLINE_ Basis operator-(const Basis& p_matrix) const; _FORCE_INLINE_ void operator*=(real_t p_val); - _FORCE_INLINE_ Matrix3 operator*(real_t p_val) const; + _FORCE_INLINE_ Basis operator*(real_t p_val) const; int get_orthogonal_index() const; void set_orthogonal_index(int p_index); @@ -163,9 +163,9 @@ public: elements[2].zero(); } - _FORCE_INLINE_ Matrix3 transpose_xform(const Matrix3& m) const + _FORCE_INLINE_ Basis transpose_xform(const Basis& m) const { - return Matrix3( + 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].y + elements[1].x * m[1].y + elements[2].x * m[2].y, elements[0].x * m[0].z + elements[1].x * m[1].z + elements[2].x * m[2].z, @@ -176,31 +176,31 @@ public: elements[0].z * m[0].y + elements[1].z * m[1].y + elements[2].z * m[2].y, elements[0].z * m[0].z + elements[1].z * m[1].z + elements[2].z * m[2].z); } - Matrix3(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) { set(xx, xy, xz, yx, yy, yz, zx, zy, zz); } void orthonormalize(); - Matrix3 orthonormalized() const; + Basis orthonormalized() const; bool is_symmetric() const; - Matrix3 diagonalize(); + Basis diagonalize(); operator Quat() const; - Matrix3(const Quat& p_quat); // euler - Matrix3(const Vector3& p_euler); // euler - Matrix3(const Vector3& p_axis, real_t p_phi); + Basis(const Quat& p_quat); // euler + Basis(const Vector3& p_euler); // euler + Basis(const Vector3& p_axis, real_t p_phi); - _FORCE_INLINE_ Matrix3(const Vector3& row0, const Vector3& row1, const Vector3& row2) + _FORCE_INLINE_ Basis(const Vector3& row0, const Vector3& row1, const Vector3& row2) { elements[0]=row0; elements[1]=row1; elements[2]=row2; } - _FORCE_INLINE_ Matrix3() { + _FORCE_INLINE_ Basis() { elements[0][0]=1; elements[0][1]=0; @@ -216,7 +216,7 @@ public: }; -_FORCE_INLINE_ void Matrix3::operator*=(const Matrix3& p_matrix) { +_FORCE_INLINE_ void Basis::operator*=(const Basis& p_matrix) { set( p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]), @@ -225,9 +225,9 @@ _FORCE_INLINE_ void Matrix3::operator*=(const Matrix3& p_matrix) { } -_FORCE_INLINE_ Matrix3 Matrix3::operator*(const Matrix3& p_matrix) const { +_FORCE_INLINE_ Basis Basis::operator*(const Basis& p_matrix) const { - return Matrix3( + return Basis( 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[2]), p_matrix.tdoty(elements[2]), p_matrix.tdotz(elements[2]) ); @@ -235,49 +235,49 @@ _FORCE_INLINE_ Matrix3 Matrix3::operator*(const Matrix3& p_matrix) const { } -_FORCE_INLINE_ void Matrix3::operator+=(const Matrix3& p_matrix) { +_FORCE_INLINE_ void Basis::operator+=(const Basis& p_matrix) { elements[0] += p_matrix.elements[0]; elements[1] += p_matrix.elements[1]; elements[2] += p_matrix.elements[2]; } -_FORCE_INLINE_ Matrix3 Matrix3::operator+(const Matrix3& p_matrix) const { +_FORCE_INLINE_ Basis Basis::operator+(const Basis& p_matrix) const { - Matrix3 ret(*this); + Basis ret(*this); ret += p_matrix; return ret; } -_FORCE_INLINE_ void Matrix3::operator-=(const Matrix3& p_matrix) { +_FORCE_INLINE_ void Basis::operator-=(const Basis& p_matrix) { elements[0] -= p_matrix.elements[0]; elements[1] -= p_matrix.elements[1]; elements[2] -= p_matrix.elements[2]; } -_FORCE_INLINE_ Matrix3 Matrix3::operator-(const Matrix3& p_matrix) const { +_FORCE_INLINE_ Basis Basis::operator-(const Basis& p_matrix) const { - Matrix3 ret(*this); + Basis ret(*this); ret -= p_matrix; return ret; } -_FORCE_INLINE_ void Matrix3::operator*=(real_t p_val) { +_FORCE_INLINE_ void Basis::operator*=(real_t p_val) { elements[0]*=p_val; elements[1]*=p_val; elements[2]*=p_val; } -_FORCE_INLINE_ Matrix3 Matrix3::operator*(real_t p_val) const { +_FORCE_INLINE_ Basis Basis::operator*(real_t p_val) const { - Matrix3 ret(*this); + Basis ret(*this); ret *= p_val; return ret; } -Vector3 Matrix3::xform(const Vector3& p_vector) const { +Vector3 Basis::xform(const Vector3& p_vector) const { return Vector3( elements[0].dot(p_vector), @@ -286,7 +286,7 @@ Vector3 Matrix3::xform(const Vector3& p_vector) const { ); } -Vector3 Matrix3::xform_inv(const Vector3& p_vector) const { +Vector3 Basis::xform_inv(const Vector3& p_vector) const { return Vector3( (elements[0][0]*p_vector.x ) + ( elements[1][0]*p_vector.y ) + ( elements[2][0]*p_vector.z ), @@ -295,7 +295,7 @@ Vector3 Matrix3::xform_inv(const Vector3& p_vector) const { ); } -real_t Matrix3::determinant() const { +real_t Basis::determinant() const { 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]) + diff --git a/core/math/octree.h b/core/math/octree.h index 189041cdc5..1a41413a76 100644 --- a/core/math/octree.h +++ b/core/math/octree.h @@ -107,7 +107,7 @@ private: struct Octant { // cached for FAST plane check - AABB aabb; + Rect3 aabb; uint64_t last_pass; Octant *parent; @@ -152,8 +152,8 @@ private: OctreeElementID _id; Octant *common_parent; - AABB aabb; - AABB container_aabb; + Rect3 aabb; + Rect3 container_aabb; List<PairData*,AL> pair_list; @@ -338,7 +338,7 @@ private: void _insert_element(Element *p_element,Octant *p_octant); - void _ensure_valid_root(const AABB& p_aabb); + void _ensure_valid_root(const Rect3& p_aabb); bool _remove_element_from_octant(Element *p_element,Octant *p_octant,Octant *p_limit=NULL); void _remove_element(Element *p_element); void _pair_element(Element *p_element,Octant *p_octant); @@ -356,7 +356,7 @@ private: }; void _cull_convex(Octant *p_octant,_CullConvexData *p_cull); - void _cull_AABB(Octant *p_octant,const AABB& p_aabb, T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask); + void _cull_AABB(Octant *p_octant,const Rect3& p_aabb, T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask); void _cull_segment(Octant *p_octant,const Vector3& p_from, const Vector3& p_to,T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask); void _cull_point(Octant *p_octant,const Vector3& p_point,T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask); @@ -375,8 +375,8 @@ private: } public: - OctreeElementID create(T* p_userdata, const AABB& p_aabb=AABB(), int p_subindex=0, bool p_pairable=false,uint32_t p_pairable_type=0,uint32_t pairable_mask=1); - void move(OctreeElementID p_id, const AABB& p_aabb); + OctreeElementID create(T* p_userdata, const Rect3& p_aabb=Rect3(), int p_subindex=0, bool p_pairable=false,uint32_t p_pairable_type=0,uint32_t pairable_mask=1); + void move(OctreeElementID p_id, const Rect3& p_aabb); void set_pairable(OctreeElementID p_id,bool p_pairable=false,uint32_t p_pairable_type=0,uint32_t pairable_mask=1); void erase(OctreeElementID p_id); @@ -385,7 +385,7 @@ public: int get_subindex(OctreeElementID p_id) const; int cull_convex(const Vector<Plane>& p_convex,T** p_result_array,int p_result_max,uint32_t p_mask=0xFFFFFFFF); - int cull_AABB(const AABB& p_aabb,T** p_result_array,int p_result_max,int *p_subindex_array=NULL,uint32_t p_mask=0xFFFFFFFF); + int cull_AABB(const Rect3& p_aabb,T** p_result_array,int p_result_max,int *p_subindex_array=NULL,uint32_t p_mask=0xFFFFFFFF); int cull_segment(const Vector3& p_from, const Vector3& p_to,T** p_result_array,int p_result_max,int *p_subindex_array=NULL,uint32_t p_mask=0xFFFFFFFF); int cull_point(const Vector3& p_point,T** p_result_array,int p_result_max,int *p_subindex_array=NULL,uint32_t p_mask=0xFFFFFFFF); @@ -487,7 +487,7 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant } else { /* check againt AABB where child should be */ - AABB aabb=p_octant->aabb; + Rect3 aabb=p_octant->aabb; aabb.size*=0.5; if (i&1) @@ -549,12 +549,12 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant template<class T,bool use_pairs,class AL> -void Octree<T,use_pairs,AL>::_ensure_valid_root(const AABB& p_aabb) { +void Octree<T,use_pairs,AL>::_ensure_valid_root(const Rect3& p_aabb) { if (!root) { // octre is empty - AABB base( Vector3(), Vector3(1.0,1.0,1.0) * unit_size); + Rect3 base( Vector3(), Vector3(1.0,1.0,1.0) * unit_size); while ( !base.encloses(p_aabb) ) { @@ -578,7 +578,7 @@ void Octree<T,use_pairs,AL>::_ensure_valid_root(const AABB& p_aabb) { } else { - AABB base=root->aabb; + Rect3 base=root->aabb; while( !base.encloses( p_aabb ) ) { @@ -814,7 +814,7 @@ void Octree<T,use_pairs,AL>::_remove_element(Element *p_element) { } template<class T,bool use_pairs,class AL> -OctreeElementID Octree<T,use_pairs,AL>::create(T* p_userdata, const AABB& p_aabb, int p_subindex,bool p_pairable,uint32_t p_pairable_type,uint32_t p_pairable_mask) { +OctreeElementID Octree<T,use_pairs,AL>::create(T* p_userdata, const Rect3& p_aabb, int p_subindex,bool p_pairable,uint32_t p_pairable_type,uint32_t p_pairable_mask) { // check for AABB validity #ifdef DEBUG_ENABLED @@ -857,7 +857,7 @@ OctreeElementID Octree<T,use_pairs,AL>::create(T* p_userdata, const AABB& p_aabb template<class T,bool use_pairs,class AL> -void Octree<T,use_pairs,AL>::move(OctreeElementID p_id, const AABB& p_aabb) { +void Octree<T,use_pairs,AL>::move(OctreeElementID p_id, const Rect3& p_aabb) { #ifdef DEBUG_ENABLED // check for AABB validity @@ -906,7 +906,7 @@ void Octree<T,use_pairs,AL>::move(OctreeElementID p_id, const AABB& p_aabb) { if (old_has_surf) { _remove_element(&e); // removing e.common_parent=NULL; - e.aabb=AABB(); + e.aabb=Rect3(); _optimize(); } else { _ensure_valid_root(p_aabb); // inserting @@ -935,7 +935,7 @@ void Octree<T,use_pairs,AL>::move(OctreeElementID p_id, const AABB& p_aabb) { return; } - AABB combined=e.aabb; + Rect3 combined=e.aabb; combined.merge_with(p_aabb); _ensure_valid_root(combined); @@ -1129,7 +1129,7 @@ void Octree<T,use_pairs,AL>::_cull_convex(Octant *p_octant,_CullConvexData *p_cu template<class T,bool use_pairs,class AL> -void Octree<T,use_pairs,AL>::_cull_AABB(Octant *p_octant,const AABB& p_aabb, T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask) { +void Octree<T,use_pairs,AL>::_cull_AABB(Octant *p_octant,const Rect3& p_aabb, T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask) { if (*p_result_idx==p_result_max) return; //pointless @@ -1376,7 +1376,7 @@ int Octree<T,use_pairs,AL>::cull_convex(const Vector<Plane>& p_convex,T** p_resu template<class T,bool use_pairs,class AL> -int Octree<T,use_pairs,AL>::cull_AABB(const AABB& p_aabb,T** p_result_array,int p_result_max,int *p_subindex_array,uint32_t p_mask) { +int Octree<T,use_pairs,AL>::cull_AABB(const Rect3& p_aabb,T** p_result_array,int p_result_max,int *p_subindex_array,uint32_t p_mask) { if (!root) diff --git a/core/math/quat.cpp b/core/math/quat.cpp index afe71100e1..055e2b7c35 100644 --- a/core/math/quat.cpp +++ b/core/math/quat.cpp @@ -59,7 +59,7 @@ void Quat::set_euler(const Vector3& p_euler) { // (a1,a2,a3), where a3 is the angle of the first rotation, and a1 is the last. // The current implementation uses XYZ convention (Z is the first rotation). Vector3 Quat::get_euler() const { - Matrix3 m(*this); + Basis m(*this); return m.get_euler(); } diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp index ce6f726418..ab81a068d4 100644 --- a/core/math/quick_hull.cpp +++ b/core/math/quick_hull.cpp @@ -38,7 +38,7 @@ Error QuickHull::build(const Vector<Vector3>& p_points, Geometry::MeshData &r_me /* CREATE AABB VOLUME */ - AABB aabb; + Rect3 aabb; for(int i=0;i<p_points.size();i++) { if (i==0) { diff --git a/core/math/transform.cpp b/core/math/transform.cpp index 0dba121013..6d9324c176 100644 --- a/core/math/transform.cpp +++ b/core/math/transform.cpp @@ -69,7 +69,7 @@ void Transform::rotate(const Vector3& p_axis,real_t p_phi) { Transform Transform::rotated(const Vector3& p_axis,real_t p_phi) const{ - return Transform(Matrix3( 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) { @@ -210,7 +210,7 @@ Transform::operator String() const { } -Transform::Transform(const Matrix3& p_basis, const Vector3& p_origin) { +Transform::Transform(const Basis& p_basis, const Vector3& p_origin) { basis=p_basis; origin=p_origin; diff --git a/core/math/transform.h b/core/math/transform.h index 5f069ab586..d65e87cc6a 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -38,7 +38,7 @@ class Transform { public: - Matrix3 basis; + Basis basis; Vector3 origin; void invert(); @@ -62,8 +62,8 @@ public: void translate( const Vector3& p_translation ); Transform translated( const Vector3& p_translation ) const; - const Matrix3& get_basis() const { return basis; } - void set_basis(const Matrix3& p_basis) { basis=p_basis; } + const Basis& get_basis() const { return basis; } + void set_basis(const Basis& p_basis) { basis=p_basis; } const Vector3& get_origin() const { return origin; } void set_origin(const Vector3& p_origin) { origin=p_origin; } @@ -80,8 +80,8 @@ public: _FORCE_INLINE_ Plane xform(const Plane& p_plane) const; _FORCE_INLINE_ Plane xform_inv(const Plane& p_plane) const; - _FORCE_INLINE_ AABB xform(const AABB& p_aabb) const; - _FORCE_INLINE_ AABB xform_inv(const AABB& p_aabb) const; + _FORCE_INLINE_ Rect3 xform(const Rect3& p_aabb) const; + _FORCE_INLINE_ Rect3 xform_inv(const Rect3& p_aabb) const; void operator*=(const Transform& p_transform); Transform operator*(const Transform& p_transform) const; @@ -113,7 +113,7 @@ public: operator String() const; - Transform(const Matrix3& p_basis, const Vector3& p_origin=Vector3()); + Transform(const Basis& p_basis, const Vector3& p_origin=Vector3()); Transform() {} }; @@ -168,7 +168,7 @@ _FORCE_INLINE_ Plane Transform::xform_inv(const Plane& p_plane) const { } -_FORCE_INLINE_ AABB Transform::xform(const AABB& p_aabb) const { +_FORCE_INLINE_ Rect3 Transform::xform(const Rect3& p_aabb) const { /* define vertices */ #if 1 Vector3 x=basis.get_axis(0)*p_aabb.size.x; @@ -176,7 +176,7 @@ _FORCE_INLINE_ AABB Transform::xform(const AABB& p_aabb) const { Vector3 z=basis.get_axis(2)*p_aabb.size.z; Vector3 pos = xform( p_aabb.pos ); //could be even further optimized - AABB new_aabb; + Rect3 new_aabb; new_aabb.pos=pos; new_aabb.expand_to( pos+x ); new_aabb.expand_to( pos+y ); @@ -214,7 +214,7 @@ _FORCE_INLINE_ AABB Transform::xform(const AABB& p_aabb) const { #endif } -_FORCE_INLINE_ AABB Transform::xform_inv(const AABB& p_aabb) const { +_FORCE_INLINE_ Rect3 Transform::xform_inv(const Rect3& p_aabb) const { /* define vertices */ Vector3 vertices[8]={ @@ -229,7 +229,7 @@ _FORCE_INLINE_ AABB Transform::xform_inv(const AABB& p_aabb) const { }; - AABB ret; + Rect3 ret; ret.pos=xform_inv(vertices[0]); diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index 101e164eae..fc5f55066b 100644 --- a/core/math/triangle_mesh.cpp +++ b/core/math/triangle_mesh.cpp @@ -48,7 +48,7 @@ int TriangleMesh::_create_bvh(BVH*p_bvh,BVH** p_bb,int p_from,int p_size,int p_d } - AABB aabb; + Rect3 aabb; aabb=p_bb[p_from]->aabb; for(int i=1;i<p_size;i++) { @@ -176,7 +176,7 @@ void TriangleMesh::create(const PoolVector<Vector3>& p_faces) { } -Vector3 TriangleMesh::get_area_normal(const AABB& p_aabb) const { +Vector3 TriangleMesh::get_area_normal(const Rect3& p_aabb) const { uint32_t* stack = (uint32_t*)alloca(sizeof(int)*max_depth); diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h index 37d32bd7ec..65250c023d 100644 --- a/core/math/triangle_mesh.h +++ b/core/math/triangle_mesh.h @@ -46,7 +46,7 @@ class TriangleMesh : public Reference { struct BVH { - AABB aabb; + Rect3 aabb; Vector3 center; //used for sorting int left; int right; @@ -88,7 +88,7 @@ public: bool is_valid() const; bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_point, Vector3 &r_normal) const; bool intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vector3 &r_point, Vector3 &r_normal) const; - Vector3 get_area_normal(const AABB& p_aabb) const; + Vector3 get_area_normal(const Rect3& p_aabb) const; PoolVector<Face3> get_faces() const; diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index 7c6cc5182d..3eb978333d 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -32,7 +32,7 @@ void Vector3::rotate(const Vector3& p_axis,float p_phi) { - *this=Matrix3(p_axis,p_phi).xform(*this); + *this=Basis(p_axis,p_phi).xform(*this); } Vector3 Vector3::rotated(const Vector3& p_axis,float p_phi) const { diff --git a/core/math/vector3.h b/core/math/vector3.h index f1f34ce318..9ae9b69dfa 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -34,7 +34,7 @@ #include "math_funcs.h" #include "ustring.h" -class Matrix3; +class Basis; struct Vector3 { @@ -93,8 +93,8 @@ struct Vector3 { _FORCE_INLINE_ Vector3 cross(const Vector3& p_b) const; _FORCE_INLINE_ real_t dot(const Vector3& p_b) const; - _FORCE_INLINE_ Matrix3 outer(const Vector3& p_b) const; - _FORCE_INLINE_ Matrix3 to_diagonal_matrix() const; + _FORCE_INLINE_ Basis outer(const Vector3& p_b) const; + _FORCE_INLINE_ Basis to_diagonal_matrix() const; _FORCE_INLINE_ Vector3 abs() const; _FORCE_INLINE_ Vector3 floor() const; @@ -165,17 +165,17 @@ real_t Vector3::dot(const Vector3& p_b) const { return x*p_b.x + y*p_b.y + z*p_b.z; } -Matrix3 Vector3::outer(const Vector3& p_b) const { +Basis Vector3::outer(const Vector3& p_b) const { Vector3 row0(x*p_b.x, x*p_b.y, x*p_b.z); Vector3 row1(y*p_b.x, y*p_b.y, y*p_b.z); Vector3 row2(z*p_b.x, z*p_b.y, z*p_b.z); - return Matrix3(row0, row1, row2); + return Basis(row0, row1, row2); } -Matrix3 Vector3::to_diagonal_matrix() const { - return Matrix3(x, 0, 0, +Basis Vector3::to_diagonal_matrix() const { + return Basis(x, 0, 0, 0, y, 0, 0, 0, z); } |