Skip to content

Commit

Permalink
Update on v3.1.0 of HARFANG 3D.
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofra committed Dec 15, 2021
1 parent b277777 commit 7804ce1
Show file tree
Hide file tree
Showing 320 changed files with 15,583 additions and 15,583 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# HARFANG® 3.0 Poppy Ergo Jr
# HARFANG® 3D Poppy Ergo Jr

This project demonstrate the usage of the [HARFANG 3.0 API](https://www.harfang3d.com/releases/3.0.0/) in **Python** with the [**Poppy Ergo Junior**](https://www.poppy-project.org/en/robots/poppy-ergo-jr/) robot.
This project demonstrate the usage of the [HARFANG 3D API](https://www.harfang3d.com/releases/3.1.0/) in **Python** with the [**Poppy Ergo Junior**](https://www.poppy-project.org/en/robots/poppy-ergo-jr/) robot.

[![](https://raw.githubusercontent.com/harfang3d/image-storage/main/portfolio/3.0.0/digital-twin-poppy-ergo-jr-yt.png)](https://www.youtube.com/watch?v=5kzy_JD_1Ag)

Expand All @@ -11,7 +11,7 @@ This project demonstrate the usage of the [HARFANG 3.0 API](https://www.harfang3
```bash
git clone https://github.com/harfang3d/python-digital-twin poppy
cd poppy/
curl https://www.harfang3d.com/releases/3.0.0/assetc-win-x64-3.0.0.zip --output assetc.zip
curl https://www.harfang3d.com/releases/3.1.0/assetc-win-x64-3.1.0.zip --output assetc.zip
powershell -command "Expand-Archive assetc.zip assetc"
pip install -r requirements.txt
assetc\assetc.exe resources app/resources_compiled
Expand All @@ -24,10 +24,10 @@ python poppy_api_rest.py
```bash
git clone https://github.com/harfang3d/python-digital-twin poppy
cd poppy/
wget https://www.harfang3d.com/releases/3.0.0/assetc-ubuntu-x64-3.0.0.zip
unzip assetc-ubuntu-x64-3.0.0.zip -d assetc
wget https://www.harfang3d.com/releases/3.0.0/harfang-3.0.0-cp32-abi3-linux_x86_64.whl
python3 -m pip install harfang-3.0.0-cp32-abi3-linux_x86_64.whl
wget https://www.harfang3d.com/releases/3.1.0/assetc-ubuntu-x64-3.1.0.zip
unzip assetc-ubuntu-x64-3.1.0.zip -d assetc
wget https://www.harfang3d.com/releases/3.1.0/harfang-3.1.0-cp32-abi3-linux_x86_64.whl
python3 -m pip install harfang-3.1.0-cp32-abi3-linux_x86_64.whl
assetc/assetc resources app/resources_compiled
cd app
python3 poppy_api_rest.py
Expand Down
158 changes: 79 additions & 79 deletions app/OrbitalCam.py
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
import harfang as hg
from statistics import median
from math import pi

d = 5

cam_rot_speed = 0.5
k_wheel = 10

dtxl = []
dtyl = []

smoothed_dx = 0
smoothed_dy = 0

smoothed_rotx = 0


def OrbitalController(keyboard, mouse, cam_pos, cam_rot, cam_tgt, dt, width, height):
global d
global dtxl, dtyl, smoothed_dx, smoothed_dy, smoothed_rotx
dt_sec = hg.time_to_sec_f(dt)

k_ar = hg.ComputeAspectRatioX(width, height).x

delta_x = mouse.DtX() if mouse.Down(hg.MB_0) else 0
delta_y = -mouse.DtY() if mouse.Down(hg.MB_0) else 0
dtxl.append(delta_x)
dtyl.append(delta_y)
if len(dtxl) > 5:
dtxl.pop(0)
if len(dtyl) > 5:
dtyl.pop(0)
delta_x = median(dtxl)
delta_y = median(dtyl)

smoothed_dx += (delta_x - smoothed_dx) * 0.1
smoothed_dy += (delta_y - smoothed_dy) * 0.1

speed = dt_sec * cam_rot_speed
cam_rot.x += smoothed_dy * speed
cam_rot.y += smoothed_dx * speed

# clamp X

if cam_rot.x > pi / 2:
cam_rot.x = pi / 2
if cam_rot.x < 0:
cam_rot.x = 0



if keyboard.Down(hg.K_LAlt):
if mouse.Down(hg.MB_0):
z_value = -mouse.DtY() * 5
speed = d * dt_sec * 10
d += z_value * speed

if mouse.Wheel() != 0:
wheel_dt = mouse.Wheel()

k = abs(wheel_dt) * k_wheel * dt_sec
if wheel_dt > 0:
d /= k + 1
else:
d *= k + 1

if d < 3:
d = 3 # make sure not to come too close to the target
if d > 28:
d = 28

if mouse.Down(hg.MB_2): # scroll viewpoint
speed = d * dt_sec * 0.1
mat = hg.TransformationMat4(cam_pos, cam_rot)
cam_tgt += (hg.GetX(mat) * -mouse.DtX() * k_ar + hg.GetY(mat) * -mouse.DtY()) * speed

world = hg.TransformationMat4(cam_tgt, cam_rot, hg.Vec3.One) * hg.TranslationMat4(hg.Vec3(0, 0, -d))
return world, cam_rot, cam_tgt, hg.GetT(world)
import harfang as hg
from statistics import median
from math import pi

d = 5

cam_rot_speed = 0.5
k_wheel = 10

dtxl = []
dtyl = []

smoothed_dx = 0
smoothed_dy = 0

smoothed_rotx = 0


def OrbitalController(keyboard, mouse, cam_pos, cam_rot, cam_tgt, dt, width, height):
global d
global dtxl, dtyl, smoothed_dx, smoothed_dy, smoothed_rotx
dt_sec = hg.time_to_sec_f(dt)

k_ar = hg.ComputeAspectRatioX(width, height).x

delta_x = mouse.DtX() if mouse.Down(hg.MB_0) else 0
delta_y = -mouse.DtY() if mouse.Down(hg.MB_0) else 0
dtxl.append(delta_x)
dtyl.append(delta_y)
if len(dtxl) > 5:
dtxl.pop(0)
if len(dtyl) > 5:
dtyl.pop(0)
delta_x = median(dtxl)
delta_y = median(dtyl)

smoothed_dx += (delta_x - smoothed_dx) * 0.1
smoothed_dy += (delta_y - smoothed_dy) * 0.1

speed = dt_sec * cam_rot_speed
cam_rot.x += smoothed_dy * speed
cam_rot.y += smoothed_dx * speed

# clamp X

if cam_rot.x > pi / 2:
cam_rot.x = pi / 2
if cam_rot.x < 0:
cam_rot.x = 0



if keyboard.Down(hg.K_LAlt):
if mouse.Down(hg.MB_0):
z_value = -mouse.DtY() * 5
speed = d * dt_sec * 10
d += z_value * speed

if mouse.Wheel() != 0:
wheel_dt = mouse.Wheel()

k = abs(wheel_dt) * k_wheel * dt_sec
if wheel_dt > 0:
d /= k + 1
else:
d *= k + 1

if d < 3:
d = 3 # make sure not to come too close to the target
if d > 28:
d = 28

if mouse.Down(hg.MB_2): # scroll viewpoint
speed = d * dt_sec * 0.1
mat = hg.TransformationMat4(cam_pos, cam_rot)
cam_tgt += (hg.GetX(mat) * -mouse.DtX() * k_ar + hg.GetY(mat) * -mouse.DtY()) * speed

world = hg.TransformationMat4(cam_tgt, cam_rot, hg.Vec3.One) * hg.TranslationMat4(hg.Vec3(0, 0, -d))
return world, cam_rot, cam_tgt, hg.GetT(world)
Loading

0 comments on commit 7804ce1

Please sign in to comment.