开发者

Need help with Direct 3D's LookAt function

I need some conceptual help with Direct3D's .... function. In their official documentation, they say that the computation that takes place can be summarized with this:

zaxis = normal(At - Eye) xaxis = normal(cross(Up, zaxis)) yaxis = cross(zaxis, xaxis)

xaxis.x yaxis.x zaxis.x 0 xaxis.y yaxis.y zaxis.y 0 xaxis.z yaxis.z zaxis.z 0 -dot(xaxis, eye) -dot(yaxis, eye) -dot(zaxis, eye) l

Now what I don't get is what's being done with the 'normal()' function being used in the first two lines ? How can I normal be computed with two vectors ?! Isn't a normal calculated for a plane ?!

In the second line, normal() is working on just one vector (since cross(Up, zaxis) w开发者_JS百科ould return one 3D vector) ..

So basically I need to know what's meant by using normal() in the first two equations ..

I need this to practice doing this computation manually on my own ..


normal() function normalises a vector.

A vector has a manitude, of length. This is defined as:

length = sqrtf( (x * x) + (y * y) + (z * z) );

So if you have a vector defined as (10, 0, 0) which will give you a length of

length = sqrtf( (10 * 10) + (0 * 0) + (0 * 0) );

which is nice easy calculation returning a length/magnitude of 10.

Now a normal vector has a magnitude of 1. So you can easily see above that by dividing each element of the vector by the magnitude you will end up with a length/magnitude of 1.

So the normal function simply does:

const float length = sqrtf( (vx*vx) + (vy*vy) + (vz*vz) );
vx                 = vx / length;
vy                 = vy / length;
vz                 = vz / length;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