WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Collision of an avatar with a quad (https://forum.worldviz.com/showthread.php?t=1492)

Frank Verberne 05-13-2008 05:06 AM

Collision of an avatar with a quad
 
Hi all,

I'm having some problems with a task I'm making. I want to do something when an avatar touches a texquad. Therefore I created the texquad, added a collidebox around it and tested the situation. If I let the avatar touch the texquad in the beginning, something happens, but if I move the texquad 50 cm in front of the avatar and I let the avatar touch the texquad later, nothing happens. My code:
Code:

import viz
#import vizmocap
import random

#viz.go( viz.HMD | viz.FULLSCREEN | viz.STEREO )
viz.go()

viz.phys.enable()

environment = viz.add('gallery.ive')

quad = viz.addTexQuad()
#quad.setPosition(0,1.5,.5) #doesn't work
quad.setPosition(0,1.5,.1) #does work (once)
quad.scale(.25, .25, .25)
quad.collideBox()
quad.color(255,255,255)
quad.enable(viz.COLLIDE_NOTIFY)#object 1 for collision
quad.disable( viz.DYNAMICS )

avatar = viz.add('vcc_female.cfg')
avatar.collideMesh() #object 2 for collision
avatar.disable( viz.DYNAMICS )
#vizmocap.LiveCharacter('192.168.2.103',8050,model=avatar)
viz.MainView.translate(0,1.80,-2)

def onCollide(e):#e.obj1 == quad & e.obj2 == avatar
        if e.obj1.getColor() == [255,255,255]:
                print "white"
                e.obj1.color(viz.GREEN)
        else:
                print "green"

viz.callback( viz.COLLIDE_BEGIN_EVENT, onCollide )

I use the LiveCharacter plugin to move the avatar, but that shouldn't be the problem (I think). What I want is that the callbackfunction is activated every time the avatar collides with the collidebox around the texquad. I.e. green should be printed the second time the texquad is touched. Can somebody help me?

farshizzo 05-14-2008 10:08 AM

When you call collideMesh on an avatar, it saves the current mesh state of the avatar and performs all subsequent collision tests with this mesh. Animating an avatar will not update the collide mesh.

For some of our demos we added dynamic collisions with live avatars by constructing collision shapes for each major limb of the avatar and updating them every frame. We plan on including this code with the vizmocap module in a future release. I will try to post some of that code here when I get a chance.

Frank Verberne 05-14-2008 10:38 AM

Please post this code as soon as you can. In the meantime, I could just move the quad (using a sensor) to the original position of the avatar I guess. I would gladly receive the code if you have the time however;)!

Frank Verberne 05-26-2008 10:34 AM

Hi Farshizzo,

Could you post the code for dynamic collision with live characters? The rest of the task is done now, and I have been struggling with the code to create something like you said (collision shapes for each major limb) but haven't been succesfull. I also tried to put avatar.collidemesh() into a timer, but that was too demanding (regarding the CPU I guess).

Thanks in advance;)!

farshizzo 05-29-2008 09:55 AM

Do you need dynamics on the collision, or do you just need to know when the avatar touches an object?

Frank Verberne 05-29-2008 10:20 AM

I don't really know what the difference is, but what my task is that a participant controlling an avatar has to touch several quads. Each quad has a bounding box around it, and every time the avatar touches the quad (i.e. enters the bounding box) the program checks if the number is the lowest of the 6 quads. If it is, the quad will turn green, otherwise the quad wil become red for a few seconds and then restore itself. This task is done multiple times.

So I think that I only need to know when the avatar (no matter which part of the avatar) touches the quads. Hope that clarifies the situation.

farshizzo 05-30-2008 10:45 AM

Here is a sample script that shows how to setup collisions with the right hand of the avatar. Adding support for other body parts should not be too difficult.
Code:

import viz
viz.go()

#Enable physics
viz.phys.enable()

#Create ground plane
ground = viz.add('tut_ground.wrl')
ground.collidePlane()

#Create static box in front of avatar
box = viz.add('box.wrl',scale=[2,2,2],pos=(0,1,1.7))
box.collideBox()
box.disable(viz.DYNAMICS)

#Create avatar that doesn't like big boxes
avatar = viz.add('vcc_female.cfg')
avatar.state(6)

#Create a collision box and link it to right hand of avatar
rHandBox = viz.add('box.wrl',scale=[0.1,0.1,0.1])
rHandBox.collideBox()
rHandBox.disable(viz.DYNAMICS)
rHandBox.enable(viz.COLLIDE_NOTIFY)
rHandLink = viz.link( avatar.getBone('Bip01 R Hand') , rHandBox )
rHandLink.preTrans([0.05,-0.05,0])

#Comment this line out if you want to see the collision box around the hand
rHandBox.disable(viz.RENDERING)

#List of colors to cycle through
colors = viz.cycle([viz.WHITE,viz.BLUE,viz.RED])

#Change color of box when avatar hits it
def onCollideBegin(e):
        if e.obj1 == rHandBox:
                if e.obj2 == box:
                        box.color(colors.next())
viz.callback(viz.COLLIDE_BEGIN_EVENT,onCollideBegin)

#Setup camera navigation
import vizcam
vizcam.PivotNavigate(center=[0,1,0],distance=5)


Frank Verberne 05-30-2008 01:14 PM

Farshizzo: thank you very much for the sample code! It works perfectly. I tried to do the same while using the live characters plugin and for some reason it didn't work then. I guess linking the box directly to the same tracker that also animated the avatar (so the same tracker was linked to a bone using MotionBuilder and to a box) could have been the problem. I will test this solution on monday and I will let you know if I still encounter some problems or if my problems are solved (during the weekends I don't have access to the live characters plugin).

Frank Verberne 06-04-2008 09:44 AM

Hi Farshizzo,

Your solution also worked in the lab! So thanks for your solution!

Yours, Frank


All times are GMT -7. The time now is 06:15 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC