Advertisement

Tunnels

Started by November 29, 2002 03:43 PM
1 comment, last by Spartacus 22 years, 2 months ago
Can someone help me compute the points needed to draw a tunnel?? I figured out that a tunnel is actually just a long cylinder, and that cylinder can be composed of n circles. So if I have a tunnel stretching from point 0,0,z1 to point 0,0,z2 all I do is compute the points of the circle lying around point 0,0,z1 and point 0,0,z2 (points are computed in the XY plane) and connect the points to create tons of triangles. But if the points lies at x1,y1,z1 and x2,y2,z2 I have to take the direction of vector [x2-x1, y2-y1, z2-z1] into account when computing the points (because the tunnel should be centered around that vector) and I can''t figure out how to do that. In short, what I want is to compute the points of a circle and the orientation of that circle should be based on a direction vector so that the direction vector is perpendicular to the circle. If someone can point me to a good tutorial on the subject that''d be cool! Thanks in advance!

Real programmers don''t document, if it was hard to write it should be hard to understand

Real programmers don't document, if it was hard to write it should be hard to understand

Hint: A vector pointing up and the cross product of the up-vector and your direction vector will be two perpendicular axises in your cylinder-plane.
Advertisement
Actually that hint is not right -- I was too much in a hurry when I wrote it ;-)

Let your direction vector be v_direction and a vector point up be v_up, then:

v_X = VectorCross(v_direction, v_up)
v_Y = VectorCross(v_up, v_X)
VectorNormalize(v_X)
VectorNormalize(v_Y)

Now v_X and v_Y are your perpendicular vectors in the cylinder plane.

This problem is the same as finding a camera matrix from a look-at point and a focus point for the cam (this is what gluLookAt() or D3DXMatrixLookAtLH()/D3DXMatrixLookAtRH() does).

This topic is closed to new replies.

Advertisement