forked from bartvdbraak/blender
code cleanup: dont use function calls like dot_v3v3, pow and sqrt within macros which results in calling the function multiple times needlessly.
also added some comments.
This commit is contained in:
parent
2336aadb80
commit
3a0593cc3d
@ -2049,7 +2049,8 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o
|
|||||||
cross_v3_v3v3(raxis, rmat[1], splineVec);
|
cross_v3_v3v3(raxis, rmat[1], splineVec);
|
||||||
|
|
||||||
rangle = dot_v3v3(rmat[1], splineVec);
|
rangle = dot_v3v3(rmat[1], splineVec);
|
||||||
rangle = acos(MAX2(-1.0f, MIN2(1.0f, rangle)));
|
CLAMP(rangle, -1.0f, 1.0f);
|
||||||
|
rangle = acosf(rangle);
|
||||||
|
|
||||||
/* multiply the magnitude of the angle by the influence of the constraint to
|
/* multiply the magnitude of the angle by the influence of the constraint to
|
||||||
* control the influence of the SplineIK effect
|
* control the influence of the SplineIK effect
|
||||||
|
@ -274,7 +274,7 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM
|
|||||||
|
|
||||||
// Decrease in magnitude of relative tangential velocity due to coulomb friction
|
// Decrease in magnitude of relative tangential velocity due to coulomb friction
|
||||||
// in original formula "magrelVel" should be the "change of relative velocity in normal direction"
|
// in original formula "magrelVel" should be the "change of relative velocity in normal direction"
|
||||||
magtangent = MIN2(clmd->coll_parms->friction * 0.01f * magrelVel, sqrtf(dot_v3v3(vrel_t_pre, vrel_t_pre)));
|
magtangent = minf(clmd->coll_parms->friction * 0.01f * magrelVel, sqrtf(dot_v3v3(vrel_t_pre, vrel_t_pre)));
|
||||||
|
|
||||||
// Apply friction impulse.
|
// Apply friction impulse.
|
||||||
if ( magtangent > ALMOST_ZERO ) {
|
if ( magtangent > ALMOST_ZERO ) {
|
||||||
|
@ -1386,17 +1386,18 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
|
|||||||
ListBase top_capbase = {NULL, NULL};
|
ListBase top_capbase = {NULL, NULL};
|
||||||
|
|
||||||
for (dlb = dlbev.first; dlb; dlb = dlb->next) {
|
for (dlb = dlbev.first; dlb; dlb = dlb->next) {
|
||||||
int i, start, steps;
|
const float bevfac1 = minf(cu->bevfac1, cu->bevfac2);
|
||||||
float bevfac1 = MIN2(cu->bevfac1, cu->bevfac2), bevfac2 = MAX2(cu->bevfac1, cu->bevfac2);
|
const float bevfac2 = maxf(cu->bevfac1, cu->bevfac2);
|
||||||
float firstblend = 0.0f, lastblend = 0.0f;
|
float firstblend = 0.0f, lastblend = 0.0f;
|
||||||
|
int i, start, steps;
|
||||||
|
|
||||||
if (cu->bevfac1 - cu->bevfac2 == 0.0f)
|
if (bevfac2 - bevfac1 == 0.0f)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
start = (int)(bevfac1 * (bl->nr - 1));
|
start = (int)(bevfac1 * (bl->nr - 1));
|
||||||
steps = 2 + (int)((bevfac2) * (bl->nr - 1)) - start;
|
steps = 2 + (int)((bevfac2) * (bl->nr - 1)) - start;
|
||||||
firstblend = 1.0f - ((float)bevfac1 * (bl->nr - 1) - (int)((float)bevfac1 * (bl->nr - 1)));
|
firstblend = 1.0f - (bevfac1 * (bl->nr - 1) - (int)(bevfac1 * (bl->nr - 1)));
|
||||||
lastblend = (float)bevfac2 * (bl->nr - 1) - (int)((float)bevfac2 * (bl->nr - 1));
|
lastblend = bevfac2 * (bl->nr - 1) - (int)(bevfac2 * (bl->nr - 1));
|
||||||
|
|
||||||
if (steps > bl->nr) {
|
if (steps > bl->nr) {
|
||||||
steps = bl->nr;
|
steps = bl->nr;
|
||||||
|
@ -699,7 +699,7 @@ makebreak:
|
|||||||
|
|
||||||
yof -= linedist;
|
yof -= linedist;
|
||||||
|
|
||||||
maxlen = MAX2(maxlen, (xof - tb->x / cu->fsize));
|
maxlen = maxf(maxlen, (xof - tb->x / cu->fsize));
|
||||||
linedata[lnr] = xof - tb->x / cu->fsize;
|
linedata[lnr] = xof - tb->x / cu->fsize;
|
||||||
linedata2[lnr] = cnr;
|
linedata2[lnr] = cnr;
|
||||||
linedata3[lnr] = tb->w / cu->fsize;
|
linedata3[lnr] = tb->w / cu->fsize;
|
||||||
|
@ -141,7 +141,7 @@ struct SmokeModifierData;
|
|||||||
|
|
||||||
/* forward declerations */
|
/* forward declerations */
|
||||||
static void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *tris, int numfaces, int numtris, int **tridivs, float cell_len);
|
static void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *tris, int numfaces, int numtris, int **tridivs, float cell_len);
|
||||||
static void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int correct);
|
static void get_cell(const float p0[3], const int res[3], float dx, const float pos[3], int cell[3], int correct);
|
||||||
static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs);
|
static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs);
|
||||||
|
|
||||||
#else /* WITH_SMOKE */
|
#else /* WITH_SMOKE */
|
||||||
@ -1977,7 +1977,7 @@ static void bresenham_linie_3D(int x1, int y1, int z1, int x2, int y2, int z2, f
|
|||||||
cb(result, input, res, pixel, tRay, correct);
|
cb(result, input, res, pixel, tRay, correct);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int correct)
|
static void get_cell(const float p0[3], const int res[3], float dx, const float pos[3], int cell[3], int correct)
|
||||||
{
|
{
|
||||||
float tmp[3];
|
float tmp[3];
|
||||||
|
|
||||||
|
@ -1718,15 +1718,15 @@ static int choose_winner(float*w, float* pos, float*a, float*b, float*c, float*c
|
|||||||
{
|
{
|
||||||
float mindist, cp;
|
float mindist, cp;
|
||||||
int winner =1;
|
int winner =1;
|
||||||
mindist = ABS(dot_v3v3(pos, a));
|
mindist = fabsf(dot_v3v3(pos, a));
|
||||||
|
|
||||||
cp = ABS(dot_v3v3(pos, b));
|
cp = fabsf(dot_v3v3(pos, b));
|
||||||
if ( mindist < cp ) {
|
if ( mindist < cp ) {
|
||||||
mindist = cp;
|
mindist = cp;
|
||||||
winner =2;
|
winner =2;
|
||||||
}
|
}
|
||||||
|
|
||||||
cp = ABS(dot_v3v3(pos, c));
|
cp = fabsf(dot_v3v3(pos, c));
|
||||||
if (mindist < cp ) {
|
if (mindist < cp ) {
|
||||||
mindist = cp;
|
mindist = cp;
|
||||||
winner =3;
|
winner =3;
|
||||||
|
@ -2315,10 +2315,10 @@ static int tracking_check_marker_margin(MovieTrackingTrack *track, MovieTracking
|
|||||||
/* margin from frame boundaries */
|
/* margin from frame boundaries */
|
||||||
BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
|
BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
|
||||||
sub_v2_v2v2(dim, pat_max, pat_min);
|
sub_v2_v2v2(dim, pat_max, pat_min);
|
||||||
margin[0] = margin[1] = MAX2(dim[0], dim[1]) / 2.0f;
|
margin[0] = margin[1] = maxf(dim[0], dim[1]) / 2.0f;
|
||||||
|
|
||||||
margin[0] = MAX2(margin[0], (float)track->margin / frame_width);
|
margin[0] = maxf(margin[0], (float)track->margin / frame_width);
|
||||||
margin[1] = MAX2(margin[1], (float)track->margin / frame_height);
|
margin[1] = maxf(margin[1], (float)track->margin / frame_height);
|
||||||
|
|
||||||
/* do not track markers which are too close to boundary */
|
/* do not track markers which are too close to boundary */
|
||||||
if (marker->pos[0] < margin[0] || marker->pos[0] > 1.0f - margin[0] ||
|
if (marker->pos[0] < margin[0] || marker->pos[0] > 1.0f - margin[0] ||
|
||||||
|
@ -266,17 +266,19 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the handles that are aligned, tricky...
|
/* get the handles that are aligned, tricky...
|
||||||
// dist_to_line_v2, check if the three beztriple points are on one line
|
* dist_to_line_v2, check if the three beztriple points are on one line
|
||||||
// len_squared_v2v2, see if there's a distance between the three points
|
* len_squared_v2v2, see if there's a distance between the three points
|
||||||
// len_squared_v2v2 again, to check the angle between the handles
|
* len_squared_v2v2 again, to check the angle between the handles
|
||||||
// finally, check if one of them is a vector handle
|
* finally, check if one of them is a vector handle */
|
||||||
if ((dist_to_line_v2(bezt->vec[0], bezt->vec[1], bezt->vec[2]) < 0.001f) &&
|
if ((bezt->h1 != HD_VECT && bezt->h2 != HD_VECT) &&
|
||||||
|
(dist_to_line_v2(bezt->vec[0], bezt->vec[1], bezt->vec[2]) < 0.001f) &&
|
||||||
(len_squared_v2v2(bezt->vec[0], bezt->vec[1]) > 0.0001f * 0.0001f) &&
|
(len_squared_v2v2(bezt->vec[0], bezt->vec[1]) > 0.0001f * 0.0001f) &&
|
||||||
(len_squared_v2v2(bezt->vec[1], bezt->vec[2]) > 0.0001f * 0.0001f) &&
|
(len_squared_v2v2(bezt->vec[1], bezt->vec[2]) > 0.0001f * 0.0001f) &&
|
||||||
(len_squared_v2v2(bezt->vec[0], bezt->vec[2]) > 0.0002f * 0.0001f) &&
|
(len_squared_v2v2(bezt->vec[0], bezt->vec[2]) > 0.0002f * 0.0001f) &&
|
||||||
(len_squared_v2v2(bezt->vec[0], bezt->vec[2]) > MAX2(len_squared_v2v2(bezt->vec[0], bezt->vec[1]), len_squared_v2v2(bezt->vec[1], bezt->vec[2]))) &&
|
(len_squared_v2v2(bezt->vec[0], bezt->vec[2]) >
|
||||||
bezt->h1 != HD_VECT && bezt->h2 != HD_VECT)
|
maxf(len_squared_v2v2(bezt->vec[0], bezt->vec[1]),
|
||||||
|
len_squared_v2v2(bezt->vec[1], bezt->vec[2]))))
|
||||||
{
|
{
|
||||||
bezt->h1 = bezt->h2 = HD_ALIGN;
|
bezt->h1 = bezt->h2 = HD_ALIGN;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,13 @@
|
|||||||
#include "BLI_math.h"
|
#include "BLI_math.h"
|
||||||
#include "BLI_utildefines.h"
|
#include "BLI_utildefines.h"
|
||||||
|
|
||||||
|
/*XXX: This operator doesn't work well (at all?) for flat surfaces with
|
||||||
|
* >3 sides - creating overlapping faces at times.
|
||||||
|
* An easy workaround is to add in some noise but this is
|
||||||
|
* weak and unreliable, ideally this would detect flat surfaces
|
||||||
|
* (possibly making them into ngons) - see
|
||||||
|
*/
|
||||||
|
|
||||||
/* XXX: using 128 for totelem and pchunk of mempool, no idea what good
|
/* XXX: using 128 for totelem and pchunk of mempool, no idea what good
|
||||||
* values would be though */
|
* values would be though */
|
||||||
#include "BLI_mempool.h"
|
#include "BLI_mempool.h"
|
||||||
|
@ -3833,7 +3833,7 @@ static int ui_numedit_but_HISTOGRAM(uiBut *but, uiHandleButtonData *data, int mx
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* scale histogram values */
|
/* scale histogram values */
|
||||||
const float yfac = MIN2(powf(hist->ymax, 2.f), 1.f) * 0.5f;
|
const float yfac = minf(powf(hist->ymax, 2.0f), 1.0f) * 0.5f;
|
||||||
hist->ymax += dy * yfac;
|
hist->ymax += dy * yfac;
|
||||||
|
|
||||||
CLAMP(hist->ymax, 1.f, 100.f);
|
CLAMP(hist->ymax, 1.f, 100.f);
|
||||||
|
@ -1400,9 +1400,10 @@ static float knife_snap_size(KnifeTool_OpData *kcd, float maxsize)
|
|||||||
{
|
{
|
||||||
float density = (float)knife_sample_screen_density(kcd, maxsize * 2.0f);
|
float density = (float)knife_sample_screen_density(kcd, maxsize * 2.0f);
|
||||||
|
|
||||||
density = MAX2(density, 1);
|
if (density < 1.0f)
|
||||||
|
density = 1.0f;
|
||||||
|
|
||||||
return MIN2(maxsize / (density * 0.5f), maxsize);
|
return minf(maxsize / (density * 0.5f), maxsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* p is closest point on edge to the mouse cursor */
|
/* p is closest point on edge to the mouse cursor */
|
||||||
|
@ -1574,6 +1574,8 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
|
|||||||
else if (bgpic->source == V3D_BGPIC_MOVIE) {
|
else if (bgpic->source == V3D_BGPIC_MOVIE) {
|
||||||
clip = NULL;
|
clip = NULL;
|
||||||
|
|
||||||
|
/* TODO: skip drawing when out of frame range (as image sequences do above) */
|
||||||
|
|
||||||
if (bgpic->flag & V3D_BGPIC_CAMERACLIP) {
|
if (bgpic->flag & V3D_BGPIC_CAMERACLIP) {
|
||||||
if (scene->camera)
|
if (scene->camera)
|
||||||
clip = BKE_object_movieclip_get(scene, scene->camera, 1);
|
clip = BKE_object_movieclip_get(scene, scene->camera, 1);
|
||||||
|
@ -1392,8 +1392,8 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
|
|||||||
float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
|
float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
|
||||||
float angle = atan2f(dy, dx);
|
float angle = atan2f(dy, dx);
|
||||||
float dist = sqrtf(dx * dx + dy * dy);
|
float dist = sqrtf(dx * dx + dy * dy);
|
||||||
float delta_angle = MIN2(15.0f / dist, (float)M_PI / 4.0f);
|
float delta_angle = minf(15.0f / dist, (float)M_PI / 4.0f);
|
||||||
float spacing_angle = MIN2(5.0f / dist, (float)M_PI / 12.0f);
|
float spacing_angle = minf(5.0f / dist, (float)M_PI / 12.0f);
|
||||||
UI_ThemeColor(TH_WIRE);
|
UI_ThemeColor(TH_WIRE);
|
||||||
|
|
||||||
setlinestyle(3);
|
setlinestyle(3);
|
||||||
|
@ -1829,7 +1829,7 @@ static void editmesh_set_connectivity_distance(BMEditMesh *em, float mtx[][3], f
|
|||||||
d2 = d + len_v3(vec);
|
d2 = d + len_v3(vec);
|
||||||
|
|
||||||
if (dists[BM_elem_index_get(v3)] != FLT_MAX)
|
if (dists[BM_elem_index_get(v3)] != FLT_MAX)
|
||||||
dists[BM_elem_index_get(v3)] = MIN2(d2, dists[BM_elem_index_get(v3)]);
|
dists[BM_elem_index_get(v3)] = minf(d2, dists[BM_elem_index_get(v3)]);
|
||||||
else
|
else
|
||||||
dists[BM_elem_index_get(v3)] = d2;
|
dists[BM_elem_index_get(v3)] = d2;
|
||||||
|
|
||||||
|
@ -403,7 +403,9 @@ static void stitch_island_calculate_edge_rotation(UvEdge *edge, StitchState *sta
|
|||||||
edgecos = uv1[0] * uv2[0] + uv1[1] * uv2[1];
|
edgecos = uv1[0] * uv2[0] + uv1[1] * uv2[1];
|
||||||
edgesin = uv1[0] * uv2[1] - uv2[0] * uv1[1];
|
edgesin = uv1[0] * uv2[1] - uv2[0] * uv1[1];
|
||||||
|
|
||||||
rotation = (edgesin > 0.0f) ? acosf(MAX2(-1.0f, MIN2(1.0f, edgecos))) : -acosf(MAX2(-1.0f, MIN2(1.0f, edgecos)));
|
rotation = (edgesin > 0.0f) ?
|
||||||
|
+acosf(maxf(-1.0f, minf(1.0f, edgecos))) :
|
||||||
|
-acosf(maxf(-1.0f, minf(1.0f, edgecos)));
|
||||||
|
|
||||||
island_stitch_data[element1->island].num_rot_elements++;
|
island_stitch_data[element1->island].num_rot_elements++;
|
||||||
island_stitch_data[element1->island].rotation += rotation;
|
island_stitch_data[element1->island].rotation += rotation;
|
||||||
|
@ -798,7 +798,6 @@ static float OrenNayar_Diff(float nl, const float n[3], const float l[3], const
|
|||||||
/* Minnaert diffuse */
|
/* Minnaert diffuse */
|
||||||
static float Minnaert_Diff(float nl, const float n[3], const float v[3], float darkness)
|
static float Minnaert_Diff(float nl, const float n[3], const float v[3], float darkness)
|
||||||
{
|
{
|
||||||
|
|
||||||
float i, nv;
|
float i, nv;
|
||||||
|
|
||||||
/* nl = dot product between surface normal and light vector */
|
/* nl = dot product between surface normal and light vector */
|
||||||
@ -806,12 +805,12 @@ static float Minnaert_Diff(float nl, const float n[3], const float v[3], float d
|
|||||||
return 0.0f;
|
return 0.0f;
|
||||||
|
|
||||||
/* nv = dot product between surface normal and view vector */
|
/* nv = dot product between surface normal and view vector */
|
||||||
nv = n[0]*v[0]+n[1]*v[1]+n[2]*v[2];
|
nv = dot_v3v3(n, v);
|
||||||
if (nv < 0.0f)
|
if (nv < 0.0f)
|
||||||
nv = 0.0f;
|
nv = 0.0f;
|
||||||
|
|
||||||
if (darkness <= 1.0f)
|
if (darkness <= 1.0f)
|
||||||
i = nl * pow(MAX2(nv*nl, 0.1f), (darkness - 1.0f) ); /*The Real model*/
|
i = nl * pow(maxf(nv * nl, 0.1f), (darkness - 1.0f) ); /*The Real model*/
|
||||||
else
|
else
|
||||||
i = nl * pow( (1.001f - nv), (darkness - 1.0f) ); /*Nvidia model*/
|
i = nl * pow( (1.001f - nv), (darkness - 1.0f) ); /*Nvidia model*/
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ int SCA_Joystick::pAxisTest(int axisnum)
|
|||||||
short i2= m_axis_array[(axisnum*2)+1];
|
short i2= m_axis_array[(axisnum*2)+1];
|
||||||
|
|
||||||
/* long winded way to do
|
/* long winded way to do
|
||||||
* return MAX2(abs(i1), abs(i2))
|
* return maxf(absf(i1), absf(i2))
|
||||||
* avoid abs from math.h */
|
* avoid abs from math.h */
|
||||||
if (i1 < 0) i1 = -i1;
|
if (i1 < 0) i1 = -i1;
|
||||||
if (i2 < 0) i2 = -i2;
|
if (i2 < 0) i2 = -i2;
|
||||||
|
@ -378,10 +378,11 @@ static MT_Point3 nearestPointToObstacle(MT_Point3& pos ,KX_Obstacle* obstacle)
|
|||||||
MT_Vector3 ab = obstacle->m_pos2 - obstacle->m_pos;
|
MT_Vector3 ab = obstacle->m_pos2 - obstacle->m_pos;
|
||||||
if (!ab.fuzzyZero())
|
if (!ab.fuzzyZero())
|
||||||
{
|
{
|
||||||
|
const MT_Scalar dist = ab.length();
|
||||||
MT_Vector3 abdir = ab.normalized();
|
MT_Vector3 abdir = ab.normalized();
|
||||||
MT_Vector3 v = pos - obstacle->m_pos;
|
MT_Vector3 v = pos - obstacle->m_pos;
|
||||||
MT_Scalar proj = abdir.dot(v);
|
MT_Scalar proj = abdir.dot(v);
|
||||||
CLAMP(proj, 0, ab.length());
|
CLAMP(proj, 0, dist);
|
||||||
MT_Point3 res = obstacle->m_pos + abdir*proj;
|
MT_Point3 res = obstacle->m_pos + abdir*proj;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user