summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
Diffstat (limited to 'core/math')
-rw-r--r--core/math/aabb.h14
-rw-r--r--core/math/bsp_tree.cpp84
-rw-r--r--core/math/bsp_tree.h22
-rw-r--r--core/math/camera_matrix.cpp118
-rw-r--r--core/math/camera_matrix.h16
-rw-r--r--core/math/face3.h4
-rw-r--r--core/math/geometry.cpp328
-rw-r--r--core/math/geometry.h106
-rw-r--r--core/math/math_2d.cpp54
-rw-r--r--core/math/math_2d.h92
-rw-r--r--core/math/math_funcs.cpp20
-rw-r--r--core/math/math_funcs.h16
-rw-r--r--core/math/matrix3.cpp42
-rw-r--r--core/math/matrix3.h32
-rw-r--r--core/math/octree.h406
-rw-r--r--core/math/plane.cpp6
-rw-r--r--core/math/plane.h4
-rw-r--r--core/math/quat.cpp12
-rw-r--r--core/math/quat.h14
-rw-r--r--core/math/transform.cpp24
-rw-r--r--core/math/transform.h62
21 files changed, 738 insertions, 738 deletions
diff --git a/core/math/aabb.h b/core/math/aabb.h
index 0fada859c0..57fe1b32f5 100644
--- a/core/math/aabb.h
+++ b/core/math/aabb.h
@@ -47,21 +47,21 @@ public:
float get_area() const; /// get area
_FORCE_INLINE_ bool has_no_area() const {
-
+
return (size.x<=CMP_EPSILON || size.y<=CMP_EPSILON || size.z<=CMP_EPSILON);
}
_FORCE_INLINE_ bool has_no_surface() const {
-
+
return (size.x<=CMP_EPSILON && size.y<=CMP_EPSILON && size.z<=CMP_EPSILON);
}
-
+
const Vector3& get_pos() const { return pos; }
void set_pos(const Vector3& p_pos) { pos=p_pos; }
const Vector3& get_size() const { return size; }
void set_size(const Vector3& p_size) { size=p_size; }
-
+
bool operator==(const AABB& p_rval) const;
bool operator!=(const AABB& p_rval) const;
@@ -265,7 +265,7 @@ bool AABB::has_point(const Vector3& p_point) const {
return false;
if (p_point.z>pos.z+size.z)
return false;
-
+
return true;
}
@@ -297,11 +297,11 @@ void AABB::project_range_in_plane(const Plane& p_plane,float &r_min,float& r_max
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 );
-
+
float length = p_plane.normal.abs().dot(half_extents);
float distance = p_plane.distance_to( center );
r_min = distance - length;
- r_max = distance + length;
+ r_max = distance + length;
}
inline real_t AABB::get_longest_axis_size() const {
diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp
index 0c07b733f0..d16495217c 100644
--- a/core/math/bsp_tree.cpp
+++ b/core/math/bsp_tree.cpp
@@ -66,12 +66,12 @@ Vector<Plane> BSP_Tree::get_planes() const {
return planes;
}
-
+
AABB BSP_Tree::get_aabb() const {
return aabb;
}
-
+
int BSP_Tree::_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 {
@@ -245,22 +245,22 @@ bool BSP_Tree::point_is_inside(const Vector3& p_point) const {
if (!aabb.has_point(p_point)) {
return false;
}
-
+
int node_count=nodes.size();
-
+
if (node_count==0) // no nodes!
return false;
-
-
+
+
const Node *nodesptr=&nodes[0];
const Plane *planesptr=&planes[0];
int plane_count=planes.size();
-
+
int idx=node_count-1;
int steps=0;
-
+
while(true) {
-
+
if (idx==OVER_LEAF) {
return false;
}
@@ -268,28 +268,28 @@ bool BSP_Tree::point_is_inside(const Vector3& p_point) const {
return true;
}
-
+
uint16_t plane=nodesptr[ idx ].plane;
#ifdef DEBUG_ENABLED
-
+
ERR_FAIL_INDEX_V( plane, plane_count, false );
#endif
bool over = planesptr[ nodesptr[ idx ].plane ].is_point_over(p_point);
idx = over ? nodes[ idx ].over : nodes[ idx ].under;
-
+
#ifdef DEBUG_ENABLED
-
+
ERR_FAIL_COND_V( idx<MAX_NODES && idx>=node_count, false );
#endif
-
+
steps++;
}
return false;
}
-
-
+
+
static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_indices,float p_tolerance) {
int ic = p_indices.size();
@@ -304,7 +304,7 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i
const Face3& f=p_faces[ indices[i] ];
Plane p = f.get_plane();
-
+
int num_over=0,num_under=0,num_spanning=0;
for(int j=0;j<ic;j++) {
@@ -335,17 +335,17 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i
num_over++;
else
num_under++;
-
+
}
//double split_cost = num_spanning / (double) face_count;
double relation = Math::abs(num_over-num_under) / (double) ic;
-
+
// being honest, i never found a way to add split cost to the mix in a meaninguful way
// in this engine, also, will likely be ignored anyway
-
+
double plane_cost = /*split_cost +*/ relation;
//printf("plane %i, %i over, %i under, %i spanning, cost is %g\n",i,num_over,num_under,num_spanning,plane_cost);
@@ -360,10 +360,10 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i
return best_plane;
}
-
+
static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Vector<Plane> &p_planes, Vector<BSP_Tree::Node> &p_nodes,float p_tolerance) {
-
+
ERR_FAIL_COND_V( p_nodes.size() == BSP_Tree::MAX_NODES, -1 );
// should not reach here
@@ -387,7 +387,7 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve
if (i==divisor_idx)
continue;
-
+
const Face3& f=p_faces[ indices[i] ];
//if (f.get_plane().is_almost_like(divisor_plane))
@@ -416,7 +416,7 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve
}
-
+
uint16_t over_idx=BSP_Tree::OVER_LEAF,under_idx=BSP_Tree::UNDER_LEAF;
if (faces_over.size()>0) { //have facess above?
@@ -434,13 +434,13 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve
}
/* Create the node */
-
+
// find existing divisor plane
int divisor_plane_idx=-1;
-
-
+
+
for (int i=0;i<p_planes.size();i++) {
-
+
if (p_planes[i].is_almost_like( divisor_plane )) {
divisor_plane_idx=i;
break;
@@ -448,22 +448,22 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve
}
if (divisor_plane_idx==-1) {
-
+
ERR_FAIL_COND_V( p_planes.size() == BSP_Tree::MAX_PLANES, -1 );
divisor_plane_idx=p_planes.size();
p_planes.push_back( divisor_plane );
}
-
+
BSP_Tree::Node node;
node.plane=divisor_plane_idx;
node.under=under_idx;
node.over=over_idx;
-
+
p_nodes.push_back(node);
-
+
return p_nodes.size()-1;
}
-
+
BSP_Tree::operator Variant() const {
@@ -563,7 +563,7 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) {
BSP_Tree::BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius) {
// compute aabb
-
+
int face_count=p_faces.size();
DVector<Face3>::Read faces_r=p_faces.read();
const Face3 *facesptr = faces_r.ptr();
@@ -574,26 +574,26 @@ BSP_Tree::BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius) {
Vector<int> indices;
for (int i=0;i<face_count;i++) {
-
+
const Face3& f=facesptr[i];
-
+
if (f.is_degenerate())
continue;
-
+
for (int j=0;j<3;j++) {
-
+
if (first) {
-
+
aabb.pos=f.vertex[0];
first=false;
} else {
-
+
aabb.expand_to(f.vertex[j]);
}
}
indices.push_back(i);
-
+
}
ERR_FAIL_COND( aabb.has_no_area() );
@@ -609,7 +609,7 @@ BSP_Tree::BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius) {
-
+
error_radius=p_error_radius;
}
diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h
index a7145f9ff1..2bfc26b51e 100644
--- a/core/math/bsp_tree.h
+++ b/core/math/bsp_tree.h
@@ -43,7 +43,7 @@ class BSP_Tree {
public:
enum {
-
+
UNDER_LEAF=0xFFFF,
OVER_LEAF=0xFFFE,
MAX_NODES=0xFFFE,
@@ -51,22 +51,22 @@ public:
};
struct Node {
-
+
uint16_t plane;
uint16_t under;
uint16_t over;
};
-
-private:
- // thanks to the properties of Vector,
+
+private:
+ // thanks to the properties of Vector,
// this class can be assigned and passed around between threads
// with no cost.
-
+
Vector<Node> nodes;
Vector<Plane> planes;
AABB aabb;
- float error_radius;
+ 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;
@@ -79,8 +79,8 @@ public:
Vector<Node> get_nodes() const;
Vector<Plane> get_planes() const;
AABB get_aabb() const;
-
- bool point_is_inside(const Vector3& p_point) const;
+
+ bool point_is_inside(const Vector3& p_point) const;
int get_points_inside(const Vector3* p_points, int p_point_count) const;
template<class T>
bool convex_is_inside(const T& p_convex) const;
@@ -91,8 +91,8 @@ public:
BSP_Tree();
BSP_Tree(const Variant& p_variant);
- BSP_Tree(const DVector<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 DVector<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();
};
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index 61c8b78e0a..f7dd8839b8 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -33,9 +33,9 @@
void CameraMatrix::set_identity() {
for (int i=0;i<4;i++) {
-
+
for (int j=0;j<4;j++) {
-
+
matrix[i][j]=(i==j)?1:0;
}
}
@@ -90,7 +90,7 @@ void CameraMatrix::set_perspective(float p_fovy_degrees, float p_aspect, float p
matrix[2][2] = -(p_z_far + p_z_near) / deltaZ;
matrix[2][3] = -1;
matrix[3][2] = -2 * p_z_near * p_z_far / deltaZ;
- matrix[3][3] = 0;
+ matrix[3][3] = 0;
}
@@ -155,95 +155,95 @@ void CameraMatrix::set_frustum(float p_left, float p_right, float p_bottom, floa
float CameraMatrix::get_z_far() const {
-
- const float * matrix = (const float*)this->matrix;
+
+ const float * matrix = (const float*)this->matrix;
Plane new_plane=Plane(matrix[ 3] - matrix[ 2],
matrix[ 7] - matrix[ 6],
matrix[11] - matrix[10],
matrix[15] - matrix[14]);
-
+
new_plane.normal=-new_plane.normal;
new_plane.normalize();
-
+
return new_plane.d;
}
float CameraMatrix::get_z_near() const {
-
- const float * matrix = (const float*)this->matrix;
+
+ const float * matrix = (const float*)this->matrix;
Plane new_plane=Plane(matrix[ 3] + matrix[ 2],
matrix[ 7] + matrix[ 6],
matrix[11] + matrix[10],
-matrix[15] - matrix[14]);
-
+
new_plane.normalize();
return new_plane.d;
}
void CameraMatrix::get_viewport_size(float& r_width, float& r_height) const {
- const float * matrix = (const float*)this->matrix;
+ const float * matrix = (const float*)this->matrix;
///////--- Near Plane ---///////
Plane near_plane=Plane(matrix[ 3] + matrix[ 2],
matrix[ 7] + matrix[ 6],
matrix[11] + matrix[10],
-matrix[15] - matrix[14]).normalized();
-
+
///////--- Right Plane ---///////
Plane right_plane=Plane(matrix[ 3] - matrix[ 0],
matrix[ 7] - matrix[ 4],
matrix[11] - matrix[ 8],
- matrix[15] + matrix[12]).normalized();
-
+
Plane top_plane=Plane(matrix[ 3] - matrix[ 1],
matrix[ 7] - matrix[ 5],
matrix[11] - matrix[ 9],
-matrix[15] + matrix[13]).normalized();
-
+
Vector3 res;
near_plane.intersect_3(right_plane,top_plane,&res);
-
+
r_width=res.x;
r_height=res.y;
}
bool CameraMatrix::get_endpoints(const Transform& p_transform, Vector3 *p_8points) const {
- const float * matrix = (const float*)this->matrix;
-
+ const float * matrix = (const float*)this->matrix;
+
///////--- Near Plane ---///////
Plane near_plane=Plane(matrix[ 3] + matrix[ 2],
matrix[ 7] + matrix[ 6],
matrix[11] + matrix[10],
-matrix[15] - matrix[14]).normalized();
-
+
///////--- Far Plane ---///////
Plane far_plane=Plane(matrix[ 2] - matrix[ 3],
matrix[ 6] - matrix[ 7],
matrix[10] - matrix[11],
matrix[15] - matrix[14]).normalized();
-
+
///////--- Right Plane ---///////
Plane right_plane=Plane(matrix[ 0] - matrix[ 3],
matrix[ 4] - matrix[ 7],
matrix[8] - matrix[ 11],
- matrix[15] + matrix[12]).normalized();
-
- ///////--- Top Plane ---///////
+
+ ///////--- Top Plane ---///////
Plane top_plane=Plane(matrix[ 1] - matrix[ 3],
matrix[ 5] - matrix[ 7],
matrix[9] - matrix[ 11],
-matrix[15] + matrix[13]).normalized();
-
+
Vector3 near_endpoint;
Vector3 far_endpoint;
-
+
bool res=near_plane.intersect_3(right_plane,top_plane,&near_endpoint);
ERR_FAIL_COND_V(!res,false);
-
+
res=far_plane.intersect_3(right_plane,top_plane,&far_endpoint);
ERR_FAIL_COND_V(!res,false);
-
+
p_8points[0]=p_transform.xform( Vector3( near_endpoint.x, near_endpoint.y, near_endpoint.z ) );
p_8points[1]=p_transform.xform( Vector3( near_endpoint.x,-near_endpoint.y, near_endpoint.z ) );
p_8points[2]=p_transform.xform( Vector3(-near_endpoint.x, near_endpoint.y, near_endpoint.z ) );
@@ -252,7 +252,7 @@ bool CameraMatrix::get_endpoints(const Transform& p_transform, Vector3 *p_8point
p_8points[5]=p_transform.xform( Vector3( far_endpoint.x,-far_endpoint.y, far_endpoint.z ) );
p_8points[6]=p_transform.xform( Vector3(-far_endpoint.x, far_endpoint.y, far_endpoint.z ) );
p_8points[7]=p_transform.xform( Vector3(-far_endpoint.x,-far_endpoint.y, far_endpoint.z ) );
-
+
return true;
}
@@ -263,10 +263,10 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform)
* http://www.markmorley.com/opengl/frustumculling.html
* http://www2.ravensoft.com/users/ggribb/plane%20extraction.pdf
*/
-
+
Vector<Plane> planes;
-
- const float * matrix = (const float*)this->matrix;
+
+ const float * matrix = (const float*)this->matrix;
Plane new_plane;
@@ -275,7 +275,7 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform)
matrix[ 7] + matrix[ 6],
matrix[11] + matrix[10],
matrix[15] + matrix[14]);
-
+
new_plane.normal=-new_plane.normal;
new_plane.normalize();
@@ -298,7 +298,7 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform)
matrix[ 7] + matrix[ 4],
matrix[11] + matrix[ 8],
matrix[15] + matrix[12]);
-
+
new_plane.normal=-new_plane.normal;
new_plane.normalize();
@@ -310,8 +310,8 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform)
matrix[ 7] - matrix[ 5],
matrix[11] - matrix[ 9],
matrix[15] - matrix[13]);
-
-
+
+
new_plane.normal=-new_plane.normal;
new_plane.normalize();
@@ -324,10 +324,10 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform)
matrix[11] - matrix[ 8],
matrix[15] - matrix[12]);
-
+
new_plane.normal=-new_plane.normal;
new_plane.normalize();
-
+
planes.push_back( p_transform.xform(new_plane) );
@@ -337,12 +337,12 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform)
matrix[11] + matrix[ 9],
matrix[15] + matrix[13]);
-
+
new_plane.normal=-new_plane.normal;
new_plane.normalize();
planes.push_back( p_transform.xform(new_plane) );
-
+
return planes;
}
@@ -356,7 +356,7 @@ CameraMatrix CameraMatrix::inverse() const {
}
void CameraMatrix::invert() {
-
+
int i,j,k;
int pvt_i[4], pvt_j[4]; /* Locations of pivot matrix */
float pvt_val; /* Value of current pivot element */
@@ -448,7 +448,7 @@ void CameraMatrix::invert() {
}
}
-
+
}
CameraMatrix::CameraMatrix() {
@@ -475,31 +475,31 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix& p_matrix) const {
void CameraMatrix::set_light_bias() {
float *m=&matrix[0][0];
-
- m[0]=0.5,
- m[1]=0.0,
- m[2]=0.0,
+
+ m[0]=0.5,
+ m[1]=0.0,
+ m[2]=0.0,
m[3]=0.0,
- m[4]=0.0,
- m[5]=0.5,
- m[6]=0.0,
+ m[4]=0.0,
+ m[5]=0.5,
+ m[6]=0.0,
m[7]=0.0,
- m[8]=0.0,
- m[9]=0.0,
- m[10]=0.5,
+ m[8]=0.0,
+ m[9]=0.0,
+ m[10]=0.5,
m[11]=0.0,
- m[12]=0.5,
- m[13]=0.5,
- m[14]=0.5,
- m[15]=1.0;
-
+ m[12]=0.5,
+ m[13]=0.5,
+ m[14]=0.5,
+ m[15]=1.0;
+
}
CameraMatrix::operator String() const {
String str;
- for (int i=0;i<4;i++)
- for (int j=0;j<4;j++)
+ for (int i=0;i<4;i++)
+ for (int j=0;j<4;j++)
str+=String((j>0)?", ":"\n")+rtos(matrix[i][j]);
return str;
@@ -513,7 +513,7 @@ float CameraMatrix::get_aspect() const {
}
float CameraMatrix::get_fov() const {
- const float * matrix = (const float*)this->matrix;
+ const float * matrix = (const float*)this->matrix;
Plane right_plane=Plane(matrix[ 3] - matrix[ 0],
matrix[ 7] - matrix[ 4],
@@ -588,7 +588,7 @@ CameraMatrix::CameraMatrix(const Transform& p_transform) {
const Transform &tr = p_transform;
float *m=&matrix[0][0];
-
+
m[0]=tr.basis.elements[0][0];
m[1]=tr.basis.elements[1][0];
m[2]=tr.basis.elements[2][0];
@@ -604,7 +604,7 @@ CameraMatrix::CameraMatrix(const Transform& p_transform) {
m[12]=tr.origin.x;
m[13]=tr.origin.y;
m[14]=tr.origin.z;
- m[15]=1.0;
+ m[15]=1.0;
}
CameraMatrix::~CameraMatrix()
diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h
index 27500a545e..d192b1fef1 100644
--- a/core/math/camera_matrix.h
+++ b/core/math/camera_matrix.h
@@ -48,8 +48,8 @@ struct CameraMatrix {
};
float matrix[4][4];
-
-
+
+
void set_identity();
void set_zero();
void set_light_bias();
@@ -67,12 +67,12 @@ struct CameraMatrix {
float get_z_near() const;
float get_aspect() const;
float get_fov() const;
-
+
Vector<Plane> get_projection_planes(const Transform& p_transform) const;
-
+
bool get_endpoints(const Transform& p_transform,Vector3 *p_8points) const;
void get_viewport_size(float& r_width, float& r_height) const;
-
+
void invert();
CameraMatrix inverse() const;
@@ -80,15 +80,15 @@ struct CameraMatrix {
Plane xform4(const Plane& p_vec4);
_FORCE_INLINE_ Vector3 xform(const Vector3& p_vec3) const;
-
+
operator String() const;
void scale_translate_to_fit(const AABB& p_aabb);
void make_scale(const Vector3 &p_scale);
operator Transform() const;
- CameraMatrix();
- CameraMatrix(const Transform& p_transform);
+ CameraMatrix();
+ CameraMatrix(const Transform& p_transform);
~CameraMatrix();
};
diff --git a/core/math/face3.h b/core/math/face3.h
index c36fdd1332..bc34be9935 100644
--- a/core/math/face3.h
+++ b/core/math/face3.h
@@ -55,7 +55,7 @@ public:
* @param _epsilon constant used for numerical error rounding, to add "thickness" to the plane (so coplanar points can happen)
* @return amount of faces generated by the split, either 0 (means no split possible), 2 or 3
*/
-
+
int split_by_plane(const Plane& p_plane,Face3 *p_res,bool *p_is_point_over) const;
Plane get_plane(ClockDirection p_dir=CLOCKWISE) const;
@@ -77,7 +77,7 @@ 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 {
AABB aabb( vertex[0], Vector3() );
diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp
index 2905d26fe5..5b767212f5 100644
--- a/core/math/geometry.cpp
+++ b/core/math/geometry.cpp
@@ -211,7 +211,7 @@ DVector< DVector< Face3 > > Geometry::separate_objects( DVector< Face3 > p_array
int len = p_array.size();
DVector<Face3>::Read r=p_array.read();
-
+
const Face3* arrayptr = r.ptr();
DVector< _FaceClassify> fc;
@@ -219,7 +219,7 @@ DVector< DVector< Face3 > > Geometry::separate_objects( DVector< Face3 > p_array
fc.resize( len );
DVector< _FaceClassify >::Write fcw=fc.write();
-
+
_FaceClassify * _fcptr = fcw.ptr();
for (int i=0;i<len;i++) {
@@ -278,7 +278,7 @@ DVector< DVector< Face3 > > Geometry::separate_objects( DVector< Face3 > p_array
/*** GEOMETRY WRAPPER ***/
enum _CellFlags {
-
+
_CELL_SOLID=1,
_CELL_EXTERIOR=2,
_CELL_STEP_MASK=0x1C,
@@ -299,7 +299,7 @@ enum _CellFlags {
_CELL_PREV_Z_POS=5<<5,
_CELL_PREV_Z_NEG=6<<5,
_CELL_PREV_FIRST=7<<5,
-
+
};
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) {
@@ -316,9 +316,9 @@ static inline void _plot_face(uint8_t*** p_cell_status,int x,int y,int z,int len
p_cell_status[x][y][z]=_CELL_SOLID;
return;
}
-
-
-
+
+
+
int div_x=len_x>1?2:1;
int div_y=len_y>1?2:1;
int div_z=len_z>1?2:1;
@@ -343,14 +343,14 @@ static inline void _plot_face(uint8_t*** p_cell_status,int x,int y,int z,int len
int new_len_z;
for (int i=0;i<div_x;i++) {
-
-
+
+
_SPLIT(i,div_x,x,len_x,new_x,new_len_x);
-
+
for (int j=0;j<div_y;j++) {
_SPLIT(j,div_y,y,len_y,new_y,new_len_y);
-
+
for (int k=0;k<div_z;k++) {
_SPLIT(k,div_z,z,len_z,new_z,new_len_z);
@@ -365,39 +365,39 @@ static inline void _mark_outside(uint8_t*** p_cell_status,int x,int y,int z,int
if (p_cell_status[x][y][z]&3)
return; // nothing to do, already used and/or visited
-
+
p_cell_status[x][y][z]=_CELL_PREV_FIRST;
-
+
while(true) {
-
+
uint8_t &c = p_cell_status[x][y][z];
-
+
//printf("at %i,%i,%i\n",x,y,z);
-
- if ( (c&_CELL_STEP_MASK)==_CELL_STEP_NONE) {
+
+ if ( (c&_CELL_STEP_MASK)==_CELL_STEP_NONE) {
/* Haven't been in here, mark as outside */
p_cell_status[x][y][z]|=_CELL_EXTERIOR;
//printf("not marked as anything, marking exterior\n");
}
-
+
//printf("cell step is %i\n",(c&_CELL_STEP_MASK));
-
+
if ( (c&_CELL_STEP_MASK)!=_CELL_STEP_DONE) {
/* if not done, increase step */
c+=1<<2;
//printf("incrementing cell step\n");
}
-
+
if ( (c&_CELL_STEP_MASK)==_CELL_STEP_DONE) {
/* Go back */
//printf("done, going back a cell\n");
-
+
switch(c&_CELL_PREV_MASK) {
case _CELL_PREV_FIRST: {
- //printf("at end, finished marking\n");
+ //printf("at end, finished marking\n");
return;
} break;
- case _CELL_PREV_Y_POS: {
+ case _CELL_PREV_Y_POS: {
y++;
ERR_FAIL_COND(y>=len_y);
} break;
@@ -427,16 +427,16 @@ static inline void _mark_outside(uint8_t*** p_cell_status,int x,int y,int z,int
}
continue;
}
-
+
//printf("attempting new cell!\n");
-
+
int next_x=x,next_y=y,next_z=z;
uint8_t prev=0;
-
+
switch(c&_CELL_STEP_MASK) {
-
+
case _CELL_STEP_Y_POS: {
-
+
next_y++;
prev=_CELL_PREV_Y_NEG;
} break;
@@ -454,32 +454,32 @@ static inline void _mark_outside(uint8_t*** p_cell_status,int x,int y,int z,int
} break;
case _CELL_STEP_Z_POS: {
next_z++;
- prev=_CELL_PREV_Z_NEG;
+ prev=_CELL_PREV_Z_NEG;
} break;
case _CELL_STEP_Z_NEG: {
next_z--;
- prev=_CELL_PREV_Z_POS;
+ prev=_CELL_PREV_Z_POS;
} break;
- default: ERR_FAIL();
-
+ default: ERR_FAIL();
+
}
-
+
//printf("testing if new cell will be ok...!\n");
-
+
if (next_x<0 || next_x>=len_x)
continue;
if (next_y<0 || next_y>=len_y)
continue;
if (next_z<0 || next_z>=len_z)
continue;
-
+
//printf("testing if new cell is traversable\n");
-
+
if (p_cell_status[next_x][next_y][next_z]&3)
continue;
-
+
//printf("move to it\n");
-
+
x=next_x;
y=next_y;
z=next_z;
@@ -488,14 +488,14 @@ static inline void _mark_outside(uint8_t*** p_cell_status,int x,int y,int z,int
}
static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int len_x,int len_y,int len_z,DVector<Face3>& p_faces) {
-
+
ERR_FAIL_INDEX(x,len_x);
ERR_FAIL_INDEX(y,len_y);
ERR_FAIL_INDEX(z,len_z);
-
+
if (p_cell_status[x][y][z]&_CELL_EXTERIOR)
- return;
-
+ return;
+
/* static const Vector3 vertices[8]={
Vector3(0,0,0),
Vector3(0,0,1),
@@ -510,73 +510,73 @@ static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int l
#define vert(m_idx) Vector3( (m_idx&4)>>2, (m_idx&2)>>1, m_idx&1 )
static const uint8_t indices[6][4]={
- {7,6,4,5},
+ {7,6,4,5},
{7,3,2,6},
- {7,5,1,3},
- {0,2,3,1},
- {0,1,5,4},
+ {7,5,1,3},
+ {0,2,3,1},
+ {0,1,5,4},
{0,4,6,2},
};
-/*
+/*
- {0,1,2,3},
- {0,1,4,5},
+ {0,1,2,3},
+ {0,1,4,5},
{0,2,4,6},
- {4,5,6,7},
+ {4,5,6,7},
{2,3,7,6},
- {1,3,5,7},
+ {1,3,5,7},
- {0,2,3,1},
- {0,1,5,4},
+ {0,2,3,1},
+ {0,1,5,4},
{0,4,6,2},
- {7,6,4,5},
+ {7,6,4,5},
{7,3,2,6},
- {7,5,1,3},
+ {7,5,1,3},
*/
-
+
for (int i=0;i<6;i++) {
-
+
Vector3 face_points[4];
int disp_x=x+((i%3)==0?((i<3)?1:-1):0);
int disp_y=y+(((i-1)%3)==0?((i<3)?1:-1):0);
int disp_z=z+(((i-2)%3)==0?((i<3)?1:-1):0);
-
+
bool plot=false;
-
+
if (disp_x<0 || disp_x>=len_x)
plot=true;
if (disp_y<0 || disp_y>=len_y)
plot=true;
if (disp_z<0 || disp_z>=len_z)
plot=true;
-
+
if (!plot && (p_cell_status[disp_x][disp_y][disp_z]&_CELL_EXTERIOR))
plot=true;
-
+
if (!plot)
continue;
-
+
for (int j=0;j<4;j++)
face_points[j]=vert( indices[i][j] ) + Vector3(x,y,z);
-
- p_faces.push_back(
- Face3(
+
+ p_faces.push_back(
+ Face3(
face_points[0],
face_points[1],
face_points[2]
)
);
-
- p_faces.push_back(
- Face3(
+
+ p_faces.push_back(
+ Face3(
face_points[2],
face_points[3],
face_points[0]
)
);
-
- }
+
+ }
}
@@ -601,7 +601,7 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro
global_aabb.merge_with( faces[i].get_aabb() );
}
}
-
+
global_aabb.grow_by(0.01); // avoid numerical error
// determine amount of cells in grid axis
@@ -649,7 +649,7 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro
// plot faces into cells
print_line("Wrapper (1/6): Plotting Faces");
-
+
for (int i=0;i<face_count;i++) {
Face3 f=faces[i];
@@ -666,68 +666,68 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro
print_line("Wrapper (2/6) Flood Filling");
for (int i=0;i<div_x;i++) {
-
+
for (int j=0;j<div_y;j++) {
-
+
_mark_outside(cell_status,i,j,0,div_x,div_y,div_z);
_mark_outside(cell_status,i,j,div_z-1,div_x,div_y,div_z);
}
}
-
+
for (int i=0;i<div_z;i++) {
-
+
for (int j=0;j<div_y;j++) {
-
+
_mark_outside(cell_status,0,j,i,div_x,div_y,div_z);
_mark_outside(cell_status,div_x-1,j,i,div_x,div_y,div_z);
}
}
-
+
for (int i=0;i<div_x;i++) {
-
+
for (int j=0;j<div_z;j++) {
-
+
_mark_outside(cell_status,i,0,j,div_x,div_y,div_z);
_mark_outside(cell_status,i,div_y-1,j,div_x,div_y,div_z);
}
}
-
+
// build faces for the inside-outside cell divisors
-
+
print_line("Wrapper (3/6): Building Faces");
DVector<Face3> wrapped_faces;
-
+
for (int i=0;i<div_x;i++) {
-
+
for (int j=0;j<div_y;j++) {
-
+
for (int k=0;k<div_z;k++) {
-
- _build_faces(cell_status,i,j,k,div_x,div_y,div_z,wrapped_faces);
+
+ _build_faces(cell_status,i,j,k,div_x,div_y,div_z,wrapped_faces);
}
}
}
-
+
print_line("Wrapper (4/6): Transforming Back Vertices");
// transform face vertices to global coords
-
+
int wrapped_faces_count=wrapped_faces.size();
DVector<Face3>::Write wrapped_facesw=wrapped_faces.write();
Face3* wrapped_faces_ptr=wrapped_facesw.ptr();
-
+
for(int i=0;i<wrapped_faces_count;i++) {
-
+
for(int j=0;j<3;j++) {
-
+
Vector3& v = wrapped_faces_ptr[i].vertex[j];
v=v*voxelsize;
v+=global_aabb.pos;
}
}
-
- // clean up grid
+
+ // clean up grid
print_line("Wrapper (5/6): Grid Cleanup");
for(int i=0;i<div_x;i++) {
@@ -736,14 +736,14 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro
memdelete_arr( cell_status[i][j] );
}
-
+
memdelete_arr( cell_status[i] );
}
-
+
memdelete_arr(cell_status);
if (p_error)
*p_error=voxelsize.length();
-
+
print_line("Wrapper (6/6): Finished.");
return wrapped_faces;
}
@@ -751,67 +751,67 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro
Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) {
MeshData mesh;
-
-
+
+
#define SUBPLANE_SIZE 1024.0
-
+
float subplane_size = 1024.0; // should compute this from the actual plane
for (int i=0;i<p_planes.size();i++) {
-
+
Plane p =p_planes[i];
-
+
Vector3 ref=Vector3(0.0,1.0,0.0);
-
+
if (ABS(p.normal.dot(ref))>0.95)
ref=Vector3(0.0,0.0,1.0); // change axis
-
+
Vector3 right = p.normal.cross(ref).normalized();
Vector3 up = p.normal.cross( right ).normalized();
-
+
Vector< Vector3 > vertices;
-
+
Vector3 center = p.get_any_point();
// make a quad clockwise
vertices.push_back( center - up * subplane_size + right * subplane_size );
vertices.push_back( center - up * subplane_size - right * subplane_size );
vertices.push_back( center + up * subplane_size - right * subplane_size );
vertices.push_back( center + up * subplane_size + right * subplane_size );
-
+
for (int j=0;j<p_planes.size();j++) {
if (j==i)
continue;
-
+
Vector< Vector3 > new_vertices;
Plane clip=p_planes[j];
-
+
if (clip.normal.dot(p.normal)>0.95)
continue;
-
+
if (vertices.size()<3)
break;
-
+
for(int k=0;k<vertices.size();k++) {
-
+
int k_n=(k+1)%vertices.size();
-
+
Vector3 edge0_A=vertices[k];
Vector3 edge1_A=vertices[k_n];
-
+
real_t dist0 = clip.distance_to(edge0_A);
real_t dist1 = clip.distance_to(edge1_A);
-
-
- if ( dist0 <= 0 ) { // behind plane
-
- new_vertices.push_back(vertices[k]);
+
+
+ if ( dist0 <= 0 ) { // behind plane
+
+ new_vertices.push_back(vertices[k]);
}
-
-
+
+
// check for different sides and non coplanar
- if ( (dist0*dist1) < 0) {
-
+ if ( (dist0*dist1) < 0) {
+
// calculate intersection
Vector3 rel = edge1_A - edge0_A;
@@ -822,55 +822,55 @@ Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) {
real_t dist=-(clip.normal.dot( edge0_A )-clip.d)/den;
Vector3 inters = edge0_A+rel*dist;
new_vertices.push_back(inters);
- }
+ }
}
-
+
vertices=new_vertices;
}
-
+
if (vertices.size()<3)
continue;
-
-
+
+
//result is a clockwise face
-
+
MeshData::Face face;
-
+
// add face indices
for (int j=0;j<vertices.size();j++) {
-
-
+
+
int idx=-1;
for (int k=0;k<mesh.vertices.size();k++) {
-
+
if (mesh.vertices[k].distance_to(vertices[j])<0.001) {
-
+
idx=k;
break;
}
}
-
+
if (idx==-1) {
-
+
idx=mesh.vertices.size();
mesh.vertices.push_back(vertices[j]);
}
-
+
face.indices.push_back(idx);
}
face.plane=p;
mesh.faces.push_back(face);
-
+
//add edge
-
+
for(int j=0;j<face.indices.size();j++) {
-
+
int a=face.indices[j];
int b=face.indices[(j+1)%face.indices.size()];
-
+
bool found=false;
for(int k=0;k<mesh.edges.size();k++) {
-
+
if (mesh.edges[k].a==a && mesh.edges[k].b==b) {
found=true;
break;
@@ -878,9 +878,9 @@ Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) {
if (mesh.edges[k].b==a && mesh.edges[k].a==b) {
found=true;
break;
- }
+ }
}
-
+
if (found)
continue;
MeshData::Edge edge;
@@ -888,8 +888,8 @@ Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) {
edge.b=b;
mesh.edges.push_back(edge);
}
-
-
+
+
}
return mesh;
@@ -899,36 +899,36 @@ Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) {
DVector<Plane> Geometry::build_box_planes(const Vector3& p_extents) {
DVector<Plane> planes;
-
+
planes.push_back( Plane( Vector3(1,0,0), p_extents.x ) );
planes.push_back( Plane( Vector3(-1,0,0), p_extents.x ) );
planes.push_back( Plane( Vector3(0,1,0), p_extents.y ) );
planes.push_back( Plane( Vector3(0,-1,0), p_extents.y ) );
planes.push_back( Plane( Vector3(0,0,1), p_extents.z ) );
planes.push_back( Plane( Vector3(0,0,-1), p_extents.z ) );
-
+
return planes;
}
DVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
DVector<Plane> planes;
-
+
for (int i=0;i<p_sides;i++) {
-
+
Vector3 normal;
normal[(p_axis+1)%3]=Math::cos(i*(2.0*Math_PI)/p_sides);
normal[(p_axis+2)%3]=Math::sin(i*(2.0*Math_PI)/p_sides);
-
+
planes.push_back( Plane( normal, p_radius ) );
}
-
+
Vector3 axis;
axis[p_axis]=1.0;
-
+
planes.push_back( Plane( axis, p_height*0.5 ) );
planes.push_back( Plane( -axis, p_height*0.5 ) );
-
+
return planes;
}
@@ -972,34 +972,34 @@ DVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p_lo
DVector<Plane> Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
DVector<Plane> planes;
-
+
Vector3 axis;
axis[p_axis]=1.0;
-
- Vector3 axis_neg;
+
+ Vector3 axis_neg;
axis_neg[(p_axis+1)%3]=1.0;
axis_neg[(p_axis+2)%3]=1.0;
axis_neg[p_axis]=-1.0;
-
+
for (int i=0;i<p_sides;i++) {
-
+
Vector3 normal;
normal[(p_axis+1)%3]=Math::cos(i*(2.0*Math_PI)/p_sides);
normal[(p_axis+2)%3]=Math::sin(i*(2.0*Math_PI)/p_sides);
-
+
planes.push_back( Plane( normal, p_radius ) );
-
+
for (int j=1;j<=p_lats;j++) {
-
+
Vector3 angle = normal.linear_interpolate(axis,j/(float)p_lats).normalized();
Vector3 pos = axis*p_height*0.5 + angle*p_radius;
planes.push_back( Plane( pos, angle ) );
planes.push_back( Plane( pos * axis_neg, angle * axis_neg) );
-
+
}
}
-
+
return planes;
}
diff --git a/core/math/geometry.h b/core/math/geometry.h
index 8370990d6e..b353423851 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -44,7 +44,7 @@
class Geometry {
Geometry();
public:
-
+
@@ -201,37 +201,37 @@ public:
real_t a =e1.dot(h);
if (a>-CMP_EPSILON && a < CMP_EPSILON) // parallel test
return false;
-
+
real_t f=1.0/a;
-
+
Vector3 s=p_from-p_v0;
real_t u = f * s.dot(h);
-
+
if ( u< 0.0 || u > 1.0)
return false;
-
+
Vector3 q=s.cross(e1);
-
+
real_t v = f * p_dir.dot(q);
-
+
if (v < 0.0 || u + v > 1.0)
return false;
-
- // at this stage we can compute t to find out where
+
+ // at this stage we can compute t to find out where
// the intersection point is on the line
real_t t = f * e2.dot(q);
-
+
if (t > 0.00001) {// ray intersection
if (r_res)
*r_res=p_from+p_dir*t;
return true;
- } else // this means that there is a line intersection
+ } else // this means that there is a line intersection
// but not a ray intersection
return false;
- }
-
+ }
+
static inline bool segment_intersects_triangle( const Vector3& p_from, const Vector3& p_to, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2,Vector3* r_res=0) {
-
+
Vector3 rel=p_to-p_from;
Vector3 e1=p_v1-p_v0;
Vector3 e2=p_v2-p_v0;
@@ -239,34 +239,34 @@ public:
real_t a =e1.dot(h);
if (a>-CMP_EPSILON && a < CMP_EPSILON) // parallel test
return false;
-
+
real_t f=1.0/a;
-
+
Vector3 s=p_from-p_v0;
real_t u = f * s.dot(h);
-
+
if ( u< 0.0 || u > 1.0)
return false;
-
+
Vector3 q=s.cross(e1);
-
+
real_t v = f * rel.dot(q);
-
+
if (v < 0.0 || u + v > 1.0)
return false;
-
- // at this stage we can compute t to find out where
+
+ // at this stage we can compute t to find out where
// the intersection point is on the line
real_t t = f * e2.dot(q);
-
+
if (t > CMP_EPSILON && t<=1.0) {// ray intersection
if (r_res)
*r_res=p_from+rel*t;
return true;
- } else // this means that there is a line intersection
+ } else // this means that there is a line intersection
// but not a ray intersection
return false;
- }
+ }
static inline bool segment_intersects_sphere( const Vector3& p_from, const Vector3& p_to, const Vector3& p_sphere_pos,real_t p_sphere_radius,Vector3* r_res=0,Vector3 *r_norm=0) {
@@ -356,24 +356,24 @@ public:
real_t box_end=size[i];
real_t cmin,cmax;
-
+
if (seg_from < seg_to) {
-
+
if (seg_from > box_end || seg_to < box_begin)
return false;
real_t length=seg_to-seg_from;
cmin = (seg_from < box_begin)?((box_begin - seg_from)/length):0;
cmax = (seg_to > box_end)?((box_end - seg_from)/length):1;
-
+
} else {
-
+
if (seg_to > box_end || seg_from < box_begin)
return false;
real_t length=seg_to-seg_from;
cmin = (seg_from > box_end)?(box_end - seg_from)/length:0;
cmax = (seg_to < box_begin)?(box_begin - seg_from)/length:1;
}
-
+
if (cmin > min) {
min = cmin;
axis=i;
@@ -468,9 +468,9 @@ public:
if (l<1e-10)
return p_segment[0]; // both points are the same, just give any
n/=l;
-
+
float d=n.dot(p);
-
+
if (d<=0.0)
return p_segment[0]; // before first point
else if (d>=l)
@@ -570,27 +570,27 @@ public:
static inline bool point_in_projected_triangle(const Vector3& p_point,const Vector3& p_v1,const Vector3& p_v2,const Vector3& p_v3) {
-
-
- Vector3 face_n = (p_v1-p_v3).cross(p_v1-p_v2);
-
- Vector3 n1 = (p_point-p_v3).cross(p_point-p_v2);
-
+
+
+ Vector3 face_n = (p_v1-p_v3).cross(p_v1-p_v2);
+
+ Vector3 n1 = (p_point-p_v3).cross(p_point-p_v2);
+
if (face_n.dot(n1)<0)
return false;
-
- Vector3 n2 = (p_v1-p_v3).cross(p_v1-p_point);
-
+
+ Vector3 n2 = (p_v1-p_v3).cross(p_v1-p_point);
+
if (face_n.dot(n2)<0)
return false;
-
- Vector3 n3 = (p_v1-p_point).cross(p_v1-p_v2);
-
+
+ Vector3 n3 = (p_v1-p_point).cross(p_v1-p_v2);
+
if (face_n.dot(n3)<0)
return false;
-
+
return true;
-
+
}
static inline bool triangle_sphere_intersection_test(const Vector3 *p_triangle,const Vector3& p_normal,const Vector3& p_sphere_pos, real_t p_sphere_radius,Vector3& r_triangle_contact,Vector3& r_sphere_contact) {
@@ -814,21 +814,21 @@ public:
struct MeshData {
-
+
struct Face {
Plane plane;
Vector<int> indices;
};
-
+
Vector<Face> faces;
-
+
struct Edge {
-
+
int a,b;
};
-
+
Vector<Edge> edges;
-
+
Vector< Vector3 > vertices;
void optimize_vertices();
@@ -927,7 +927,7 @@ public:
static void make_atlas(const Vector<Size2i>& p_rects,Vector<Point2i>& r_result, Size2i& r_size);
-
+
};
diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp
index a485125cb4..0e2060008c 100644
--- a/core/math/math_2d.cpp
+++ b/core/math/math_2d.cpp
@@ -45,10 +45,10 @@ float Vector2::length_squared() const {
}
void Vector2::normalize() {
-
+
float l = x*x + y*y;
if (l!=0) {
-
+
l=Math::sqrt(l);
x/=l;
y/=l;
@@ -56,14 +56,14 @@ void Vector2::normalize() {
}
Vector2 Vector2::normalized() const {
-
+
Vector2 v=*this;
v.normalize();
return v;
}
float Vector2::distance_to(const Vector2& p_vector2) const {
-
+
return Math::sqrt( (x-p_vector2.x)*(x-p_vector2.x) + (y-p_vector2.y)*(y-p_vector2.y));
}
@@ -73,7 +73,7 @@ float Vector2::distance_squared_to(const Vector2& p_vector2) const {
}
float Vector2::angle_to(const Vector2& p_vector2) const {
-
+
return Math::atan2( tangent().dot(p_vector2), dot(p_vector2) );
}
@@ -83,7 +83,7 @@ float Vector2::angle_to_point(const Vector2& p_vector2) const {
}
float Vector2::dot(const Vector2& p_other) const {
-
+
return x*p_other.x + y*p_other.y;
}
@@ -99,62 +99,62 @@ Vector2 Vector2::cross(real_t p_other) const {
Vector2 Vector2::operator+(const Vector2& p_v) const {
-
+
return Vector2(x+p_v.x,y+p_v.y);
}
void Vector2::operator+=(const Vector2& p_v) {
-
+
x+=p_v.x; y+=p_v.y;
}
Vector2 Vector2::operator-(const Vector2& p_v) const {
-
+
return Vector2(x-p_v.x,y-p_v.y);
}
void Vector2::operator-=(const Vector2& p_v) {
-
+
x-=p_v.x; y-=p_v.y;
}
Vector2 Vector2::operator*(const Vector2 &p_v1) const {
-
+
return Vector2(x * p_v1.x, y * p_v1.y);
};
Vector2 Vector2::operator*(const float &rvalue) const {
-
+
return Vector2(x * rvalue, y * rvalue);
};
void Vector2::operator*=(const float &rvalue) {
-
+
x *= rvalue; y *= rvalue;
};
Vector2 Vector2::operator/(const Vector2 &p_v1) const {
-
+
return Vector2(x / p_v1.x, y / p_v1.y);
};
Vector2 Vector2::operator/(const float &rvalue) const {
-
+
return Vector2(x / rvalue, y / rvalue);
};
void Vector2::operator/=(const float &rvalue) {
-
+
x /= rvalue; y /= rvalue;
};
Vector2 Vector2::operator-() const {
-
+
return Vector2(-x,-y);
}
bool Vector2::operator==(const Vector2& p_vec2) const {
-
+
return x==p_vec2.x && y==p_vec2.y;
}
bool Vector2::operator!=(const Vector2& p_vec2) const {
-
+
return x!=p_vec2.x || y!=p_vec2.y;
}
Vector2 Vector2::floor() const {
@@ -621,25 +621,25 @@ float Matrix32::basis_determinant() const {
}
Matrix32 Matrix32::interpolate_with(const Matrix32& p_transform, float p_c) const {
-
+
//extract parameters
Vector2 p1 = get_origin();
Vector2 p2 = p_transform.get_origin();
-
+
real_t r1 = get_rotation();
real_t r2 = p_transform.get_rotation();
-
+
Vector2 s1 = get_scale();
Vector2 s2 = p_transform.get_scale();
-
+
//slerp rotation
Vector2 v1(Math::cos(r1), Math::sin(r1));
Vector2 v2(Math::cos(r2), Math::sin(r2));
-
+
real_t dot = v1.dot(v2);
-
+
dot = (dot < -1.0) ? -1.0 : ((dot > 1.0) ? 1.0 : dot); //clamp dot to [-1,1]
-
+
Vector2 v;
if (dot > 0.9995) {
@@ -649,7 +649,7 @@ Matrix32 Matrix32::interpolate_with(const Matrix32& p_transform, float p_c) cons
Vector2 v3 = (v2 - v1*dot).normalized();
v = v1*Math::cos(angle) + v3*Math::sin(angle);
}
-
+
//construct matrix
Matrix32 res(Math::atan2(v.y, v.x), Vector2::linear_interpolate(p1, p2, p_c));
res.scale_basis(Vector2::linear_interpolate(s1, s2, p_c));
diff --git a/core/math/math_2d.h b/core/math/math_2d.h
index 1171364671..ad4655b8f7 100644
--- a/core/math/math_2d.h
+++ b/core/math/math_2d.h
@@ -35,15 +35,15 @@
@author Juan Linietsky <reduzio@gmail.com>
*/
enum Margin {
-
+
MARGIN_LEFT,
MARGIN_TOP,
MARGIN_RIGHT,
- MARGIN_BOTTOM
+ MARGIN_BOTTOM
};
enum Orientation {
-
+
HORIZONTAL,
VERTICAL
};
@@ -63,7 +63,7 @@ enum VAlign {
};
struct Vector2 {
-
+
union {
float x;
float width;
@@ -87,7 +87,7 @@ struct Vector2 {
float length() const;
float length_squared() const;
- float distance_to(const Vector2& p_vector2) const;
+ float distance_to(const Vector2& p_vector2) const;
float distance_squared_to(const Vector2& p_vector2) const;
float angle_to(const Vector2& p_vector2) const;
float angle_to_point(const Vector2& p_vector2) const;
@@ -114,19 +114,19 @@ struct Vector2 {
Vector2 operator-(const Vector2& p_v) const;
void operator-=(const Vector2& p_v);
Vector2 operator*(const Vector2 &p_v1) const;
-
+
Vector2 operator*(const float &rvalue) const;
void operator*=(const float &rvalue);
void operator*=(const Vector2 &rvalue) { *this = *this * rvalue; }
Vector2 operator/(const Vector2 &p_v1) const;
-
+
Vector2 operator/(const float &rvalue) const;
-
+
void operator/=(const float &rvalue);
-
+
Vector2 operator-() const;
-
+
bool operator==(const Vector2& p_vec2) const;
bool operator!=(const Vector2& p_vec2) const;
@@ -151,14 +151,14 @@ struct Vector2 {
return Vector2(y,-x);
}
-
+
Vector2 floor() const;
Vector2 snapped(const Vector2& p_by) const;
float get_aspect() const { return width/height; }
-
+
operator String() const { return String::num(x)+","+String::num(y); }
-
+
_FORCE_INLINE_ Vector2(float p_x,float p_y) { x=p_x; y=p_y; }
_FORCE_INLINE_ Vector2() { x=0; y=0; }
};
@@ -202,7 +202,7 @@ struct Matrix32;
struct Rect2 {
-
+
Point2 pos;
Size2 size;
@@ -213,7 +213,7 @@ struct Rect2 {
float 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) )
return false;
if ( (pos.x+size.width) <= p_rect.pos.x )
@@ -222,7 +222,7 @@ struct Rect2 {
return false;
if ( (pos.y+size.height) <= p_rect.pos.y )
return false;
-
+
return true;
}
@@ -254,73 +254,73 @@ struct Rect2 {
bool intersects_segment(const Point2& p_from, const Point2& p_to, Point2* r_pos=NULL, Point2* r_normal=NULL) 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));
-
+
}
-
+
inline bool has_no_area() const {
-
+
return (size.x<=0 || size.y<=0);
-
+
}
inline Rect2 clip(const Rect2& p_rect) const { /// return a clipped rect
-
+
Rect2 new_rect=p_rect;
-
+
if (!intersects( new_rect ))
return Rect2();
-
+
new_rect.pos.x = MAX( p_rect.pos.x , pos.x );
new_rect.pos.y = MAX( p_rect.pos.y , pos.y );
-
+
Point2 p_rect_end=p_rect.pos+p_rect.size;
Point2 end=pos+size;
-
+
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;
-
+
return new_rect;
}
-
+
inline Rect2 merge(const Rect2& p_rect) const { ///< return a merged rect
-
+
Rect2 new_rect;
-
+
new_rect.pos.x=MIN( p_rect.pos.x , pos.x );
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.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
-
+
return new_rect;
};
inline bool has_point(const Point2& p_point) const {
if (p_point.x < pos.x)
- return false;
+ return false;
if (p_point.y < pos.y)
- return false;
-
+ return false;
+
if (p_point.x >= (pos.x+size.x) )
- return false;
+ return false;
if (p_point.y >= (pos.y+size.y) )
- return false;
-
+ return false;
+
return true;
}
-
+
inline bool no_area() const { return (size.width<=0 || size.height<=0 ); }
-
+
bool operator==(const Rect2& p_rect) const { return pos==p_rect.pos && size==p_rect.size; }
bool operator!=(const Rect2& p_rect) const { return pos!=p_rect.pos || size!=p_rect.size; }
-
+
inline Rect2 grow(real_t p_by) const {
-
+
Rect2 g=*this;
g.pos.x-=p_by;
g.pos.y-=p_by;
@@ -357,9 +357,9 @@ struct Rect2 {
operator String() const { return String(pos)+","+String(size); }
-
+
Rect2() {}
- Rect2( float p_x, float p_y, float p_width, float p_height) { pos=Point2(p_x,p_y); size=Size2( p_width, p_height ); }
+ Rect2( float p_x, float p_y, float p_width, float p_height) { pos=Point2(p_x,p_y); size=Size2( p_width, p_height ); }
Rect2( const Point2& p_pos, const Size2& p_size ) { pos=p_pos; size=p_size; }
};
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index 20d9db3375..07f114725d 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -185,12 +185,12 @@ double Math::fmod(double p_x,double p_y) {
double Math::fposmod(double p_x,double p_y) {
if (p_x>=0) {
-
+
return Math::fmod(p_x,p_y);
-
+
} else {
-
- return p_y-Math::fmod(-p_x,p_y);
+
+ return p_y-Math::fmod(-p_x,p_y);
}
}
@@ -205,7 +205,7 @@ double Math::ceil(double p_x) {
}
int Math::decimals(double p_step) {
-
+
int max=4;
double llimit = Math::pow(0.1,max);
double ulimit = 1.0-llimit;
@@ -220,7 +220,7 @@ int Math::decimals(double p_step) {
max--;
i++;
}
-
+
return i;
}
@@ -251,11 +251,11 @@ double Math::ease(double p_x, double p_c) {
}
double Math::stepify(double p_value,double p_step) {
-
+
if (p_step!=0) {
-
- p_value=floor( p_value / p_step + 0.5 ) * p_step;
- }
+
+ p_value=floor( p_value / p_step + 0.5 ) * p_step;
+ }
return p_value;
}
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 62890b0371..2e1b9c989e 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -91,25 +91,25 @@ public:
static uint32_t rand();
static double randf();
-
+
static double round(double p_val);
static double random(double from, double to);
-
+
static _FORCE_INLINE_ real_t abs(real_t g) {
-#ifdef REAL_T_IS_DOUBLE
-
- return absd(g);
+#ifdef REAL_T_IS_DOUBLE
+
+ return absd(g);
#else
- return absf(g);
+ return absf(g);
#endif
}
static _FORCE_INLINE_ float absf(float g) {
-
+
union {
float f;
uint32_t i;
@@ -174,7 +174,7 @@ public:
static double pow(double x, double y);
static double log(double x);
static double exp(double x);
-
+
};
diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp
index f51da80a83..71e6b62212 100644
--- a/core/math/matrix3.cpp
+++ b/core/math/matrix3.cpp
@@ -62,11 +62,11 @@ void Matrix3::invert() {
real_t det = elements[0][0] * co[0]+
elements[0][1] * co[1]+
elements[0][2] * co[2];
-
+
ERR_FAIL_COND( det == 0 );
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[2]*s, cofac(0, 1, 2, 0) * s, cofac(0, 0, 1, 1) * s );
@@ -148,7 +148,7 @@ Vector3 Matrix3::get_scale() const {
Vector3(elements[0][1],elements[1][1],elements[2][1]).length(),
Vector3(elements[0][2],elements[1][2],elements[2][2]).length()
);
-
+
}
void Matrix3::rotate(const Vector3& p_axis, real_t p_phi) {
@@ -223,7 +223,7 @@ bool Matrix3::operator==(const Matrix3& p_matrix) const {
return false;
}
}
-
+
return true;
}
bool Matrix3::operator!=(const Matrix3& p_matrix) const {
@@ -235,16 +235,16 @@ Matrix3::operator String() const {
String mtx;
for (int i=0;i<3;i++) {
-
+
for (int j=0;j<3;j++) {
-
+
if (i!=0 || j!=0)
mtx+=", ";
-
+
mtx+=rtos( elements[i][j] );
}
}
-
+
return mtx;
}
@@ -255,34 +255,34 @@ Matrix3::operator Quat() const {
real_t trace = m.elements[0][0] + m.elements[1][1] + m.elements[2][2];
real_t temp[4];
-
- if (trace > 0.0)
+
+ if (trace > 0.0)
{
real_t s = Math::sqrt(trace + 1.0);
temp[3]=(s * 0.5);
s = 0.5 / s;
-
+
temp[0]=((m.elements[2][1] - m.elements[1][2]) * s);
temp[1]=((m.elements[0][2] - m.elements[2][0]) * s);
temp[2]=((m.elements[1][0] - m.elements[0][1]) * s);
- }
- else
+ }
+ else
{
int i = m.elements[0][0] < m.elements[1][1] ?
(m.elements[1][1] < m.elements[2][2] ? 2 : 1) :
(m.elements[0][0] < m.elements[2][2] ? 2 : 0);
- int j = (i + 1) % 3;
+ int j = (i + 1) % 3;
int k = (i + 2) % 3;
-
+
real_t s = Math::sqrt(m.elements[i][i] - m.elements[j][j] - m.elements[k][k] + 1.0);
temp[i] = s * 0.5;
s = 0.5 / s;
-
+
temp[3] = (m.elements[k][j] - m.elements[j][k]) * s;
temp[j] = (m.elements[j][i] + m.elements[i][j]) * s;
temp[k] = (m.elements[k][i] + m.elements[i][k]) * s;
}
-
+
return Quat(temp[0],temp[1],temp[2],temp[3]);
}
@@ -439,7 +439,7 @@ void Matrix3::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const {
Matrix3::Matrix3(const Vector3& p_euler) {
set_euler( p_euler );
-
+
}
Matrix3::Matrix3(const Quat& p_quat) {
@@ -450,8 +450,8 @@ Matrix3::Matrix3(const Quat& p_quat) {
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 yy = p_quat.y * ys, yz = p_quat.y * zs, zz = p_quat.z * zs;
- set( 1.0 - (yy + zz), xy - wz, xz + wy,
- xy + wz, 1.0 - (xx + zz), yz - wx,
+ set( 1.0 - (yy + zz), xy - wz, xz + wy,
+ xy + wz, 1.0 - (xx + zz), yz - wx,
xz - wy, yz + wx, 1.0 - (xx + yy)) ;
}
diff --git a/core/math/matrix3.h b/core/math/matrix3.h
index 291934b8eb..e514f490f7 100644
--- a/core/math/matrix3.h
+++ b/core/math/matrix3.h
@@ -39,20 +39,20 @@ class Matrix3 {
public:
Vector3 elements[3];
-
+
_FORCE_INLINE_ const Vector3& operator[](int axis) const {
-
+
return elements[axis];
}
_FORCE_INLINE_ Vector3& operator[](int axis) {
-
+
return elements[axis];
}
- void invert();
+ void invert();
void transpose();
-
- Matrix3 inverse() const;
+
+ Matrix3 inverse() const;
Matrix3 transposed() const;
_FORCE_INLINE_ float determinant() const;
@@ -90,7 +90,7 @@ public:
_FORCE_INLINE_ real_t tdotz(const Vector3& v) const {
return elements[0][2] * v[0] + elements[1][2] * v[1] + elements[2][2] * v[2];
}
-
+
bool operator==(const Matrix3& p_matrix) const;
bool operator!=(const Matrix3& p_matrix) const;
@@ -110,7 +110,7 @@ public:
_FORCE_INLINE_ 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) {
-
+
elements[0][0]=xx;
elements[0][1]=xy;
elements[0][2]=xz;
@@ -119,15 +119,15 @@ public:
elements[1][2]=yz;
elements[2][0]=zx;
elements[2][1]=zy;
- elements[2][2]=zz;
+ elements[2][2]=zz;
}
_FORCE_INLINE_ Vector3 get_column(int i) const {
-
+
return Vector3(elements[0][i],elements[1][i],elements[2][i]);
}
-
+
_FORCE_INLINE_ Vector3 get_row(int i) const {
-
+
return Vector3(elements[i][0],elements[i][1],elements[i][2]);
}
_FORCE_INLINE_ void set_row(int i, const Vector3& p_row) {
@@ -155,8 +155,8 @@ 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) {
-
+ 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) {
+
set(xx, xy, xz, yx, yy, yz, zx, zy, zz);
}
@@ -170,7 +170,7 @@ public:
Matrix3(const Vector3& p_axis, real_t p_phi);
_FORCE_INLINE_ Matrix3() {
-
+
elements[0][0]=1;
elements[0][1]=0;
elements[0][2]=0;
@@ -191,7 +191,7 @@ _FORCE_INLINE_ void Matrix3::operator*=(const Matrix3& p_matrix) {
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]));
-
+
}
_FORCE_INLINE_ Matrix3 Matrix3::operator*(const Matrix3& p_matrix) const {
diff --git a/core/math/octree.h b/core/math/octree.h
index 69edf80e09..6080b21680 100644
--- a/core/math/octree.h
+++ b/core/math/octree.h
@@ -52,11 +52,11 @@ public:
typedef void* (*PairCallback)(void*,OctreeElementID, T*,int,OctreeElementID, T*,int);
typedef void (*UnpairCallback)(void*,OctreeElementID, T*,int,OctreeElementID, T*,int,void*);
-private:
+private:
enum {
-
+
NEG=0,
- POS=1,
+ POS=1,
};
enum {
@@ -72,7 +72,7 @@ private:
struct PairKey {
-
+
union {
struct {
OctreeElementID A;
@@ -80,66 +80,66 @@ private:
};
uint64_t key;
};
-
+
_FORCE_INLINE_ bool operator<(const PairKey& p_pair) const {
-
+
return key<p_pair.key;
}
-
+
_FORCE_INLINE_ PairKey( OctreeElementID p_A, OctreeElementID p_B) {
-
+
if (p_A<p_B) {
-
+
A=p_A;
- B=p_B;
+ B=p_B;
} else {
-
+
B=p_A;
A=p_B;
}
}
-
+
_FORCE_INLINE_ PairKey() {}
- };
-
+ };
+
struct Element;
-
+
struct Octant {
-
+
// cached for FAST plane check
AABB aabb;
-
+
uint64_t last_pass;
Octant *parent;
Octant *children[8];
-
+
int children_count; // cache for amount of childrens (fast check for removal)
int parent_index; // cache for parent index (fast check for removal)
-
+
List<Element*,AL> pairable_elements;
List<Element*,AL> elements;
-
+
Octant() {
children_count=0;
parent_index=-1;
last_pass=0;
parent=NULL;
for (int i=0;i<8;i++)
- children[i]=NULL;
+ children[i]=NULL;
}
-
+
~Octant() {
-
+
//for (int i=0;i<8;i++)
// memdelete_notnull(children[i]);
}
};
-
+
struct PairData;
struct Element {
-
+
Octree *octree;
T *userdata;
@@ -147,28 +147,28 @@ private:
bool pairable;
uint32_t pairable_mask;
uint32_t pairable_type;
-
+
uint64_t last_pass;
OctreeElementID _id;
Octant *common_parent;
-
+
AABB aabb;
AABB container_aabb;
List<PairData*,AL> pair_list;
-
+
struct OctantOwner {
-
+
Octant *octant;
typename List<Element*,AL>::Element *E;
- }; // an element can be in max 8 octants
-
+ }; // an element can be in max 8 octants
+
List<OctantOwner,AL> octant_owners;
-
-
+
+
Element() { last_pass=0; _id=0; pairable=false; subindex=0; userdata=0; octree=0; pairable_mask=0; pairable_type=0; common_parent=NULL; }
};
-
+
struct PairData {
@@ -181,15 +181,15 @@ private:
typedef Map<OctreeElementID, Element, Comparator<OctreeElementID>, AL> ElementMap;
typedef Map<PairKey, PairData, Comparator<PairKey>, AL> PairMap;
- ElementMap element_map;
- PairMap pair_map;
+ ElementMap element_map;
+ PairMap pair_map;
PairCallback pair_callback;
UnpairCallback unpair_callback;
void *pair_callback_userdata;
void *unpair_callback_userdata;
-
- OctreeElementID last_element_id;
+
+ OctreeElementID last_element_id;
uint64_t pass;
real_t unit_size;
@@ -231,7 +231,7 @@ private:
if (p_A==p_B || (p_A->userdata==p_B->userdata && p_A->userdata))
return;
-
+
if ( !(p_A->pairable_type&p_B->pairable_mask) &&
!(p_B->pairable_type&p_A->pairable_mask) )
return; // none can pair with none
@@ -253,17 +253,17 @@ private:
// if (pair_callback)
// pair_callback(pair_callback_userdata,p_A->userdata,p_B->userdata);
} else {
-
+
E->get().refcount++;
}
-
+
}
-
+
_FORCE_INLINE_ void _pair_unreference(Element* p_A,Element* p_B) {
-
+
if (p_A==p_B)
return;
-
+
PairKey key(p_A->_id, p_B->_id);
typename PairMap::Element *E=pair_map.find(key);
if (!E) {
@@ -293,7 +293,7 @@ private:
p_B->pair_list.erase( E->get().eB );
pair_map.erase(E);
}
-
+
}
_FORCE_INLINE_ void _element_check_pairs(Element *p_element) {
@@ -341,7 +341,7 @@ private:
void _ensure_valid_root(const AABB& 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);
+ void _pair_element(Element *p_element,Octant *p_octant);
void _unpair_element(Element *p_element,Octant *p_octant);
@@ -361,16 +361,16 @@ private:
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);
void _remove_tree(Octant *p_octant) {
-
+
if (!p_octant)
return;
for(int i=0;i<8;i++) {
-
+
if (p_octant->children[i])
_remove_tree(p_octant->children[i]);
}
-
+
memdelete_allocator<Octant,AL>(p_octant);
}
public:
@@ -432,24 +432,24 @@ template<class T,bool use_pairs,class AL>
void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant) {
float element_size = p_element->aabb.get_longest_axis_size() * 1.01; // avoid precision issues
-
+
if (p_octant->aabb.size.x/OCTREE_DIVISOR < element_size) {
- //if (p_octant->aabb.size.x*0.5 < element_size) {
-
- /* at smallest possible size for the element */
+ //if (p_octant->aabb.size.x*0.5 < element_size) {
+
+ /* at smallest possible size for the element */
typename Element::OctantOwner owner;
owner.octant=p_octant;
-
+
if (use_pairs && p_element->pairable) {
-
+
p_octant->pairable_elements.push_back(p_element);
owner.E = p_octant->pairable_elements.back();
} else {
-
+
p_octant->elements.push_back(p_element);
owner.E = p_octant->elements.back();
}
-
+
p_element->octant_owners.push_back( owner );
if (p_element->common_parent==NULL) {
@@ -461,13 +461,13 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant
if (use_pairs && p_octant->children_count>0) {
-
+
pass++; //elements below this only get ONE reference added
for (int i=0;i<8;i++) {
-
+
if (p_octant->children[i]) {
- _pair_element(p_element,p_octant->children[i]);
+ _pair_element(p_element,p_octant->children[i]);
}
}
}
@@ -477,7 +477,7 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant
bool candidate=p_element->common_parent==NULL;
for (int i=0;i<8;i++) {
-
+
if (p_octant->children[i]) {
/* element exists, go straight to it */
if (p_octant->children[i]->aabb.intersects_inclusive( p_element->aabb ) ) {
@@ -486,20 +486,20 @@ 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;
aabb.size*=0.5;
-
+
if (i&1)
aabb.pos.x+=aabb.size.x;
if (i&2)
aabb.pos.y+=aabb.size.y;
if (i&4)
aabb.pos.z+=aabb.size.z;
-
+
if (aabb.intersects_inclusive( p_element->aabb) ) {
/* if actually intersects, create the child */
-
+
Octant *child = memnew_allocator( Octant, AL );
p_octant->children[i]=child;
child->parent=p_octant;
@@ -517,14 +517,14 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant
}
}
-
+
if (candidate && splits>1) {
p_element->common_parent=p_octant;
}
-
+
}
-
+
if (use_pairs) {
typename List<Element*,AL>::Element *E=p_octant->pairable_elements.front();
@@ -532,8 +532,8 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant
while(E) {
_pair_reference( p_element,E->get() );
E=E->next();
- }
-
+ }
+
if (p_element->pairable) {
// and always test non-pairable if element is pairable
E=p_octant->elements.front();
@@ -541,9 +541,9 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant
_pair_reference( p_element,E->get() );
E=E->next();
}
- }
+ }
}
-
+
}
@@ -553,35 +553,35 @@ void Octree<T,use_pairs,AL>::_ensure_valid_root(const AABB& p_aabb) {
if (!root) {
// octre is empty
-
+
AABB base( Vector3(), Vector3(1.0,1.0,1.0) * unit_size);
-
+
while ( !base.encloses(p_aabb) ) {
-
+
if ( ABS(base.pos.x+base.size.x) <= ABS(base.pos.x) ) {
/* grow towards positive */
base.size*=2.0;
} else {
- base.pos-=base.size;
+ base.pos-=base.size;
base.size*=2.0;
}
}
-
+
root = memnew_allocator( Octant, AL );
- root->parent=NULL;
- root->parent_index=-1;
+ root->parent=NULL;
+ root->parent_index=-1;
root->aabb=base;
-
+
octant_count++;
-
-
- } else {
-
+
+
+ } else {
+
AABB base=root->aabb;
-
+
while( !base.encloses( p_aabb ) ) {
-
+
if (base.size.x > OCTREE_SIZE_LIMIT) {
ERR_EXPLAIN("Octree upper size limit reeached, does the AABB supplied contain NAN?");
ERR_FAIL();
@@ -590,7 +590,7 @@ void Octree<T,use_pairs,AL>::_ensure_valid_root(const AABB& p_aabb) {
Octant * gp = memnew_allocator( Octant, AL );
octant_count++;
root->parent=gp;
-
+
if ( ABS(base.pos.x+base.size.x) <= ABS(base.pos.x) ) {
/* grow towards positive */
base.size*=2.0;
@@ -598,16 +598,16 @@ void Octree<T,use_pairs,AL>::_ensure_valid_root(const AABB& p_aabb) {
gp->children[0]=root;
root->parent_index=0;
} else {
- base.pos-=base.size;
+ base.pos-=base.size;
base.size*=2.0;
gp->aabb=base;
gp->children[(1<<0)|(1<<1)|(1<<2)]=root; // add at all-positive
root->parent_index=(1<<0)|(1<<1)|(1<<2);
}
-
+
gp->children_count=1;
- root=gp;
- }
+ root=gp;
+ }
}
}
@@ -615,16 +615,16 @@ template<class T,bool use_pairs,class AL>
bool Octree<T,use_pairs,AL>::_remove_element_from_octant(Element *p_element,Octant *p_octant,Octant *p_limit) {
bool octant_removed=false;
-
+
while(true) {
-
+
// check all exit conditions
-
+
if (p_octant==p_limit) // reached limit, nothing to erase, exit
return octant_removed;
-
+
bool unpaired=false;
-
+
if (use_pairs && p_octant->last_pass!=pass) {
// check wether we should unpair stuff
// always test pairable
@@ -644,21 +644,21 @@ bool Octree<T,use_pairs,AL>::_remove_element_from_octant(Element *p_element,Octa
p_octant->last_pass=pass;
unpaired=true;
}
-
+
bool removed=false;
-
+
Octant *parent=p_octant->parent;
-
+
if (p_octant->children_count==0 && p_octant->elements.empty() && p_octant->pairable_elements.empty()) {
-
+
// erase octant
-
+
if (p_octant==root) { // won't have a parent, just erase
-
+
root=NULL;
} else {
ERR_FAIL_INDEX_V(p_octant->parent_index,8,octant_removed);
-
+
parent->children[ p_octant->parent_index ]=NULL;
parent->children_count--;
}
@@ -668,12 +668,12 @@ bool Octree<T,use_pairs,AL>::_remove_element_from_octant(Element *p_element,Octa
removed=true;
octant_removed=true;
}
-
+
if (!removed && !unpaired)
return octant_removed; // no reason to keep going up anymore! was already visited and was not removed
-
+
p_octant=parent;
-
+
}
return octant_removed;
@@ -682,8 +682,8 @@ bool Octree<T,use_pairs,AL>::_remove_element_from_octant(Element *p_element,Octa
template<class T,bool use_pairs,class AL>
void Octree<T,use_pairs,AL>::_unpair_element(Element *p_element,Octant *p_octant) {
-
- // always test pairable
+
+ // always test pairable
typename List<Element*,AL>::Element *E=p_octant->pairable_elements.front();
while(E) {
if (E->get()->last_pass!=pass) { // only remove ONE reference
@@ -692,7 +692,7 @@ void Octree<T,use_pairs,AL>::_unpair_element(Element *p_element,Octant *p_octant
}
E=E->next();
}
-
+
if (p_element->pairable) {
// and always test non-pairable if element is pairable
E=p_octant->elements.front();
@@ -704,14 +704,14 @@ void Octree<T,use_pairs,AL>::_unpair_element(Element *p_element,Octant *p_octant
E=E->next();
}
}
-
+
p_octant->last_pass=pass;
-
+
if (p_octant->children_count==0)
return; // small optimization for leafs
-
+
for (int i=0;i<8;i++) {
-
+
if (p_octant->children[i])
_unpair_element(p_element,p_octant->children[i]);
}
@@ -732,7 +732,7 @@ void Octree<T,use_pairs,AL>::_pair_element(Element *p_element,Octant *p_octant)
}
E=E->next();
}
-
+
if (p_element->pairable) {
// and always test non-pairable if element is pairable
E=p_octant->elements.front();
@@ -745,12 +745,12 @@ void Octree<T,use_pairs,AL>::_pair_element(Element *p_element,Octant *p_octant)
}
}
p_octant->last_pass=pass;
-
+
if (p_octant->children_count==0)
return; // small optimization for leafs
-
+
for (int i=0;i<8;i++) {
-
+
if (p_octant->children[i])
_pair_element(p_element,p_octant->children[i]);
}
@@ -760,13 +760,13 @@ template<class T,bool use_pairs,class AL>
void Octree<T,use_pairs,AL>::_remove_element(Element *p_element) {
pass++; // will do a new pass for this
-
+
typename List< typename Element::OctantOwner,AL >::Element *I=p_element->octant_owners.front();
-
+
/* FIRST remove going up normally */
for(;I;I=I->next()) {
-
+
Octant *o=I->get().octant;
if (!use_pairs) // small speedup
@@ -809,14 +809,14 @@ void Octree<T,use_pairs,AL>::_remove_element(Element *p_element) {
int remaining=p_element->pair_list.size();
//p_element->pair_list.clear();
ERR_FAIL_COND( remaining );
- }
+ }
}
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) {
- // check for AABB validity
+ // check for AABB validity
#ifdef DEBUG_ENABLED
ERR_FAIL_COND_V( p_aabb.pos.x > 1e15 || p_aabb.pos.x < -1e15, 0 );
ERR_FAIL_COND_V( p_aabb.pos.y > 1e15 || p_aabb.pos.y < -1e15, 0 );
@@ -828,12 +828,12 @@ OctreeElementID Octree<T,use_pairs,AL>::create(T* p_userdata, const AABB& p_aabb
ERR_FAIL_COND_V( Math::is_nan(p_aabb.size.y) , 0 );
ERR_FAIL_COND_V( Math::is_nan(p_aabb.size.z) , 0 );
-
+
#endif
typename ElementMap::Element *E = element_map.insert(last_element_id++,
Element());
Element &e = E->get();
-
+
e.aabb=p_aabb;
e.userdata=p_userdata;
e.subindex=p_subindex;
@@ -843,7 +843,7 @@ OctreeElementID Octree<T,use_pairs,AL>::create(T* p_userdata, const AABB& p_aabb
e.pairable_type=p_pairable_type;
e.pairable_mask=p_pairable_mask;
e._id=last_element_id-1;
-
+
if (!e.aabb.has_no_surface()) {
_ensure_valid_root(p_aabb);
_insert_element(&e,root);
@@ -964,7 +964,7 @@ void Octree<T,use_pairs,AL>::move(OctreeElementID p_id, const AABB& p_aabb) {
_insert_element(&e,common_parent); // reinsert from this point
pass++;
-
+
for(typename List<typename Element::OctantOwner,AL>::Element *E=owners.front();E;) {
Octant *o=E->get().octant;
@@ -1018,28 +1018,28 @@ void Octree<T,use_pairs,AL>::set_pairable(OctreeElementID p_id,bool p_pairable,u
typename ElementMap::Element *E = element_map.find(p_id);
ERR_FAIL_COND(!E);
-
+
Element &e = E->get();
if (p_pairable == e.pairable && e.pairable_type==p_pairable_type && e.pairable_mask==p_pairable_mask)
return; // no changes, return
-
+
if (!e.aabb.has_no_surface()) {
_remove_element(&e);
}
-
+
e.pairable=p_pairable;
e.pairable_type=p_pairable_type;
e.pairable_mask=p_pairable_mask;
e.common_parent=NULL;
-
+
if (!e.aabb.has_no_surface()) {
_ensure_valid_root(e.aabb);
_insert_element(&e,root);
if (use_pairs)
_element_check_pairs(&e);
- }
+ }
}
@@ -1048,155 +1048,155 @@ void Octree<T,use_pairs,AL>::erase(OctreeElementID p_id) {
typename ElementMap::Element *E = element_map.find(p_id);
ERR_FAIL_COND(!E);
-
+
Element &e = E->get();
if (!e.aabb.has_no_surface()) {
-
- _remove_element(&e);
+
+ _remove_element(&e);
}
-
+
element_map.erase(p_id);
_optimize();
}
template<class T,bool use_pairs,class AL>
void Octree<T,use_pairs,AL>::_cull_convex(Octant *p_octant,_CullConvexData *p_cull) {
-
+
if (*p_cull->result_idx==p_cull->result_max)
return; //pointless
-
+
if (!p_octant->elements.empty()) {
-
+
typename List< Element*,AL >::Element *I;
I=p_octant->elements.front();
-
+
for(;I;I=I->next()) {
-
+
Element *e=I->get();
-
+
if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_cull->mask)))
continue;
e->last_pass=pass;
-
+
if (e->aabb.intersects_convex_shape(p_cull->planes,p_cull->plane_count)) {
-
+
if (*p_cull->result_idx<p_cull->result_max) {
p_cull->result_array[*p_cull->result_idx] = e->userdata;
(*p_cull->result_idx)++;
} else {
-
+
return; // pointless to continue
}
}
}
}
-
+
if (use_pairs && !p_octant->pairable_elements.empty()) {
-
+
typename List< Element*,AL >::Element *I;
I=p_octant->pairable_elements.front();
-
+
for(;I;I=I->next()) {
-
+
Element *e=I->get();
-
+
if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_cull->mask)))
continue;
e->last_pass=pass;
-
+
if (e->aabb.intersects_convex_shape(p_cull->planes,p_cull->plane_count)) {
-
+
if (*p_cull->result_idx<p_cull->result_max) {
p_cull->result_array[*p_cull->result_idx] = e->userdata;
(*p_cull->result_idx)++;
} else {
-
+
return; // pointless to continue
}
}
}
}
-
+
for (int i=0;i<8;i++) {
-
+
if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_convex_shape(p_cull->planes,p_cull->plane_count)) {
_cull_convex(p_octant->children[i],p_cull);
}
- }
+ }
}
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) {
-
+
if (*p_result_idx==p_result_max)
return; //pointless
-
+
if (!p_octant->elements.empty()) {
-
+
typename List< Element*,AL >::Element *I;
I=p_octant->elements.front();
for(;I;I=I->next()) {
-
+
Element *e=I->get();
-
+
if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_mask)))
continue;
e->last_pass=pass;
-
+
if (p_aabb.intersects_inclusive(e->aabb)) {
-
+
if (*p_result_idx<p_result_max) {
-
+
p_result_array[*p_result_idx] = e->userdata;
if (p_subindex_array)
p_subindex_array[*p_result_idx] = e->subindex;
(*p_result_idx)++;
} else {
-
+
return; // pointless to continue
}
}
}
}
-
+
if (use_pairs && !p_octant->pairable_elements.empty()) {
-
+
typename List< Element*,AL >::Element *I;
I=p_octant->pairable_elements.front();
for(;I;I=I->next()) {
-
+
Element *e=I->get();
-
+
if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_mask)))
continue;
e->last_pass=pass;
-
+
if (p_aabb.intersects_inclusive(e->aabb)) {
-
+
if (*p_result_idx<p_result_max) {
-
+
p_result_array[*p_result_idx] = e->userdata;
if (p_subindex_array)
p_subindex_array[*p_result_idx] = e->subindex;
(*p_result_idx)++;
} else {
-
+
return; // pointless to continue
}
}
}
- }
+ }
for (int i=0;i<8;i++) {
-
+
if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_inclusive(p_aabb)) {
_cull_AABB(p_octant->children[i],p_aabb, p_result_array,p_result_idx,p_result_max,p_subindex_array,p_mask);
}
- }
+ }
}
@@ -1205,53 +1205,53 @@ void Octree<T,use_pairs,AL>::_cull_segment(Octant *p_octant,const Vector3& p_fro
if (*p_result_idx==p_result_max)
return; //pointless
-
+
if (!p_octant->elements.empty()) {
-
+
typename List< Element*,AL >::Element *I;
I=p_octant->elements.front();
for(;I;I=I->next()) {
-
+
Element *e=I->get();
-
+
if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_mask)))
continue;
e->last_pass=pass;
-
+
if (e->aabb.intersects_segment(p_from,p_to)) {
-
+
if (*p_result_idx<p_result_max) {
-
+
p_result_array[*p_result_idx] = e->userdata;
if (p_subindex_array)
p_subindex_array[*p_result_idx] = e->subindex;
(*p_result_idx)++;
} else {
-
+
return; // pointless to continue
}
}
}
}
-
+
if (use_pairs && !p_octant->pairable_elements.empty()) {
-
+
typename List< Element*,AL >::Element *I;
I=p_octant->pairable_elements.front();
for(;I;I=I->next()) {
-
+
Element *e=I->get();
-
+
if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_mask)))
continue;
-
+
e->last_pass=pass;
-
+
if (e->aabb.intersects_segment(p_from,p_to)) {
-
+
if (*p_result_idx<p_result_max) {
-
+
p_result_array[*p_result_idx] = e->userdata;
if (p_subindex_array)
p_subindex_array[*p_result_idx] = e->subindex;
@@ -1259,20 +1259,20 @@ void Octree<T,use_pairs,AL>::_cull_segment(Octant *p_octant,const Vector3& p_fro
(*p_result_idx)++;
} else {
-
+
return; // pointless to continue
}
}
}
}
-
+
for (int i=0;i<8;i++) {
-
+
if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_segment(p_from,p_to)) {
_cull_segment(p_octant->children[i],p_from,p_to, p_result_array,p_result_idx,p_result_max,p_subindex_array,p_mask);
}
- }
+ }
}
@@ -1357,7 +1357,7 @@ int Octree<T,use_pairs,AL>::cull_convex(const Vector<Plane>& p_convex,T** p_resu
if (!root)
return 0;
-
+
int result_count=0;
pass++;
_CullConvexData cdata;
@@ -1367,9 +1367,9 @@ int Octree<T,use_pairs,AL>::cull_convex(const Vector<Plane>& p_convex,T** p_resu
cdata.result_max=p_result_max;
cdata.result_idx=&result_count;
cdata.mask=p_mask;
-
+
_cull_convex(root,&cdata);
-
+
return result_count;
}
@@ -1381,11 +1381,11 @@ int Octree<T,use_pairs,AL>::cull_AABB(const AABB& p_aabb,T** p_result_array,int
if (!root)
return 0;
-
+
int result_count=0;
pass++;
_cull_AABB(root,p_aabb,p_result_array,&result_count,p_result_max,p_subindex_array,p_mask);
-
+
return result_count;
}
@@ -1395,11 +1395,11 @@ int Octree<T,use_pairs,AL>::cull_segment(const Vector3& p_from, const Vector3& p
if (!root)
return 0;
-
+
int result_count=0;
pass++;
_cull_segment(root,p_from,p_to,p_result_array,&result_count,p_result_max,p_subindex_array,p_mask);
-
+
return result_count;
}
@@ -1436,7 +1436,7 @@ void Octree<T,use_pairs,AL>::set_unpair_callback( UnpairCallback p_callback, voi
template<class T,bool use_pairs,class AL>
Octree<T,use_pairs,AL>::Octree(real_t p_unit_size) {
-
+
last_element_id=1;
pass=1;
unit_size=p_unit_size;
diff --git a/core/math/plane.cpp b/core/math/plane.cpp
index d17ce01bec..b29350fe3c 100644
--- a/core/math/plane.cpp
+++ b/core/math/plane.cpp
@@ -50,7 +50,7 @@ void Plane::normalize() {
}
Plane Plane::normalized() const {
-
+
Plane p = *this;
p.normalize();
return p;
@@ -66,12 +66,12 @@ Vector3 Plane::get_any_perpendicular_normal() const {
static const Vector3 p1 = Vector3(1,0,0);
static const Vector3 p2 = Vector3(0,1,0);
Vector3 p;
-
+
if (ABS(normal.dot(p1)) > 0.99) // if too similar to p1
p=p2; // use p2
else
p=p1; // use p1
-
+
p-=normal * normal.dot(p);
p.normalize();
diff --git a/core/math/plane.h b/core/math/plane.h
index d20e63dc47..81a968682e 100644
--- a/core/math/plane.h
+++ b/core/math/plane.h
@@ -62,9 +62,9 @@ public:
bool intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3* p_intersection) const;
_FORCE_INLINE_ Vector3 project(const Vector3& p_point) const {
-
+
return p_point - normal * distance_to(p_point);
- }
+ }
/* misc */
diff --git a/core/math/quat.cpp b/core/math/quat.cpp
index ebc5ec4e65..c6c12129b3 100644
--- a/core/math/quat.cpp
+++ b/core/math/quat.cpp
@@ -30,9 +30,9 @@
#include "print_string.h"
void Quat::set_euler(const Vector3& p_euler) {
- real_t half_yaw = p_euler.x * 0.5;
- real_t half_pitch = p_euler.y * 0.5;
- real_t half_roll = p_euler.z * 0.5;
+ real_t half_yaw = p_euler.x * 0.5;
+ real_t half_pitch = p_euler.y * 0.5;
+ real_t half_roll = p_euler.z * 0.5;
real_t cos_yaw = Math::cos(half_yaw);
real_t sin_yaw = Math::sin(half_yaw);
real_t cos_pitch = Math::cos(half_pitch);
@@ -75,7 +75,7 @@ void Quat::normalize() {
Quat Quat::normalized() const {
return *this / length();
-}
+}
Quat Quat::inverse() const {
return Quat( -x, -y, -z, w );
@@ -252,7 +252,7 @@ Quat Quat::cubic_slerp(const Quat& q, const Quat& prep, const Quat& postq,const
Quat::operator String() const {
- return String::num(x)+","+String::num(y)+","+ String::num(z)+","+ String::num(w);
+ return String::num(x)+","+String::num(y)+","+ String::num(z)+","+ String::num(w);
}
Quat::Quat(const Vector3& axis, const real_t& angle) {
@@ -261,7 +261,7 @@ Quat::Quat(const Vector3& axis, const real_t& angle) {
set(0,0,0,0);
else {
real_t s = Math::sin(-angle * 0.5) / d;
- set(axis.x * s, axis.y * s, axis.z * s,
+ set(axis.x * s, axis.y * s, axis.z * s,
Math::cos(-angle * 0.5));
}
}
diff --git a/core/math/quat.h b/core/math/quat.h
index 738b6946c7..0d206bb3b7 100644
--- a/core/math/quat.h
+++ b/core/math/quat.h
@@ -89,18 +89,18 @@ public:
_FORCE_INLINE_ Quat operator-() const;
_FORCE_INLINE_ Quat operator*(const real_t& s) const;
_FORCE_INLINE_ Quat operator/(const real_t& s) const;
-
+
_FORCE_INLINE_ bool operator==(const Quat& p_quat) const;
_FORCE_INLINE_ bool operator!=(const Quat& p_quat) const;
-
+
operator String() const;
-
+
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) {
- 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);
@@ -127,7 +127,7 @@ public:
}
inline Quat() {x=y=z=0; w=1; }
-
+
};
@@ -141,7 +141,7 @@ real_t Quat::length_squared() const {
}
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) {
diff --git a/core/math/transform.cpp b/core/math/transform.cpp
index 8371f7e34b..22eb6c4fdd 100644
--- a/core/math/transform.cpp
+++ b/core/math/transform.cpp
@@ -30,7 +30,7 @@
#include "math_funcs.h"
#include "os/copymem.h"
#include "print_string.h"
-
+
void Transform::affine_invert() {
@@ -50,7 +50,7 @@ Transform Transform::affine_inverse() const {
void Transform::invert() {
basis.transpose();
- origin = basis.xform(-origin);
+ origin = basis.xform(-origin);
}
Transform Transform::inverse() const {
@@ -87,30 +87,30 @@ void Transform::set_look_at( const Vector3& p_eye, const Vector3& p_target, cons
// Reference: MESA source code
Vector3 v_x, v_y, v_z;
-
+
/* Make rotation matrix */
-
+
/* Z vector */
v_z = p_eye - p_target;
-
+
v_z.normalize();
-
+
v_y = p_up;
-
+
v_x=v_y.cross(v_z);
-
+
/* Recompute Y = Z cross X */
v_y=v_z.cross(v_x);
-
+
v_x.normalize();
v_y.normalize();
-
+
basis.set_axis(0,v_x);
basis.set_axis(1,v_y);
basis.set_axis(2,v_z);
origin=p_eye;
-
+
}
Transform Transform::interpolate_with(const Transform& p_transform, float p_c) const {
@@ -193,7 +193,7 @@ bool Transform::operator!=(const Transform& p_transform) const {
void Transform::operator*=(const Transform& p_transform) {
origin=xform(p_transform.origin);
- basis*=p_transform.basis;
+ basis*=p_transform.basis;
}
Transform Transform::operator*(const Transform& p_transform) const {
diff --git a/core/math/transform.h b/core/math/transform.h
index bd1247084d..f948a4c919 100644
--- a/core/math/transform.h
+++ b/core/math/transform.h
@@ -40,9 +40,9 @@ public:
Matrix3 basis;
Vector3 origin;
-
- void invert();
- Transform inverse() const;
+
+ void invert();
+ Transform inverse() const;
void affine_invert();
Transform affine_inverse() const;
@@ -76,27 +76,27 @@ public:
_FORCE_INLINE_ Vector3 xform(const Vector3& p_vector) const;
_FORCE_INLINE_ Vector3 xform_inv(const Vector3& p_vector) const;
-
+
_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;
-
+
void operator*=(const Transform& p_transform);
Transform operator*(const Transform& p_transform) const;
Transform interpolate_with(const Transform& p_transform, float p_c) const;
-
+
_FORCE_INLINE_ Transform inverse_xform(const Transform& t) const {
-
+
Vector3 v = t.origin - origin;
return Transform(basis.transpose_xform(t.basis),
basis.xform(v));
}
-
+
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) {
-
+
basis.elements[0][0]=xx;
basis.elements[0][1]=xy;
basis.elements[0][2]=xz;
@@ -105,14 +105,14 @@ public:
basis.elements[1][2]=yz;
basis.elements[2][0]=zx;
basis.elements[2][1]=zy;
- basis.elements[2][2]=zz;
+ basis.elements[2][2]=zz;
origin.x=tx;
origin.y=ty;
origin.z=tz;
}
-
+
operator String() const;
-
+
Transform(const Matrix3& p_basis, const Vector3& p_origin=Vector3());
Transform() {}
@@ -128,9 +128,9 @@ _FORCE_INLINE_ Vector3 Transform::xform(const Vector3& p_vector) const {
);
}
_FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3& p_vector) const {
-
+
Vector3 v = p_vector - origin;
-
+
return Vector3(
(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 ),
@@ -140,16 +140,16 @@ _FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3& p_vector) const {
_FORCE_INLINE_ 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 normal=point_dir-point;
normal.normalize();
real_t d=normal.dot(point);
-
+
return Plane(normal,d);
}
@@ -159,11 +159,11 @@ _FORCE_INLINE_ Plane Transform::xform_inv(const Plane& p_plane) const {
Vector3 point_dir=point+p_plane.normal;
xform_inv(point);
xform_inv(point_dir);
-
+
Vector3 normal=point_dir-point;
normal.normalize();
real_t d=normal.dot(point);
-
+
return Plane(normal,d);
}
@@ -199,17 +199,17 @@ _FORCE_INLINE_ AABB Transform::xform(const AABB& p_aabb) const {
Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z+p_aabb.size.z),
Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z)
};
-
-
+
+
AABB ret;
-
+
ret.pos=xform(vertices[0]);
-
+
for (int i=1;i<8;i++) {
-
+
ret.expand_to( xform(vertices[i]) );
}
-
+
return ret;
#endif
@@ -227,17 +227,17 @@ _FORCE_INLINE_ AABB Transform::xform_inv(const AABB& p_aabb) const {
Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z+p_aabb.size.z),
Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z)
};
-
-
+
+
AABB ret;
-
+
ret.pos=xform_inv(vertices[0]);
-
+
for (int i=1;i<8;i++) {
-
+
ret.expand_to( xform_inv(vertices[i]) );
}
-
+
return ret;
}