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)
def render(self, view, renderingSystem): #put switch statement here for each type of prop if ann where appropriate modelToWorldTransform = lu.make_mat4_from_zAxis( self.position, self.facing, vec3(0, 0, 1)) rotationByRandAmount = lu.make_rotation_z(self.rotAmount) renderingSystem.drawObjModel( self.model, rotationByRandAmount * modelToWorldTransform, view)
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)
def update(dt, keyStateMap, mouseDelta): global g_sunPosition global g_sunAngle global g_globalAmbientLight global g_sunLightColour global g_sunAngle global g_updateSun global g_viewTarget global g_viewPosition global g_followCamOffset global g_followCamLookOffset ##headLight global g_lightPos global g_lightAngle global g_lightColourAndIntensity if g_updateSun: g_sunAngle += dt * 0.25 g_sunAngle = g_sunAngle % (2.0 * math.pi) g_sunPosition = lu.Mat3( lu.make_rotation_x(g_sunAngle)) * g_sunStartPosition g_sunLightColour = sampleKeyFrames( lu.dot(lu.normalize(g_sunPosition), vec3(0.0, 0.0, 1.0)), g_sunKeyFrames) g_globalAmbientLight = sampleKeyFrames( lu.dot(lu.normalize(g_sunPosition), vec3(0.0, 0.0, 1.0)), g_ambientKeyFrames) g_racer.update(dt, keyStateMap) # TODO 1.2: Make the camera look at the racer. Code for updating the camera should be done after the # racer, otherwise the offset will lag and it generally looks weird. g_viewPosition = vec3( g_racer.position[0], g_racer.position[1], g_racer.position[2] + g_followCamOffset) - g_racer.heading * (g_followCamOffset) g_viewTarget = vec3(g_racer.position[0], g_racer.position[1], g_racer.position[2] \ + g_followCamLookOffset) g_lightAngle += dt * 0.25 g_lightAngle = g_lightAngle % (2.0 * math.pi) g_lightPos = lu.Mat3(lu.make_rotation_z(g_lightAngle)) * \ vec3(g_racer.position[0] + g_racer.heading[0], \ g_racer.position[1]+g_racer.heading[1], \ g_racer.position[2]+g_racer.heading[2]) if imgui.tree_node("Camera", imgui.TREE_NODE_DEFAULT_OPEN): _, g_followCamOffset = imgui.slider_float("FollowCamOffset ", g_followCamOffset, 2.0, 100.0) _, g_followCamLookOffset = imgui.slider_float("FollowCamLookOffset", g_followCamLookOffset, 0.0, 100.0) imgui.tree_pop() if imgui.tree_node("Racer", imgui.TREE_NODE_DEFAULT_OPEN): g_racer.drawUi() imgui.tree_pop() if imgui.tree_node("Terrain", imgui.TREE_NODE_DEFAULT_OPEN): g_terrain.drawUi() imgui.tree_pop() if imgui.tree_node("Lighting", imgui.TREE_NODE_DEFAULT_OPEN): _, g_globalAmbientLight = lu.imguiX_color_edit3_list( "GlobalAmbientLight", g_globalAmbientLight ) #, imgui.GuiColorEditFlags_Float);// | ImGuiColorEditFlags_HSV); _, g_sunLightColour = lu.imguiX_color_edit3_list( "SunLightColour", g_sunLightColour ) #, imgui.GuiColorEditFlags_Float);// | ImGuiColorEditFlags_HSV); _, g_sunAngle = imgui.slider_float("SunAngle", g_sunAngle, 0.0, 2.0 * math.pi) _, g_updateSun = imgui.checkbox("UpdateSun", g_updateSun) imgui.tree_pop()