Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 /* 00034 00035 * Copyright (c) 2000 Gino van den Bergen <gino@acm.org> 00036 * 00037 * Permission to use, copy, modify, distribute and sell this software 00038 * and its documentation for any purpose is hereby granted without fee, 00039 * provided that the above copyright notice appear in all copies and 00040 * that both that copyright notice and this permission notice appear 00041 * in supporting documentation. Gino van den Bergen makes no 00042 * representations about the suitability of this software for any 00043 * purpose. It is provided "as is" without express or implied warranty. 00044 * 00045 */ 00046 00047 #ifndef MT_SCALAR_H 00048 #define MT_SCALAR_H 00049 00050 #include <math.h> 00051 #include <float.h> 00052 00053 #include "MT_random.h" 00054 #include "NM_Scalar.h" 00055 00056 typedef double MT_Scalar; //this should be float ! 00057 00058 00059 const MT_Scalar MT_DEGS_PER_RAD(57.29577951308232286465); 00060 const MT_Scalar MT_RADS_PER_DEG(0.01745329251994329547); 00061 const MT_Scalar MT_PI(3.14159265358979323846); 00062 const MT_Scalar MT_2_PI(6.28318530717958623200); 00063 const MT_Scalar MT_EPSILON(1.0e-10); 00064 const MT_Scalar MT_EPSILON2(1.0e-20); 00065 const MT_Scalar MT_INFINITY(1.0e50); 00066 00067 inline int MT_sign(MT_Scalar x) { 00068 return x < 0.0 ? -1 : x > 0.0 ? 1 : 0; 00069 } 00070 00071 inline MT_Scalar MT_abs(MT_Scalar x) { return fabs(x); } 00072 00073 inline bool MT_fuzzyZero(MT_Scalar x) { return MT_abs(x) < MT_EPSILON; } 00074 inline bool MT_fuzzyZero2(MT_Scalar x) { return MT_abs(x) < MT_EPSILON2; } 00075 00076 inline MT_Scalar MT_radians(MT_Scalar x) { 00077 return x * MT_RADS_PER_DEG; 00078 } 00079 00080 inline MT_Scalar MT_degrees(MT_Scalar x) { 00081 return x * MT_DEGS_PER_RAD; 00082 } 00083 00084 inline MT_Scalar MT_random() { 00085 return MT_Scalar(MT_rand()) / MT_Scalar(MT_RAND_MAX); 00086 } 00087 00088 inline MT_Scalar MT_clamp(const MT_Scalar x, const MT_Scalar min, const MT_Scalar max) 00089 { 00090 if (x < min) 00091 return min; 00092 else if (x > max) 00093 return max; 00094 return x; 00095 } 00096 #endif 00097