def render_strings_array(strings=None, fade=1.0, fonts_dict={}, plus=None): if plus is None: return rsys = plus.GetRenderSystem() plus.GetRenderer().EnableBlending(True) plus.GetRenderer().EnableDepthTest(False) for line in strings: font_key = line[4] + "_" + str(line[5]) if not (font_key in fonts_dict): fonts_dict[font_key] = hg.RasterFont( "@assets/" + line[4] + ".ttf", int(line[5] * zoom_size() / 3), 512) rect = fonts_dict[font_key].GetTextRect(rsys, line[0]) x = (demo_screen_size[0] - rect.GetWidth()) * 0.5 y = (amiga_screen_size[1] - line[1]) * zoom_size() plus.Text2D(x, y, line[0], int(line[5] * zoom_size() / 3), hg.Color.White * fade, "@assets/" + line[4] + ".ttf") plus.GetRenderer().EnableBlending(False) # underline ? for line in strings: if line[3] == 1: font_key = line[4] + "_" + str(line[5]) rect = fonts_dict[font_key].GetTextRect(rsys, line[0]) x = (demo_screen_size[0] - rect.GetWidth()) * 0.5 y = (amiga_screen_size[1] - line[1]) * zoom_size() - ( line[5] * 0.2 * zoom_size() / 3) plus.Line2D(x, y, x + rect.GetWidth(), y, hg.Color.White * fade * fade, hg.Color.White * fade * fade) return fonts_dict
plus.GetRendererAsync().SetVSync(False) scn = plus.NewScene() scn.AddComponent(hg.Environment()) simple_graphic_scene_overlay = hg.SimpleGraphicSceneOverlay(False) scn.AddComponent(simple_graphic_scene_overlay) cam = plus.AddCamera(scn, mat4.TranslationMatrix(vec3(0, 0, -5))) cam.GetCamera().SetZNear(1) cam.GetCamera().SetZFar(100000) # 100km fps = hg.FPSController(0, 0, -2) fps.SetSmoothFactor(0.3, 0.3) font = hg.RasterFont("@assets/fonts/Handel Gothic D Bold.ttf", 16) navier_stokes.setup() while not plus.IsAppEnded(): dt_sec = plus.UpdateClock() #fps.UpdateAndApplyToNode(cam, dt_sec) navier_stokes.simulation_step(simple_graphic_scene_overlay, hg.time_to_sec_f(dt_sec)) fps.ApplyToNode(cam) plus.GetRenderer().SetProjectionMatrix(cam.GetCamera().GetProjectionMatrix( plus.GetRenderer().GetAspectRatio())) plus.UpdateScene(scn, dt_sec)
geo = hg.Geometry() ok = hg.LoadGeometry(geo, "maze/maze.geo") if not ok: exit() nav_geo = hg.CreateNavigationGeometry(geo, nav_sys.GetConfig()) nav = hg.Navigation() nav.SetGeometry(nav_geo) maze = plus.AddGeometry(scn, "maze/maze.geo") maze.AddComponent(nav) # main loop start, endpoint = hg.Vector3(2, 1, -23), hg.Vector3(-3, 1, 23) font = hg.RasterFont("@core/fonts/default.ttf", 32) picker = hg.ScenePicking(plus.GetRenderSystem()) while not plus.IsAppEnded(): ok, path = nav.FindPathTo(start, endpoint) dt = plus.UpdateClock() plus.UpdateScene(scn, dt) # pick start/end points if picker.Prepare(scn, False, True).get(): mx, my = plus.GetMousePos() my = resolution.y - my if plus.MouseButtonDown(hg.Button0): result, start = picker.PickWorld(scn, mx, my) elif plus.MouseButtonDown(hg.Button1):
import harfang as hg import math import bspline from harfang_shortcut import * font = hg.RasterFont("@assets/fonts/DS-DIGI.TTF", 16) def get_spline_val(t, v1, v2, v3, v4): v = [v1, v2, v3, v4.z] C = bspline.C_factory(v, 1, "clamped") if C: val = C(t * C.max) return val return v2 def get_spline_val_vec(t, p1, p2, p3, p4): P = [(p1.x, p1.y, p1.z), (p2.x, p2.y, p2.z), (p3.x, p3.y, p3.z), (p4.x, p4.y, p4.z)] C = bspline.C_factory(P, 3, "clamped") if C: val = C(t * C.max) return vec3(val[0], val[1], val[2]) return p2 def draw_spline(scene_simple_graphic, p1, p2, p3, p4, color=hg.Color.White): P = [(p1.x, p1.y, p1.z), (p2.x, p2.y, p2.z), (p3.x, p3.y, p3.z),
# open a new window win = hg.NewWindow(1000, 1000) # create a new output surface for the newly opened window surface = renderer.NewOutputSurface(win) renderer.SetOutputSurface(surface) # initialize the render system, which is used to draw through the renderer render_system = hg.RenderSystem() render_system.Initialize(renderer) # create the font objects no_hint_fonts = [] for size in range(4, 44): no_hint_fonts.append(hg.RasterFont("@core/fonts/default.ttf", size, 512)) hint_fonts = [] for size in range(4, 44): hint_fonts.append( hg.RasterFont("@core/fonts/default.ttf", size, 512, 2, True)) # set default render states renderer.Set2DMatrices() renderer.EnableBlending(True) renderer.EnableDepthTest(False) hinting = False glyph_snap = True # retrieve the keyboard device