View Full Version : Running through walls

Neo the great hacker

12-12-2001, 09:37 AM

Is there a simple way to make the camera stop in front of the walls of a square room for example???

Please help me as I'm a real Newbie and despirate to finish this project to Christmas http://www.opengl.org/discussion_boards/ubb/smile.gif

chowe6685

12-12-2001, 10:49 AM

treat each wall as a plane, if they are parallel to your axes this will be easy, store them in Ax+By+Cz+D=0 form, then before updating the camera's position, plug the position into the formula, then check to see if the new position changes the sign of the result, if so you have crossed the plane and jou can just nullify portions or all of the movement. Alterately you can use a whole bunch of if statements to make sure the camera stays in bounds, this will be less easy to read, but faster to code for a square room

Neo the great hacker

12-13-2001, 04:22 AM

Thanks for your reply but as I'm quite new to OpenGL I actually don't really understand what you mean. Could you post some lines of code or something like that???

I son't really understand this Ax + By + Cz + D buissines. What is A, B, C, D and x, y, z?

chowe6685

12-13-2001, 08:26 AM

collision detection has nothing to do with opengl, opengl is merely a rendering API. however, Ax+By+Cz+D=0 is the standerd equation for a plane. A,B,C and D are constants and x,y , and z are variables. all points (x,y,z) which satisfy the equation are in the plane. So a horizontal plane located 3 units under the origen would have the equation

0x+1y+0z+3=0

which reduces to

y=-3

thus defining a plane

if Ax+By+Cz+D is zero, the point is one the plane, if poistive it is on one side, if negative the other, so store your camera pos as a point, and test to see which side of the plane it is on, then see if the point is on the other side of the plane after moving, if so, don't move, since you will have crossed the plane. With a square room it will be easy to define the six planes, then use a loop to ensure the camera doesn't intersect them.

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.