WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Moving view with object (https://forum.worldviz.com/showthread.php?t=382)

Xliben 07-21-2005 04:53 PM

Moving view with object
 
Ok, this is probably going to sound REALLY dumb so excuse me but I am new to Vizard.

What I would like to is make it so when I have a Wheelbarrow move the camera stays behind it at a specified distance. I currently only have the Wheelbarrow moving (and that doesn't even completely work seeing as when I move forward or backwards meanwhile turning the object slows down and goes for twice the time it should); anyway, I have tried nearly everything I could find but nothing seems to work so... heres what I have... it doesn't work at all so any assistance what so ever would be soooooooooo helpful.

BTW to anyone who cares this is going to be used for a game prototype so any additional information would be much appreciated.

Most of the script below has been derived from tutorials within the trial version. Thanks

import viz
viz.go()

viz.mouse(viz.OFF)

viz.add('tut_ground.wrl')
Wheelbarrow = viz.add('wheelbarrow.ive')

UPDATE_RATE = 0.001

view = viz.add(viz.VIEWPOINT)

Wheelbarrow.translate(0,0,6)

MOVE_SPEED = 10
TURN_SPEED = 360

MOVE_FORWARD = vizact.move(0,0,MOVE_SPEED,.01)
MOVE_BACKWARD = vizact.move(0,0,-MOVE_SPEED,.01)

TURN_RIGHT = vizact.spin(0,1,0,TURN_SPEED,.01)
TURN_LEFT = vizact.spin(0,-1,0,TURN_SPEED,.01)

def mytimer (num1):
if viz.iskeydown(viz.KEY_UP):
Wheelbarrow.add(MOVE_FORWARD)
elif viz.iskeydown(viz.KEY_DOWN):
Wheelbarrow.add(MOVE_BACKWARD)
elif viz.iskeydown(viz.KEY_RIGHT):
Wheelbarrow.add(TURN_RIGHT)
elif viz.iskeydown(viz.KEY_LEFT):
Wheelbarrow.add(TURN_LEFT)
viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(1,0.01,viz.PERPETUAL)

def updateview(num1):
POS = Wheelbarrow.get(viz.POSITION)
view.goto([viz.get(Wheelbarrow.get(viz.POSITION))],5,5)

farshizzo 07-25-2005 12:15 PM

Hi,

I've modified your script a little to do what I believe you want it to do. I've commented the parts of the code that modify the viewpoint. Let me know if this isn't exactly what you are looking for.
Code:

import viz
viz.go()

viz.mouse(viz.OFF)

viz.add('tut_ground.wrl')
Wheelbarrow = viz.add('wheelbarrow.ive')

#Get handle to main viewpoint
view = viz.get(viz.MAIN_VIEWPOINT)

Wheelbarrow.translate(0,0,6)

MOVE_SPEED = 10
TURN_SPEED = 360

def mytimer(num1):
        #Move wheelbarrow using arrow keys
        if viz.iskeydown(viz.KEY_UP):
                Wheelbarrow.translate(0,0,MOVE_SPEED*viz.elapsed(),viz.RELATIVE_LOCAL)
        elif viz.iskeydown(viz.KEY_DOWN):
                Wheelbarrow.translate(0,0,-MOVE_SPEED*viz.elapsed(),viz.RELATIVE_LOCAL)
        if viz.iskeydown(viz.KEY_RIGHT):
                Wheelbarrow.rotate(0,1,0,TURN_SPEED*viz.elapsed(),viz.RELATIVE_LOCAL)
        elif viz.iskeydown(viz.KEY_LEFT):
                Wheelbarrow.rotate(0,1,0,-TURN_SPEED*viz.elapsed(),viz.RELATIVE_LOCAL)

        #Create transform from wheelbarrow
        xform = viz.Transform(Wheelbarrow.get(viz.MATRIX))
        #Move position up 1 meter and back 5 meters
        xform.preTrans(0,1,-5)
        #Apply position of transform to viewpoint
        view.translate(xform.getTrans())
        #Have viewpoint look at wheelbarrow
        view.lookat(Wheelbarrow.get(viz.POSITION))
       
viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(1,0,viz.PERPETUAL)


Xliben 07-25-2005 05:36 PM

Thanks a million it looks great!


All times are GMT -7. The time now is 10:34 AM.

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