MCPcopy Create free account
hub / github.com/OGSR/OGSR-Engine / dCollideRayBox

Function dCollideRayBox

3rd_party/Src/ode/ode/src/collision_std.cpp:1813–1905  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1811
1812
1813int dCollideRayBox (dxGeom *o1, dxGeom *o2, int flags,
1814 dContactGeom *contact, int skip)
1815{
1816 dIASSERT (skip >= (int)sizeof(dContactGeom));
1817 dIASSERT (o1->type == dRayClass);
1818 dIASSERT (o2->type == dBoxClass);
1819 dxRay *ray = (dxRay*) o1;
1820 dxBox *box = (dxBox*) o2;
1821
1822 contact->g1 = ray;
1823 contact->g2 = box;
1824
1825 int i;
1826
1827 // compute the start and delta of the ray relative to the box.
1828 // we will do all subsequent computations in this box-relative coordinate
1829 // system. we have to do a translation and rotation for each point.
1830 dVector3 tmp,s,v;
1831 tmp[0] = ray->pos[0] - box->pos[0];
1832 tmp[1] = ray->pos[1] - box->pos[1];
1833 tmp[2] = ray->pos[2] - box->pos[2];
1834 dMULTIPLY1_331 (s,box->R,tmp);
1835 tmp[0] = ray->R[0*4+2];
1836 tmp[1] = ray->R[1*4+2];
1837 tmp[2] = ray->R[2*4+2];
1838 dMULTIPLY1_331 (v,box->R,tmp);
1839
1840 // mirror the line so that v has all components >= 0
1841 dVector3 sign;
1842 for (i=0; i<3; i++) {
1843 if (v[i] < 0) {
1844 s[i] = -s[i];
1845 v[i] = -v[i];
1846 sign[i] = 1;
1847 }
1848 else sign[i] = -1;
1849 }
1850
1851 // compute the half-sides of the box
1852 dReal h[3];
1853 h[0] = REAL(0.5) * box->side[0];
1854 h[1] = REAL(0.5) * box->side[1];
1855 h[2] = REAL(0.5) * box->side[2];
1856
1857 // do a few early exit tests
1858 if ((s[0] < -h[0] && v[0] <= 0) || s[0] > h[0] ||
1859 (s[1] < -h[1] && v[1] <= 0) || s[1] > h[1] ||
1860 (s[2] < -h[2] && v[2] <= 0) || s[2] > h[2] ||
1861 (v[0] == 0 && v[1] == 0 && v[2] == 0)) {
1862 return 0;
1863 }
1864
1865 // compute the t=[lo..hi] range for where s+v*t intersects the box
1866 dReal lo = -dInfinity;
1867 dReal hi = dInfinity;
1868 int nlo = 0, nhi = 0;
1869 for (i=0; i<3; i++) {
1870 if (v[i] != 0) {

Callers 1

dCollideRMBFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected