Пример #1
0
    def update(self, dt, keyStateMap):
        info = self.terrain.getInfoAt(self.position)
        # Select max speed based on material
        maxSpeed = self.maxSpeedRoad if info.material == TerrainInfo.M_Road else self.maxSpeedRough

        targetVel = vec3(0.0)
        if keyStateMap["UP"]:
            targetVel = self.heading * maxSpeed
        if keyStateMap["DOWN"]:
            targetVel = self.heading * -maxSpeed

        # linearly interpolate towards the target velocity - this means it is tied to the frame rate, which kind of is bad.
        self.velocity = lu.mix(self.velocity, targetVel, 0.01)

        self.speed = lu.length(self.velocity)

        rotationMat = lu.Mat4()
        if keyStateMap["LEFT"]:
            rotationMat = lu.make_rotation_z(dt * self.angvel)
        if keyStateMap["RIGHT"]:
            rotationMat = lu.make_rotation_z(dt * -self.angvel)

        self.heading = lu.Mat3(rotationMat) * self.heading

        # get height of ground at this point.

        self.position += self.velocity * dt

        # TODO 1.1: After the terrain height is correct, uncomment this line to make the racer follow the ground height
        self.position[2] = lu.mix(self.position[2], info.height + self.zOffset,
                                  0.1)
Пример #2
0
 def render(self, view, renderingSystem):
     getInfo = self.terrain.getInfoAt(self.position)
     self.position[2] = lu.mix(self.position[2], getInfo.height - self.zOffset,\
                               1)
     rotation = lu.make_rotation_z(self.randRot)
     modelToWorldTransform = lu.make_mat4_from_zAxis(self.position, self.heading, \
                                                     vec3(0,0,1))
     renderingSystem.drawObjModel(self.model,
                                  rotation * modelToWorldTransform, view)
Пример #3
0
def sampleKeyFrames(t, kfs):
    # 1. find correct interval
    if t <= kfs[0][0]:
        return kfs[0][1]

    if t >= kfs[-1][0]:
        return kfs[-1][1]

    for i1 in range(1, len(kfs)):
        if t < kfs[i1][0]:
            i0 = i1 - 1
            t0 = kfs[i0][0]
            t1 = kfs[i1][0]
            # linear interpolation from one to the other
            return lu.mix(kfs[i0][1], kfs[i1][1], (t - t0) / (t1 - t0))

    # we should not get here, unless the key values are malformed (i.e., not strictly increasing)
    assert False
    # but if we do, we return a value that is obviously no good (rahter than say zero that might pass unnoticed for much longer)
    return None
Пример #4
0
 def update(self):
     info = self.terrain.getInfoAt(self.position)
     self.position[2] = lu.mix(self.position[2], info.height + self.zOffset,
                               0.1)