]> icculus.org git repositories - taylor/freespace2.git/blob - include/floating.h
rendering functions mostly done; more complete shader setup
[taylor/freespace2.git] / include / floating.h
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Math/Floating.h $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Low-level floating point math macros and routines
16  *
17  * $Log$
18  * Revision 1.2  2002/06/09 04:41:13  relnev
19  * added copyright header
20  *
21  * Revision 1.1.1.1  2002/05/03 03:28:12  root
22  * Initial import.
23  *
24  * 
25  * 4     4/07/99 6:22p Dave
26  * Fred and Freespace support for multiple background bitmaps and suns.
27  * Fixed link errors on all subprojects. Moved encrypt_init() to
28  * cfile_init() and lcl_init(), since its safe to call twice.
29  * 
30  * 3     11/05/98 4:18p Dave
31  * First run nebula support. Beefed up localization a bit. Removed all
32  * conditional compiles for foreign versions. Modified mission file
33  * format.
34  * 
35  * 2     10/07/98 10:53a Dave
36  * Initial checkin.
37  * 
38  * 1     10/07/98 10:49a Dave
39  * 
40  * 13    2/26/98 3:28p John
41  * Changed all sqrt's to use fl_sqrt.  Took out isqrt function
42  * 
43  * 12    1/26/98 10:43p Mike
44  * Make ships not all zoom away from an impending shockwave at the same
45  * time.  Based on ai class and randomness
46  * 
47  * 11    1/17/98 3:32p Mike
48  * Add rand_range(), returns random float in min..max.
49  * 
50  * 10    7/29/97 2:36p Hoffoss
51  * Added header file required by _isnan().
52  * 
53  * 9     7/29/97 2:35p Hoffoss
54  * Added a NaN check macro.
55  * 
56  * 8     2/17/97 5:18p John
57  * Added a bunch of RCS headers to a bunch of old files that don't have
58  * them.
59  *
60  * $NoKeywords: $
61  */
62
63 #ifndef _FLOATING_H
64 #define _FLOATING_H
65
66 #include <math.h>
67 #include <float.h>
68
69 extern float fl_isqrt( float a );
70 extern float frand();
71 extern int rand_chance(float frametime, float chance = 1.0f);
72 float frand_range(float min, float max);
73
74 // determine if a floating point number is NaN (Not a Number)
75 #define fl_is_nan(fl) isnan(fl)
76
77 // Handy macros to prevent type casting all over the place
78
79 #define fl_sqrt(fl) (float)sqrt((float)(fl))
80 #define fl_isqrt(fl) (1.0f/(float)sqrt((float)(fl)))
81 #define fl_abs(fl) (float)fabs((double)(fl))
82 #define i2fl(i) ((float)(i))
83 #define fl2i(fl) ((int)(fl))
84 #define flceil(fl) (int)ceil(fl)
85 #define flfloor(fl) (int)floor(fl)
86 #define f2fl(fx) ((float)(fx)/65536.0f)
87 #define fl2f(fl) (int)((fl)*65536.0f)
88
89 // convert a measurement in degrees to radians
90 #define fl_radian(fl)   ((float)((fl * 3.14159f)/180.0f))
91
92 // convert a measurement in radians to degrees
93 #define fl_degrees(fl)  ((float)((fl * 180.0f)/3.14159))
94
95 // use this instead of:
96 // for:  (int)floor(x+0.5f) use fl_round_2048(x)
97 //       (int)ceil(x-0.5f)  use fl_round_2048(x)
98 //       (int)floor(x-0.5f) use fl_round_2048(x-1.0f)
99 //       (int)floor(x)      use fl_round_2048(x-0.5f)
100 // for values in the range -2048 to 2048
101 // use this instead of:
102 // for:  (int)floor(x+0.5f) use fl_round_2048(x)
103 //       (int)ceil(x-0.5f)  use fl_round_2048(x)
104 //       (int)floor(x-0.5f) use fl_round_2048(x-1.0f)
105 //       (int)floor(x)      use fl_round_2048(x-0.5f)
106 // for values in the range -2048 to 2048
107
108 /*
109 extern const float *p_fl_magic;
110
111 inline int fl_round_2048( float x )
112 {
113         double tmp_quad;
114         tmp_quad = x + *p_fl_magic;
115         return *((int *)&tmp_quad);
116 }
117
118 inline float fl_sqrt( float x)
119 {
120         float retval;
121
122         _asm fld x
123         _asm fsqrt
124         _asm fstp retval
125         
126         return retval;
127 }
128
129 float fl_isqrt( float x )
130 {
131         float retval;
132
133         _asm fld x
134         _asm fsqrt
135         _asm fstp retval
136         
137         return 1.0f / retval;
138
139 */
140
141
142
143 // rounds off a floating point number to a multiple of some number
144 extern float fl_roundoff(float x, int multiple);
145
146
147 #endif
148