Skip to content

Commit

Permalink
updated to left hand coordinate system
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin committed Dec 19, 2024
1 parent c926e5f commit a64c28f
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 167 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/publish.yaml

This file was deleted.

86 changes: 80 additions & 6 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,89 @@
name: tests
run-name: tests
on: [push]
run-name: Python Tests
on:
workflow_call:

push:
branches:
- "**"

jobs:
run-unittests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: 'Checkout repository'
uses: actions/checkout@v3
with:
submodules: true
- uses: actions/setup-python@v4
- name: 'Setup Python'
uses: actions/setup-python@v4
with:
python-version: '3.11'
- run: pip install -r requirements.txt
- run: tox
- name: 'Install dependencies'
run: pip install -r requirements.txt
- name: 'Run unit tests'
run: tox
- name: 'Test engine/basic_camera_model/main.py'
run: python engine/basic_camera_model/main.py
- name: 'Test engine/extended_camera_model/main.py'
run: python engine/extended_camera_model/main.py

smoke-tests-linux:
strategy:
fail-fast: false
matrix:
image: [ 'ubuntu:latest', 'ubuntu:20.04', 'ubuntu:22.04', 'debian:latest', 'archlinux:latest' ]
runs-on: ubuntu-latest
container:
image: ${{ matrix.image }}
env:
TZ: Europe/Berlin
steps:
- name: 'Install git (Ubuntu, Debian)'
if: ${{ contains(fromJSON('["ubuntu:latest", "ubuntu:20.04", "ubuntu:22.04", "debian:latest"]'), matrix.image) }}
run: apt-get update && apt-get install -y git
- name: 'Install git (Arch)'
if: ${{ contains('archlinux:latest', matrix.image) }}
run: pacman -Syu --noconfirm git
- name: 'Checkout repository'
uses: actions/checkout@v3
with:
submodules: true
- name: 'Setup timezone'
run: ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
- name: 'Setup Python'
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: 'Install dependencies'
run: pip install -r requirements.txt
- name: 'Run unit tests'
run: tox
- name: 'Test engine/basic_camera_model/main.py'
run: python engine/basic_camera_model/main.py
- name: 'Test engine/extended_camera_model/main.py'
run: python engine/extended_camera_model/main.py

smoke-tests-macos:
strategy:
fail-fast: false
matrix:
macos_version: [ 'macos-latest', 'macos-13' ]
runs-on: ${{ matrix.macos_version }}
steps:
- name: 'Checkout repository'
uses: actions/checkout@v3
with:
submodules: true
- name: 'Setup Python'
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: 'Install dependencies'
run: pip install -r requirements.txt
- name: 'Run unit tests'
run: tox
- name: 'Test engine/basic_camera_model/main.py'
run: python engine/basic_camera_model/main.py
- name: 'Test engine/extended_camera_model/main.py'
run: python engine/extended_camera_model/main.py
11 changes: 5 additions & 6 deletions engine/basic_camera_model/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ def DEG_TO_RAD(deg: float) -> float:


if __name__ == "__main__":
print("playground_camera_model started!")

camera_model = CameraModel(0.00452, 0.00254, 0.004, 1280, 720, 1280/2, 720/2)
camera_model = CameraModel(0.00452, 0.00339, 0.004, 640*2, 480*2, 640, 480)

W_T_V = create_homogeneous_transformation_matrix(0, 0, 0, 0, 0, 0)
V_T_C = create_homogeneous_transformation_matrix(0, 0, 0, 0, 0, 0)
Expand Down Expand Up @@ -102,14 +101,14 @@ def nothing(x):

cv.setTrackbarPos("X", "camera settings", 10000)
cv.setTrackbarPos("Y", "camera settings", 10000)
cv.setTrackbarPos("Z", "camera settings", 11000)
cv.setTrackbarPos("Z", "camera settings", 5000)
cv.setTrackbarPos("Roll", "camera settings", 0)
cv.setTrackbarPos("Pitch", "camera settings", 180)
cv.setTrackbarPos("Pitch", "camera settings", 1800)
cv.setTrackbarPos("Yaw", "camera settings", 0)

