![]() |
#1
|
|||
|
|||
Some Problem in navigation
I have been trying to use UserAvatar.py for navigation from link:
http://vizworkshop.com/articles/walkthrough_app I did two following changes in UserAvatar file: Change 1: In _init_ function, I used collideBox in place of collideCapsule. Change 2: In updatePrePhysics, I changed headEuler following way: headEuler = self.head.getEuler(viz.ABS_GLOBAL) headEuler[0] = headEuler[0] + yawChange headEuler[1] = headEuler[1] headEuler[2] = headEuler[2] self.head.setEuler(headEuler, viz.ABS_GLOBAL) Problem: In code, there is no change of y-coordinate of self.feet. According to code, it should be always zero (0). But when I run the code with above change, I get change in y-coordinate of self.feet. So in order to keep it zero, I add following code in updatePostPhysics: temp_pos= self.feet.getPosition(viz.ABS_GLOBAL) temp_pos[1]=0 self.feet.setPosition(temp_pos) After doing this , y is zero . But movement is not smooth. Could you give some solutions? For your convenience, updated UserAvatar.py is attached below. import viz import vizact import vizmat import viztask class UserAvatar(viz.EventClass): THROTTLE_SPEED = 4 HYPER_THROTTLE_SPEED = 30 TURN_SPEED = .1 def __init__(self): viz.EventClass.__init__(self) self.feet = viz.addGroup(pos=[0, 0, 0]) #position of user avatar #physics init self.physicShape = self.feet.collideBox([0.5,1,0.5],friction=.00000001, hardness=.0000001, bounce=0) self.velMotor = self.feet.addVelocity(velocity=[0,0,0], maxForce=100, gravity=False)) #orientation of user avatar self.head = viz.addGroup() #view should link to this self.avatar = viz.mergeLinkable(self.feet, self.head) self.count =0; self.mouseDx = 0 self.mouseDy = 0 self.callback(viz.MOUSE_MOVE_EVENT, self.onMouseMove) vizact.onupdate(viz.PRIORITY_PHYSICS-1, self.updatePrePhysics) vizact.onupdate(viz.PRIORITY_PHYSICS+1, self.updatePostPhysics) def updatePrePhysics(self): print "count " +str(self.count) self.count =self.count+1 throttle = vizmat.Vector([0,0,0]) print "vizmat.Vector:Feet Pos: " + str(self.feet.getPosition(viz.ABS_GLOBAL)) ## Steer Control yawChange = self.mouseDx * self.TURN_SPEED pitchChange = -self.mouseDy * self.TURN_SPEED #discard old mouse movement and start collecting new mouse input self.mouseDx = 0 self.mouseDy = 0 ''' headEuler = self.head.getEuler(viz.ABS_GLOBAL) headEuler[0] = headEuler[0] + yawChange headEuler[1] = headEuler[1] headEuler[2] = headEuler[2] self.head.setEuler(headEuler, viz.ABS_GLOBAL) ''' ## Translate Control throttle.set([0,0,0]) #forward/back if viz.key.isDown('w') or viz.mouse.getState() & viz.MOUSEBUTTON_LEFT: throttle += [0,0,1] if viz.key.isDown('s') or viz.mouse.getState() & viz.MOUSEBUTTON_RIGHT: throttle += [0,0,-1] #left/right if viz.key.isDown('a'): throttle += [-1,0,0] if viz.key.isDown('d'): throttle += [1,0,0] throttle.normalize() #<--direction print "throttle.normalize:Feet Pos: " + str(self.feet.getPosition(viz.ABS_GLOBAL)) print "throttle.length():Feet Pos: " + str(self.feet.getPosition(viz.ABS_GLOBAL)) if viz.key.isDown(' ') or viz.mouse.getState() & viz.MOUSEBUTTON_MIDDLE: throttle *= self.HYPER_THROTTLE_SPEED else: throttle *= self.THROTTLE_SPEED print "viz.key.isDown:Feet Pos: " + str(self.feet.getPosition(viz.ABS_GLOBAL)) if throttle.length(): #if throttle not zero #move forward in direction of head newVel = vizmat.Transform() newVel.setTrans(throttle) newVel.postEuler(self.head.getEuler(viz.ABS_GLOBAL )) self.velMotor.setVelocity(newVel.getTrans()) else: print "hey" #self.velMotor.setVelocity([0, 0, 0]) print "throttle.length():Feet Pos: " + str(self.feet.getPosition(viz.ABS_GLOBAL)) def updatePostPhysics(self): print "updatePostPhysics " + str(self.feet.getPosition(viz.ABS_GLOBAL)) self.feet.setEuler([0, 0, 0]) def onMouseMove(self, e): #fuction called twice, once for movement on x axis, once for y axis print "onMouseMove " + str(self.feet.getPosition(viz.ABS_GLOBAL)) self.mouseDx = self.mouseDx + e.dx self.mouseDy = self.mouseDy + e.dy def linkView(self, view): return viz.link(self.avatar, view, srcFlag=viz.LINK_ABSOLUTE, dstFlag=viz.LINK_POS_RAW) def setPosition(self, xyz): self.feet.setPosition(xyz) print "setPosition " + str(self.feet.getPosition(viz.ABS_GLOBAL)) def setEuler(self, euler): self.head.setEuler(euler) if __name__ == '__main__': viz.go() viz.move([0, 0, -2]) viz.phys.enable() t = viz.add('tankmaze.wrl') t.collideMesh(bounce=0, hardness=1, friction=0) user = UserAvatar() user.feet.setPosition([0, 0, 0]) user.linkView(viz.MainView) |
#2
|
|||
|
|||
Please disregard my previous post
I have been trying to use UserAvatar.py for navigation from link:
http://vizworkshop.com/articles/walkthrough_app I did two following changes in UserAvatar file: Change 1: In _init_ function, I used collideBox in place of collideCapsule. Change 2: In updatePrePhysics, I changed headEuler following way: headEuler = self.head.getEuler(viz.ABS_GLOBAL) headEuler[0] = headEuler[0] + yawChange headEuler[1] = headEuler[1] headEuler[2] = headEuler[2] self.head.setEuler(headEuler, viz.ABS_GLOBAL) Problem: In code, there is no change of y-coordinate of self.feet. According to code, it should be always zero (0). But when I run the code with above change, I get change in y-coordinate of self.feet. So in order to keep it zero, I add following code in updatePostPhysics: temp_pos= self.feet.getPosition(viz.ABS_GLOBAL) temp_pos[1]=0 self.feet.setPosition(temp_pos) After doing this , y is zero . But movement is not smooth. Could you give any solution? For your convenience, updated UserAvatar.py is attached below. Code:
''' Moves the view according to user input ''' import viz import vizact import vizmat import viztask class UserAvatar(viz.EventClass): THROTTLE_SPEED = 4 HYPER_THROTTLE_SPEED = 30 TURN_SPEED = .1 def __init__(self): viz.EventClass.__init__(self) self.feet = viz.addGroup(pos=[0, 0, 0]) #position of user avatar #physics init self.physicShape = self.feet.collideBox([0.5,1,0.5],friction=.00000001, hardness=.0000001, bounce=0) self.velMotor = self.feet.addVelocity(velocity=[0,0,0], maxForce=100, gravity=False)) #orientation of user avatar self.head = viz.addGroup() #view should link to this self.avatar = viz.mergeLinkable(self.feet, self.head) self.mouseDx = 0 self.mouseDy = 0 self.callback(viz.MOUSE_MOVE_EVENT, self.onMouseMove) vizact.onupdate(viz.PRIORITY_PHYSICS-1, self.updatePrePhysics) vizact.onupdate(viz.PRIORITY_PHYSICS+1, self.updatePostPhysics) def updatePrePhysics(self): throttle = vizmat.Vector([0,0,0]) ## Steer Control yawChange = self.mouseDx * self.TURN_SPEED pitchChange = -self.mouseDy * self.TURN_SPEED #discard old mouse movement and start collecting new mouse input self.mouseDx = 0 self.mouseDy = 0 headEuler = self.head.getEuler(viz.ABS_GLOBAL) headEuler[0] = headEuler[0] + yawChange headEuler[1] = headEuler[1] headEuler[2] = headEuler[2] self.head.setEuler(headEuler, viz.ABS_GLOBAL) ## Translate Control throttle.set([0,0,0]) #forward/back if viz.key.isDown('w') or viz.mouse.getState() & viz.MOUSEBUTTON_LEFT: throttle += [0,0,1] if viz.key.isDown('s') or viz.mouse.getState() & viz.MOUSEBUTTON_RIGHT: throttle += [0,0,-1] #left/right if viz.key.isDown('a'): throttle += [-1,0,0] if viz.key.isDown('d'): throttle += [1,0,0] throttle.normalize() #<--direction if viz.key.isDown(' ') or viz.mouse.getState() & viz.MOUSEBUTTON_MIDDLE: throttle *= self.HYPER_THROTTLE_SPEED else: throttle *= self.THROTTLE_SPEED if throttle.length(): #if throttle not zero #move forward in direction of head newVel = vizmat.Transform() newVel.setTrans(throttle) newVel.postEuler(self.head.getEuler(viz.ABS_GLOBAL)) self.velMotor.setVelocity(newVel.getTrans()) else: self.velMotor.setVelocity([0, 0, 0]) def updatePostPhysics(self): self.feet.setEuler([0, 0, 0]) def onMouseMove(self, e): #fuction called twice, once for movement on x axis, once for y axis self.mouseDx = self.mouseDx + e.dx self.mouseDy = self.mouseDy + e.dy def linkView(self, view): return viz.link(self.avatar, view, srcFlag=viz.LINK_ABSOLUTE, dstFlag=viz.LINK_POS_RAW) def setPosition(self, xyz): self.feet.setPosition(xyz) def setEuler(self, euler): self.head.setEuler(euler) if __name__ == '__main__': viz.go() viz.move([0, 0, -2]) viz.phys.enable() t = viz.add('tankmaze.wrl') t.collideMesh(bounce=0, hardness=1, friction=0) user = UserAvatar() user.feet.setPosition([0, 0, 0]) user.linkView(viz.MainView) |
#3
|
|||
|
|||
Replied to here:
http://vizworkshop.com/articles/walk..._app#comment-3 Answer: I could not reproduce the problem. I made your changes to UserAvatar.py and movement is smooth. Perhaps if you post your UserAvatar.py I can see your problem. The one you posted does not have your change to the "updatePostPhysics" method. The problem could be because your moving the physics shape/box inside of another physics object, the tankmaze floor, with your updatePostPhysics method. This could be generating some strong "repelling" forces and make your movement jerky/weird. Hold the feet Y value at 1 or above to fix. Also, the corners of collideBox cause some funky jerks when running into the hedra shape. Change back to smooth object like capsule or sphere to fix.
__________________
Paul Elliott WorldViz LLC |
#4
|
|||
|
|||
My code
Thanks for your reply.
According to your instruction, I changed. But, still, movememnt is not smooth. Please check the attached code. |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
navigation in cave environment | Andy | Vizard | 4 | 03-28-2008 02:32 AM |
5DT Data Glove 5 Ultra Problem | bjgold | Vizard | 1 | 08-08-2006 05:08 PM |
problem with female animations | vmonkey | Vizard | 1 | 10-07-2005 11:36 AM |
sound problem | alaa | Vizard | 7 | 09-02-2005 02:13 PM |
PROBLEM: Picture-in-Picture breaks textures?!? | vcarlson | Vizard | 4 | 10-05-2004 05:22 PM |