def __init__(self, radius, pos): Unit.__init__(self) self.radius = radius self.geo = three.Mesh(three.SphereGeometry(self.radius), three.MeshNormalMaterial()) self.geo.position.set(pos.x, pos.y, pos.z) self.bbox = AABB(self.radius * 2, self.radius * 2, self.geo.position) self.momentum = three.Vector3(0, 0, 0)
def __init__(self, keyboard, game): Unit.__init__(self) self.keyboard = keyboard self.geo = three.Mesh(three.ConeBufferGeometry(1, 3, 8), three.MeshNormalMaterial()) exhaust = three.Mesh(three.ConeBufferGeometry(.5, 2, 8), three.MeshBasicMaterial({'color': 0xffff00})) self.geo.add(exhaust) exhaust.translateY(-2) exhaust.rotateZ(3.14159) self.exhaust = exhaust self.momentum = three.Vector3(0, 0, 0) self.keyboard = keyboard self.bbox = AABB(2, 3, self.geo.position) self.game = game
class Ship(Unit): ROTATE_SPEED = 2.1 THRUST = 45 def __init__(self, keyboard, game): Unit.__init__(self) self.keyboard = keyboard self.geo = three.Mesh( three.ConeBufferGeometry(1, 3, 8), three.MeshNormalMaterial() ) exhaust = three.Mesh( three.ConeBufferGeometry(.5, 2, 8), three.MeshBasicMaterial({'color': 0xffff00}) ) self.geo.add(exhaust) exhaust.translateY(-2) exhaust.rotateZ(3.14159) self.exhaust = exhaust self.momentum = three.Vector3(0, 0, 0) self.keyboard = keyboard self.bbox = AABB(2, 3, self.geo.position) self.game = game def thrust(self, amt): thrust_amt = amt * self.THRUST self.momentum = self.momentum.add(self.heading.multiplyScalar(thrust_amt)) self.exhaust.visible = amt > 0 def spin(self, amt): self.geo.rotateZ(amt * self.ROTATE_SPEED * -1) def update(self, t): Unit.update(self, t) self.bbox.update(self.position) def get_heading(self): # return the local Y axis, since Z is 'up' m = self.geo.matrixWorld.elements return three.Vector3(m[4], m[5], m[6]) heading = property(get_heading)