PDA

View Full Version : problem with collision detection


paulpars
05-18-2006, 04:06 PM
I am currently having a problem with collision detection in that whenever I turn it on, my view keeps getting higher along the y axis and doesn't stop. I am using files that came with vizard and basically what I've done is add a car and a road using a texquad to the 'playground.wrl' file. I have set it so the viewpoint is inside the car and I think this is what is creating the problem. As soon as I start the program the car just starts floating up away from the ground. Does anyone have any ideas on how to fix this? Thanks.

Gladsomebeast
05-18-2006, 05:05 PM
I think the viewpoint is colliding with the car. Stop that with the following:

car.disable( viz.COLLISION )

paulpars
05-19-2006, 08:24 AM
ok that's much better, thanks!
I have another problem now...if I understand correctly, there is no way to make it so that the car will collide with every other object in the world, so I would have to do it manually...is this correct? and how would I go about doing that?

Gladsomebeast
05-19-2006, 09:34 AM
A simple collision detection method would use viz.intersect() to draw a line in front of the car checking if any objects are in the way. Check out the Using real-time physics tutorial for an example of this method.

paulpars
05-19-2006, 11:40 AM
ok thanks, i've found the tutorial online, but i don't seem to have any of the tutorial files....can i download them somewhere?

Gladsomebeast
05-19-2006, 12:14 PM
Can't seem to find the files eather. Basicly what you are interesed in is the following code. The future and current position points are computed. Then the line between these points is supplied to the viz.intersect command. This command will return a struture with an intersected attribute. If intersected is true, then there is an object intersecting the line. Because you have called car.disable( viz.COLLISION ), this line will never intersect with car.



def ontimer(num):
global vector, whirling, active
if num == ANIMATION:
#Get the amount of time elapsed since this timer started running.
elapsed = viz.elapsed()
#If the dart is active, move it.
if active:
#Get the dart's current position.
current = dart.get(viz.POSITION)
#Get the vector for the direction in which the dart is positioned.
vector = dart.get(viz.LOOK)
#Find the dart's future position if it travels along the vector .1 meter.
future = vizmat.MoveAlongVector(current, vector,.1)
#Draw a line between the current and future positions and
#see if it intersects anything.
hit = viz.intersect(current, future)

#If the dart has hit anything, stop it.
if hit.intersected:
active = 0


#Move the dart to the future position.
dart.translate(future)


viz.callback(viz.TIMER_EVENT,ontimer)
viz.starttimer(ANIMATION,.01,viz.PERPETUAL)



Call the following code to visualize the line for your develpment:

viz.startlayer(viz.LINE_LOOP)
viz.vertex(p1)
viz.vertex(p2)
line = viz.endlayer()


p1 and p2 are the current and future points of the car. You are going to have to offset these points the lenght of the car, in the z direction, in the car's viz.LOCAL_RELETIVE coordinates.

mspusch
06-09-2006, 06:03 PM
Location of physics demo files:
With the standard Vizard 2.5xx installation, the physics files can be found at
program files / vizard25/examples/physics.
The one that shows the intersect is physics2.py.

Driving simulation tutorial:
You might have already seen this, but a tutorial that shows how to put together a basic driving demo can be found at:
http://www.worldviz.com/vizhelp/VizHelp.htm#Tutorial__Viewpoint_control.htm