cv.setTrackbarPos("X", "cube settings", 14000)
cv.setTrackbarPos("X", "cube settings", 10000)
cv.setTrackbarPos("Y", "cube settings", 10000)
cv.setTrackbarPos("Z", "cube settings", 11000)
cv.setTrackbarPos("Z", "cube settings", 10000)
cv.setTrackbarPos("Roll", "cube settings", 0)
cv.setTrackbarPos("Pitch", "cube settings", 0)
cv.setTrackbarPos("Yaw", "cube settings", 0)
Expand Down
5 changes: 4 additions & 1 deletion engine/basic_camera_model/utils/fps_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ def update(self) -> None:
timestamp = time.time()
delta_time = timestamp - self.last_timestamp
self.last_timestamp = timestamp
self.fps = 1.0 / delta_time
try:
self.fps = 1.0 / delta_time
except:
self.fps = 0
self.fps_history.append(self.fps)
if len(self.fps_history) > self.filter_window_size:
self.fps_history.pop(0)
Expand Down
8 changes: 2 additions & 6 deletions engine/extended_camera_model/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Engine:

def __init__(self):

self.camera_model = CameraModel(0.00452, 0.00254, 0.004, 1280, 720, 1280/2, 720/2)
self.camera_model = CameraModel(0.00452, 0.00339, 0.004, 640, 480, 640/2, 480/2)
self.window = Window()
self.clipping_space = Clipping_Space()
self.fps_counter = FpsCounter(60)
Expand Down Expand Up @@ -48,7 +48,6 @@ def main(self):

while True:

self.window.handle_movement()
self.fps_counter.update()
self.camera_model.reset_camera_image()

Expand All @@ -68,7 +67,7 @@ def main(self):

if self.is_triangle_facing_camera(triangle.normal, triangle.centroids, camera_vector_world) < 0.0:

light_direction = (1, -0.5, -0.8)
light_direction = (0.5, -2.0, 0.5)
triangle.ilm = Color.intensity(light_direction, triangle.normal)
triangle.color = Color.adjust_bgr_intensity(Color.ALICE_BLUE, triangle.ilm)

Expand All @@ -81,9 +80,6 @@ def main(self):
shadow_points_camera = self.camera_model.world_transform(shadow_points, self.C_T_V)
self.camera_model.draw_poly(shadow_points_camera)

print(shadow_points_camera)


clipped_triangles = []
clipped_triangles.extend(self.clipping_space.cube_in_space(sorted_list))

Expand Down
2 changes: 1 addition & 1 deletion engine/extended_camera_model/utils/vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def normal(triangle, scale = 0.5):
def get_shadow(triangles, light_vec):

shadow_points = []
plane_normal = np.array([0, 0, 1])
plane_normal = np.array([0, 1, 0])

for triangle in triangles:
for point in triangle.world_points:
Expand Down
118 changes: 10 additions & 108 deletions engine/extended_camera_model/utils/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ class Window:

def __init__(self):
self.camera_system_translation_x = 10000
self.camera_system_translation_y = 10000
self.camera_system_translation_z = 10000
self.camera_system_rotation_roll = 2700
self.camera_system_rotation_pitch = 0
self.camera_system_rotation_yaw = 2700
self.camera_system_translation_y = 13000
self.camera_system_translation_z = 3000
self.camera_system_rotation_roll = 1500
self.camera_system_rotation_pitch = 1800
self.camera_system_rotation_yaw = 0

self.cube_system_translation_x = 16000
self.cube_system_translation_x = 10000
self.cube_system_translation_y = 10000
self.cube_system_translation_z = 10000
self.cube_system_rotation_roll = 0
self.cube_system_rotation_pitch = 0
self.cube_system_rotation_yaw = 300
self.cube_system_rotation_pitch = 500
self.cube_system_rotation_yaw = 0
self.cube_system_scale = 1

self.camera_window_name = "camera settings"
Expand Down Expand Up @@ -82,10 +82,9 @@ def window_creator(self):
cv.setTrackbarPos("Scale", "cube settings", self.cube_system_scale)

cv.setTrackbarPos("Normals", "cube settings", 0)
cv.setTrackbarPos("Planes", "cube settings", 0)
cv.setTrackbarPos("Points", "cube settings", 1)
cv.setTrackbarPos("Planes", "cube settings", 1)
cv.setTrackbarPos("Points", "cube settings", 0)

cv.setMouseCallback("image window", self.mouse_event_handler)

def toggle_normal(self, value):
self.show_normals = not self.show_normals
Expand Down Expand Up @@ -142,100 +141,3 @@ def get_cube_system_scale(self):
@staticmethod
def nothing(value):
pass


