# -*- coding: utf-8 -*-
# Teststadt für Rundgang
# 2010-03-08

from visual import *
from visual.text import *
from random import *


scene.title = "ARTIFICIAL CITY" # Fenstertitel
scene.x = 0	                    # Fensterpos v. links
scene.y = 0	                    # Fensterpos v. oben
scene.height = 600              # Fensterhöhe
scene.width = 1000              # Fensterbreite
scene.range = (1,1,1)           # Abstand
scene.center = (0,5,50)         # Festlegung Blickziel
scene.userspin = False          # Blickwechsel abgeschaltet
scene.userzoom = False          # Benutzerzoom abgeschaltet
scene.fov = 2                   # Kamerawinkel
scene.background = (0.8,0.85,1) # Farbe Hintergrund
scene.stereodepth = 2           # Stereotiefe
scene.show_rendertime = True    # Anzeige der Berechnungszeiten
scene.fullscreen = False        # Vollbildmodus
haus_anzahl = 40                # Konstante: Anzahl der Häuser

# graue Bodenplatte
floor = box(pos=(0,0,0), width=120, height=1, length=120, color=(0.4,0.4,0.4), material=materials.wood)
for i in range(haus_anzahl): # Häuser durch Zufall generieren
    zufall = random()
    box(pos=(random()*100-50, (10+zufall*5)/2,random()*100-50),\
        width=5+random()*5, height=10+zufall*5, length=7+random()*3, \
        color=color.hsv_to_rgb(((float(i)/haus_anzahl),.8,.4)), material = materials.marble)
text(pos=(0, 20, -50), string="WEIMAR", color=(.9,.9,0), depth=1, height=5, justify="center") #Schriftzug


#auge
auge = frame()
kugel = sphere(pos=(1,2,1), radius=5, material=materials.plastic, frame=auge)
iris = sphere(pos=(1,2,2.7), radius=3.5, material=materials.wood, color=(0,0.5,6), frame=auge)
pupille = sphere(pos=(1,2,3.8), radius = 2.5, material=materials.plastic,color=(0,0,0), frame=auge)


#-Zweitfenster für topview---
zweitfenster = display(width=400,height=430, title="TOP-VIEW",\
                       center=(0,5,0), forward=(0,-5,0), x=1000, y=0,\
                       background=(0.8,0.85,1))
zweitfenster.range = 75
zweitfenster.select()
for obj in scene.objects:
    try:
        obj.__copy__(display=zweitfenster).opacity=0.5
    except:
        pass
walker = sphere(radius=1.5, color=color.white, pos=scene.center, material=materials.emissive)
walker.trail = curve(color=color.yellow)

while True:
    rate(50)

    
    zweitfenster.select()
    walker.pos = scene.center
    walker.trail.append(pos=walker.pos, retain=5000)
    
    

    # Falls Tastatur gedrückt...
    if scene.kb.keys:
        s = scene.kb.getkey()
        print s
        
        if   s == 'up':     # vorwärts
            scene.center = scene.center+scene.forward*.6*mag(scene.center-scene.mouse.camera)
        elif s == 'down':   # rückwärts
            scene.center = scene.center-scene.forward*.6*mag(scene.center-scene.mouse.camera)
        
        elif s == 'left':   # links drehen
            newforward = rotate(scene.forward, axis=scene.up, angle=radians(4))
            scene.center = scene.mouse.camera+newforward*mag(scene.center-scene.mouse.camera)
            scene.forward = newforward
            #scene.center = scene.center+scene.forward*ray.y/2.
        elif s == 'right':  # rechts drehen
            newforward = rotate(scene.forward, axis=scene.up, angle=radians(-4))
            scene.center = scene.mouse.camera+newforward*mag(scene.center-scene.mouse.camera)
            scene.forward = newforward

