1 /* NAME: 2 E3Utils.h 3 4 DESCRIPTION: 5 Header file for E3Utils.c. 6 7 COPYRIGHT: 8 Copyright (c) 1999-2004, Quesa Developers. All rights reserved. 9 10 For the current release of Quesa, please see: 11 12 <http://www.quesa.org/> 13 14 Redistribution and use in source and binary forms, with or without 15 modification, are permitted provided that the following conditions 16 are met: 17 18 o Redistributions of source code must retain the above copyright 19 notice, this list of conditions and the following disclaimer. 20 21 o Redistributions in binary form must reproduce the above 22 copyright notice, this list of conditions and the following 23 disclaimer in the documentation and/or other materials provided 24 with the distribution. 25 26 o Neither the name of Quesa nor the names of its contributors 27 may be used to endorse or promote products derived from this 28 software without specific prior written permission. 29 30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 31 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 32 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 33 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 34 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 35 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 36 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 37 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 38 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 39 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 40 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 ___________________________________________________________________________ 42 */ 43 #ifndef E3UTILS_HDR 44 #define E3UTILS_HDR 45 //============================================================================= 46 // C++ preamble 47 //----------------------------------------------------------------------------- 48 #ifdef __cplusplus 49 extern "C" { 50 #endif 51 52 53 54 55 56 //============================================================================= 57 // Types 58 //----------------------------------------------------------------------------- 59 typedef TQ3AttributeSet (*E3GetSetForGatherProc)(const void *userData, TQ3Uns32 setIndex); 60 61 62 63 64 65 //============================================================================= 66 // Macros 67 //----------------------------------------------------------------------------- 68 #define E3Rect_GetWidth(_r) (TQ3Uns32) ((_r)->right - (_r)->left) 69 70 #define E3Rect_GetHeight(_r) (TQ3Uns32) ((_r)->bottom - (_r)->top) 71 72 #define E3Area_FromRect(_area, _rect) \ 73 do \ 74 { \ 75 (_area)->min.x = (float) (_rect)->left; \ 76 (_area)->min.y = (float) (_rect)->top; \ 77 (_area)->max.x = (float) (_rect)->right; \ 78 (_area)->max.y = (float) (_rect)->bottom; \ 79 } \ 80 while (0) 81 82 #define E3Area_ToRect(_area, _rect) \ 83 do \ 84 { \ 85 (_rect)->left = (TQ3Int16) (_area)->min.x; \ 86 (_rect)->top = (TQ3Int16) (_area)->min.y; \ 87 (_rect)->right = (TQ3Int16) (_area)->max.x; \ 88 (_rect)->bottom = (TQ3Int16) (_area)->max.y; \ 89 } \ 90 while (0) 91 92 #define E3Integer_Swap(_a, _b) \ 93 do \ 94 { \ 95 TQ3Uns32 _temp; \ 96 \ 97 _temp = (_a); \ 98 (_a) = (_b); \ 99 (_b) = _temp; \ 100 } \ 101 while (0) 102 103 #define E3Float_Swap(_a, _b) \ 104 do \ 105 { \ 106 float _temp; \ 107 \ 108 _temp = (_a); \ 109 (_a) = (_b); \ 110 (_b) = _temp; \ 111 } \ 112 while (0) 113 114 #define E3Num_Min(_a, _b) ((_a) < (_b) ? (_a) : (_b)) 115 116 #define E3Num_Max(_a, _b) ((_a) > (_b) ? (_a) : (_b)) 117 118 #define E3Num_Clamp(_n, _min, _max) E3Num_Max(E3Num_Min((_n), (_max)), (_min)) 119 120 #define E3Integer_Abs(_a) ((_a) > 0 ? (_a) : -(_a)) 121 122 #define E3Float_Abs(_a) ((_a) > 0.0f ? (_a) : -(_a)) 123 124 #define E3Bit_Set(_bf, _b) (_bf) |= (_b) 125 126 #define E3Bit_Clear(_bf, _b) (_bf) &= ~(_b) 127 128 #define E3Bit_AnySet(_bf, _b) ((TQ3Boolean) (((_bf) & (_b)) != 0)) 129 130 #define E3Bit_IsSet(_bf, _b) ((TQ3Boolean) (((_bf) & (_b)) == (_b))) 131 132 #define E3Bit_IsNotSet(_bf, _b) ((TQ3Boolean) !E3Bit_IsSet(_bf, _b)) 133 134 #define E3EndianSwap16(_value) \ 135 (((((TQ3Uns16) _value) << 8) & 0xFF00) | \ 136 ((((TQ3Uns16) _value) >> 8) & 0x00FF)) 137 138 #define E3EndianSwap32(_value) \ 139 (((((TQ3Uns32) _value) << 24) & 0xFF000000) | \ 140 ((((TQ3Uns32) _value) << 8) & 0x00FF0000) | \ 141 ((((TQ3Uns32) _value) >> 8) & 0x0000FF00) | \ 142 ((((TQ3Uns32) _value) >> 24) & 0x000000FF)) 143 144 145 146 147 148 //============================================================================= 149 // Function prototypes 150 //----------------------------------------------------------------------------- 151 void E3Shared_Acquire(TQ3SharedObject *newRef, TQ3SharedObject theObject); 152 153 void E3Shared_Replace(TQ3SharedObject *origObject, TQ3SharedObject newObject); 154 155 TQ3Status E3Bitmap_Replace(const TQ3Bitmap *original, TQ3Bitmap *copy, TQ3Boolean isCopyInternal); 156 157 void E3AttributeSet_Combine(TQ3AttributeSet parent, TQ3AttributeSet child, TQ3AttributeSet *result); 158 159 void E3Geometry_AddNormalIndicators(TQ3GroupObject group, TQ3Uns32 numPoints, const TQ3Point3D *points, const TQ3Vector3D *normals); 160 161 TQ3Boolean E3Matrix4x4_IsIdentity(const TQ3Matrix4x4 *theMatrix); 162 163 TQ3Boolean E3CString_IsEqual(const char *str_a, const char *str_b); 164 165 TQ3Boolean E3Rect_ClipLine(const TQ3Area *theRect, TQ3Point2D *lineStart, TQ3Point2D *lineEnd); 166 167 TQ3Boolean E3Rect_ContainsLine(const TQ3Area *theRect, const TQ3Point2D *lineStart, const TQ3Point2D *lineEnd); 168 169 TQ3Boolean E3Rect_ContainsRect(const TQ3Area *rect1, const TQ3Area *rect2); 170 171 TQ3Boolean E3Rect_IntersectRect(const TQ3Area *rect1, const TQ3Area *rect2); 172 173 void E3Triangle_InterpolateHit ( TQ3ViewObject theView, 174 const TQ3TriangleData *triangleData, 175 const TQ3Param3D *theHit, 176 TQ3Point3D *hitXYZ, 177 TQ3Vector3D *hitNormal, 178 TQ3Param2D *hitUV, 179 TQ3Boolean *haveUV); 180 181 TQ3Boolean E3TriMeshAttribute_GatherArray(TQ3Uns32 numSets, 182 E3GetSetForGatherProc userCallback, 183 const void *userData, 184 TQ3TriMeshAttributeData *theAttribute, 185 TQ3AttributeType attributeType); 186 187 TQ3GroupObject E3TriMesh_BuildOrientationGroup(TQ3GeometryObject theTriMesh, TQ3OrientationStyle theOrientation); 188 189 190 191 192 193 //============================================================================= 194 // C++ postamble 195 //----------------------------------------------------------------------------- 196 #ifdef __cplusplus 197 } 198 #endif 199 200 #endif 201 202