Skip to content

Commit

Permalink
Changed vector3 to Vector3, color to Color
Browse files Browse the repository at this point in the history
  • Loading branch information
DiogoDeAndrade committed Aug 25, 2020
1 parent 15fde56 commit ca9cf7c
Show file tree
Hide file tree
Showing 23 changed files with 1,127 additions and 1,127 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ It provides very little functionality out-of-the- box: it allows for the program

A scene is composed of 3D objects organized in an optional hierarchical fashion, and each object contains a polygonal mesh and a material that controls how the mesh is rendered.

At the most basic level, it has a few elementary helper classes, like Color, which describes a color with separate red, green, blue and alpha channels, and Vector3, a straightforward 3D vector implementation.
At the most basic level, it has a few elementary helper classes, like Color, which describes a Color with separate red, green, blue and alpha channels, and Vector3, a straightforward 3D vector implementation.

The core of the engine is comprised of the Scene, Object3d, Camera and Mesh classes, which handle the rendering itself.

Expand All @@ -33,7 +33,7 @@ The Camera is derived from Object3d, so that it can be treated in the same way,

The Mesh contains a list of polygons, with each polygon being a list of vertex positions in local space. There are no indexing primitives as simplicity is the main driver of the engine.

The Material class stores the rendering properties like line color and width. A single material can be used by multiple meshes for rendering.
The Material class stores the rendering properties like line Color and width. A single material can be used by multiple meshes for rendering.

The current implementation of PyXYZ uses Pygame for the actual render- ing. We chose Pygame for its simplicity, support for polygon rendering and full software implementation.

Expand Down Expand Up @@ -79,13 +79,13 @@ Then, a scene can be setup:
scene = Scene("TestScene")
scene.camera = Camera(False , res_x , res_y)
# Moves the camera back 2 units
scene.camera.position -= vector3(0,0,2)
scene.camera.position -= Vector3(0,0,2)
# Create a sphere and place it in a scene, at position (0,0,0)
obj1 = Object3d("TestObject")
obj1.scale = vector3(1, 1, 1)
obj1.position = vector3(0, 0, 0)
obj1.scale = Vector3(1, 1, 1)
obj1.position = Vector3(0, 0, 0)
# Set the material of the sphere, in this case it is red
obj1.mesh = Mesh.create_sphere((1, 1, 1), 12, 12) obj1.material = Material(color(1,0,0,1), "TestMaterial1") scene.add_object(obj1)
obj1.mesh = Mesh.create_sphere((1, 1, 1), 12, 12) obj1.material = Material(Color(1,0,0,1), "TestMaterial1") scene.add_object(obj1)
~~~

To render the scene, the programmer just has to use:
Expand Down
8 changes: 4 additions & 4 deletions camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import math
import numpy as np
from quaternion import as_rotation_matrix
from vector3 import vector3
from vector3 import Vector3
from object3d import Object3d

class Camera(Object3d):
Expand Down Expand Up @@ -108,18 +108,18 @@ def ray_from_ndc(self, pos):
pos {2-tuple} -- Screen position in NDC (normalized device coordinates)
Returns:
vector3, vector3 - Origin and direction of the ray corresponding to that screen
Vector3, Vector3 - Origin and direction of the ray corresponding to that screen
positions
"""

vpos = vector3(pos[0], pos[1], self.near_plane)
vpos = Vector3(pos[0], pos[1], self.near_plane)
vpos.x = vpos.x * self.res_x * 0.5
vpos.y = -vpos.y * self.res_y * 0.5

inv_view_proj_matrix = self.get_camera_matrix() @ self.get_projection_matrix()
inv_view_proj_matrix = np.linalg.inv(inv_view_proj_matrix)

direction = inv_view_proj_matrix @ vpos.to_np4(1)
direction = vector3.from_np(direction).normalized()
direction = Vector3.from_np(direction).normalized()

return self.position + direction * self.near_plane, direction
Loading

0 comments on commit ca9cf7c

Please sign in to comment.