MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / collideRay

Method collideRay

Engine/source/environment/river.cpp:1874–1927  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1872}
1873
1874bool River::collideRay( const Point3F &origin, const Point3F &direction, U32 *nodeIdx, Point3F *collisionPnt ) const
1875{
1876 Point3F p0 = origin;
1877 Point3F p1 = origin + direction * 2000.0f;
1878
1879 // If the line segment does not collide with the river's world box,
1880 // it definitely does not collide with any part of the river.
1881 if ( !getWorldBox().collideLine( p0, p1 ) )
1882 return false;
1883
1884 if ( mSlices.size() < 2 )
1885 return false;
1886
1887 MathUtils::Quad quad;
1888 MathUtils::Ray ray;
1889 F32 t;
1890
1891 // Check each river segment (formed by a pair of slices) for collision
1892 // with the line segment.
1893 for ( U32 i = 0; i < mSlices.size() - 1; i++ )
1894 {
1895 const RiverSlice &slice0 = mSlices[i];
1896 const RiverSlice &slice1 = mSlices[i+1];
1897
1898 // For simplicities sake we will only test for collision between the
1899 // line segment and the Top face of the river segment.
1900
1901 // Clockwise starting with the leftmost/closest point.
1902 quad.p00 = slice0.p0;
1903 quad.p01 = slice1.p0;
1904 quad.p11 = slice1.p2;
1905 quad.p10 = slice0.p2;
1906
1907 ray.origin = origin;
1908 ray.direction = direction;
1909
1910 // NOTE:
1911 // mRayQuadCollide is designed for a "real" quad in which all four points
1912 // are coplanar which is actually not the case here. The more twist
1913 // and turn in-between two neighboring river slices the more incorrect
1914 // this calculation will be.
1915
1916 if ( MathUtils::mRayQuadCollide( quad, ray, NULL, &t ) )
1917 {
1918 if ( nodeIdx )
1919 *nodeIdx = slice0.parentNodeIdx;
1920 if ( collisionPnt )
1921 *collisionPnt = ray.origin + ray.direction * t;
1922 return true;
1923 }
1924 }
1925
1926 return false;
1927}
1928
1929Point3F River::getNodePosition( U32 idx ) const
1930{

Callers 3

_process3DMouseDownMethod · 0.45
on3DMouseMoveMethod · 0.45
on3DMouseDownMethod · 0.45

Calls 3

mRayQuadCollideFunction · 0.85
collideLineMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected