Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy to Github pages #10

Merged
merged 3 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
chore: Update favicon and readme
  • Loading branch information
mithi committed Aug 17, 2020
commit 1dd8d605fd1034b34a41e238c55909f33b7b669d
48 changes: 4 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,12 @@
# Hello Tiny Box

Manipulate a three dimensional box. Algorithm code: [Python script](./prototype-script.py)
> Manipulate a three-dimensional box.

![User Interface Screenshot](https://user-images.githubusercontent.com/1670421/90424712-258d9f80-e0f1-11ea-972d-01f738102517.png)

## High Level Pseudocode

The pseudocode is taken from [Gabriel Gambetta's Computer Graphics from Scratch online book (Scene Setup)](https://www.gabrielgambetta.com/computer-graphics-from-scratch/scene-setup.html)

We manipulate vertex V in model space until it’s projected into the canvas point (cx,cy)

1. We first apply the model transform, to go from model space to world space (rotate, scale, translate)
2. Then we apply the camera transform, to go from world space to camera space (rotate and translate)
3. Next we apply the perspective equations and we finally map the viewport coordinates to canvas coordinates

You can inspect the algorithm I first wrote in python here: Algorithm code: [Python script](./prototype-script.py)

```python
# High level pseudo code only
- This project is inspired by [Gabriel Gambetta's Computer Graphics from Scratch online book](https://www.gabrielgambetta.com/computer-graphics-from-scratch/scene-setup.html)

def get_projected_point(point):
return {
"x": point.x / point.z * projection_constant,
"y": point.y / point.z * projection_constant,
"z" projection_constant
}
- Algorithm code: [Python script](./prototype-script.py)

def render_model(model_instance, model_to_camera_matrix):
transformed_points = [] # x, y, z wrt camera (3d)
projected_points = [] # x, y wrt canvas of camera (2d)

for point in model_instance.points:
transformed_points.append(model_to_camera_matrix * point)
projected_points.append(get_projected_point(point))

# figure out which places are on the back or front
# modified_back_face_culling algorithm
information = which_planes_front_facing(transformed_points)
plot_points_in_image(projected_points, information)



def render_scene():
camera_to_world_matrix = build_camera_matrix(camera_position, camera_orientation)
for each model_instance in scene:
model_to_camera_matrix = world_to_camera_matrix * model_instance.model_to_world_matrix
render_model(model_instance, model_to_camera_matrix)
```
![User Interface Screenshot](https://user-images.githubusercontent.com/1670421/90424712-258d9f80-e0f1-11ea-972d-01f738102517.png)

## References

Expand Down
Binary file added public/favicon512x512.ico
Binary file not shown.
Binary file removed public/favicon64x64.png
Binary file not shown.
12 changes: 9 additions & 3 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Hello Tiny Box - Manipulate a 3d Box" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192x192.png" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo512x512.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>Hello Tiny Box! Manipulate a 3d Box</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
/>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/icon?family=Material+Icons"
/>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
Binary file removed public/logo192x192.png
Binary file not shown.
Binary file modified public/logo512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.