WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Object animation using a picture? (https://forum.worldviz.com/showthread.php?t=1202)

Elittdogg 09-06-2007 09:44 AM

Object animation using a picture?
 
I need to animate a picture such that it moves forward a bit and backward a bit. Kind of like a moving room. I'm having trouble; here's what I've got:

import viz

tex1 = viz.add('picture.jpg')
quad = viz.add(viz.TEXQUAD)
quad.translate(0,1,12)
quad.scale(12.8, 10.24)
quad.texture(tex1)

moveForward = vizact.move(0,0,2,5)
moveBackward = vizact.move(0,0,-2,5)
#tex1.add(moveForward)
#tex1.add(moveBackward)
MovingRoom = vizact.sequence(moveForward,moveBackward,4)


def onkeydown(key):
if key == ' ':
tex1.add(MovingRoom)

viz.callback(viz.KEYDOWN_EVENT,onkeydown)

But when I run the script I get this error message:
Traceback (most recent call last):
File "Moving Room 3.py", line 25, in onkeydown
tex1.add(MovingRoom)
AttributeError: VizTexture instance has no attribute 'add'

Which, I guess, makes sense to me. But I wondering if there is a way around this. Like, how can I make it such that the picture moves forward X distance for Y duration and then backward X distance for Y duration...etc (i.e. put that in a loop/timer). Namely, I'd like the picture to keep moving forward and backward the entire time the script is running.

Thanks for the help.

farshizzo 09-06-2007 10:37 AM

You almost had it. You need to add the MovingRoom action to the quad, not the texture. Your code should look something like this:
Code:

import viz
viz.go()

tex1 = viz.add('picture.jpg')
quad = viz.add(viz.TEXQUAD)
quad.translate(0,1,12)
quad.scale(12.8, 10.24)
quad.texture(tex1)

moveForward = vizact.move(0,0,2,5)
moveBackward = vizact.move(0,0,-2,5)
MovingRoom = vizact.sequence(moveForward,moveBackward,4)


def onkeydown(key):
        if key == ' ':
                quad.add(MovingRoom)

viz.callback(viz.KEYDOWN_EVENT,onkeydown)


Elittdogg 09-10-2007 08:12 AM

Thank you for your help. It makes so much sense in retrospect.


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

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