WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-11-2009, 08:51 PM
nlfrnassimi nlfrnassimi is offline
Member
 
Join Date: Feb 2009
Posts: 37
View

I have tried to link my view to my avatar and make it first point of view. I have assigned r key to make avatar and view go to a certain point and also created another view to be able to change my view. I have tried to look side, up and down by pressing certain keys but they don't work properly and another problem is that my animated path (r key ) doesn't work now.

Please take a look at my code. and tell me what are the mistakes that I have made.



import viz

viz.go()

viz.add('tut_ground.wrl')

view = viz.MainView

character = viz.add('vcc_male.cfg') # Add a CAL3D based avatar
character.state(1) # Activate the walking state

viewLink = viz.link( character, view)
viewLink.setDstFlag( viz.LINK_HEAD)
viewLink.preTrans( [-.4, .1, 0] )

vizact.whilekeydown(viz.KEY_UP,character.rotate,1, 0,0,vizact.elapsed(-15),viz.REL_PARENT)
vizact.whilekeydown(viz.KEY_DOWN,character.rotate,-1,0,0,vizact.elapsed(-15),viz.REL_PARENT)
vizact.whilekeydown(viz.KEY_RIGHT,character.rotate ,0,1,0,vizact.elapsed(15),viz.REL_PARENT)
vizact.whilekeydown(viz.KEY_LEFT,character.rotate, 0,1,0,vizact.elapsed(-15),viz.REL_PARENT)


def characterWalk (key):
if key == 'r':
character.state(2)
walk = vizact.walkTo([10,0,0],1,45)
character.addAction(walk)

viz.callback(viz.KEYBOARD_EVENT, characterWalk)

secondView = viz.addView()
secondView.setPosition(10,2,20)
secondView.rotate(220)

def anotherView (key):
if key == 'v':
viz.MainWindow.viewpoint(secondView)

viz.callback(viz.KEYBOARD_EVENT, anotherView,priority=1)
Reply With Quote
  #2  
Old 03-11-2009, 10:06 PM
nlfrnassimi nlfrnassimi is offline
Member
 
Join Date: Feb 2009
Posts: 37
I found the solution
Reply With Quote
  #3  
Old 03-11-2009, 11:18 PM
nlfrnassimi nlfrnassimi is offline
Member
 
Join Date: Feb 2009
Posts: 37
I was able to make my view move and rotate correctly, but the problem is that I can't fix my view to be beside the avatar's head. and I also want to press a key for example 'r' and move the character to a certain point but anything I tried didn't work at all.

Please take a look at my code:


import viz

viz.go()

viz.clearcolor(0.5,0.5,1)

MOVE_SPEED = 5 # how fast the viewpoint move
TURN_SPEED = 60 # how fast the view point rotate

viz.add('tut_ground.wrl')
char = viz.add('vcc_male.cfg')
char.state(1)

view = viz.MainView
view.setPosition(0,1.7,0)
car = viz.add('mini.osgx')
car.translate(5,0,5)

def mytimer(num):
Quote:
if viz.iskeydown(viz.KEY_DOWN):
view.move(0,0,-MOVE_SPEED*viz.elapsed(),viz.BODY_ORI)
elif viz.iskeydown(viz.KEY_UP):
view.move(0,0,MOVE_SPEED*viz.elapsed(),viz.BODY_OR I)
elif viz.iskeydown(viz.KEY_RIGHT):
view.rotate(0,1,0,TURN_SPEED*viz.elapsed(),viz.BOD Y_ORI,viz.REL_PARENT)
elif viz.iskeydown(viz.KEY_LEFT):
view.rotate(0,1,0,-TURN_SPEED*viz.elapsed(),viz.BODY_ORI,viz.REL_PARE NT)
updatechar()
viz.callback(viz.TIMER_EVENT,mytimer)

viz.starttimer(0,0.01,viz.FOREVER)

def updatechar():

#translate the character to the position of the viewpoint
char.translate(view.get(viz.HEAD_POS))
#rotate the character to the same orientation as the BODY_ORI.
char.rotate(view.get(viz.BODY_AXISANGLE))
#move the character beside the view.
char.translate(0,-0.35,0,viz.REL_LOCAL) #viz.REL_LOCAL. This tells vizard to translate the car relative to its local coordinate system (i.e. relative to the direction the car is facing).


def mousemove(e):
#gets the Euler angle rotation of the HEAD_ORI
euler = view.get(viz.HEAD_EULER)
#adding the x movement of the mouse to the current yaw(we multiply the x movement by 0.1. This is to decrease the sensitivity of the movement)
euler[0] += e.dx*0.1
#adds the y movement of the mouse to the current pitch. We need to negate the value since a positive pitch value means rotating down, but moving the mouse down means having a negative y movement.
euler[1] += -e.dy*0.1
#clamping the pitch value between -90 and 90, since we don't want to let the user look down or up so much that they end up upside down.
euler[1] = viz.clamp(euler[1],-90.0,90.0)
#rotating the HEAD_ORI of the viewpoint by the new euler angle rotation
view.rotate(euler,viz.HEAD_ORI)

viz.callback(viz.MOUSE_MOVE_EVENT,mousemove)
#Turn off built in mouse
viz.setMouseOverride()
#Hide cursor
viz.cursor(viz.OFF)

def mousedown(button):
if button == viz.MOUSEBUTTON_LEFT:
view.reset(viz.HEAD_ORI)

elif button == viz.MOUSEBUTTON_RIGHT:
view.reset(viz.BODY_ORI|viz.HEAD_POS)
updatechar()

viz.callback(viz.MOUSEBUTTON_EVENT,mousedown)

Last edited by nlfrnassimi; 03-11-2009 at 11:24 PM.
Reply With Quote
  #4  
Old 03-11-2009, 11:38 PM
nlfrnassimi nlfrnassimi is offline
Member
 
Join Date: Feb 2009
Posts: 37
sorry about the code I can't get the code indentation. please tell me how to do that.
Reply With Quote
  #5  
Old 03-12-2009, 05:25 AM
moooh moooh is offline
Member
 
Join Date: Dec 2008
Posts: 19
just post the code inbetween the code tags [ code] code goes here [ /code]
without the extra spaces I added in order for the tags to show up as text
Reply With Quote
Reply

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
view problem nlfrnassimi Vizard 3 03-11-2009 08:33 PM
Manipulating Tracker View Micha Vizard 3 02-25-2008 10:05 AM
problem with stereo mode shivanangel Vizard 3 10-17-2006 09:58 AM
Moving view with object Xliben Vizard 2 07-25-2005 05:36 PM
keeping a 3d object in front of the view tavaksai Vizard 1 07-07-2004 09:33 AM


All times are GMT -7. The time now is 01:38 AM.


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