0

实时碰撞检测书有以下等式。

// Compute the t value for the directed line ab intersecting the plane
Vector ab = b - a;
t = (p.d - Dot(p.n, a)) / Dot(p.n, ab);

所以我目前有

GLKVector3 abD = GLKVector3Subtract(b, a);

GLKVector3 planeD = GLKVector3Make(1.0f, 0.0f, 1.0f);
GLKVector3 planeN = GLKVector3Make(0.0f, 1.0f, 0.0f);

//t = (p.d - Dot(p.n, a)) / Dot(p.n, ab);

float dotPbA = GLKVector3DotProduct(planeN, a);
float dotPbAbD = GLKVector3DotProduct(planeN, abD);

GLKVector3 nominator = GLKVector3SubtractScalar(planeD, dotPbA);

GLKVector3 t = GLKVector3DivideScalar(nom, dotPbAbD);
// float t = nominator / dotPbA

我需要 t 作为浮点数。我该怎么办?我知道在 glm 或类似的东西中它只会使用运算符。

GLKVector3 的长度会给我我需要的吗?

4

1 回答 1

1

我假设这p.d是平面到原点的距离,因此不是矢量,而是标量,即 a float

然后你可以计算

float planeD = ...
GLKVector3 planeN = ...

GLKVector3 abD = GLKVector3Subtract(b, a);
float dotPbA = GLKVector3DotProduct(planeN, a);
float dotPbAbD = GLKVector3DotProduct(planeN, abD);

float t = (planeD - dotPbA)/dotPbAbD;
于 2013-05-16T13:14:12.790 回答