Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion axes_indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def draw(self, screen: pygame.Surface):
[self.center[0], self.center[1]],
[self.center[0], self.center[1]]))

projected_rotation = projection_matrix @ rotation_x(self.angle_x) @ rotation_y(self.angle_y) @ rotation_z(self.angle_z)
projected_rotation = projection_matrix @ rotation_z(self.angle_z) @ rotation_y(self.angle_y) @ rotation_x(self.angle_x)
transposed_rotation = (projected_rotation * self.line_size).transpose()
lines_end_positions = (transposed_rotation + add_center_matrix).tolist()

Expand Down
169 changes: 169 additions & 0 deletions grid.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# Vertices
v 0 0 -5
v 0 0 -4
v 0 0 -3
v 0 0 -2
v 0 0 -1
v 0 0 0
v 0 0 1
v 0 0 2
v 0 0 3
v 0 0 4
v 0 0 5

v 1 0 -5
v 1 0 -4
v 1 0 -3
v 1 0 -2
v 1 0 -1
v 1 0 0
v 1 0 1
v 1 0 2
v 1 0 3
v 1 0 4
v 1 0 5

v 2 0 -5
v 2 0 -4
v 2 0 -3
v 2 0 -2
v 2 0 -1
v 2 0 0
v 2 0 1
v 2 0 2
v 2 0 3
v 2 0 4
v 2 0 5

v 3 0 -5
v 3 0 -4
v 3 0 -3
v 3 0 -2
v 3 0 -1
v 3 0 0
v 3 0 1
v 3 0 2
v 3 0 3
v 3 0 4
v 3 0 5

v 4 0 -5
v 4 0 -4
v 4 0 -3
v 4 0 -2
v 4 0 -1
v 4 0 0
v 4 0 1
v 4 0 2
v 4 0 3
v 4 0 4
v 4 0 5

v 5 0 -5
v 5 0 -4
v 5 0 -3
v 5 0 -2
v 5 0 -1
v 5 0 0
v 5 0 1
v 5 0 2
v 5 0 3
v 5 0 4
v 5 0 5

v -1 0 -5
v -1 0 -4
v -1 0 -3
v -1 0 -2
v -1 0 -1
v -1 0 0
v -1 0 1
v -1 0 2
v -1 0 3
v -1 0 4
v -1 0 5

v -2 0 -5
v -2 0 -4
v -2 0 -3
v -2 0 -2
v -2 0 -1
v -2 0 0
v -2 0 1
v -2 0 2
v -2 0 3
v -2 0 4
v -2 0 5

v -3 0 -5
v -3 0 -4
v -3 0 -3
v -3 0 -2
v -3 0 -1
v -3 0 0
v -3 0 1
v -3 0 2
v -3 0 3
v -3 0 4
v -3 0 5

v -4 0 -5
v -4 0 -4
v -4 0 -3
v -4 0 -2
v -4 0 -1
v -4 0 0
v -4 0 1
v -4 0 2
v -4 0 3
v -4 0 4
v -4 0 5

v -5 0 -5
v -5 0 -4
v -5 0 -3
v -5 0 -2
v -5 0 -1
v -5 0 0
v -5 0 1
v -5 0 2
v -5 0 3
v -5 0 4
v -5 0 5

# Faces
f 1 2 14 13
f 2 3 15 14
f 3 4 16 15
f 4 5 17 16
f 5 6 18 17
f 6 7 19 18
f 7 8 20 19
f 8 9 21 20
f 9 10 22 21
f 10 11 23 22
f 11 12 24 23

f 13 14 26 25
f 14 15 27 26
f 15 16 28 27
f 16 17 29 28
f 17 18 30 29
f 18 19 31 30
f 19 20 32 31
f 20 21 33 32
f 21 22 34 33
f 22 23 35 34
f 23 24 36 35

