Links und Funktionen
Sprachumschaltung

Navigationspfad


Inhaltsbereich

Objects

Basisklasse für alle bewegten Objekte

Objects.py — text/python-source, 1 KB (1665 bytes)

Dateiinhalt

from visual import *
import math

class MovingObject(object):
    def __init__ (self, position=vector((0,0,0)), speed=vector((0,0,0)), col_radius=1, focus = False ):
        self.position     = position
        self.speed        = speed
        self.acceleration = vector((0,0,0))
        self.col_radius   = col_radius
        self.focus        = focus

        self.collision    = False
        self.collisions   = []

        #self.adjustFrameToDir = True
        self.rahmen       = frame(pos=self.position)
        
        #if self.adjustFrameToDir:
            #self.rahmen.rotate(angle = math.atan2((-1)*speed[2], (-1)*speed[0]), axis = (0,1,0))
            #i = math.sqrt(speed[0]**2 + speed[2]**2)
            #self.rahmen.rotate(angle = (-1) * math.atan2(speed[1], i), axis = (1,0,0))

        self.i = 0
        

    def collisionWith(self,x):
        self.collision = True
        self.collisions.append(x)

    def getCollision(self):
        y = self.collisions.pop()
        if self.collisions == []:
            self.collision = False
        return y
    
    def step(self,dtime):
        self.eventInteraction()
        self.speed += self.acceleration
        self.position   += self.speed*dtime

        self.rahmen.pos = self.position
        self.rahmen.axis = self.speed
        #print self.position, "\t", self.speed, "\t", self.i
        self.i += 1
        if self.focus:
            scene.center = self.position
            scene.range=(18,18,18)
            scene.forward = self.speed+vector((0,-10,0))
        
    def eventInteraction(self):
        # abstract Method
        pass

Funktionsleiste