Skip to content

Instantly share code, notes, and snippets.

@cr1901
Created March 19, 2016 23:51
Show Gist options
  • Save cr1901/7d212c860b7f32922dbb to your computer and use it in GitHub Desktop.
Save cr1901/7d212c860b7f32922dbb to your computer and use it in GitHub Desktop.
SolvespaceCamera.prototype.updateProjectionMatrix = function() {
temp = new THREE.Matrix4();
offset = new THREE.Matrix4().makeTranslation(this.offset.x, this.offset.y, this.offset.z);
n = new THREE.Vector3().crossVectors(this.right, this.up);
rotate = new THREE.Matrix4().makeBasis(this.right, this.up, n);
/* TODO: If we want perspective, we need an additional matrix
here which will modify w for perspective divide. */
scale = new THREE.Matrix4().makeScale(2*this.zoom_scale, 2*this.zoom_scale, this.zoom_scale);
/* FIXME: Where did the negative sign in the zScale come from?
It's not in Solvespace, but it's required here to prevent the depth buffer
from being reversed. */
render_correct = new THREE.Matrix4()
.makeScale(1/this.render_width, 1/this.render_height,
-1/30000.0);
/* FIXME: This adds a (negative, thanks to scaling) bias to the
z coordinate to push certain layers (edges) closer to the front of the
screen. Biases don't match solvespace because solvespace uses Open GL
1.0's glDepthRange to change the offset/normalization. We do it manually
here. Solvespace uses a depth_bias of 2/60000 for edges. This also works
here, but it looks bad. */
depth_correct = new THREE.Matrix4().makeTranslation(0, 0, this.depth_bias);
temp.multiply( offset );
temp.multiply( rotate );
temp.multiply( scale );
temp.multiply( render_correct );
temp.multiply( depth_correct );
this.projectionMatrix.copy( temp );
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment