Merge pull request #7528 from tagcup/real_t_float_fixes

Use real_t rather than float or double in generic functions (core/mat…
This commit is contained in:
Juan Linietsky 2017-01-20 19:24:49 -03:00 committed by GitHub
commit ee0f53df52
50 changed files with 543 additions and 615 deletions

View file

@ -39,7 +39,7 @@ int AStar::get_available_point_id() const {
return points.back()->key()+1;
}
void AStar::add_point(int p_id, const Vector3 &p_pos, float p_weight_scale) {
void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) {
ERR_FAIL_COND(p_id<0);
if (!points.has(p_id)) {
Point *pt = memnew( Point );
@ -62,7 +62,7 @@ Vector3 AStar::get_point_pos(int p_id) const{
return points[p_id]->pos;
}
float AStar::get_point_weight_scale(int p_id) const{
real_t AStar::get_point_weight_scale(int p_id) const{
ERR_FAIL_COND_V(!points.has(p_id),0);
@ -145,11 +145,11 @@ void AStar::clear(){
int AStar::get_closest_point(const Vector3& p_point) const{
int closest_id=-1;
float closest_dist=1e20;
real_t closest_dist=1e20;
for (const Map<int,Point*>::Element *E=points.front();E;E=E->next()) {
float d = p_point.distance_squared_to(E->get()->pos);
real_t d = p_point.distance_squared_to(E->get()->pos);
if (closest_id<0 || d<closest_dist) {
closest_dist=d;
closest_id=E->key();
@ -162,7 +162,7 @@ int AStar::get_closest_point(const Vector3& p_point) const{
}
Vector3 AStar::get_closest_pos_in_segment(const Vector3& p_point) const {
float closest_dist = 1e20;
real_t closest_dist = 1e20;
bool found=false;
Vector3 closest_point;
@ -175,7 +175,7 @@ Vector3 AStar::get_closest_pos_in_segment(const Vector3& p_point) const {
};
Vector3 p = Geometry::get_closest_point_to_segment(p_point,segment);
float d = p_point.distance_squared_to(p);
real_t d = p_point.distance_squared_to(p);
if (!found || d<closest_dist) {
closest_point=p;
@ -220,14 +220,14 @@ bool AStar::_solve(Point* begin_point, Point* end_point) {
//check open list
SelfList<Point> *least_cost_point=NULL;
float least_cost=1e30;
real_t least_cost=1e30;
//this could be faster (cache previous results)
for (SelfList<Point> *E=open_list.first();E;E=E->next()) {
Point *p=E->self();
float cost=p->distance;
real_t cost=p->distance;
cost+=p->pos.distance_to(end_point->pos);
cost*=p->weight_scale;
@ -249,7 +249,7 @@ bool AStar::_solve(Point* begin_point, Point* end_point) {
Point* e=p->neighbours[i];
float distance = p->pos.distance_to(e->pos) + p->distance;
real_t distance = p->pos.distance_to(e->pos) + p->distance;
distance*=e->weight_scale;

View file

@ -48,14 +48,14 @@ class AStar: public Reference {
int id;
Vector3 pos;
float weight_scale;
real_t weight_scale;
uint64_t last_pass;
Vector<Point*> neighbours;
//used for pathfinding
Point *prev_point;
float distance;
real_t distance;
Point() : list(this) {}
};
@ -98,9 +98,9 @@ public:
int get_available_point_id() const;
void add_point(int p_id,const Vector3& p_pos,float p_weight_scale=1);
void add_point(int p_id,const Vector3& p_pos,real_t p_weight_scale=1);
Vector3 get_point_pos(int p_id) const;
float get_point_weight_scale(int p_id) const;
real_t get_point_weight_scale(int p_id) const;
void remove_point(int p_id);
void connect_points(int p_id,int p_with_id);

View file

@ -87,8 +87,8 @@ int BSP_Tree::_get_points_inside(int p_node,const Vector3* p_points,int *p_indic
max+=p_center;
min+=p_center;
float dist_min = p.distance_to(min);
float dist_max = p.distance_to(max);
real_t dist_min = p.distance_to(min);
real_t dist_max = p.distance_to(max);
if ((dist_min * dist_max) < CMP_EPSILON ) { //intersection, test point by point
@ -290,13 +290,13 @@ bool BSP_Tree::point_is_inside(const Vector3& p_point) const {
}
static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_indices,float p_tolerance) {
static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_indices,real_t p_tolerance) {
int ic = p_indices.size();
const int*indices=p_indices.ptr();
int best_plane = -1;
float best_plane_cost = 1e20;
real_t best_plane_cost = 1e20;
// Loop to find the polygon that best divides the set.
@ -317,7 +317,7 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i
for(int k=0;k<3;k++) {
float d = p.distance_to(g.vertex[j]);
real_t d = p.distance_to(g.vertex[j]);
if (Math::abs(d)>p_tolerance) {
@ -340,13 +340,13 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i
//double split_cost = num_spanning / (double) face_count;
double relation = Math::abs(num_over-num_under) / (double) ic;
//real_t split_cost = num_spanning / (real_t) face_count;
real_t relation = Math::abs(num_over-num_under) / (real_t) 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;
real_t 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);
if (plane_cost<best_plane_cost) {
@ -362,7 +362,7 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i
}
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) {
static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Vector<Plane> &p_planes, Vector<BSP_Tree::Node> &p_nodes,real_t p_tolerance) {
ERR_FAIL_COND_V( p_nodes.size() == BSP_Tree::MAX_NODES, -1 );
@ -400,7 +400,7 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve
for(int j=0;j<3;j++) {
float d = divisor_plane.distance_to(f.vertex[j]);
real_t d = divisor_plane.distance_to(f.vertex[j]);
if (Math::abs(d)>p_tolerance) {
if (d > 0)
@ -473,7 +473,7 @@ BSP_Tree::operator Variant() const {
Dictionary d;
d["error_radius"]=error_radius;
Vector<float> plane_values;
Vector<real_t> plane_values;
plane_values.resize(planes.size()*4);
for(int i=0;i<planes.size();i++) {
@ -522,13 +522,13 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) {
if (d["planes"].get_type()==Variant::POOL_REAL_ARRAY) {
PoolVector<float> src_planes=d["planes"];
PoolVector<real_t> src_planes=d["planes"];
int plane_count=src_planes.size();
ERR_FAIL_COND(plane_count%4);
planes.resize(plane_count/4);
if (plane_count) {
PoolVector<float>::Read r = src_planes.read();
PoolVector<real_t>::Read r = src_planes.read();
for(int i=0;i<plane_count/4;i++) {
planes[i].normal.x=r[i*4+0];
@ -562,7 +562,7 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) {
}
BSP_Tree::BSP_Tree(const PoolVector<Face3>& p_faces,float p_error_radius) {
BSP_Tree::BSP_Tree(const PoolVector<Face3>& p_faces,real_t p_error_radius) {
// compute aabb
@ -615,7 +615,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 Rect3& p_aabb,float p_error_radius) {
BSP_Tree::BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,real_t p_error_radius) {
nodes=p_nodes;
planes=p_planes;

View file

@ -66,7 +66,7 @@ private:
Vector<Node> nodes;
Vector<Plane> planes;
Rect3 aabb;
float error_radius;
real_t 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;
@ -91,8 +91,8 @@ public:
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 Rect3& p_aabb,float p_error_radius=0);
BSP_Tree(const PoolVector<Face3>& p_faces,real_t p_error_radius=0);
BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const Rect3& p_aabb,real_t p_error_radius=0);
~BSP_Tree();
};
@ -110,7 +110,7 @@ bool BSP_Tree::_test_convex(const Node* p_nodes, const Plane* p_planes,int p_cur
const Plane& p=p_planes[n.plane];
float min,max;
real_t min,max;
p_convex.project_range(p.normal,min,max);
bool go_under = min < p.d;

View file

@ -65,15 +65,15 @@ Plane CameraMatrix::xform4(const Plane& p_vec4) const {
return ret;
}
void CameraMatrix::set_perspective(float p_fovy_degrees, float p_aspect, float p_z_near, float p_z_far,bool p_flip_fov) {
void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far,bool p_flip_fov) {
if (p_flip_fov) {
p_fovy_degrees=get_fovy(p_fovy_degrees,1.0/p_aspect);
}
float sine, cotangent, deltaZ;
float radians = p_fovy_degrees / 2.0 * Math_PI / 180.0;
real_t sine, cotangent, deltaZ;
real_t radians = p_fovy_degrees / 2.0 * Math_PI / 180.0;
deltaZ = p_z_far - p_z_near;
sine = Math::sin(radians);
@ -94,7 +94,7 @@ void CameraMatrix::set_perspective(float p_fovy_degrees, float p_aspect, float p
}
void CameraMatrix::set_orthogonal(float p_left, float p_right, float p_bottom, float p_top, float p_znear, float p_zfar) {
void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) {
set_identity();
@ -109,7 +109,7 @@ void CameraMatrix::set_orthogonal(float p_left, float p_right, float p_bottom, f
}
void CameraMatrix::set_orthogonal(float p_size, float p_aspect, float p_znear, float p_zfar,bool p_flip_fov) {
void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar,bool p_flip_fov) {
if (!p_flip_fov) {
p_size*=p_aspect;
@ -120,7 +120,7 @@ void CameraMatrix::set_orthogonal(float p_size, float p_aspect, float p_znear, f
void CameraMatrix::set_frustum(float p_left, float p_right, float p_bottom, float p_top, float p_near, float p_far) {
void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) {
#if 0
///@TODO, give a check to this. I'm not sure if it's working.
set_identity();
@ -134,14 +134,14 @@ void CameraMatrix::set_frustum(float p_left, float p_right, float p_bottom, floa
matrix[3][2]=-1;
matrix[3][3]=0;
#else
float *te = &matrix[0][0];
float x = 2 * p_near / ( p_right - p_left );
float y = 2 * p_near / ( p_top - p_bottom );
real_t *te = &matrix[0][0];
real_t x = 2 * p_near / ( p_right - p_left );
real_t y = 2 * p_near / ( p_top - p_bottom );
float a = ( p_right + p_left ) / ( p_right - p_left );
float b = ( p_top + p_bottom ) / ( p_top - p_bottom );
float c = - ( p_far + p_near ) / ( p_far - p_near );
float d = - 2 * p_far * p_near / ( p_far - p_near );
real_t a = ( p_right + p_left ) / ( p_right - p_left );
real_t b = ( p_top + p_bottom ) / ( p_top - p_bottom );
real_t c = - ( p_far + p_near ) / ( p_far - p_near );
real_t d = - 2 * p_far * p_near / ( p_far - p_near );
te[0] = x;
te[1] = 0;
@ -166,9 +166,9 @@ void CameraMatrix::set_frustum(float p_left, float p_right, float p_bottom, floa
float CameraMatrix::get_z_far() const {
real_t CameraMatrix::get_z_far() const {
const float * matrix = (const float*)this->matrix;
const real_t * matrix = (const real_t*)this->matrix;
Plane new_plane=Plane(matrix[ 3] - matrix[ 2],
matrix[ 7] - matrix[ 6],
matrix[11] - matrix[10],
@ -179,9 +179,9 @@ float CameraMatrix::get_z_far() const {
return new_plane.d;
}
float CameraMatrix::get_z_near() const {
real_t CameraMatrix::get_z_near() const {
const float * matrix = (const float*)this->matrix;
const real_t * matrix = (const real_t*)this->matrix;
Plane new_plane=Plane(matrix[ 3] + matrix[ 2],
matrix[ 7] + matrix[ 6],
matrix[11] + matrix[10],
@ -191,9 +191,9 @@ float CameraMatrix::get_z_near() const {
return new_plane.d;
}
void CameraMatrix::get_viewport_size(float& r_width, float& r_height) const {
void CameraMatrix::get_viewport_size(real_t& r_width, real_t& r_height) const {
const float * matrix = (const float*)this->matrix;
const real_t * matrix = (const real_t*)this->matrix;
///////--- Near Plane ---///////
Plane near_plane=Plane(matrix[ 3] + matrix[ 2],
matrix[ 7] + matrix[ 6],
@ -223,7 +223,7 @@ void CameraMatrix::get_viewport_size(float& r_width, float& r_height) const {
bool CameraMatrix::get_endpoints(const Transform& p_transform, Vector3 *p_8points) const {
const float * matrix = (const float*)this->matrix;
const real_t * matrix = (const real_t*)this->matrix;
///////--- Near Plane ---///////
Plane near_plane=Plane(matrix[ 3] + matrix[ 2],
@ -284,7 +284,7 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform)
Vector<Plane> planes;
const float * matrix = (const float*)this->matrix;
const real_t * matrix = (const real_t*)this->matrix;
Plane new_plane;
@ -377,9 +377,9 @@ 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 */
float hold; /* Temporary storage */
float determinat; /* Determinant */
real_t pvt_val; /* Value of current pivot element */
real_t hold; /* Temporary storage */
real_t determinat; /* Determinant */
determinat = 1.0;
for (k=0; k<4; k++) {
@ -492,7 +492,7 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix& p_matrix) const {
void CameraMatrix::set_light_bias() {
float *m=&matrix[0][0];
real_t *m=&matrix[0][0];
m[0]=0.5,
m[1]=0.0,
@ -515,7 +515,7 @@ void CameraMatrix::set_light_bias() {
void CameraMatrix::set_light_atlas_rect(const Rect2& p_rect) {
float *m=&matrix[0][0];
real_t *m=&matrix[0][0];
m[0]=p_rect.size.width,
m[1]=0.0,
@ -545,9 +545,9 @@ CameraMatrix::operator String() const {
return str;
}
float CameraMatrix::get_aspect() const {
real_t CameraMatrix::get_aspect() const {
float w,h;
real_t w,h;
get_viewport_size(w,h);
return w/h;
}
@ -561,8 +561,8 @@ int CameraMatrix::get_pixels_per_meter(int p_for_pixel_width) const {
}
float CameraMatrix::get_fov() const {
const float * matrix = (const float*)this->matrix;
real_t CameraMatrix::get_fov() const {
const real_t * matrix = (const real_t*)this->matrix;
Plane right_plane=Plane(matrix[ 3] - matrix[ 0],
matrix[ 7] - matrix[ 4],
@ -613,7 +613,7 @@ void CameraMatrix::scale_translate_to_fit(const Rect3& p_aabb) {
CameraMatrix::operator Transform() const {
Transform tr;
const float *m=&matrix[0][0];
const real_t *m=&matrix[0][0];
tr.basis.elements[0][0]=m[0];
tr.basis.elements[1][0]=m[1];
@ -637,7 +637,7 @@ CameraMatrix::operator Transform() const {
CameraMatrix::CameraMatrix(const Transform& p_transform) {
const Transform &tr = p_transform;
float *m=&matrix[0][0];
real_t *m=&matrix[0][0];
m[0]=tr.basis.elements[0][0];
m[1]=tr.basis.elements[1][0];

View file

@ -48,32 +48,32 @@ struct CameraMatrix {
PLANE_BOTTOM
};
float matrix[4][4];
real_t matrix[4][4];
void set_identity();
void set_zero();
void set_light_bias();
void set_light_atlas_rect(const Rect2& p_rect);
void set_perspective(float p_fovy_degrees, float p_aspect, float p_z_near, float p_z_far,bool p_flip_fov=false);
void set_orthogonal(float p_left, float p_right, float p_bottom, float p_top, float p_znear, float p_zfar);
void set_orthogonal(float p_size, float p_aspect, float p_znear, float p_zfar,bool p_flip_fov=false);
void set_frustum(float p_left, float p_right, float p_bottom, float p_top, float p_near, float p_far);
void set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far,bool p_flip_fov=false);
void set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar);
void set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar,bool p_flip_fov=false);
void set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far);
static float get_fovy(float p_fovx,float p_aspect) {
static real_t get_fovy(real_t p_fovx,real_t p_aspect) {
return Math::rad2deg(Math::atan(p_aspect * Math::tan(Math::deg2rad(p_fovx) * 0.5))*2.0);
}
float get_z_far() const;
float get_z_near() const;
float get_aspect() const;
float get_fov() const;
real_t get_z_far() const;
real_t get_z_near() const;
real_t get_aspect() const;
real_t 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 get_viewport_size(real_t& r_width, real_t& r_height) const;
void invert();
CameraMatrix inverse() const;
@ -102,7 +102,7 @@ Vector3 CameraMatrix::xform(const Vector3& p_vec3) const {
ret.x = matrix[0][0] * p_vec3.x + matrix[1][0] * p_vec3.y + matrix[2][0] * p_vec3.z + matrix[3][0];
ret.y = matrix[0][1] * p_vec3.x + matrix[1][1] * p_vec3.y + matrix[2][1] * p_vec3.z + matrix[3][1];
ret.z = matrix[0][2] * p_vec3.x + matrix[1][2] * p_vec3.y + matrix[2][2] * p_vec3.z + matrix[3][2];
float w = matrix[0][3] * p_vec3.x + matrix[1][3] * p_vec3.y + matrix[2][3] * p_vec3.z + matrix[3][3];
real_t w = matrix[0][3] * p_vec3.x + matrix[1][3] * p_vec3.y + matrix[2][3] * p_vec3.z + matrix[3][3];
return ret/w;
}

View file

@ -168,8 +168,8 @@ Face3::Side Face3::get_side_of(const Face3& p_face,ClockDirection p_clock_dir) c
Vector3 Face3::get_random_point_inside() const {
float a=Math::random(0,1);
float b=Math::random(0,1);
real_t a=Math::random(0,1);
real_t b=Math::random(0,1);
if (a>b) {
SWAP(a,b);
}
@ -215,9 +215,9 @@ bool Face3::intersects_aabb(const Rect3& p_aabb) const {
#define TEST_AXIS(m_ax)\
{\
float aabb_min=p_aabb.pos.m_ax;\
float aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\
float tri_min,tri_max;\
real_t aabb_min=p_aabb.pos.m_ax;\
real_t aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\
real_t tri_min,tri_max;\
for (int i=0;i<3;i++) {\
if (i==0 || vertex[i].m_ax > tri_max)\
tri_max=vertex[i].m_ax;\
@ -255,7 +255,7 @@ bool Face3::intersects_aabb(const Rect3& p_aabb) const {
continue; // coplanar
axis.normalize();
float minA,maxA,minB,maxB;
real_t minA,maxA,minB,maxB;
p_aabb.project_range_in_plane(Plane(axis,0),minA,maxA);
project_range(axis,Transform(),minB,maxB);
@ -272,12 +272,12 @@ Face3::operator String() const {
return String()+vertex[0]+", "+vertex[1]+", "+vertex[2];
}
void Face3::project_range(const Vector3& p_normal,const Transform& p_transform,float& r_min, float& r_max) const {
void Face3::project_range(const Vector3& p_normal,const Transform& p_transform,real_t& r_min, real_t& r_max) const {
for (int i=0;i<3;i++) {
Vector3 v=p_transform.xform(vertex[i]);
float d=p_normal.dot(v);
real_t d=p_normal.dot(v);
if (i==0 || d > r_max)
r_max=d;
@ -316,11 +316,11 @@ void Face3::get_support(const Vector3& p_normal,const Transform& p_transform,Vec
/** FIND SUPPORT VERTEX **/
int vert_support_idx=-1;
float support_max;
real_t support_max;
for (int i=0;i<3;i++) {
float d=n.dot(vertex[i]);
real_t d=n.dot(vertex[i]);
if (i==0 || d > support_max) {
support_max=d;
@ -336,7 +336,7 @@ void Face3::get_support(const Vector3& p_normal,const Transform& p_transform,Vec
continue;
// check if edge is valid as a support
float dot=(vertex[i]-vertex[(i+1)%3]).normalized().dot(n);
real_t dot=(vertex[i]-vertex[(i+1)%3]).normalized().dot(n);
dot=ABS(dot);
if (dot < _EDGE_IS_VALID_SUPPORT_TRESHOLD) {
@ -362,15 +362,15 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const {
Vector3 edge1 = vertex[2] - vertex[0];
Vector3 v0 = vertex[0] - p_point;
float a = edge0.dot( edge0 );
float b = edge0.dot( edge1 );
float c = edge1.dot( edge1 );
float d = edge0.dot( v0 );
float e = edge1.dot( v0 );
real_t a = edge0.dot( edge0 );
real_t b = edge0.dot( edge1 );
real_t c = edge1.dot( edge1 );
real_t d = edge0.dot( v0 );
real_t e = edge1.dot( v0 );
float det = a*c - b*b;
float s = b*e - c*d;
float t = b*d - a*e;
real_t det = a*c - b*b;
real_t s = b*e - c*d;
real_t t = b*d - a*e;
if ( s + t < det )
{
@ -402,7 +402,7 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const {
}
else
{
float invDet = 1.f / det;
real_t invDet = 1.f / det;
s *= invDet;
t *= invDet;
}
@ -411,12 +411,12 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const {
{
if ( s < 0.f )
{
float tmp0 = b+d;
float tmp1 = c+e;
real_t tmp0 = b+d;
real_t tmp1 = c+e;
if ( tmp1 > tmp0 )
{
float numer = tmp1 - tmp0;
float denom = a-2*b+c;
real_t numer = tmp1 - tmp0;
real_t denom = a-2*b+c;
s = CLAMP( numer/denom, 0.f, 1.f );
t = 1-s;
}
@ -430,8 +430,8 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const {
{
if ( a+d > b+e )
{
float numer = c+e-b-d;
float denom = a-2*b+c;
real_t numer = c+e-b-d;
real_t denom = a-2*b+c;
s = CLAMP( numer/denom, 0.f, 1.f );
t = 1-s;
}
@ -443,8 +443,8 @@ Vector3 Face3::get_closest_point_to(const Vector3& p_point) const {
}
else
{
float numer = c+e-b-d;
float denom = a-2*b+c;
real_t numer = c+e-b-d;
real_t denom = a-2*b+c;
s = CLAMP( numer/denom, 0.f, 1.f );
t = 1.f - s;
}

View file

@ -76,7 +76,7 @@ public:
ClockDirection get_clock_dir() const; ///< todo, test if this is returning the proper clockwisity
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;
void project_range(const Vector3& p_normal,const Transform& p_transform,real_t& r_min, real_t& r_max) const;
Rect3 get_aabb() const {
@ -109,9 +109,9 @@ bool Face3::intersects_aabb2(const Rect3& p_aabb) const {
(perp.z>0) ? -half_extents.z : half_extents.z
);
float d = perp.dot(vertex[0]);
float dist_a = perp.dot(ofs+sup)-d;
float dist_b = perp.dot(ofs-sup)-d;
real_t d = perp.dot(vertex[0]);
real_t dist_a = perp.dot(ofs+sup)-d;
real_t dist_b = perp.dot(ofs-sup)-d;
if (dist_a*dist_b > 0)
return false; //does not intersect the plane
@ -119,9 +119,9 @@ bool Face3::intersects_aabb2(const Rect3& p_aabb) const {
#define TEST_AXIS(m_ax)\
{\
float aabb_min=p_aabb.pos.m_ax;\
float aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\
float tri_min,tri_max;\
real_t aabb_min=p_aabb.pos.m_ax;\
real_t aabb_max=p_aabb.pos.m_ax+p_aabb.size.m_ax;\
real_t tri_min,tri_max;\
for (int i=0;i<3;i++) {\
if (i==0 || vertex[i].m_ax > tri_max)\
tri_max=vertex[i].m_ax;\
@ -236,16 +236,16 @@ bool Face3::intersects_aabb2(const Rect3& p_aabb) const {
(axis.z>0) ? -half_extents.z : half_extents.z
);
float maxB = axis.dot(ofs+sup2);
float minB = axis.dot(ofs-sup2);
real_t maxB = axis.dot(ofs+sup2);
real_t minB = axis.dot(ofs-sup2);
if (minB>maxB) {
SWAP(maxB,minB);
}
float minT=1e20,maxT=-1e20;
real_t minT=1e20,maxT=-1e20;
for (int k=0;k<3;k++) {
float d=axis.dot(vertex[k]);
real_t d=axis.dot(vertex[k]);
if (d > maxT)
maxT=d;

View file

@ -580,7 +580,7 @@ static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int l
}
PoolVector< Face3 > Geometry::wrap_geometry( PoolVector< Face3 > p_array,float *p_error ) {
PoolVector< Face3 > Geometry::wrap_geometry( PoolVector< Face3 > p_array,real_t *p_error ) {
#define _MIN_SIZE 1.0
#define _MAX_LENGTH 20
@ -755,7 +755,7 @@ Geometry::MeshData Geometry::build_convex_mesh(const PoolVector<Plane> &p_planes
#define SUBPLANE_SIZE 1024.0
float subplane_size = 1024.0; // should compute this from the actual plane
real_t 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];
@ -910,7 +910,7 @@ PoolVector<Plane> Geometry::build_box_planes(const Vector3& p_extents) {
return planes;
}
PoolVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
PoolVector<Plane> Geometry::build_cylinder_planes(real_t p_radius, real_t p_height, int p_sides, Vector3::Axis p_axis) {
PoolVector<Plane> planes;
@ -933,7 +933,7 @@ PoolVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height
}
PoolVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p_lons, Vector3::Axis p_axis) {
PoolVector<Plane> Geometry::build_sphere_planes(real_t p_radius, int p_lats,int p_lons, Vector3::Axis p_axis) {
PoolVector<Plane> planes;
@ -957,7 +957,7 @@ PoolVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p
for (int j=1;j<=p_lats;j++) {
//todo this is stupid, fix
Vector3 angle = normal.linear_interpolate(axis,j/(float)p_lats).normalized();
Vector3 angle = normal.linear_interpolate(axis,j/(real_t)p_lats).normalized();
Vector3 pos = angle*p_radius;
planes.push_back( Plane( pos, angle ) );
planes.push_back( Plane( pos * axis_neg, angle * axis_neg) );
@ -969,7 +969,7 @@ PoolVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p
}
PoolVector<Plane> Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
PoolVector<Plane> Geometry::build_capsule_planes(real_t p_radius, real_t p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
PoolVector<Plane> planes;
@ -991,7 +991,7 @@ PoolVector<Plane> Geometry::build_capsule_planes(float p_radius, float p_height,
for (int j=1;j<=p_lats;j++) {
Vector3 angle = normal.linear_interpolate(axis,j/(float)p_lats).normalized();
Vector3 angle = normal.linear_interpolate(axis,j/(real_t)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) );
@ -1108,13 +1108,13 @@ void Geometry::make_atlas(const Vector<Size2i>& p_rects,Vector<Point2i>& r_resul
//find the result with the best aspect ratio
int best=-1;
float best_aspect=1e20;
real_t best_aspect=1e20;
for(int i=0;i<results.size();i++) {
float h = nearest_power_of_2(results[i].max_h);
float w = nearest_power_of_2(results[i].max_w);
float aspect = h>w ? h/w : w/h;
real_t h = nearest_power_of_2(results[i].max_h);
real_t w = nearest_power_of_2(results[i].max_w);
real_t aspect = h>w ? h/w : w/h;
if (aspect < best_aspect) {
best=i;
best_aspect=aspect;

View file

@ -48,15 +48,15 @@ public:
static float get_closest_points_between_segments( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2, Vector2& c1, Vector2& c2) {
static real_t get_closest_points_between_segments( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2, Vector2& c1, Vector2& c2) {
Vector2 d1 = q1 - p1; // Direction vector of segment S1
Vector2 d2 = q2 - p2; // Direction vector of segment S2
Vector2 r = p1 - p2;
float a = d1.dot(d1); // Squared length of segment S1, always nonnegative
float e = d2.dot(d2); // Squared length of segment S2, always nonnegative
float f = d2.dot(r);
float s,t;
real_t a = d1.dot(d1); // Squared length of segment S1, always nonnegative
real_t e = d2.dot(d2); // Squared length of segment S2, always nonnegative
real_t f = d2.dot(r);
real_t s,t;
// Check if either or both segments degenerate into points
if (a <= CMP_EPSILON && e <= CMP_EPSILON) {
// Both segments degenerate into points
@ -66,25 +66,25 @@ public:
}
if (a <= CMP_EPSILON) {
// First segment degenerates into a point
s = 0.0f;
s = 0.0;
t = f / e; // s = 0 => t = (b*s + f) / e = f / e
t = CLAMP(t, 0.0f, 1.0f);
t = CLAMP(t, 0.0, 1.0);
} else {
float c = d1.dot(r);
real_t c = d1.dot(r);
if (e <= CMP_EPSILON) {
// Second segment degenerates into a point
t = 0.0f;
s = CLAMP(-c / a, 0.0f, 1.0f); // t = 0 => s = (b*t - c) / a = -c / a
t = 0.0;
s = CLAMP(-c / a, 0.0, 1.0); // t = 0 => s = (b*t - c) / a = -c / a
} else {
// The general nondegenerate case starts here
float b = d1.dot(d2);
float denom = a*e-b*b; // Always nonnegative
real_t b = d1.dot(d2);
real_t denom = a*e-b*b; // Always nonnegative
// If segments not parallel, compute closest point on L1 to L2 and
// clamp to segment S1. Else pick arbitrary s (here 0)
if (denom != 0.0f) {
s = CLAMP((b*f - c*e) / denom, 0.0f, 1.0f);
if (denom != 0.0) {
s = CLAMP((b*f - c*e) / denom, 0.0, 1.0);
} else
s = 0.0f;
s = 0.0;
// Compute point on L2 closest to S1(s) using
// t = Dot((P1 + D1*s) - P2,D2) / Dot(D2,D2) = (b*s + f) / e
t = (b*s + f) / e;
@ -92,12 +92,12 @@ public:
//If t in [0,1] done. Else clamp t, recompute s for the new value
// of t using s = Dot((P2 + D2*t) - P1,D1) / Dot(D1,D1)= (t*b - c) / a
// and clamp s to [0, 1]
if (t < 0.0f) {
t = 0.0f;
s = CLAMP(-c / a, 0.0f, 1.0f);
} else if (t > 1.0f) {
t = 1.0f;
s = CLAMP((b - c) / a, 0.0f, 1.0f);
if (t < 0.0) {
t = 0.0;
s = CLAMP(-c / a, 0.0, 1.0);
} else if (t > 1.0) {
t = 1.0;
s = CLAMP((b - c) / a, 0.0, 1.0);
}
}
}
@ -113,8 +113,8 @@ public:
#define d_of(m,n,o,p) ( (m.x - n.x) * (o.x - p.x) + (m.y - n.y) * (o.y - p.y) + (m.z - n.z) * (o.z - p.z) )
//caluclate the parpametric position on the 2 curves, mua and mub
float mua = ( d_of(p1,q1,q2,q1) * d_of(q2,q1,p2,p1) - d_of(p1,q1,p2,p1) * d_of(q2,q1,q2,q1) ) / ( d_of(p2,p1,p2,p1) * d_of(q2,q1,q2,q1) - d_of(q2,q1,p2,p1) * d_of(q2,q1,p2,p1) );
float mub = ( d_of(p1,q1,q2,q1) + mua * d_of(q2,q1,p2,p1) ) / d_of(q2,q1,q2,q1);
real_t mua = ( d_of(p1,q1,q2,q1) * d_of(q2,q1,p2,p1) - d_of(p1,q1,p2,p1) * d_of(q2,q1,q2,q1) ) / ( d_of(p2,p1,p2,p1) * d_of(q2,q1,q2,q1) - d_of(q2,q1,p2,p1) * d_of(q2,q1,p2,p1) );
real_t mub = ( d_of(p1,q1,q2,q1) + mua * d_of(q2,q1,p2,p1) ) / d_of(q2,q1,q2,q1);
//clip the value between [0..1] constraining the solution to lie on the original curves
if (mua < 0) mua = 0;
@ -125,7 +125,7 @@ public:
c2 = q1.linear_interpolate(q2,mub);
}
static float get_closest_distance_between_segments( const Vector3& p_from_a,const Vector3& p_to_a, const Vector3& p_from_b,const Vector3& p_to_b) {
static real_t get_closest_distance_between_segments( const Vector3& p_from_a,const Vector3& p_to_a, const Vector3& p_from_b,const Vector3& p_to_b) {
Vector3 u = p_to_a - p_from_a;
Vector3 v = p_to_b - p_from_b;
Vector3 w = p_from_a - p_to_a;
@ -273,22 +273,22 @@ public:
Vector3 sphere_pos=p_sphere_pos-p_from;
Vector3 rel=(p_to-p_from);
float rel_l=rel.length();
real_t rel_l=rel.length();
if (rel_l<CMP_EPSILON)
return false; // both points are the same
Vector3 normal=rel/rel_l;
float sphere_d=normal.dot(sphere_pos);
real_t sphere_d=normal.dot(sphere_pos);
//Vector3 ray_closest=normal*sphere_d;
float ray_distance=sphere_pos.distance_to(normal*sphere_d);
real_t ray_distance=sphere_pos.distance_to(normal*sphere_d);
if (ray_distance>=p_sphere_radius)
return false;
float inters_d2=p_sphere_radius*p_sphere_radius - ray_distance*ray_distance;
float inters_d=sphere_d;
real_t inters_d2=p_sphere_radius*p_sphere_radius - ray_distance*ray_distance;
real_t inters_d=sphere_d;
if (inters_d2>=CMP_EPSILON)
inters_d-=Math::sqrt(inters_d2);
@ -307,17 +307,17 @@ public:
return true;
}
static inline bool segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, float p_height,float p_radius,Vector3* r_res=0,Vector3 *r_norm=0) {
static inline bool segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, real_t p_height,real_t p_radius,Vector3* r_res=0,Vector3 *r_norm=0) {
Vector3 rel=(p_to-p_from);
float rel_l=rel.length();
real_t rel_l=rel.length();
if (rel_l<CMP_EPSILON)
return false; // both points are the same
// first check if they are parallel
Vector3 normal=(rel/rel_l);
Vector3 crs = normal.cross(Vector3(0,0,1));
float crs_l=crs.length();
real_t crs_l=crs.length();
Vector3 z_dir;
@ -328,13 +328,13 @@ public:
z_dir=crs/crs_l;
}
float dist=z_dir.dot(p_from);
real_t dist=z_dir.dot(p_from);
if (dist>=p_radius)
return false; // too far away
// convert to 2D
float w2=p_radius*p_radius-dist*dist;
real_t w2=p_radius*p_radius-dist*dist;
if (w2<CMP_EPSILON)
return false; //avoid numerical error
Size2 size(Math::sqrt(w2),p_height*0.5);
@ -344,7 +344,7 @@ public:
Vector2 from2D(x_dir.dot(p_from),p_from.z);
Vector2 to2D(x_dir.dot(p_to),p_to.z);
float min=0,max=1;
real_t min=0,max=1;
int axis=-1;
@ -464,12 +464,12 @@ public:
Vector3 p=p_point-p_segment[0];
Vector3 n=p_segment[1]-p_segment[0];
float l =n.length();
real_t l =n.length();
if (l<1e-10)
return p_segment[0]; // both points are the same, just give any
n/=l;
float d=n.dot(p);
real_t d=n.dot(p);
if (d<=0.0)
return p_segment[0]; // before first point
@ -483,12 +483,12 @@ public:
Vector3 p=p_point-p_segment[0];
Vector3 n=p_segment[1]-p_segment[0];
float l =n.length();
real_t l =n.length();
if (l<1e-10)
return p_segment[0]; // both points are the same, just give any
n/=l;
float d=n.dot(p);
real_t d=n.dot(p);
return p_segment[0]+n*d; // inside
}
@ -497,12 +497,12 @@ public:
Vector2 p=p_point-p_segment[0];
Vector2 n=p_segment[1]-p_segment[0];
float l =n.length();
real_t l =n.length();
if (l<1e-10)
return p_segment[0]; // both points are the same, just give any
n/=l;
float d=n.dot(p);
real_t d=n.dot(p);
if (d<=0.0)
return p_segment[0]; // before first point
@ -529,12 +529,12 @@ public:
Vector2 p=p_point-p_segment[0];
Vector2 n=p_segment[1]-p_segment[0];
float l =n.length();
real_t l =n.length();
if (l<1e-10)
return p_segment[0]; // both points are the same, just give any
n/=l;
float d=n.dot(p);
real_t d=n.dot(p);
return p_segment[0]+n*d; // inside
}
@ -555,7 +555,7 @@ public:
if ((C.y<0 && D.y<0) || (C.y>=0 && D.y>=0))
return false;
float ABpos=D.x+(C.x-D.x)*D.y/(D.y-C.y);
real_t ABpos=D.x+(C.x-D.x)*D.y/(D.y-C.y);
// Fail if segment C-D crosses line A-B outside of segment A-B.
if (ABpos<0 || ABpos>1.0)
@ -595,7 +595,7 @@ public:
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) {
float d=p_normal.dot(p_sphere_pos)-p_normal.dot(p_triangle[0]);
real_t d=p_normal.dot(p_sphere_pos)-p_normal.dot(p_triangle[0]);
if (d > p_sphere_radius || d < -p_sphere_radius) // not touching the plane of the face, return
return false;
@ -629,7 +629,7 @@ public:
Vector3 axis =n1.cross(n2).cross(n1);
axis.normalize(); // ugh
float ad=axis.dot(n2);
real_t ad=axis.dot(n2);
if (ABS(ad)>p_sphere_radius) {
// no chance with this edge, too far away
@ -639,7 +639,7 @@ public:
// check point within edge capsule cylinder
/** 4th TEST INSIDE EDGE POINTS **/
float sphere_at = n1.dot(n2);
real_t sphere_at = n1.dot(n2);
if (sphere_at>=0 && sphere_at<n1.dot(n1)) {
@ -650,7 +650,7 @@ public:
return true;
}
float r2=p_sphere_radius*p_sphere_radius;
real_t r2=p_sphere_radius*p_sphere_radius;
if (n2.length_squared()<r2) {
@ -726,8 +726,8 @@ public:
int outside_count = 0;
for (int a = 0; a < polygon.size(); a++) {
//float p_plane.d = (*this) * polygon[a];
float dist = p_plane.distance_to(polygon[a]);
//real_t p_plane.d = (*this) * polygon[a];
real_t dist = p_plane.distance_to(polygon[a]);
if (dist <-CMP_POINT_IN_PLANE_EPSILON) {
location_cache[a] = LOC_INSIDE;
inside_count++;
@ -761,8 +761,8 @@ public:
const Vector3& v2 = polygon[index];
Vector3 segment= v1 - v2;
double den=p_plane.normal.dot( segment );
double dist=p_plane.distance_to( v1 ) / den;
real_t den=p_plane.normal.dot( segment );
real_t dist=p_plane.distance_to( v1 ) / den;
dist=-dist;
clipped.push_back( v1 + segment * dist );
}
@ -771,8 +771,8 @@ public:
if ((loc == LOC_INSIDE) && (location_cache[previous] == LOC_OUTSIDE)) {
const Vector3& v2 = polygon[previous];
Vector3 segment= v1 - v2;
double den=p_plane.normal.dot( segment );
double dist=p_plane.distance_to( v1 ) / den;
real_t den=p_plane.normal.dot( segment );
real_t dist=p_plane.distance_to( v1 ) / den;
dist=-dist;
clipped.push_back( v1 + segment * dist );
}
@ -808,7 +808,7 @@ public:
static PoolVector< PoolVector< Face3 > > separate_objects( PoolVector< Face3 > p_array );
static PoolVector< Face3 > wrap_geometry( PoolVector< Face3 > p_array, float *p_error=NULL ); ///< create a "wrap" that encloses the given geometry
static PoolVector< Face3 > wrap_geometry( PoolVector< Face3 > p_array, real_t *p_error=NULL ); ///< create a "wrap" that encloses the given geometry
struct MeshData {
@ -884,9 +884,9 @@ public:
}
static double vec2_cross(const Point2 &O, const Point2 &A, const Point2 &B)
static real_t vec2_cross(const Point2 &O, const Point2 &A, const Point2 &B)
{
return (double)(A.x - O.x) * (B.y - O.y) - (double)(A.y - O.y) * (B.x - O.x);
return (real_t)(A.x - O.x) * (B.y - O.y) - (real_t)(A.y - O.y) * (B.x - O.x);
}
// Returns a list of points on the convex hull in counter-clockwise order.
@ -918,10 +918,10 @@ public:
}
static MeshData build_convex_mesh(const PoolVector<Plane> &p_planes);
static PoolVector<Plane> build_sphere_planes(float p_radius, int p_lats, int p_lons, Vector3::Axis p_axis=Vector3::AXIS_Z);
static PoolVector<Plane> build_sphere_planes(real_t p_radius, int p_lats, int p_lons, Vector3::Axis p_axis=Vector3::AXIS_Z);
static PoolVector<Plane> build_box_planes(const Vector3& p_extents);
static PoolVector<Plane> build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z);
static PoolVector<Plane> build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z);
static PoolVector<Plane> build_cylinder_planes(real_t p_radius, real_t p_height, int p_sides, Vector3::Axis p_axis=Vector3::AXIS_Z);
static PoolVector<Plane> build_capsule_planes(real_t p_radius, real_t p_height, int p_sides, int p_lats, Vector3::Axis p_axis=Vector3::AXIS_Z);
static void make_atlas(const Vector<Size2i>& p_rects,Vector<Point2i>& r_result, Size2i& r_size);

View file

@ -239,10 +239,10 @@ Vector2 Vector2::cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, co
real_t t3 = t2 * t;
Vector2 out;
out = 0.5f * ( ( p1 * 2.0f) +
out = 0.5 * ( ( p1 * 2.0) +
( -p0 + p2 ) * t +
( 2.0f * p0 - 5.0f * p1 + 4 * p2 - p3 ) * t2 +
( -p0 + 3.0f * p1 - 3.0f * p2 + p3 ) * t3 );
( 2.0 * p0 - 5.0 * p1 + 4 * p2 - p3 ) * t2 +
( -p0 + 3.0 * p1 - 3.0 * p2 + p3 ) * t3 );
return out;
/*

View file

@ -59,35 +59,8 @@ uint32_t Math::rand() {
return pcg32_random_r(&default_pcg);
}
double Math::randf() {
return (double)rand() / (double)Math::RANDOM_MAX;
}
double Math::round(double p_val) {
if (p_val>=0) {
return ::floor(p_val+0.5);
} else {
p_val=-p_val;
return -::floor(p_val+0.5);
}
}
double Math::dectime(double p_value,double p_amount, double p_step) {
float sgn = p_value < 0 ? -1.0 : 1.0;
float val = absf(p_value);
val-=p_amount*p_step;
if (val<0.0)
val=0.0;
return val*sgn;
}
int Math::step_decimals(double p_step) {
static const int maxn=9;
static const double sd[maxn]={
0.9999, // somehow compensate for floating point error
@ -101,7 +74,7 @@ int Math::step_decimals(double p_step) {
0.000000009999
};
double as=absf(p_step);
double as=Math::abs(p_step);
for(int i=0;i<maxn;i++) {
if (as>=sd[i]) {
return i;
@ -111,8 +84,16 @@ int Math::step_decimals(double p_step) {
return maxn;
}
double Math::ease(double p_x, double p_c) {
double Math::dectime(double p_value,double p_amount, double p_step) {
double sgn = p_value < 0 ? -1.0 : 1.0;
double val = Math::abs(p_value);
val-=p_amount*p_step;
if (val<0.0)
val=0.0;
return val*sgn;
}
double Math::ease(double p_x, double p_c) {
if (p_x<0)
p_x=0;
else if (p_x>1.0)
@ -133,20 +114,16 @@ double Math::ease(double p_x, double p_c) {
}
} else
return 0; // no ease (raw)
}
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=Math::floor( p_value / p_step + 0.5 ) * p_step;
}
return p_value;
}
uint32_t Math::larger_prime(uint32_t p_val) {
static const uint32_t primes[] = {
@ -195,22 +172,15 @@ uint32_t Math::larger_prime(uint32_t p_val) {
}
double Math::random(double from, double to) {
unsigned int r = Math::rand();
double ret = (double)r/(double)RANDOM_MAX;
return (ret)*(to-from) + from;
}
double Math::pow(double x, double y) {
return ::pow(x,y);
float Math::random(float from, float to) {
unsigned int r = Math::rand();
float ret = (float)r/(float)RANDOM_MAX;
return (ret)*(to-from) + from;
}
double Math::log(double x) {
return ::log(x);
}
double Math::exp(double x) {
return ::exp(x);
}

View file

@ -38,6 +38,7 @@
#define Math_PI 3.14159265358979323846
#define Math_SQRT12 0.7071067811865475244008443621048490
#define Math_LN2 0.693147180559945309417
class Math {
@ -51,149 +52,122 @@ public:
};
static _ALWAYS_INLINE_ double sin(double p_x) {
static _ALWAYS_INLINE_ double sin(double p_x) { return ::sin(p_x); }
static _ALWAYS_INLINE_ float sin(float p_x) { return ::sinf(p_x); }
return ::sin(p_x);
static _ALWAYS_INLINE_ double cos(double p_x) { return ::cos(p_x); }
static _ALWAYS_INLINE_ float cos(float p_x) { return ::cosf(p_x); }
}
static _ALWAYS_INLINE_ double tan(double p_x) { return ::tan(p_x); }
static _ALWAYS_INLINE_ float tan(float p_x) { return ::tanf(p_x); }
static _ALWAYS_INLINE_ double cos(double p_x) {
static _ALWAYS_INLINE_ double sinh(double p_x) { return ::sinh(p_x); }
static _ALWAYS_INLINE_ float sinh(float p_x) { return ::sinhf(p_x); }
return ::cos(p_x);
static _ALWAYS_INLINE_ double cosh(double p_x) { return ::cosh(p_x); }
static _ALWAYS_INLINE_ float cosh(float p_x) { return ::coshf(p_x); }
}
static _ALWAYS_INLINE_ double tanh(double p_x) { return ::tanh(p_x); }
static _ALWAYS_INLINE_ float tanh(float p_x) { return ::tanhf(p_x); }
static _ALWAYS_INLINE_ double tan(double p_x) {
static _ALWAYS_INLINE_ double asin(double p_x) { return ::asin(p_x); }
static _ALWAYS_INLINE_ float asin(float p_x) { return ::asinf(p_x); }
return ::tan(p_x);
static _ALWAYS_INLINE_ double acos(double p_x) { return ::acos(p_x); }
static _ALWAYS_INLINE_ float acos(float p_x) { return ::acosf(p_x); }
}
static _ALWAYS_INLINE_ double sinh(double p_x) {
static _ALWAYS_INLINE_ double atan(double p_x) { return ::atan(p_x); }
static _ALWAYS_INLINE_ float atan(float p_x) { return ::atanf(p_x); }
return ::sinh(p_x);
}
static _ALWAYS_INLINE_ double atan2(double p_y, double p_x) { return ::atan2(p_y,p_x); }
static _ALWAYS_INLINE_ float atan2(float p_y, float p_x) { return ::atan2f(p_y,p_x); }
static _ALWAYS_INLINE_ double cosh(double p_x) {
static _ALWAYS_INLINE_ double sqrt(double p_x) { return ::sqrt(p_x); }
static _ALWAYS_INLINE_ float sqrt(float p_x) { return ::sqrtf(p_x); }
return ::cosh(p_x);
}
static _ALWAYS_INLINE_ double fmod(double p_x,double p_y) { return ::fmod(p_x,p_y); }
static _ALWAYS_INLINE_ float fmod(float p_x,float p_y) { return ::fmodf(p_x,p_y); }
static _ALWAYS_INLINE_ double tanh(double p_x) {
static _ALWAYS_INLINE_ double floor(double p_x) { return ::floor(p_x); }
static _ALWAYS_INLINE_ float floor(float p_x) { return ::floorf(p_x); }
return ::tanh(p_x);
}
static _ALWAYS_INLINE_ double ceil(double p_x) { return ::ceil(p_x); }
static _ALWAYS_INLINE_ float ceil(float p_x) { return ::ceilf(p_x); }
static _ALWAYS_INLINE_ double pow(double p_x, double p_y) { return ::pow(p_x,p_y); }
static _ALWAYS_INLINE_ float pow(float p_x, float p_y) { return ::powf(p_x,p_y); }
static _ALWAYS_INLINE_ double asin(double p_x) {
static _ALWAYS_INLINE_ double log(double p_x) { return ::log(p_x); }
static _ALWAYS_INLINE_ float log(float p_x) { return ::logf(p_x); }
return ::asin(p_x);
static _ALWAYS_INLINE_ double exp(double p_x) { return ::exp(p_x); }
static _ALWAYS_INLINE_ float exp(float p_x) { return ::expf(p_x); }
}
static _ALWAYS_INLINE_ double acos(double p_x) {
return ::acos(p_x);
}
static _ALWAYS_INLINE_ double atan(double p_x) {
return ::atan(p_x);
}
static _ALWAYS_INLINE_ double atan2(double p_y, double p_x) {
return ::atan2(p_y,p_x);
}
static _ALWAYS_INLINE_ double deg2rad(double p_y) {
return p_y*Math_PI/180.0;
}
static _ALWAYS_INLINE_ double rad2deg(double p_y) {
return p_y*180.0/Math_PI;
}
static _ALWAYS_INLINE_ double sqrt(double p_x) {
return ::sqrt(p_x);
}
static _ALWAYS_INLINE_ double fmod(double p_x,double p_y) {
return ::fmod(p_x,p_y);
}
static _ALWAYS_INLINE_ double fposmod(double p_x,double p_y) {
if (p_x>=0) {
return fmod(p_x,p_y);
} else {
return p_y-fmod(-p_x,p_y);
}
}
static _ALWAYS_INLINE_ double floor(double p_x) {
return ::floor(p_x);
}
static _ALWAYS_INLINE_ double ceil(double p_x) {
return ::ceil(p_x);
}
static uint32_t rand_from_seed(uint64_t *seed);
static double ease(double p_x, double p_c);
static int step_decimals(double p_step);
static double stepify(double p_value,double p_step);
static void seed(uint64_t x=0);
static void randomize();
static uint32_t larger_prime(uint32_t p_val);
static double dectime(double p_value,double p_amount, double p_step);
static inline double linear2db(double p_linear) {
return Math::log( p_linear ) * 8.6858896380650365530225783783321;
}
static inline double db2linear(double p_db) {
return Math::exp( p_db * 0.11512925464970228420089957273422 );
}
static _ALWAYS_INLINE_ bool is_nan(double p_val) {
return (p_val!=p_val);
}
static _ALWAYS_INLINE_ bool is_nan(double p_val) { return (p_val!=p_val); }
static _ALWAYS_INLINE_ bool is_nan(float p_val) { return (p_val!=p_val); }
static _ALWAYS_INLINE_ bool is_inf(double p_val) {
#ifdef _MSC_VER
return !_finite(p_val);
#else
return isinf(p_val);
#endif
}
static uint32_t rand();
static double randf();
static _ALWAYS_INLINE_ bool is_inf(float p_val) {
#ifdef _MSC_VER
return !_finite(p_val);
#else
return isinf(p_val);
#endif
}
static double round(double p_val);
static _ALWAYS_INLINE_ double abs(double g) { return absd(g); }
static _ALWAYS_INLINE_ float abs(float g) { return absf(g); }
static _ALWAYS_INLINE_ int abs(int g) { return g > 0 ? g : -g; }
static _ALWAYS_INLINE_ double fposmod(double p_x,double p_y) { return (p_x>=0) ? Math::fmod(p_x,p_y) : p_y-Math::fmod(-p_x,p_y); }
static _ALWAYS_INLINE_ float fposmod(float p_x,float p_y) { return (p_x>=0) ? Math::fmod(p_x,p_y) : p_y-Math::fmod(-p_x,p_y); }
static _ALWAYS_INLINE_ double deg2rad(double p_y) { return p_y*Math_PI/180.0; }
static _ALWAYS_INLINE_ float deg2rad(float p_y) { return p_y*Math_PI/180.0; }
static _ALWAYS_INLINE_ double rad2deg(double p_y) { return p_y*180.0/Math_PI; }
static _ALWAYS_INLINE_ float rad2deg(float p_y) { return p_y*180.0/Math_PI; }
static _ALWAYS_INLINE_ double lerp(double a, double b, double c) { return a+(b-a)*c; }
static _ALWAYS_INLINE_ float lerp(float a, float b, float c) { return a+(b-a)*c; }
static _ALWAYS_INLINE_ double linear2db(double p_linear) { return Math::log( p_linear ) * 8.6858896380650365530225783783321; }
static _ALWAYS_INLINE_ float linear2db(float p_linear) { return Math::log( p_linear ) * 8.6858896380650365530225783783321; }
static _ALWAYS_INLINE_ double db2linear(double p_db) { return Math::exp( p_db * 0.11512925464970228420089957273422 ); }
static _ALWAYS_INLINE_ float db2linear(float p_db) { return Math::exp( p_db * 0.11512925464970228420089957273422 ); }
static _ALWAYS_INLINE_ double round(double p_val) { return (p_val>=0) ? Math::floor(p_val+0.5) : -Math::floor(-p_val+0.5); }
static _ALWAYS_INLINE_ float round(float p_val) { return (p_val>=0) ? Math::floor(p_val+0.5) : -Math::floor(-p_val+0.5); }
// double only, as these functions are mainly used by the editor and not performance-critical,
static double ease(double p_x, double p_c);
static int step_decimals(double p_step);
static double stepify(double p_value,double p_step);
static double dectime(double p_value,double p_amount, double p_step);
static uint32_t larger_prime(uint32_t p_val);
static void seed(uint64_t x=0);
static void randomize();
static uint32_t rand_from_seed(uint64_t *seed);
static uint32_t rand();
static _ALWAYS_INLINE_ double randf() { return (double)rand() / (double)Math::RANDOM_MAX; }
static _ALWAYS_INLINE_ float randd() { return (float)rand() / (float)Math::RANDOM_MAX; }
static double random(double from, double to);
static float random(float from, float to);
static real_t random(int from, int to) { return (real_t)random((real_t)from, (real_t)to); }
static _FORCE_INLINE_ bool isequal_approx(real_t a, real_t b) {
static _ALWAYS_INLINE_ bool isequal_approx(real_t a, real_t b) {
// TODO: Comparing floats for approximate-equality is non-trivial.
// Using epsilon should cover the typical cases in Godot (where a == b is used to compare two reals), such as matrix and vector comparison operators.
// A proper implementation in terms of ULPs should eventually replace the contents of this function.
@ -203,18 +177,7 @@ public:
}
static _FORCE_INLINE_ real_t abs(real_t g) {
#ifdef REAL_T_IS_DOUBLE
return absd(g);
#else
return absf(g);
#endif
}
static _FORCE_INLINE_ float absf(float g) {
static _ALWAYS_INLINE_ float absf(float g) {
union {
float f;
@ -226,7 +189,7 @@ public:
return u.f;
}
static _FORCE_INLINE_ double absd(double g) {
static _ALWAYS_INLINE_ double absd(double g) {
union {
double d;
@ -238,12 +201,12 @@ public:
}
//this function should be as fast as possible and rounding mode should not matter
static _FORCE_INLINE_ int fast_ftoi(float a) {
static _ALWAYS_INLINE_ int fast_ftoi(float a) {
static int b;
#if (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0603) || WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // windows 8 phone?
b = (int)((a>0.0f) ? (a + 0.5f):(a -0.5f));
b = (int)((a>0.0) ? (a + 0.5):(a -0.5));
#elif defined(_MSC_VER) && _MSC_VER < 1800
__asm fld a
@ -266,23 +229,16 @@ public:
#if defined(__GNUC__)
static _FORCE_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE
static _ALWAYS_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE
static _ALWAYS_INLINE_ int64_t dtoll(float p_float) { return (int64_t)p_float; } ///@TODO OPTIMIZE and rename
#else
static _FORCE_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE
static _ALWAYS_INLINE_ int64_t dtoll(double p_double) { return (int64_t)p_double; } ///@TODO OPTIMIZE
static _ALWAYS_INLINE_ int64_t dtoll(float p_float) { return (int64_t)p_float; } ///@TODO OPTIMIZE and rename
#endif
static _FORCE_INLINE_ float lerp(float a, float b, float c) {
return a+(b-a)*c;
}
static double pow(double x, double y);
static double log(double x);
static double exp(double x);
static _FORCE_INLINE_ uint32_t halfbits_to_floatbits(uint16_t h)
static _ALWAYS_INLINE_ uint32_t halfbits_to_floatbits(uint16_t h)
{
uint16_t h_exp, h_sig;
uint32_t f_sgn, f_exp, f_sig;
@ -314,7 +270,7 @@ public:
}
}
static _FORCE_INLINE_ float halfptr_to_float(const uint16_t *h) {
static _ALWAYS_INLINE_ float halfptr_to_float(const uint16_t *h) {
union {
uint32_t u32;
@ -325,7 +281,7 @@ public:
return u.f32;
}
static _FORCE_INLINE_ uint16_t make_half_float(float f) {
static _ALWAYS_INLINE_ uint16_t make_half_float(float f) {
union {
float fv;

View file

@ -504,9 +504,9 @@ void Basis::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const {
ERR_FAIL_COND(is_rotation() == false);
double angle,x,y,z; // variables for result
double epsilon = 0.01; // margin to allow for rounding errors
double epsilon2 = 0.1; // margin to distinguish between 0 and 180 degrees
real_t angle,x,y,z; // variables for result
real_t epsilon = 0.01; // margin to allow for rounding errors
real_t epsilon2 = 0.1; // margin to distinguish between 0 and 180 degrees
if ( (Math::abs(elements[1][0]-elements[0][1])< epsilon)
&& (Math::abs(elements[2][0]-elements[0][2])< epsilon)
@ -525,12 +525,12 @@ void Basis::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const {
}
// otherwise this singularity is angle = 180
angle = Math_PI;
double xx = (elements[0][0]+1)/2;
double yy = (elements[1][1]+1)/2;
double zz = (elements[2][2]+1)/2;
double xy = (elements[1][0]+elements[0][1])/4;
double xz = (elements[2][0]+elements[0][2])/4;
double yz = (elements[2][1]+elements[1][2])/4;
real_t xx = (elements[0][0]+1)/2;
real_t yy = (elements[1][1]+1)/2;
real_t zz = (elements[2][2]+1)/2;
real_t xy = (elements[1][0]+elements[0][1])/4;
real_t xz = (elements[2][0]+elements[0][2])/4;
real_t yz = (elements[2][1]+elements[1][2])/4;
if ((xx > yy) && (xx > zz)) { // elements[0][0] is the largest diagonal term
if (xx< epsilon) {
x = 0;
@ -567,7 +567,7 @@ void Basis::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const {
return;
}
// as we have reached here there are no singularities so we can handle normally
double s = Math::sqrt((elements[1][2] - elements[2][1])*(elements[1][2] - elements[2][1])
real_t s = Math::sqrt((elements[1][2] - elements[2][1])*(elements[1][2] - elements[2][1])
+(elements[2][0] - elements[0][2])*(elements[2][0] - elements[0][2])
+(elements[0][1] - elements[1][0])*(elements[0][1] - elements[1][0])); // s=|axis||sin(angle)|, used to normalise

View file

@ -435,7 +435,7 @@ int Octree<T,use_pairs,AL>::get_subindex(OctreeElementID p_id) const {
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
real_t 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) {

View file

@ -99,7 +99,7 @@ real_t Plane::distance_to(const Vector3 &p_point) const {
bool Plane::has_point(const Vector3 &p_point,real_t _epsilon) const {
float dist=normal.dot(p_point) - d;
real_t dist=normal.dot(p_point) - d;
dist=ABS(dist);
return ( dist <= _epsilon);

View file

@ -124,8 +124,8 @@ Quat Quat::slerp(const Quat& q, const real_t& t) const {
// Standard case (slerp)
real_t sine = Math::sqrt(1 - cosine*cosine);
real_t angle = Math::atan2(sine, cosine);
real_t inv_sine = 1.0f / sine;
real_t coeff_0 = Math::sin((1.0f - t) * angle) * inv_sine;
real_t inv_sine = 1.0 / sine;
real_t coeff_0 = Math::sin((1.0 - t) * angle) * inv_sine;
real_t coeff_1 = Math::sin(t * angle) * inv_sine;
Quat ret= src * coeff_0 + dst * coeff_1;
@ -137,7 +137,7 @@ Quat Quat::slerp(const Quat& q, const real_t& t) const {
// 2. "rkP" and "q" are almost invedste of each other (cosine ~= -1), there
// are an infinite number of possibilities interpolation. but we haven't
// have method to fix this case, so just use linear interpolation here.
Quat ret = src * (1.0f - t) + dst *t;
Quat ret = src * (1.0 - t) + dst *t;
// taking the complement requires renormalisation
ret.normalize();
return ret;
@ -194,14 +194,14 @@ Quat Quat::slerpni(const Quat& q, const real_t& t) const {
const Quat &from = *this;
float dot = from.dot(q);
real_t dot = from.dot(q);
if (Math::absf(dot) > 0.9999f) return from;
if (Math::absf(dot) > 0.9999) return from;
float theta = Math::acos(dot),
sinT = 1.0f / Math::sin(theta),
real_t theta = Math::acos(dot),
sinT = 1.0 / Math::sin(theta),
newFactor = Math::sin(t * theta) * sinT,
invFactor = Math::sin((1.0f - t) * theta) * sinT;
invFactor = Math::sin((1.0 - t) * theta) * sinT;
return Quat(invFactor * from.x + newFactor * q.x,
invFactor * from.y + newFactor * q.y,
@ -259,7 +259,7 @@ Quat Quat::slerpni(const Quat& q, const real_t& t) const {
Quat Quat::cubic_slerp(const Quat& q, const Quat& prep, const Quat& postq,const real_t& t) const {
//the only way to do slerp :|
float t2 = (1.0-t)*t*2;
real_t t2 = (1.0-t)*t*2;
Quat sp = this->slerp(q,t);
Quat sq = prep.slerpni(postq,t);
return sp.slerpni(sq,t2);

View file

@ -119,8 +119,8 @@ public:
w=0;
} else {
real_t s = Math::sqrt((1.0f + d) * 2.0f);
real_t rs = 1.0f / s;
real_t s = Math::sqrt((1.0 + d) * 2.0);
real_t rs = 1.0 / s;
x=c.x*rs;
y=c.y*rs;

View file

@ -86,7 +86,7 @@ Error QuickHull::build(const Vector<Vector3>& p_points, Geometry::MeshData &r_me
if (!valid_points[i])
continue;
float d = p_points[i][longest_axis];
real_t d = p_points[i][longest_axis];
if (i==0 || d < min) {
simplex[0]=i;
@ -105,7 +105,7 @@ Error QuickHull::build(const Vector<Vector3>& p_points, Geometry::MeshData &r_me
{
float maxd;
real_t maxd;
Vector3 rel12 = p_points[simplex[0]] - p_points[simplex[1]];
for(int i=0;i<p_points.size();i++) {
@ -127,7 +127,7 @@ Error QuickHull::build(const Vector<Vector3>& p_points, Geometry::MeshData &r_me
//fourth vertex is the one most further away from the plane
{
float maxd;
real_t maxd;
Plane p(p_points[simplex[0]],p_points[simplex[1]],p_points[simplex[2]]);
for(int i=0;i<p_points.size();i++) {

View file

@ -30,7 +30,7 @@
#include "print_string.h"
float Rect3::get_area() const {
real_t Rect3::get_area() const {
return size.x*size.y*size.z;
@ -114,8 +114,8 @@ bool Rect3::intersects_ray(const Vector3& p_from, const Vector3& p_dir,Vector3*
Vector3 c1, c2;
Vector3 end = pos+size;
float near=-1e20;
float far=1e20;
real_t near=-1e20;
real_t far=1e20;
int axis=0;
for (int i=0;i<3;i++){
@ -159,7 +159,7 @@ bool Rect3::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector
real_t min=0,max=1;
int axis=0;
float sign=0;
real_t sign=0;
for(int i=0;i<3;i++) {
real_t seg_from=p_from[i];
@ -167,7 +167,7 @@ bool Rect3::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector
real_t box_begin=pos[i];
real_t box_end=box_begin+size[i];
real_t cmin,cmax;
float csign;
real_t csign;
if (seg_from < seg_to) {

View file

@ -33,6 +33,8 @@
#include "vector3.h"
#include "plane.h"
#include "math_defs.h"
/**
* AABB / AABB (Axis Aligned Bounding Box)
* This is implemented by a point (pos) and the box size
@ -45,7 +47,7 @@ public:
Vector3 pos;
Vector3 size;
float get_area() const; /// get area
real_t 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);
@ -74,7 +76,7 @@ public:
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;
_FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &from,const Vector3& p_dir, real_t t0, real_t t1) const;
_FORCE_INLINE_ bool intersects_convex_shape(const Plane *p_plane, int p_plane_count) const;
bool intersects_plane(const Plane &p_plane) const;
@ -98,7 +100,7 @@ public:
_FORCE_INLINE_ Vector3 get_endpoint(int p_point) 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 project_range_in_plane(const Plane& p_plane,real_t &r_min,real_t& r_max) const;
_FORCE_INLINE_ void expand_to(const Vector3& p_vector); /** expand to contain a point if necesary */
operator String() const;
@ -293,13 +295,13 @@ inline void Rect3::expand_to(const Vector3& p_vector) {
size=end-begin;
}
void Rect3::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,real_t &r_min,real_t& r_max) const {
Vector3 half_extents( size.x * 0.5, size.y * 0.5, size.z * 0.5 );
Vector3 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 );
real_t length = p_plane.normal.abs().dot(half_extents);
real_t distance = p_plane.distance_to( center );
r_min = distance - length;
r_max = distance + length;
}
@ -334,14 +336,14 @@ inline real_t Rect3::get_shortest_axis_size() const {
return max_size;
}
bool Rect3::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, real_t t0, real_t t1) const {
float divx=1.0/dir.x;
float divy=1.0/dir.y;
float divz=1.0/dir.z;
real_t divx=1.0/dir.x;
real_t divy=1.0/dir.y;
real_t divz=1.0/dir.z;
Vector3 upbound=pos+size;
float tmin, tmax, tymin, tymax, tzmin, tzmax;
real_t tmin, tmax, tymin, tymax, tzmin, tzmax;
if (dir.x >= 0) {
tmin = (pos.x - from.x) * divx;
tmax = (upbound.x - from.x) * divx;

View file

@ -340,7 +340,7 @@ bool TriangleMesh::intersect_segment(const Vector3& p_begin,const Vector3& p_end
if (f3.intersects_segment(p_begin,p_end,&res)) {
float nd = n.dot(res);
real_t nd = n.dot(res);
if (nd<d) {
d=nd;
@ -462,7 +462,7 @@ bool TriangleMesh::intersect_ray(const Vector3& p_begin,const Vector3& p_dir,Vec
if (f3.intersects_ray(p_begin,p_dir,&res)) {
float nd = n.dot(res);
real_t nd = n.dot(res);
if (nd<d) {
d=nd;

View file

@ -28,19 +28,19 @@
/*************************************************************************/
#include "triangulate.h"
float Triangulate::get_area(const Vector<Vector2> &contour)
real_t Triangulate::get_area(const Vector<Vector2> &contour)
{
int n = contour.size();
const Vector2 *c=&contour[0];
float A=0.0f;
real_t A=0.0;
for(int p=n-1,q=0; q<n; p=q++)
{
A+= c[p].cross(c[q]);
}
return A*0.5f;
return A*0.5;
}
/*
@ -48,14 +48,14 @@ float Triangulate::get_area(const Vector<Vector2> &contour)
defined by A, B, C.
*/
bool Triangulate::is_inside_triangle(float Ax, float Ay,
float Bx, float By,
float Cx, float Cy,
float Px, float Py)
bool Triangulate::is_inside_triangle(real_t Ax, real_t Ay,
real_t Bx, real_t By,
real_t Cx, real_t Cy,
real_t Px, real_t Py)
{
float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
float cCROSSap, bCROSScp, aCROSSbp;
real_t ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
real_t cCROSSap, bCROSScp, aCROSSbp;
ax = Cx - Bx; ay = Cy - By;
bx = Ax - Cx; by = Ay - Cy;
@ -68,13 +68,13 @@ bool Triangulate::is_inside_triangle(float Ax, float Ay,
cCROSSap = cx*apy - cy*apx;
bCROSScp = bx*cpy - by*cpx;
return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
return ((aCROSSbp >= 0.0) && (bCROSScp >= 0.0) && (cCROSSap >= 0.0));
};
bool Triangulate::snip(const Vector<Vector2> &p_contour,int u,int v,int w,int n,const Vector<int>& V)
{
int p;
float Ax, Ay, Bx, By, Cx, Cy, Px, Py;
real_t Ax, Ay, Bx, By, Cx, Cy, Px, Py;
const Vector2 *contour=&p_contour[0];
Ax = contour[V[u]].x;
@ -112,7 +112,7 @@ bool Triangulate::triangulate(const Vector<Vector2> &contour,Vector<int> &result
/* we want a counter-clockwise polygon in V */
if ( 0.0f < get_area(contour) )
if ( 0.0 < get_area(contour) )
for (int v=0; v<n; v++) V[v] = v;
else
for(int v=0; v<n; v++) V[v] = (n-1)-v;

View file

@ -45,14 +45,14 @@ public:
static bool triangulate(const Vector< Vector2 > &contour, Vector<int> &result);
// compute area of a contour/polygon
static float get_area(const Vector< Vector2 > &contour);
static real_t get_area(const Vector< Vector2 > &contour);
// decide if point Px/Py is inside triangle defined by
// (Ax,Ay) (Bx,By) (Cx,Cy)
static bool is_inside_triangle(float Ax, float Ay,
float Bx, float By,
float Cx, float Cy,
float Px, float Py);
static bool is_inside_triangle(real_t Ax, real_t Ay,
real_t Bx, real_t By,
real_t Cx, real_t Cy,
real_t Px, real_t Py);
private:

View file

@ -30,12 +30,12 @@
#include "matrix3.h"
void Vector3::rotate(const Vector3& p_axis,float p_phi) {
void Vector3::rotate(const Vector3& p_axis,real_t p_phi) {
*this=Basis(p_axis,p_phi).xform(*this);
}
Vector3 Vector3::rotated(const Vector3& p_axis,float p_phi) const {
Vector3 Vector3::rotated(const Vector3& p_axis,real_t p_phi) const {
Vector3 r = *this;
r.rotate(p_axis,p_phi);
@ -63,13 +63,13 @@ int Vector3::max_axis() const {
}
void Vector3::snap(float p_val) {
void Vector3::snap(real_t p_val) {
x=Math::stepify(x,p_val);
y=Math::stepify(y,p_val);
z=Math::stepify(z,p_val);
}
Vector3 Vector3::snapped(float p_val) const {
Vector3 Vector3::snapped(real_t p_val) const {
Vector3 v=*this;
v.snap(p_val);
@ -77,7 +77,7 @@ Vector3 Vector3::snapped(float p_val) const {
}
Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const {
Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const {
Vector3 p0=p_pre_a;
Vector3 p1=*this;
@ -87,9 +87,9 @@ Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, c
{
//normalize
float ab = p0.distance_to(p1);
float bc = p1.distance_to(p2);
float cd = p2.distance_to(p3);
real_t ab = p0.distance_to(p1);
real_t bc = p1.distance_to(p2);
real_t cd = p2.distance_to(p3);
if (ab>0)
p0 = p1+(p0-p1)*(bc/ab);
@ -98,41 +98,41 @@ Vector3 Vector3::cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, c
}
float t = p_t;
float t2 = t * t;
float t3 = t2 * t;
real_t t = p_t;
real_t t2 = t * t;
real_t t3 = t2 * t;
Vector3 out;
out = 0.5f * ( ( p1 * 2.0f) +
out = 0.5 * ( ( p1 * 2.0) +
( -p0 + p2 ) * t +
( 2.0f * p0 - 5.0f * p1 + 4 * p2 - p3 ) * t2 +
( -p0 + 3.0f * p1 - 3.0f * p2 + p3 ) * t3 );
( 2.0 * p0 - 5.0 * p1 + 4 * p2 - p3 ) * t2 +
( -p0 + 3.0 * p1 - 3.0 * p2 + p3 ) * t3 );
return out;
}
Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const {
Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const {
Vector3 p0=p_pre_a;
Vector3 p1=*this;
Vector3 p2=p_b;
Vector3 p3=p_post_b;
float t = p_t;
float t2 = t * t;
float t3 = t2 * t;
real_t t = p_t;
real_t t2 = t * t;
real_t t3 = t2 * t;
Vector3 out;
out = 0.5f * ( ( p1 * 2.0f) +
out = 0.5 * ( ( p1 * 2.0) +
( -p0 + p2 ) * t +
( 2.0f * p0 - 5.0f * p1 + 4 * p2 - p3 ) * t2 +
( -p0 + 3.0f * p1 - 3.0f * p2 + p3 ) * t3 );
( 2.0 * p0 - 5.0 * p1 + 4 * p2 - p3 ) * t2 +
( -p0 + 3.0 * p1 - 3.0 * p2 + p3 ) * t3 );
return out;
}
#if 0
Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const {
Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const {
Vector3 p0=p_pre_a;
Vector3 p1=*this;
@ -141,9 +141,9 @@ Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, co
if (true) {
float ab = p0.distance_to(p1);
float bc = p1.distance_to(p2);
float cd = p2.distance_to(p3);
real_t ab = p0.distance_to(p1);
real_t bc = p1.distance_to(p2);
real_t cd = p2.distance_to(p3);
//if (ab>bc) {
if (ab>0)
@ -156,23 +156,23 @@ Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, co
//}
}
float t = p_t;
float t2 = t * t;
float t3 = t2 * t;
real_t t = p_t;
real_t t2 = t * t;
real_t t3 = t2 * t;
Vector3 out;
out.x = 0.5f * ( ( 2.0f * p1.x ) +
out.x = 0.5 * ( ( 2.0 * p1.x ) +
( -p0.x + p2.x ) * t +
( 2.0f * p0.x - 5.0f * p1.x + 4 * p2.x - p3.x ) * t2 +
( -p0.x + 3.0f * p1.x - 3.0f * p2.x + p3.x ) * t3 );
out.y = 0.5f * ( ( 2.0f * p1.y ) +
( 2.0 * p0.x - 5.0 * p1.x + 4 * p2.x - p3.x ) * t2 +
( -p0.x + 3.0 * p1.x - 3.0 * p2.x + p3.x ) * t3 );
out.y = 0.5 * ( ( 2.0 * p1.y ) +
( -p0.y + p2.y ) * t +
( 2.0f * p0.y - 5.0f * p1.y + 4 * p2.y - p3.y ) * t2 +
( -p0.y + 3.0f * p1.y - 3.0f * p2.y + p3.y ) * t3 );
out.z = 0.5f * ( ( 2.0f * p1.z ) +
( 2.0 * p0.y - 5.0 * p1.y + 4 * p2.y - p3.y ) * t2 +
( -p0.y + 3.0 * p1.y - 3.0 * p2.y + p3.y ) * t3 );
out.z = 0.5 * ( ( 2.0 * p1.z ) +
( -p0.z + p2.z ) * t +
( 2.0f * p0.z - 5.0f * p1.z + 4 * p2.z - p3.z ) * t2 +
( -p0.z + 3.0f * p1.z - 3.0f * p2.z + p3.z ) * t3 );
( 2.0 * p0.z - 5.0 * p1.z + 4 * p2.z - p3.z ) * t2 +
( -p0.z + 3.0 * p1.z - 3.0 * p2.z + p3.z ) * t3 );
return out;
}
# endif

View file

@ -79,17 +79,17 @@ struct Vector3 {
_FORCE_INLINE_ void zero();
void snap(float p_val);
Vector3 snapped(float p_val) const;
void snap(real_t p_val);
Vector3 snapped(real_t p_val) const;
void rotate(const Vector3& p_axis,float p_phi);
Vector3 rotated(const Vector3& p_axis,float p_phi) const;
void rotate(const Vector3& p_axis,real_t p_phi);
Vector3 rotated(const Vector3& p_axis,real_t p_phi) const;
/* Static Methods between 2 vector3s */
_FORCE_INLINE_ Vector3 linear_interpolate(const Vector3& p_b,float p_t) const;
Vector3 cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const;
Vector3 cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,float p_t) const;
_FORCE_INLINE_ Vector3 linear_interpolate(const Vector3& p_b,real_t p_t) const;
Vector3 cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const;
Vector3 cubic_interpolaten(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const;
_FORCE_INLINE_ Vector3 cross(const Vector3& p_b) const;
_FORCE_INLINE_ real_t dot(const Vector3& p_b) const;
@ -195,7 +195,7 @@ Vector3 Vector3::ceil() const {
return Vector3( Math::ceil(x), Math::ceil(y), Math::ceil(z) );
}
Vector3 Vector3::linear_interpolate(const Vector3& p_b,float p_t) const {
Vector3 Vector3::linear_interpolate(const Vector3& p_b,real_t p_t) const {
return Vector3(
x+(p_t * (p_b.x-x)),

View file

@ -166,7 +166,7 @@ void RasterizerSceneGLES3::shadow_atlas_set_quadrant_subdivision(RID p_atlas,int
subdiv<<=1;
}
subdiv=int(Math::sqrt(subdiv));
subdiv=int(Math::sqrt((float)subdiv));
//obtain the number that will be x*x
@ -568,7 +568,7 @@ void RasterizerSceneGLES3::reflection_atlas_set_subdivision(RID p_ref_atlas,int
subdiv<<=1;
}
subdiv=int(Math::sqrt(subdiv));
subdiv=int(Math::sqrt((float)subdiv));
if (reflection_atlas->subdiv==subdiv)
return;
@ -4567,7 +4567,7 @@ static _FORCE_INLINE_ Vector3 ImportanceSampleGGX(Vector2 Xi, float Roughness, V
// Compute distribution direction
float Phi = 2.0f * Math_PI * Xi.x;
float CosTheta = Math::sqrt((1.0f - Xi.y) / (1.0f + (a*a - 1.0f) * Xi.y));
float CosTheta = Math::sqrt((float)(1.0f - Xi.y) / (1.0f + (a*a - 1.0f) * Xi.y));
float SinTheta = Math::sqrt((float)Math::abs(1.0f - CosTheta * CosTheta));
// Convert to spherical direction
@ -4615,7 +4615,7 @@ void RasterizerSceneGLES3::_generate_brdf() {
float NoV = float(i+1)/(brdf_size); //avoid storing nov0
Vector3 V;
V.x = Math::sqrt( 1.0 - NoV * NoV );
V.x = Math::sqrt( 1.0f - NoV * NoV );
V.y = 0.0;
V.z = NoV;

View file

@ -5256,7 +5256,7 @@ void RasterizerStorageGLES3::update_particles() {
shaders.particles.set_uniform(ParticlesShaderGLES3::ORIGIN,particles->origin);
float new_phase = Math::fmod(particles->phase+(frame.delta/particles->lifetime),1.0);
float new_phase = Math::fmod((float)particles->phase+(frame.delta/particles->lifetime),(float)1.0);
shaders.particles.set_uniform(ParticlesShaderGLES3::SYSTEM_PHASE,new_phase);
shaders.particles.set_uniform(ParticlesShaderGLES3::PREV_SYSTEM_PHASE,particles->phase);

View file

@ -159,85 +159,85 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
case MATH_SIN: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::sin(*p_args[0]);
r_ret=Math::sin((double)*p_args[0]);
} break;
case MATH_COS: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::cos(*p_args[0]);
r_ret=Math::cos((double)*p_args[0]);
} break;
case MATH_TAN: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::tan(*p_args[0]);
r_ret=Math::tan((double)*p_args[0]);
} break;
case MATH_SINH: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::sinh(*p_args[0]);
r_ret=Math::sinh((double)*p_args[0]);
} break;
case MATH_COSH: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::cosh(*p_args[0]);
r_ret=Math::cosh((double)*p_args[0]);
} break;
case MATH_TANH: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::tanh(*p_args[0]);
r_ret=Math::tanh((double)*p_args[0]);
} break;
case MATH_ASIN: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::asin(*p_args[0]);
r_ret=Math::asin((double)*p_args[0]);
} break;
case MATH_ACOS: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::acos(*p_args[0]);
r_ret=Math::acos((double)*p_args[0]);
} break;
case MATH_ATAN: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::atan(*p_args[0]);
r_ret=Math::atan((double)*p_args[0]);
} break;
case MATH_ATAN2: {
VALIDATE_ARG_COUNT(2);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
r_ret=Math::atan2(*p_args[0],*p_args[1]);
r_ret=Math::atan2((double)*p_args[0],(double)*p_args[1]);
} break;
case MATH_SQRT: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::sqrt(*p_args[0]);
r_ret=Math::sqrt((double)*p_args[0]);
} break;
case MATH_FMOD: {
VALIDATE_ARG_COUNT(2);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
r_ret=Math::fmod(*p_args[0],*p_args[1]);
r_ret=Math::fmod((double)*p_args[0],(double)*p_args[1]);
} break;
case MATH_FPOSMOD: {
VALIDATE_ARG_COUNT(2);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
r_ret=Math::fposmod(*p_args[0],*p_args[1]);
r_ret=Math::fposmod((double)*p_args[0],(double)*p_args[1]);
} break;
case MATH_FLOOR: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::floor(*p_args[0]);
r_ret=Math::floor((double)*p_args[0]);
} break;
case MATH_CEIL: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::ceil(*p_args[0]);
r_ret=Math::ceil((double)*p_args[0]);
} break;
case MATH_ROUND: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::round(*p_args[0]);
r_ret=Math::round((double)*p_args[0]);
} break;
case MATH_ABS: {
VALIDATE_ARG_COUNT(1);
@ -247,7 +247,7 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
r_ret=ABS(i);
} else if (p_args[0]->get_type()==Variant::REAL) {
real_t r = *p_args[0];
double r = *p_args[0];
r_ret=Math::abs(r);
} else {
@ -279,58 +279,58 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
VALIDATE_ARG_COUNT(2);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
r_ret=Math::pow(*p_args[0],*p_args[1]);
r_ret=Math::pow((double)*p_args[0],(double)*p_args[1]);
} break;
case MATH_LOG: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::log(*p_args[0]);
r_ret=Math::log((double)*p_args[0]);
} break;
case MATH_EXP: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::exp(*p_args[0]);
r_ret=Math::exp((double)*p_args[0]);
} break;
case MATH_ISNAN: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::is_nan(*p_args[0]);
r_ret=Math::is_nan((double)*p_args[0]);
} break;
case MATH_ISINF: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::is_inf(*p_args[0]);
r_ret=Math::is_inf((double)*p_args[0]);
} break;
case MATH_EASE: {
VALIDATE_ARG_COUNT(2);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
r_ret=Math::ease(*p_args[0],*p_args[1]);
r_ret=Math::ease((double)*p_args[0],(double)*p_args[1]);
} break;
case MATH_DECIMALS: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::step_decimals(*p_args[0]);
r_ret=Math::step_decimals((double)*p_args[0]);
} break;
case MATH_STEPIFY: {
VALIDATE_ARG_COUNT(2);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
r_ret=Math::stepify(*p_args[0],*p_args[1]);
r_ret=Math::stepify((double)*p_args[0],(double)*p_args[1]);
} break;
case MATH_LERP: {
VALIDATE_ARG_COUNT(3);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
r_ret=Math::lerp(*p_args[0],*p_args[1],*p_args[2]);
r_ret=Math::lerp((double)*p_args[0],(double)*p_args[1],(double)*p_args[2]);
} break;
case MATH_DECTIME: {
VALIDATE_ARG_COUNT(3);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
r_ret=Math::dectime(*p_args[0],*p_args[1],*p_args[2]);
r_ret=Math::dectime((double)*p_args[0],(double)*p_args[1],(double)*p_args[2]);
} break;
case MATH_RANDOMIZE: {
Math::randomize();
@ -346,7 +346,7 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
VALIDATE_ARG_COUNT(2);
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
r_ret=Math::random(*p_args[0],*p_args[1]);
r_ret=Math::random((double)*p_args[0],(double)*p_args[1]);
} break;
case MATH_SEED: {
VALIDATE_ARG_COUNT(1);
@ -369,22 +369,22 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
case MATH_DEG2RAD: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::deg2rad(*p_args[0]);
r_ret=Math::deg2rad((double)*p_args[0]);
} break;
case MATH_RAD2DEG: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::rad2deg(*p_args[0]);
r_ret=Math::rad2deg((double)*p_args[0]);
} break;
case MATH_LINEAR2DB: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::linear2db(*p_args[0]);
r_ret=Math::linear2db((double)*p_args[0]);
} break;
case MATH_DB2LINEAR: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
r_ret=Math::db2linear(*p_args[0]);
r_ret=Math::db2linear((double)*p_args[0]);
} break;
case LOGIC_MAX: {
VALIDATE_ARG_COUNT(2);

View file

@ -610,85 +610,85 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp
case VisualScriptBuiltinFunc::MATH_SIN: {
VALIDATE_ARG_NUM(0);
*r_return=Math::sin(*p_inputs[0]);
*r_return=Math::sin((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_COS: {
VALIDATE_ARG_NUM(0);
*r_return=Math::cos(*p_inputs[0]);
*r_return=Math::cos((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_TAN: {
VALIDATE_ARG_NUM(0);
*r_return=Math::tan(*p_inputs[0]);
*r_return=Math::tan((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_SINH: {
VALIDATE_ARG_NUM(0);
*r_return=Math::sinh(*p_inputs[0]);
*r_return=Math::sinh((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_COSH: {
VALIDATE_ARG_NUM(0);
*r_return=Math::cosh(*p_inputs[0]);
*r_return=Math::cosh((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_TANH: {
VALIDATE_ARG_NUM(0);
*r_return=Math::tanh(*p_inputs[0]);
*r_return=Math::tanh((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ASIN: {
VALIDATE_ARG_NUM(0);
*r_return=Math::asin(*p_inputs[0]);
*r_return=Math::asin((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ACOS: {
VALIDATE_ARG_NUM(0);
*r_return=Math::acos(*p_inputs[0]);
*r_return=Math::acos((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ATAN: {
VALIDATE_ARG_NUM(0);
*r_return=Math::atan(*p_inputs[0]);
*r_return=Math::atan((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ATAN2: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return=Math::atan2(*p_inputs[0],*p_inputs[1]);
*r_return=Math::atan2((double)*p_inputs[0],(double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_SQRT: {
VALIDATE_ARG_NUM(0);
*r_return=Math::sqrt(*p_inputs[0]);
*r_return=Math::sqrt((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_FMOD: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return=Math::fmod(*p_inputs[0],*p_inputs[1]);
*r_return=Math::fmod((double)*p_inputs[0],(double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_FPOSMOD: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return=Math::fposmod(*p_inputs[0],*p_inputs[1]);
*r_return=Math::fposmod((double)*p_inputs[0],(double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_FLOOR: {
VALIDATE_ARG_NUM(0);
*r_return=Math::floor(*p_inputs[0]);
*r_return=Math::floor((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_CEIL: {
VALIDATE_ARG_NUM(0);
*r_return=Math::ceil(*p_inputs[0]);
*r_return=Math::ceil((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ROUND: {
VALIDATE_ARG_NUM(0);
*r_return=Math::round(*p_inputs[0]);
*r_return=Math::round((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ABS: {
@ -730,58 +730,58 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return=Math::pow(*p_inputs[0],*p_inputs[1]);
*r_return=Math::pow((double)*p_inputs[0],(double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_LOG: {
VALIDATE_ARG_NUM(0);
*r_return=Math::log(*p_inputs[0]);
*r_return=Math::log((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_EXP: {
VALIDATE_ARG_NUM(0);
*r_return=Math::exp(*p_inputs[0]);
*r_return=Math::exp((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ISNAN: {
VALIDATE_ARG_NUM(0);
*r_return=Math::is_nan(*p_inputs[0]);
*r_return=Math::is_nan((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_ISINF: {
VALIDATE_ARG_NUM(0);
*r_return=Math::is_inf(*p_inputs[0]);
*r_return=Math::is_inf((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_EASE: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return=Math::ease(*p_inputs[0],*p_inputs[1]);
*r_return=Math::ease((double)*p_inputs[0],(double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_DECIMALS: {
VALIDATE_ARG_NUM(0);
*r_return=Math::step_decimals(*p_inputs[0]);
*r_return=Math::step_decimals((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_STEPIFY: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return=Math::stepify(*p_inputs[0],*p_inputs[1]);
*r_return=Math::stepify((double)*p_inputs[0],(double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_LERP: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
*r_return=Math::lerp(*p_inputs[0],*p_inputs[1],*p_inputs[2]);
*r_return=Math::lerp((double)*p_inputs[0],(double)*p_inputs[1],(double)*p_inputs[2]);
} break;
case VisualScriptBuiltinFunc::MATH_DECTIME: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
VALIDATE_ARG_NUM(2);
*r_return=Math::dectime(*p_inputs[0],*p_inputs[1],*p_inputs[2]);
*r_return=Math::dectime((double)*p_inputs[0],(double)*p_inputs[1],(double)*p_inputs[2]);
} break;
case VisualScriptBuiltinFunc::MATH_RANDOMIZE: {
Math::randomize();
@ -797,7 +797,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
*r_return=Math::random(*p_inputs[0],*p_inputs[1]);
*r_return=Math::random((double)*p_inputs[0],(double)*p_inputs[1]);
} break;
case VisualScriptBuiltinFunc::MATH_SEED: {
@ -820,22 +820,22 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func,const Variant** p_inp
case VisualScriptBuiltinFunc::MATH_DEG2RAD: {
VALIDATE_ARG_NUM(0);
*r_return=Math::deg2rad(*p_inputs[0]);
*r_return=Math::deg2rad((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_RAD2DEG: {
VALIDATE_ARG_NUM(0);
*r_return=Math::rad2deg(*p_inputs[0]);
*r_return=Math::rad2deg((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_LINEAR2DB: {
VALIDATE_ARG_NUM(0);
*r_return=Math::linear2db(*p_inputs[0]);
*r_return=Math::linear2db((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::MATH_DB2LINEAR: {
VALIDATE_ARG_NUM(0);
*r_return=Math::db2linear(*p_inputs[0]);
*r_return=Math::db2linear((double)*p_inputs[0]);
} break;
case VisualScriptBuiltinFunc::LOGIC_MAX: {

View file

@ -364,7 +364,7 @@ void Particles2D::_process_particles(float p_delta) {
p.rot=Math::deg2rad(param[PARAM_INITIAL_ANGLE]+param[PARAM_INITIAL_ANGLE]*randomness[PARAM_INITIAL_ANGLE]*_rand_from_seed(&rand_seed));
active_count++;
p.frame=Math::fmod(param[PARAM_ANIM_INITIAL_POS]+randomness[PARAM_ANIM_INITIAL_POS]*_rand_from_seed(&rand_seed),1.0);
p.frame=Math::fmod(param[PARAM_ANIM_INITIAL_POS]+randomness[PARAM_ANIM_INITIAL_POS]*_rand_from_seed(&rand_seed),1.0f);
} else {
@ -438,7 +438,7 @@ void Particles2D::_process_particles(float p_delta) {
p.pos+=p.velocity*frame_time;
p.rot+=Math::lerp(param[PARAM_SPIN_VELOCITY],param[PARAM_SPIN_VELOCITY]*randomness[PARAM_SPIN_VELOCITY]*_rand_from_seed(&rand_seed),randomness[PARAM_SPIN_VELOCITY])*frame_time;
float anim_spd=param[PARAM_ANIM_SPEED_SCALE]+param[PARAM_ANIM_SPEED_SCALE]*randomness[PARAM_ANIM_SPEED_SCALE]*_rand_from_seed(&rand_seed);
p.frame=Math::fposmod(p.frame+(frame_time/lifetime)*anim_spd,1.0);
p.frame=Math::fposmod(p.frame+(frame_time/lifetime)*anim_spd,1.0f);
active_count++;
@ -555,7 +555,7 @@ void Particles2D::_notification(int p_what) {
float a=color.a;
//float preh=h;
h+=huerot;
h=Math::abs(Math::fposmod(h,1.0));
h=Math::abs(Math::fposmod(h,1.0f));
//print_line("rand: "+rtos(randomness[PARAM_HUE_VARIATION])+" rand: "+rtos(huerand));
//print_line(itos(i)+":hue: "+rtos(preh)+" + "+rtos(huerot)+" = "+rtos(h));
color.set_hsv(h,s,v);

View file

@ -1262,7 +1262,7 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2& p_linear_velocity,const V
//all is a wall
move_and_slide_on_wall=true;
} else {
if ( get_collision_normal().dot(p_floor_direction) > Math::cos(Math::deg2rad(45))) { //floor
if ( get_collision_normal().dot(p_floor_direction) > Math::cos(Math::deg2rad((float)45))) { //floor
move_and_slide_on_floor=true;
@ -1272,7 +1272,7 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2& p_linear_velocity,const V
revert_motion();
return Vector2();
}
} else if ( get_collision_normal().dot(p_floor_direction) < Math::cos(Math::deg2rad(45))) { //ceiling
} else if ( get_collision_normal().dot(p_floor_direction) < Math::cos(Math::deg2rad((float)45))) { //ceiling
move_and_slide_on_ceiling=true;
} else {
move_and_slide_on_wall=true;

View file

@ -389,8 +389,8 @@ void BakedLight::_plot_face(int p_idx, int p_level, const Vector3 *p_vtx, const
Vector2 uv = get_uv(intersection,p_vtx,p_uv);
int uv_x = CLAMP(Math::fposmod(uv.x,1.0)*bake_texture_size,0,bake_texture_size-1);
int uv_y = CLAMP(Math::fposmod(uv.y,1.0)*bake_texture_size,0,bake_texture_size-1);
int uv_x = CLAMP(Math::fposmod(uv.x,1.0f)*bake_texture_size,0,bake_texture_size-1);
int uv_y = CLAMP(Math::fposmod(uv.y,1.0f)*bake_texture_size,0,bake_texture_size-1);
int ofs = uv_y*bake_texture_size+uv_x;
albedo_accum.r+=p_material.albedo[ofs].r;
@ -415,8 +415,8 @@ void BakedLight::_plot_face(int p_idx, int p_level, const Vector3 *p_vtx, const
Vector2 uv = get_uv(inters,p_vtx,p_uv);
int uv_x = CLAMP(Math::fposmod(uv.x,1.0)*bake_texture_size,0,bake_texture_size-1);
int uv_y = CLAMP(Math::fposmod(uv.y,1.0)*bake_texture_size,0,bake_texture_size-1);
int uv_x = CLAMP(Math::fposmod(uv.x,1.0f)*bake_texture_size,0,bake_texture_size-1);
int uv_y = CLAMP(Math::fposmod(uv.y,1.0f)*bake_texture_size,0,bake_texture_size-1);
int ofs = uv_y*bake_texture_size+uv_x;

View file

@ -510,8 +510,8 @@ void GIProbe::_plot_face(int p_idx, int p_level,int p_x,int p_y,int p_z, const V
Vector2 uv = get_uv(intersection,p_vtx,p_uv);
int uv_x = CLAMP(Math::fposmod(uv.x,1.0)*bake_texture_size,0,bake_texture_size-1);
int uv_y = CLAMP(Math::fposmod(uv.y,1.0)*bake_texture_size,0,bake_texture_size-1);
int uv_x = CLAMP(Math::fposmod(uv.x,1.0f)*bake_texture_size,0,bake_texture_size-1);
int uv_y = CLAMP(Math::fposmod(uv.y,1.0f)*bake_texture_size,0,bake_texture_size-1);
int ofs = uv_y*bake_texture_size+uv_x;
albedo_accum.r+=p_material.albedo[ofs].r;
@ -539,8 +539,8 @@ void GIProbe::_plot_face(int p_idx, int p_level,int p_x,int p_y,int p_z, const V
Vector2 uv = get_uv(inters,p_vtx,p_uv);
int uv_x = CLAMP(Math::fposmod(uv.x,1.0)*bake_texture_size,0,bake_texture_size-1);
int uv_y = CLAMP(Math::fposmod(uv.y,1.0)*bake_texture_size,0,bake_texture_size-1);
int uv_x = CLAMP(Math::fposmod(uv.x,1.0f)*bake_texture_size,0,bake_texture_size-1);
int uv_y = CLAMP(Math::fposmod(uv.y,1.0f)*bake_texture_size,0,bake_texture_size-1);
int ofs = uv_y*bake_texture_size+uv_x;

View file

@ -476,7 +476,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData* p_anim,float p
}
#endif
static_cast<Node2D*>(pa->object)->set_rotation(Math::deg2rad(value));
static_cast<Node2D*>(pa->object)->set_rotation(Math::deg2rad((double)value));
} break;
case SP_NODE2D_SCALE: {
#ifdef DEBUG_ENABLED
@ -690,7 +690,7 @@ void AnimationPlayer::_animation_update_transforms() {
}
#endif
static_cast<Node2D*>(pa->object)->set_rotation(Math::deg2rad(pa->value_accum));
static_cast<Node2D*>(pa->object)->set_rotation(Math::deg2rad((double)pa->value_accum));
} break;
case SP_NODE2D_SCALE: {
#ifdef DEBUG_ENABLED

View file

@ -141,8 +141,8 @@ void Range::set_as_ratio(double p_value) {
if (shared->exp_ratio && get_min()>0) {
double exp_min = Math::log(get_min())/Math::log(2);
double exp_max = Math::log(get_max())/Math::log(2);
double exp_min = Math::log(get_min())/Math::log((double)2);
double exp_max = Math::log(get_max())/Math::log((double)2);
v = Math::pow(2,exp_min+(exp_max-exp_min)*p_value);
} else {
@ -160,9 +160,9 @@ double Range::get_as_ratio() const {
if (shared->exp_ratio && get_min()>0) {
double exp_min = Math::log(get_min())/Math::log(2);
double exp_max = Math::log(get_max())/Math::log(2);
double v = Math::log(get_value())/Math::log(2);
double exp_min = Math::log(get_min())/Math::log((double)2);
double exp_max = Math::log(get_max())/Math::log((double)2);
double v = Math::log(get_value())/Math::log((double)2);
return (v - exp_min) / (exp_max - exp_min);

View file

@ -162,7 +162,7 @@ void SpinBox::_gui_input(const InputEvent& p_event) {
if (drag.enabled) {
float diff_y = drag.mouse_pos.y - cpos.y;
diff_y=Math::pow(ABS(diff_y),1.8)*SGN(diff_y);
diff_y=Math::pow(ABS(diff_y),1.8f)*SGN(diff_y);
diff_y*=0.1;
drag.mouse_pos=cpos;

View file

@ -943,7 +943,7 @@ void Tree::draw_item_rect(const TreeItem::Cell& p_cell,const Rect2i& p_rect,cons
bmsize.width=p_cell.icon_max_w;
}
p_cell.draw_icon(ci,rect.pos + Size2i(0,Math::floor((rect.size.y-bmsize.y)/2)),bmsize);
p_cell.draw_icon(ci,rect.pos + Size2i(0,Math::floor((real_t)(rect.size.y-bmsize.y)/2)),bmsize);
rect.pos.x+=bmsize.x+cache.hseparation;
rect.size.x-=bmsize.x+cache.hseparation;
@ -1173,7 +1173,7 @@ int Tree::draw_item(const Point2i& p_pos,const Point2& p_draw_ofs, const Size2&
Ref<Texture> checked = cache.checked;
Ref<Texture> unchecked = cache.unchecked;
Point2i check_ofs=item_rect.pos;
check_ofs.y+=Math::floor((item_rect.size.y-checked->get_height())/2);
check_ofs.y+=Math::floor((real_t)(item_rect.size.y-checked->get_height())/2);
if (p_item->cells[i].checked) {
@ -2321,7 +2321,7 @@ void Tree::_gui_input(InputEvent p_event) {
TreeItem::Cell &c=popup_edited_item->cells[popup_edited_item_col];
float diff_y = -b.relative_y;
diff_y=Math::pow(ABS(diff_y),1.8)*SGN(diff_y);
diff_y=Math::pow(ABS(diff_y),1.8f)*SGN(diff_y);
diff_y*=0.1;
range_drag_base=CLAMP(range_drag_base + c.step * diff_y, c.min, c.max);
popup_edited_item->set_range(popup_edited_item_col,range_drag_base);

View file

@ -42,8 +42,8 @@ Vector<Vector3> CapsuleShape::_gen_debug_mesh_lines() {
Vector3 d(0,0,height*0.5);
for(int i=0;i<360;i++) {
float ra=Math::deg2rad(i);
float rb=Math::deg2rad(i+1);
float ra=Math::deg2rad((float)i);
float rb=Math::deg2rad((float)i+1);
Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*radius;
Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*radius;

View file

@ -498,7 +498,7 @@ Vector2 Curve2D::interpolatef(real_t p_findex) const {
else if (p_findex>=points.size())
p_findex=points.size();
return interpolate((int)p_findex,Math::fmod(p_findex,1.0));
return interpolate((int)p_findex,Math::fmod(p_findex,(real_t)1.0));
}
@ -653,7 +653,7 @@ Vector2 Curve2D::interpolate_baked(float p_offset,bool p_cubic) const{
return r[bpc-1];
int idx = Math::floor((double)p_offset/(double)bake_interval);
float frac = Math::fmod(p_offset,bake_interval);
float frac = Math::fmod(p_offset,(float)bake_interval);
if (idx>=bpc-1) {
return r[bpc-1];
@ -974,7 +974,7 @@ Vector3 Curve3D::interpolatef(real_t p_findex) const {
else if (p_findex>=points.size())
p_findex=points.size();
return interpolate((int)p_findex,Math::fmod(p_findex,1.0));
return interpolate((int)p_findex,Math::fmod(p_findex,(real_t)1.0));
}

View file

@ -37,8 +37,8 @@ Vector<Vector3> SphereShape::_gen_debug_mesh_lines() {
for(int i=0;i<=360;i++) {
float ra=Math::deg2rad(i);
float rb=Math::deg2rad(i+1);
float ra=Math::deg2rad((float)i);
float rb=Math::deg2rad((float)i+1);
Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*r;
Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*r;

View file

@ -142,9 +142,9 @@ void AudioFilterSW::prepare_coefficients(Coeffs *p_coeffs) {
//this one is extra tricky
double hicutoff=resonance;
double centercutoff = (cutoff+resonance)/2.0;
double bandwidth=(Math::log(centercutoff)-Math::log(hicutoff))/Math::log(2);
double bandwidth=(Math::log(centercutoff)-Math::log(hicutoff))/Math::log((double)2);
omega=2.0*Math_PI*centercutoff/sampling_rate;
alpha = Math::sin(omega)*Math::sinh( Math::log(2)/2 * bandwidth * omega/Math::sin(omega) );
alpha = Math::sin(omega)*Math::sinh( Math::log((double)2)/2 * bandwidth * omega/Math::sin(omega) );
a0=1+alpha;
p_coeffs->b0 = alpha;

View file

@ -539,14 +539,14 @@ int BroadPhase2DHashGrid::cull_segment(const Vector2& p_from, const Vector2& p_t
Vector2 max;
if (dir.x<0)
max.x= (Math::floor(pos.x)*cell_size - p_from.x) / dir.x;
max.x= (Math::floor((double)pos.x)*cell_size - p_from.x) / dir.x;
else
max.x= (Math::floor(pos.x + 1)*cell_size - p_from.x) / dir.x;
max.x= (Math::floor((double)pos.x + 1)*cell_size - p_from.x) / dir.x;
if (dir.y<0)
max.y= (Math::floor(pos.y)*cell_size - p_from.y) / dir.y;
max.y= (Math::floor((double)pos.y)*cell_size - p_from.y) / dir.y;
else
max.y= (Math::floor(pos.y + 1)*cell_size - p_from.y) / dir.y;
max.y= (Math::floor((double)pos.y + 1)*cell_size - p_from.y) / dir.y;
int cullcount=0;
_cull<false,true>(pos,Rect2(),p_from,p_to,p_results,p_max_results,p_result_indices,cullcount);

View file

@ -179,12 +179,12 @@ private:
bool sg = val < 0;
val = Math::absf(val);
val = Math::log(val)/Math::log(2);
val = Math::log(val)/Math::log((float)2.0);
//logspace
val+=rel*0.05;
//
val = Math::pow(2,val);
val = Math::pow((float)2.0,val);
if (sg)
val=-val;
@ -1055,9 +1055,9 @@ float AnimationKeyEditor::_get_zoom_scale() const {
float zv = zoom->get_value();
if (zv<1) {
zv = 1.0-zv;
return Math::pow(1.0+zv,8.0)*100;
return Math::pow(1.0f+zv,8.0f)*100;
} else {
return 1.0/Math::pow(zv,8.0)*100;
return 1.0/Math::pow(zv,8.0f)*100;
}
}
@ -1487,8 +1487,8 @@ void AnimationKeyEditor::_track_editor_draw() {
//draw the keys;
int tt = animation->track_get_type(idx);
float key_vofs = Math::floor((h - type_icon[tt]->get_height())/2);
float key_hofs = -Math::floor(type_icon[tt]->get_height()/2);
float key_vofs = Math::floor((float)(h - type_icon[tt]->get_height())/2);
float key_hofs = -Math::floor((float)type_icon[tt]->get_height()/2);
int kc=animation->track_get_key_count(idx);
bool first=true;
@ -1592,8 +1592,8 @@ void AnimationKeyEditor::_track_editor_draw() {
continue;
int y = h+i*h+sep;
float key_vofs = Math::floor((h - type_selected->get_height())/2);
float key_hofs = -Math::floor(type_selected->get_height()/2);
float key_vofs = Math::floor((float)(h - type_selected->get_height())/2);
float key_hofs = -Math::floor((float)type_selected->get_height()/2);
float time = animation->track_get_key_time(idx,E->key().key);
float diff = time-from_t;

View file

@ -1473,7 +1473,7 @@ Ref<BitmapFont> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMe
sum+=w2[ofs_l];
}
wa[ofs]=Math::pow(float(sum/(r*2+1))/255.0,tr)*255.0;
wa[ofs]=Math::pow(float(sum/(r*2+1))/255.0f,tr)*255.0f;
}
}

View file

@ -541,7 +541,7 @@ Error EditorSampleImportPlugin::import(const String& p_path, const Ref<ResourceI
int first=0;
int last=(len*chans)-1;
bool found=false;
float limit = Math::db2linear(-30);
float limit = Math::db2linear((float)-30);
for(int i=0;i<data.size();i++) {
float amp = Math::abs(data[i]);

View file

@ -216,7 +216,7 @@ void MultiMeshEditor::_populate() {
for(int i=0;i<instance_count;i++) {
float areapos = Math::random(0,area_accum);
float areapos = Math::random(0.0f,area_accum);
Map<float,int>::Element *E = triangle_area_map.find_closest(areapos);
ERR_FAIL_COND(!E)

View file

@ -1503,12 +1503,12 @@ void CustomPropertyEditor::_drag_easing(const InputEvent& p_ev) {
bool sg = val < 0;
val = Math::absf(val);
val = Math::log(val)/Math::log(2);
val = Math::log(val)/Math::log((float)2.0);
//logspace
val+=rel*0.05;
//
val = Math::pow(2,val);
val = Math::pow(2.0f,val);
if (sg)
val=-val;

View file

@ -826,7 +826,7 @@ void ScriptEditorDebugger::_performance_draw() {
Ref<StyleBox> graph_sb = get_stylebox("normal","TextEdit");
Ref<Font> graph_font = get_font("font","TextEdit");
int cols = Math::ceil(Math::sqrt(which.size()));
int cols = Math::ceil(Math::sqrt((float)which.size()));
int rows = (which.size()+1)/cols;
if (which.size()==1)
rows=1;

View file

@ -839,8 +839,8 @@ void LightSpatialGizmo::redraw() {
for(int i=0;i<=360;i++) {
float ra=Math::deg2rad(i);
float rb=Math::deg2rad(i+1);
float ra=Math::deg2rad((float)i);
float rb=Math::deg2rad((float)i+1);
Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*r;
Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*r;
@ -881,8 +881,8 @@ void LightSpatialGizmo::redraw() {
for(int i=0;i<360;i++) {
float ra=Math::deg2rad(i);
float rb=Math::deg2rad(i+1);
float ra=Math::deg2rad((float)i);
float rb=Math::deg2rad((float)i+1);
Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*w;
Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*w;
@ -1519,8 +1519,8 @@ void VehicleWheelSpatialGizmo::redraw() {
const int skip=10;
for(int i=0;i<=360;i+=skip) {
float ra=Math::deg2rad(i);
float rb=Math::deg2rad(i+skip);
float ra=Math::deg2rad((float)i);
float rb=Math::deg2rad((float)i+skip);
Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*r;
Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*r;
@ -1826,8 +1826,8 @@ void CollisionShapeSpatialGizmo::redraw(){
for(int i=0;i<=360;i++) {
float ra=Math::deg2rad(i);
float rb=Math::deg2rad(i+1);
float ra=Math::deg2rad((float)i);
float rb=Math::deg2rad((float)i+1);
Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*r;
Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*r;
@ -1907,8 +1907,8 @@ void CollisionShapeSpatialGizmo::redraw(){
Vector3 d(0,0,height*0.5);
for(int i=0;i<360;i++) {
float ra=Math::deg2rad(i);
float rb=Math::deg2rad(i+1);
float ra=Math::deg2rad((float)i);
float rb=Math::deg2rad((float)i+1);
Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*radius;
Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*radius;
@ -2844,8 +2844,8 @@ void ConeTwistJointSpatialGizmo::redraw() {
//swing
for(int i=0;i<360;i+=10) {
float ra=Math::deg2rad(i);
float rb=Math::deg2rad(i+10);
float ra=Math::deg2rad((float)i);
float rb=Math::deg2rad((float)i+10);
Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*w;
Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*w;
@ -2876,8 +2876,8 @@ void ConeTwistJointSpatialGizmo::redraw() {
for(int i=0;i<int(ts);i+=5) {
float ra=Math::deg2rad(i);
float rb=Math::deg2rad(i+5);
float ra=Math::deg2rad((float)i);
float rb=Math::deg2rad((float)i+5);
float c = i/720.0;
float cn = (i+5)/720.0;
Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*w*c;