|
|
@ -13,10 +13,10 @@ const UP = vec3.fromValues(0, 1, 0); |
|
|
|
|
|
|
|
const printMat4 = (name: string, m: mat4) => { |
|
|
|
console.log(name); |
|
|
|
console.log([m[0], m[1], m[2], m[3]]); |
|
|
|
console.log([m[4], m[5], m[6], m[7]]); |
|
|
|
console.log([m[8], m[9], m[10], m[11]]); |
|
|
|
console.log([m[12], m[13], m[14], m[15]]); |
|
|
|
console.log([m[0], m[4], m[8], m[12]]); |
|
|
|
console.log([m[1], m[5], m[9], m[13]]); |
|
|
|
console.log([m[2], m[6], m[10], m[11]]); |
|
|
|
console.log([m[3], m[7], m[14], m[15]]); |
|
|
|
}; |
|
|
|
|
|
|
|
// Function to download data to a file
|
|
|
@ -86,26 +86,30 @@ export const renderGAT = (gl: WebGLRenderingContext, gat: GAT) => { |
|
|
|
mat4.rotateX(view, view, -Math.PI / 2); |
|
|
|
// mat4.lookAt(view, camera, center, UP);
|
|
|
|
|
|
|
|
const modelview = model; |
|
|
|
mat4.multiply(modelview, model, view); |
|
|
|
|
|
|
|
const perspective = mat4.create(); |
|
|
|
const aspect = gl.canvas.clientWidth / gl.canvas.clientHeight; |
|
|
|
mat4.perspective(perspective, Math.PI / 4, aspect, 0.5, 2000); |
|
|
|
mat4.perspective(perspective, Math.PI / 4, aspect, -10, -2000); |
|
|
|
|
|
|
|
const matrix = mat4.create(); |
|
|
|
mat4.multiply(matrix, view, model); |
|
|
|
printMat4("view * model", matrix); |
|
|
|
mat4.multiply(matrix, perspective, matrix); |
|
|
|
mat4.multiply(matrix, modelview, perspective); |
|
|
|
|
|
|
|
const matrixLoc = gl.getUniformLocation(program, "u_matrix"); |
|
|
|
gl.uniformMatrix4fv(matrixLoc, false, matrix); |
|
|
|
|
|
|
|
printMat4("model", model); |
|
|
|
printMat4("view", view); |
|
|
|
printMat4("model + view", modelview); |
|
|
|
printMat4("projection", perspective); |
|
|
|
printMat4("matrix", matrix); |
|
|
|
printMat4("model + view + projection", matrix); |
|
|
|
|
|
|
|
const origin = vec4.create(); |
|
|
|
vec4.transformMat4(origin, ORIGIN, modelview); |
|
|
|
console.log("origin (modelview)", origin); |
|
|
|
vec4.transformMat4(origin, ORIGIN, matrix); |
|
|
|
console.log("origin", origin); |
|
|
|
console.log("origin (projection)", origin); |
|
|
|
|
|
|
|
const vertices: number[] = []; |
|
|
|
|
|
|
@ -132,20 +136,20 @@ export const renderGAT = (gl: WebGLRenderingContext, gat: GAT) => { |
|
|
|
|
|
|
|
// download(exportObj(vertices), "heightmap.obj", "text/plain");
|
|
|
|
|
|
|
|
// let failCount = 0;
|
|
|
|
// for (let i = 0; i < vertices.length / 3; ++i) {
|
|
|
|
// const vec = vec3.fromValues(vertices[i], vertices[i + 1], vertices[i + 2]);
|
|
|
|
// const result = checkPixelCoord(vec, matrix);
|
|
|
|
// if (result) {
|
|
|
|
// if (failCount < 10) {
|
|
|
|
// // console.log(vec);
|
|
|
|
// // console.log(result);
|
|
|
|
// }
|
|
|
|
// failCount++;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// console.log("failCount", failCount);
|
|
|
|
// console.log("totalCount", vertices.length / 3);
|
|
|
|
let failCount = 0; |
|
|
|
for (let i = 0; i < vertices.length / 3; ++i) { |
|
|
|
const vec = vec3.fromValues(vertices[i], vertices[i + 1], vertices[i + 2]); |
|
|
|
const result = checkPixelCoord(vec, matrix); |
|
|
|
if (result) { |
|
|
|
if (failCount < 10) { |
|
|
|
console.log(vec); |
|
|
|
console.log(result); |
|
|
|
} |
|
|
|
failCount++; |
|
|
|
} |
|
|
|
} |
|
|
|
console.log("failCount", failCount); |
|
|
|
console.log("totalCount", vertices.length / 3); |
|
|
|
|
|
|
|
const vertexBuffer = gl.createBuffer(); |
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); |
|
|
|