Skip to content

Instantly share code, notes, and snippets.

@teoyoung
teoyoung / must-see
Last active December 26, 2023 12:17
WebGl courses + tutorials
---------------------------------------
1. Great GLSL course
https://thebookofshaders.com/
https://thebookofshaders.com/?lan=ru (russian language)
2. WebGl basics
https://webglfundamentals.org
https://webglfundamentals.org/webgl/lessons/ru (russian language)
@dghez
dghez / distanceCameraBasedOnWidth.js
Last active March 28, 2021 15:00
Calculate the distance of the camera to fit a given width
import { MathUtils } from "three";
export default function distance(width, camera) {
const vFOV = MathUtils.degToRad(camera.fov);
const distance = width / camera.aspect / (2 * Math.tan(vFOV / 2));
const heightPlane = 2 * Math.tan(vFOV / 2) * distance;
return { distance, height: heightPlane };
}
@ayamflow
ayamflow / gist:96a1f554c3f88eef2f9d0024fc42940f
Last active May 15, 2024 12:37
Threejs Fit plane to screen
var cameraZ = camera.position.z;
var planeZ = 5;
var distance = cameraZ - planeZ;
var aspect = viewWidth / viewHeight;
var vFov = camera.fov * Math.PI / 180;
var planeHeightAtDistance = 2 * Math.tan(vFov / 2) * distance;
var planeWidthAtDistance = planeHeightAtDistance * aspect;
// or