mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
change to use sincos
This commit is contained in:
parent
8d939150d7
commit
08dac49237
@ -206,9 +206,11 @@ make_geometry(float intensity, float length, int num_facets)
|
|||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 2; i < num_indices-1; 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;
|
dx = x_axis * t;
|
||||||
t = (float)sin(ang) * radius;
|
t = sine * radius;
|
||||||
dz = z_axis * t;
|
dz = z_axis * t;
|
||||||
coords[i] = dx + dz + offset;
|
coords[i] = dx + dz + offset;
|
||||||
ang += ang_inc;
|
ang += ang_inc;
|
||||||
|
@ -822,9 +822,9 @@ translate_mat(NumType tx, NumType ty) {
|
|||||||
template<class NumType>
|
template<class NumType>
|
||||||
LMatrix3<NumType> LMatrix3<NumType>::
|
LMatrix3<NumType> LMatrix3<NumType>::
|
||||||
rotate_mat(NumType angle) {
|
rotate_mat(NumType angle) {
|
||||||
double s = sin(deg_2_rad(angle));
|
double angle_rad=deg_2_rad(angle);
|
||||||
double c = cos(deg_2_rad(angle));
|
double s,c;
|
||||||
|
csincos(angle_rad,&s,&c);
|
||||||
return LMatrix3<NumType>( c, s, 0.0,
|
return LMatrix3<NumType>( c, s, 0.0,
|
||||||
-s, c, 0.0,
|
-s, c, 0.0,
|
||||||
0.0, 0.0, 1.0);
|
0.0, 0.0, 1.0);
|
||||||
@ -884,10 +884,12 @@ rotate_mat(NumType angle, LVecBase3<NumType> axis,
|
|||||||
// Normalize the axis.
|
// Normalize the axis.
|
||||||
NumType length = axis.dot(axis);
|
NumType length = axis.dot(axis);
|
||||||
nassertr(length != 0.0, ident_mat());
|
nassertr(length != 0.0, ident_mat());
|
||||||
axis /= length;
|
NumType recip_length=1.0f/length;
|
||||||
|
axis *= recip_length;
|
||||||
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);
|
||||||
double t = 1.0 - c;
|
double t = 1.0 - c;
|
||||||
|
|
||||||
mat(0, 0) = t * axis[0] * axis[0] + c;
|
mat(0, 0) = t * axis[0] * axis[0] + c;
|
||||||
|
@ -1030,10 +1030,12 @@ rotate_mat(NumType angle, LVecBase3<NumType> axis,
|
|||||||
NumType length2 = axis.dot(axis);
|
NumType length2 = axis.dot(axis);
|
||||||
// Cannot rotate about a zero-length axis.
|
// Cannot rotate about a zero-length axis.
|
||||||
nassertr(length2 != 0.0, ident_mat());
|
nassertr(length2 != 0.0, ident_mat());
|
||||||
axis /= csqrt(length2);
|
NumType recip_sqrt_length2=1.0f/csqrt(length2);
|
||||||
|
axis *= recip_sqrt_length2;
|
||||||
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);
|
||||||
double t = 1.0 - c;
|
double t = 1.0 - c;
|
||||||
|
|
||||||
mat(0, 0) = t * axis[0] * axis[0] + c;
|
mat(0, 0) = t * axis[0] * axis[0] + c;
|
||||||
|
@ -489,16 +489,19 @@ set_hpr(const LVecBase3<NumType> &hpr) {
|
|||||||
|
|
||||||
LVector3<NumType> v = LVector3<NumType>::up();
|
LVector3<NumType> v = LVector3<NumType>::up();
|
||||||
NumType a = deg_2_rad(hpr[0] * 0.5);
|
NumType a = deg_2_rad(hpr[0] * 0.5);
|
||||||
NumType s = csin(a);
|
NumType s,c;
|
||||||
quat_h.set(ccos(a), v[0] * s, v[1] * s, v[2] * s);
|
|
||||||
|
csincos(a,&s,&c);
|
||||||
|
quat_h.set(c, v[0] * s, v[1] * s, v[2] * s);
|
||||||
v = LVector3<NumType>::right();
|
v = LVector3<NumType>::right();
|
||||||
a = deg_2_rad(hpr[1] * 0.5);
|
a = deg_2_rad(hpr[1] * 0.5);
|
||||||
|
csincos(a,&s,&c);
|
||||||
s = csin(a);
|
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();
|
v = LVector3<NumType>::forward();
|
||||||
a = deg_2_rad(hpr[2] * 0.5);
|
a = deg_2_rad(hpr[2] * 0.5);
|
||||||
s = csin(a);
|
csincos(a,&s,&c);
|
||||||
quat_r.set(ccos(a), v[0] * s, v[1] * s, v[2] * s);
|
quat_r.set(c, v[0] * s, v[1] * s, v[2] * s);
|
||||||
|
|
||||||
(*this) = quat_h * quat_p * quat_r;
|
(*this) = quat_h * quat_p * quat_r;
|
||||||
}
|
}
|
||||||
@ -542,8 +545,7 @@ get_hpr() const {
|
|||||||
} else {
|
} else {
|
||||||
// this should work all the time, but the above saves some trig operations
|
// this should work all the time, but the above saves some trig operations
|
||||||
roll = catan2(-c1, c2);
|
roll = catan2(-c1, c2);
|
||||||
sr = csin(roll);
|
csincos(roll,&sr,&cr);
|
||||||
cr = ccos(roll);
|
|
||||||
roll = rad_2_deg(roll);
|
roll = rad_2_deg(roll);
|
||||||
ch = (cr * c3) + (sr * (xz + wy));
|
ch = (cr * c3) + (sr * (xz + wy));
|
||||||
sh = (cr * c4) + (sr * (yz - wx));
|
sh = (cr * c4) + (sr * (yz - wx));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user