~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to extern/recastnavigation/Detour/Include/DetourCommon.h

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Copyright (c) 2009 Mikko Mononen memon@inside.org
 
3
//
 
4
// This software is provided 'as-is', without any express or implied
 
5
// warranty.  In no event will the authors be held liable for any damages
 
6
// arising from the use of this software.
 
7
// Permission is granted to anyone to use this software for any purpose,
 
8
// including commercial applications, and to alter it and redistribute it
 
9
// freely, subject to the following restrictions:
 
10
// 1. The origin of this software must not be misrepresented; you must not
 
11
//    claim that you wrote the original software. If you use this software
 
12
//    in a product, an acknowledgment in the product documentation would be
 
13
//    appreciated but is not required.
 
14
// 2. Altered source versions must be plainly marked as such, and must not be
 
15
//    misrepresented as being the original software.
 
16
// 3. This notice may not be removed or altered from any source distribution.
 
17
//
 
18
 
 
19
#ifndef DETOURCOMMON_H
 
20
#define DETOURCOMMON_H
 
21
 
 
22
//////////////////////////////////////////////////////////////////////////////////////////
 
23
 
 
24
template<class T> inline void swap(T& a, T& b) { T t = a; a = b; b = t; }
 
25
template<class T> inline T min(T a, T b) { return a < b ? a : b; }
 
26
template<class T> inline T max(T a, T b) { return a > b ? a : b; }
 
27
template<class T> inline T abs(T a) { return a < 0 ? -a : a; }
 
28
template<class T> inline T sqr(T a) { return a*a; }
 
29
template<class T> inline T clamp(T v, T mn, T mx) { return v < mn ? mn : (v > mx ? mx : v); }
 
30
 
 
31
inline void vcross(float* dest, const float* v1, const float* v2)
 
32
{
 
33
        dest[0] = v1[1]*v2[2] - v1[2]*v2[1];
 
34
        dest[1] = v1[2]*v2[0] - v1[0]*v2[2];
 
35
        dest[2] = v1[0]*v2[1] - v1[1]*v2[0]; 
 
36
}
 
37
 
 
38
inline float vdot(const float* v1, const float* v2)
 
39
{
 
40
        return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
 
41
}
 
42
 
 
43
inline void vmad(float* dest, const float* v1, const float* v2, const float s)
 
44
{
 
45
        dest[0] = v1[0]+v2[0]*s;
 
46
        dest[1] = v1[1]+v2[1]*s;
 
47
        dest[2] = v1[2]+v2[2]*s;
 
48
}
 
49
 
 
50
inline void vadd(float* dest, const float* v1, const float* v2)
 
51
{
 
52
        dest[0] = v1[0]+v2[0];
 
53
        dest[1] = v1[1]+v2[1];
 
54
        dest[2] = v1[2]+v2[2];
 
55
}
 
56
 
 
57
inline void vsub(float* dest, const float* v1, const float* v2)
 
58
{
 
59
        dest[0] = v1[0]-v2[0];
 
60
        dest[1] = v1[1]-v2[1];
 
61
        dest[2] = v1[2]-v2[2];
 
62
}
 
63
 
 
64
inline void vmin(float* mn, const float* v)
 
65
{
 
66
        mn[0] = min(mn[0], v[0]);
 
67
        mn[1] = min(mn[1], v[1]);
 
68
        mn[2] = min(mn[2], v[2]);
 
69
}
 
70
 
 
71
inline void vmax(float* mx, const float* v)
 
72
{
 
73
        mx[0] = max(mx[0], v[0]);
 
74
        mx[1] = max(mx[1], v[1]);
 
75
        mx[2] = max(mx[2], v[2]);
 
76
}
 
77
 
 
78
inline void vcopy(float* dest, const float* a)
 
79
{
 
80
        dest[0] = a[0];
 
81
        dest[1] = a[1];
 
82
        dest[2] = a[2];
 
83
}
 
84
 
 
85
inline float vdist(const float* v1, const float* v2)
 
86
{
 
87
        float dx = v2[0] - v1[0];
 
88
        float dy = v2[1] - v1[1];
 
89
        float dz = v2[2] - v1[2];
 
90
        return sqrtf(dx*dx + dy*dy + dz*dz);
 
91
}
 
92
 
 
93
inline float vdistSqr(const float* v1, const float* v2)
 
94
{
 
95
        float dx = v2[0] - v1[0];
 
96
        float dy = v2[1] - v1[1];
 
97
        float dz = v2[2] - v1[2];
 
98
        return dx*dx + dy*dy + dz*dz;
 
99
}
 
100
 
 
101
inline void vnormalize(float* v)
 
102
{
 
103
        float d = 1.0f / sqrtf(sqr(v[0]) + sqr(v[1]) + sqr(v[2]));
 
104
        v[0] *= d;
 
105
        v[1] *= d;
 
106
        v[2] *= d;
 
107
}
 
108
 
 
109
inline bool vequal(const float* p0, const float* p1)
 
110
{
 
111
        static const float thr = sqr(1.0f/16384.0f);
 
112
        const float d = vdistSqr(p0, p1);
 
113
        return d < thr;
 
114
}
 
115
 
 
116
inline int nextPow2(int v)
 
117
{
 
118
        v--;
 
119
        v |= v >> 1;
 
120
        v |= v >> 2;
 
121
        v |= v >> 4;
 
122
        v |= v >> 8;
 
123
        v |= v >> 16;
 
124
        v++;
 
125
        return v;
 
126
}
 
127
 
 
128
inline float vdot2D(const float* u, const float* v)
 
129
{
 
130
        return u[0]*v[0] + u[2]*v[2];
 
131
}
 
132
 
 
133
inline float vperp2D(const float* u, const float* v)
 
134
{
 
135
        return u[2]*v[0] - u[0]*v[2];
 
136
}
 
137
 
 
138
inline float triArea2D(const float* a, const float* b, const float* c)
 
139
{
 
140
        return ((b[0]*a[2] - a[0]*b[2]) + (c[0]*b[2] - b[0]*c[2]) + (a[0]*c[2] - c[0]*a[2])) * 0.5f;
 
141
}
 
142
 
 
143
inline bool checkOverlapBox(const unsigned short amin[3], const unsigned short amax[3],
 
144
                                                        const unsigned short bmin[3], const unsigned short bmax[3])
 
145
{
 
146
        bool overlap = true;
 
147
        overlap = (amin[0] > bmax[0] || amax[0] < bmin[0]) ? false : overlap;
 
148
        overlap = (amin[1] > bmax[1] || amax[1] < bmin[1]) ? false : overlap;
 
149
        overlap = (amin[2] > bmax[2] || amax[2] < bmin[2]) ? false : overlap;
 
150
        return overlap;
 
151
}
 
152
 
 
153
void closestPtPointTriangle(float* closest, const float* p,
 
154
                                                        const float* a, const float* b, const float* c);
 
155
 
 
156
bool closestHeightPointTriangle(const float* p, const float* a, const float* b, const float* c, float& h);
 
157
 
 
158
bool intersectSegmentPoly2D(const float* p0, const float* p1,
 
159
                                                        const float* verts, int nverts,
 
160
                                                        float& tmin, float& tmax,
 
161
                                                        int& segMin, int& segMax);
 
162
 
 
163
float distancePtSegSqr2D(const float* pt, const float* p, const float* q, float& t);
 
164
 
 
165
void calcPolyCenter(float* tc, const unsigned short* idx, int nidx, const float* verts);
 
166
 
 
167
#endif // DETOURCOMMON_H
 
 
b'\\ No newline at end of file'