예제 #1
0
def loadModel(modelName):
    global g_model
    g_model = ObjModel("data/" + modelName)

    g_camera.target = g_model.centre
    g_camera.distance = lu.length(g_model.centre - g_model.aabbMin) * 3.1
    g_lightDistance = lu.length(g_model.centre - g_model.aabbMin) * 1.3
예제 #2
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)