Browse Source

go fuck yourself

master
Forest Belton 3 years ago
parent
commit
c1969d72a5
1 changed files with 18 additions and 14 deletions
  1. +18
    -14
      lib/render/gat.ts

+ 18
- 14
lib/render/gat.ts View File

@ -74,24 +74,22 @@ export const renderGAT = (gl: WebGLRenderingContext, gat: GAT) => {
console.log("center", center); console.log("center", center);
const model = mat4.create(); const model = mat4.create();
mat4.identity(model);
mat4.translate( mat4.translate(
model, model,
model, model,
vec3.fromValues(-centerX, -maxAltitude - 10, -centerZ)
vec3.fromValues(-camera[0], -camera[1], -camera[2])
); );
const view = mat4.create(); const view = mat4.create();
mat4.identity(view);
mat4.rotateX(view, view, -Math.PI / 2); mat4.rotateX(view, view, -Math.PI / 2);
// mat4.lookAt(view, camera, center, UP); // mat4.lookAt(view, camera, center, UP);
const modelview = model; const modelview = model;
mat4.multiply(modelview, model, view);
mat4.multiply(modelview, view, model);
const perspective = mat4.create(); const perspective = mat4.create();
const aspect = gl.canvas.clientWidth / gl.canvas.clientHeight; const aspect = gl.canvas.clientWidth / gl.canvas.clientHeight;
mat4.perspective(perspective, Math.PI / 4, aspect, -10, -2000);
mat4.perspective(perspective, Math.PI / 4, aspect, -0.5, 1000);
const matrix = mat4.create(); const matrix = mat4.create();
mat4.multiply(matrix, modelview, perspective); mat4.multiply(matrix, modelview, perspective);
@ -101,11 +99,13 @@ export const renderGAT = (gl: WebGLRenderingContext, gat: GAT) => {
printMat4("model", model); printMat4("model", model);
printMat4("view", view); printMat4("view", view);
printMat4("model + view", modelview);
printMat4("view * model", modelview);
printMat4("projection", perspective); printMat4("projection", perspective);
printMat4("model + view + projection", matrix);
printMat4("projection * view * model", matrix);
const origin = vec4.create(); const origin = vec4.create();
vec4.transformMat4(origin, ORIGIN, model);
console.log("origin (model)", origin);
vec4.transformMat4(origin, ORIGIN, modelview); vec4.transformMat4(origin, ORIGIN, modelview);
console.log("origin (modelview)", origin); console.log("origin (modelview)", origin);
vec4.transformMat4(origin, ORIGIN, matrix); vec4.transformMat4(origin, ORIGIN, matrix);
@ -138,17 +138,21 @@ export const renderGAT = (gl: WebGLRenderingContext, gat: GAT) => {
let failCount = 0; let failCount = 0;
for (let i = 0; i < vertices.length / 3; ++i) { for (let i = 0; i < vertices.length / 3; ++i) {
const vec = vec3.fromValues(vertices[i], vertices[i + 1], vertices[i + 2]);
const vec = vec4.fromValues(
vertices[i],
vertices[i + 1],
vertices[i + 2],
1
);
const result = checkPixelCoord(vec, matrix); const result = checkPixelCoord(vec, matrix);
if (result) { if (result) {
if (failCount < 10) { if (failCount < 10) {
console.log(vec);
console.log(result);
console.log("vertex clipped, (pre-xform)", vec, "(post-xform)", result);
} }
failCount++; failCount++;
} }
} }
console.log("failCount", failCount);
console.log("clipCount", failCount);
console.log("totalCount", vertices.length / 3); console.log("totalCount", vertices.length / 3);
const vertexBuffer = gl.createBuffer(); const vertexBuffer = gl.createBuffer();
@ -167,9 +171,9 @@ export const renderGAT = (gl: WebGLRenderingContext, gat: GAT) => {
gl.drawArrays(gl.TRIANGLES, 0, vertices.length / 3); gl.drawArrays(gl.TRIANGLES, 0, vertices.length / 3);
}; };
const checkPixelCoord = (x: vec3, mat: mat4): vec4 | null => {
const vec = vec4.fromValues(x[0], x[1], x[2], 1);
vec4.transformMat4(vec, vec, mat);
const checkPixelCoord = (x: vec4, mat: mat4): vec4 | null => {
const vec = vec4.create();
vec4.transformMat4(vec, x, mat);
for (let i = 0; i < vec.length; ++i) { for (let i = 0; i < vec.length; ++i) {
if (Math.abs(vec[i]) >= 1) { if (Math.abs(vec[i]) >= 1) {
return vec; return vec;

Loading…
Cancel
Save