def step(self, moveVector): l = vmath.length(moveVector) if l > 20.0: self.gorlDir = vmath.normalize(moveVector) self.__changeStatus(STATUS_RUN) elif l > 5.0: self.gorlDir = vmath.normalize(moveVector) self.__changeStatus(STATUS_WALK) else: self.__changeStatus(STATUS_STAY) r = vmath.dot(self.currentDir, self.gorlDir) if r < 0.99: n = vmath.cross(self.currentDir, self.gorlDir) ROT = vmath.mat_rotationY((1.0-r)*n.y*0.5, 3) self.currentDir = vmath.normalize(ROT * self.currentDir) if self.currentState == STATUS_RUN: self.currentPosition += self.currentDir * 2.0 * core.getElapsedTime() elif self.currentState == STATUS_WALK: self.currentPosition += self.currentDir * 1.0 * core.getElapsedTime() self.__transitMotion() self.figure.rotation = vmath.normalize(vmath.quat_rotation((0, 0, 1), self.currentDir)) self.figure.position = self.currentPosition self.figure.step()
def makePlane(width: float, height: float, uv_left_top: tuple = (0, 0), uv_right_bottom: tuple = (1, 1), normal=None): w = width / 2 h = height / 2 points = ((-w, h, 0.0), (w, h, 0.0), (-w, -h, 0.0), (w, -h, 0.0)) if normal is not None: newpoints = [] nom0 = (0, 0, 1) mat = vmath.mat33(vmath.quat_rotation(nom0, normal)) for p in points: newpoints.append(mat * p) points = newpoints uvs = (uv_left_top[0], uv_right_bottom[1], uv_right_bottom[0], uv_right_bottom[1], uv_left_top[0], uv_left_top[1], uv_right_bottom[1], uv_left_top[1]) nom = (0, 0, -1) if normal is not None: nom = normal norms = (nom, nom, nom, nom) return points, norms, uvs, _spriteIndices
def draw_contents(self): if USE_IGE_CORE: core.update() d = self.goal - self.pos dist = vmath.length(d) d = vmath.normalize(d) r = vmath.dot(d, self.dir) if r < 0.98: n = vmath.cross(d, self.dir) if n > 0: rot = vmath.mat_rotation(-5.0 * core.getElapsedTime(), 2) else: rot = vmath.mat_rotation(5.0 * core.getElapsedTime(), 2) self.dir = rot * self.dir if dist > 5.0: self.pos = self.pos + self.dir * (core.getElapsedTime() * 100.0) self.ship.rotation = vmath.normalize( vmath.quat_rotation((0, 1), self.dir)) self.ship.position = self.pos self.camera.shoot(self.showcase) else: super(TestApp, self).draw_contents()
if touch is not None: goal = vmath.vec2(touch['cur_x'], touch['cur_y']) d = goal - pos dist = vmath.length(d) d = vmath.normalize(d) r = vmath.dot(d, dir) if r < 0.98: n = vmath.cross(d, dir) if n > 0: rot = vmath.mat_rotation(-5.0 * core.getElapsedTime(), 2) else: rot = vmath.mat_rotation(5.0 * core.getElapsedTime(), 2) dir = rot * dir if dist > 5.0: pos = pos + dir * (core.getElapsedTime() * 100.0) # update the direction and position of the ship object ship.rotation = vmath.normalize(vmath.quat_rotation((0, 1), dir)) ship.position = pos # update core core.update() # render the objects contained in showcase from the camera. camera.shoot(showcase) # update frame buffer core.swap()