def __init__(self, map, position): print "New player" Entity.__init__(self) self._lock = None self._phys = Verlet(position) self._phys.setDamping((0.02, 0.02, 0.0002)) self._phys.setGravity((0, 0, -0.00006)) self._on_floor = False self._speed = 0 self._map = map self._heading = 0 self.reset() r = self._radius = 0.1 self.setBounds(((-r, -r, -r), (r, r, r))) # entity stuff Entity.moveTo(self, position) # keep the entity updated self._scaling = T.scale_matrix(self._radius) self._last_pos = N.array((0, 0, 0), dtype="f") self._graphics = R.loadObject("sphere.obj", "diffuse")
def update(self, time): if self._destroyed: return False if self._t0 is None: self._t0 = time if self._follow is not None and not self._follow.closing() : d = self._follow._pos - self._pos T.unit_vector(d,d) self._dir = self._dir * (1-self._thrust) + d * self._thrust if time - self._t0 > 3000 or self._follow._destroyed: print "Not following anymore" self._follow = None Entity.moveTo(self, self._pos + self._dir * self._speed) # also updates _pos else: # too simple to use Verlet Entity.moveTo(self, self._pos + self._dir * self._speed) # also updates _pos self._dir += self._gravity self._xform = mmult(self._pos_m,self._scaling_m, T.quaternion_matrix(self._rotation)) self._rotation = T.quaternion_multiply(self._d_rotation, self._rotation) # hit the floor if self._map(self._pos[0], self._pos[1], False) > self._pos[2]: self.explode() return False # tell the scene the missile is toast return True
def update(self, time): self._lock = None # ----- here be dragons ph = self._phys ph._impuse = ph._gravity ph.update() # test for collision with map z, normal = self._map(ph._position[0], ph._position[1]) h = (z + self._radius) - ph._position[2] T.unit_vector(normal, out=normal) self._on_floor = h > 0 if self._on_floor and ph._position[2] < ph._last_position[2]: # collision ph._impulse += h * normal * 0.00001 # * normal[2] ph._position[2] += h ph._last_position[2] += h new_pos = ph._position # ----- self._dir = new_pos - self._pos self._speed = T.vector_norm(self._dir) self._last_pos[:] = new_pos Entity.moveTo(self, new_pos) # updates self._pos too self._normal = normal self._axis = N.cross(self._dir, normal) self.roll(self._axis)
def moveTo(self, pos): dp = pos - self._pos Entity.moveTo(pos) self._phys.displace(dp)