bool DTreePlanter::FindDropPoint(vec3_t in, vec3_t out) { DPlane p1; DPlane p2; vec3_t vUp = { 0, 0, 1 }; vec3_t vForward = { 0, 1, 0 }; vec3_t vLeft = { 1, 0, 0 }; in[2] = 65535; VectorCopy(in, p1.points[0]); VectorCopy(in, p1.points[1]); VectorCopy(in, p1.points[2]); VectorMA(p1.points[1], 20, vUp, p1.points[1]); VectorMA(p1.points[1], 20, vLeft, p1.points[2]); VectorCopy(in, p2.points[0]); VectorCopy(in, p2.points[1]); VectorCopy(in, p2.points[2]); VectorMA(p1.points[1], 20, vUp, p2.points[1]); VectorMA(p1.points[1], 20, vForward, p2.points[2]); p1.Rebuild(); p2.Rebuild(); bool found = false; vec3_t temp; vec_t dist; int cnt = m_world.GetIDMax(); for(int i = 0; i < cnt; i++) { DBrush* pBrush = m_world.GetBrushForID( i ); if(pBrush->IntersectsWith( &p1, &p2, temp )) { vec3_t diff; vec_t tempdist; VectorSubtract(in, temp, diff); tempdist = VectorLength( diff ); if(!found || (tempdist < dist)) { dist = tempdist; VectorCopy( temp, out ); found = true; } } } return found; }