MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / CheckIntersection

Method CheckIntersection

engine/Poseidon/World/Simulation/Collisions.cpp:2044–2157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2042}
2043
2044bool Landscape::CheckIntersection(Vector3Par beg, Vector3Par end, int x, int z, float& tRet) const
2045{
2046 // beg and end must be in square (x,z)
2047 float y00, y01, y10, y11;
2048#if !USE_SWIZZLED_ARRAYS
2049 if (!this_TerrainInRange(z, x) || !this_TerrainInRange(z + 1, x + 1))
2050 {
2051 y00 = y01 = y10 = y11 = -100;
2052 }
2053 else
2054 {
2055 y00 = GetData(x, z);
2056 y01 = GetData(x + 1, z);
2057 y10 = GetData(x, z + 1);
2058 y11 = GetData(x + 1, z + 1);
2059 }
2060#else
2061 if (!this_TerrainInRange(z, x) || !this_TerrainInRange(z + 1, x + 1))
2062 return false; // no bump outside landscape
2063 RawType y4[2][2];
2064 _data.GetFour(y4, x, z);
2065 y00 = RawToHeight(y4[0][0]);
2066 y01 = RawToHeight(y4[0][1]);
2067 y10 = RawToHeight(y4[1][0]);
2068 y11 = RawToHeight(y4[1][1]);
2069#endif
2070
2071 float maxSurfY = floatMax(floatMax(y00, y01), floatMax(y10, y11));
2072 float minLineY = floatMin(beg.Y(), end.Y());
2073 if (minLineY > maxSurfY)
2074 {
2075 return false;
2076 }
2077 Vector3 normal1;
2078 Vector3 normal2;
2079 normal1.Init();
2080 normal2.Init();
2081 // triangle 00,01,10
2082 normal1[0] = (y01 - y00) * -_invTerrainGrid;
2083 normal1[1] = 1;
2084 normal1[2] = (y10 - y00) * -_invTerrainGrid;
2085 // triangle 01,10,11
2086 normal2[0] = (y11 - y10) * -_invTerrainGrid;
2087 normal2[1] = 1;
2088 normal2[2] = (y11 - y01) * -_invTerrainGrid;
2089 //
2090 Vector3 point((x + 1) * _terrainGrid, y01, z * _terrainGrid);
2091 Plane plane1(normal1, point);
2092 Plane plane2(normal2, point);
2093
2094 const float inEps = _invTerrainGrid * 0.01;
2095
2096 Vector3 direction = end - beg;
2097 float dist1 = plane1.Distance(beg);
2098 if (dist1 < 0)
2099 {
2100 float xIn = beg.X() * _invTerrainGrid - x; // relative 0..1 in square
2101 float zIn = beg.Z() * _invTerrainGrid - z;

Callers

nothing calls this directly

Calls 10

floatMaxFunction · 0.85
floatMinFunction · 0.85
fabsFunction · 0.85
GetFourMethod · 0.80
NormalMethod · 0.80
YMethod · 0.45
InitMethod · 0.45
DistanceMethod · 0.45
XMethod · 0.45
ZMethod · 0.45

Tested by

no test coverage detected