Skip to content

Commit 46df6ba

Browse files
tamlin-mikeXottab-DUTY
authored andcommitted
More compile-time distanglement.
1 parent 28f695d commit 46df6ba

File tree

98 files changed

+832
-662
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+832
-662
lines changed

src/editors/ECore/Editor/EditMesh.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define EditMeshH
77
#include "xrCore/_types.h"
88
#include "xrCore/_fbox.h"
9+
#include "xrCommon/math_funcs_inline.h"
910

1011
//----------------------------------------------------
1112
// fwd. decl.

src/editors/ECore/Editor/EditObject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "xrCore/Animation/Bone.hpp"
66
#include "xrCore/Animation/Motion.hpp"
77
#include "xrCore/_fbox.h"
8+
#include "xrCore/_std_extensions.h"
89

910
#ifdef _EDITOR
1011
#include "xrServerEntities/PropertiesListTypes.h"

src/plugins/lw/Shader/stdafx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#pragma once
99

1010
#include "xrCore/xrCore.h"
11+
#include "xrCore/_std_extensions.h"
1112
#pragma comment(lib, "xrCore.lib")
1213

1314
#define ENGINE_API

src/utils/ETools/ETools.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "stdafx.h"
22
#include "ETools.h"
33
#include "xrXRC.h"
4+
#include "xrCommon/math_funcs_inline.h"
45

56
#pragma warning(disable : 4267)
67

src/utils/ETools/StdAfx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "Common/Common.hpp"
66
#include "xrCore/xrCore.h"
7+
#include "xrCore/_std_extensions.h"
78

89
#pragma warning(push)
910
#pragma warning(disable : 4995)

src/utils/xrLCUtil/pch.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#pragma once
22
#include "Common/Common.hpp"
33
#include "xrLCUtil.hpp"
4+
#include "xrCore/_std_extensions.h"

src/utils/xrLC_Light/stdafx.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
#define NUM_THREADS 8
1414

15+
#include "xrCore/cdecl_cast.hpp"
16+
#include "xrCore/_std_extensions.h"
17+
1518
extern ILevelCompilerLogger& Logger;
1619
extern CThread::LogFunc ProxyMsg;
1720
extern CThreadManager::ReportStatusFunc ProxyStatus;

