From c420f7b7af2fa1ee05b0917ea66bad0cfae47bb9 Mon Sep 17 00:00:00 2001 From: cxgeorge <> Date: Thu, 24 May 2001 03:59:55 +0000 Subject: [PATCH] many micro-optimizations --- panda/src/collide/collisionPlane.cxx | 16 +++++++------- panda/src/collide/collisionPolygon.cxx | 30 +++++++++++++------------- panda/src/collide/collisionSphere.cxx | 4 ++-- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/panda/src/collide/collisionPlane.cxx b/panda/src/collide/collisionPlane.cxx index ff160a20a8..aac7da009c 100644 --- a/panda/src/collide/collisionPlane.cxx +++ b/panda/src/collide/collisionPlane.cxx @@ -111,7 +111,7 @@ test_intersection_from_sphere(CollisionHandler *record, LPoint3f from_center = sphere->get_center() * entry.get_wrt_space(); LVector3f from_radius_v = - LVector3f(sphere->get_radius(), 0.0, 0.0) * entry.get_wrt_space(); + LVector3f(sphere->get_radius(), 0.0f, 0.0f) * entry.get_wrt_space(); float from_radius = length(from_radius_v); float dist = dist_to_plane(from_center); @@ -157,7 +157,7 @@ test_intersection_from_ray(CollisionHandler *record, return 0; } - if (t < 0.0) { + if (t < 0.0f) { // The intersection point is before the start of the ray. return 0; } @@ -211,18 +211,18 @@ recompute_viz(Node *parent) { if (fabs(normal[0]) > fabs(normal[1]) && fabs(normal[0]) > fabs(normal[2])) { // X has the largest coefficient. - cp.set(-D / normal[0], 0.0, 0.0); - p1 = LPoint3f(-(normal[1] + normal[2] + D)/normal[0], 1.0, 1.0) - cp; + cp.set(-D / normal[0], 0.0f, 0.0f); + p1 = LPoint3f(-(normal[1] + normal[2] + D)/normal[0], 1.0f, 1.0f) - cp; } else if (fabs(normal[1]) > fabs(normal[2])) { // Y has the largest coefficient. - cp.set(0.0, -D / normal[1], 0.0); - p1 = LPoint3f(1.0, -(normal[0] + normal[2] + D)/normal[1], 1.0) - cp; + cp.set(0.0f, -D / normal[1], 0.0f); + p1 = LPoint3f(1.0f, -(normal[0] + normal[2] + D)/normal[1], 1.0f) - cp; } else { // Z has the largest coefficient. - cp.set(0.0, 0.0, -D / normal[2]); - p1 = LPoint3f(1.0, 1.0, -(normal[0] + normal[1] + D)/normal[2]) - cp; + cp.set(0.0f, 0.0f, -D / normal[2]); + p1 = LPoint3f(1.0f, 1.0f, -(normal[0] + normal[1] + D)/normal[2]) - cp; } p1.normalize(); diff --git a/panda/src/collide/collisionPolygon.cxx b/panda/src/collide/collisionPolygon.cxx index 74d917ff6a..1e33233485 100644 --- a/panda/src/collide/collisionPolygon.cxx +++ b/panda/src/collide/collisionPolygon.cxx @@ -85,7 +85,7 @@ verify_points(const LPoint3f *begin, const LPoint3f *end) { Planef plane(begin[0], begin[1], begin[2]); LVector3f normal = plane.get_normal(); float normal_length = normal.length(); - bool all_ok = IS_THRESHOLD_EQUAL(normal_length, 1.0, 0.001); + bool all_ok = IS_THRESHOLD_EQUAL(normal_length, 1.0f, 0.001f); const LPoint3f *pi; for (pi = begin; pi != end && all_ok; ++pi) { @@ -225,7 +225,7 @@ test_intersection_from_sphere(CollisionHandler *record, LPoint3f from_center = sphere->get_center() * entry.get_wrt_space(); LVector3f from_radius_v = - LVector3f(sphere->get_radius(), 0.0, 0.0) * entry.get_wrt_space(); + LVector3f(sphere->get_radius(), 0.0f, 0.0f) * entry.get_wrt_space(); float from_radius = length(from_radius_v); float dist = dist_to_plane(from_center); @@ -268,7 +268,7 @@ test_intersection_from_sphere(CollisionHandler *record, } else { - if (from_radius > 0.0) { + if (from_radius > 0.0f) { // Now find the point on the rim of the circle nearest the // polygon's center. @@ -340,7 +340,7 @@ test_intersection_from_ray(CollisionHandler *record, return 0; } - if (t < 0.0) { + if (t < 0.0f) { // The intersection point is before the start of the ray. return 0; } @@ -389,7 +389,7 @@ test_intersection_from_segment(CollisionHandler *record, return 0; } - if (t < 0.0 || t > 1.0) { + if (t < 0.0f || t > 1.0f) { // The intersection point is before the start of the segment or // after the end of the segment. return 0; @@ -504,7 +504,7 @@ is_concave() const { float dx2 = p1[0] - p0[0]; float dy2 = p1[1] - p0[1]; - int asum = ((dx1 * dy2 - dx2 * dy1 >= 0.0) ? 1 : 0); + int asum = ((dx1 * dy2 - dx2 * dy1 >= 0.0f) ? 1 : 0); for (size_t i = 0; i < _points.size() - 1; i++) { p0 = p1; @@ -514,7 +514,7 @@ is_concave() const { dy1 = dy2; dx2 = p1[0] - p0[0]; dy2 = p1[1] - p0[1]; - int csum = ((dx1 * dy2 - dx2 * dy1 >= 0.0) ? 1 : 0); + int csum = ((dx1 * dy2 - dx2 * dy1 >= 0.0f) ? 1 : 0); if (csum ^ asum) { // Oops, the polygon is concave. @@ -662,7 +662,7 @@ setup_points(const LPoint3f *begin, const LPoint3f *end) { //////////////////////////////////////////////////////////////////// LPoint2f CollisionPolygon:: to_2d(const LPoint3f &point3d) const { - nassertr(!point3d.is_nan(), LPoint2f(0.0, 0.0)); + nassertr(!point3d.is_nan(), LPoint2f(0.0f, 0.0f)); // Project the point of intersection with the plane onto the // axis-aligned plane we projected the polygon onto, and see if the @@ -678,8 +678,8 @@ to_2d(const LPoint3f &point3d) const { return LPoint2f(point3d[0], point3d[1]); } - nassertr(false, LPoint2f(0.0, 0.0)); - return LPoint2f(0.0, 0.0); + nassertr(false, LPoint2f(0.0f, 0.0f)); + return LPoint2f(0.0f, 0.0f); } //////////////////////////////////////////////////////////////////// @@ -690,13 +690,13 @@ to_2d(const LPoint3f &point3d) const { //////////////////////////////////////////////////////////////////// LPoint3f CollisionPolygon:: to_3d(const LPoint2f &point2d) const { - nassertr(!point2d.is_nan(), LPoint3f(0.0, 0.0, 0.0)); + nassertr(!point2d.is_nan(), LPoint3f(0.0f, 0.0f, 0.0f)); LVector3f normal = get_normal(); float D = get_plane()._d; - nassertr(!normal.is_nan(), LPoint3f(0.0, 0.0, 0.0)); - nassertr(!cnan(D), LPoint3f(0.0, 0.0, 0.0)); + nassertr(!normal.is_nan(), LPoint3f(0.0f, 0.0f, 0.0f)); + nassertr(!cnan(D), LPoint3f(0.0f, 0.0f, 0.0f)); switch (_axis) { case AT_x: @@ -713,8 +713,8 @@ to_3d(const LPoint2f &point2d) const { -(normal[0]*point2d[0] + normal[1]*point2d[1] + D)/normal[2]); } - nassertr(false, LPoint3f(0.0, 0.0, 0.0)); - return LPoint3f(0.0, 0.0, 0.0); + nassertr(false, LPoint3f(0.0f, 0.0f, 0.0f)); + return LPoint3f(0.0f, 0.0f, 0.0f); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/collide/collisionSphere.cxx b/panda/src/collide/collisionSphere.cxx index 716f9cafb4..89d73699d7 100644 --- a/panda/src/collide/collisionSphere.cxx +++ b/panda/src/collide/collisionSphere.cxx @@ -324,14 +324,14 @@ intersects_line(double &t1, double &t2, // Tangent. t1 = t2 = -B /(2.0*A); return true; - } + } else if (radical < 0.0) { // No real roots: no intersection with the line. return false; } - double reciprocal_2A = 1.0f/(2.0*A); + double reciprocal_2A = 1.0/(2.0*A); double sqrt_radical = sqrtf(radical); t1 = ( -B - sqrt_radical ) * reciprocal_2A; t2 = ( -B + sqrt_radical ) * reciprocal_2A;