Пример #1
0
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

    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.

    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()
Пример #2
0
 def __make_inner_squares_up(squares):
     rot_tfm = lu.make_rotation_x(-math.pi / 2)
     translation = lambda i: lu.make_translation(0, -2 + i, 0)
     CubeRenderer.__add_inner_squares(squares, rot_tfm, translation,
                                      TOP_TRANS)
     translation = lambda i: lu.make_translation(0, -2 + 2 * SPACING + i, 0)
     CubeRenderer.__add_inner_squares(squares, rot_tfm, translation,
                                      TOP_TRANS)
Пример #3
0
def renderFrame(uiWidth, width, height):
    global g_triangleVerts
    global g_cameraDistance
    global g_cameraYawDeg
    global g_cameraPitchDeg
    global g_yFovDeg

    global g_lightYaw
    global g_lightDistance
    global g_lightPitch

    # This configures the fixed-function transformation from Normalized Device Coordinates (NDC)
    # to the screen (pixels - called 'window coordinates' in OpenGL documentation).
    #   See: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glViewport.xhtml
    glViewport(0, 0, width, height)
    # Set the colour we want the frame buffer cleared to,
    glClearColor(0.2, 0.5, 0.1, 1.0)
    # Tell OpenGL to clear the render target to the clear values for both depth and colour buffers (depth uses the default)
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)

    viewToClipTransform = lu.make_perspective(g_yFovDeg, width / height, 0.1,
                                              50.0)

    eyePos = lu.Mat3(lu.make_rotation_y(
        math.radians(g_cameraYawDeg))) * lu.Mat3(
            lu.make_rotation_x(
                math.radians(g_cameraPitchDeg))) * [0, 0, g_cameraDistance]
    worldToViewTransform = magic.make_lookAt(eyePos, [0, 0, 0], [0, 1, 0])

    worldToClipTransform = viewToClipTransform * worldToViewTransform

    lightRotation = lu.Mat3(lu.make_rotation_y(
        math.radians(g_lightYaw))) * lu.Mat3(
            lu.make_rotation_x(math.radians(g_lightPitch)))
    lightPosition = [0.02, 0, 0] + lu.vec3(0, 23, 0.2)

    draw_court(worldToClipTransform, lightPosition)
    lu.drawSphere([0.23, -0.45, 0.1, 0], 0.007, [0, 1, 0, 0.5],
                  viewToClipTransform, worldToViewTransform)
    lu.drawSphere(lightPosition, 0.01, [1, 1, 0, 1], viewToClipTransform,
                  worldToViewTransform)
Пример #4
0
 def __add_bottom_squares(self, squares):
     translation = lambda row, col: lu.make_translation(
         SPACING + col, SPACING, -SPACING - row)
     rot_tfm = lu.make_rotation_x(-math.pi / 2)
     CubeRenderer.__add_squares(self.cube.top.squares, squares, rot_tfm,
                                translation)
Пример #5
0
 def __add_top_squares(self, squares):
     translation = TOP_TRANS
     rot_tfm = lu.make_rotation_x(-math.pi / 2)
     CubeRenderer.__add_squares(self.cube.top.squares, squares, rot_tfm,
                                translation)