forked from bartvdbraak/blender
code cleanup: use cosf and sinf when both args and results are float values.
also remove local math functions in KX_Camera
This commit is contained in:
parent
e58104c515
commit
fefddc320d
@ -2367,7 +2367,8 @@ void resolve_quad_uv(float r_uv[2], const float st[2], const float st0[2], const
|
||||
|
||||
/***************************** View & Projection *****************************/
|
||||
|
||||
void orthographic_m4(float matrix[][4], const float left, const float right, const float bottom, const float top, const float nearClip, const float farClip)
|
||||
void orthographic_m4(float matrix[][4], const float left, const float right, const float bottom, const float top,
|
||||
const float nearClip, const float farClip)
|
||||
{
|
||||
float Xdelta, Ydelta, Zdelta;
|
||||
|
||||
@ -2386,7 +2387,8 @@ void orthographic_m4(float matrix[][4], const float left, const float right, con
|
||||
matrix[3][2] = -(farClip + nearClip) / Zdelta;
|
||||
}
|
||||
|
||||
void perspective_m4(float mat[4][4], const float left, const float right, const float bottom, const float top, const float nearClip, const float farClip)
|
||||
void perspective_m4(float mat[4][4], const float left, const float right, const float bottom, const float top,
|
||||
const float nearClip, const float farClip)
|
||||
{
|
||||
float Xdelta, Ydelta, Zdelta;
|
||||
|
||||
|
@ -166,10 +166,9 @@ void sub_qt_qtqt(float q[4], const float q1[4], const float q2[4])
|
||||
/* angular mult factor */
|
||||
void mul_fac_qt_fl(float q[4], const float fac)
|
||||
{
|
||||
float angle = fac * saacos(q[0]); /* quat[0] = cos(0.5 * angle), but now the 0.5 and 2.0 rule out */
|
||||
|
||||
float co = (float)cos(angle);
|
||||
float si = (float)sin(angle);
|
||||
const float angle = fac * saacos(q[0]); /* quat[0] = cos(0.5 * angle), but now the 0.5 and 2.0 rule out */
|
||||
const float co = cosf(angle);
|
||||
const float si = sinf(angle);
|
||||
q[0] = co;
|
||||
normalize_v3(q + 1);
|
||||
mul_v3_fl(q + 1, si);
|
||||
@ -342,8 +341,8 @@ void mat3_to_quat_is_ok(float q[4], float wmat[3][3])
|
||||
co = mat[2][2];
|
||||
angle = 0.5f * saacos(co);
|
||||
|
||||
co = (float)cos(angle);
|
||||
si = (float)sin(angle);
|
||||
co = cosf(angle);
|
||||
si = sinf(angle);
|
||||
q1[0] = co;
|
||||
q1[1] = -nor[0] * si; /* negative here, but why? */
|
||||
q1[2] = -nor[1] * si;
|
||||
@ -357,8 +356,8 @@ void mat3_to_quat_is_ok(float q[4], float wmat[3][3])
|
||||
/* and align x-axes */
|
||||
angle = (float)(0.5 * atan2(mat[0][1], mat[0][0]));
|
||||
|
||||
co = (float)cos(angle);
|
||||
si = (float)sin(angle);
|
||||
co = cosf(angle);
|
||||
si = sinf(angle);
|
||||
q2[0] = co;
|
||||
q2[1] = 0.0f;
|
||||
q2[2] = 0.0f;
|
||||
@ -483,8 +482,8 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag)
|
||||
normalize_v3(nor);
|
||||
|
||||
angle = 0.5f * saacos(co);
|
||||
si = (float)sin(angle);
|
||||
q[0] = (float)cos(angle);
|
||||
si = sinf(angle);
|
||||
q[0] = cosf(angle);
|
||||
q[1] = nor[0] * si;
|
||||
q[2] = nor[1] * si;
|
||||
q[3] = nor[2] * si;
|
||||
@ -615,16 +614,18 @@ void tri_to_quat(float quat[4], const float v1[3], const float v2[3], const floa
|
||||
/* move z-axis to face-normal */
|
||||
normal_tri_v3(vec, v1, v2, v3);
|
||||
|
||||
n[0] = vec[1];
|
||||
n[0] = vec[1];
|
||||
n[1] = -vec[0];
|
||||
n[2] = 0.0f;
|
||||
n[2] = 0.0f;
|
||||
normalize_v3(n);
|
||||
|
||||
if (n[0] == 0.0f && n[1] == 0.0f) n[0] = 1.0f;
|
||||
if (n[0] == 0.0f && n[1] == 0.0f) {
|
||||
n[0] = 1.0f;
|
||||
}
|
||||
|
||||
angle = -0.5f * (float)saacos(vec[2]);
|
||||
co = (float)cos(angle);
|
||||
si = (float)sin(angle);
|
||||
co = cosf(angle);
|
||||
si = sinf(angle);
|
||||
q1[0] = co;
|
||||
q1[1] = n[0] * si;
|
||||
q1[2] = n[1] * si;
|
||||
@ -641,8 +642,8 @@ void tri_to_quat(float quat[4], const float v1[3], const float v2[3], const floa
|
||||
normalize_v3(vec);
|
||||
|
||||
angle = (float)(0.5 * atan2(vec[1], vec[0]));
|
||||
co = (float)cos(angle);
|
||||
si = (float)sin(angle);
|
||||
co = cosf(angle);
|
||||
si = sinf(angle);
|
||||
q2[0] = co;
|
||||
q2[1] = 0.0f;
|
||||
q2[2] = 0.0f;
|
||||
@ -670,8 +671,8 @@ void axis_angle_to_quat(float q[4], const float axis[3], float angle)
|
||||
}
|
||||
|
||||
angle /= 2;
|
||||
si = (float)sin(angle);
|
||||
q[0] = (float)cos(angle);
|
||||
si = sinf(angle);
|
||||
q[0] = cosf(angle);
|
||||
q[1] = nor[0] * si;
|
||||
q[2] = nor[1] * si;
|
||||
q[3] = nor[2] * si;
|
||||
@ -689,8 +690,8 @@ void quat_to_axis_angle(float axis[3], float *angle, const float q[4])
|
||||
#endif
|
||||
|
||||
/* calculate angle/2, and sin(angle/2) */
|
||||
ha = (float)acos(q[0]);
|
||||
si = (float)sin(ha);
|
||||
ha = acosf(q[0]);
|
||||
si = sinf(ha);
|
||||
|
||||
/* from half-angle to angle */
|
||||
*angle = ha * 2;
|
||||
@ -739,8 +740,8 @@ void axis_angle_to_mat3(float mat[3][3], const float axis[3], const float angle)
|
||||
}
|
||||
|
||||
/* now convert this to a 3x3 matrix */
|
||||
co = (float)cos(angle);
|
||||
si = (float)sin(angle);
|
||||
co = cosf(angle);
|
||||
si = sinf(angle);
|
||||
|
||||
ico = (1.0f - co);
|
||||
nsi[0] = nor[0] * si;
|
||||
@ -849,8 +850,8 @@ void vec_rot_to_mat3(float mat[][3], const float vec[3], const float phi)
|
||||
vx2 = vx * vx;
|
||||
vy2 = vy * vy;
|
||||
vz2 = vz * vz;
|
||||
co = (float)cos(phi);
|
||||
si = (float)sin(phi);
|
||||
co = cosf(phi);
|
||||
si = sinf(phi);
|
||||
|
||||
mat[0][0] = vx2 + co * (1.0f - vx2);
|
||||
mat[0][1] = vx * vy * (1.0f - co) + vz * si;
|
||||
@ -887,8 +888,8 @@ void vec_rot_to_quat(float *quat, const float vec[3], const float phi)
|
||||
unit_qt(quat);
|
||||
}
|
||||
else {
|
||||
quat[0] = (float)cos((double)phi / 2.0);
|
||||
si = (float)sin((double)phi / 2.0);
|
||||
si = sinf(phi / 2.0);
|
||||
quat[0] = cosf(phi / 2.0f);
|
||||
quat[1] *= si;
|
||||
quat[2] *= si;
|
||||
quat[3] *= si;
|
||||
|
@ -42,6 +42,7 @@
|
||||
|
||||
#include "PyObjectPlus.h"
|
||||
|
||||
#include "BLI_math_vector.h"
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* Native functions */
|
||||
@ -113,34 +114,7 @@ void KX_CameraActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
|
||||
}
|
||||
}
|
||||
|
||||
/* three functions copied from blender arith... don't know if there's an equivalent */
|
||||
|
||||
static float Kx_Normalize(float *n)
|
||||
{
|
||||
float d;
|
||||
|
||||
d= n[0]*n[0]+n[1]*n[1]+n[2]*n[2];
|
||||
/* FLT_EPSILON is too large! A larger value causes normalize errors in a scaled down utah teapot */
|
||||
if (d>0.0000000000001) {
|
||||
d= sqrt(d);
|
||||
|
||||
n[0]/=d;
|
||||
n[1]/=d;
|
||||
n[2]/=d;
|
||||
} else {
|
||||
n[0]=n[1]=n[2]= 0.0;
|
||||
d= 0.0;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
static void Kx_Crossf(float *c, float *a, float *b)
|
||||
{
|
||||
c[0] = a[1] * b[2] - a[2] * b[1];
|
||||
c[1] = a[2] * b[0] - a[0] * b[2];
|
||||
c[2] = a[0] * b[1] - a[1] * b[0];
|
||||
}
|
||||
|
||||
/* copied from blender BLI_math ... don't know if there's an equivalent */
|
||||
|
||||
static void Kx_VecUpMat3(float vec[3], float mat[][3], short axis)
|
||||
{
|
||||
@ -184,7 +158,7 @@ static void Kx_VecUpMat3(float vec[3], float mat[][3], short axis)
|
||||
mat[coz][0]= vec[0];
|
||||
mat[coz][1]= vec[1];
|
||||
mat[coz][2]= vec[2];
|
||||
if (Kx_Normalize((float *)mat[coz]) == 0.f) {
|
||||
if (normalize_v3((float *)mat[coz]) == 0.f) {
|
||||
/* this is a very abnormal situation: the camera has reach the object center exactly
|
||||
* We will choose a completely arbitrary direction */
|
||||
mat[coz][0] = 1.0f;
|
||||
@ -197,15 +171,14 @@ static void Kx_VecUpMat3(float vec[3], float mat[][3], short axis)
|
||||
mat[coy][1] = - inp * mat[coz][1];
|
||||
mat[coy][2] = 1.0f - inp * mat[coz][2];
|
||||
|
||||
if (Kx_Normalize((float *)mat[coy]) == 0.f) {
|
||||
if (normalize_v3((float *)mat[coy]) == 0.f) {
|
||||
/* the camera is vertical, chose the y axis arbitrary */
|
||||
mat[coy][0] = 0.f;
|
||||
mat[coy][1] = 1.f;
|
||||
mat[coy][2] = 0.f;
|
||||
}
|
||||
|
||||
Kx_Crossf(mat[cox], mat[coy], mat[coz]);
|
||||
|
||||
cross_v3_v3v3(mat[cox], mat[coy], mat[coz]);
|
||||
}
|
||||
|
||||
bool KX_CameraActuator::Update(double curtime, bool frame)
|
||||
|
Loading…
Reference in New Issue
Block a user