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 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()
def step(self, moveVector): currentDir = vmath.mat33(self.figure.rotation).getCol(2) l = vmath.length(moveVector) if l > 10.0: gorlDir = vmath.normalize(moveVector) self.body.linearVelocity = gorlDir * 100.0 * core.getElapsedTime() else: gorlDir = currentDir self.body.linearVelocity = (0, 0, 0) self.body.angularVelocity = (0, 0, 0) r = vmath.dot(currentDir, gorlDir) if r < 0.99: n = vmath.cross(currentDir, gorlDir) self.body.angularVelocity = (0, n.y * 10.0, 0) self.figure.rotation = self.body.rotation self.figure.position = self.body.position self.figure.setVertexElements('cape', core.ATTRIBUTE_ID_POSITION, self.soft.meshPositions()) self.figure.setVertexElements('cape', core.ATTRIBUTE_ID_NORMAL, self.soft.meshNormals())
def step(self, targetFigure): at = targetFigure.position dir = at - self.pos distance = vmath.length(dir) dir = vmath.normalize(dir) speed = 0.0 if distance > 6.0: speed = (distance - 6.0) * 0.1 elif distance < 4.0: speed = (distance - 4.0) * 0.1 self.pos += dir * speed self.camera.target = at + vmath.vec3(0, self.targetHeighjt, 0) self.camera.position = self.pos + vmath.vec3(0, self.height, 0)
showcase = core.showcase("case01") showcase.add(ship) goal = vmath.vec2(0, 0) pos = vmath.vec2(0, 0) dir = vmath.vec2(0, 1) loop = True while loop: core.update() touch = core.singleTouch() 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))
showcase3D.add(env) cam2D = core.camera('2dcam') cam2D.orthographicProjection = True cam2D.position = (0, 0, 100) loop = True while loop: core.update() dv = 0.0 moveVector = vmath.vec3(0.0, 0.0, 0.0) touch = core.singleTouch() if touch is not None: moveVector = vmath.vec3(touch['cur_x'] - touch['org_x'], 0, -(touch['cur_y'] - touch['org_y'])) d = vmath.length(moveVector) viewMat = cam.getWalkThroughMatrix() moveVector = vmath.vec3(viewMat * moveVector) char.step(moveVector) cam.step(char.figure) controller.step() cam.camera.shoot(showcase3D, shadowBuffer, renderPass=core.PASS_SHADOW) cam.camera.shoot(showcase3D) cam2D.shoot(showcase2D, clearColor=False) core.swap()