Browse Source

more small opts

cxgeorge 24 years ago
parent
commit
98f6c845b9

+ 10 - 4
panda/src/collide/collisionPlane.cxx

@@ -125,11 +125,17 @@ test_intersection_from_sphere(CollisionHandler *record,
   DCAST_INTO_R(sphere, entry.get_from(), 0);
   DCAST_INTO_R(sphere, entry.get_from(), 0);
 
 
   LPoint3f from_center = sphere->get_center() * entry.get_wrt_space();
   LPoint3f from_center = sphere->get_center() * entry.get_wrt_space();
-  LVector3f from_radius_v =
-    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);
   float dist = dist_to_plane(from_center);
+//  LVector3f from_radius_v =
+//    LVector3f(sphere->get_radius(), 0.0f, 0.0f) * entry.get_wrt_space();
+//  float from_radius = length(from_radius_v);
+
+  const LMatrix4f *pMat = &entry.get_wrt_space();
+  float from_radius = sphere->get_radius() *
+                      sqrtf((*pMat)(0,0)*(*pMat)(0,0) + 
+                            (*pMat)(0,1)*(*pMat)(0,1) + 
+                            (*pMat)(0,2)*(*pMat)(0,2));
+
   if (dist > from_radius) {
   if (dist > from_radius) {
     // No intersection.
     // No intersection.
     return 0;
     return 0;

+ 15 - 5
panda/src/collide/collisionPolygon.cxx

@@ -239,12 +239,20 @@ test_intersection_from_sphere(CollisionHandler *record,
   DCAST_INTO_R(sphere, entry.get_from(), 0);
   DCAST_INTO_R(sphere, entry.get_from(), 0);
 
 
   LPoint3f from_center = sphere->get_center() * entry.get_wrt_space();
   LPoint3f from_center = sphere->get_center() * entry.get_wrt_space();
-  LVector3f from_radius_v =
-    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);
   float dist = dist_to_plane(from_center);
-  if (dist > from_radius || dist < -from_radius) {
+
+//  LVector3f from_radius_v =
+//    LVector3f(sphere->get_radius(), 0.0f, 0.0f) * entry.get_wrt_space();
+//  float from_radius = length(from_radius_v);
+
+  const LMatrix4f *pMat = &entry.get_wrt_space();
+  float from_radius = sphere->get_radius() *
+                      sqrtf((*pMat)(0,0)*(*pMat)(0,0) + 
+                            (*pMat)(0,1)*(*pMat)(0,1) + 
+                            (*pMat)(0,2)*(*pMat)(0,2));
+
+//  if (dist > from_radius || dist < -from_radius) {
+  if (fabs(dist) > from_radius) {
     // No intersection.
     // No intersection.
     return 0;
     return 0;
   }
   }
@@ -257,7 +265,9 @@ test_intersection_from_sphere(CollisionHandler *record,
   bool really_intersects =
   bool really_intersects =
     get_plane().intersects_line(plane_point,
     get_plane().intersects_line(plane_point,
                                 from_center, from_center + get_normal());
                                 from_center, from_center + get_normal());
+#ifdef _DEBUG
   nassertr(really_intersects, 0);
   nassertr(really_intersects, 0);
+#endif
 
 
   LPoint2f p = to_2d(plane_point);
   LPoint2f p = to_2d(plane_point);
 
 

+ 2 - 2
panda/src/collide/collisionSphere.cxx

@@ -123,8 +123,6 @@ test_intersection_from_sphere(CollisionHandler *record,
   const CollisionSphere *sphere;
   const CollisionSphere *sphere;
   DCAST_INTO_R(sphere, entry.get_from(), 0);
   DCAST_INTO_R(sphere, entry.get_from(), 0);
 
 
-  LPoint3f from_center = sphere->get_center() * entry.get_wrt_space();
-
  //from_radius_v = LVector3f(sphere->get_radius(), 0.0, 0.0) * entry.get_wrt_space();
  //from_radius_v = LVector3f(sphere->get_radius(), 0.0, 0.0) * entry.get_wrt_space();
  //float from_radius = length(from_radius_v);
  //float from_radius = length(from_radius_v);
 
 
@@ -134,7 +132,9 @@ test_intersection_from_sphere(CollisionHandler *record,
                             (*pMat)(0,1)*(*pMat)(0,1) + 
                             (*pMat)(0,1)*(*pMat)(0,1) + 
                             (*pMat)(0,2)*(*pMat)(0,2));
                             (*pMat)(0,2)*(*pMat)(0,2));
 
 
+  LPoint3f from_center = sphere->get_center() * entry.get_wrt_space();
   LVector3f vec = from_center - _center;
   LVector3f vec = from_center - _center;
+
   float dist2 = dot(vec, vec);
   float dist2 = dot(vec, vec);
   float total_radius = _radius + from_radius;
   float total_radius = _radius + from_radius;