def handle_movement(self):
camera_speed = 100
current_time = time.time()
if current_time - self.last_update_time >= self.update_interval:
self.last_update_time = current_time

key = cv.waitKey(30) & 0xFF

if key == ord('d'):
self.move_camera('forward', camera_speed)
if key == ord('a'):
self.move_camera('backward', camera_speed)
if key == ord('w'):
self.move_camera('left', camera_speed)
if key == ord('s'):
self.move_camera('right', camera_speed)
if key == ord('q'):
self.move_camera('down', camera_speed)
if key == ord('e'):
self.move_camera('up', camera_speed)

def move_camera(self, direction, speed):
# Calculate vectors
yaw = np.deg2rad(self.camera_system_rotation_yaw / 10.0)
pitch = np.deg2rad(self.camera_system_rotation_pitch / 10.0)

forward_x = np.cos(pitch) * np.cos(yaw)
forward_y = np.cos(pitch) * np.sin(yaw)
forward_z = np.sin(pitch)

right_x = np.sin(yaw)
right_y = -np.cos(yaw)
right_z = 0

up_x = 0
up_y = 0
up_z = 1

if direction == 'forward':
self.camera_system_translation_x += int(forward_x * speed)
self.camera_system_translation_y += int(forward_y * speed)
self.camera_system_translation_z += int(forward_z * speed)
elif direction == 'backward':
self.camera_system_translation_x -= int(forward_x * speed)
self.camera_system_translation_y -= int(forward_y * speed)
self.camera_system_translation_z -= int(forward_z * speed)
elif direction == 'left':
self.camera_system_translation_x -= int(right_x * speed)
self.camera_system_translation_y -= int(right_y * speed)
elif direction == 'right':
self.camera_system_translation_x += int(right_x * speed)
self.camera_system_translation_y += int(right_y * speed)
elif direction == 'up':
self.camera_system_translation_z += int(up_z * speed)
elif direction == 'down':
self.camera_system_translation_z -= int(up_z * speed)

self.camera_system_translation_x = np.clip(self.camera_system_translation_x, 0, 20000)
self.camera_system_translation_y = np.clip(self.camera_system_translation_y, 0, 20000)
self.camera_system_translation_z = np.clip(self.camera_system_translation_z, 0, 20000)
cv.setTrackbarPos("X", self.camera_window_name, self.camera_system_translation_x)
cv.setTrackbarPos("Y", self.camera_window_name, self.camera_system_translation_y)
cv.setTrackbarPos("Z", self.camera_window_name, self.camera_system_translation_z)

def mouse_event_handler(self, event, x, y, flags, param):
if event == cv.EVENT_LBUTTONDOWN:
self.mouse_is_pressed = True
self.last_mouse_position = (x, y)
elif event == cv.EVENT_LBUTTONUP:
self.mouse_is_pressed = False
elif event == cv.EVENT_RBUTTONDOWN:
self.right_button_mode = True
elif event == cv.EVENT_RBUTTONDBLCLK:
self.right_button_mode = False
self.last_mouse_position = (x, y)
elif event == cv.EVENT_MOUSEMOVE:
if self.mouse_is_pressed or self.right_button_mode:
dx = x - self.last_mouse_position[0]
dy = y - self.last_mouse_position[1]
self.camera_system_rotation_yaw += dx
self.camera_system_rotation_roll += dy
if self.camera_system_rotation_yaw > 3600:
self.camera_system_rotation_yaw -= 3599
if self.camera_system_rotation_roll > 3600:
self.camera_system_rotation_roll -= 3599
if self.camera_system_rotation_yaw < 0:
self.camera_system_rotation_yaw += 3599
if self.camera_system_rotation_roll < 0:
self.camera_system_rotation_roll += 3599
#self.camera_system_rotation_yaw = np.clip(self.camera_system_rotation_yaw, 0, 3600)
#self.camera_system_rotation_roll = np.clip(self.camera_system_rotation_roll, 0, 3600)
cv.setTrackbarPos("Yaw", self.camera_window_name, self.camera_system_rotation_yaw)
cv.setTrackbarPos("Roll", self.camera_window_name, self.camera_system_rotation_roll)
self.last_mouse_position = (x, y)

0 comments on commit a64c28f

Please sign in to comment.