Speedracer

From GeoMod

Jump to: navigation, search
from visual import *
class speedracer:
   def __init__ (self, pos, scale=1):
       self.pos= pos
       #pos=(0,0,0)
       self.scale= scale
       self.name = "oldtimer"
       self.body = frame(pos=pos)
       #framepos =pos.z*scale+2.0
       chassis = box(frame=self.body, length=5*scale, height=1*scale, width=3*scale, color=color.white)
       self.wheelLF = sphere(frame=self.body, radius=0.75, color=color.blue, pos=(-1.25*scale,-1.2*scale,1.5*scale))
       self.hubLF = sphere(frame=self.body, radius=0.5, color=color.red, pos=(-1.25*scale,-1.2*scale,2*scale))
       self.wheelLB = sphere(frame=self.body, radius=0.75, color=color.blue, pos=(1.25*scale,-1.2*scale,1.5*scale))
       self.hubLB = sphere(frame=self.body, radius=0.5, color=color.red, pos=(1.25*scale,-1.2*scale,2*scale))
       self.wheelRF = sphere(frame=self.body, radius=0.75, color=color.blue, pos=(-1.25*scale,-1.2*scale,-1.5*scale))
       self.hubRF = sphere(frame=self.body, radius=0.5, color=color.red, pos=(-1.25*scale,-1.2*scale,-.5*scale))
       self.wheelRB = sphere(frame=self.body, radius=0.75, color=color.blue, pos=(1.25*scale,-1.2*scale,-1.5*scale))
       self.hubRB = sphere(frame=self.body, radius=0.75, color=color.red, pos=(1.25*scale,-1.2*scale,-.5*scale))
       self.doorLF = box(frame=self.body, length=1, height=.5, width=0.1, color=color.orange, pos=(-1*scale,0*scale,1.5*scale))
       self.doorLB = box(frame=self.body, length=1, height=.5, width=0.1, color=color.orange, pos=(1*scale,0*scale,1.5*scale))
       self.doorRF = box(frame=self.body, length=1, height=.5, width=0.1, color=color.orange, pos=(-1*scale,0*scale,-1.5*scale))
       self.doorLF = box(frame=self.body, length=1, height=.5, width=0.1, color=color.orange, pos=(1*scale,0*scale,-1.5*scale))
       self.helmet = box(frame=self.body, length=.5, height=.5, width=2, color=color.green, pos=(-3*scale,-0.25*scale,0*scale))

      
   def movcar(self,newpos):
       print "moving"     
       while 1:
           rate(2)
           self.body.x = self.body.x - newpos
   def move(self, new_pos):		#REQUIRED
       self.pos = new_pos		#REQUIRED
       self.body.pos = new_pos	#REQUIRED
       #self.speedracer.pos =new_pos  
   def choose_direction(self, local_topo, target_x, target_z, target_dir, dx, max_slope=1): #REQUIRED
        '''local_topo is a 3x3 array of topogarphy data of the area around the car
           target_dir is a vector with the direction of the target relative to the car
              eg: vector(1,0,0) is the x direction (East)
                  vector(0,0,-1) is the negative z direction (North)
                  vector(1,0,-1) is 45 degrees east of due north
           RETURNS a vector indicating which direction you want your car to go'''
        print "taret_dir", #target_dir    #define directions
        North = vector(0,1,0)
        South = vector(0,-1,0)
        East = vector(1,0,0)
        West = vector(-1,0,0)
      
        slope1 = (local_topo[0,1] - local_topo[1,1]) / dx
        slope2 = (local_topo[2,1] - local_topo[1,1]) / dx
        slope3 = (local_topo[1,2] - local_topo[1,1]) / dx
        slope4 = (local_topo[1,0] - local_topo[1,1]) / dx
         
        if slope1 < (slope2, slope3, slope4):
            min_slope = North
        if slope2 < (slope1, slope3, slope4):
            min_slope = West
        if slope3 < (slope2, slope1):
            min_slope = East
        if slope3 < slope4:
            min_slope = target_dir
        if slope4 < (slope2, slope1, slope3):
            min_slope = target_dir
        if slope1 == (slope2, slope3, slope4):
            min_slope = target_dir 
        choose_direction = min_slope
        return choose_direction
Personal tools