Archived

This topic is now archived and is closed to further replies.

tobymurray

moving camera parallel to walls

Recommended Posts

I've written a damn simple collision detection function to work with quads. At the moment if the user tries to move the camera in a direction which will result in the camera being "too close" to a polygon in the level, then the move is disallowed. However what I want to do is to allow the user to move in this case, parallel to the offending polygon. The amount that they move parallel to the polygon will be scaled by the angle between the way they want to go and the vector parallel to the polygon. OK so assuming that I can find the vector parallel to the polygon I would use
newVectorForward = dot(OriginalVectorForward,ParallelVector)*ParallelVector
  
To find this vector, will it work to use the cross product of the Y-axis vector and the normal of the plane of the polygon? If anyone has done this, some advice would be really appreciated. Thanks Toby Gobsmacked - by Toby Murray [edited by - tobymurray on April 29, 2002 10:55:21 PM]

Share this post


Link to post
Share on other sites
What you want to do is this:

newVector = scaleFactor * ( moveVector - quadnormal*( dot(quadnormal, moveVector) ) )

From the basics:
dot(quadnormal, movevector) = "length" of projection of moveVector onto quadnormal (assuming unit-length qn)

We subtract out the perpendicular part of mV, which is the part we just projected onto qn, to get newVector in the plane of the quad, and multiply by a scale factor dependent on how we want to relate the initial and final vectors. In the simplest case,
scaleFactor is equal to length of moveVector divided by length of newVector.

HTH,
ld

Share this post


Link to post
Share on other sites