[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49121] trunk/blender/source: code cleanup : use cosf and sinf when both args and results are float values.
Campbell Barton
ideasman42 at gmail.com
Sun Jul 22 19:35:43 CEST 2012
Revision: 49121
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49121
Author: campbellbarton
Date: 2012-07-22 17:35:43 +0000 (Sun, 22 Jul 2012)
Log Message:
-----------
code cleanup: use cosf and sinf when both args and results are float values.
also remove local math functions in KX_Camera
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/intern/math_geom.c
trunk/blender/source/blender/blenlib/intern/math_rotation.c
trunk/blender/source/gameengine/Ketsji/KX_CameraActuator.cpp
Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c 2012-07-22 16:14:57 UTC (rev 49120)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c 2012-07-22 17:35:43 UTC (rev 49121)
@@ -2367,7 +2367,8 @@
/***************************** 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 @@
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;
Modified: trunk/blender/source/blender/blenlib/intern/math_rotation.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_rotation.c 2012-07-22 16:14:57 UTC (rev 49120)
+++ trunk/blender/source/blender/blenlib/intern/math_rotation.c 2012-07-22 17:35:43 UTC (rev 49121)
@@ -166,10 +166,9 @@
/* 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 @@
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 @@
/* 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 @@
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 @@
/* 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 @@
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 @@
}
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 @@
#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 @@
}
/* 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 @@
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 @@
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;
Modified: trunk/blender/source/gameengine/Ketsji/KX_CameraActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_CameraActuator.cpp 2012-07-22 16:14:57 UTC (rev 49120)
+++ trunk/blender/source/gameengine/Ketsji/KX_CameraActuator.cpp 2012-07-22 17:35:43 UTC (rev 49121)
@@ -42,6 +42,7 @@
#include "PyObjectPlus.h"
+#include "BLI_math_vector.h"
/* ------------------------------------------------------------------------- */
/* Native functions */
@@ -113,35 +114,8 @@
}
}
-/* three functions copied from blender arith... don't know if there's an equivalent */
+/* copied from blender BLI_math ... 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];
-}
-
-
static void Kx_VecUpMat3(float vec[3], float mat[][3], short axis)
{
@@ -184,7 +158,7 @@
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 @@
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)
More information about the Bf-blender-cvs
mailing list