PDA

View Full Version : Vizard Collision (ON) issue


kovitch
08-08-2011, 08:33 AM
Hi,

I'm trying to enable the collision in my world. However, when I use the line viz.collision(viz.ON) something strange happens and I'm not sure what it is.

Could someone give me a tip about what is happening?

My guess is that there's something wrong with the view, but I don't know what to do.

Here is the code:


import viz
import viztask
import vizmat
import AvatarCamera

viz.go()

viz.MainView.getHeadLight().disable()
#add sun-like directional light
l = viz.addLight()
l.position(0, 1, -.2, 0) #sets light direction

#root encapsulates all world geometry
#root = viz.addGroup()

#viz.setOption('viz.model.apply_collada_scale',1)
#viz.add('Bairro_c_passeio_4.dae', pos=[-1, 0, -1])

ground = viz.add('tut_ground.wrl')

avatarRoot = viz.addGroup()
avatarRoot = viz.add('marker.wrl')
cameraLookAtNode = viz.addGroup(parent=avatarRoot, pos=[0, 1.5, 0])
avatar = viz.add('vcc_male.cfg', parent=avatarRoot)

#Turn on collision
viz.collision(viz.ON)

#setup physics system so viewpoint does not move through walls
viz.phys.enable()
avatar.collideMesh(bounce=0, hardness=1, friction=0)

def moveAvatar():
avatar_speed = 1
running = False
jump = False
while True:
#get user input
newPos = vizmat.Vector()
newPos.set([0,0,0])
if viz.iskeydown(viz.KEY_SHIFT_L):
avatar_speed = 10
running = True
else:
avatar_speed = 4
running = False

if viz.iskeydown('w'):
#walk forward
newPos = newPos + [0, 0, avatar_speed]
if viz.iskeydown('s'):
newPos = newPos + [0, 0, -avatar_speed]
if viz.iskeydown('a'):
newPos = newPos + [-avatar_speed, 0, 0]
if viz.iskeydown('d'):
newPos = newPos + [avatar_speed, 0, 0]
isJumping = False
isAttacking = False
if viz.iskeydown(' '):
#jump
isJumping = True
elif viz.iskeydown('v'):
isAttacking = True

if isAttacking:
avatar.state(6)
yield viztask.waitTime( 1.5 )
if newPos.length() > 0 or isJumping:
if newPos.length() == 0:
#jumping but no direction key, use current heading
t = vizmat.Transform()
t.setTrans([0, 0, 1.8])
t.postEuler(avatar.getEuler()[0],0,0)
newPos = vizmat.Vector( t.getTrans() )
newYaw = vizmat.AngleToPoint(0, 0, newPos[0], newPos[2])
avatar.setEuler(newYaw, 0, 0)
if not isJumping:
#just walking
cameraEuler = viz.MainView.getEuler()
avatarRoot.setEuler(cameraEuler[0], 0, 0)
newPos = newPos * viz.getFrameElapsed()
avatarRoot.setPosition(newPos, viz.REL_LOCAL)
if running == False:
avatar.state(2)
else:
avatar.state(11)
else:
#jumping
avatar.state(7)
yield viztask.waitTime( avatar.getDuration(7)+.01 )
#compute jump direction
newJumpPos = vizmat.Transform()
newJumpPos.setTrans([0, 0, 1.8])
newJumpPos.postEuler(avatar.getEuler(viz.ABS_GLOBA L)[0], 0, 0)
avatarRoot.setPosition(newJumpPos.getTrans(), viz.REL_GLOBAL)


if not (viz.iskeydown(' ') or viz.iskeydown('w') or viz.iskeydown('s') or viz.iskeydown('a') or viz.iskeydown('d') ):
avatar.state(1)

yield None

viztask.schedule(moveAvatar())

import vizcam

camera = vizcam.PivotNavigate()
camera.setDistance(5)


def moveCamera():
while True:
lookAtPos = avatar.getBone('Bip01 Pelvis').getPosition(viz.ABS_GLOBAL)
lookAtPos[1] = lookAtPos[1] + .5
camera.setCenter(lookAtPos)
camera.updateCenter()

