change to use sincos

This commit is contained in:
georges 2001-02-16 23:59:16 +00:00
parent 8d939150d7
commit 08dac49237
4 changed files with 28 additions and 20 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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));