So what we are going to do now is to add another event handler - for click this time - and this will switch between the "3D cone" and "2D conic section" modes. All the rest of the functionality will work in both modes; you are just somewhat "in the dark" about what you are doing when you are in "intersect" mode.
Showing the Intersect
The basic approach we are going to use for this is to instruct the camera to only show a small amount of the full 3D space; everything else is hidden. The camera has the feature to ignore everything that is too close or two far away, thus allowing the appearance of X-ray vision. But by limiting our view to just around the z = 0 plane, we are able to see the intersection of the curve and the plane. This is exactly what we were originally going to do in the right hand canvas; it's just that we are now doing it "modally" rather than in parallel; time-slicing rather than window-slicing if you like.
Because we have defined the camera to be at z = 99, we would like to define the view to be exactly 99. However, when we do that, nothing shows up. Instead, we have to define it to be "a little bit" either side of that exact amount. The consequence of this is that the lines are not perfect lines but "a little bit fat" but this is just a demonstration, so I'm not that bothered.
We start by introducing a variable to remind us of which mode we are in:
var showIntersect = false;Then we add an event handler to change between the modes:
onClick: function(e) {This first handles the event by inverting the value of showIntersect. Then, if the value is now true, it limits the camera range to a very small window around the z axis (from z = -0.25 to z = 0.25), causing something approximating the intersection plane to be shown. If the value is now false, it goes back to the approximate defaults of showing a wide range.
showIntersect = !showIntersect;
if (showIntersect) {
this.camera.near = 98.75;
this.camera.far = 99.25;
} else {
this.camera.near = 10;
this.camera.far = 200;
}
this.camera.update();
}
As with everything else, it is not sufficient to update these variables; it is necessary to call update() (on the camera this time), and then the next redraw event will change the image on the screen.
No comments:
Post a Comment