MCPcopy Create free account
hub / github.com/carbonengine/trinity / RayTriangleIntersection

Function RayTriangleIntersection

trinity/Resources/TriGrannyRes.cpp:1825–1865  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1823
1824
1825bool RayTriangleIntersection( float& dist, float& u, float& v, const Vector3& pos, const Vector3& dir, const Vector3& p0, const Vector3& p1, const Vector3& p2 )
1826{
1827 Matrix m;
1828 Vector4 vec;
1829
1830 m.m[0][0] = p1.x - p0.x;
1831 m.m[1][0] = p2.x - p0.x;
1832 m.m[2][0] = -dir.x;
1833 m.m[3][0] = 0.0f;
1834 m.m[0][1] = p1.y - p0.y;
1835 m.m[1][1] = p2.y - p0.y;
1836 m.m[2][1] = -dir.y;
1837 m.m[3][1] = 0.0f;
1838 m.m[0][2] = p1.z - p0.z;
1839 m.m[1][2] = p2.z - p0.z;
1840 m.m[2][2] = -dir.z;
1841 m.m[3][2] = 0.0f;
1842 m.m[0][3] = 0.0f;
1843 m.m[1][3] = 0.0f;
1844 m.m[2][3] = 0.0f;
1845 m.m[3][3] = 1.0f;
1846
1847 vec.x = pos.x - p0.x;
1848 vec.y = pos.y - p0.y;
1849 vec.z = pos.z - p0.z;
1850 vec.w = 0.0f;
1851
1852 if( Inverse( m, m ) )
1853 {
1854 vec = Transform( vec, m );
1855 if( ( vec.x >= 0.0f ) && ( vec.y >= 0.0f ) && ( vec.x + vec.y <= 1.0f ) && ( vec.z >= 0.0f ) )
1856 {
1857 u = vec.x;
1858 v = vec.y;
1859 dist = fabs( vec.z );
1860 return true;
1861 }
1862 }
1863
1864 return false;
1865}
1866
1867#if WITH_GRANNY
1868namespace

Callers 2

GrannyRayIntersectionFunction · 0.85
RayIntersectionMethod · 0.85

Calls 1

ExtractVector3Function · 0.85

Tested by

no test coverage detected