Links und Funktionen
Sprachumschaltung

Navigationspfad


Inhaltsbereich

auto1

car.py — text/python-source, 6 KB (6201 bytes)

Dateiinhalt

from visual import *
from threading import*
from math import *

# Szene-Einstellungen
scene.userzoom = True           # User darf zoomen?
scene.userspin = True           # User darf rotieren?
scene.forward = (-1,-1,-1)      # Kameraposition
scene.autoscale = True          # Autoskalierung aktiv?
scene.range = 150               # Kameraabstand von scene.center
scene.center = (0,0,0)          # Kamerablickpunkt: norm. (0,0,0)
scene.up = (0,1,0)              # Rotationsachse Kamera: norm. (0,1,0)
scene.background = color.white  # Hintergrundfarbe
scene.fov = 2                   # Kamerawinkeloeffnung: norm. 1
scene.fullscreen = True       # Vollbild? norm. False
scene.title = "Koordinaten"     # Fenstertitel
scene.width = 500               # Fensterbreite: norm. 200
scene.height = 500              # Fensterhoehe: norm 200
scene.x = 50                    # x-Koordinate d. Fensters: norm. 0
scene.y = 25                    # y-Koordinate d. Fensters: norm. 0


class Car(frame,Thread):
    def __init__(self,pos=(0,0,0)):
        frame.__init__(self, pos=pos)
        Thread.__init__(self)
        self.unterboden=box(pos=(-18,0,0), length=(60), height=(1), width=(26),color=(0.3,0.3,0.3),frame=self)

        self.reifen1=ring(pos=(-36,0,-15),thickness=(2),radius=(5),axis=(0,0,1),color=(0.3,0.3,0.3),frame=self)
        self.reifen2=ring(pos=(0,0,-15),thickness=(2),radius=(5),axis=(0,0,1),color=(0.3,0.3,0.3),frame=self)
        self.reifen3=ring(pos=(-36,0,15),thickness=(2),radius=(5),axis=(0,0,1),color=(0.3,0.3,0.3),frame=self)
        self.reifen4=ring(pos=(0,0,15),thickness=(2),radius=(5),axis=(0,0,1),color=(0.3,0.3,0.3),frame=self)

        self.felge1=cylinder(pos=(-36,0,-15),radius=(5),length=(1),axis=(0,0,1),frame=self)
        self.felge1=cylinder(pos=(0,0,-15),radius=(5),length=(1),axis=(0,0,1),frame=self)
        self.felge1=cylinder(pos=(-36,0,15),radius=(5),length=(1),axis=(0,0,1),frame=self)
        self.felge1=cylinder(pos=(0,0,15),radius=(5),length=(1),axis=(0,0,1),frame=self)

        self.front=box(pos=(-52,3,0),size=(10,1,26),axis=(-1.3,1,0),color=(1,0.84,0),frame=self)
        self.front2=box(pos=(-56,8.5,0),size=(5,1,26),axis=(0,1,0),color=(1,0.84,0),frame=self)
        self.haube=box(pos=(-41.5,12.5,0),size=(30,1,26),axis=(1,0.1,0),color=(1,0.84,0),frame=self)
        self.scheibe=box(pos=(-26,18,0),size=(7,1,26),axis=(0.3,1,0),opacity=(0.5),frame=self)
        self.dach=box(pos=(-18,21,0),size=(15,1,26),axis=(1,0,0),color=(1,0.84,0),frame=self)
        self.dach2=box(pos=(-4,19,0),size=(15,1,26),axis=(1,-0.3,0),color=(1,0.84,0),frame=self)
        self.heck=box(pos=(12,3,0),size=(7,1,26),axis=(0.2,1,0),color=(1,0.84,0),frame=self)
        self.dach3=box(pos=(8,15,0),size=(10,1,26),axis=(1,-0.4,0),color=(1,0.84,0),frame=self)
        self.heck2=box(pos=(13,10,0),size=(7,1,26),axis=(0,1,0),color=(1,0.84,0),frame=self)
        self.spoiler=box(pos=(16,13,00),size=(7,1,26),axis=(1,0.3,0),color=(1,0.84,0),frame=self)
        self.spoiler2=box(pos=(16,14,0),size=(7,1,26),axis=(1,0.2,0),color=(1,0.84,0),frame=self)

        seite1=frame(frame=self)
        seitenwand=Polygon([(0,0),(-8,6),(-8,11),(22,14),(37,14),(39,20),(53,16),(60,14),(61,12),(61,5),(60,0) ])
        straight = [(0,0,0),(0,0,-1)]
        self.wand=extrusion(pos=straight, shape=seitenwand,
                  color=(1,0.84,0),frame=seite1) 
        seite1.pos=(-48,0,-12)

        seite2=frame(frame=self)
        seitenwand=Polygon([(0,0),(-8,6),(-8,11),(22,14),(37,14),(39,20),(53,16),(60,14),(61,12),(61,5),(60,0) ])
        straight = [(0,0,0),(0,0,-1)]
        self.wand2=extrusion(pos=straight, shape=seitenwand,
                 color=(1,0.84,0),frame=seite2) 
        seite2.pos=(-48,0,13)

        self.birne=sphere(pos=(-53,12,-9),radius=2,material=materials.emissive,frame=self)
        self.licht=sphere(pos=(-52,12,-9),radius=2.4,color=(1,0.84,0),frame=self)
        self.birne2=sphere(pos=(-53,12,9),radius=2,material=materials.emissive,frame=self)
        self.licht2=sphere(pos=(-52,12,9),radius=2.4,color=(1,0.84,0),frame=self)

        self.kuehler=box(pos=(-56.4,8.5,0),color=(0,0,0),axis=(0,1,0),frame=self,size=(0.2,0.3,20))
        self.kuehler=box(pos=(-56.4,9,0),color=(0,0,0),axis=(0,1,0),frame=self,size=(0.2,0.3,20))
        self.kuehler=box(pos=(-56.4,9.5,0),color=(0,0,0),axis=(0,1,0),frame=self,size=(0.2,0.3,20))
        self.kuehler=box(pos=(-56.4,10,0),color=(0,0,0),axis=(0,1,0),frame=self,size=(0.2,0.3,20))
        self.kuehler=box(pos=(-56.4,8,0),color=(0,0,0),axis=(0,1,0),frame=self,size=(0.2,0.3,20))
        self.kuehler=box(pos=(-56.4,7.5,0),color=(0,0,0),axis=(0,1,0),frame=self,size=(0.2,0.3,20))

        self.licht=sphere(pos=(12.5,1,-10),radius=0.5,color=(0.7,0,0),material=materials.emissive,frame=self)
        self.licht=sphere(pos=(12.5,1,10),radius=0.5,color=(0.7,0,0),material=materials.emissive,frame=self)   
        
if __name__ == "__main__":
    car=Car()
    
    v=(0,0,0)
    vs=0
    left=0
    right=0  
    while True:
        rate(50)
        print vs 
        if vs>=0.001:
            if scene.kb.keys:
                skk = scene.kb.getkey()
                if skk=='up':
                    vs=vs+0.3
                elif skk=='down':
                    vs=vs-0.3
                
                elif skk=='right':
                        car.axis=car.axis.rotate(angle=-pi/32,axis=(0,1,0))


                        
                elif skk=='left':

                        car.axis=car.axis.rotate(angle=pi/32,axis=(0,1,0))


                                               
            v=-vs*car.axis
               
            car.pos=car.pos+v   
        else:
            if scene.kb.keys:
                skk = scene.kb.getkey()
                if skk=='up':
                    vs=vs+0.3
                elif skk=='down':
                    vs=vs-0.3
                elif skk=='right':
                        car.axis=car.axis.rotate(angle=-pi/32,axis=(0,1,0))


                        
                elif skk=='left':

                        car.axis=car.axis.rotate(angle=pi/32,axis=(0,1,0))
                print vs
            v=-vs*car.axis
            car.pos=car.pos+v
        

Funktionsleiste