You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-22 15:06:45 +00:00
Use real_t as floating point type in physics code.
This is a continuation of an on-going work for 64-bit floating point builds, started in PR #7528. Covers physics, physics/joints and physics_2d code. Also removed matrixToEulerXYZ function in favor of Basis::get_euler.
This commit is contained in:
@@ -125,7 +125,7 @@ bool PlaneShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_end
|
||||
return inters;
|
||||
}
|
||||
|
||||
Vector3 PlaneShapeSW::get_moment_of_inertia(float p_mass) const {
|
||||
Vector3 PlaneShapeSW::get_moment_of_inertia(real_t p_mass) const {
|
||||
|
||||
return Vector3(); //wtf
|
||||
}
|
||||
@@ -154,7 +154,7 @@ PlaneShapeSW::PlaneShapeSW() {
|
||||
|
||||
//
|
||||
|
||||
float RayShapeSW::get_length() const {
|
||||
real_t RayShapeSW::get_length() const {
|
||||
|
||||
return length;
|
||||
}
|
||||
@@ -196,12 +196,12 @@ bool RayShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_end,V
|
||||
return false; //simply not possible
|
||||
}
|
||||
|
||||
Vector3 RayShapeSW::get_moment_of_inertia(float p_mass) const {
|
||||
Vector3 RayShapeSW::get_moment_of_inertia(real_t p_mass) const {
|
||||
|
||||
return Vector3();
|
||||
}
|
||||
|
||||
void RayShapeSW::_setup(float p_length) {
|
||||
void RayShapeSW::_setup(real_t p_length) {
|
||||
|
||||
length=p_length;
|
||||
configure(Rect3(Vector3(0,0,0),Vector3(0.1,0.1,length)));
|
||||
@@ -234,11 +234,11 @@ real_t SphereShapeSW::get_radius() const {
|
||||
|
||||
void SphereShapeSW::project_range(const Vector3& p_normal, const Transform& p_transform, real_t &r_min, real_t &r_max) const {
|
||||
|
||||
float d = p_normal.dot( p_transform.origin );
|
||||
real_t d = p_normal.dot( p_transform.origin );
|
||||
|
||||
// figure out scale at point
|
||||
Vector3 local_normal = p_transform.basis.xform_inv(p_normal);
|
||||
float scale = local_normal.length();
|
||||
real_t scale = local_normal.length();
|
||||
|
||||
r_min = d - (radius) * scale;
|
||||
r_max = d + (radius) * scale;
|
||||
@@ -261,9 +261,9 @@ bool SphereShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_en
|
||||
return Geometry::segment_intersects_sphere(p_begin,p_end,Vector3(),radius,&r_result,&r_normal);
|
||||
}
|
||||
|
||||
Vector3 SphereShapeSW::get_moment_of_inertia(float p_mass) const {
|
||||
Vector3 SphereShapeSW::get_moment_of_inertia(real_t p_mass) const {
|
||||
|
||||
float s = 0.4 * p_mass * radius * radius;
|
||||
real_t s = 0.4 * p_mass * radius * radius;
|
||||
return Vector3(s,s,s);
|
||||
}
|
||||
|
||||
@@ -299,8 +299,8 @@ void BoxShapeSW::project_range(const Vector3& p_normal, const Transform& p_trans
|
||||
// no matter the angle, the box is mirrored anyway
|
||||
Vector3 local_normal=p_transform.basis.xform_inv(p_normal);
|
||||
|
||||
float length = local_normal.abs().dot(half_extents);
|
||||
float distance = p_normal.dot( p_transform.origin );
|
||||
real_t length = local_normal.abs().dot(half_extents);
|
||||
real_t distance = p_normal.dot( p_transform.origin );
|
||||
|
||||
r_min = distance - length;
|
||||
r_max = distance + length;
|
||||
@@ -329,7 +329,7 @@ void BoxShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector3 *r_suppo
|
||||
|
||||
Vector3 axis;
|
||||
axis[i]=1.0;
|
||||
float dot = p_normal.dot( axis );
|
||||
real_t dot = p_normal.dot( axis );
|
||||
if ( Math::abs( dot ) > _FACE_IS_VALID_SUPPORT_TRESHOLD ) {
|
||||
|
||||
//Vector3 axis_b;
|
||||
@@ -343,7 +343,7 @@ void BoxShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector3 *r_suppo
|
||||
int i_n=next[i];
|
||||
int i_n2=next2[i];
|
||||
|
||||
static const float sign[4][2]={
|
||||
static const real_t sign[4][2]={
|
||||
|
||||
{-1.0, 1.0},
|
||||
{ 1.0, 1.0},
|
||||
@@ -418,11 +418,11 @@ bool BoxShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_end,V
|
||||
|
||||
}
|
||||
|
||||
Vector3 BoxShapeSW::get_moment_of_inertia(float p_mass) const {
|
||||
Vector3 BoxShapeSW::get_moment_of_inertia(real_t p_mass) const {
|
||||
|
||||
float lx=half_extents.x;
|
||||
float ly=half_extents.y;
|
||||
float lz=half_extents.z;
|
||||
real_t lx=half_extents.x;
|
||||
real_t ly=half_extents.y;
|
||||
real_t lz=half_extents.z;
|
||||
|
||||
return Vector3( (p_mass/3.0) * (ly*ly + lz*lz), (p_mass/3.0) * (lx*lx + lz*lz), (p_mass/3.0) * (lx*lx + ly*ly) );
|
||||
|
||||
@@ -460,7 +460,7 @@ BoxShapeSW::BoxShapeSW() {
|
||||
void CapsuleShapeSW::project_range(const Vector3& p_normal, const Transform& p_transform, real_t &r_min, real_t &r_max) const {
|
||||
|
||||
Vector3 n=p_transform.basis.xform_inv(p_normal).normalized();
|
||||
float h = (n.z > 0) ? height : -height;
|
||||
real_t h = (n.z > 0) ? height : -height;
|
||||
|
||||
n *= radius;
|
||||
n.z += h * 0.5;
|
||||
@@ -471,8 +471,8 @@ void CapsuleShapeSW::project_range(const Vector3& p_normal, const Transform& p_t
|
||||
|
||||
n = p_transform.basis.xform(n);
|
||||
|
||||
float distance = p_normal.dot( p_transform.origin );
|
||||
float length = Math::abs(p_normal.dot(n));
|
||||
real_t distance = p_normal.dot( p_transform.origin );
|
||||
real_t length = Math::abs(p_normal.dot(n));
|
||||
r_min = distance - length;
|
||||
r_max = distance + length;
|
||||
|
||||
@@ -484,7 +484,7 @@ Vector3 CapsuleShapeSW::get_support(const Vector3& p_normal) const {
|
||||
|
||||
Vector3 n=p_normal;
|
||||
|
||||
float h = (n.z > 0) ? height : -height;
|
||||
real_t h = (n.z > 0) ? height : -height;
|
||||
|
||||
n*=radius;
|
||||
n.z += h*0.5;
|
||||
@@ -496,7 +496,7 @@ void CapsuleShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector3 *r_s
|
||||
|
||||
Vector3 n=p_normal;
|
||||
|
||||
float d = n.z;
|
||||
real_t d = n.z;
|
||||
|
||||
if (Math::abs( d )<_EDGE_IS_VALID_SUPPORT_TRESHOLD ) {
|
||||
|
||||
@@ -513,7 +513,7 @@ void CapsuleShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector3 *r_s
|
||||
|
||||
} else {
|
||||
|
||||
float h = (d > 0) ? height : -height;
|
||||
real_t h = (d > 0) ? height : -height;
|
||||
|
||||
n*=radius;
|
||||
n.z += h*0.5;
|
||||
@@ -528,7 +528,7 @@ void CapsuleShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector3 *r_s
|
||||
bool CapsuleShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_result, Vector3 &r_normal) const {
|
||||
|
||||
Vector3 norm=(p_end-p_begin).normalized();
|
||||
float min_d=1e20;
|
||||
real_t min_d=1e20;
|
||||
|
||||
|
||||
Vector3 res,n;
|
||||
@@ -542,7 +542,7 @@ bool CapsuleShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_e
|
||||
collided = Geometry::segment_intersects_cylinder(p_begin,p_end,height,radius,&auxres,&auxn);
|
||||
|
||||
if (collided) {
|
||||
float d=norm.dot(auxres);
|
||||
real_t d=norm.dot(auxres);
|
||||
if (d<min_d) {
|
||||
min_d=d;
|
||||
res=auxres;
|
||||
@@ -554,7 +554,7 @@ bool CapsuleShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_e
|
||||
collided = Geometry::segment_intersects_sphere(p_begin,p_end,Vector3(0,0,height*0.5),radius,&auxres,&auxn);
|
||||
|
||||
if (collided) {
|
||||
float d=norm.dot(auxres);
|
||||
real_t d=norm.dot(auxres);
|
||||
if (d<min_d) {
|
||||
min_d=d;
|
||||
res=auxres;
|
||||
@@ -566,7 +566,7 @@ bool CapsuleShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_e
|
||||
collided = Geometry::segment_intersects_sphere(p_begin,p_end,Vector3(0,0,height*-0.5),radius,&auxres,&auxn);
|
||||
|
||||
if (collided) {
|
||||
float d=norm.dot(auxres);
|
||||
real_t d=norm.dot(auxres);
|
||||
|
||||
if (d<min_d) {
|
||||
min_d=d;
|
||||
@@ -584,7 +584,7 @@ bool CapsuleShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_e
|
||||
return collision;
|
||||
}
|
||||
|
||||
Vector3 CapsuleShapeSW::get_moment_of_inertia(float p_mass) const {
|
||||
Vector3 CapsuleShapeSW::get_moment_of_inertia(real_t p_mass) const {
|
||||
|
||||
// use crappy AABB approximation
|
||||
Vector3 extents=get_aabb().size*0.5;
|
||||
@@ -647,7 +647,7 @@ void ConvexPolygonShapeSW::project_range(const Vector3& p_normal, const Transfor
|
||||
|
||||
for (int i=0;i<vertex_count;i++) {
|
||||
|
||||
float d=p_normal.dot( p_transform.xform( vrts[i] ) );
|
||||
real_t d=p_normal.dot( p_transform.xform( vrts[i] ) );
|
||||
|
||||
if (i==0 || d > r_max)
|
||||
r_max=d;
|
||||
@@ -661,7 +661,7 @@ Vector3 ConvexPolygonShapeSW::get_support(const Vector3& p_normal) const {
|
||||
Vector3 n=p_normal;
|
||||
|
||||
int vert_support_idx=-1;
|
||||
float support_max;
|
||||
real_t support_max;
|
||||
|
||||
int vertex_count=mesh.vertices.size();
|
||||
if (vertex_count==0)
|
||||
@@ -671,7 +671,7 @@ Vector3 ConvexPolygonShapeSW::get_support(const Vector3& p_normal) const {
|
||||
|
||||
for (int i=0;i<vertex_count;i++) {
|
||||
|
||||
float d=n.dot(vrts[i]);
|
||||
real_t d=n.dot(vrts[i]);
|
||||
|
||||
if (i==0 || d > support_max) {
|
||||
support_max=d;
|
||||
@@ -702,7 +702,7 @@ void ConvexPolygonShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector
|
||||
|
||||
for (int i=0;i<vc;i++) {
|
||||
|
||||
float d=p_normal.dot(vertices[i]);
|
||||
real_t d=p_normal.dot(vertices[i]);
|
||||
|
||||
if (i==0 || d > max) {
|
||||
max=d;
|
||||
@@ -742,7 +742,7 @@ void ConvexPolygonShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector
|
||||
for(int i=0;i<ec;i++) {
|
||||
|
||||
|
||||
float dot=(vertices[edges[i].a]-vertices[edges[i].b]).normalized().dot(p_normal);
|
||||
real_t dot=(vertices[edges[i].a]-vertices[edges[i].b]).normalized().dot(p_normal);
|
||||
dot=ABS(dot);
|
||||
if (dot < _EDGE_IS_VALID_SUPPORT_TRESHOLD && (edges[i].a==vtx || edges[i].b==vtx)) {
|
||||
|
||||
@@ -768,7 +768,7 @@ bool ConvexPolygonShapeSW::intersect_segment(const Vector3& p_begin,const Vector
|
||||
const Vector3 *vertices = mesh.vertices.ptr();
|
||||
|
||||
Vector3 n = p_end-p_begin;
|
||||
float min = 1e20;
|
||||
real_t min = 1e20;
|
||||
bool col=false;
|
||||
|
||||
for(int i=0;i<fc;i++) {
|
||||
@@ -784,7 +784,7 @@ bool ConvexPolygonShapeSW::intersect_segment(const Vector3& p_begin,const Vector
|
||||
Face3 f(vertices[ind[0]],vertices[ind[j]],vertices[ind[j+1]]);
|
||||
Vector3 result;
|
||||
if (f.intersects_segment(p_begin,p_end,&result)) {
|
||||
float d = n.dot(result);
|
||||
real_t d = n.dot(result);
|
||||
if (d<min) {
|
||||
min=d;
|
||||
r_result=result;
|
||||
@@ -802,7 +802,7 @@ bool ConvexPolygonShapeSW::intersect_segment(const Vector3& p_begin,const Vector
|
||||
|
||||
}
|
||||
|
||||
Vector3 ConvexPolygonShapeSW::get_moment_of_inertia(float p_mass) const {
|
||||
Vector3 ConvexPolygonShapeSW::get_moment_of_inertia(real_t p_mass) const {
|
||||
|
||||
// use crappy AABB approximation
|
||||
Vector3 extents=get_aabb().size*0.5;
|
||||
@@ -859,7 +859,7 @@ void FaceShapeSW::project_range(const Vector3& p_normal, const Transform& p_tran
|
||||
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;
|
||||
@@ -873,11 +873,11 @@ Vector3 FaceShapeSW::get_support(const Vector3& p_normal) const {
|
||||
|
||||
|
||||
int vert_support_idx=-1;
|
||||
float support_max;
|
||||
real_t support_max;
|
||||
|
||||
for (int i=0;i<3;i++) {
|
||||
|
||||
float d=p_normal.dot(vertex[i]);
|
||||
real_t d=p_normal.dot(vertex[i]);
|
||||
|
||||
if (i==0 || d > support_max) {
|
||||
support_max=d;
|
||||
@@ -907,11 +907,11 @@ void FaceShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector3 *r_supp
|
||||
/** 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;
|
||||
@@ -928,7 +928,7 @@ void FaceShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector3 *r_supp
|
||||
continue;
|
||||
|
||||
// check if edge is valid as a support
|
||||
float dot=(vertex[i]-vertex[nx]).normalized().dot(n);
|
||||
real_t dot=(vertex[i]-vertex[nx]).normalized().dot(n);
|
||||
dot=ABS(dot);
|
||||
if (dot < _EDGE_IS_VALID_SUPPORT_TRESHOLD) {
|
||||
|
||||
@@ -957,7 +957,7 @@ bool FaceShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_end,
|
||||
return c;
|
||||
}
|
||||
|
||||
Vector3 FaceShapeSW::get_moment_of_inertia(float p_mass) const {
|
||||
Vector3 FaceShapeSW::get_moment_of_inertia(real_t p_mass) const {
|
||||
|
||||
return Vector3(); // Sorry, but i don't think anyone cares, FaceShape!
|
||||
|
||||
@@ -1003,7 +1003,7 @@ void ConcavePolygonShapeSW::project_range(const Vector3& p_normal, const Transfo
|
||||
|
||||
for (int i=0;i<count;i++) {
|
||||
|
||||
float d=p_normal.dot( p_transform.xform( vptr[i] ) );
|
||||
real_t d=p_normal.dot( p_transform.xform( vptr[i] ) );
|
||||
|
||||
if (i==0 || d > r_max)
|
||||
r_max=d;
|
||||
@@ -1026,11 +1026,11 @@ Vector3 ConcavePolygonShapeSW::get_support(const Vector3& p_normal) const {
|
||||
Vector3 n=p_normal;
|
||||
|
||||
int vert_support_idx=-1;
|
||||
float support_max;
|
||||
real_t support_max;
|
||||
|
||||
for (int i=0;i<count;i++) {
|
||||
|
||||
float d=n.dot(vptr[i]);
|
||||
real_t d=n.dot(vptr[i]);
|
||||
|
||||
if (i==0 || d > support_max) {
|
||||
support_max=d;
|
||||
@@ -1080,7 +1080,7 @@ void ConcavePolygonShapeSW::_cull_segment(int p_idx,_SegmentCullParams *p_params
|
||||
&res)) {
|
||||
|
||||
|
||||
float d=p_params->dir.dot(res) - p_params->dir.dot(p_params->from);
|
||||
real_t d=p_params->dir.dot(res) - p_params->dir.dot(p_params->from);
|
||||
//TODO, seems segmen/triangle intersection is broken :(
|
||||
if (d>0 && d<p_params->min_d) {
|
||||
|
||||
@@ -1206,7 +1206,7 @@ void ConcavePolygonShapeSW::cull(const Rect3& p_local_aabb,Callback p_callback,v
|
||||
|
||||
}
|
||||
|
||||
Vector3 ConcavePolygonShapeSW::get_moment_of_inertia(float p_mass) const {
|
||||
Vector3 ConcavePolygonShapeSW::get_moment_of_inertia(real_t p_mass) const {
|
||||
|
||||
// use crappy AABB approximation
|
||||
Vector3 extents=get_aabb().size*0.5;
|
||||
@@ -1555,7 +1555,7 @@ ConcavePolygonShapeSW::ConcavePolygonShapeSW() {
|
||||
|
||||
/* HEIGHT MAP SHAPE */
|
||||
|
||||
PoolVector<float> HeightMapShapeSW::get_heights() const {
|
||||
PoolVector<real_t> HeightMapShapeSW::get_heights() const {
|
||||
|
||||
return heights;
|
||||
}
|
||||
@@ -1567,7 +1567,7 @@ int HeightMapShapeSW::get_depth() const {
|
||||
|
||||
return depth;
|
||||
}
|
||||
float HeightMapShapeSW::get_cell_size() const {
|
||||
real_t HeightMapShapeSW::get_cell_size() const {
|
||||
|
||||
return cell_size;
|
||||
}
|
||||
@@ -1602,7 +1602,7 @@ void HeightMapShapeSW::cull(const Rect3& p_local_aabb,Callback p_callback,void*
|
||||
}
|
||||
|
||||
|
||||
Vector3 HeightMapShapeSW::get_moment_of_inertia(float p_mass) const {
|
||||
Vector3 HeightMapShapeSW::get_moment_of_inertia(real_t p_mass) const {
|
||||
|
||||
|
||||
// use crappy AABB approximation
|
||||
@@ -1631,7 +1631,7 @@ void HeightMapShapeSW::_setup(PoolVector<real_t> p_heights,int p_width,int p_dep
|
||||
|
||||
for(int j=0;j<width;j++) {
|
||||
|
||||
float h = r[i*width+j];
|
||||
real_t h = r[i*width+j];
|
||||
|
||||
Vector3 pos( j*cell_size, h, i*cell_size );
|
||||
if (i==0 || j==0)
|
||||
@@ -1657,8 +1657,8 @@ void HeightMapShapeSW::set_data(const Variant& p_data) {
|
||||
|
||||
int width=d["width"];
|
||||
int depth=d["depth"];
|
||||
float cell_size=d["cell_size"];
|
||||
PoolVector<float> heights=d["heights"];
|
||||
real_t cell_size=d["cell_size"];
|
||||
PoolVector<real_t> heights=d["heights"];
|
||||
|
||||
ERR_FAIL_COND( width<= 0);
|
||||
ERR_FAIL_COND( depth<= 0);
|
||||
|
||||
Reference in New Issue
Block a user