#Stepspeed rev4 is the first revision to use the CPP server instead of TMM to get data from Nexus
#wda 1/21/2015

import socket
import sys
import io
import re
#from xml.etree import ElementTree
import xml.etree.cElementTree as ElementTree
import viz
import threading
import Queue
import time
viz.splashScreen('C:\Users\Gelsey Torres-Oviedo\Desktop\VizardFolderVRServer\Logo_final.jpg')
viz.go(
viz.FULLSCREEN
)

#setup the VR space with objects
global targetL
targetL = 0.5

global targetR
targetR = 0.5

global targettol
targettol = 0.05
'''
global boxL
boxL = viz.addChild('target.obj',color=(0.063,0.102,0.898),scale=[0.1,targettol*0.5,0.0125])
boxL.setPosition([-0.2,(targetL-targettol),0])
import itertools
import socket
import sys
import io
import re
#from xml.etree import ElementTree
import xml.etree.cElementTree as ElementTree
import threading
import Queue
import time
import json
import vizact
import struct
import array
viz.splashScreen(
    'C:\Users\Gelsey Torres-Oviedo\Desktop\VizardFolderVRServer\Logo_final.jpg'
)
viz.go(viz.FULLSCREEN  #run world in full screen
       )
time.sleep(1)  #show off our cool logo, not really required but cool
#set target tolerance for stride length

global targetL
targetL = 0.414

global targetR
targetR = 0.414

global targettol
targettol = 0.025
car = viz.addChild("mini.osg", parent=offsetNode)  #load car model here
car.setPosition(0.3, -1.1, 0.2)
viz.setMultiSample(4)
NUM_CARS = 0
carlist = []
pivot = [0, 0, 0]
carchoice = 1
currentcar = 'Mini'
speed = 0.0
steer = 0.0
motion = 0
rotateY = 0.0
rotateX = 0.0
viz.clip(0.1, 30000)
vizconnect.go('camera.py')
viz.splashScreen('assets/tracksplash.jpg')
viz.phys.enable()
#carchoiceinit = vizinput.choose('Choose a car:', ['Mini','BMW','Ford Thunderbird','Ford Focus','Lamborghini Murcielago','TVR Speed 12','Dodge Challenger', 'Caterham Seven'])
#carchoice = carchoiceinit + 1
environmentchoice = vizinput.choose('Select time of day:', ['Day', 'Night'])
viz.message(
    'Arrow Keys to steer. Z to go down a gear, X to go up a gear. G to swap between automatic/manual. Up to accelerate, Down to reverse (Automatic only). Spacebar to brake.'
)
#import Drivingfunctions
track = viz.addChild('assets/environment/track.osgb')
station = viz.addChild('assets/environment/gasStation.fbx')
#buildings = viz.addChild('assets/environment/City.osgb')
tower = viz.addChild('assets/environment/Building.fbx')
if environmentchoice == 0:
    environment = viz.addChild('sky_day.osgb')
else: