2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-11-10 19:13:05 +00:00
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-11-10 19:13:05 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
|
|
|
|
* The Original Code is: some of this file.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
* */
|
|
|
|
|
2011-02-27 20:37:56 +00:00
|
|
|
/** \file blender/blenlib/intern/math_vector_inline.c
|
|
|
|
* \ingroup bli
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-11-10 19:13:05 +00:00
|
|
|
#include "BLI_math.h"
|
|
|
|
|
2011-01-15 16:14:57 +00:00
|
|
|
#ifndef BLI_MATH_VECTOR_INLINE_H
|
|
|
|
#define BLI_MATH_VECTOR_INLINE_H
|
2009-11-10 19:13:05 +00:00
|
|
|
|
|
|
|
/********************************** Init *************************************/
|
|
|
|
|
|
|
|
MINLINE void zero_v2(float r[2])
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-01-22 11:10:24 +00:00
|
|
|
MINLINE void zero_v4(float r[4])
|
|
|
|
{
|
|
|
|
r[0]= 0.0f;
|
|
|
|
r[1]= 0.0f;
|
|
|
|
r[2]= 0.0f;
|
|
|
|
r[3]= 0.0f;
|
|
|
|
}
|
|
|
|
|
2009-12-27 01:32:58 +00:00
|
|
|
MINLINE void copy_v2_v2(float r[2], const float a[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
r[0]= a[0];
|
|
|
|
r[1]= a[1];
|
|
|
|
}
|
|
|
|
|
2009-12-27 01:32:58 +00:00
|
|
|
MINLINE void copy_v3_v3(float r[3], const float a[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
r[0]= a[0];
|
|
|
|
r[1]= a[1];
|
|
|
|
r[2]= a[2];
|
|
|
|
}
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void copy_v4_v4(float r[4], const float a[4])
|
2010-01-22 11:10:24 +00:00
|
|
|
{
|
|
|
|
r[0]= a[0];
|
|
|
|
r[1]= a[1];
|
|
|
|
r[2]= a[2];
|
|
|
|
r[3]= a[3];
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:14:12 +00:00
|
|
|
/* short */
|
|
|
|
MINLINE void copy_v2_v2_short(short r[2], const short a[2])
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2009-11-28 13:11:41 +00:00
|
|
|
MINLINE void swap_v2_v2(float a[2], float b[2])
|
|
|
|
{
|
|
|
|
SWAP(float, a[0], b[0]);
|
|
|
|
SWAP(float, a[1], b[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
MINLINE void swap_v3_v3(float a[3], float b[3])
|
|
|
|
{
|
|
|
|
SWAP(float, a[0], b[0]);
|
|
|
|
SWAP(float, a[1], b[1]);
|
|
|
|
SWAP(float, a[2], b[2]);
|
|
|
|
}
|
|
|
|
|
2010-01-22 11:10:24 +00:00
|
|
|
MINLINE void swap_v4_v4(float a[4], float b[4])
|
|
|
|
{
|
|
|
|
SWAP(float, a[0], b[0]);
|
|
|
|
SWAP(float, a[1], b[1]);
|
|
|
|
SWAP(float, a[2], b[2]);
|
|
|
|
SWAP(float, a[3], b[3]);
|
|
|
|
}
|
|
|
|
|
2009-11-10 19:13:05 +00:00
|
|
|
/********************************* Arithmetic ********************************/
|
|
|
|
|
2011-06-06 22:10:05 +00:00
|
|
|
MINLINE void add_v3_fl(float r[3], float f)
|
|
|
|
{
|
|
|
|
r[0] += f;
|
|
|
|
r[1] += f;
|
|
|
|
r[2] += f;
|
|
|
|
}
|
|
|
|
|
|
|
|
MINLINE void add_v4_fl(float r[4], float f)
|
|
|
|
{
|
|
|
|
r[0] += f;
|
|
|
|
r[1] += f;
|
|
|
|
r[2] += f;
|
|
|
|
r[3] += f;
|
|
|
|
}
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void add_v2_v2(float *r, const float *a)
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
r[0] += a[0];
|
|
|
|
r[1] += a[1];
|
|
|
|
}
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void add_v2_v2v2(float *r, const float *a, const float *b)
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
r[0]= a[0] + b[0];
|
|
|
|
r[1]= a[1] + b[1];
|
|
|
|
}
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void add_v3_v3(float *r, const float *a)
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
r[0] += a[0];
|
|
|
|
r[1] += a[1];
|
2009-11-28 13:11:41 +00:00
|
|
|
r[2] += a[2];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
r[0]= a[0] + b[0];
|
|
|
|
r[1]= a[1] + b[1];
|
|
|
|
r[2]= a[2] + b[2];
|
|
|
|
}
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE void sub_v2_v2(float r[2], const float a[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
r[0] -= a[0];
|
|
|
|
r[1] -= a[1];
|
|
|
|
}
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
r[0]= a[0] - b[0];
|
|
|
|
r[1]= a[1] - b[1];
|
|
|
|
}
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE void sub_v3_v3(float r[3], const float a[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
r[0] -= a[0];
|
|
|
|
r[1] -= a[1];
|
2009-11-28 13:11:41 +00:00
|
|
|
r[2] -= a[2];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
2009-12-27 01:32:58 +00:00
|
|
|
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
r[0]= a[0] - b[0];
|
|
|
|
r[1]= a[1] - b[1];
|
|
|
|
r[2]= a[2] - b[2];
|
|
|
|
}
|
|
|
|
|
2010-11-12 11:16:04 +00:00
|
|
|
MINLINE void sub_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];
|
|
|
|
}
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE void sub_v4_v4v4(float r[4], const float a[4], const float b[4])
|
2010-11-12 11:16:04 +00:00
|
|
|
{
|
|
|
|
r[0]= a[0] - b[0];
|
|
|
|
r[1]= a[1] - b[1];
|
|
|
|
r[2]= a[2] - b[2];
|
|
|
|
r[3]= a[3] - b[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE void mul_v2_fl(float r[2], float f)
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2011-08-26 22:37:20 +00:00
|
|
|
r[0]*= f;
|
|
|
|
r[1]*= f;
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
2010-01-12 19:47:54 +00:00
|
|
|
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
|
|
|
|
{
|
|
|
|
r[0]= a[0]*f;
|
|
|
|
r[1]= a[1]*f;
|
|
|
|
}
|
|
|
|
|
2009-11-10 19:13:05 +00:00
|
|
|
MINLINE void mul_v3_fl(float r[3], float f)
|
|
|
|
{
|
|
|
|
r[0] *= f;
|
|
|
|
r[1] *= f;
|
|
|
|
r[2] *= f;
|
|
|
|
}
|
|
|
|
|
2010-01-12 19:47:54 +00:00
|
|
|
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
r[0]= a[0]*f;
|
|
|
|
r[1]= a[1]*f;
|
|
|
|
r[2]= a[2]*f;
|
|
|
|
}
|
|
|
|
|
2010-01-07 12:41:07 +00:00
|
|
|
MINLINE void mul_v2_v2(float r[2], const float a[2])
|
|
|
|
{
|
|
|
|
r[0] *= a[0];
|
|
|
|
r[1] *= a[1];
|
|
|
|
}
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void mul_v3_v3(float r[3], const float a[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
r[0] *= a[0];
|
|
|
|
r[1] *= a[1];
|
|
|
|
r[2] *= a[2];
|
|
|
|
}
|
|
|
|
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
MINLINE void mul_v4_fl(float r[4], float f)
|
|
|
|
{
|
|
|
|
r[0]*= f;
|
|
|
|
r[1]*= f;
|
|
|
|
r[2]*= f;
|
|
|
|
r[3]*= f;
|
|
|
|
}
|
|
|
|
|
2010-04-15 10:28:32 +00:00
|
|
|
MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f)
|
|
|
|
{
|
|
|
|
r[0] += a[0]*f;
|
|
|
|
r[1] += a[1]*f;
|
|
|
|
}
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
|
2009-11-28 13:11:41 +00:00
|
|
|
{
|
|
|
|
r[0] += a[0]*f;
|
|
|
|
r[1] += a[1]*f;
|
|
|
|
r[2] += a[2]*f;
|
|
|
|
}
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3])
|
2009-11-28 13:11:41 +00:00
|
|
|
{
|
|
|
|
r[0] += a[0]*b[0];
|
|
|
|
r[1] += a[1]*b[1];
|
|
|
|
r[2] += a[2]*b[2];
|
|
|
|
}
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
|
2010-01-07 12:41:07 +00:00
|
|
|
{
|
|
|
|
r[0] = a[0] + b[0]*f;
|
|
|
|
r[1] = a[1] + b[1]*f;
|
|
|
|
}
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
|
2009-11-28 13:11:41 +00:00
|
|
|
{
|
|
|
|
r[0] = a[0] + b[0]*f;
|
|
|
|
r[1] = a[1] + b[1]*f;
|
|
|
|
r[2] = a[2] + b[2]*f;
|
|
|
|
}
|
|
|
|
|
2010-03-22 15:55:12 +00:00
|
|
|
MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3])
|
2009-11-28 13:11:41 +00:00
|
|
|
{
|
|
|
|
r[0] = a[0] + b[0]*c[0];
|
|
|
|
r[1] = a[1] + b[1]*c[1];
|
|
|
|
r[2] = a[2] + b[2]*c[2];
|
|
|
|
}
|
|
|
|
|
2010-04-15 10:28:32 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE void mul_v3_v3v3(float r[3], const float v1[3], const float v2[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2011-08-26 22:37:20 +00:00
|
|
|
r[0] = v1[0] * v2[0];
|
|
|
|
r[1] = v1[1] * v2[1];
|
|
|
|
r[2] = v1[2] * v2[2];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MINLINE void negate_v3(float r[3])
|
|
|
|
{
|
|
|
|
r[0]= -r[0];
|
|
|
|
r[1]= -r[1];
|
|
|
|
r[2]= -r[2];
|
|
|
|
}
|
|
|
|
|
2009-12-29 15:40:26 +00:00
|
|
|
MINLINE void negate_v3_v3(float r[3], const float a[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
r[0]= -a[0];
|
|
|
|
r[1]= -a[1];
|
|
|
|
r[2]= -a[2];
|
|
|
|
}
|
|
|
|
|
2011-02-02 00:40:55 +00:00
|
|
|
MINLINE void negate_v4(float r[4])
|
|
|
|
{
|
|
|
|
r[0]= -r[0];
|
|
|
|
r[1]= -r[1];
|
|
|
|
r[2]= -r[2];
|
|
|
|
r[3]= -r[3];
|
|
|
|
}
|
|
|
|
|
2011-02-08 03:37:49 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2009-12-29 15:40:26 +00:00
|
|
|
MINLINE float dot_v2v2(const float a[2], const float b[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
return a[0]*b[0] + a[1]*b[1];
|
|
|
|
}
|
|
|
|
|
2009-12-29 15:40:26 +00:00
|
|
|
MINLINE float dot_v3v3(const float a[3], const float b[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
|
|
|
|
}
|
|
|
|
|
2009-12-29 15:40:26 +00:00
|
|
|
MINLINE float cross_v2v2(const float a[2], const float b[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2011-04-21 15:53:30 +00:00
|
|
|
return a[0]*b[1] - a[1]*b[0];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
2009-12-27 01:32:58 +00:00
|
|
|
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE void star_m3_v3(float rmat[][3], float a[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2011-08-26 22:37:20 +00:00
|
|
|
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];
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************** Length **********************************/
|
|
|
|
|
2009-12-29 15:40:26 +00:00
|
|
|
MINLINE float len_v2(const float v[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2010-10-03 14:16:27 +00:00
|
|
|
return (float)sqrtf(v[0]*v[0] + v[1]*v[1]);
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
2009-12-29 15:40:26 +00:00
|
|
|
MINLINE float len_v2v2(const float v1[2], const float v2[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
float x, y;
|
|
|
|
|
|
|
|
x = v1[0]-v2[0];
|
|
|
|
y = v1[1]-v2[1];
|
2010-10-03 14:16:27 +00:00
|
|
|
return (float)sqrtf(x*x+y*y);
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
|
2009-12-29 15:40:26 +00:00
|
|
|
MINLINE float len_v3(const float a[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
return sqrtf(dot_v3v3(a, a));
|
|
|
|
}
|
|
|
|
|
2010-10-03 14:16:27 +00:00
|
|
|
MINLINE float len_squared_v2v2(const float a[3], const float b[3])
|
|
|
|
{
|
|
|
|
float d[2];
|
|
|
|
|
|
|
|
sub_v2_v2v2(d, b, a);
|
|
|
|
return dot_v2v2(d, d);
|
|
|
|
}
|
|
|
|
|
2009-12-29 15:40:26 +00:00
|
|
|
MINLINE float len_v3v3(const float a[3], const float b[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
|
|
|
float d[3];
|
|
|
|
|
|
|
|
sub_v3_v3v3(d, b, a);
|
|
|
|
return len_v3(d);
|
|
|
|
}
|
|
|
|
|
2010-04-15 10:28:32 +00:00
|
|
|
MINLINE float len_squared_v3v3(const float a[3], const float b[3])
|
|
|
|
{
|
|
|
|
float d[3];
|
|
|
|
|
|
|
|
sub_v3_v3v3(d, b, a);
|
|
|
|
return dot_v3v3(d, d);
|
|
|
|
}
|
|
|
|
|
2010-01-12 19:47:54 +00:00
|
|
|
MINLINE float normalize_v2_v2(float r[2], const float a[2])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2010-01-12 19:47:54 +00:00
|
|
|
float d= dot_v2v2(a, a);
|
2009-11-10 19:13:05 +00:00
|
|
|
|
|
|
|
if(d > 1.0e-35f) {
|
|
|
|
d= sqrtf(d);
|
2010-01-12 19:47:54 +00:00
|
|
|
mul_v2_v2fl(r, a, 1.0f/d);
|
2009-11-10 19:13:05 +00:00
|
|
|
} else {
|
2010-01-12 19:47:54 +00:00
|
|
|
zero_v2(r);
|
2009-11-10 19:13:05 +00:00
|
|
|
d= 0.0f;
|
|
|
|
}
|
2010-01-12 19:47:54 +00:00
|
|
|
|
2009-11-10 19:13:05 +00:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2010-01-12 19:47:54 +00:00
|
|
|
MINLINE float normalize_v2(float n[2])
|
|
|
|
{
|
|
|
|
return normalize_v2_v2(n, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
MINLINE float normalize_v3_v3(float r[3], const float a[3])
|
2009-11-10 19:13:05 +00:00
|
|
|
{
|
2010-01-12 19:47:54 +00:00
|
|
|
float d= dot_v3v3(a, a);
|
2009-11-10 19:13:05 +00:00
|
|
|
|
|
|
|
/* a larger value causes normalize errors in a
|
|
|
|
scaled down models with camera xtreme close */
|
|
|
|
if(d > 1.0e-35f) {
|
|
|
|
d= sqrtf(d);
|
2010-01-12 19:47:54 +00:00
|
|
|
mul_v3_v3fl(r, a, 1.0f/d);
|
2009-11-10 19:13:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-01-12 19:47:54 +00:00
|
|
|
zero_v3(r);
|
2009-11-10 19:13:05 +00:00
|
|
|
d= 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2010-01-12 19:47:54 +00:00
|
|
|
MINLINE float normalize_v3(float n[3])
|
|
|
|
{
|
|
|
|
return normalize_v3_v3(n, n);
|
|
|
|
}
|
|
|
|
|
2011-04-27 04:57:57 +00:00
|
|
|
MINLINE void normal_short_to_float_v3(float out[3], const short in[3])
|
2009-11-28 13:11:41 +00:00
|
|
|
{
|
|
|
|
out[0] = in[0]*(1.0f/32767.0f);
|
|
|
|
out[1] = in[1]*(1.0f/32767.0f);
|
|
|
|
out[2] = in[2]*(1.0f/32767.0f);
|
|
|
|
}
|
|
|
|
|
2011-04-27 04:57:57 +00:00
|
|
|
MINLINE void normal_float_to_short_v3(short out[3], const float in[3])
|
2009-11-28 13:11:41 +00:00
|
|
|
{
|
|
|
|
out[0] = (short)(in[0]*32767.0f);
|
|
|
|
out[1] = (short)(in[1]*32767.0f);
|
|
|
|
out[2] = (short)(in[2]*32767.0f);
|
|
|
|
}
|
|
|
|
|
2010-01-22 11:10:24 +00:00
|
|
|
/********************************* Comparison ********************************/
|
|
|
|
|
2011-02-06 09:01:01 +00:00
|
|
|
MINLINE int is_zero_v3(const float v[3])
|
2010-01-22 11:10:24 +00:00
|
|
|
{
|
|
|
|
return (v[0] == 0 && v[1] == 0 && v[2] == 0);
|
|
|
|
}
|
|
|
|
|
2011-02-06 09:01:01 +00:00
|
|
|
MINLINE int is_zero_v4(const float v[4])
|
|
|
|
{
|
|
|
|
return (v[0] == 0 && v[1] == 0 && v[2] == 0 && v[3] == 0);
|
|
|
|
}
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE int is_one_v3(const float v[3])
|
2010-01-22 11:10:24 +00:00
|
|
|
{
|
|
|
|
return (v[0] == 1 && v[1] == 1 && v[2] == 1);
|
|
|
|
}
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE int equals_v2v2(const float v1[2], const float v2[2])
|
2010-12-11 21:27:39 +00:00
|
|
|
{
|
|
|
|
return ((v1[0]==v2[0]) && (v1[1]==v2[1]));
|
|
|
|
}
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE int equals_v3v3(const float v1[3], const float v2[3])
|
2010-01-22 11:10:24 +00:00
|
|
|
{
|
|
|
|
return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2]));
|
|
|
|
}
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE int equals_v4v4(const float v1[4], const float v2[4])
|
2010-07-27 04:56:24 +00:00
|
|
|
{
|
|
|
|
return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2]) && (v1[3]==v2[3]));
|
|
|
|
}
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE int compare_v3v3(const float v1[3], const float v2[3], const float limit)
|
2010-01-22 11:10:24 +00:00
|
|
|
{
|
2011-03-27 14:59:55 +00:00
|
|
|
if(fabsf(v1[0]-v2[0])<limit)
|
|
|
|
if(fabsf(v1[1]-v2[1])<limit)
|
|
|
|
if(fabsf(v1[2]-v2[2])<limit)
|
2010-01-22 11:10:24 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE int compare_len_v3v3(const float v1[3], const float v2[3], const float limit)
|
2010-01-22 11:10:24 +00:00
|
|
|
{
|
2010-03-22 09:30:00 +00:00
|
|
|
float x,y,z;
|
2010-01-22 11:10:24 +00:00
|
|
|
|
|
|
|
x=v1[0]-v2[0];
|
|
|
|
y=v1[1]-v2[1];
|
|
|
|
z=v1[2]-v2[2];
|
|
|
|
|
|
|
|
return ((x*x + y*y + z*z) < (limit*limit));
|
|
|
|
}
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE int compare_v4v4(const float v1[4], const float v2[4], const float limit)
|
2010-01-22 11:10:24 +00:00
|
|
|
{
|
2011-03-27 14:59:55 +00:00
|
|
|
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)
|
2010-01-22 11:10:24 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-26 22:37:20 +00:00
|
|
|
MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2])
|
2010-10-15 05:18:45 +00:00
|
|
|
{
|
|
|
|
return ((l1[0]-pt[0]) * (l2[1]-pt[1])) -
|
|
|
|
((l2[0]-pt[0]) * (l1[1]-pt[1]));
|
|
|
|
}
|
|
|
|
|
2011-01-15 16:14:57 +00:00
|
|
|
#endif /* BLI_MATH_VECTOR_INLINE_H */
|
2009-11-10 19:13:05 +00:00
|
|
|
|