Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
    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()
Exemplo n.º 3
0
    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())
Exemplo n.º 4
0
    def ConvertScreenToWorld(self, scrx, scry, worldz, cam):
        invproj = vmath.inverse(cam.projectionMatrix)
        invview = cam.viewInverseMatrix

        w, h = core.viewSize()
        x = scrx / w * 2
        y = scry / h * 2

        pos = vmath.vec4(x, y, 0.0, 1.0)
        npos = invproj * pos
        npos = invview * npos
        npos.z /= npos.w
        npos.x /= npos.w
        npos.y /= npos.w
        npos.w = 1.0

        pos = vmath.vec4(x, y, 1.0, 1.0)
        fpos = invproj * pos
        fpos = invview * fpos
        fpos.z /= fpos.w
        fpos.x /= fpos.w
        fpos.y /= fpos.w
        fpos.w = 1.0

        dir = vmath.normalize(fpos - npos)
        return npos + (dir * (npos.z - worldz))
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
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))
    ship.position = pos
Exemplo n.º 7
0
    touch = core.singleTouch()
    if touch is not None:
        if touch['is_moved']:
            rotX += touch['delta_x'] * 0.05
            rotY += touch['delta_y'] * 0.05
            figure2.rotation = vmath.quat_rotationZYX((rotY, rotX, 0.0))
        elif touch['is_tapped']:
            invProj = vmath.inverse(cam.projectionMatrix)
            invView = cam.viewInverseMatrix
            sw, sh = core.viewSize()
            sx = touch['cur_x'] / (sw / 2)
            sy = touch['cur_y'] / (sh / 2)
            near = vmath.vec4(sx, sy, 0.0, 1.0)
            if cam.orthographicProjection:
                near.z = -1.0
            near = invProj * near
            near = invView * near
            near /= near.w
            far = vmath.vec4(sx, sy, 1.0, 1.0)
            far = invProj * far
            far = invView * far
            far /= far.w
            dir = vmath.normalize(far - near)
            hit, dist, pos = IntersectRayAABB(near, dir, min, max)
            if hit:
                print('hit!')

    figure2.step()
    cam.shoot(showcase)
    core.swap()