Published
Edited
Oct 17, 2021
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
planes = [
5,
controls.bottom,
controls.view_z - controls.near,
5,
controls.bottom,
controls.view_z - controls.far,
5,
controls.top,
controls.view_z - controls.far,

5,
controls.top,
controls.view_z - controls.far,
5,
controls.top,
controls.view_z - controls.near,
5,
controls.bottom,
controls.view_z - controls.near,

controls.right,
5,
controls.view_z - controls.near,
controls.right,
5,
controls.view_z - controls.far,
controls.left,
5,
controls.view_z - controls.far,

controls.left,
5,
controls.view_z - controls.far,
controls.left,
5,
controls.view_z - controls.near,
controls.right,
5,
controls.view_z - controls.near
]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function draw() {
// Reset to clear everything
gl.viewport(0, 0, viewof gl.width, viewof gl.height);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

// Draw camera's perspective on the car in top 2/3 of view
gl.useProgram(cameraProgram);
gl.bindBuffer(gl.ARRAY_BUFFER, carVertexBuffer);
const position = gl.getAttribLocation(cameraProgram, "position");
gl.vertexAttribPointer(position, 3, gl.FLOAT, false, FLOAT_SIZE * 8, 0);
gl.viewport(
0,
(1 / 3) * viewof gl.height,
viewof gl.width,
(2 / 3) * viewof gl.height
);
gl.uniformMatrix4fv(
u_model,
false,
glm.mat4.fromYRotation(
glm.mat4.create(),
glm.glMatrix.toRadian(controls.model_yrot)
)
);
gl.uniformMatrix4fv(
u_view,
false,
glm.mat4.lookAt(
glm.mat4.create(),
[0, 0, controls.view_z],
[0, 0, 0],
[0, 1, 0]
)
);
gl.uniformMatrix4fv(
u_projection,
false,
glm.mat4.ortho(
glm.mat4.create(),
controls.left,
controls.right,
controls.bottom,
controls.top,
controls.near,
controls.far
)
);

for (const group in geometry.indices) {
gl.uniform3fv(u_color, geometry.materials[group].albedo);
const [start, end] = geometry.indices[group];
gl.drawElements(
gl.TRIANGLES,
end - start,
gl.UNSIGNED_SHORT,
INDEX_SIZE * start
);
}

// Draw +x side perspective on the car in left lower 1/3 of view
gl.useProgram(sideProgram);
const position_side = gl.getAttribLocation(sideProgram, "position");
gl.vertexAttribPointer(position_side, 3, gl.FLOAT, false, FLOAT_SIZE * 8, 0);
gl.enableVertexAttribArray(position_side);
gl.viewport(
0,
(1 / 12) * viewof gl.width,
0.5 * viewof gl.width,
(1 / 3) * viewof gl.width
);
gl.uniformMatrix4fv(
u_model_side,
false,
glm.mat4.fromYRotation(
glm.mat4.create(),
glm.glMatrix.toRadian(controls.model_yrot)
)
);
gl.uniformMatrix4fv(
u_view_side,
false,
glm.mat4.lookAt(glm.mat4.create(), [5, 0, 2.5], [0, 0, 2.5], [0, 1, 0])
);
gl.uniformMatrix4fv(
u_projection_side,
false,
glm.mat4.ortho(glm.mat4.create(), -7.5, 7.5, -5, 5, -1, 10)
);

for (const group in geometry.indices) {
gl.uniform4fv(u_color_side, geometry.materials[group].albedo.concat([1]));
const [start, end] = geometry.indices[group];
gl.drawElements(
gl.TRIANGLES,
end - start,
gl.UNSIGNED_SHORT,
INDEX_SIZE * start
);
}

// Now draw the bounding volume extents
gl.uniformMatrix4fv(u_model_side, false, glm.mat4.create());
gl.bindBuffer(gl.ARRAY_BUFFER, planesBuffer);
gl.vertexAttribPointer(position_side, 3, gl.FLOAT, false, FLOAT_SIZE * 3, 0);
gl.uniform4fv(u_color_side, [0, 0, 0, 1]);
gl.drawArrays(gl.LINE_STRIP, 0, 3);
gl.drawArrays(gl.LINE_STRIP, 3, 3);

// Draw +y side perspective on the car in right lower 1/3 of view
gl.useProgram(sideProgram);
gl.bindBuffer(gl.ARRAY_BUFFER, carVertexBuffer);
gl.vertexAttribPointer(position_side, 3, gl.FLOAT, false, FLOAT_SIZE * 8, 0);
gl.viewport(
0.5 * viewof gl.width,
(1 / 12) * viewof gl.width,
0.5 * viewof gl.width,
(1 / 3) * viewof gl.width
);
gl.uniformMatrix4fv(
u_model_side,
false,
glm.mat4.fromYRotation(
glm.mat4.create(),
glm.glMatrix.toRadian(controls.model_yrot)
)
);
gl.uniformMatrix4fv(
u_view_side,
false,
glm.mat4.lookAt(glm.mat4.create(), [0, 5, 2.5], [0, 0, 2.5], [-1, 0, 0])
);

for (const group in geometry.indices) {
gl.uniform4fv(u_color_side, geometry.materials[group].albedo.concat([1]));
const [start, end] = geometry.indices[group];
gl.drawElements(
gl.TRIANGLES,
end - start,
gl.UNSIGNED_SHORT,
INDEX_SIZE * start
);
}

// Now draw the bounding volume extents
gl.uniformMatrix4fv(u_model_side, false, glm.mat4.create());
gl.bindBuffer(gl.ARRAY_BUFFER, planesBuffer);
gl.vertexAttribPointer(position_side, 3, gl.FLOAT, false, FLOAT_SIZE * 3, 0);
gl.uniform4fv(u_color_side, [0, 0, 0, 1]);
gl.drawArrays(gl.LINE_STRIP, 6, 3);
gl.drawArrays(gl.LINE_STRIP, 9, 3);
}
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more