f 25 26 38 37
f 26 27 39 38
f 27 28 40 39
f 28 29 41 40
f 29 30 42 41
f 30 31 43 42
f 31 32 44 43
f 32 33 45 44
f 33 34 46 45
f 34 35 47 46
f 35 36 48 47
9 changes: 5 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
camera = Camera()
camera_axes = AxesIndicator((camera.angle_x, camera.angle_y, camera.angle_z),(50, 50), 20)

obj = Object_3D("cessna.obj", (0, 0, 100))
obj = Object_3D("grid.obj", (0, -10, 100))
object_axes = AxesIndicator((obj.angle_x, obj.angle_y, obj.angle_z), (100, 50), 20)

t = 0
Expand Down Expand Up @@ -57,15 +57,16 @@

screen.fill("black")

obj.draw(screen, width, height, final_matrix)
obj.update(final_matrix)
obj.draw_vertex(screen, width, height)

camera_axes.update((camera.angle_x, camera.angle_y, camera.angle_z))
camera_axes.draw(screen)

object_axes.update((obj.angle_x, obj.angle_y, obj.angle_z))
object_axes.draw(screen)

pygame.draw.circle(screen, "grey", (width//2, height//2), 5, 2)
pygame.draw.circle(screen, "#ff3333", (width//2, height//2), 5, 2)

pygame.display.update()
clock.tick()
clock.tick(60)
15 changes: 14 additions & 1 deletion object_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
import numpy as np
from typing import Tuple
from transforms import *

class Object_3D:
def __init__(self, file_path: str, initial_pos: Tuple[int] = (0, 0, 0)):

self.initial_pos = initial_pos
file = open(file_path)
self.vertices = []
self.faces = []
self.relative_vertices = []

for line in file:
if line.startswith("v"):
try:
Expand All @@ -30,12 +33,22 @@ def __init__(self, file_path: str, initial_pos: Tuple[int] = (0, 0, 0)):
self._angle_y = 0
self._angle_z = 0

def draw(self, screen: pygame.Surface, width: int, height: int, view_matrix: np.ndarray):

def update(self, view_matrix: np.ndarray):
self.relative_vertices = self.vertices @ (view_matrix @ translation(*self.initial_pos)).transpose()

def draw_vertex(self, screen: pygame.Surface, width: int, height: int):
for vertex in self.relative_vertices:
if vertex[0,3] < 0:
pygame.draw.circle(screen, "white", (vertex[0,0] / vertex[0,3] + width//2, vertex[0,1]/vertex[0,3] + height//2), 1)

def draw_edges(self, screen: pygame.Surface, width: int, height: int, view_matrix: np.ndarray):
relative_vertices = self.vertices @ (view_matrix @ translation(*self.initial_pos)).transpose()
for vertex in relative_vertices:
if vertex[0,3] < 0:
pygame.draw.circle(screen, "white", (vertex[0,0] / vertex[0,3] + width//2, vertex[0,1]/vertex[0,3] + height//2), 1)


@property
def angle_x(self):
return self._angle_x
Expand Down
Binary file added relatorio/imgs/07_glspace7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added relatorio/imgs/07_lookat1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added relatorio/imgs/07_lookat7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added relatorio/imgs/07_rotation5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added relatorio/imgs/07_scaling4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added relatorio/imgs/07_translation1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added relatorio/imgs/08_projection7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added relatorio/imgs/emap.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added relatorio/imgs/logo_emap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added relatorio/imgs/ndc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added relatorio/imgs/projection02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions relatorio/importantstuff.sty
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
\ProvidesPackage{importantstuff}

\usepackage[letterpaper,top=2cm,bottom=2cm,left=3cm,right=3cm,marginparwidth=1.75cm]{geometry}

\usepackage[portuguese]{babel}
\usepackage{ragged2e}
\usepackage{enumitem}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{amsfonts}
\usepackage{float}
\usepackage{listings}
\usepackage{xcolor}

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}

\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=cyan,
}
Loading