yield None

viztask.schedule(moveCamera())

Jeff
08-08-2011, 12:44 PM
Please post or attach example code that we can run to see the issue. Also, try to make the example as concise as possible.

kovitch
08-09-2011, 01:40 AM
Run the following code, then uncomment the line viz.collision(viz.ON) and you will see what I am experiencing. Regards.


import viz
import viztask
import vizmat

viz.go()

viz.MainView.getHeadLight().disable()
#add sun-like directional light
l = viz.addLight()
l.position(0, 1, -.2, 0) #sets light direction

ground = viz.add('tut_ground.wrl')

avatarRoot = viz.addGroup()
avatarRoot = viz.add('marker.wrl')
cameraLookAtNode = viz.addGroup(parent=avatarRoot, pos=[0, 1.5, 0])
avatar = viz.add('vcc_male.cfg', parent=avatarRoot)

#Turn on collision
#viz.collision(viz.ON)

#setup physics system so viewpoint does not move through walls
viz.phys.enable()
avatar.collideMesh(bounce=0, hardness=1, friction=0)

def moveAvatar():
avatar_speed = 1
running = False
jump = False
while True:
#get user input
newPos = vizmat.Vector()
newPos.set([0,0,0])
if viz.iskeydown(viz.KEY_SHIFT_L):
avatar_speed = 10
running = True
else:
avatar_speed = 4
running = False

if viz.iskeydown('w'):
#walk forward
newPos = newPos + [0, 0, avatar_speed]
if viz.iskeydown('s'):
newPos = newPos + [0, 0, -avatar_speed]
if viz.iskeydown('a'):
newPos = newPos + [-avatar_speed, 0, 0]
if viz.iskeydown('d'):
newPos = newPos + [avatar_speed, 0, 0]
isJumping = False
isAttacking = False
if viz.iskeydown(' '):
#jump
isJumping = True
elif viz.iskeydown('v'):
isAttacking = True

if isAttacking:
avatar.state(6)
yield viztask.waitTime( 1.5 )
if newPos.length() > 0 or isJumping:
if newPos.length() == 0:
#jumping but no direction key, use current heading
t = vizmat.Transform()
t.setTrans([0, 0, 1.8])
t.postEuler(avatar.getEuler()[0],0,0)
newPos = vizmat.Vector( t.getTrans() )
newYaw = vizmat.AngleToPoint(0, 0, newPos[0], newPos[2])
avatar.setEuler(newYaw, 0, 0)
if not isJumping:
#just walking
cameraEuler = viz.MainView.getEuler()
avatarRoot.setEuler(cameraEuler[0], 0, 0)
newPos = newPos * viz.getFrameElapsed()
avatarRoot.setPosition(newPos, viz.REL_LOCAL)
if running == False:
avatar.state(2)
else:
avatar.state(11)
else:
#jumping
avatar.state(7)
yield viztask.waitTime( avatar.getDuration(7)+.01 )
#compute jump direction
newJumpPos = vizmat.Transform()
newJumpPos.setTrans([0, 0, 1.8])
newJumpPos.postEuler(avatar.getEuler(viz.ABS_GLOBA L)[0], 0, 0)
avatarRoot.setPosition(newJumpPos.getTrans(), viz.REL_GLOBAL)


if not (viz.iskeydown(' ') or viz.iskeydown('w') or viz.iskeydown('s') or viz.iskeydown('a') or viz.iskeydown('d') ):
avatar.state(1)

yield None

viztask.schedule(moveAvatar())

import vizcam

camera = vizcam.PivotNavigate()
camera.setDistance(5)


def moveCamera():
while True:
lookAtPos = avatar.getBone('Bip01 Pelvis').getPosition(viz.ABS_GLOBAL)
lookAtPos[1] = lookAtPos[1] + .5
camera.setCenter(lookAtPos)
camera.updateCenter()

yield None

viztask.schedule(moveCamera())