Exploring ThreeJS has been an intriguing experience for me, especially when projecting vectors in the world space onto normalized device coordinates (NDC). Surprisingly, everything works flawlessly without any hiccups.
However, a noticeable issue arises when swiftly panning the view, resulting in a significant amount of jitter in the x/y coordinate produced by the projection. While object #2, which orbits around the origin, shows less obvious jitter, object #1 positioned at the origin should remain stationary as the camera pans, only to orbit around the origin:
https://i.sstatic.net/PJO5j.gif
Initially, I suspected that the DOM updates might not be keeping pace with the rAF callback execution. However, upon inspecting the x/y coordinates of object #1, I observed the same jittering behavior. For instance, focusing solely on the x-coordinate, it fluctuates around the value of 323.50 while rotating the camera, despite pointing directly at the vector's center:
https://i.sstatic.net/22E1n.png
Take a look at the example provided below:
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(window.devicePixelRatio);
document.body.appendChild(renderer.domElement);
// Rest of the JavaScript code and example omitted for brevity
body {
position: relative;
margin: 0;
padding: 0;
font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
.overlay {
position: absolute;
z-index: 2;
top: 0;
left: 0;
display: grid;
place-items: center;
background-color: #555;
width: 48px;
height: 48px;
border: 4px solid #fff;
border-radius: 50px;
transform: translate(calc(var(--x, 0) - 50%), calc(var(--y, 0) - 50%));
color: #fff;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.146.0/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dca8b4aeb9b99cecf2ede8eaf2ec">[email protected]</a>/examples/js/controls/OrbitControls.js"></script>