src/utils/xrMiscMath/cylinder.cpp

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
#include "pch.hpp"
2+
#include <limits>
3+
#include "xrCore/_cylinder.h"
4+
#include "xrCommon/math_funcs_inline.h"
5+
#ifdef DEBUG
6+
#include "xrCore/xrDebug_macros.h"
7+
#include "xrCore/log.h"
8+
#endif
9+
10+
template <class T>
11+
int _cylinder<T>::intersect(const VEC_TYPE& start, const VEC_TYPE& dir, T afT[2], ecode code[2]) const
12+
{
13+
T fEpsilon = 1e-12f;
14+
15+
// set up quadratic Q(t) = a*t^2 + 2*b*t + c
16+
VEC_TYPE kU, kV, kW = m_direction;
17+
VEC_TYPE::generate_orthonormal_basis(kW, kU, kV);
18+
VEC_TYPE kD;
19+
kD.set(kU.dotproduct(dir), kV.dotproduct(dir), kW.dotproduct(dir));
20+
#ifdef DEBUG
21+
if (kD.square_magnitude() <= std::numeric_limits<T>::min())
22+
{
23+
Msg("dir :%f,%f,%f", dir.x, dir.y, dir.z);
24+
Msg("kU :%f,%f,%f", kU.x, kU.y, kU.z);
25+
Msg("kV :%f,%f,%f", kV.x, kV.y, kV.z);
26+
Msg("kW :%f,%f,%f", kW.x, kW.y, kW.z);
27+
VERIFY2(0, "KD is zero");
28+
}
29+
#endif
30+
T fDLength = kD.normalize_magn();
31+
T fInvDLength = 1.0f / fDLength;
32+
VEC_TYPE kDiff;
33+
kDiff.sub(start, m_center);
34+
VEC_TYPE kP;
35+
kP.set(kU.dotproduct(kDiff), kV.dotproduct(kDiff), kW.dotproduct(kDiff));
36+
T fHalfHeight = 0.5f * m_height;
37+
T fRadiusSqr = m_radius * m_radius;
38+
39+
T fInv, fA, fB, fC, fDiscr, fRoot, fT, fT0, fT1, fTmp0, fTmp1;
40+
41+
if (_abs(kD.z) >= 1.0f - fEpsilon)
42+
{
43+
// line is parallel to cylinder axis
44+
if (kP.x * kP.x + kP.y * kP.y <= fRadiusSqr)
45+
{
46+
fTmp0 = fInvDLength / kD.z;
47+
afT[0] = (+fHalfHeight - kP.z) * fTmp0;
48+
afT[1] = (-fHalfHeight - kP.z) * fTmp0;
49+
code[0] = cyl_cap;
50+
code[1] = cyl_cap;
51+
return 2;
52+
}
53+
else
54+
{
55+
return 0;
56+
}
57+
}
58+
59+
if (_abs(kD.z) <= fEpsilon)
60+
{
61+
// line is perpendicular to axis of cylinder
62+
if (_abs(kP.z) > fHalfHeight)
63+
{
64+
// line is outside the planar caps of cylinder
65+
return 0;
66+
}
67+
68+
fA = kD.x * kD.x + kD.y * kD.y;
69+
fB = kP.x * kD.x + kP.y * kD.y;
70+
fC = kP.x * kP.x + kP.y * kP.y - fRadiusSqr;
71+
fDiscr = fB * fB - fA * fC;
72+
if (fDiscr < 0.0f)
73+
{
74+
// line does not intersect cylinder wall
75+
return 0;
76+
}
77+
else if (fDiscr > 0.0f)
78+
{
79+
fRoot = _sqrt(fDiscr);
80+
fTmp0 = fInvDLength / fA;
81+
afT[0] = (-fB - fRoot) * fTmp0;
82+
afT[1] = (-fB + fRoot) * fTmp0;
83+
code[0] = cyl_wall;
84+
code[1] = cyl_wall;
85+
return 2; // wall
86+
}
87+
else
88+
{
89+
afT[0] = -fB * fInvDLength / fA;
90+
code[0] = cyl_wall;
91+
return 1; // wall
92+
}
93+
}
94+
95+
// test plane intersections first
96+
int iQuantity = 0;
97+
fInv = 1.0f / kD.z;
98+
fT0 = (+fHalfHeight - kP.z) * fInv;
99+
fTmp0 = kP.x + fT0 * kD.x;
100+
fTmp1 = kP.y + fT0 * kD.y;
101+
if (fTmp0 * fTmp0 + fTmp1 * fTmp1 <= fRadiusSqr)
102+
{
103+
code[iQuantity] = cyl_cap;
104+
afT[iQuantity++] = fT0 * fInvDLength;
105+
}
106+
107+
fT1 = (-fHalfHeight - kP.z) * fInv;
108+
fTmp0 = kP.x + fT1 * kD.x;
109+
fTmp1 = kP.y + fT1 * kD.y;
110+
if (fTmp0 * fTmp0 + fTmp1 * fTmp1 <= fRadiusSqr)
111+
{
112+
code[iQuantity] = cyl_cap;
113+
afT[iQuantity++] = fT1 * fInvDLength;
114+
}
115+
116+
if (iQuantity == 2)
117+
{
118+
// line intersects both top and bottom
119+
return 2; // both caps
120+
}
121+
122+
// If iQuantity == 1, then line must intersect cylinder wall
123+
// somewhere between caps in a single point. This case is detected
124+
// in the following code that tests for intersection between line and
125+
// cylinder wall.
126+
127+
fA = kD.x * kD.x + kD.y * kD.y;
128+
fB = kP.x * kD.x + kP.y * kD.y;
129+
fC = kP.x * kP.x + kP.y * kP.y - fRadiusSqr;
130+
fDiscr = fB * fB - fA * fC;
131+
if (fDiscr < 0.0f)
132+
{
133+
// line does not intersect cylinder wall
134+
// VERIFY( iQuantity == 0 );
135+
return 0;
136+
}
137+
else if (fDiscr > 0.0f)
138+
{
139+
fRoot = _sqrt(fDiscr);
140+
fInv = 1.0f / fA;
141+
fT = (-fB - fRoot) * fInv;
142+
if (fT0 <= fT1)
143+
{
144+
if (fT0 <= fT && fT <= fT1)
145+
{
146+
code[iQuantity] = cyl_wall;
147+
afT[iQuantity++] = fT * fInvDLength;
148+
}
149+
}
150+
else
151+
{
152+
if (fT1 <= fT && fT <= fT0)
153+
{
154+
code[iQuantity] = cyl_wall;
155+
afT[iQuantity++] = fT * fInvDLength;
156+
}
157+
}
158+
159+
if (iQuantity == 2)
160+
{
161+
// Line intersects one of top/bottom of cylinder and once on
162+
// cylinder wall.
163+
return 2;
164+
}
165+
166+
fT = (-fB + fRoot) * fInv;
167+
if (fT0 <= fT1)
168+
{
169+
if (fT0 <= fT && fT <= fT1)
170+
{
171+
code[iQuantity] = cyl_wall;
172+
afT[iQuantity++] = fT * fInvDLength;
173+
}
174+
}
175+
else
176+
{
177+
if (fT1 <= fT && fT <= fT0)
178+
{
179+
code[iQuantity] = cyl_wall;
180+
afT[iQuantity++] = fT * fInvDLength;
181+
}
182+
}
183+
}
184+
else
185+
{
186+
fT = -fB / fA;
187+
if (fT0 <= fT1)
188+
{
189+
if (fT0 <= fT && fT <= fT1)
190+
{
191+
code[iQuantity] = cyl_wall;
192+
afT[iQuantity++] = fT * fInvDLength;
193+
}
194+
}
195+
else
196+
{
197+
if (fT1 <= fT && fT <= fT0)
198+
{
199+
code[iQuantity] = cyl_wall;
200+
afT[iQuantity++] = fT * fInvDLength;
201+
}
202+
}
203+
}
204+
205+
return iQuantity;
206+
}
207+
208+
template <class T>
209+
typename _cylinder<T>::ERP_Result _cylinder<T>::intersect(const VEC_TYPE& start, const VEC_TYPE& dir, T& dist) const
210+
{
211+
T afT[2];
212+
ecode code[2];
213+
int cnt;
214+
if (0 != (cnt = intersect(start, dir, afT, code)))
215+
{
216+
bool o_inside = false;
217+
bool b_result = false;
218+
for (int k = 0; k < cnt; k++)
219+
{
220+
if (afT[k] < 0.f)
221+
{
222+
if (cnt == 2)
223+
o_inside = true;
224+
continue;
225+
}
226+
if (afT[k] < dist)
227+
{
228+
dist = afT[k];
229+
b_result = true;
230+
}
231+
}
232+
return b_result ? (o_inside ? rpOriginInside : rpOriginOutside) : rpNone;
233+
}
234+
else
235+
{
236+
return rpNone;
237+
}
238+
}
239+
240+
// instantiate on float and double
241+
template int Fcylinder::intersect(const VEC_TYPE& start, const VEC_TYPE& dir, float afT[2], ecode code[2]) const;
242+
template int Dcylinder::intersect(const VEC_TYPE& start, const VEC_TYPE& dir, double afT[2], ecode code[2]) const;
243+
244+
template Fcylinder::ERP_Result Fcylinder::intersect(const VEC_TYPE& start, const VEC_TYPE& dir, TYPE& dist) const;
245+
template Dcylinder::ERP_Result Dcylinder::intersect(const VEC_TYPE& start, const VEC_TYPE& dir, TYPE& dist) const;

src/utils/xrMiscMath/matrix.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "xrCore/_quaternion.h"
77
#include "xrCore/xrDebug_macros.h"
88
#include "xrCore/xrDebug.h"
9+
#include "xrCommon/math_funcs_inline.h"
910

1011

1112
template <typename T>

src/utils/xrMiscMath/quaternion.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "pch.hpp"
22
#include "xrCore/_quaternion.h"
33
#include "xrCore/_matrix.h"
4+
#include "xrCommon/math_funcs_inline.h"
45

56
//
67
// _quaternion<T> member functions

0 commit comments

Comments
 (0)