-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 005b6db
Showing
614 changed files
with
179,712 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/resources_compiled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Python: Current File", | ||
"type": "python", | ||
"request": "launch", | ||
"program": "${file}", | ||
"cwd": "${workspaceFolder}/", | ||
"console": "integratedTerminal" | ||
}, | ||
{ | ||
"name": "Lua: Current File", | ||
"type": "lua", | ||
"request": "launch", | ||
"stopOnEntry": false, | ||
"program": "${file}", | ||
"cwd": "${workspaceFolder}/", | ||
"luaexe": "${workspaceFolder}/_bin/lua.exe", | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-- Spatialized sound | ||
|
||
hg = require("harfang") | ||
|
||
hg.InputInit() | ||
hg.WindowSystemInit() | ||
|
||
hg.AddAssetsFolder("resources_compiled") | ||
|
||
snd_ref = hg.LoadWAVSoundAsset("sounds/metro_announce.wav") | ||
src_ref = hg.PlaySpatialized(snd_ref, hg.SpatializedSourceState(hg.Mat4.Identity, 1, hg.SR_Loop)) | ||
|
||
angle = 0 | ||
|
||
while not hg.ReadKeyboard('raw'):Key(hg.K_Escape) do | ||
dt = hg.TickClock() | ||
dt_sec_f = hg.time_to_sec_f(dt) -- delta frame in seconds | ||
|
||
-- compute the source old and new position in world | ||
src_old_pos = hg.Vec3(math.sin(angle), 0, math.cos(angle)) * 5 | ||
angle = angle + hg.time_to_sec_f(hg.TickClock()) * 45 | ||
src_new_pos = hg.Vec3(math.sin(angle), 0, math.cos(angle)) * 5 | ||
|
||
-- source velocity in m.s-1 | ||
src_vel = (src_new_pos - src_old_pos) / dt_sec_f | ||
|
||
-- update source properties | ||
hg.SetSourceTransform(src_ref, hg.TranslationMat4(src_new_pos), src_vel) | ||
end | ||
|
||
hg.AudioShutdown() | ||
hg.InputShutdown() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Spatialized sound | ||
|
||
import harfang as hg | ||
import math | ||
|
||
hg.InputInit() | ||
hg.AudioInit() | ||
|
||
hg.AddAssetsFolder("resources_compiled") | ||
|
||
snd_ref = hg.LoadWAVSoundAsset("sounds/metro_announce.wav") | ||
src_ref = hg.PlaySpatialized(snd_ref, hg.SpatializedSourceState(hg.Mat4.Identity, 1, hg.SR_Loop)) | ||
|
||
angle = 0 | ||
|
||
while not hg.ReadKeyboard('raw').Key(hg.K_Escape): | ||
dt = hg.TickClock() | ||
dt_sec_f = hg.time_to_sec_f(dt) # delta frame in seconds | ||
|
||
# compute the source old and new position in world | ||
src_old_pos = hg.Vec3(math.sin(angle), 0, math.cos(angle)) * 5 | ||
angle += hg.time_to_sec_f(hg.TickClock()) * 45 | ||
src_new_pos = hg.Vec3(math.sin(angle), 0, math.cos(angle)) * 5 | ||
|
||
# source velocity in m.s-1 | ||
src_vel = (src_new_pos - src_old_pos) / dt_sec_f | ||
|
||
# update source properties | ||
hg.SetSourceTransform(src_ref, hg.TranslationMat4(src_new_pos), src_vel) | ||
|
||
hg.AudioShutdown() | ||
hg.InputShutdown() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- Play a mono sound with stereo panning | ||
|
||
hg = require("harfang") | ||
|
||
hg.InputInit() | ||
hg.AudioInit() | ||
|
||
snd_ref = hg.LoadWAVSoundFile('resources_compiled/sounds/metro_announce.wav') -- WAV 44.1kHz 16bit mono | ||
src_ref = hg.PlayStereo(snd_ref, hg.StereoSourceState(1, hg.SR_Loop)) | ||
|
||
angle = 0 | ||
|
||
while not hg.ReadKeyboard('raw'):Key(hg.K_Escape) do | ||
angle = angle + hg.time_to_sec_f(hg.TickClock()) * 0.5 | ||
hg.SetSourcePanning(src_ref, math.sin(angle)) -- panning left = -1, panning right = 1 | ||
end | ||
|
||
hg.AudioShutdown() | ||
hg.InputShutdown() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Play a mono sound with stereo panning | ||
|
||
import harfang as hg | ||
import math | ||
|
||
hg.InputInit() | ||
hg.AudioInit() | ||
|
||
snd_ref = hg.LoadWAVSoundFile('resources_compiled/sounds/metro_announce.wav') # WAV 44.1kHz 16bit mono | ||
src_ref = hg.PlayStereo(snd_ref, hg.StereoSourceState(1, hg.SR_Loop)) | ||
|
||
angle = 0 | ||
|
||
while not hg.ReadKeyboard('raw').Key(hg.K_Escape): | ||
angle += hg.time_to_sec_f(hg.TickClock()) * 0.5 | ||
hg.SetSourcePanning(src_ref, math.sin(angle)) # panning left = -1, panning right = 1 | ||
|
||
hg.AudioShutdown() | ||
hg.InputShutdown() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- Basic loop | ||
|
||
hg = require("harfang") | ||
|
||
hg.InputInit() | ||
hg.WindowSystemInit() | ||
|
||
width, height = 1280, 720 | ||
window = hg.RenderInit('Harfang - Basic Loop', width, height, hg.RF_VSync) | ||
|
||
while not hg.ReadKeyboard():Key(hg.K_Escape) do | ||
hg.SetViewClear(0, hg.CF_Color | hg.CF_Depth, hg.Color.Green, 1, 0) | ||
hg.SetViewRect(0, 0, 0, width, height) | ||
|
||
hg.Touch(0) -- force the view to be processed as it would be ignored since nothing is drawn to it (a clear does not count) | ||
|
||
hg.Frame() | ||
hg.UpdateWindow(window) | ||
end | ||
|
||
hg.RenderShutdown() | ||
hg.DestroyWindow(window) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Basic loop | ||
|
||
import harfang as hg | ||
|
||
hg.InputInit() | ||
hg.WindowSystemInit() | ||
|
||
width, height = 1280, 720 | ||
window = hg.RenderInit('Harfang - Basic Loop', width, height, hg.RF_VSync) | ||
|
||
while not hg.ReadKeyboard().Key(hg.K_Escape): | ||
hg.SetViewClear(0, hg.CF_Color | hg.CF_Depth, hg.Color.Green, 1, 0) | ||
hg.SetViewRect(0, 0, 0, width, height) | ||
|
||
hg.Touch(0) # force the view to be processed as it would be ignored since nothing is drawn to it (a clear does not count) | ||
|
||
hg.Frame() | ||
hg.UpdateWindow(window) | ||
|
||
hg.RenderShutdown() | ||
hg.DestroyWindow(window) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
-- Draw Lines | ||
|
||
hg = require("harfang") | ||
|
||
hg.InputInit() | ||
hg.WindowSystemInit() | ||
|
||
res_x, res_y = 1280, 720 | ||
win = hg.RenderInit('Harfang - Draw Lines', res_x, res_y, hg.RF_VSync | hg.RF_MSAA4X) | ||
|
||
line_count = 1000 | ||
|
||
shader = hg.LoadProgramFromFile('resources_compiled/shaders/white') | ||
|
||
-- vertices | ||
vtx_layout = hg.VertexLayout() | ||
vtx_layout:Begin() | ||
vtx_layout:Add(hg.A_Position, 3, hg.AT_Float) | ||
vtx_layout:End() | ||
|
||
vtx = hg.Vertices(vtx_layout, line_count * 2) | ||
|
||
-- main loop | ||
angle = 0 | ||
|
||
while not hg.ReadKeyboard():Key(hg.K_Escape) do | ||
hg.SetViewClear(0, hg.CF_Color | hg.CF_Depth, hg.ColorI(64, 64, 64), 1, 0) | ||
hg.SetViewRect(0, 0, 0, res_x, res_y) | ||
|
||
vtx:Clear() | ||
for i = 0, line_count-1 do | ||
vtx:Begin(2 * i):SetPos(hg.Vec3(math.sin(angle + i * 0.005), math.cos(angle + i * 0.01), 0)):End() | ||
vtx:Begin(2 * i + 1):SetPos(hg.Vec3(math.sin(angle + i * -0.005), math.cos(angle + i * 0.005), 0)):End() | ||
end | ||
|
||
hg.DrawLines(0, vtx, shader) -- submit all lines in a single call | ||
|
||
angle = angle + hg.time_to_sec_f(hg.TickClock()) | ||
|
||
hg.Frame() | ||
hg.UpdateWindow(win) | ||
end | ||
|
||
hg.RenderShutdown() | ||
hg.DestroyWindow(win) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Draw Lines | ||
|
||
import harfang as hg | ||
from math import sin, cos | ||
|
||
hg.InputInit() | ||
hg.WindowSystemInit() | ||
|
||
res_x, res_y = 1280, 720 | ||
win = hg.RenderInit('Harfang - Draw Lines', res_x, res_y, hg.RF_VSync | hg.RF_MSAA4X) | ||
|
||
line_count = 1000 | ||
|
||
shader = hg.LoadProgramFromFile('resources_compiled/shaders/white') | ||
|
||
# vertices | ||
vtx_layout = hg.VertexLayout() | ||
vtx_layout.Begin() | ||
vtx_layout.Add(hg.A_Position, 3, hg.AT_Float) | ||
vtx_layout.End() | ||
|
||
vtx = hg.Vertices(vtx_layout, line_count * 2) | ||
|
||
# main loop | ||
angle = 0 | ||
|
||
while not hg.ReadKeyboard().Key(hg.K_Escape): | ||
hg.SetViewClear(0, hg.CF_Color | hg.CF_Depth, hg.ColorI(64, 64, 64), 1, 0) | ||
hg.SetViewRect(0, 0, 0, res_x, res_y) | ||
|
||
vtx.Clear() | ||
for i in range(0, line_count): | ||
vtx.Begin(2 * i).SetPos(hg.Vec3(sin(angle + i * 0.005), cos(angle + i * 0.01), 0)).End() | ||
vtx.Begin(2 * i + 1).SetPos(hg.Vec3(sin(angle + i * -0.005), cos(angle + i * 0.005), 0)).End() | ||
|
||
hg.DrawLines(0, vtx, shader) # submit all lines in a single call | ||
|
||
angle = angle + hg.time_to_sec_f(hg.TickClock()) | ||
|
||
hg.Frame() | ||
hg.UpdateWindow(win) | ||
|
||
hg.RenderShutdown() | ||
hg.DestroyWindow(win) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
-- Starfield 3D | ||
|
||
hg = require("harfang") | ||
|
||
hg.InputInit() | ||
hg.WindowSystemInit() | ||
|
||
width, height = 1280, 720 | ||
window = hg.RenderInit('Harfang - Starfield', width, height, hg.RF_VSync | hg.RF_MSAA4X) | ||
|
||
-- vertex layout | ||
vtx_layout = hg.VertexLayout() | ||
vtx_layout:Begin() | ||
vtx_layout:Add(hg.A_Position, 3, hg.AT_Float) | ||
vtx_layout:Add(hg.A_Color0, 3, hg.AT_Float) | ||
vtx_layout:End() | ||
|
||
-- simple shader program | ||
shader = hg.LoadProgramFromFile('resources_compiled/shaders/pos_rgb') | ||
|
||
-- initialize stars | ||
starfield_size = 10 | ||
|
||
max_stars = 1000 | ||
vtx = hg.Vertices(vtx_layout, max_stars * 2) | ||
|
||
stars = {} | ||
for i = 1, max_stars do | ||
table.insert(stars, hg.RandomVec3(-starfield_size, starfield_size)) | ||
end | ||
|
||
-- main loop | ||
while not hg.ReadKeyboard():Key(hg.K_Escape) do | ||
hg.SetViewClear(0, hg.CF_Color | hg.CF_Depth, hg.Color.Black, 1, 0) | ||
hg.SetViewRect(0, 0, 0, width, height) | ||
|
||
dt = hg.TickClock() | ||
dt_f = hg.time_to_sec_f(dt) | ||
|
||
-- update stars | ||
vtx:Clear() | ||
for i, star in ipairs(stars) do | ||
star.z = star.z - 2 * dt_f | ||
if star.z < starfield_size then | ||
star.z = star.z + starfield_size | ||
end | ||
vtx:Begin(2 * (i-1)):SetPos(star * hg.Vec3(1 / star.z, 1 / star.z, 0)):SetColor0(hg.Color.Black):End() | ||
vtx:Begin(2 * (i - 1) + 1):SetPos(star * hg.Vec3(1.04 / star.z, 1.04 / star.z, 0)):SetColor0(hg.Color.White):End() | ||
end | ||
|
||
-- draw stars as lines | ||
hg.DrawLines(0, vtx, shader) | ||
|
||
hg.Frame() | ||
hg.UpdateWindow(window) | ||
end | ||
|
||
hg.RenderShutdown() | ||
hg.DestroyWindow(window) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Starfield 3D | ||
|
||
import harfang as hg | ||
|
||
hg.InputInit() | ||
hg.WindowSystemInit() | ||
|
||
width, height = 1280, 720 | ||
window = hg.RenderInit('Harfang - Starfield', width, height, hg.RF_VSync | hg.RF_MSAA4X) | ||
|
||
# vertex layout | ||
vtx_layout = hg.VertexLayout() | ||
vtx_layout.Begin() | ||
vtx_layout.Add(hg.A_Position, 3, hg.AT_Float) | ||
vtx_layout.Add(hg.A_Color0, 3, hg.AT_Float) | ||
vtx_layout.End() | ||
|
||
# simple shader program | ||
shader = hg.LoadProgramFromFile('resources_compiled/shaders/pos_rgb') | ||
|
||
# initialize stars | ||
starfield_size = 10 | ||
|
||
max_stars = 1000 | ||
vtx = hg.Vertices(vtx_layout, max_stars * 2) | ||
|
||
stars = [] | ||
for i in range(max_stars): | ||
stars.append(hg.RandomVec3(-starfield_size, starfield_size)) | ||
|
||
# main loop | ||
while not hg.ReadKeyboard().Key(hg.K_Escape): | ||
hg.SetViewClear(0, hg.CF_Color | hg.CF_Depth, hg.Color.Black, 1, 0) | ||
hg.SetViewRect(0, 0, 0, width, height) | ||
|
||
dt = hg.TickClock() | ||
dt_f = hg.time_to_sec_f(dt) | ||
|
||
# update stars | ||
vtx.Clear() | ||
for i, star in enumerate(stars): | ||
star.z -= 2 * dt_f | ||
if star.z < starfield_size: | ||
star.z += starfield_size | ||
|
||
vtx.Begin(2 * i).SetPos(star * hg.Vec3(1 / star.z, 1 / star.z, 0)).SetColor0(hg.Color.Black).End() | ||
vtx.Begin(2 * i + 1).SetPos(star * hg.Vec3(1.04 / star.z, 1.04 / star.z, 0)).SetColor0(hg.Color.White).End() | ||
|
||
# draw stars as lines | ||
hg.DrawLines(0, vtx, shader) | ||
|
||
hg.Frame() | ||
hg.UpdateWindow(window) | ||
|
||
hg.RenderShutdown() | ||
hg.DestroyWindow(window) |
Oops, something went wrong.