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 getMissile(self, scene): if self._lock is not None: follow = self._lock[0] else: follow = None m_dir = 50 * (self._speed + 0.02) * self._front_vec * 1.5 + self._normal T.unit_vector(m_dir, out=m_dir) return Missile(scene, self._pos, m_dir, "projectile", follow)
def advance(self, amount): if amount == 0: return r = N.cross(self._normal, self._front_vec) T.unit_vector(r, out=r) # vector facing front, parallel to the floor front = N.cross(r, self._normal) self._phys.impulse(front * amount)
def lookAtMtx(eye, target, up): fwd = target - eye fwd = T.unit_vector(fwd) side = N.cross(fwd, up) side = T.unit_vector(side) up = N.cross(side, fwd) M = N.identity(4,dtype="f") M[0,0:3] = side M[1,0:3] = up M[2,0:3] = -fwd M[0:3,3] = N.dot(M[0:3,0:3],-eye) return M
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 planeNormal(p0,p1,p2): d1 = p1-p0 d2 = p2-p0 return T.unit_vector(N.cross(d2,d1))