forked from bartvdbraak/blender
style cleanup: conform to style guide - mostly operator whitespace changes
This commit is contained in:
parent
e99a23fc6b
commit
53d32a0bd2
@ -60,7 +60,6 @@ double round(double x)
|
||||
double round(double x);
|
||||
#endif
|
||||
|
||||
|
||||
/* from python 3.1 floatobject.c
|
||||
* ndigits must be between 0 and 21 */
|
||||
double double_round(double x, int ndigits)
|
||||
@ -69,7 +68,7 @@ double double_round(double x, int ndigits)
|
||||
if (ndigits >= 0) {
|
||||
pow1 = pow(10.0, (double)ndigits);
|
||||
pow2 = 1.0;
|
||||
y = (x*pow1)*pow2;
|
||||
y = (x * pow1) * pow2;
|
||||
/* if y overflows, then rounded value is exactly x */
|
||||
if (!finite(y))
|
||||
return x;
|
||||
@ -81,9 +80,9 @@ double double_round(double x, int ndigits)
|
||||
}
|
||||
|
||||
z = round(y);
|
||||
if (fabs(y-z) == 0.5)
|
||||
if (fabs(y - z) == 0.5)
|
||||
/* halfway between two integers; use round-half-even */
|
||||
z = 2.0*round(y/2.0);
|
||||
z = 2.0 * round(y / 2.0);
|
||||
|
||||
if (ndigits >= 0)
|
||||
z = (z / pow2) / pow1;
|
||||
@ -93,4 +92,3 @@ double double_round(double x, int ndigits)
|
||||
/* if computation resulted in overflow, raise OverflowError */
|
||||
return z;
|
||||
}
|
||||
|
||||
|
@ -43,61 +43,61 @@
|
||||
|
||||
MINLINE float sqrt3f(float f)
|
||||
{
|
||||
if (f==0.0f) return 0.0f;
|
||||
if (f<0) return (float)(-exp(log(-f)/3));
|
||||
else return (float)(exp(log(f)/3));
|
||||
if (f == 0.0f) return 0.0f;
|
||||
if (f < 0) return (float)(-exp(log(-f) / 3));
|
||||
else return (float)(exp(log(f) / 3));
|
||||
}
|
||||
|
||||
MINLINE double sqrt3d(double d)
|
||||
{
|
||||
if (d==0.0) return 0;
|
||||
if (d<0) return -exp(log(-d)/3);
|
||||
else return exp(log(d)/3);
|
||||
if (d == 0.0) return 0;
|
||||
if (d < 0) return -exp(log(-d) / 3);
|
||||
else return exp(log(d) / 3);
|
||||
}
|
||||
|
||||
MINLINE float saacos(float fac)
|
||||
{
|
||||
if (fac<= -1.0f) return (float)M_PI;
|
||||
else if (fac>=1.0f) return 0.0;
|
||||
if (fac <= -1.0f) return (float)M_PI;
|
||||
else if (fac >= 1.0f) return 0.0;
|
||||
else return (float)acos(fac);
|
||||
}
|
||||
|
||||
MINLINE float saasin(float fac)
|
||||
{
|
||||
if (fac<= -1.0f) return (float)-M_PI/2.0f;
|
||||
else if (fac>=1.0f) return (float)M_PI/2.0f;
|
||||
if (fac <= -1.0f) return (float)-M_PI / 2.0f;
|
||||
else if (fac >= 1.0f) return (float)M_PI / 2.0f;
|
||||
else return (float)asin(fac);
|
||||
}
|
||||
|
||||
MINLINE float sasqrt(float fac)
|
||||
{
|
||||
if (fac<=0.0f) return 0.0f;
|
||||
if (fac <= 0.0f) return 0.0f;
|
||||
return (float)sqrt(fac);
|
||||
}
|
||||
|
||||
MINLINE float saacosf(float fac)
|
||||
{
|
||||
if (fac<= -1.0f) return (float)M_PI;
|
||||
else if (fac>=1.0f) return 0.0f;
|
||||
if (fac <= -1.0f) return (float)M_PI;
|
||||
else if (fac >= 1.0f) return 0.0f;
|
||||
else return (float)acosf(fac);
|
||||
}
|
||||
|
||||
MINLINE float saasinf(float fac)
|
||||
{
|
||||
if (fac<= -1.0f) return (float)-M_PI/2.0f;
|
||||
else if (fac>=1.0f) return (float)M_PI/2.0f;
|
||||
if (fac <= -1.0f) return (float)-M_PI / 2.0f;
|
||||
else if (fac >= 1.0f) return (float)M_PI / 2.0f;
|
||||
else return (float)asinf(fac);
|
||||
}
|
||||
|
||||
MINLINE float sasqrtf(float fac)
|
||||
{
|
||||
if (fac<=0.0f) return 0.0f;
|
||||
if (fac <= 0.0f) return 0.0f;
|
||||
return (float)sqrtf(fac);
|
||||
}
|
||||
|
||||
MINLINE float interpf(float target, float origin, float fac)
|
||||
{
|
||||
return (fac*target) + (1.0f-fac)*origin;
|
||||
return (fac * target) + (1.0f - fac) * origin;
|
||||
}
|
||||
|
||||
/* useful to calculate an even width shell, by taking the angle between 2 planes.
|
||||
@ -139,20 +139,19 @@ MINLINE int power_of_2_min_i(int n)
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
MINLINE float minf(float a, float b)
|
||||
{
|
||||
return (a < b)? a: b;
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
MINLINE float maxf(float a, float b)
|
||||
{
|
||||
return (a > b)? a: b;
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
MINLINE float signf(float f)
|
||||
{
|
||||
return (f < 0.f)? -1.f: 1.f;
|
||||
return (f < 0.f) ? -1.f : 1.f;
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,51 +41,51 @@ void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b)
|
||||
int i;
|
||||
float f, p, q, t;
|
||||
|
||||
if (s==0.0f) {
|
||||
if (s == 0.0f) {
|
||||
*r = v;
|
||||
*g = v;
|
||||
*b = v;
|
||||
}
|
||||
else {
|
||||
h= (h - floorf(h))*6.0f;
|
||||
h = (h - floorf(h)) * 6.0f;
|
||||
|
||||
i = (int)floorf(h);
|
||||
f = h - i;
|
||||
p = v*(1.0f-s);
|
||||
q = v*(1.0f-(s*f));
|
||||
t = v*(1.0f-(s*(1.0f-f)));
|
||||
|
||||
p = v * (1.0f - s);
|
||||
q = v * (1.0f - (s * f));
|
||||
t = v * (1.0f - (s * (1.0f - f)));
|
||||
|
||||
switch (i) {
|
||||
case 0 :
|
||||
*r = v;
|
||||
*g = t;
|
||||
*b = p;
|
||||
break;
|
||||
case 1 :
|
||||
*r = q;
|
||||
*g = v;
|
||||
*b = p;
|
||||
break;
|
||||
case 2 :
|
||||
*r = p;
|
||||
*g = v;
|
||||
*b = t;
|
||||
break;
|
||||
case 3 :
|
||||
*r = p;
|
||||
*g = q;
|
||||
*b = v;
|
||||
break;
|
||||
case 4 :
|
||||
*r = t;
|
||||
*g = p;
|
||||
*b = v;
|
||||
break;
|
||||
case 5 :
|
||||
*r = v;
|
||||
*g = p;
|
||||
*b = q;
|
||||
break;
|
||||
case 0:
|
||||
*r = v;
|
||||
*g = t;
|
||||
*b = p;
|
||||
break;
|
||||
case 1:
|
||||
*r = q;
|
||||
*g = v;
|
||||
*b = p;
|
||||
break;
|
||||
case 2:
|
||||
*r = p;
|
||||
*g = v;
|
||||
*b = t;
|
||||
break;
|
||||
case 3:
|
||||
*r = p;
|
||||
*g = q;
|
||||
*b = v;
|
||||
break;
|
||||
case 4:
|
||||
*r = t;
|
||||
*g = p;
|
||||
*b = v;
|
||||
break;
|
||||
case 5:
|
||||
*r = v;
|
||||
*g = p;
|
||||
*b = q;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -93,93 +93,95 @@ void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b)
|
||||
void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv)
|
||||
{
|
||||
float y, u, v;
|
||||
y= 0.299f*r + 0.587f*g + 0.114f*b;
|
||||
u=-0.147f*r - 0.289f*g + 0.436f*b;
|
||||
v= 0.615f*r - 0.515f*g - 0.100f*b;
|
||||
|
||||
*ly=y;
|
||||
*lu=u;
|
||||
*lv=v;
|
||||
y = 0.299f * r + 0.587f * g + 0.114f * b;
|
||||
u = -0.147f * r - 0.289f * g + 0.436f * b;
|
||||
v = 0.615f * r - 0.515f * g - 0.100f * b;
|
||||
|
||||
*ly = y;
|
||||
*lu = u;
|
||||
*lv = v;
|
||||
}
|
||||
|
||||
void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb)
|
||||
{
|
||||
float r, g, b;
|
||||
r=y+1.140f*v;
|
||||
g=y-0.394f*u - 0.581f*v;
|
||||
b=y+2.032f*u;
|
||||
|
||||
*lr=r;
|
||||
*lg=g;
|
||||
*lb=b;
|
||||
r = y + 1.140f * v;
|
||||
g = y - 0.394f * u - 0.581f * v;
|
||||
b = y + 2.032f * u;
|
||||
|
||||
*lr = r;
|
||||
*lg = g;
|
||||
*lb = b;
|
||||
}
|
||||
|
||||
/* The RGB inputs are supposed gamma corrected and in the range 0 - 1.0f */
|
||||
/* Output YCC have a range of 16-235 and 16-240 except with JFIF_0_255 where the range is 0-255 */
|
||||
/* The RGB inputs are supposed gamma corrected and in the range 0 - 1.0f
|
||||
*
|
||||
* Output YCC have a range of 16-235 and 16-240 except with JFIF_0_255 where the range is 0-255 */
|
||||
void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr, int colorspace)
|
||||
{
|
||||
float sr,sg, sb;
|
||||
float sr, sg, sb;
|
||||
float y = 128.f, cr = 128.f, cb = 128.f;
|
||||
|
||||
sr=255.0f*r;
|
||||
sg=255.0f*g;
|
||||
sb=255.0f*b;
|
||||
|
||||
|
||||
sr = 255.0f * r;
|
||||
sg = 255.0f * g;
|
||||
sb = 255.0f * b;
|
||||
|
||||
switch (colorspace) {
|
||||
case BLI_YCC_ITU_BT601 :
|
||||
y=(0.257f*sr)+(0.504f*sg)+(0.098f*sb)+16.0f;
|
||||
cb=(-0.148f*sr)-(0.291f*sg)+(0.439f*sb)+128.0f;
|
||||
cr=(0.439f*sr)-(0.368f*sg)-(0.071f*sb)+128.0f;
|
||||
break;
|
||||
case BLI_YCC_ITU_BT709 :
|
||||
y=(0.183f*sr)+(0.614f*sg)+(0.062f*sb)+16.0f;
|
||||
cb=(-0.101f*sr)-(0.338f*sg)+(0.439f*sb)+128.0f;
|
||||
cr=(0.439f*sr)-(0.399f*sg)-(0.040f*sb)+128.0f;
|
||||
break;
|
||||
case BLI_YCC_JFIF_0_255 :
|
||||
y=(0.299f*sr)+(0.587f*sg)+(0.114f*sb);
|
||||
cb=(-0.16874f*sr)-(0.33126f*sg)+(0.5f*sb)+128.0f;
|
||||
cr=(0.5f*sr)-(0.41869f*sg)-(0.08131f*sb)+128.0f;
|
||||
break;
|
||||
default:
|
||||
assert(!"invalid colorspace");
|
||||
case BLI_YCC_ITU_BT601:
|
||||
y = (0.257f * sr) + (0.504f * sg) + (0.098f * sb) + 16.0f;
|
||||
cb = (-0.148f * sr)-(0.291f * sg) + (0.439f * sb) + 128.0f;
|
||||
cr = (0.439f * sr)-(0.368f * sg)-(0.071f * sb) + 128.0f;
|
||||
break;
|
||||
case BLI_YCC_ITU_BT709:
|
||||
y = (0.183f * sr) + (0.614f * sg) + (0.062f * sb) + 16.0f;
|
||||
cb = (-0.101f * sr)-(0.338f * sg) + (0.439f * sb) + 128.0f;
|
||||
cr = (0.439f * sr)-(0.399f * sg)-(0.040f * sb) + 128.0f;
|
||||
break;
|
||||
case BLI_YCC_JFIF_0_255:
|
||||
y = (0.299f * sr) + (0.587f * sg) + (0.114f * sb);
|
||||
cb = (-0.16874f * sr)-(0.33126f * sg) + (0.5f * sb) + 128.0f;
|
||||
cr = (0.5f * sr)-(0.41869f * sg)-(0.08131f * sb) + 128.0f;
|
||||
break;
|
||||
default:
|
||||
assert(!"invalid colorspace");
|
||||
}
|
||||
|
||||
*ly=y;
|
||||
*lcb=cb;
|
||||
*lcr=cr;
|
||||
|
||||
*ly = y;
|
||||
*lcb = cb;
|
||||
*lcr = cr;
|
||||
}
|
||||
|
||||
|
||||
/* YCC input have a range of 16-235 and 16-240 except with JFIF_0_255 where the range is 0-255 */
|
||||
/* RGB outputs are in the range 0 - 1.0f */
|
||||
|
||||
/* FIXME comment above must be wrong because BLI_YCC_ITU_BT601 y 16.0 cr 16.0 -> r -0.7009 */
|
||||
void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb, int colorspace)
|
||||
{
|
||||
float r = 128.f, g = 128.f, b = 128.f;
|
||||
|
||||
|
||||
switch (colorspace) {
|
||||
case BLI_YCC_ITU_BT601 :
|
||||
r=1.164f*(y-16.0f)+1.596f*(cr-128.0f);
|
||||
g=1.164f*(y-16.0f)-0.813f*(cr-128.0f)-0.392f*(cb-128.0f);
|
||||
b=1.164f*(y-16.0f)+2.017f*(cb-128.0f);
|
||||
break;
|
||||
case BLI_YCC_ITU_BT709 :
|
||||
r=1.164f*(y-16.0f)+1.793f*(cr-128.0f);
|
||||
g=1.164f*(y-16.0f)-0.534f*(cr-128.0f)-0.213f*(cb-128.0f);
|
||||
b=1.164f*(y-16.0f)+2.115f*(cb-128.0f);
|
||||
break;
|
||||
case BLI_YCC_JFIF_0_255 :
|
||||
r=y+1.402f*cr - 179.456f;
|
||||
g=y-0.34414f*cb - 0.71414f*cr + 135.45984f;
|
||||
b=y+1.772f*cb - 226.816f;
|
||||
break;
|
||||
default:
|
||||
assert(!"invalid colorspace");
|
||||
case BLI_YCC_ITU_BT601:
|
||||
r = 1.164f * (y - 16.0f) + 1.596f * (cr - 128.0f);
|
||||
g = 1.164f * (y - 16.0f) - 0.813f * (cr - 128.0f) - 0.392f * (cb - 128.0f);
|
||||
b = 1.164f * (y - 16.0f) + 2.017f * (cb - 128.0f);
|
||||
break;
|
||||
case BLI_YCC_ITU_BT709:
|
||||
r = 1.164f * (y - 16.0f) + 1.793f * (cr - 128.0f);
|
||||
g = 1.164f * (y - 16.0f) - 0.534f * (cr - 128.0f) - 0.213f * (cb - 128.0f);
|
||||
b = 1.164f * (y - 16.0f) + 2.115f * (cb - 128.0f);
|
||||
break;
|
||||
case BLI_YCC_JFIF_0_255:
|
||||
r = y + 1.402f * cr - 179.456f;
|
||||
g = y - 0.34414f * cb - 0.71414f * cr + 135.45984f;
|
||||
b = y + 1.772f * cb - 226.816f;
|
||||
break;
|
||||
default:
|
||||
assert(!"invalid colorspace");
|
||||
}
|
||||
*lr=r/255.0f;
|
||||
*lg=g/255.0f;
|
||||
*lb=b/255.0f;
|
||||
*lr = r / 255.0f;
|
||||
*lg = g / 255.0f;
|
||||
*lb = b / 255.0f;
|
||||
}
|
||||
|
||||
void hex_to_rgb(char *hexcol, float *r, float *g, float *b)
|
||||
@ -188,7 +190,7 @@ void hex_to_rgb(char *hexcol, float *r, float *g, float *b)
|
||||
|
||||
if (hexcol[0] == '#') hexcol++;
|
||||
|
||||
if (sscanf(hexcol, "%02x%02x%02x", &ri, &gi, &bi)==3) {
|
||||
if (sscanf(hexcol, "%02x%02x%02x", &ri, &gi, &bi) == 3) {
|
||||
*r = ri / 255.0f;
|
||||
*g = gi / 255.0f;
|
||||
*b = bi / 255.0f;
|
||||
@ -198,7 +200,7 @@ void hex_to_rgb(char *hexcol, float *r, float *g, float *b)
|
||||
}
|
||||
else {
|
||||
/* avoid using un-initialized vars */
|
||||
*r= *g= *b= 0.0f;
|
||||
*r = *g = *b = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,59 +212,59 @@ void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv)
|
||||
|
||||
cmax = r;
|
||||
cmin = r;
|
||||
cmax = (g>cmax ? g:cmax);
|
||||
cmin = (g<cmin ? g:cmin);
|
||||
cmax = (b>cmax ? b:cmax);
|
||||
cmin = (b<cmin ? b:cmin);
|
||||
cmax = (g > cmax ? g : cmax);
|
||||
cmin = (g < cmin ? g : cmin);
|
||||
cmax = (b > cmax ? b : cmax);
|
||||
cmin = (b < cmin ? b : cmin);
|
||||
|
||||
v = cmax; /* value */
|
||||
v = cmax; /* value */
|
||||
if (cmax != 0.0f)
|
||||
s = (cmax - cmin)/cmax;
|
||||
s = (cmax - cmin) / cmax;
|
||||
else {
|
||||
s = 0.0f;
|
||||
}
|
||||
if (s == 0.0f)
|
||||
h = -1.0f;
|
||||
else {
|
||||
cdelta = cmax-cmin;
|
||||
rc = (cmax-r)/cdelta;
|
||||
gc = (cmax-g)/cdelta;
|
||||
bc = (cmax-b)/cdelta;
|
||||
if (r==cmax)
|
||||
h = bc-gc;
|
||||
cdelta = cmax - cmin;
|
||||
rc = (cmax - r) / cdelta;
|
||||
gc = (cmax - g) / cdelta;
|
||||
bc = (cmax - b) / cdelta;
|
||||
if (r == cmax)
|
||||
h = bc - gc;
|
||||
else
|
||||
if (g==cmax)
|
||||
h = 2.0f+rc-bc;
|
||||
if (g == cmax)
|
||||
h = 2.0f + rc - bc;
|
||||
else
|
||||
h = 4.0f+gc-rc;
|
||||
h = h*60.0f;
|
||||
h = 4.0f + gc - rc;
|
||||
h = h * 60.0f;
|
||||
if (h < 0.0f)
|
||||
h += 360.0f;
|
||||
}
|
||||
|
||||
|
||||
*ls = s;
|
||||
*lh = h / 360.0f;
|
||||
if (*lh < 0.0f) *lh= 0.0f;
|
||||
if (*lh < 0.0f) *lh = 0.0f;
|
||||
*lv = v;
|
||||
}
|
||||
|
||||
void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *lv)
|
||||
{
|
||||
float orig_h= *lh;
|
||||
float orig_s= *ls;
|
||||
float orig_h = *lh;
|
||||
float orig_s = *ls;
|
||||
|
||||
rgb_to_hsv(r, g, b, lh, ls, lv);
|
||||
|
||||
if (*lv <= 0.0f) {
|
||||
*lh= orig_h;
|
||||
*ls= orig_s;
|
||||
*lh = orig_h;
|
||||
*ls = orig_s;
|
||||
}
|
||||
else if (*ls <= 0.0f) {
|
||||
*lh= orig_h;
|
||||
*lh = orig_h;
|
||||
}
|
||||
|
||||
if (*lh==0.0f && orig_h >= 1.0f) {
|
||||
*lh= 1.0f;
|
||||
if (*lh == 0.0f && orig_h >= 1.0f) {
|
||||
*lh = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,22 +272,22 @@ void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *l
|
||||
|
||||
void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b, int colorspace)
|
||||
{
|
||||
switch (colorspace) {
|
||||
case BLI_XYZ_SMPTE:
|
||||
*r = (3.50570f * xc) + (-1.73964f * yc) + (-0.544011f * zc);
|
||||
*g = (-1.06906f * xc) + (1.97781f * yc) + (0.0351720f * zc);
|
||||
*b = (0.0563117f * xc) + (-0.196994f * yc) + (1.05005f * zc);
|
||||
break;
|
||||
case BLI_XYZ_REC709_SRGB:
|
||||
*r = (3.240476f * xc) + (-1.537150f * yc) + (-0.498535f * zc);
|
||||
*g = (-0.969256f * xc) + (1.875992f * yc) + (0.041556f * zc);
|
||||
*b = (0.055648f * xc) + (-0.204043f * yc) + (1.057311f * zc);
|
||||
break;
|
||||
case BLI_XYZ_CIE:
|
||||
*r = (2.28783848734076f * xc) + (-0.833367677835217f * yc) + (-0.454470795871421f * zc);
|
||||
*g = (-0.511651380743862f * xc) + (1.42275837632178f * yc) + (0.0888930017552939f * zc);
|
||||
*b = (0.00572040983140966f * xc) + (-0.0159068485104036f * yc) + (1.0101864083734f * zc);
|
||||
break;
|
||||
switch (colorspace) {
|
||||
case BLI_XYZ_SMPTE:
|
||||
*r = (3.50570f * xc) + (-1.73964f * yc) + (-0.544011f * zc);
|
||||
*g = (-1.06906f * xc) + (1.97781f * yc) + (0.0351720f * zc);
|
||||
*b = (0.0563117f * xc) + (-0.196994f * yc) + (1.05005f * zc);
|
||||
break;
|
||||
case BLI_XYZ_REC709_SRGB:
|
||||
*r = (3.240476f * xc) + (-1.537150f * yc) + (-0.498535f * zc);
|
||||
*g = (-0.969256f * xc) + (1.875992f * yc) + (0.041556f * zc);
|
||||
*b = (0.055648f * xc) + (-0.204043f * yc) + (1.057311f * zc);
|
||||
break;
|
||||
case BLI_XYZ_CIE:
|
||||
*r = (2.28783848734076f * xc) + (-0.833367677835217f * yc) + (-0.454470795871421f * zc);
|
||||
*g = (-0.511651380743862f * xc) + (1.42275837632178f * yc) + (0.0888930017552939f * zc);
|
||||
*b = (0.00572040983140966f * xc) + (-0.0159068485104036f * yc) + (1.0101864083734f * zc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -298,58 +300,60 @@ unsigned int hsv_to_cpack(float h, float s, float v)
|
||||
short r, g, b;
|
||||
float rf, gf, bf;
|
||||
unsigned int col;
|
||||
|
||||
|
||||
hsv_to_rgb(h, s, v, &rf, &gf, &bf);
|
||||
|
||||
r= (short)(rf*255.0f);
|
||||
g= (short)(gf*255.0f);
|
||||
b= (short)(bf*255.0f);
|
||||
|
||||
col= ( r + (g*256) + (b*256*256) );
|
||||
|
||||
r = (short) (rf * 255.0f);
|
||||
g = (short) (gf * 255.0f);
|
||||
b = (short) (bf * 255.0f);
|
||||
|
||||
col = (r + (g * 256) + (b * 256 * 256));
|
||||
return col;
|
||||
}
|
||||
|
||||
|
||||
unsigned int rgb_to_cpack(float r, float g, float b)
|
||||
{
|
||||
int ir, ig, ib;
|
||||
|
||||
ir= (int)floor(255.0f*r);
|
||||
if (ir<0) ir= 0; else if (ir>255) ir= 255;
|
||||
ig= (int)floor(255.0f*g);
|
||||
if (ig<0) ig= 0; else if (ig>255) ig= 255;
|
||||
ib= (int)floor(255.0f*b);
|
||||
if (ib<0) ib= 0; else if (ib>255) ib= 255;
|
||||
|
||||
return (ir+ (ig*256) + (ib*256*256));
|
||||
|
||||
ir = (int)floor(255.0f * r);
|
||||
if (ir < 0) ir = 0;
|
||||
else if (ir > 255) ir = 255;
|
||||
ig = (int)floor(255.0f * g);
|
||||
if (ig < 0) ig = 0;
|
||||
else if (ig > 255) ig = 255;
|
||||
ib = (int)floor(255.0f * b);
|
||||
if (ib < 0) ib = 0;
|
||||
else if (ib > 255) ib = 255;
|
||||
|
||||
return (ir + (ig * 256) + (ib * 256 * 256));
|
||||
}
|
||||
|
||||
void cpack_to_rgb(unsigned int col, float *r, float *g, float *b)
|
||||
{
|
||||
|
||||
*r= (float)((col)&0xFF);
|
||||
|
||||
*r = (float)((col)&0xFF);
|
||||
*r /= 255.0f;
|
||||
|
||||
*g= (float)(((col)>>8)&0xFF);
|
||||
*g = (float)(((col) >> 8)&0xFF);
|
||||
*g /= 255.0f;
|
||||
|
||||
*b= (float)(((col)>>16)&0xFF);
|
||||
*b = (float)(((col) >> 16)&0xFF);
|
||||
*b /= 255.0f;
|
||||
}
|
||||
|
||||
void rgb_uchar_to_float(float col_r[3], const unsigned char col_ub[3])
|
||||
{
|
||||
col_r[0]= ((float)col_ub[0]) / 255.0f;
|
||||
col_r[1]= ((float)col_ub[1]) / 255.0f;
|
||||
col_r[2]= ((float)col_ub[2]) / 255.0f;
|
||||
col_r[0] = ((float)col_ub[0]) / 255.0f;
|
||||
col_r[1] = ((float)col_ub[1]) / 255.0f;
|
||||
col_r[2] = ((float)col_ub[2]) / 255.0f;
|
||||
}
|
||||
|
||||
void rgba_uchar_to_float(float col_r[4], const unsigned char col_ub[4])
|
||||
{
|
||||
col_r[0]= ((float)col_ub[0]) / 255.0f;
|
||||
col_r[1]= ((float)col_ub[1]) / 255.0f;
|
||||
col_r[2]= ((float)col_ub[2]) / 255.0f;
|
||||
col_r[3]= ((float)col_ub[3]) / 255.0f;
|
||||
col_r[0] = ((float)col_ub[0]) / 255.0f;
|
||||
col_r[1] = ((float)col_ub[1]) / 255.0f;
|
||||
col_r[2] = ((float)col_ub[2]) / 255.0f;
|
||||
col_r[3] = ((float)col_ub[3]) / 255.0f;
|
||||
}
|
||||
|
||||
void rgb_float_to_uchar(unsigned char col_r[3], const float col_f[3])
|
||||
@ -373,15 +377,15 @@ void gamma_correct(float *c, float gamma)
|
||||
float rec709_to_linearrgb(float c)
|
||||
{
|
||||
if (c < 0.081f)
|
||||
return (c < 0.0f)? 0.0f: c * (1.0f/4.5f);
|
||||
return (c < 0.0f) ? 0.0f : c * (1.0f / 4.5f);
|
||||
else
|
||||
return powf((c + 0.099f)*(1.0f/1.099f), (1.0f/0.45f));
|
||||
return powf((c + 0.099f) * (1.0f / 1.099f), (1.0f / 0.45f));
|
||||
}
|
||||
|
||||
float linearrgb_to_rec709(float c)
|
||||
{
|
||||
if (c < 0.018f)
|
||||
return (c < 0.0f)? 0.0f: c * 4.5f;
|
||||
return (c < 0.0f) ? 0.0f : c * 4.5f;
|
||||
else
|
||||
return 1.099f * powf(c, 0.45f) - 0.099f;
|
||||
}
|
||||
@ -389,31 +393,31 @@ float linearrgb_to_rec709(float c)
|
||||
float srgb_to_linearrgb(float c)
|
||||
{
|
||||
if (c < 0.04045f)
|
||||
return (c < 0.0f)? 0.0f: c * (1.0f/12.92f);
|
||||
return (c < 0.0f) ? 0.0f : c * (1.0f / 12.92f);
|
||||
else
|
||||
return powf((c + 0.055f)*(1.0f/1.055f), 2.4f);
|
||||
return powf((c + 0.055f) * (1.0f / 1.055f), 2.4f);
|
||||
}
|
||||
|
||||
float linearrgb_to_srgb(float c)
|
||||
{
|
||||
if (c < 0.0031308f)
|
||||
return (c < 0.0f)? 0.0f: c * 12.92f;
|
||||
return (c < 0.0f) ? 0.0f : c * 12.92f;
|
||||
else
|
||||
return 1.055f * powf(c, 1.0f/2.4f) - 0.055f;
|
||||
return 1.055f * powf(c, 1.0f / 2.4f) - 0.055f;
|
||||
}
|
||||
|
||||
void minmax_rgb(short c[])
|
||||
{
|
||||
if (c[0]>255) c[0]=255;
|
||||
else if (c[0]<0) c[0]=0;
|
||||
if (c[1]>255) c[1]=255;
|
||||
else if (c[1]<0) c[1]=0;
|
||||
if (c[2]>255) c[2]=255;
|
||||
else if (c[2]<0) c[2]=0;
|
||||
if (c[0] > 255) c[0] = 255;
|
||||
else if (c[0] < 0) c[0] = 0;
|
||||
if (c[1] > 255) c[1] = 255;
|
||||
else if (c[1] < 0) c[1] = 0;
|
||||
if (c[2] > 255) c[2] = 255;
|
||||
else if (c[2] < 0) c[2] = 0;
|
||||
}
|
||||
|
||||
/*If the requested RGB shade contains a negative weight for
|
||||
* one of the primaries, it lies outside the color gamut
|
||||
* one of the primaries, it lies outside the color gamut
|
||||
* accessible from the given triple of primaries. Desaturate
|
||||
* it by adding white, equal quantities of R, G, and B, enough
|
||||
* to make RGB all positive. The function returns 1 if the
|
||||
@ -432,31 +436,33 @@ int constrain_rgb(float *r, float *g, float *b)
|
||||
/* Add just enough white to make r, g, b all positive. */
|
||||
|
||||
if (w > 0) {
|
||||
*r += w; *g += w; *b += w;
|
||||
return 1; /* Color modified to fit RGB gamut */
|
||||
*r += w;
|
||||
*g += w;
|
||||
*b += w;
|
||||
return 1; /* Color modified to fit RGB gamut */
|
||||
}
|
||||
|
||||
return 0; /* Color within RGB gamut */
|
||||
return 0; /* Color within RGB gamut */
|
||||
}
|
||||
|
||||
float rgb_to_grayscale(const float rgb[3])
|
||||
{
|
||||
return 0.3f*rgb[0] + 0.58f*rgb[1] + 0.12f*rgb[2];
|
||||
return 0.3f * rgb[0] + 0.58f * rgb[1] + 0.12f * rgb[2];
|
||||
}
|
||||
|
||||
unsigned char rgb_to_grayscale_byte(const unsigned char rgb[3])
|
||||
{
|
||||
return (76*(unsigned short)rgb[0] + 148*(unsigned short)rgb[1] + 31*(unsigned short)rgb[2]) / 255;
|
||||
return (76 * (unsigned short) rgb[0] + 148 * (unsigned short) rgb[1] + 31 * (unsigned short) rgb[2]) / 255;
|
||||
}
|
||||
|
||||
float rgb_to_luma(const float rgb[3])
|
||||
{
|
||||
return 0.299f*rgb[0] + 0.587f*rgb[1] + 0.114f*rgb[2];
|
||||
return 0.299f * rgb[0] + 0.587f * rgb[1] + 0.114f * rgb[2];
|
||||
}
|
||||
|
||||
unsigned char rgb_to_luma_byte(const unsigned char rgb[3])
|
||||
{
|
||||
return (76*(unsigned short)rgb[0] + 150*(unsigned short)rgb[1] + 29*(unsigned short)rgb[2]) / 255;
|
||||
return (76 * (unsigned short) rgb[0] + 150 * (unsigned short) rgb[1] + 29 * (unsigned short) rgb[2]) / 255;
|
||||
}
|
||||
|
||||
/* ********************************* lift/gamma/gain / ASC-CDL conversion ********************************* */
|
||||
@ -464,13 +470,13 @@ unsigned char rgb_to_luma_byte(const unsigned char rgb[3])
|
||||
void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *offset, float *slope, float *power)
|
||||
{
|
||||
int c;
|
||||
for (c=0; c<3; c++) {
|
||||
offset[c]= lift[c]*gain[c];
|
||||
slope[c]= gain[c]*(1.0f-lift[c]);
|
||||
for (c = 0; c < 3; c++) {
|
||||
offset[c] = lift[c] * gain[c];
|
||||
slope[c] = gain[c] * (1.0f - lift[c]);
|
||||
if (gamma[c] == 0)
|
||||
power[c]= FLT_MAX;
|
||||
power[c] = FLT_MAX;
|
||||
else
|
||||
power[c]= 1.0f/gamma[c];
|
||||
power[c] = 1.0f / gamma[c];
|
||||
}
|
||||
}
|
||||
|
||||
@ -480,21 +486,21 @@ void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *o
|
||||
void rgb_float_set_hue_float_offset(float rgb[3], float hue_offset)
|
||||
{
|
||||
float hsv[3];
|
||||
|
||||
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
|
||||
|
||||
hsv[0]+= hue_offset;
|
||||
if (hsv[0] > 1.0f) hsv[0] -= 1.0f;
|
||||
else if (hsv[0] < 0.0f) hsv[0] += 1.0f;
|
||||
|
||||
hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2);
|
||||
|
||||
rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
|
||||
|
||||
hsv[0] += hue_offset;
|
||||
if (hsv[0] > 1.0f) hsv[0] -= 1.0f;
|
||||
else if (hsv[0] < 0.0f) hsv[0] += 1.0f;
|
||||
|
||||
hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
|
||||
}
|
||||
|
||||
/* Applies an hue offset to a byte rgb color */
|
||||
void rgb_byte_set_hue_float_offset(unsigned char rgb[3], float hue_offset)
|
||||
{
|
||||
float rgb_float[3];
|
||||
|
||||
|
||||
rgb_uchar_to_float(rgb_float, rgb);
|
||||
rgb_float_set_hue_float_offset(rgb_float, hue_offset);
|
||||
rgb_float_to_uchar(rgb, rgb_float);
|
||||
@ -527,16 +533,17 @@ static unsigned short hipart(const float f)
|
||||
|
||||
static float index_to_float(const unsigned short i)
|
||||
{
|
||||
|
||||
union {
|
||||
float f;
|
||||
unsigned short us[2];
|
||||
} tmp;
|
||||
|
||||
/* positive and negative zeros, and all gradual underflow, turn into zero: */
|
||||
if (i<0x80 || (i >= 0x8000 && i < 0x8080)) return 0;
|
||||
if (i < 0x80 || (i >= 0x8000 && i < 0x8080)) return 0;
|
||||
/* All NaN's and infinity turn into the largest possible legal float: */
|
||||
if (i>=0x7f80 && i<0x8000) return FLT_MAX;
|
||||
if (i>=0xff80) return -FLT_MAX;
|
||||
if (i >= 0x7f80 && i < 0x8000) return FLT_MAX;
|
||||
if (i >= 0xff80) return -FLT_MAX;
|
||||
|
||||
#ifdef __BIG_ENDIAN__
|
||||
tmp.us[0] = i;
|
||||
@ -551,7 +558,7 @@ static float index_to_float(const unsigned short i)
|
||||
|
||||
void BLI_init_srgb_conversion(void)
|
||||
{
|
||||
static int initialized= 0;
|
||||
static int initialized = 0;
|
||||
int i, b;
|
||||
|
||||
if (initialized) return;
|
||||
@ -559,19 +566,18 @@ void BLI_init_srgb_conversion(void)
|
||||
|
||||
/* Fill in the lookup table to convert floats to bytes: */
|
||||
for (i = 0; i < 0x10000; i++) {
|
||||
float f = linearrgb_to_srgb(index_to_float(i))*255.0f;
|
||||
float f = linearrgb_to_srgb(index_to_float(i)) * 255.0f;
|
||||
if (f <= 0) BLI_color_to_srgb_table[i] = 0;
|
||||
else if (f < 255) BLI_color_to_srgb_table[i] = (unsigned short)(f*0x100+0.5f);
|
||||
else if (f < 255) BLI_color_to_srgb_table[i] = (unsigned short) (f * 0x100 + 0.5f);
|
||||
else BLI_color_to_srgb_table[i] = 0xff00;
|
||||
}
|
||||
|
||||
/* Fill in the lookup table to convert bytes to float: */
|
||||
for (b = 0; b <= 255; b++) {
|
||||
float f = srgb_to_linearrgb(((float)b)*(1.0f/255.0f));
|
||||
float f = srgb_to_linearrgb(((float)b) * (1.0f / 255.0f));
|
||||
BLI_color_from_srgb_table[b] = f;
|
||||
i = hipart(f);
|
||||
/* replace entries so byte->float->byte does not change the data: */
|
||||
BLI_color_to_srgb_table[i] = b*0x100;
|
||||
BLI_color_to_srgb_table[i] = b * 0x100;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ MINLINE void srgb_to_linearrgb_predivide_v4(float linear[4], const float srgb[4]
|
||||
}
|
||||
else {
|
||||
alpha = srgb[3];
|
||||
inv_alpha = 1.0f/alpha;
|
||||
inv_alpha = 1.0f / alpha;
|
||||
}
|
||||
|
||||
linear[0] = srgb_to_linearrgb(srgb[0] * inv_alpha) * alpha;
|
||||
@ -112,7 +112,7 @@ MINLINE void linearrgb_to_srgb_predivide_v4(float srgb[4], const float linear[4]
|
||||
}
|
||||
else {
|
||||
alpha = linear[3];
|
||||
inv_alpha = 1.0f/alpha;
|
||||
inv_alpha = 1.0f / alpha;
|
||||
}
|
||||
|
||||
srgb[0] = linearrgb_to_srgb(linear[0] * inv_alpha) * alpha;
|
||||
@ -128,6 +128,7 @@ extern unsigned short BLI_color_to_srgb_table[0x10000];
|
||||
|
||||
MINLINE unsigned short to_srgb_table_lookup(const float f)
|
||||
{
|
||||
|
||||
union {
|
||||
float f;
|
||||
unsigned short us[2];
|
||||
@ -159,11 +160,11 @@ MINLINE void linearrgb_to_srgb_ushort4_predivide(unsigned short srgb[4], const f
|
||||
}
|
||||
|
||||
alpha = linear[3];
|
||||
inv_alpha = 1.0f/alpha;
|
||||
inv_alpha = 1.0f / alpha;
|
||||
|
||||
for (i=0; i<3; ++i) {
|
||||
for (i = 0; i < 3; ++i) {
|
||||
t = linear[i] * inv_alpha;
|
||||
srgb[i] = (t < 1.0f)? (unsigned short)(to_srgb_table_lookup(t) * alpha) : FTOUSHORT(linearrgb_to_srgb(t) * alpha);
|
||||
srgb[i] = (t < 1.0f) ? (unsigned short) (to_srgb_table_lookup(t) * alpha) : FTOUSHORT(linearrgb_to_srgb(t) * alpha);
|
||||
}
|
||||
|
||||
srgb[3] = FTOUSHORT(linear[3]);
|
||||
@ -174,7 +175,7 @@ MINLINE void srgb_to_linearrgb_uchar4(float linear[4], const unsigned char srgb[
|
||||
linear[0] = BLI_color_from_srgb_table[srgb[0]];
|
||||
linear[1] = BLI_color_from_srgb_table[srgb[1]];
|
||||
linear[2] = BLI_color_from_srgb_table[srgb[2]];
|
||||
linear[3] = srgb[3] * (1.0f/255.0f);
|
||||
linear[3] = srgb[3] * (1.0f / 255.0f);
|
||||
}
|
||||
|
||||
MINLINE void srgb_to_linearrgb_uchar4_predivide(float linear[4], const unsigned char srgb[4])
|
||||
@ -187,8 +188,8 @@ MINLINE void srgb_to_linearrgb_uchar4_predivide(float linear[4], const unsigned
|
||||
return;
|
||||
}
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
fsrgb[i] = srgb[i] * (1.0f/255.0f);
|
||||
for (i = 0; i < 4; i++)
|
||||
fsrgb[i] = srgb[i] * (1.0f / 255.0f);
|
||||
|
||||
srgb_to_linearrgb_predivide_v4(linear, fsrgb);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -37,19 +37,19 @@
|
||||
|
||||
MINLINE void zero_sh(float r[9])
|
||||
{
|
||||
memset(r, 0, sizeof(float)*9);
|
||||
memset(r, 0, sizeof(float) * 9);
|
||||
}
|
||||
|
||||
MINLINE void copy_sh_sh(float r[9], const float a[9])
|
||||
{
|
||||
memcpy(r, a, sizeof(float)*9);
|
||||
memcpy(r, a, sizeof(float) * 9);
|
||||
}
|
||||
|
||||
MINLINE void mul_sh_fl(float r[9], const float f)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<9; i++)
|
||||
for (i = 0; i < 9; i++)
|
||||
r[i] *= f;
|
||||
}
|
||||
|
||||
@ -57,18 +57,18 @@ MINLINE void add_sh_shsh(float r[9], const float a[9], const float b[9])
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<9; i++)
|
||||
r[i]= a[i] + b[i];
|
||||
for (i = 0; i < 9; i++)
|
||||
r[i] = a[i] + b[i];
|
||||
}
|
||||
|
||||
MINLINE float dot_shsh(float a[9], float b[9])
|
||||
{
|
||||
float r= 0.0f;
|
||||
float r = 0.0f;
|
||||
int i;
|
||||
|
||||
for (i=0; i<9; i++)
|
||||
r += a[i]*b[i];
|
||||
|
||||
for (i = 0; i < 9; i++)
|
||||
r += a[i] * b[i];
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -80,16 +80,16 @@ MINLINE float diffuse_shv3(float sh[9], const float v[3])
|
||||
static const float c4 = 0.886227f, c5 = 0.247708f;
|
||||
float x, y, z, sum;
|
||||
|
||||
x= v[0];
|
||||
y= v[1];
|
||||
z= v[2];
|
||||
x = v[0];
|
||||
y = v[1];
|
||||
z = v[2];
|
||||
|
||||
sum= c1*sh[8]*(x*x - y*y);
|
||||
sum += c3*sh[6]*z*z;
|
||||
sum += c4*sh[0];
|
||||
sum += -c5*sh[6];
|
||||
sum += 2.0f*c1*(sh[4]*x*y + sh[7]*x*z + sh[5]*y*z);
|
||||
sum += 2.0f*c2*(sh[3]*x + sh[1]*y + sh[2]*z);
|
||||
sum = c1 * sh[8] * (x * x - y * y);
|
||||
sum += c3 * sh[6] * z * z;
|
||||
sum += c4 * sh[0];
|
||||
sum += -c5 * sh[6];
|
||||
sum += 2.0f * c1 * (sh[4] * x * y + sh[7] * x * z + sh[5] * y * z);
|
||||
sum += 2.0f * c2 * (sh[3] * x + sh[1] * y + sh[2] * z);
|
||||
|
||||
return sum;
|
||||
}
|
||||
@ -100,21 +100,21 @@ MINLINE void vec_fac_to_sh(float r[9], const float v[3], const float f)
|
||||
* "An Efficient Representation for Irradiance Environment Maps" */
|
||||
float sh[9], x, y, z;
|
||||
|
||||
x= v[0];
|
||||
y= v[1];
|
||||
z= v[2];
|
||||
x = v[0];
|
||||
y = v[1];
|
||||
z = v[2];
|
||||
|
||||
sh[0]= 0.282095f;
|
||||
sh[0] = 0.282095f;
|
||||
|
||||
sh[1]= 0.488603f*y;
|
||||
sh[2]= 0.488603f*z;
|
||||
sh[3]= 0.488603f*x;
|
||||
|
||||
sh[4]= 1.092548f*x*y;
|
||||
sh[5]= 1.092548f*y*z;
|
||||
sh[6]= 0.315392f*(3.0f*z*z - 1.0f);
|
||||
sh[7]= 1.092548f*x*z;
|
||||
sh[8]= 0.546274f*(x*x - y*y);
|
||||
sh[1] = 0.488603f * y;
|
||||
sh[2] = 0.488603f * z;
|
||||
sh[3] = 0.488603f * x;
|
||||
|
||||
sh[4] = 1.092548f * x * y;
|
||||
sh[5] = 1.092548f * y * z;
|
||||
sh[6] = 0.315392f * (3.0f * z * z - 1.0f);
|
||||
sh[7] = 1.092548f * x * z;
|
||||
sh[8] = 0.546274f * (x * x - y * y);
|
||||
|
||||
mul_sh_fl(sh, f);
|
||||
copy_sh_sh(r, sh);
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -35,78 +35,78 @@
|
||||
|
||||
void interp_v2_v2v2(float target[2], const float a[2], const float b[2], const float t)
|
||||
{
|
||||
float s = 1.0f-t;
|
||||
float s = 1.0f - t;
|
||||
|
||||
target[0]= s*a[0] + t*b[0];
|
||||
target[1]= s*a[1] + t*b[1];
|
||||
target[0] = s * a[0] + t * b[0];
|
||||
target[1] = s * a[1] + t * b[1];
|
||||
}
|
||||
|
||||
/* weight 3 2D vectors,
|
||||
* 'w' must be unit length but is not a vector, just 3 weights */
|
||||
void interp_v2_v2v2v2(float p[2], const float v1[2], const float v2[2], const float v3[2], const float w[3])
|
||||
{
|
||||
p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2];
|
||||
p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2];
|
||||
p[0] = v1[0] * w[0] + v2[0] * w[1] + v3[0] * w[2];
|
||||
p[1] = v1[1] * w[0] + v2[1] * w[1] + v3[1] * w[2];
|
||||
}
|
||||
|
||||
void interp_v3_v3v3(float target[3], const float a[3], const float b[3], const float t)
|
||||
{
|
||||
float s = 1.0f-t;
|
||||
float s = 1.0f - t;
|
||||
|
||||
target[0]= s*a[0] + t*b[0];
|
||||
target[1]= s*a[1] + t*b[1];
|
||||
target[2]= s*a[2] + t*b[2];
|
||||
target[0] = s * a[0] + t * b[0];
|
||||
target[1] = s * a[1] + t * b[1];
|
||||
target[2] = s * a[2] + t * b[2];
|
||||
}
|
||||
|
||||
void interp_v4_v4v4(float target[4], const float a[4], const float b[4], const float t)
|
||||
{
|
||||
float s = 1.0f-t;
|
||||
float s = 1.0f - t;
|
||||
|
||||
target[0]= s*a[0] + t*b[0];
|
||||
target[1]= s*a[1] + t*b[1];
|
||||
target[2]= s*a[2] + t*b[2];
|
||||
target[3]= s*a[3] + t*b[3];
|
||||
target[0] = s * a[0] + t * b[0];
|
||||
target[1] = s * a[1] + t * b[1];
|
||||
target[2] = s * a[2] + t * b[2];
|
||||
target[3] = s * a[3] + t * b[3];
|
||||
}
|
||||
|
||||
/* weight 3 vectors,
|
||||
* 'w' must be unit length but is not a vector, just 3 weights */
|
||||
void interp_v3_v3v3v3(float p[3], const float v1[3], const float v2[3], const float v3[3], const float w[3])
|
||||
{
|
||||
p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2];
|
||||
p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2];
|
||||
p[2] = v1[2]*w[0] + v2[2]*w[1] + v3[2]*w[2];
|
||||
p[0] = v1[0] * w[0] + v2[0] * w[1] + v3[0] * w[2];
|
||||
p[1] = v1[1] * w[0] + v2[1] * w[1] + v3[1] * w[2];
|
||||
p[2] = v1[2] * w[0] + v2[2] * w[1] + v3[2] * w[2];
|
||||
}
|
||||
|
||||
/* weight 3 vectors,
|
||||
* 'w' must be unit length but is not a vector, just 4 weights */
|
||||
void interp_v3_v3v3v3v3(float p[3], const float v1[3], const float v2[3], const float v3[3], const float v4[3], const float w[4])
|
||||
{
|
||||
p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2] + v4[0]*w[3];
|
||||
p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2] + v4[1]*w[3];
|
||||
p[2] = v1[2]*w[0] + v2[2]*w[1] + v3[2]*w[2] + v4[2]*w[3];
|
||||
p[0] = v1[0] * w[0] + v2[0] * w[1] + v3[0] * w[2] + v4[0] * w[3];
|
||||
p[1] = v1[1] * w[0] + v2[1] * w[1] + v3[1] * w[2] + v4[1] * w[3];
|
||||
p[2] = v1[2] * w[0] + v2[2] * w[1] + v3[2] * w[2] + v4[2] * w[3];
|
||||
}
|
||||
|
||||
void interp_v4_v4v4v4(float p[4], const float v1[4], const float v2[4], const float v3[4], const float w[3])
|
||||
{
|
||||
p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2];
|
||||
p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2];
|
||||
p[2] = v1[2]*w[0] + v2[2]*w[1] + v3[2]*w[2];
|
||||
p[3] = v1[3]*w[0] + v2[3]*w[1] + v3[3]*w[2];
|
||||
p[0] = v1[0] * w[0] + v2[0] * w[1] + v3[0] * w[2];
|
||||
p[1] = v1[1] * w[0] + v2[1] * w[1] + v3[1] * w[2];
|
||||
p[2] = v1[2] * w[0] + v2[2] * w[1] + v3[2] * w[2];
|
||||
p[3] = v1[3] * w[0] + v2[3] * w[1] + v3[3] * w[2];
|
||||
}
|
||||
|
||||
void interp_v4_v4v4v4v4(float p[4], const float v1[4], const float v2[4], const float v3[4], const float v4[4], const float w[4])
|
||||
{
|
||||
p[0] = v1[0]*w[0] + v2[0]*w[1] + v3[0]*w[2] + v4[0]*w[3];
|
||||
p[1] = v1[1]*w[0] + v2[1]*w[1] + v3[1]*w[2] + v4[1]*w[3];
|
||||
p[2] = v1[2]*w[0] + v2[2]*w[1] + v3[2]*w[2] + v4[2]*w[3];
|
||||
p[3] = v1[3]*w[0] + v2[3]*w[1] + v3[3]*w[2] + v4[3]*w[3];
|
||||
p[0] = v1[0] * w[0] + v2[0] * w[1] + v3[0] * w[2] + v4[0] * w[3];
|
||||
p[1] = v1[1] * w[0] + v2[1] * w[1] + v3[1] * w[2] + v4[1] * w[3];
|
||||
p[2] = v1[2] * w[0] + v2[2] * w[1] + v3[2] * w[2] + v4[2] * w[3];
|
||||
p[3] = v1[3] * w[0] + v2[3] * w[1] + v3[3] * w[2] + v4[3] * w[3];
|
||||
}
|
||||
|
||||
void mid_v3_v3v3(float v[3], const float v1[3], const float v2[3])
|
||||
{
|
||||
v[0]= 0.5f*(v1[0] + v2[0]);
|
||||
v[1]= 0.5f*(v1[1] + v2[1]);
|
||||
v[2]= 0.5f*(v1[2] + v2[2]);
|
||||
v[0] = 0.5f * (v1[0] + v2[0]);
|
||||
v[1] = 0.5f * (v1[1] + v2[1]);
|
||||
v[2] = 0.5f * (v1[2] + v2[2]);
|
||||
}
|
||||
|
||||
/********************************** Angles ***********************************/
|
||||
@ -145,12 +145,12 @@ float angle_v2v2v2(const float v1[2], const float v2[2], const float v3[2])
|
||||
{
|
||||
float vec1[2], vec2[2];
|
||||
|
||||
vec1[0] = v2[0]-v1[0];
|
||||
vec1[1] = v2[1]-v1[1];
|
||||
|
||||
vec2[0] = v2[0]-v3[0];
|
||||
vec2[1] = v2[1]-v3[1];
|
||||
|
||||
vec1[0] = v2[0] - v1[0];
|
||||
vec1[1] = v2[1] - v1[1];
|
||||
|
||||
vec2[0] = v2[0] - v3[0];
|
||||
vec2[1] = v2[1] - v3[1];
|
||||
|
||||
normalize_v2(vec1);
|
||||
normalize_v2(vec2);
|
||||
|
||||
@ -185,15 +185,15 @@ float angle_normalized_v3v3(const float v1[3], const float v2[3])
|
||||
/* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */
|
||||
if (dot_v3v3(v1, v2) < 0.0f) {
|
||||
float vec[3];
|
||||
|
||||
vec[0]= -v2[0];
|
||||
vec[1]= -v2[1];
|
||||
vec[2]= -v2[2];
|
||||
|
||||
return (float)M_PI - 2.0f*(float)saasin(len_v3v3(vec, v1)/2.0f);
|
||||
|
||||
vec[0] = -v2[0];
|
||||
vec[1] = -v2[1];
|
||||
vec[2] = -v2[2];
|
||||
|
||||
return (float)M_PI - 2.0f * (float)saasin(len_v3v3(vec, v1) / 2.0f);
|
||||
}
|
||||
else
|
||||
return 2.0f*(float)saasin(len_v3v3(v2, v1)/2.0f);
|
||||
return 2.0f * (float)saasin(len_v3v3(v2, v1) / 2.0f);
|
||||
}
|
||||
|
||||
float angle_normalized_v2v2(const float v1[2], const float v2[2])
|
||||
@ -201,14 +201,14 @@ float angle_normalized_v2v2(const float v1[2], const float v2[2])
|
||||
/* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */
|
||||
if (dot_v2v2(v1, v2) < 0.0f) {
|
||||
float vec[2];
|
||||
|
||||
vec[0]= -v2[0];
|
||||
vec[1]= -v2[1];
|
||||
|
||||
return (float)M_PI - 2.0f*saasin(len_v2v2(vec, v1)/2.0f);
|
||||
|
||||
vec[0] = -v2[0];
|
||||
vec[1] = -v2[1];
|
||||
|
||||
return (float)M_PI - 2.0f * saasin(len_v2v2(vec, v1) / 2.0f);
|
||||
}
|
||||
else
|
||||
return 2.0f*(float)saasin(len_v2v2(v2, v1)/2.0f);
|
||||
return 2.0f * (float)saasin(len_v2v2(v2, v1) / 2.0f);
|
||||
}
|
||||
|
||||
void angle_tri_v3(float angles[3], const float v1[3], const float v2[3], const float v3[3])
|
||||
@ -223,10 +223,10 @@ void angle_tri_v3(float angles[3], const float v1[3], const float v2[3], const f
|
||||
normalize_v3(ed2);
|
||||
normalize_v3(ed3);
|
||||
|
||||
angles[0]= (float)M_PI - angle_normalized_v3v3(ed1, ed2);
|
||||
angles[1]= (float)M_PI - angle_normalized_v3v3(ed2, ed3);
|
||||
angles[0] = (float)M_PI - angle_normalized_v3v3(ed1, ed2);
|
||||
angles[1] = (float)M_PI - angle_normalized_v3v3(ed2, ed3);
|
||||
// face_angles[2] = M_PI - angle_normalized_v3v3(ed3, ed1);
|
||||
angles[2]= (float)M_PI - (angles[0] + angles[1]);
|
||||
angles[2] = (float)M_PI - (angles[0] + angles[1]);
|
||||
}
|
||||
|
||||
void angle_quad_v3(float angles[4], const float v1[3], const float v2[3], const float v3[3], const float v4[3])
|
||||
@ -243,10 +243,10 @@ void angle_quad_v3(float angles[4], const float v1[3], const float v2[3], const
|
||||
normalize_v3(ed3);
|
||||
normalize_v3(ed4);
|
||||
|
||||
angles[0]= (float)M_PI - angle_normalized_v3v3(ed1, ed2);
|
||||
angles[1]= (float)M_PI - angle_normalized_v3v3(ed2, ed3);
|
||||
angles[2]= (float)M_PI - angle_normalized_v3v3(ed3, ed4);
|
||||
angles[3]= (float)M_PI - angle_normalized_v3v3(ed4, ed1);
|
||||
angles[0] = (float)M_PI - angle_normalized_v3v3(ed1, ed2);
|
||||
angles[1] = (float)M_PI - angle_normalized_v3v3(ed2, ed3);
|
||||
angles[2] = (float)M_PI - angle_normalized_v3v3(ed3, ed4);
|
||||
angles[3] = (float)M_PI - angle_normalized_v3v3(ed4, ed1);
|
||||
}
|
||||
|
||||
void angle_poly_v3(float *angles, const float *verts[3], int len)
|
||||
@ -254,12 +254,12 @@ void angle_poly_v3(float *angles, const float *verts[3], int len)
|
||||
int i;
|
||||
float vec[3][3];
|
||||
|
||||
sub_v3_v3v3(vec[2], verts[len-1], verts[0]);
|
||||
sub_v3_v3v3(vec[2], verts[len - 1], verts[0]);
|
||||
normalize_v3(vec[2]);
|
||||
for (i = 0; i < len; i++) {
|
||||
sub_v3_v3v3(vec[i%3], verts[i%len], verts[(i+1)%len]);
|
||||
normalize_v3(vec[i%3]);
|
||||
angles[i] = (float)M_PI - angle_normalized_v3v3(vec[(i+2)%3], vec[i%3]);
|
||||
sub_v3_v3v3(vec[i % 3], verts[i % len], verts[(i + 1) % len]);
|
||||
normalize_v3(vec[i % 3]);
|
||||
angles[i] = (float)M_PI - angle_normalized_v3v3(vec[(i + 2) % 3], vec[i % 3]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,7 +280,7 @@ void project_v3_v3v3(float c[3], const float v1[3], const float v2[3])
|
||||
{
|
||||
float mul;
|
||||
mul = dot_v3v3(v1, v2) / dot_v3v3(v2, v2);
|
||||
|
||||
|
||||
c[0] = mul * v2[0];
|
||||
c[1] = mul * v2[1];
|
||||
c[2] = mul * v2[2];
|
||||
@ -321,7 +321,7 @@ void reflect_v3_v3v3(float out[3], const float v1[3], const float v2[3])
|
||||
|
||||
void ortho_basis_v3v3_v3(float v1[3], float v2[3], const float v[3])
|
||||
{
|
||||
const float f = (float)sqrt(v[0]*v[0] + v[1]*v[1]);
|
||||
const float f = (float)sqrt(v[0] * v[0] + v[1] * v[1]);
|
||||
|
||||
if (f < 1e-35f) {
|
||||
// degenerate case
|
||||
@ -329,15 +329,15 @@ void ortho_basis_v3v3_v3(float v1[3], float v2[3], const float v[3])
|
||||
v1[1] = v1[2] = v2[0] = v2[2] = 0.0f;
|
||||
v2[1] = 1.0f;
|
||||
}
|
||||
else {
|
||||
const float d= 1.0f/f;
|
||||
else {
|
||||
const float d = 1.0f / f;
|
||||
|
||||
v1[0] = v[1]*d;
|
||||
v1[1] = -v[0]*d;
|
||||
v1[0] = v[1] * d;
|
||||
v1[1] = -v[0] * d;
|
||||
v1[2] = 0.0f;
|
||||
v2[0] = -v[2]*v1[1];
|
||||
v2[1] = v[2]*v1[0];
|
||||
v2[2] = v[0]*v1[1] - v[1]*v1[0];
|
||||
v2[0] = -v[2] * v1[1];
|
||||
v2[1] = v[2] * v1[0];
|
||||
v2[2] = v[0] * v1[1] - v[1] * v1[0];
|
||||
}
|
||||
}
|
||||
|
||||
@ -346,20 +346,20 @@ void ortho_basis_v3v3_v3(float v1[3], float v2[3], const float v[3])
|
||||
*/
|
||||
void rotate_normalized_v3_v3v3fl(float r[3], const float p[3], const float axis[3], const float angle)
|
||||
{
|
||||
const float costheta= cos(angle);
|
||||
const float sintheta= sin(angle);
|
||||
const float costheta = cos(angle);
|
||||
const float sintheta = sin(angle);
|
||||
|
||||
r[0]= ((costheta + (1 - costheta) * axis[0] * axis[0]) * p[0]) +
|
||||
(((1 - costheta) * axis[0] * axis[1] - axis[2] * sintheta) * p[1]) +
|
||||
(((1 - costheta) * axis[0] * axis[2] + axis[1] * sintheta) * p[2]);
|
||||
r[0] = ((costheta + (1 - costheta) * axis[0] * axis[0]) * p[0]) +
|
||||
(((1 - costheta) * axis[0] * axis[1] - axis[2] * sintheta) * p[1]) +
|
||||
(((1 - costheta) * axis[0] * axis[2] + axis[1] * sintheta) * p[2]);
|
||||
|
||||
r[1]= (((1 - costheta) * axis[0] * axis[1] + axis[2] * sintheta) * p[0]) +
|
||||
((costheta + (1 - costheta) * axis[1] * axis[1]) * p[1]) +
|
||||
(((1 - costheta) * axis[1] * axis[2] - axis[0] * sintheta) * p[2]);
|
||||
r[1] = (((1 - costheta) * axis[0] * axis[1] + axis[2] * sintheta) * p[0]) +
|
||||
((costheta + (1 - costheta) * axis[1] * axis[1]) * p[1]) +
|
||||
(((1 - costheta) * axis[1] * axis[2] - axis[0] * sintheta) * p[2]);
|
||||
|
||||
r[2]= (((1 - costheta) * axis[0] * axis[2] - axis[1] * sintheta) * p[0]) +
|
||||
(((1 - costheta) * axis[1] * axis[2] + axis[0] * sintheta) * p[1]) +
|
||||
((costheta + (1 - costheta) * axis[2] * axis[2]) * p[2]);
|
||||
r[2] = (((1 - costheta) * axis[0] * axis[2] - axis[1] * sintheta) * p[0]) +
|
||||
(((1 - costheta) * axis[1] * axis[2] + axis[0] * sintheta) * p[1]) +
|
||||
((costheta + (1 - costheta) * axis[2] * axis[2]) * p[2]);
|
||||
}
|
||||
|
||||
void rotate_v3_v3v3fl(float r[3], const float p[3], const float axis[3], const float angle)
|
||||
@ -390,39 +390,40 @@ void print_v4(const char *str, const float v[4])
|
||||
|
||||
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
|
||||
{
|
||||
if (min[0]>vec[0]) min[0]= vec[0];
|
||||
if (min[1]>vec[1]) min[1]= vec[1];
|
||||
if (min[2]>vec[2]) min[2]= vec[2];
|
||||
if (min[0] > vec[0]) min[0] = vec[0];
|
||||
if (min[1] > vec[1]) min[1] = vec[1];
|
||||
if (min[2] > vec[2]) min[2] = vec[2];
|
||||
|
||||
if (max[0]<vec[0]) max[0]= vec[0];
|
||||
if (max[1]<vec[1]) max[1]= vec[1];
|
||||
if (max[2]<vec[2]) max[2]= vec[2];
|
||||
if (max[0] < vec[0]) max[0] = vec[0];
|
||||
if (max[1] < vec[1]) max[1] = vec[1];
|
||||
if (max[2] < vec[2]) max[2] = vec[2];
|
||||
}
|
||||
|
||||
|
||||
/***************************** Array Functions *******************************/
|
||||
|
||||
double dot_vn_vn(const float *array_src_a, const float *array_src_b, const int size)
|
||||
{
|
||||
double d= 0.0f;
|
||||
const float *array_pt_a= array_src_a + (size-1);
|
||||
const float *array_pt_b= array_src_b + (size-1);
|
||||
int i= size;
|
||||
while (i--) { d += *(array_pt_a--) * *(array_pt_b--); }
|
||||
double d = 0.0f;
|
||||
const float *array_pt_a = array_src_a + (size - 1);
|
||||
const float *array_pt_b = array_src_b + (size - 1);
|
||||
int i = size;
|
||||
while (i--) {
|
||||
d += *(array_pt_a--) * *(array_pt_b--);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
float normalize_vn_vn(float *array_tar, const float *array_src, const int size)
|
||||
{
|
||||
double d= dot_vn_vn(array_tar, array_src, size);
|
||||
double d = dot_vn_vn(array_tar, array_src, size);
|
||||
float d_sqrt;
|
||||
if (d > 1.0e-35) {
|
||||
d_sqrt= (float)sqrt(d);
|
||||
mul_vn_vn_fl(array_tar, array_src, size, 1.0f/d_sqrt);
|
||||
d_sqrt = (float)sqrt(d);
|
||||
mul_vn_vn_fl(array_tar, array_src, size, 1.0f / d_sqrt);
|
||||
}
|
||||
else {
|
||||
fill_vn_fl(array_tar, size, 0.0f);
|
||||
d_sqrt= 0.0f;
|
||||
d_sqrt = 0.0f;
|
||||
}
|
||||
return d_sqrt;
|
||||
}
|
||||
@ -434,16 +435,18 @@ float normalize_vn(float *array_tar, const int size)
|
||||
|
||||
void range_vn_i(int *array_tar, const int size, const int start)
|
||||
{
|
||||
int *array_pt= array_tar + (size-1);
|
||||
int j= start + (size-1);
|
||||
int i= size;
|
||||
while (i--) { *(array_pt--) = j--; }
|
||||
int *array_pt = array_tar + (size - 1);
|
||||
int j = start + (size - 1);
|
||||
int i = size;
|
||||
while (i--) {
|
||||
*(array_pt--) = j--;
|
||||
}
|
||||
}
|
||||
|
||||
void range_vn_fl(float *array_tar, const int size, const float start, const float step)
|
||||
{
|
||||
float *array_pt= array_tar + (size-1);
|
||||
int i= size;
|
||||
float *array_pt = array_tar + (size - 1);
|
||||
int i = size;
|
||||
while (i--) {
|
||||
*(array_pt--) = start + step * (float)(i);
|
||||
}
|
||||
@ -451,78 +454,98 @@ void range_vn_fl(float *array_tar, const int size, const float start, const floa
|
||||
|
||||
void negate_vn(float *array_tar, const int size)
|
||||
{
|
||||
float *array_pt= array_tar + (size-1);
|
||||
int i= size;
|
||||
while (i--) { *(array_pt--) *= -1.0f; }
|
||||
float *array_pt = array_tar + (size - 1);
|
||||
int i = size;
|
||||
while (i--) {
|
||||
*(array_pt--) *= -1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void negate_vn_vn(float *array_tar, const float *array_src, const int size)
|
||||
{
|
||||
float *tar= array_tar + (size-1);
|
||||
const float *src= array_src + (size-1);
|
||||
int i= size;
|
||||
while (i--) { *(tar--) = - *(src--); }
|
||||
float *tar = array_tar + (size - 1);
|
||||
const float *src = array_src + (size - 1);
|
||||
int i = size;
|
||||
while (i--) {
|
||||
*(tar--) = - *(src--);
|
||||
}
|
||||
}
|
||||
|
||||
void mul_vn_fl(float *array_tar, const int size, const float f)
|
||||
{
|
||||
float *array_pt= array_tar + (size-1);
|
||||
int i= size;
|
||||
while (i--) { *(array_pt--) *= f; }
|
||||
float *array_pt = array_tar + (size - 1);
|
||||
int i = size;
|
||||
while (i--) {
|
||||
*(array_pt--) *= f;
|
||||
}
|
||||
}
|
||||
|
||||
void mul_vn_vn_fl(float *array_tar, const float *array_src, const int size, const float f)
|
||||
{
|
||||
float *tar= array_tar + (size-1);
|
||||
const float *src= array_src + (size-1);
|
||||
int i= size;
|
||||
while (i--) { *(tar--) = *(src--) * f; }
|
||||
float *tar = array_tar + (size - 1);
|
||||
const float *src = array_src + (size - 1);
|
||||
int i = size;
|
||||
while (i--) {
|
||||
*(tar--) = *(src--) * f;
|
||||
}
|
||||
}
|
||||
|
||||
void add_vn_vn(float *array_tar, const float *array_src, const int size)
|
||||
{
|
||||
float *tar= array_tar + (size-1);
|
||||
const float *src= array_src + (size-1);
|
||||
int i= size;
|
||||
while (i--) { *(tar--) += *(src--); }
|
||||
float *tar = array_tar + (size - 1);
|
||||
const float *src = array_src + (size - 1);
|
||||
int i = size;
|
||||
while (i--) {
|
||||
*(tar--) += *(src--);
|
||||
}
|
||||
}
|
||||
|
||||
void add_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size)
|
||||
{
|
||||
float *tar= array_tar + (size-1);
|
||||
const float *src_a= array_src_a + (size-1);
|
||||
const float *src_b= array_src_b + (size-1);
|
||||
int i= size;
|
||||
while (i--) { *(tar--) = *(src_a--) + *(src_b--); }
|
||||
float *tar = array_tar + (size - 1);
|
||||
const float *src_a = array_src_a + (size - 1);
|
||||
const float *src_b = array_src_b + (size - 1);
|
||||
int i = size;
|
||||
while (i--) {
|
||||
*(tar--) = *(src_a--) + *(src_b--);
|
||||
}
|
||||
}
|
||||
|
||||
void sub_vn_vn(float *array_tar, const float *array_src, const int size)
|
||||
{
|
||||
float *tar= array_tar + (size-1);
|
||||
const float *src= array_src + (size-1);
|
||||
int i= size;
|
||||
while (i--) { *(tar--) -= *(src--); }
|
||||
float *tar = array_tar + (size - 1);
|
||||
const float *src = array_src + (size - 1);
|
||||
int i = size;
|
||||
while (i--) {
|
||||
*(tar--) -= *(src--);
|
||||
}
|
||||
}
|
||||
|
||||
void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size)
|
||||
{
|
||||
float *tar= array_tar + (size-1);
|
||||
const float *src_a= array_src_a + (size-1);
|
||||
const float *src_b= array_src_b + (size-1);
|
||||
int i= size;
|
||||
while (i--) { *(tar--) = *(src_a--) - *(src_b--); }
|
||||
float *tar = array_tar + (size - 1);
|
||||
const float *src_a = array_src_a + (size - 1);
|
||||
const float *src_b = array_src_b + (size - 1);
|
||||
int i = size;
|
||||
while (i--) {
|
||||
*(tar--) = *(src_a--) - *(src_b--);
|
||||
}
|
||||
}
|
||||
|
||||
void fill_vn_i(int *array_tar, const int size, const int val)
|
||||
{
|
||||
int *tar= array_tar + (size-1);
|
||||
int i= size;
|
||||
while (i--) { *(tar--) = val; }
|
||||
int *tar = array_tar + (size - 1);
|
||||
int i = size;
|
||||
while (i--) {
|
||||
*(tar--) = val;
|
||||
}
|
||||
}
|
||||
|
||||
void fill_vn_fl(float *array_tar, const int size, const float val)
|
||||
{
|
||||
float *tar= array_tar + (size-1);
|
||||
int i= size;
|
||||
while (i--) { *(tar--) = val; }
|
||||
float *tar = array_tar + (size - 1);
|
||||
int i = size;
|
||||
while (i--) {
|
||||
*(tar--) = val;
|
||||
}
|
||||
}
|
||||
|
@ -37,131 +37,131 @@
|
||||
|
||||
MINLINE void zero_v2(float r[2])
|
||||
{
|
||||
r[0]= 0.0f;
|
||||
r[1]= 0.0f;
|
||||
r[0] = 0.0f;
|
||||
r[1] = 0.0f;
|
||||
}
|
||||
|
||||
MINLINE void zero_v3(float r[3])
|
||||
{
|
||||
r[0]= 0.0f;
|
||||
r[1]= 0.0f;
|
||||
r[2]= 0.0f;
|
||||
r[0] = 0.0f;
|
||||
r[1] = 0.0f;
|
||||
r[2] = 0.0f;
|
||||
}
|
||||
|
||||
MINLINE void zero_v4(float r[4])
|
||||
{
|
||||
r[0]= 0.0f;
|
||||
r[1]= 0.0f;
|
||||
r[2]= 0.0f;
|
||||
r[3]= 0.0f;
|
||||
r[0] = 0.0f;
|
||||
r[1] = 0.0f;
|
||||
r[2] = 0.0f;
|
||||
r[3] = 0.0f;
|
||||
}
|
||||
|
||||
MINLINE void copy_v2_v2(float r[2], const float a[2])
|
||||
{
|
||||
r[0]= a[0];
|
||||
r[1]= a[1];
|
||||
r[0] = a[0];
|
||||
r[1] = a[1];
|
||||
}
|
||||
|
||||
MINLINE void copy_v3_v3(float r[3], const float a[3])
|
||||
{
|
||||
r[0]= a[0];
|
||||
r[1]= a[1];
|
||||
r[2]= a[2];
|
||||
r[0] = a[0];
|
||||
r[1] = a[1];
|
||||
r[2] = a[2];
|
||||
}
|
||||
|
||||
MINLINE void copy_v4_v4(float r[4], const float a[4])
|
||||
{
|
||||
r[0]= a[0];
|
||||
r[1]= a[1];
|
||||
r[2]= a[2];
|
||||
r[3]= a[3];
|
||||
r[0] = a[0];
|
||||
r[1] = a[1];
|
||||
r[2] = a[2];
|
||||
r[3] = a[3];
|
||||
}
|
||||
|
||||
MINLINE void copy_v2_fl(float r[2], float f)
|
||||
{
|
||||
r[0]= f;
|
||||
r[1]= f;
|
||||
r[0] = f;
|
||||
r[1] = f;
|
||||
}
|
||||
|
||||
MINLINE void copy_v3_fl(float r[3], float f)
|
||||
{
|
||||
r[0]= f;
|
||||
r[1]= f;
|
||||
r[2]= f;
|
||||
r[0] = f;
|
||||
r[1] = f;
|
||||
r[2] = f;
|
||||
}
|
||||
|
||||
MINLINE void copy_v4_fl(float r[4], float f)
|
||||
{
|
||||
r[0]= f;
|
||||
r[1]= f;
|
||||
r[2]= f;
|
||||
r[3]= f;
|
||||
r[0] = f;
|
||||
r[1] = f;
|
||||
r[2] = f;
|
||||
r[3] = f;
|
||||
}
|
||||
|
||||
/* short */
|
||||
MINLINE void copy_v2_v2_char(char r[2], const char a[2])
|
||||
{
|
||||
r[0]= a[0];
|
||||
r[1]= a[1];
|
||||
r[0] = a[0];
|
||||
r[1] = a[1];
|
||||
}
|
||||
|
||||
MINLINE void copy_v3_v3_char(char r[3], const char a[3])
|
||||
{
|
||||
r[0]= a[0];
|
||||
r[1]= a[1];
|
||||
r[2]= a[2];
|
||||
r[0] = a[0];
|
||||
r[1] = a[1];
|
||||
r[2] = a[2];
|
||||
}
|
||||
|
||||
MINLINE void copy_v4_v4_char(char r[4], const char a[4])
|
||||
{
|
||||
r[0]= a[0];
|
||||
r[1]= a[1];
|
||||
r[2]= a[2];
|
||||
r[3]= a[3];
|
||||
r[0] = a[0];
|
||||
r[1] = a[1];
|
||||
r[2] = a[2];
|
||||
r[3] = a[3];
|
||||
}
|
||||
|
||||
/* short */
|
||||
MINLINE void copy_v2_v2_short(short r[2], const short a[2])
|
||||
{
|
||||
r[0]= a[0];
|
||||
r[1]= a[1];
|
||||
r[0] = a[0];
|
||||
r[1] = a[1];
|
||||
}
|
||||
|
||||
MINLINE void copy_v3_v3_short(short r[3], const short a[3])
|
||||
{
|
||||
r[0]= a[0];
|
||||
r[1]= a[1];
|
||||
r[2]= a[2];
|
||||
r[0] = a[0];
|
||||
r[1] = a[1];
|
||||
r[2] = a[2];
|
||||
}
|
||||
|
||||
MINLINE void copy_v4_v4_short(short r[4], const short a[4])
|
||||
{
|
||||
r[0]= a[0];
|
||||
r[1]= a[1];
|
||||
r[2]= a[2];
|
||||
r[3]= a[3];
|
||||
r[0] = a[0];
|
||||
r[1] = a[1];
|
||||
r[2] = a[2];
|
||||
r[3] = a[3];
|
||||
}
|
||||
|
||||
/* int */
|
||||
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
|
||||
{
|
||||
r[0]= a[0];
|
||||
r[1]= a[1];
|
||||
r[0] = a[0];
|
||||
r[1] = a[1];
|
||||
}
|
||||
|
||||
MINLINE void copy_v3_v3_int(int r[3], const int a[3])
|
||||
{
|
||||
r[0]= a[0];
|
||||
r[1]= a[1];
|
||||
r[2]= a[2];
|
||||
r[0] = a[0];
|
||||
r[1] = a[1];
|
||||
r[2] = a[2];
|
||||
}
|
||||
|
||||
MINLINE void copy_v4_v4_int(int r[4], const int a[4])
|
||||
{
|
||||
r[0]= a[0];
|
||||
r[1]= a[1];
|
||||
r[2]= a[2];
|
||||
r[3]= a[3];
|
||||
r[0] = a[0];
|
||||
r[1] = a[1];
|
||||
r[2] = a[2];
|
||||
r[3] = a[3];
|
||||
}
|
||||
|
||||
/* double -> float */
|
||||
@ -208,7 +208,6 @@ MINLINE void copy_v4db_v4fl(double r[4], const float a[4])
|
||||
r[3] = (double)a[3];
|
||||
}
|
||||
|
||||
|
||||
MINLINE void swap_v2_v2(float a[2], float b[2])
|
||||
{
|
||||
SWAP(float, a[0], b[0]);
|
||||
@ -255,8 +254,8 @@ MINLINE void add_v2_v2(float r[2], const float a[2])
|
||||
|
||||
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
|
||||
{
|
||||
r[0]= a[0] + b[0];
|
||||
r[1]= a[1] + b[1];
|
||||
r[0] = a[0] + b[0];
|
||||
r[1] = a[1] + b[1];
|
||||
}
|
||||
|
||||
MINLINE void add_v3_v3(float r[3], const float a[3])
|
||||
@ -268,9 +267,9 @@ MINLINE void add_v3_v3(float r[3], const float a[3])
|
||||
|
||||
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
|
||||
{
|
||||
r[0]= a[0] + b[0];
|
||||
r[1]= a[1] + b[1];
|
||||
r[2]= a[2] + b[2];
|
||||
r[0] = a[0] + b[0];
|
||||
r[1] = a[1] + b[1];
|
||||
r[2] = a[2] + b[2];
|
||||
}
|
||||
|
||||
MINLINE void sub_v2_v2(float r[2], const float a[2])
|
||||
@ -281,8 +280,8 @@ MINLINE void sub_v2_v2(float r[2], const float a[2])
|
||||
|
||||
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
|
||||
{
|
||||
r[0]= a[0] - b[0];
|
||||
r[1]= a[1] - b[1];
|
||||
r[0] = a[0] - b[0];
|
||||
r[1] = a[1] - b[1];
|
||||
}
|
||||
|
||||
MINLINE void sub_v3_v3(float r[3], const float a[3])
|
||||
@ -294,9 +293,9 @@ MINLINE void sub_v3_v3(float r[3], const float a[3])
|
||||
|
||||
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
|
||||
{
|
||||
r[0]= a[0] - b[0];
|
||||
r[1]= a[1] - b[1];
|
||||
r[2]= a[2] - b[2];
|
||||
r[0] = a[0] - b[0];
|
||||
r[1] = a[1] - b[1];
|
||||
r[2] = a[2] - b[2];
|
||||
}
|
||||
|
||||
MINLINE void sub_v4_v4(float r[4], const float a[4])
|
||||
@ -309,23 +308,22 @@ MINLINE void sub_v4_v4(float r[4], const float a[4])
|
||||
|
||||
MINLINE void sub_v4_v4v4(float r[4], const float a[4], const float b[4])
|
||||
{
|
||||
r[0]= a[0] - b[0];
|
||||
r[1]= a[1] - b[1];
|
||||
r[2]= a[2] - b[2];
|
||||
r[3]= a[3] - b[3];
|
||||
r[0] = a[0] - b[0];
|
||||
r[1] = a[1] - b[1];
|
||||
r[2] = a[2] - b[2];
|
||||
r[3] = a[3] - b[3];
|
||||
}
|
||||
|
||||
|
||||
MINLINE void mul_v2_fl(float r[2], float f)
|
||||
{
|
||||
r[0]*= f;
|
||||
r[1]*= f;
|
||||
r[0] *= f;
|
||||
r[1] *= f;
|
||||
}
|
||||
|
||||
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
|
||||
{
|
||||
r[0]= a[0]*f;
|
||||
r[1]= a[1]*f;
|
||||
r[0] = a[0] * f;
|
||||
r[1] = a[1] * f;
|
||||
}
|
||||
|
||||
MINLINE void mul_v3_fl(float r[3], float f)
|
||||
@ -337,9 +335,9 @@ MINLINE void mul_v3_fl(float r[3], float f)
|
||||
|
||||
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
|
||||
{
|
||||
r[0]= a[0]*f;
|
||||
r[1]= a[1]*f;
|
||||
r[2]= a[2]*f;
|
||||
r[0] = a[0] * f;
|
||||
r[1] = a[1] * f;
|
||||
r[2] = a[2] * f;
|
||||
}
|
||||
|
||||
MINLINE void mul_v2_v2(float r[2], const float a[2])
|
||||
@ -357,58 +355,58 @@ MINLINE void mul_v3_v3(float r[3], const float a[3])
|
||||
|
||||
MINLINE void mul_v4_fl(float r[4], float f)
|
||||
{
|
||||
r[0]*= f;
|
||||
r[1]*= f;
|
||||
r[2]*= f;
|
||||
r[3]*= f;
|
||||
r[0] *= f;
|
||||
r[1] *= f;
|
||||
r[2] *= f;
|
||||
r[3] *= f;
|
||||
}
|
||||
|
||||
MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f)
|
||||
{
|
||||
r[0] += a[0]*f;
|
||||
r[1] += a[1]*f;
|
||||
r[0] += a[0] * f;
|
||||
r[1] += a[1] * f;
|
||||
}
|
||||
|
||||
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
|
||||
{
|
||||
r[0] += a[0]*f;
|
||||
r[1] += a[1]*f;
|
||||
r[2] += a[2]*f;
|
||||
r[0] += a[0] * f;
|
||||
r[1] += a[1] * f;
|
||||
r[2] += a[2] * f;
|
||||
}
|
||||
|
||||
MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3])
|
||||
{
|
||||
r[0] += a[0]*b[0];
|
||||
r[1] += a[1]*b[1];
|
||||
r[2] += a[2]*b[2];
|
||||
r[0] += a[0] * b[0];
|
||||
r[1] += a[1] * b[1];
|
||||
r[2] += a[2] * b[2];
|
||||
}
|
||||
|
||||
MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
|
||||
{
|
||||
r[0] = a[0] + b[0]*f;
|
||||
r[1] = a[1] + b[1]*f;
|
||||
r[0] = a[0] + b[0] * f;
|
||||
r[1] = a[1] + b[1] * f;
|
||||
}
|
||||
|
||||
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
|
||||
{
|
||||
r[0] = a[0] + b[0]*f;
|
||||
r[1] = a[1] + b[1]*f;
|
||||
r[2] = a[2] + b[2]*f;
|
||||
r[0] = a[0] + b[0] * f;
|
||||
r[1] = a[1] + b[1] * f;
|
||||
r[2] = a[2] + b[2] * f;
|
||||
}
|
||||
|
||||
MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3])
|
||||
{
|
||||
r[0] = a[0] + b[0]*c[0];
|
||||
r[1] = a[1] + b[1]*c[1];
|
||||
r[2] = a[2] + b[2]*c[2];
|
||||
r[0] = a[0] + b[0] * c[0];
|
||||
r[1] = a[1] + b[1] * c[1];
|
||||
r[2] = a[2] + b[2] * c[2];
|
||||
}
|
||||
|
||||
MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f)
|
||||
{
|
||||
r[0] += a[0]*f;
|
||||
r[1] += a[1]*f;
|
||||
r[2] += a[2]*f;
|
||||
r[3] += a[3]*f;
|
||||
r[0] += a[0] * f;
|
||||
r[1] += a[1] * f;
|
||||
r[2] += a[2] * f;
|
||||
r[3] += a[3] * f;
|
||||
}
|
||||
|
||||
MINLINE void mul_v3_v3v3(float r[3], const float v1[3], const float v2[3])
|
||||
@ -420,98 +418,98 @@ MINLINE void mul_v3_v3v3(float r[3], const float v1[3], const float v2[3])
|
||||
|
||||
MINLINE void negate_v2(float r[3])
|
||||
{
|
||||
r[0]= -r[0];
|
||||
r[1]= -r[1];
|
||||
r[0] = -r[0];
|
||||
r[1] = -r[1];
|
||||
}
|
||||
|
||||
MINLINE void negate_v2_v2(float r[2], const float a[2])
|
||||
{
|
||||
r[0]= -a[0];
|
||||
r[1]= -a[1];
|
||||
r[0] = -a[0];
|
||||
r[1] = -a[1];
|
||||
}
|
||||
|
||||
MINLINE void negate_v3(float r[3])
|
||||
{
|
||||
r[0]= -r[0];
|
||||
r[1]= -r[1];
|
||||
r[2]= -r[2];
|
||||
r[0] = -r[0];
|
||||
r[1] = -r[1];
|
||||
r[2] = -r[2];
|
||||
}
|
||||
|
||||
MINLINE void negate_v3_v3(float r[3], const float a[3])
|
||||
{
|
||||
r[0]= -a[0];
|
||||
r[1]= -a[1];
|
||||
r[2]= -a[2];
|
||||
r[0] = -a[0];
|
||||
r[1] = -a[1];
|
||||
r[2] = -a[2];
|
||||
}
|
||||
|
||||
MINLINE void negate_v4(float r[4])
|
||||
{
|
||||
r[0]= -r[0];
|
||||
r[1]= -r[1];
|
||||
r[2]= -r[2];
|
||||
r[3]= -r[3];
|
||||
r[0] = -r[0];
|
||||
r[1] = -r[1];
|
||||
r[2] = -r[2];
|
||||
r[3] = -r[3];
|
||||
}
|
||||
|
||||
MINLINE void negate_v4_v4(float r[4], const float a[4])
|
||||
{
|
||||
r[0]= -a[0];
|
||||
r[1]= -a[1];
|
||||
r[2]= -a[2];
|
||||
r[3]= -a[3];
|
||||
r[0] = -a[0];
|
||||
r[1] = -a[1];
|
||||
r[2] = -a[2];
|
||||
r[3] = -a[3];
|
||||
}
|
||||
|
||||
MINLINE float dot_v2v2(const float a[2], const float b[2])
|
||||
{
|
||||
return a[0]*b[0] + a[1]*b[1];
|
||||
return a[0] * b[0] + a[1] * b[1];
|
||||
}
|
||||
|
||||
MINLINE float dot_v3v3(const float a[3], const float b[3])
|
||||
{
|
||||
return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
|
||||
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
||||
}
|
||||
|
||||
MINLINE float cross_v2v2(const float a[2], const float b[2])
|
||||
{
|
||||
return a[0]*b[1] - a[1]*b[0];
|
||||
return a[0] * b[1] - a[1] * b[0];
|
||||
}
|
||||
|
||||
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
|
||||
{
|
||||
r[0]= a[1]*b[2] - a[2]*b[1];
|
||||
r[1]= a[2]*b[0] - a[0]*b[2];
|
||||
r[2]= a[0]*b[1] - a[1]*b[0];
|
||||
r[0] = a[1] * b[2] - a[2] * b[1];
|
||||
r[1] = a[2] * b[0] - a[0] * b[2];
|
||||
r[2] = a[0] * b[1] - a[1] * b[0];
|
||||
}
|
||||
|
||||
MINLINE void star_m3_v3(float rmat[][3], float a[3])
|
||||
{
|
||||
rmat[0][0]= rmat[1][1]= rmat[2][2]= 0.0;
|
||||
rmat[0][1]= -a[2];
|
||||
rmat[0][2]= a[1];
|
||||
rmat[1][0]= a[2];
|
||||
rmat[1][2]= -a[0];
|
||||
rmat[2][0]= -a[1];
|
||||
rmat[2][1]= a[0];
|
||||
rmat[0][0] = rmat[1][1] = rmat[2][2] = 0.0;
|
||||
rmat[0][1] = -a[2];
|
||||
rmat[0][2] = a[1];
|
||||
rmat[1][0] = a[2];
|
||||
rmat[1][2] = -a[0];
|
||||
rmat[2][0] = -a[1];
|
||||
rmat[2][1] = a[0];
|
||||
}
|
||||
|
||||
/*********************************** Length **********************************/
|
||||
|
||||
MINLINE float len_squared_v2(const float v[2])
|
||||
{
|
||||
return v[0]*v[0] + v[1]*v[1];
|
||||
return v[0] * v[0] + v[1] * v[1];
|
||||
}
|
||||
|
||||
MINLINE float len_v2(const float v[2])
|
||||
{
|
||||
return (float)sqrtf(v[0]*v[0] + v[1]*v[1]);
|
||||
return (float)sqrtf(v[0] * v[0] + v[1] * v[1]);
|
||||
}
|
||||
|
||||
MINLINE float len_v2v2(const float v1[2], const float v2[2])
|
||||
{
|
||||
float x, y;
|
||||
|
||||
x = v1[0]-v2[0];
|
||||
y = v1[1]-v2[1];
|
||||
return (float)sqrtf(x*x+y*y);
|
||||
x = v1[0] - v2[0];
|
||||
y = v1[1] - v2[1];
|
||||
return (float)sqrtf(x * x + y * y);
|
||||
}
|
||||
|
||||
MINLINE float len_v3(const float a[3])
|
||||
@ -545,15 +543,15 @@ MINLINE float len_squared_v3v3(const float a[3], const float b[3])
|
||||
|
||||
MINLINE float normalize_v2_v2(float r[2], const float a[2])
|
||||
{
|
||||
float d= dot_v2v2(a, a);
|
||||
float d = dot_v2v2(a, a);
|
||||
|
||||
if (d > 1.0e-35f) {
|
||||
d= sqrtf(d);
|
||||
mul_v2_v2fl(r, a, 1.0f/d);
|
||||
d = sqrtf(d);
|
||||
mul_v2_v2fl(r, a, 1.0f / d);
|
||||
}
|
||||
else {
|
||||
zero_v2(r);
|
||||
d= 0.0f;
|
||||
d = 0.0f;
|
||||
}
|
||||
|
||||
return d;
|
||||
@ -566,17 +564,17 @@ MINLINE float normalize_v2(float n[2])
|
||||
|
||||
MINLINE float normalize_v3_v3(float r[3], const float a[3])
|
||||
{
|
||||
float d= dot_v3v3(a, a);
|
||||
float d = dot_v3v3(a, a);
|
||||
|
||||
/* a larger value causes normalize errors in a
|
||||
* scaled down models with camera xtreme close */
|
||||
if (d > 1.0e-35f) {
|
||||
d= sqrtf(d);
|
||||
mul_v3_v3fl(r, a, 1.0f/d);
|
||||
d = sqrtf(d);
|
||||
mul_v3_v3fl(r, a, 1.0f / d);
|
||||
}
|
||||
else {
|
||||
zero_v3(r);
|
||||
d= 0.0f;
|
||||
d = 0.0f;
|
||||
}
|
||||
|
||||
return d;
|
||||
@ -584,14 +582,14 @@ MINLINE float normalize_v3_v3(float r[3], const float a[3])
|
||||
|
||||
MINLINE double normalize_v3_d(double n[3])
|
||||
{
|
||||
double d= n[0]*n[0] + n[1]*n[1] + n[2]*n[2];
|
||||
double d = n[0] * n[0] + n[1] * n[1] + n[2] * n[2];
|
||||
|
||||
/* a larger value causes normalize errors in a
|
||||
* scaled down models with camera xtreme close */
|
||||
if (d > 1.0e-35) {
|
||||
double mul;
|
||||
|
||||
d= sqrt(d);
|
||||
d = sqrt(d);
|
||||
mul = 1.0 / d;
|
||||
|
||||
n[0] *= mul;
|
||||
@ -600,7 +598,7 @@ MINLINE double normalize_v3_d(double n[3])
|
||||
}
|
||||
else {
|
||||
n[0] = n[1] = n[2] = 0;
|
||||
d= 0.0;
|
||||
d = 0.0;
|
||||
}
|
||||
|
||||
return d;
|
||||
@ -613,16 +611,16 @@ MINLINE float normalize_v3(float n[3])
|
||||
|
||||
MINLINE void normal_short_to_float_v3(float out[3], const short in[3])
|
||||
{
|
||||
out[0] = in[0]*(1.0f/32767.0f);
|
||||
out[1] = in[1]*(1.0f/32767.0f);
|
||||
out[2] = in[2]*(1.0f/32767.0f);
|
||||
out[0] = in[0] * (1.0f / 32767.0f);
|
||||
out[1] = in[1] * (1.0f / 32767.0f);
|
||||
out[2] = in[2] * (1.0f / 32767.0f);
|
||||
}
|
||||
|
||||
MINLINE void normal_float_to_short_v3(short out[3], const float in[3])
|
||||
{
|
||||
out[0] = (short)(in[0]*32767.0f);
|
||||
out[1] = (short)(in[1]*32767.0f);
|
||||
out[2] = (short)(in[2]*32767.0f);
|
||||
out[0] = (short) (in[0] * 32767.0f);
|
||||
out[1] = (short) (in[1] * 32767.0f);
|
||||
out[2] = (short) (in[2] * 32767.0f);
|
||||
}
|
||||
|
||||
/********************************* Comparison ********************************/
|
||||
@ -650,24 +648,24 @@ MINLINE int is_one_v3(const float v[3])
|
||||
|
||||
MINLINE int equals_v2v2(const float v1[2], const float v2[2])
|
||||
{
|
||||
return ((v1[0]==v2[0]) && (v1[1]==v2[1]));
|
||||
return ((v1[0] == v2[0]) && (v1[1] == v2[1]));
|
||||
}
|
||||
|
||||
MINLINE int equals_v3v3(const float v1[3], const float v2[3])
|
||||
{
|
||||
return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2]));
|
||||
return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]));
|
||||
}
|
||||
|
||||
MINLINE int equals_v4v4(const float v1[4], const float v2[4])
|
||||
{
|
||||
return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2]) && (v1[3]==v2[3]));
|
||||
return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]) && (v1[3] == v2[3]));
|
||||
}
|
||||
|
||||
MINLINE int compare_v3v3(const float v1[3], const float v2[3], const float limit)
|
||||
{
|
||||
if (fabsf(v1[0]-v2[0])<limit)
|
||||
if (fabsf(v1[1]-v2[1])<limit)
|
||||
if (fabsf(v1[2]-v2[2])<limit)
|
||||
if (fabsf(v1[0] - v2[0]) < limit)
|
||||
if (fabsf(v1[1] - v2[1]) < limit)
|
||||
if (fabsf(v1[2] - v2[2]) < limit)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
@ -675,21 +673,21 @@ MINLINE int compare_v3v3(const float v1[3], const float v2[3], const float limit
|
||||
|
||||
MINLINE int compare_len_v3v3(const float v1[3], const float v2[3], const float limit)
|
||||
{
|
||||
float x,y,z;
|
||||
float x, y, z;
|
||||
|
||||
x=v1[0]-v2[0];
|
||||
y=v1[1]-v2[1];
|
||||
z=v1[2]-v2[2];
|
||||
x = v1[0] - v2[0];
|
||||
y = v1[1] - v2[1];
|
||||
z = v1[2] - v2[2];
|
||||
|
||||
return ((x*x + y*y + z*z) < (limit*limit));
|
||||
return ((x * x + y * y + z * z) < (limit * limit));
|
||||
}
|
||||
|
||||
MINLINE int compare_v4v4(const float v1[4], const float v2[4], const float limit)
|
||||
{
|
||||
if (fabsf(v1[0]-v2[0])<limit)
|
||||
if (fabsf(v1[1]-v2[1])<limit)
|
||||
if (fabsf(v1[2]-v2[2])<limit)
|
||||
if (fabsf(v1[3]-v2[3])<limit)
|
||||
if (fabsf(v1[0] - v2[0]) < limit)
|
||||
if (fabsf(v1[1] - v2[1]) < limit)
|
||||
if (fabsf(v1[2] - v2[2]) < limit)
|
||||
if (fabsf(v1[3] - v2[3]) < limit)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
@ -697,8 +695,8 @@ MINLINE int compare_v4v4(const float v1[4], const float v2[4], const float limit
|
||||
|
||||
MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2])
|
||||
{
|
||||
return ((l1[0]-pt[0]) * (l2[1]-pt[1])) -
|
||||
((l2[0]-pt[0]) * (l1[1]-pt[1]));
|
||||
return (((l1[0] - pt[0]) * (l2[1] - pt[1])) -
|
||||
((l2[0] - pt[0]) * (l1[1] - pt[1])));
|
||||
}
|
||||
|
||||
#endif /* __MATH_VECTOR_INLINE_C__ */
|
||||
|
Loading…
Reference in New Issue
Block a user