Skip to content

Commit c541fc3

Browse files
author
Aitor
committedJan 30, 2019
Initial commit
0 parents  commit c541fc3

8 files changed

+724
-0
lines changed
 

‎.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
6+
indent_size = 2
7+
indent_style = space
8+
9+
end_of_line = lf
10+
11+
insert_final_newline = true
12+
13+
trim_trailing_whitespace = true

‎.gitignore

+269
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
2+
# Created by https://www.gitignore.io/api/linux,osx,windows,vim,emacs,sublimetext,visualstudiocode,node
3+
# Edit at https://www.gitignore.io/?templates=linux,osx,windows,vim,emacs,sublimetext,visualstudiocode,node
4+
5+
### Emacs ###
6+
# -*- mode: gitignore; -*-
7+
*~
8+
\#*\#
9+
/.emacs.desktop
10+
/.emacs.desktop.lock
11+
*.elc
12+
auto-save-list
13+
tramp
14+
.\#*
15+
16+
# Org-mode
17+
.org-id-locations
18+
*_archive
19+
20+
# flymake-mode
21+
*_flymake.*
22+
23+
# eshell files
24+
/eshell/history
25+
/eshell/lastdir
26+
27+
# elpa packages
28+
/elpa/
29+
30+
# reftex files
31+
*.rel
32+
33+
# AUCTeX auto folder
34+
/auto/
35+
36+
# cask packages
37+
.cask/
38+
dist/
39+
40+
# Flycheck
41+
flycheck_*.el
42+
43+
# server auth directory
44+
/server/
45+
46+
# projectiles files
47+
.projectile
48+
49+
# directory configuration
50+
.dir-locals.el
51+
52+
# network security
53+
/network-security.data
54+
55+
56+
### Linux ###
57+
58+
# temporary files which can be created if a process still has a handle open of a deleted file
59+
.fuse_hidden*
60+
61+
# KDE directory preferences
62+
.directory
63+
64+
# Linux trash folder which might appear on any partition or disk
65+
.Trash-*
66+
67+
# .nfs files are created when an open file is removed but is still being accessed
68+
.nfs*
69+
70+
### Node ###
71+
# Logs
72+
logs
73+
*.log
74+
npm-debug.log*
75+
yarn-debug.log*
76+
yarn-error.log*
77+
78+
# Runtime data
79+
pids
80+
*.pid
81+
*.seed
82+
*.pid.lock
83+
84+
# Directory for instrumented libs generated by jscoverage/JSCover
85+
lib-cov
86+
87+
# Coverage directory used by tools like istanbul
88+
coverage
89+
90+
# nyc test coverage
91+
.nyc_output
92+
93+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
94+
.grunt
95+
96+
# Bower dependency directory (https://bower.io/)
97+
bower_components
98+
99+
# node-waf configuration
100+
.lock-wscript
101+
102+
# Compiled binary addons (https://nodejs.org/api/addons.html)
103+
build/Release
104+
105+
# Dependency directories
106+
node_modules/
107+
jspm_packages/
108+
109+
# TypeScript v1 declaration files
110+
typings/
111+
112+
# Optional npm cache directory
113+
.npm
114+
115+
# Optional eslint cache
116+
.eslintcache
117+
118+
# Optional REPL history
119+
.node_repl_history
120+
121+
# Output of 'npm pack'
122+
*.tgz
123+
124+
# Yarn Integrity file
125+
.yarn-integrity
126+
127+
# dotenv environment variables file
128+
.env
129+
.env.test
130+
131+
# parcel-bundler cache (https://parceljs.org/)
132+
.cache
133+
134+
# next.js build output
135+
.next
136+
137+
# nuxt.js build output
138+
.nuxt
139+
140+
# vuepress build output
141+
.vuepress/dist
142+
143+
# Serverless directories
144+
.serverless/
145+
146+
# FuseBox cache
147+
.fusebox/
148+
149+
# DynamoDB Local files
150+
.dynamodb/
151+
152+
### OSX ###
153+
# General
154+
.DS_Store
155+
.AppleDouble
156+
.LSOverride
157+
158+
# Icon must end with two \r
159+
Icon
160+
161+
# Thumbnails
162+
._*
163+
164+
# Files that might appear in the root of a volume
165+
.DocumentRevisions-V100
166+
.fseventsd
167+
.Spotlight-V100
168+
.TemporaryItems
169+
.Trashes
170+
.VolumeIcon.icns
171+
.com.apple.timemachine.donotpresent
172+
173+
# Directories potentially created on remote AFP share
174+
.AppleDB
175+
.AppleDesktop
176+
Network Trash Folder
177+
Temporary Items
178+
.apdisk
179+
180+
### SublimeText ###
181+
# Cache files for Sublime Text
182+
*.tmlanguage.cache
183+
*.tmPreferences.cache
184+
*.stTheme.cache
185+
186+
# Workspace files are user-specific
187+
*.sublime-workspace
188+
189+
# Project files should be checked into the repository, unless a significant
190+
# proportion of contributors will probably not be using Sublime Text
191+
# *.sublime-project
192+
193+
# SFTP configuration file
194+
sftp-config.json
195+
196+
# Package control specific files
197+
Package Control.last-run
198+
Package Control.ca-list
199+
Package Control.ca-bundle
200+
Package Control.system-ca-bundle
201+
Package Control.cache/
202+
Package Control.ca-certs/
203+
Package Control.merged-ca-bundle
204+
Package Control.user-ca-bundle
205+
oscrypto-ca-bundle.crt
206+
bh_unicode_properties.cache
207+
208+
# Sublime-github package stores a github token in this file
209+
# https://packagecontrol.io/packages/sublime-github
210+
GitHub.sublime-settings
211+
212+
### Vim ###
213+
# Swap
214+
[._]*.s[a-v][a-z]
215+
[._]*.sw[a-p]
216+
[._]s[a-rt-v][a-z]
217+
[._]ss[a-gi-z]
218+
[._]sw[a-p]
219+
220+
# Session
221+
Session.vim
222+
223+
# Temporary
224+
.netrwhist
225+
# Auto-generated tag files
226+
tags
227+
# Persistent undo
228+
[._]*.un~
229+
230+
### VisualStudioCode ###
231+
.vscode/*
232+
!.vscode/settings.json
233+
!.vscode/tasks.json
234+
!.vscode/launch.json
235+
!.vscode/extensions.json
236+
237+
### VisualStudioCode Patch ###
238+
# Ignore all local history of files
239+
.history
240+
241+
### Windows ###
242+
# Windows thumbnail cache files
243+
Thumbs.db
244+
ehthumbs.db
245+
ehthumbs_vista.db
246+
247+
# Dump file
248+
*.stackdump
249+
250+
# Folder config file
251+
[Dd]esktop.ini
252+
253+
# Recycle Bin used on file shares
254+
$RECYCLE.BIN/
255+
256+
# Windows Installer files
257+
*.cab
258+
*.msi
259+
*.msix
260+
*.msm
261+
*.msp
262+
263+
# Windows shortcuts
264+
*.lnk
265+
266+
# End of https://www.gitignore.io/api/linux,osx,windows,vim,emacs,sublimetext,visualstudiocode,node
267+
268+
mode7.js
269+
mode7.wasm

‎LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright 2019 AzazelN28
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7+
of the Software, and to permit persons to whom the Software is furnished to do
8+
so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

‎README.md

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Mode 7
2+
3+
Mode 7 implementation in C for WebAssembly.
4+
5+
## How to compile this?
6+
7+
### Emscripten
8+
9+
First of all you need to install emscripten and its `emcc` compiler. Follow the installation guide that you will find in [Emscripten](https://kripken.github.io/emscripten-site/index.html).
10+
11+
### Compiling
12+
13+
Once you have `emcc` properly installed run this to generate a debuggable `mode7.js` and `mode7.wasm`:
14+
15+
```sh
16+
build.dev.sh
17+
```
18+
19+
## How to use this library?
20+
21+
Its easy, you only need to import `mode7.js` in your webpage and then:
22+
23+
```html
24+
<script src="mode7.js"></script>
25+
<script>
26+
27+
Module.onRuntimeInitialized = async _ => {
28+
// Allocate 64x64x4 to draw the plane texture in it.
29+
const PlaneSize = 64
30+
const planePointer = Module._get_safe_memory(PlaneSize * PlaneSize * 4)
31+
const plane = new ImageData(new Uint8ClampedArray(Module.buffer, planePointer, PlaneSize * PlaneSize * 4), PlaneSize, PlaneSize)
32+
33+
// Allocate 320x200x4 to draw the final image.
34+
const targetPointer = Module._get_safe_memory(320 * 200 * 4)
35+
const target = new ImageData(new Uint8ClampedArray(Module.buffer, targetPointer, 320 * 200 * 4), 320, 200)
36+
37+
// Initialize mode 7.
38+
Module._set_perspective(Math.PI * 0.5, 0.001, 0.006)
39+
Module._set_plane(plane.width, plane.height, planePointer)
40+
Module._set_view(angle, x, y)
41+
42+
let frameID
43+
, angle = 0
44+
, x = 0
45+
, y = 0
46+
47+
function frame(time) {
48+
if (keys.get('ArrowLeft')) {
49+
angle -= 0.05
50+
} else if (keys.get('ArrowRight')) {
51+
angle += 0.05
52+
}
53+
54+
if (keys.get('ArrowUp')) {
55+
x += Math.cos(angle) * 0.001
56+
y += Math.sin(angle) * 0.001
57+
} else if (keys.get('ArrowDown')) {
58+
x -= Math.cos(angle) * 0.001
59+
y -= Math.sin(angle) * 0.001
60+
}
61+
62+
// Updates the view angle and position.
63+
Module._set_view(angle, x, y)
64+
// Renders the pseudo-plane.
65+
Module._render(target.width, target.height, targetPointer)
66+
67+
cx.putImageData(target, 0, 0)
68+
69+
frameID = window.requestAnimationFrame(frame)
70+
}
71+
72+
frameID = window.requestAnimationFrame(frame)
73+
}
74+
75+
</script>
76+
```
77+
78+
## Thanks to
79+
80+
- [javidx9][https://twitter.com/javidx9] for its great video explanation [Programming Pseudo 3D Planes aka MODE7 (C++)](https://www.youtube.com/watch?v=ybLZyY655iY)
81+
82+
Made with :heart: by [AzazelN28](https://github.com/AzazelN28)

‎build.dev.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
emcc -s INVOKE_RUN=0 -s MALLOC=emmalloc -s ABORTING_MALLOC=0 -s SAFE_HEAP=1 -s TOTAL_MEMORY=33554432 -o mode7.js mode7.c

‎build.pro.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
emcc -Oz -s INVOKE_RUN=0 -s MALLOC=emmalloc -s ABORTING_MALLOC=0 -s TOTAL_MEMORY=33554432 -o mode7.js mode7.c

0 commit comments

Comments
 (0)