WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-08-2010, 05:08 PM
ssaha ssaha is offline
Member
 
Join Date: Feb 2010
Posts: 4
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)
Reply With Quote
 

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
navigation in cave environment Andy Vizard 4 03-28-2008 01:32 AM
5DT Data Glove 5 Ultra Problem bjgold Vizard 1 08-08-2006 04:08 PM
problem with female animations vmonkey Vizard 1 10-07-2005 10:36 AM
sound problem alaa Vizard 7 09-02-2005 01:13 PM
PROBLEM: Picture-in-Picture breaks textures?!? vcarlson Vizard 4 10-05-2004 04:22 PM


All times are GMT -7. The time now is 07:17 PM.


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