3 inline float Clamp(
float val,
float min,
float max)
12 inline float Lerp(
float val1,
float val2,
float lerp)
14 return val2 * lerp + val1 * (1.0f - lerp);
24 latlng.x = -D3DXToDegree(atanf(position.z / sqrtf(position.x*position.x + position.y*position.y)));
25 if (position.x <= 0 && position.y > 0)
26 latlng.y = -D3DXToDegree(atanf(position.x / position.y));
27 else if (position.x < 0 && position.y <= 0)
28 latlng.y = D3DXToDegree(atanf(position.y / position.x)) + 90.0f;
29 else if (position.x >= 0 && position.y < 0)
30 latlng.y = -D3DXToDegree(atanf(position.x / position.y)) - 180.0f;
31 else if (position.x > 0 && position.y >= 0)
32 latlng.y = D3DXToDegree(atanf(position.y / position.x)) - 90.0f;
37 inline float GetArcDist(D3DXVECTOR3 from, D3DXVECTOR3 to,
bool includeAltDiff)
39 D3DXVECTOR3 result = to - from;
40 const float olddist = D3DXVec3Length(&result);
41 const float lerp = max(0.0f, min(1.0f, (olddist - 320.0f) / 160.0f));
46 const float dLat = D3DXToRadian(latlng34.x - latlng56.x);
47 const float dLon = D3DXToRadian(latlng34.y - latlng56.y);
50 const float a = sinf(dLat * 0.5f) * sinf(dLat * 0.5f) + cosf(D3DXToRadian(latlng56.x)) * cosf(D3DXToRadian(latlng34.x)) *
51 sinf(dLon * 0.5f) * sinf(dLon * 0.5f);
52 const float c = 2.0f * atan2f(sqrtf(a), sqrtf(1.0f - a));
57 const float alt = D3DXVec3Length(&from) - D3DXVec3Length(&to);
58 newdist = sqrtf(newdist*newdist + alt * alt);
61 return newdist * lerp + olddist * (1.0f - lerp);
64 inline D3DXVECTOR3
GetArcBear(D3DXVECTOR3 vec2,
float dist,
float altd, D3DXVECTOR3 posnorml)
68 D3DXVECTOR3 cross, location = -posnorml, tempvelocity, relativel;
69 D3DXVec3Normalize(&tempvelocity, &vec2);
70 D3DXVec3Cross(&cross, &location, &tempvelocity);
72 const float angle = D3DXVec3Dot(&location, &tempvelocity);
75 f_temp = -D3DX_HALFPI;
76 else if (angle <= -1.0f)
80 f_temp = -acosf(angle) - D3DX_HALFPI;
81 f_temp += atanf(altd / dist);
85 D3DXMatrixRotationAxis(&dor, &cross, f_temp);
86 D3DXVec3TransformCoord(&relativel, &tempvelocity, &dor);
88 const float lerp = max(0.0f, min(1.0f, (dist - 320.0f) / 160.0f));
89 return -relativel * lerp + vec2 * (1.0f - lerp);
94 return rect1.left == rect2.left && rect1.right == rect2.right && rect1.top == rect2.top && rect1.bottom == rect2.bottom;
100 return static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
float GetArcDist(D3DXVECTOR3 from, D3DXVECTOR3 to, bool includeAltDiff)
bool RectEquality(RECT rect1, RECT rect2)
D3DXVECTOR2 CalculateLatLng(D3DXVECTOR3 position)
D3DXVECTOR3 GetArcBear(D3DXVECTOR3 vec2, float dist, float altd, D3DXVECTOR3 posnorml)
float Clamp(float val, float min, float max)
float Lerp(float val1, float val2, float lerp)