Links und Funktionen
Sprachumschaltung

Navigationspfad
Sie sind hier: Startseite / Probestudium / 2014 / WS I: 3D-Programmierung / Skripte (neu) / 2-fensterrundgang-artificial-city.py


Inhaltsbereich

2-fensterrundgang-artificial-city.py

Python Source icon 2-fensterrundgang-artificial-city.py — Python Source, 3 KB (3970 bytes)

Dateiinhalt

# -*- 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 = 320              # Fensterhöhe
scene.width = 700               # 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 = 30                # 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))

# Häuser durch Zufall generieren
for i in range(haus_anzahl): 
    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),1,1)))
text(pos=(0, 20, -50), string="ARTIFICIAL CITY", color=color.orange, depth=1, height=5, justify="center") #Schriftzug

rhairs = 0.025 # half-length of crosshairs
dhairs = 2 # how far away the crosshairs are
maxcosine = dhairs/sqrt(rhairs**2+dhairs**2) # if ray inside crosshairs, don't move
haircolor = color.black
#walker1 = sphere(radius=2, color=color.white, pos=scene.center, material=materials.emissive)

#-Zweitfenster für topview---
zweitfenster = display(width=300,height=320, title="TOP-VIEW",\
                       center=(0,5,0), forward=(0,-5,0), x=700, 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=2, color=color.white, pos=scene.center, material=materials.emissive)
walker.trail = curve(color=color.yellow)    

while True:
    rate(50) 

    # scene.center und scene.forward werden mausabhängig angepasst
    ray = scene.mouse.ray
    if abs(dot(ray,scene.forward)) < maxcosine: # tu was, falls außerhalb des Fadenkreuzes
        newray = norm(vector(ray.x, ray.y, ray.z))
        angle = arcsin(dot(cross(scene.forward,newray),scene.up))
        newforward = rotate(scene.forward, axis=scene.up, angle=angle/50)
        scene.center = scene.mouse.camera+newforward*mag(scene.center-scene.mouse.camera)
        scene.forward = newforward
        scene.center = scene.center+scene.forward*ray.y/2.
        #walker1.pos = scene.pos
        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\
            *mag(scene.center-scene.mouse.camera)
        elif s == 'down':   # rückwärts
            scene.center = scene.center-scene.forward\
            *mag(scene.center-scene.mouse.camera)
        elif s == 'ctrl+up':   # links drehen
            newforward = rotate(scene.forward, axis=scene.up, angle=radians(2))
            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 == 'alt+up':  # rechts drehen
            newforward = rotate(scene.forward, axis=scene.up, angle=radians(-2))
            scene.center = scene.mouse.camera+newforward\
            *mag(scene.center-scene.mouse.camera)
            scene.forward = newforward


Funktionsleiste