Links und Funktionen
Sprachumschaltung

Navigationspfad
Sie sind hier: Startseite / Probestudium / 2011 / WS I: 3D-Programmierung / Arbeitsgruppen / Kaptludo (Fangenspiel) / kaptludoWorldWithBallWithoutCollisionTest


Inhaltsbereich

kaptludoWorldWithBallWithoutCollisionTest

Die Welt mit Ball und Kamera und Bewegung, aber ohne Kollisionscheck.

kaptludoWorldWithBallWithoutCollisionTest.py — text/python-source, 6 KB (6331 bytes)

Dateiinhalt

# -*- coding: utf-8 -*-


from visual import *
from random import*


scene.x = 0	                    # Fensterpos v. links
scene.y = 0	                    # Fensterpos v. oben
scene.height =1000           # Fensterhöhe
scene.width = 1920               # Fensterbreite
scene.range = (3,3,3)           # Abstand
scene.center = (0,1,0)         # Festlegung Blickziel
scene.userspin = False          # Blickwechsel abgeschaltet
scene.userzoom = False         # Benutzerzoom abgeschaltet
scene.fov = 2                   # Kamerawinkel


colors=[color.yellow,color.magenta,color.green,color.orange,color.white,color.blue,color.cyan,color.red]
ground = box(pos=(50,-1,50), length=100, height=1, width=100, material=materials.rough)
landscape = box(pos=(50,-0.5,50), length=101, height=30, width=101, material=materials.earth, opacity=0)

class house():    #class house
    def __init__(self, px, pz, pLength, pWidth, pcolor=color.cyan, popacity=1):                            #__init__
        a = box(pos=(px, 4.5, pz), length=pLength, height=10, width=pWidth, color=pcolor, opacity=popacity)
        b = curve(pos=[(px+0.5*pLength,0,pz+0.5*pWidth),(px-0.5*pLength,0,pz+0.5*pWidth),(px-0.5*pLength,0,pz-0.5*pWidth),(px+0.5*pLength,0,pz-0.5*pWidth),(px+0.5*pLength,0,pz+0.5*pWidth)])

#outer walls
wall1=house(50,0.5,100,1,colors[randint(0,7)])
wall2=house(50,99.5,100,1,colors[randint(0,7)])
wall3=house(0.5,50,1,100,colors[randint(0,7)])
wall4=house(99.5,50,1,100,colors[randint(0,7)])

#inner cross
house1=house(25,50,40,1,colors[randint(0,7)])
house2=house(75,50,40,1,colors[randint(0,7)])
house3=house(50,25,1,40,colors[randint(0,7)])
house4=house(50,75,1,40,colors[randint(0,7)])

#central walls
house5=house(43.25,40,7.5,1,colors[randint(0,7)])
house6=house(56.75,40,7.5,1,colors[randint(0,7)])
house7=house(43.25,60,7.5,1,colors[randint(0,7)])
house8=house(56.75,60,7.5,1,colors[randint(0,7)])
house9=house(40,43.25,1,7.5,colors[randint(0,7)])
house10=house(60,43.25,1,7.5,colors[randint(0,7)])
house11=house(40,56.75,1,7.5,colors[randint(0,7)])
house12=house(60,56.75,1,7.5,colors[randint(0,7)])

#sector I
bubble1 = sphere(pos=(65,1,15), radius=5, color = colors[randint(0,7)])
bubble2 = sphere(pos=(75,-2,23), radius=7, color = colors[randint(0,7)])
bubble3 = sphere(pos=(80,4.5,35), radius=5, color = colors[randint(0,7)])
bubble4 = sphere(pos=(90,1,5), radius=6, color = colors[randint(0,7)])
bubble5 = sphere(pos=(70,5.5,44), radius=6, color = colors[randint(0,7)])
bubble6 = sphere(pos=(60,5,29), radius=5, color = colors[randint(0,7)])
bubble7 = sphere(pos=(90,3,23), radius=5, color = colors[randint(0,7)])
bubble8 = sphere(pos=(95,5,37), radius=7, color = colors[randint(0,7)])


