#1
|
|||
|
|||
animation path problem - coordinates not resetting
Dear Jeff,
I am sorry, but I am still having problems with my animation path from here http://forum.worldviz.com/showthread.php?t=5695 Since it is a different problem, I decided to open a new thread. The problem is that after the trial (and the animation) run once, the other three times they run, the coordinates are not reset. To find out what happens I added two lines to find out the cooridnates (red below), at those points where I believe I should get the starting and end positions. The output gives me this, which is indeed very strange: Code:
now [-6.400000095367432, 0.0, -8.0] [0.0, 1.399999976158142, 5.0] now [0.0, 0.0, 5.0] [0.0, 0.0, 5.0] now [0.0, 0.0, 5.0] [0.0, 0.0, 5.0] now [0.0, 0.0, 5.0] [0.0, 0.0, 5.0] I would be so grateful for your help! I have updated the code below: Code:
import viz #Needed to generate a world. import viztask #Needed to control the experiment structure. viz.mouse.setVisible(viz.OFF) #Stops the mouse appearing on the screen. viz.mouse.setOverride(viz.ON) #Stops Vizard navigation using the mouse. viz.clearcolor(viz.BLACK) #Set the start position: startPos = [-6.4,0,-8] viz.go() ### Add all the resources. ############### maze1 = viz.add('Objects/Maze_1.dae') maze1.visible(viz.OFF) #Add a sky with an environment map. env = viz.add(viz.ENVIRONMENT_MAP,'sky.jpg') dome = viz.add('skydome.dlc') dome.texture(env) view = viz.MainView view.eyeheight(1.4) view.setPosition(startPos) view.collision(viz.ON) viz.collisionbuffer(.8) viewNode = viz.addGroup() viewLink = viz.link( viewNode, viz.MainView) viewNode.setPosition([-6.4,0,-8]) ##Animation path pathMaze1 = viz.addAnimationPath() #Add control points to the path, along with their time stamp. pathMaze1.addControlPoint(0,pos=(-6.4,0,-8),euler=(0,0,0),scale=(2,2,2)) pathMaze1.addControlPoint(2,pos=(-6.4,0,-8),euler=(90,0,0),scale=(2,2,2)) pathMaze1.addControlPoint(4,pos=(0,0,-8),euler=(0,0,0),scale=(2,2,2)) pathMaze1.addControlPoint(8,pos=(0,0,5),euler=(0,0,0),scale=(2,2,2)) #Duation of animation pathMaze1Duration = pathMaze1.getDuration() #Loop the path in a swinging fashion (point A to point B to point A, etc.). pathMaze1.setLoopMode(viz.OFF) def maze1trial(): print 'now' print view.getPosition(mode = viz.ABS_PARENT) pathMaze1.reset() maze1.visible(viz.ON) viewNode.setPosition(startPos) link = viz.link(pathMaze1,viewNode) yield pathMaze1.play() yield viztask.waitTime(pathMaze1Duration) print view.getPosition(mode = viz.ABS_PARENT) link.remove maze1.visible(viz.OFF) def masterFunction(): for x in range(4): yield maze1trial() viztask.schedule(masterFunction()) |
#2
|
|||
|
|||
Try placing the print statement after the path is reset:
Code:
pathMaze1.reset() print view.getPosition(mode = viz.ABS_PARENT) Last edited by Jeff; 04-20-2016 at 09:50 PM. |
#3
|
|||
|
|||
Thank you very much!
It worked now, though I am not sure what did the trick! I simplified it and it now looks like this: Code:
import viz #Needed to generate a world. import viztask #Needed to control the experiment structure. viz.mouse.setVisible(viz.OFF) #Stops the mouse appearing on the screen. viz.mouse.setOverride(viz.ON) #Stops Vizard navigation using the mouse. viz.clearcolor(viz.BLACK) viz.go() #Set the start position: startPos = [-6.4,0,-8] ### Add all the resources. ############### maze1 = viz.add('Objects/Maze_1.dae') maze1.visible(viz.OFF) #Add a sky with an environment map. env = viz.add(viz.ENVIRONMENT_MAP,'sky.jpg') dome = viz.add('skydome.dlc') dome.texture(env) view = viz.MainView view.eyeheight(1.4) view.setPosition(startPos) view.collision(viz.ON) viz.collisionbuffer(.8) ##Animation path pathMaze1 = viz.addAnimationPath() #Add control points to the path, along with their time stamp. pathMaze1.addControlPoint(2, pos=startPos,euler=(0,0,0),scale=(2,2,2)) pathMaze1.addControlPoint(4, pos=startPos,euler=(90,0,0),scale=(2,2,2)) pathMaze1.addControlPoint(6, pos=(0,0,-8),euler=(0,0,0),scale=(2,2,2)) pathMaze1.addControlPoint(8, pos=(0,0,5),euler=(0,0,0),scale=(2,2,2)) #Duation of animation pathMaze1Duration = pathMaze1.getDuration() def animation(): link = viz.link(pathMaze1,view) pathMaze1.play() yield viztask.waitTime(pathMaze1Duration) pathMaze1.reset() def maze1trial(): print 'now' view.setPosition(startPos) print view.getPosition(mode = viz.ABS_PARENT) maze1.visible(viz.ON) yield animation() print view.getPosition(mode = viz.ABS_PARENT) maze1.visible(viz.OFF) def masterFunction(): for x in range(4): yield maze1trial() viztask.schedule(masterFunction()) |
#4
|
|||
|
|||
I am afraid that the problem continues as soon as I introduce further animation paths. I changed the one I had before to get the following: a trial triggers an animation that moves the viewpoint through a maze until a certain point when it wiats for an arrow key. Once a key is pressed it triggers one of two possible animations (going through left or right door). After this, immmediately, the next trial should start.
Problem 1: This almost happens, only that the second trial starts at the point where the last door was, etc. I tried resetting the animation paths at various points and nothing seems to help. Problem 2: For some reason, it the right arrow key seems to not work. This seems to be a problem of the if statement, because even if I replace the arrow key with the space bar, it does not take the "elif" statement... I would highly appreciate any pointers in the right direction! Code:
import viz #Needed to generate a world. import viztask #Needed to control the experiment structure. viz.mouse.setVisible(viz.OFF) #Stops the mouse appearing on the screen. viz.mouse.setOverride(viz.ON) #Stops Vizard navigation using the mouse. viz.clearcolor(viz.BLACK) viz.go() #Set the start position: startPos = [-6.4,0,-8] #Load a maze and make it invisible maze1 = viz.add('Objects/Maze_1.dae') maze1.visible(viz.OFF) #Add a sky with an environment map. env = viz.add(viz.ENVIRONMENT_MAP,'sky.jpg') dome = viz.add('skydome.dlc') dome.texture(env) #Parameters for the viewpoint view = viz.MainView view.eyeheight(1.4) view.setPosition(startPos) view.collision(viz.ON) viz.collisionbuffer(.8) ##Animation path pathMaze1 = viz.addAnimationPath() #Add control points to the path, along with their time stamp. pathMaze1.addControlPoint(2, autoRemove = True, pos=startPos,euler=(0,0,0),scale=(2,2,2)) pathMaze1.addControlPoint(4, autoRemove = True, pos=startPos,euler=(90,0,0),scale=(2,2,2)) pathMaze1.addControlPoint(6, autoRemove = True, pos=(0,0,-8),euler=(0,0,0),scale=(2,2,2)) pathMaze1.addControlPoint(8, autoRemove = True, pos=(0,0,5),euler=(0,0,0),scale=(2,2,2)) #Duation of animation path pathMaze1Duration = pathMaze1.getDuration() #animation paths for choosing doors pathDoorLeft = viz.addAnimationPath() pathDoorLeft.addControlPoint(0, autoRemove = True, pos=(0,0,5),euler=(0,0,0),scale=(2,2,2)) pathDoorLeft.addControlPoint(1, autoRemove = True, pos=(0,0,5),euler=(-10,0,0),scale=(2,2,2)) pathDoorLeft.addControlPoint(2, autoRemove = True, pos=(-1.3,0,10),euler=(-10,0,0),scale=(2,2,2)) pathDoorLeftDuration = pathDoorLeft.getDuration() pathDoorRight = viz.addAnimationPath() pathDoorRight.addControlPoint(0, autoRemove = True, pos=(0,0,5),euler=(0,0,0),scale=(2,2,2)) pathDoorRight.addControlPoint(1, autoRemove = True, pos=(0,0,5),euler=(10,0,0),scale=(2,2,2)) pathDoorRight.addControlPoint(2, autoRemove = True, pos=(1.3,0,10),euler=(10,0,0),scale=(2,2,2)) pathDoorRightDuration = pathDoorRight.getDuration() def chooseDoor(): yield viztask.waitKeyDown(viz.KEY_LEFT or viz.KEY_RIGHT) if viz.key.isDown(viz.KEY_LEFT): link = viz.link(pathDoorLeft,view) pathDoorLeft.play() yield viztask.waitTime(pathDoorLeftDuration) elif viz.key.isDown(viz.KEY_RIGHT): link = viz.link(pathDoorRight,view) pathDoorRight.play() yield viztask.waitTime(pathDoorRightDuration) def animation(): link = viz.link(pathMaze1,view) pathMaze1.play() yield viztask.waitTime(pathMaze1Duration) #pathMaze1.reset() def maze1trial(): print 'new trial' pathMaze1.reset() pathDoorRight.reset() pathDoorLeft.reset() view.setPosition(startPos) link = viz.link(pathMaze1,view) print view.getPosition(mode = viz.ABS_PARENT) #starting point of animation just for control purposes maze1.visible(viz.ON) yield animation() print view.getPosition(mode = viz.ABS_PARENT) #ending point of animation just for control purposes yield chooseDoor() def masterFunction(): for x in range(4): yield maze1trial() viztask.schedule(masterFunction()) |
#5
|
|||
|
|||
The arrow key problem seems to be a problem in my particular case, but not necessarily acoding mistake. This simple code shows that, for some reason only the left arrow key works.
Code:
import viz import viztask viz.clearcolor(viz.BLACK) viz.go() def key(): yield viztask.waitKeyDown(viz.KEY_LEFT or viz.KEY_RIGHT) if viz.key.isDown(viz.KEY_RIGHT): print '"RIGHT" key is down' elif viz.key.isDown(viz.KEY_LEFT): print '"LEFT" key is down' viztask.schedule(key()) As for the second problem with the animation paths: I have reset all three animation paths at the beginning of the trial and re-established the link. I have actually tried an impossible number of combinations, where I resert the animations at different locations (inside each of the functions, same goes for the link and resetting the viewpoint at the start location. Each time things turn out different, sometimes the coordinates are so much off, it is impossible to track what is going on. Other times, they are only slightly off and in some cases I have animations that add the paths of the second animation to the first one, hence creating one long one. This is a clue that sometimes the animation paths maybe do not reset? The closes I got was with this code (please see below). This works almost perfectly. Only the first control point of the main maze animation path is a bit off. Firts time, it runs perfectly, the next times it always takes the same last coordinates of the end control point of the left door animation path. So the biggest clue for me to understand is where do I reset the door animation best? In the chooseDoor function, in the trial function? I have tried them all.. Code:
import viz import viztask viz.mouse.setVisible(viz.OFF) #Stops the mouse appearing on the screen. viz.mouse.setOverride(viz.ON) #Stops Vizard navigation using the mouse. viz.clearcolor(viz.BLACK) viz.go() #Set the start position: startPos = [-6.4,0,-8] #Load a maze and make it invisible maze1 = viz.add('Objects/Maze_1.dae') maze1.visible(viz.OFF) #Add a sky with an environment map. env = viz.add(viz.ENVIRONMENT_MAP,'sky.jpg') dome = viz.add('skydome.dlc') dome.texture(env) #Parameters for the viewpoint view = viz.MainView view.eyeheight(1.4) view.setPosition(startPos) view.collision(viz.ON) viz.collisionbuffer(.8) ##Animation path pathMaze1 = viz.addAnimationPath() #Add control points to the path, along with their time stamp. pathMaze1.addControlPoint(2, autoRemove = True, pos=startPos,euler=(0,0,0),scale=(2,2,2)) pathMaze1.addControlPoint(4, autoRemove = True, pos=startPos,euler=(90,0,0),scale=(2,2,2)) pathMaze1.addControlPoint(6, autoRemove = True, pos=(0,0,-8),euler=(0,0,0),scale=(2,2,2)) pathMaze1.addControlPoint(8, autoRemove = True, pos=(0,0,5),euler=(0,0,0),scale=(2,2,2)) #Duation of animation path pathMaze1Duration = pathMaze1.getDuration() #animation paths for choosing doors pathDoorLeft = viz.addAnimationPath() pathDoorLeft.addControlPoint(0, autoRemove = True, pos=(0,0,5),euler=(0,0,0),scale=(2,2,2)) pathDoorLeft.addControlPoint(1, autoRemove = True, pos=(0,0,5),euler=(-10,0,0),scale=(2,2,2)) pathDoorLeft.addControlPoint(2, autoRemove = True, pos=(-1.3,0,10),euler=(-10,0,0),scale=(2,2,2)) pathDoorLeftDuration = pathDoorLeft.getDuration() pathDoorRight = viz.addAnimationPath() pathDoorRight.addControlPoint(0, autoRemove = True, pos=(0,0,5),euler=(0,0,0),scale=(2,2,2)) pathDoorRight.addControlPoint(1, autoRemove = True, pos=(0,0,5),euler=(10,0,0),scale=(2,2,2)) pathDoorRight.addControlPoint(2, autoRemove = True, pos=(1.3,0,10),euler=(10,0,0),scale=(2,2,2)) pathDoorRightDuration = pathDoorRight.getDuration() link = viz.link(pathMaze1,view) def chooseDoor(): yield viztask.waitKeyDown(viz.KEY_LEFT or viz.KEY_RIGHT) if viz.key.isDown(viz.KEY_LEFT): link = viz.link(pathDoorLeft,view) pathDoorLeft.play() yield viztask.waitTime(pathDoorLeftDuration) pathDoorLeft.reset() link.remove() elif viz.key.isDown(viz.KEY_RIGHT): link = viz.link(pathDoorRight,view) pathDoorRight.play() yield viztask.waitTime(pathDoorRightDuration) pathDoorRight.reset() link.remove() def animation(): link = viz.link(pathMaze1,view) pathMaze1.play() yield viztask.waitTime(pathMaze1Duration) #pathMaze1.reset() def maze1trial(): print 'new trial' pathMaze1.reset() view.setPosition(startPos) link = viz.link(pathMaze1,view) print view.getPosition(mode = viz.ABS_PARENT) #starting point of animation just for control purposes maze1.visible(viz.ON) yield animation() print view.getPosition(mode = viz.ABS_PARENT) #ending point of animation just for control purposes yield chooseDoor() link.remove() def masterFunction(): for x in range(4): yield maze1trial() viztask.schedule(masterFunction()) |
#6
|
|||
|
|||
The viztask.waitKeyDown command requires a list of keys. Try the following instead:
Code:
yield viztask.waitKeyDown([viz.KEY_LEFT,viz.KEY_RIGHT]) |
#7
|
|||
|
|||
Perfect, it works! My intermediate solution was to try (None), as in "any key" in order to get rid of the "or" but this solution is perfect. Thank you!
|
#8
|
|||
|
|||
problem resetting an animation path
I have a little problem that I have been stuck on for quite some time now. It is related to using several animation paths.
My trial function does the following: An animation is triggered right at the beginning, which takes the viewpoint through a short maze, according to the control points of the patheMaze1 animation. The viewpoint then stops at a position in front of two doors. Here one of two arrow keys must be pressed. This then triggers one of two possible animation paths (either going through the left or through the right door). Then all of this should repeat 4 times. The problem is that I tried working with resetting the animation paths, linkin and unlinking the paths and the viewpoint and resetting the viewpoints at various locations in the code. Nothing seems to work. I now have a new function that gives the coordinates of the animation path and the viewpoint (which should be linked) every 2 sec in order to be better able to understand the location coordinates. The code I have now (at the bottom) gives these following coordinates. NEW TRIAL View : [0.0, 1.399999976158142, -8.0] Maze1 : [-6.390899658203125, 1.399999976158142, -8.0] View : [0.0, 1.399999976158142, -7.971726894378662] Maze1 : [0.0, 1.399999976158142, -7.971726894378662] View : [0.0, 1.399999976158142, 5.0] Maze1 : [0.0, 1.399999976158142, 5.0] LEFT DOOR View : [-0.5865119695663452, 1.399999976158142, 7.255815505981445] Maze1 : [0.0, 1.399999976158142, 5.0] NEW TRIAL View : [0.0, 1.399999976158142, -8.0] Maze1 : [-6.400000095367432, 1.399999976158142, -8.0] View : [-1.8042783737182617, 1.399999976158142, -8.0] Maze1 : [-1.8042783737182617, 1.399999976158142, -8.0] View : [0.0, 1.399999976158142, 1.3455696105957031] Maze1 : [0.0, 1.399999976158142, 1.3455696105957031] View : [0.0, 1.399999976158142, 4.923357009887695] Maze1 : [0.0, 1.399999976158142, 5.0] LEFT DOOR View : [-1.2999999523162842, 1.399999976158142, 10.0] Maze1 : [0.0, 1.399999976158142, 5.0] NEW TRIAL View : [0.0, 1.399999976158142, -8.0] Maze1 : [-6.400000095367432, 1.399999976158142, -8.0] View : [-1.6976442337036133, 1.399999976158142, -8.0] Maze1 : [-1.6976442337036133, 1.399999976158142, -8.0] View : [0.0, 1.399999976158142, 1.5620803833007812] Maze1 : [0.0, 1.399999976158142, 1.5620803833007812] LEFT DOOR View : [-1.2999999523162842, 1.399999976158142, 10.0] Maze1 : [0.0, 1.399999976158142, 5.0] NEW TRIAL View : [0.0, 1.399999976158142, -8.0] Maze1 : [-6.400000095367432, 1.399999976158142, -8.0] View : [-4.900414943695068, 1.399999976158142, -8.0] Maze1 : [-4.900414943695068, 1.399999976158142, -8.0] View : [0.0, 1.399999976158142, -4.9427947998046875] Maze1 : [0.0, 1.399999976158142, -4.9427947998046875] View : [0.0, 1.399999976158142, 4.9235992431640625] Maze1 : [0.0, 1.399999976158142, 5.0] View : [0.0, 1.399999976158142, 4.9235992431640625] Maze1 : [0.0, 1.399999976158142, 5.0] QUESTION: I have highlighted in red, whenever the maze animation path and the viewpoint are not coinciding. WHY COULD THIS BE? I would really appreciate your help, because apart from the animation path basics, I have found no other online resources to understand how several animation paths may interact/ disturb each other and all my efforts so far of trying to come up with combinations and move pieces of code around, have not been successful Thank you very much for any kind help or pointers! Code:
import viz #Needed to generate a world. import viztask #Needed to control the experiment structure. import vizact viz.mouse.setVisible(viz.OFF) #Stops the mouse appearing on the screen. viz.mouse.setOverride(viz.ON) #Stops Vizard navigation using the mouse. viz.clearcolor(viz.BLACK) viz.go() #Add a sky with an environment map. env = viz.add(viz.ENVIRONMENT_MAP,'sky.jpg') dome = viz.add('skydome.dlc') dome.texture(env) #Load a maze and make it invisible maze1 = viz.add('Objects/Maze_1.dae') maze1.visible(viz.OFF) #Set the start position: startPos = [-6.4, 1.4, -8] #Parameters for the viewpoint view = viz.MainView view.setPosition(startPos) view.eyeheight(1.4) view.collision(viz.ON) viz.collisionbuffer(0.8) #Link link = None ##Animation paths pathMaze1 = viz.addAnimationPath() pathMaze1.addControlPoint(2, pos=startPos,euler=(0,0,0)) pathMaze1.addControlPoint(4, pos=startPos,euler=(90,0,0)) pathMaze1.addControlPoint(6, pos=(0,1.4,-8),euler=(0,0,0)) pathMaze1.addControlPoint(8, pos=(0,1.4,5),euler=(0,0,0)) pathMaze1Duration = pathMaze1.getDuration() pathDoorLeft = viz.addAnimationPath() pathDoorLeft.addControlPoint(0, pos=(0,1.4,5),euler=(0,0,0)) pathDoorLeft.addControlPoint(1, pos=(0,1.4,5),euler=(-10,0,0)) pathDoorLeft.addControlPoint(2, pos=(-1.3,1.4,10),euler=(-10,0,0)) pathDoorLeftDuration = pathDoorLeft.getDuration() pathDoorRight = viz.addAnimationPath() pathDoorRight.addControlPoint(0, pos=(0,1.4,5),euler=(0,0,0)) pathDoorRight.addControlPoint(1, pos=(0,1.4,5),euler=(10,0,0)) pathDoorRight.addControlPoint(2, pos=(1.3,1.4,10),euler=(10,0,0)) pathDoorRightDuration = pathDoorRight.getDuration() def mazeTrial(): global link, view, pathMaze1, pathDoorLeft, pathDoorRight, startPos print 'NEW TRIAL' maze1.visible(viz.ON) pathMaze1.reset() link = viz.link(pathMaze1, view) view.reset(viz.HEAD_POS| viz.HEAD_ORI) view.setPosition(startPos) pathMaze1.play() yield viztask.waitTime(pathMaze1Duration) link.remove() yield viztask.waitKeyDown([viz.KEY_LEFT,viz.KEY_RIGHT]) if viz.key.isDown(viz.KEY_LEFT): print "LEFT DOOR" link = viz.link(pathDoorLeft,view) pathDoorLeft.play() yield viztask.waitTime(pathDoorLeftDuration) pathDoorLeft.reset() link.remove() elif viz.key.isDown(viz.KEY_RIGHT): print "RIGHT DOOR" link = viz.link(pathDoorRight,view) pathDoorRight.play() yield viztask.waitTime(pathDoorRightDuration) pathDoorRight.reset() link.remove() # Loop trial 4 times def masterFunction(): for x in range(4): yield mazeTrial() #Schedule & trigger Loop viztask.schedule(masterFunction()) # For control purposes, prints position of View and Maze every 2 sec def Print_view_pos(): global view, pathMaze1 print "View :", view.getPosition() print "Maze1 :", pathMaze1.getPosition() vizact.ontimer(2,Print_view_pos) |
Thread Tools | |
Display Modes | Rate This Thread |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
problem with path animation | jelly | Vizard | 5 | 04-20-2016 06:15 AM |
Road Animation Path | vserchi | Vizard | 4 | 11-12-2015 09:29 AM |
Problems with interaction of vizact.turn and animation path | Enlil | Vizard | 3 | 11-24-2008 04:23 PM |
speed on animation path | whj | Vizard | 8 | 11-17-2008 07:41 PM |
another bezier animation problem | masaki | Vizard | 1 | 01-24-2008 02:29 PM |