コード例 #1
0
ファイル: animate.py プロジェクト: ulethHCI/GLuskap
 def makeStepVal(name, start, end, steps, locks=self._moveLock):
     """
     This function gets called in event time, not right now!
     """
     if name in locks:
         # Special case
         # We set =end on every frame if the end is a function (lambda).
         return None
     elif isinstance(end, (tuple, list)):
         # Assume these are 3D values.
         return div3D(
             diff3D(start, end),
             steps
         )
     elif isinstance(end, FunctionType):
         # Evaluate lambdas here:
         # in clocktime this is the start of movement.
         # This can only lead to confusion.
         print "self:", self
         print "kwargs:", kwargs
         print "name:", name
         print "end:", end
         assert (False)
     else:
         return float(end - start) / steps
コード例 #2
0
ファイル: edge.py プロジェクト: ulethHCI/GLuskap
    def midpoint(self):
        """
        Edge.midpoint() -> (float,float,float)
        Returns the midpoint of this edge as a position tuple.
        """
        from utilities import add3D, div3D

        sum = add3D(self.source.pos, self.target.pos)
        return div3D(sum, 2.0)
コード例 #3
0
ファイル: animate.py プロジェクト: ulethHCI/GLuskap
    def arrangeStepwise(self, graph, vertices, newPos, duration, wait=0.0, tween=True):
        """
        Arrange the vertices of the graph into a new layout
        specified by an indexed list of new positions newPos.
        The vertices will be positioned one at a time.
        """
        assert (len(newPos) == len(vertices))
        delay = float(duration) / len(vertices)

        from math import floor

        if tween:
            if delay > (1.0 / self.parent.fps):
                # No sense tweening faster than the frame rate can keep up
                stepsPerVert = int(floor(delay / (1.0 / self.parent.fps)))
                totalMove = [diff3D(a, b) for a, b in zip([x.pos for x in vertices], newPos)]
                partialMove = [div3D(x, stepsPerVert) for x in totalMove]
            else:
                tween = False

        accum = wait

        for i in range(len(vertices)):
            if tween:
                accum += delay / stepsPerVert
                for step in range(stepsPerVert - 1):
                    self.post(accum,
                              objects=(
                              vertices[i],
                              ),
                              props=(
                              (
                              'pos',
                              add3D(vertices[i].pos, mult3D(partialMove[i], (step + 1))),
                              ),
                              ),
                              changeGraph=graph,
                    )
                    accum += delay / stepsPerVert
            else:
                accum += delay
            self.post(accum,
                      objects=(
                      vertices[i],
                      ),
                      props=(
                      ('pos', newPos[i]),
                      ),
                      changeGraph=graph,
            )

        self.signal()
コード例 #4
0
ファイル: animate.py プロジェクト: ulethHCI/GLuskap
    def perspCameraLookatMove(self, camera, newPos, fixLook, duration, wait=0.0):
        """
        Moves the camera smoothly to a new position and orientation.
        If newLook is None, does not change the orientation of the camera.
        If newPos is None, does not change the position of the camera.
        """
        from camera import Camera, OrthoCamera, X_AXIS, Y_AXIS, Z_AXIS

        assert (not isinstance(camera, OrthoCamera))

        fixLook = self.normalizePos(fixLook)
        steps = int(duration * self.parent.fps)

        deltaPos = diff3D(camera.pos, newPos)
        stepPos = div3D(deltaPos, steps)

        accum = wait
        delay = 1.0 / self.parent.fps

        # Set up the animation
        for i in range(steps - 1):
            accum += delay

            self.post(accum,
                      objects=(camera,),
                      props=(
                      ( 'pos', add3D(camera.pos, mult3D(stepPos, i + 1)) ),
                      ( 'lookAt', fixLook),
                      ),
                      call=(
                      ('absrotate', (Y_AXIS, stepYaw), {}),
                      ('rotate', (X_AXIS, stepPitch), {}),
                      ),
            )

        # Finish up in the correct place
        accum += delay
        self.post(accum,
                  objects=(camera,),
                  props=(
                  ('pos', newPos),
                  ('lookAt', fixLook),
                  ),
        )

        self.signal()
コード例 #5
0
ファイル: animate.py プロジェクト: ulethHCI/GLuskap
    def arrangeMorph(self, graph, vertices, newPos, duration, wait=0.0):
        """
        Arrange the vertices of the graph into a new layout
        specified by an indexed list of new positions newPos.
        The vertices will be positioned simultaneously (smooth morph)
        """
        assert (len(newPos) == len(vertices))

        accum = wait

        steps = int(duration * self.parent.fps)
        delay = 1.0 / self.parent.fps

        d = [div3D(diff3D(a.pos, b), steps) for a, b in zip(vertices, newPos)]

        for i in range(steps - 1):
            accum += delay
            self.post(accum,
                      objects=vertices,
                      multiprops=(
                      (
                      'pos',
                      [add3D(a.pos, mult3D(b, i + 1)) for a, b in zip(vertices, d)]
                      ),
                      ),
                      changeGraph=graph,
            )

        accum += delay
        self.post(accum,
                  objects=vertices,
                  multiprops=(
                  ('pos', newPos),
                  ),
                  changeGraph=graph,
        )
        self.signal()
コード例 #6
0
ファイル: animate.py プロジェクト: ulethHCI/GLuskap
    def perspCameraMove(self, camera, newPos=None, newLook=None, duration=1.0, wait=0.0):
        """
        Moves the camera smoothly to a new position and orientation.
        If newLook is None, does not change the orientation of the camera.
        If newPos is None, does not change the position of the camera.
        """
        from camera import Camera, OrthoCamera, X_AXIS, Y_AXIS, Z_AXIS

        assert (not isinstance(camera, OrthoCamera))

        newCam = Camera()
        if newPos != None:
            newCam.pos = self.normalizePos(newPos)
        else:
            newCam.pos = camera.pos
        if newLook != None:
            newCam.lookAt = self.normalizePos(newLook)
        else:
            newCam.lookAt = camera.lookAt

        steps = int(duration * self.parent.fps)

        (oldTheta, oldPhi) = camera.polar()
        (newTheta, newPhi) = newCam.polar()

        deltaYaw = newTheta - oldTheta
        deltaPitch = newPhi - oldPhi
        deltaPos = diff3D(camera.pos, newCam.pos)

        # Check to make sure we're coming around the short side
        if deltaYaw > 180.0:
            deltaYaw = deltaYaw - 360.0
        elif deltaYaw < -180.0:
            deltaYaw = deltaYaw + 360.0
        print "DeltaYaw", deltaYaw

        stepYaw = deltaYaw / steps
        stepPitch = deltaPitch / steps
        stepPos = div3D(deltaPos, steps)

        accum = wait
        delay = 1.0 / self.parent.fps

        # Set up the animation
        for i in range(steps - 1):
            accum += delay

            self.post(accum,
                      objects=(
                      camera,
                      ),
                      props=(
                      (
                      'pos',
                      add3D(camera.pos, mult3D(stepPos, i + 1)),
                      ),
                      ),
                      call=(
                      ('absrotate', (Y_AXIS, stepYaw), {}),
                      ('rotate', (X_AXIS, stepPitch), {}),
                      ),
            )

        # Finish up in the correct place
        accum += delay
        self.post(accum,
                  objects=(camera,),
                  props=(
                  ('pos', newCam.pos),
                  ('lookAt', newCam.lookAt),
                  ),
        )

        self.signal()