xxxxxxxxxx
115
//Fixed point bullshiznic
//I'm dealing with 16bit integers. So hopefully I can get away with 3 points of precission
//1.234 = 1234
//To force it hear I guess I will add a mask 0xffff
FB_MAX = 64;
FB_LOC = 0;//0x200;
PIX_SZ = 4;
G_W = 4;
G_H = 4;
memory = []
function MAX(x, y){return ((x) > (y)) ? (x) : (y);}
function getMyVec(x, y, z){
return {'x': x & 0xffff, 'y': y & 0xffff, 'z': z & 0xffff};
}
function createWorld(){
return {'plane': {'normal': getMyVec(0, 0, 1),
'd': 0,
'matIdx': 1},
'sphere': {'point':0,
'radius': 0},
'material': [
{'color': getMyVec(0, 0, 0)},
{'color': getMyVec(255, 0, 0)}
]
}
}
function initMemory(){
s = 256/64;
for (i = 0; i < 64 * 64; i++){
for(j = 0; j < 64; j++){
memory[(i * 64) + j] = createVector(s * i, s * j, 0);
}
}
}
//Ok so we have a grid that is 64x64
function poke(x, y, r, g, b){
idx = (64 * y) + x;
memory[idx] = createVector(r, g, b);
}
function PutPixel(x, y, r, g, b){
x = x/PIX_SZ;
poke(x, y, r, g, b);
}
function Square( x, y, width, height, r, g, b){
ends = PIX_SZ * (x + width);
sx = MAX(0, x * PIX_SZ);
for(yp = y; (yp < (y + height)) && (yp < FB_MAX); yp++){
for(xp = sx;
(xp < ends) &&
(xp < (FB_MAX * PIX_SZ));
xp+=PIX_SZ){
//console.log(xp, yp, ends, sx);
PutPixel(xp, yp, r, g, b);
}
}
}
function blit(){
w = floor(width/64);
h = floor(height/64);
px = 0;
py = 0;
for(y = 0; y < 64; y++){
for(x = 0; x < 64; x++){
idx = (64 * y) + x;
noStroke();
fill(memory[idx].x, memory[idx].y, memory[idx].z);
rect(px, py, w, h);
px += w;
}
px = 0;
py += h;
}
}
function setup() {
initMemory();
createCanvas(800, 800);
}
dx = 0;
function draw() {
//noLoop();
background(220);
cameraP = getMyVec(0, 10, 1);
world = createWorld();
poke(0, 0, 0, 0, 255);
Square(dx, 0, 32, 32, 255, 100, 10 * (255/65));
Square(dx + 32, 0, 32, 32, 255, 100, 100 * (255/65));
Square(dx+32, 32, 32, 32, 255, 100, 10 * (255/65));
Square(dx, 32, 32, 32, 255, 100, 100 * (255/65));
dx--;
if (dx == -33)
dx = 64;
//console.log(dx);
//for(i = 0; i < 64; i++){
//}
blit();
}