WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   A problem with cave (https://forum.worldviz.com/showthread.php?t=4857)

apmx 10-28-2013 04:37 AM

A problem with cave
 
Hello,I am doing a project about car simulation,but I don't know how to link the cave view point with the car,the result should be more like sitting in the car and if the car is moving the view point should follow.

Here is my code:
Code:

import cavelib2
import math
import viz
import vizact
import random
import vizshape
import vizcave
import viztracker

hangle=0
vangle=0

#Param: True = DesktopMode on
#                False = DesktopMode off

print "Initializing CaveLib"
cave = cavelib2.CaveLib(True)

import vizshape

#wiimote update code

#Speed for the wiimote movement
MOVE_SPEED = 1

#Initial values of camera angles
hangle = 0
vangle = 0

#object id's that are ignored with raycasting


drawing  = None

print "Adding a model"
#position camera in startingposition
cave_origin=cave.getOriginTracker().setPosition(0,3,0)
#cave.caveorigin.setPosition(0,2,0)
#cave.caveorigin.setEuler(90,0,0)

#adding the models
world = viz.add('road1002.OSGB')
world.setPosition(0,0,0)
world.enable(viz.LIGHTING)

truck = viz.add('truck1005.OSGB')
truck.setPosition(1,2,-8)







def WiiMove():
        global hangle
        global vangle
       
        elapsed = viz.elapsed()        #the amount of time elapsed
       
        state = cave.wiimote.getState()
       
        #process buttons
        if state & cave.wiimote.BUTTON_LEFT:
                #cave.caveorigin.setPosition([-MOVE_SPEED*elapsed,0,0],viz.REL_LOCAL)
                sun.setPosition([-MOVE_SPEED*elapsed,0,0],viz.REL_LOCAL)
               
        if state & cave.wiimote.BUTTON_RIGHT:
                #cave.caveorigin.setPosition([MOVE_SPEED*elapsed,0,0],viz.REL_LOCAL)
                sun.setPosition([MOVE_SPEED*elapsed,0,0],viz.REL_LOCAL)
               
        if state & cave.wiimote.BUTTON_UP:
                #cave.caveorigin.setPosition([0,0,MOVE_SPEED*elapsed],viz.REL_LOCAL)
                sun.setPosition([0,MOVE_SPEED*elapsed,0],viz.REL_LOCAL)
               
        if state & cave.wiimote.BUTTON_DOWN:
                #cave.caveorigin.setPosition([0,0,-MOVE_SPEED*elapsed],viz.REL_LOCAL)
                sun.setPosition([0,-MOVE_SPEED*elapsed,0],viz.REL_LOCAL)
               
        if state & cave.wiimote.BUTTON_1:
                cave.caveorigin.setPosition([0,-.001,0],viz.REL_LOCAL)
        if state & cave.wiimote.BUTTON_2:
                cave.caveorigin.setPosition([0,.001,0],viz.REL_LOCAL)
       
        hangle = hangle + 90 * cave.wiimote.getJoystick()[0] * elapsed
        cave.caveorigin.setEuler([hangle,vangle,0])       
       
#Set input function               
vizact.ontimer(0, WiiMove)

#onUpdate callback function
def onUpdate(e):
        cave.getWandPosition()
        cave.getWandQuat()
        cave.getWandMatrix()
               
viz.callback(viz.UPDATE_EVENT,onUpdate)


print "Setting the headlight"

#Get a handle to the main headlight and disable it


print "Setting the antialiasing factor"

viz.setMultiSample(4)

print "Start the simulation"

cave.go()



All times are GMT -7. The time now is 04:18 AM.

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