浏览代码

change to use sincos

georges 25 年之前
父节点
当前提交
08dac49237
共有 4 个文件被更改,包括 28 次插入20 次删除
  1. 4 2
      panda/src/light/spotlight.cxx
  2. 9 7
      panda/src/linmath/lmatrix3.I
  3. 6 4
      panda/src/linmath/lmatrix4.I
  4. 9 7
      panda/src/linmath/lquaternion.I

+ 4 - 2
panda/src/light/spotlight.cxx

@@ -206,9 +206,11 @@ make_geometry(float intensity, float length, int num_facets)
 
   int i;
   for (i = 2; i < num_indices-1; i++) {
-    t = (float)cos(ang) * radius;
+	float sine,cosine;
+	csincos(ang,&sine,&cosine);
+    t = cosine * radius;
     dx = x_axis * t;
-    t = (float)sin(ang) * radius;
+    t = sine * radius;
     dz = z_axis * t;
     coords[i] = dx + dz + offset;
     ang += ang_inc;

+ 9 - 7
panda/src/linmath/lmatrix3.I

@@ -822,9 +822,9 @@ translate_mat(NumType tx, NumType ty) {
 template<class NumType>
 LMatrix3<NumType> LMatrix3<NumType>::
 rotate_mat(NumType angle) {
-  double s = sin(deg_2_rad(angle));
-  double c = cos(deg_2_rad(angle));
-
+  double angle_rad=deg_2_rad(angle);
+  double s,c;
+  csincos(angle_rad,&s,&c);
   return LMatrix3<NumType>(  c,    s,  0.0,
 			    -s,    c,  0.0,
 			   0.0,  0.0,  1.0);
@@ -884,10 +884,12 @@ rotate_mat(NumType angle, LVecBase3<NumType> axis,
   // Normalize the axis.
   NumType length = axis.dot(axis);
   nassertr(length != 0.0, ident_mat());
-  axis /= length;
-    
-  double s = sin(deg_2_rad(angle));
-  double c = cos(deg_2_rad(angle));
+  NumType recip_length=1.0f/length;
+  axis *= recip_length;
+
+  double angle_rad=deg_2_rad(angle);
+  double s,c;
+  csincos(angle_rad,&s,&c);
   double t = 1.0 - c;
 
   mat(0, 0) = t * axis[0] * axis[0] + c;

+ 6 - 4
panda/src/linmath/lmatrix4.I

@@ -1030,10 +1030,12 @@ rotate_mat(NumType angle, LVecBase3<NumType> axis,
   NumType length2 = axis.dot(axis);
   // Cannot rotate about a zero-length axis.
   nassertr(length2 != 0.0, ident_mat());
-  axis /= csqrt(length2);
-    
-  double s = sin(deg_2_rad(angle));
-  double c = cos(deg_2_rad(angle));
+  NumType recip_sqrt_length2=1.0f/csqrt(length2);
+  axis *= recip_sqrt_length2;
+
+  double angle_rad=deg_2_rad(angle);
+  double s,c;
+  csincos(angle_rad,&s,&c);
   double t = 1.0 - c;
 
   mat(0, 0) = t * axis[0] * axis[0] + c;

+ 9 - 7
panda/src/linmath/lquaternion.I

@@ -489,16 +489,19 @@ set_hpr(const LVecBase3<NumType> &hpr) {
 
   LVector3<NumType> v = LVector3<NumType>::up();
   NumType a = deg_2_rad(hpr[0] * 0.5);
-  NumType s = csin(a);
-  quat_h.set(ccos(a), v[0] * s, v[1] * s, v[2] * s);
+  NumType s,c;
+
+  csincos(a,&s,&c);
+  quat_h.set(c, v[0] * s, v[1] * s, v[2] * s);
   v = LVector3<NumType>::right();
   a = deg_2_rad(hpr[1] * 0.5);
+  csincos(a,&s,&c);
   s = csin(a);
-  quat_p.set(ccos(a), v[0] * s, v[1] * s, v[2] * s);
+  quat_p.set(c, v[0] * s, v[1] * s, v[2] * s);
   v = LVector3<NumType>::forward();
   a = deg_2_rad(hpr[2] * 0.5);
-  s = csin(a);
-  quat_r.set(ccos(a), v[0] * s, v[1] * s, v[2] * s);
+  csincos(a,&s,&c);
+  quat_r.set(c, v[0] * s, v[1] * s, v[2] * s);
 
   (*this) = quat_h * quat_p * quat_r;
 }
@@ -542,8 +545,7 @@ get_hpr() const {
   } else {
     // this should work all the time, but the above saves some trig operations
     roll = catan2(-c1, c2);
-    sr = csin(roll);
-    cr = ccos(roll);
+	csincos(roll,&sr,&cr);
     roll = rad_2_deg(roll);
     ch = (cr * c3) + (sr * (xz + wy));
     sh = (cr * c4) + (sr * (yz - wx));