Skip to content
Snippets Groups Projects
Commit 7abc578e authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

Suzanne fixed

parent 9665ac42
No related branches found
No related tags found
No related merge requests found
...@@ -469,8 +469,6 @@ function map_worker() { ...@@ -469,8 +469,6 @@ function map_worker() {
// //
if (y2 != y1) { if (y2 != y1) {
for (var y = y1; y <= y2; ++y) { for (var y = y1; y <= y2; ++y) {
if (y < 0) continue
if (y > (h - 1)) break
x12 = Math.floor(0.5+x1+(y-y1)*(x2-x1)/(y2-y1)) x12 = Math.floor(0.5+x1+(y-y1)*(x2-x1)/(y2-y1))
z12 = z1+(y-y1)*(z2-z1)/(y2-y1) z12 = z1+(y-y1)*(z2-z1)/(y2-y1)
x02 = Math.floor(0.5+x0+(y-y0)*(x2-x0)/(y2-y0)) x02 = Math.floor(0.5+x0+(y-y0)*(x2-x0)/(y2-y0))
...@@ -482,7 +480,6 @@ function map_worker() { ...@@ -482,7 +480,6 @@ function map_worker() {
var x = x12 - dir var x = x12 - dir
while (x != x02) { while (x != x02) {
x += dir x += dir
if ((x < 0) || (x > (h-1))) continue
var z = z12+slope*(x-x12) var z = z12+slope*(x-x12)
if (z > map[(h-1-y)*w+x]) { if (z > map[(h-1-y)*w+x]) {
map[(h-1-y)*w+x] = z map[(h-1-y)*w+x] = z
...@@ -496,8 +493,6 @@ function map_worker() { ...@@ -496,8 +493,6 @@ function map_worker() {
} }
if (y1 != y0) { if (y1 != y0) {
for (var y = y0; y <= y1; ++y) { for (var y = y0; y <= y1; ++y) {
if (y < 0) continue
if (y > (h-1)) break
x01 = Math.floor(0.5+x0+(y-y0)*(x1-x0)/(y1-y0)) x01 = Math.floor(0.5+x0+(y-y0)*(x1-x0)/(y1-y0))
z01 = z0+(y-y0)*(z1-z0)/(y1-y0) z01 = z0+(y-y0)*(z1-z0)/(y1-y0)
x02 = Math.floor(0.5+x0+(y-y0)*(x2-x0)/(y2-y0)) x02 = Math.floor(0.5+x0+(y-y0)*(x2-x0)/(y2-y0))
...@@ -509,7 +504,6 @@ function map_worker() { ...@@ -509,7 +504,6 @@ function map_worker() {
var x = x01 - dir var x = x01 - dir
while (x != x02) { while (x != x02) {
x += dir x += dir
if ((x < 0) || (x > (w-1))) continue
var z = z01+slope*(x-x01) var z = z01+slope*(x-x01)
if (z > map[(h-1-y)*w+x]) { if (z > map[(h-1-y)*w+x]) {
map[(h-1-y)*w+x] = z map[(h-1-y)*w+x] = z
...@@ -522,104 +516,6 @@ function map_worker() { ...@@ -522,104 +516,6 @@ function map_worker() {
} }
} }
} }
/*
//
// find triangles crossing the map
//
var segs = []
offset = 80+4
for (var t = 0; t < triangles; ++t) {
offset += 3*4
x0 = view.getFloat32(offset,endian)
offset += 4
y0 = view.getFloat32(offset,endian)
offset += 4
z0 = view.getFloat32(offset,endian)
offset += 4
x1 = view.getFloat32(offset,endian)
offset += 4
y1 = view.getFloat32(offset,endian)
offset += 4
z1 = view.getFloat32(offset,endian)
offset += 4
x2 = view.getFloat32(offset,endian)
offset += 4
y2 = view.getFloat32(offset,endian)
offset += 4
z2 = view.getFloat32(offset,endian)
offset += 4
//
// assemble vertices
//
offset += 2
var v = [[x0,y0,z0],[x1,y1,z1],[x2,y2,z2]]
//
// sort z
//
v.sort(function(a,b) {
if (a[2] < b[2])
return -1
else if (a[2] > b[2])
return 1
else
return 0
})
//
// check for crossings
//
if ((v[0][2] < (zmax-depth)) && (v[2][2] > (zmax-depth))) {
//
// crossing found, check for side and save
//
if (v[1][2] < (zmax-depth)) {
var x0 = v[2][0]+(v[0][0]-v[2][0])
*(v[2][2]-(zmax-depth))/(v[2][2]-v[0][2])
var y0 = v[2][1]+(v[0][1]-v[2][1])
*(v[2][2]-(zmax-depth))/(v[2][2]-v[0][2])
var x1 = v[2][0]+(v[1][0]-v[2][0])
*(v[2][2]-(zmax-depth))/(v[2][2]-v[1][2])
var y1 = v[2][1]+(v[1][1]-v[2][1])
*(v[2][2]-(zmax-depth))/(v[2][2]-v[1][2])
}
else if (v[1][2] >= (zmax-depth)) {
var x0 = v[2][0]+(v[0][0]-v[2][0])
*(v[2][2]-(zmax-depth))/(v[2][2]-v[0][2])
var y0 = v[2][1]+(v[0][1]-v[2][1])
*(v[2][2]-(zmax-depth))/(v[2][2]-v[0][2])
var x1 = v[1][0]+(v[0][0]-v[1][0])
*(v[1][2]-(zmax-depth))/(v[1][2]-v[0][2])
var y1 = v[1][1]+(v[0][1]-v[1][1])
*(v[1][2]-(zmax-depth))/(v[1][2]-v[0][2])
}
if (y0 < y1)
segs.push({x0:x0,y0:y0,x1:x1,y1:y1})
else
segs.push({x0:x1,y0:y1,x1:x0,y1:y0})
}
}
//
// fill interior
//
for (var row = 0; row < h; ++row) {
var y = ymin+(ymax-ymin)*row/(h-1)
rowsegs = segs.filter(p => ((p.y0 <= y) && (p.y1 >= y)))
var xs = rowsegs.map(p =>
(p.x0+(p.x1-p.x0)*(y-p.y0)/(p.y1-p.y0)))
xs.sort((a,b) => (a-b))
for (var col = 0; col < w; ++col) {
var x = xmin+(xmax-xmin)*col/(w-1)
var index = xs.findIndex((p) => (p >= x))
if (index == -1)
var i = 0
else
var i = 255*(index%2)
buf[(h-1-row)*w*4+col*4+0] = i
buf[(h-1-row)*w*4+col*4+1] = i
buf[(h-1-row)*w*4+col*4+2] = i
buf[(h-1-row)*w*4+col*4+3] = 255
}
}
*/
// //
// output the map // output the map
// //
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment