- 147 名前:名前は開発中のものです。 [2006/06/20(火) 21:54:00 ID:q3QYoQKK]
- >>146
int CheckTriangleCross( VECTOR begin, VECTOR end, VECTOR* pos, VECTOR *v) { // 平面の方程式より n(法線ベクトル)、d を求める VECTOR n, p1, p2; VectorSub( &p1, &v[1], &v[0]); VectorSub( &p2, &v[2], &v[0]); CrossVector( &n, &p1, &p2); float d = -1 * (n.x * v[0].x + n.y * v[0].y + n.z * v[0].z); // 直線の方程式より a、p を求める // p = a*t + b VECTOR a; VectorSub( &a, &end, &begin); // tを求めることで、交点を求める float top = -(begin.x*n.x + begin.y*n.y + begin.z*n.z + d); float bottom = DotVector( &n, &a); // 平行判定 if ( bottom == 0.0f) return false; // tは直線のパラメータ float t = top / bottom;
|

|