#sector II
dice1=house(34.5,47,6,6,colors[randint(0,7)])
dice2=house(29.5,42,6,6,colors[randint(0,7)])
dice3=house(40,34,6,6,colors[randint(0,7)])
dice4=house(47,25,6,6,colors[randint(0,7)])
dice5=house(42,15,6,6,colors[randint(0,7)])
dice6=house(37,10,6,6,colors[randint(0,7)])
dice7=house(34,25,6,6,colors[randint(0,7)])
dice8=house(29,30,6,6,colors[randint(0,7)])
dice9=house(25,15,6,6,colors[randint(0,7)])
dice10=house(20,12,6,6,colors[randint(0,7)])
dice11=house(15,17,6,6,colors[randint(0,7)])
dice12=house(11,9,6,6,colors[randint(0,7)])
dice13=house(11,29,6,6,colors[randint(0,7)])
dice14=house(16,34,6,6,colors[randint(0,7)])
dice15=house(11,39,6,6,colors[randint(0,7)])

#sector III
walllab1=house(10,54,1,8,colors[randint(0,7)])
walllab2=house(8,62,16,1,colors[randint(0,7)])
walllab3=house(16,58.5,1,8,colors[randint(0,7)])
walllab4=house(5,80,10,1,colors[randint(0,7)])
walllab5=house(10,80,1,20,colors[randint(0,7)])
walllab6=house(8,90,5,1,colors[randint(0,7)])
walllab7=house(10,70,10,1,colors[randint(0,7)])
walllab8=house(30,60,1,20,colors[randint(0,7)])
walllab9=house(28,70,5,1,colors[randint(0,7)])
walllab10=house(26,68,1,4,colors[randint(0,7)])
walllab11=house(26,92,1,16,colors[randint(0,7)])
walllab12=house(34,84,17,1,colors[randint(0,7)])
walllab13=house(42,89,1,10,colors[randint(0,7)])
walllab14=house(40.5,94,4,1,colors[randint(0,7)])
walllab15=house(45,70,10,1,colors[randint(0,7)])
walllab16=house(40,70,1,12,colors[randint(0,7)])

#sector IV
walllab1=house(60,90,1,20,colors[randint(0,7)],0.2)
walllab2=house(90,60,20,1,colors[randint(0,7)],0.2)
walllab3=house(60,80,10,1,colors[randint(0,7)],0.2)
walllab4=house(80,60,1,10,colors[randint(0,7)],0.2)
walllab5=house(80,90,20,1,colors[randint(0,7)],0.2)
walllab6=house(90,80,1,20,colors[randint(0,7)],0.2)
walllab7=house(70,75,1,11,colors[randint(0,7)],0.2)
walllab8=house(75,70,11,1,colors[randint(0,7)],0.2)

#main base circle
base =cylinder(pos=(50,-0.5,50), axis=(0,0.11,0), radius=0.5, material=materials.emissive, color=color.red, opacity=0.3)
baseLamp = local_light(pos=(50,2,50), color=color.red)

#sector lights
sectorILamp=local_light(pos=(75,2,25), color=color.cyan)
sectorIILamp=local_light(pos=(25,2,25), color=color.orange)
sectorIIILamp=local_light(pos=(25,2,75), color=color.magenta)
sectorIVLamp=local_light(pos=(75,2,75), color=color.green)


# Ball
ball = sphere(pos=(0,0,0), color=color.red, radius=0.5)


rhairs = 0.025 
dhairs = 2 
maxcosine = dhairs/sqrt(rhairs**2+dhairs**2) 
haircolor = color.black
roam=False

while True:
    rate(200) 
    
    ball.pos=scene.center-(0,1,0)
    
    roam = True

    # If in roaming mode, change center and forward according to mouse position
    if roam:
        ray = scene.mouse.ray
        if abs(dot(ray,scene.forward)) < maxcosine: # do something only if outside crosshairs
            newray = norm(vector(ray.x, 0, ray.z))
            angle = arcsin(dot(cross(scene.forward,newray),scene.up))
            newforward = rotate(scene.forward, axis=scene.up, angle=angle/100)
            scene.forward = newforward

    # Falls Tastatur gedrückt...
    if scene.kb.keys:
        s = scene.kb.getkey()
        
        if   s == 'up':     # vor gehen
            scene.center = scene.center+scene.forward*mag(scene.center-scene.mouse.camera)/12

        elif s == 'down':   # hinter gehen
            scene.center = scene.center-scene.forward*mag(scene.center-scene.mouse.camera)/12
    
        elif s == 'left':   # links gehen
            scene.center-=cross(scene.forward,scene.up)/6
    
        elif s == 'right':  # rechts gehen
            scene.center+=cross(scene.forward,scene.up)/6

Funktionsleiste