def init_scene(plus): scene = plus.NewScene() camera = plus.AddCamera( scene, hg.Matrix4.TranslationMatrix(hg.Vector3(0, 0, -10))) camera.SetName("Camera") camera.GetCamera().SetZNear(1.) camera.GetCamera().SetZFar(10000) init_lights(plus, scene) fps = hg.FPSController(0, 500, -10) while not scene.IsReady(): # Wait until scene is ready plus.UpdateScene(scene, plus.UpdateClock()) plus.UpdateScene(scene, plus.UpdateClock()) return scene, fps
import harfang as hg hg.LoadPlugins() plus = hg.GetPlus() plus.RenderInit(640, 400) scn = plus.NewScene() cam = plus.AddCamera(scn, hg.Matrix4.TranslationMatrix(hg.Vector3(0, 1, -10))) plus.AddLight(scn, hg.Matrix4.TranslationMatrix(hg.Vector3(6, 4, -6))) plus.AddCube(scn, hg.Matrix4.TranslationMatrix(hg.Vector3(0, 0.5, 0))) plus.AddPlane(scn) fps = hg.FPSController(0, 2, -10) while not plus.IsAppEnded(): dt = plus.UpdateClock() fps.UpdateAndApplyToNode(cam, dt) plus.UpdateScene(scn, dt) plus.Text2D(5, 5, "Move around with QSZD, left mouse button to look around") plus.Flip() plus.EndFrame() plus.RenderUninit()
geo = hg.RenderGeometry() hg.IsoSurfaceToRenderGeometry(plus.GetRenderSystem(), iso, geo, mat) t_new = hg.time_to_us_f(hg.time_now()) bench_create_geo.append(t_new - t_ref) return geo # hg.MountFileDriver(hg.StdFileDriver("../_data/"), "@data/") plus = hg.GetPlus() plus.RenderInit(1280, 720) mat = plus.LoadMaterial("@core/materials/default.mat") fps = hg.FPSController(w / 2, h / 2, -100) # scn = plus.NewScene() cam = plus.AddCamera(scn, hg.Matrix4.TranslationMatrix(hg.Vector3(0, 1, -10))) plus.AddLight(scn, hg.Matrix4.RotationMatrix(hg.Vector3(0.6, -0.4, 0)), hg.LightModelLinear, 300) plus.AddPlane(scn) renderable_system = scn.GetRenderableSystem() a = 0 while not plus.IsAppEnded(): dt = plus.UpdateClock() fps.UpdateAndApplyToNode(cam, dt) geo = update_field(a)
plus.SetBlend3D(hg.BlendAlpha) plus.SetRenderWindow() 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(
physic_system = scn.GetPhysicSystem() physic_system.SetTimestep(1 / 200) # raise physic frequency for more stability # create default content cam = plus.AddCamera(scn, hg.Matrix4.TranslationMatrix(hg.Vector3(0, 1, -10))) plus.AddLight(scn, hg.Matrix4.RotationMatrix(hg.Vector3(0.6, -0.4, 0)), hg.LightModelLinear, 150) plus.AddLight(scn, hg.Matrix4.RotationMatrix(hg.Vector3(0.6, pi, 0.2)), hg.LightModelLinear, 0, False, hg.Color(0.3, 0.3, 0.4)) plus.AddPhysicPlane(scn) # create the initial tower tower_radius = 6 tower_height = 16 nodes = add_kapla_tower(scn, 0.5, 2, 2, tower_radius, tower_height) # create the FPS controller fps = hg.FPSController(0, 16, -80) # enter the simulation loop while not plus.IsAppEnded(): # handle inputs old_tower_radius, old_tower_height = tower_radius, tower_height if plus.KeyPress(hg.KeyF2): tower_radius += 1 elif plus.KeyPress(hg.KeyF1): if tower_radius > 5: tower_radius -= 1 elif plus.KeyPress(hg.KeyF4): tower_height += 1 elif plus.KeyPress(hg.KeyF3): if tower_height > 1:
terrain = hg.Terrain() terrain.SetSize(hg.Vector3(68767, 5760, 68767)) terrain.SetHeightmap("@data/terrain/island.r16") terrain.SetHeightmapResolution(hg.IntVector2(1024, 1024)) terrain.SetMinPrecision( 50 ) # don't bother with a very fine grid given the low resolution heightmap in use terrain.SetSurfaceShader("@data/terrain/island.isl") terrain_node = hg.Node() terrain_node.AddComponent(hg.Transform()) terrain_node.AddComponent(terrain) scn.AddNode(terrain_node) # fps = hg.FPSController(0, 3000, -30000, 100, 400) while not plus.IsAppEnded(): dt = plus.UpdateClock() old_pos = fps.GetPos() fps.UpdateAndApplyToNode(cam, dt) speed = hg.Dist(fps.GetPos(), old_pos) / hg.time_to_sec_f(dt) if dt > 0 else 0 plus.UpdateScene(scn, dt) plus.Text2D(5, 25, "Current speed: %d m/s" % int(speed)) plus.Text2D( 5, 5, "Move around with QSZD, left mouse button to look around (hold shift to go faster)"
def init_game(plus): init_scene(plus) Aircraft.main_node = Main.main_node Main.audio = hg.CreateMixer() Main.audio.Open() # Clear color alpha = 0 Main.scene.GetEnvironment().SetBackgroundColor(hg.Color(0, 0, 0, 0)) # Aircrafts & Cie: Main.p1_aircraft = Aircraft("TangoCharly", 1, "aircraft", plus, Main.scene, hg.Vector3(0, 3000, 0), hg.Vector3(0, 0, 0)) Main.p2_aircraft = Aircraft("Zorglub", 2, "ennemyaircraft", plus, Main.scene, hg.Vector3(4000, 3000, 4000), hg.Vector3(0, 0, 0)) Main.carrier = Carrier("Charles_de_Gaules", 1, plus, Main.scene) for i in range(4): Main.p1_missiles[i] = Missile("sidewinder_" + str(i), 1, plus, Main.scene, Main.audio, "assets/weaponry/enemymissile_low.geo", "assets/weaponry/enemymissile_smoke") Main.p2_missiles[i] = Missile("ennemy_sidewinder_" + str(i), 2, plus, Main.scene, Main.audio, "assets/weaponry/enemymissile_low.geo", "assets/weaponry/enemymissile_smoke") # Machine guns : Main.bullets = Main.p1_aircraft.gun_machine Main.ennemy_bullets = Main.p2_aircraft.gun_machine Main.p1_aircraft.set_destroyable_targets([Main.p2_aircraft, Main.carrier]) Main.p2_aircraft.set_destroyable_targets([Main.p1_aircraft, Main.carrier]) # Fps Main.fps = hg.FPSController(0, 0, 0) Main.controller=find_controller("xinput.port0") Main.scene.Commit() Main.scene.WaitCommit() #plus.UpdateScene(Main.scene) load_game_parameters() Main.texture_hud_plot_aircraft = plus.LoadTexture("assets/sprites/plot.png") Main.texture_hud_plot_missile = plus.LoadTexture("assets/sprites/plot_missile.png") Main.texture_hud_plot_ship = plus.LoadTexture("assets/sprites/plot_ship.png") Main.texture_hud_plot_dir = plus.LoadTexture("assets/sprites/plot_dir.png") Main.texture_noise = plus.LoadTexture("assets/sprites/noise.png") # ---- Blend settings: renderer = plus.GetRenderer() renderer.SetBlendFunc(hg.BlendSrcAlpha, hg.BlendOneMinusSrcAlpha) # --- Sfx: Main.p1_sfx = AircraftSFX(Main.p1_aircraft) Main.p2_sfx = AircraftSFX(Main.p2_aircraft) # P2 engine sound is different: Main.p2_sfx.set_air_pitch(0.75) Main.p2_sfx.set_pc_pitch(1.5) Main.p2_sfx.set_turbine_pitch_levels(hg.Vector2(1.5, 2.5)) # ---- Camera: Main.scene.SetCurrentCamera(Main.camera) # ---- PostProcess: Main.MotionBlur_postProcess=hg.MotionBlurPostProcess() Main.HSL_postProcess=hg.HSLPostProcess() Main.RadialBlur_postProcess=hg.RadialBlurPostProcess() Main.camera.AddComponent(Main.RadialBlur_postProcess) Main.camera.AddComponent(Main.HSL_postProcess) post_processes_load_parameters()