Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Swapped Chapters 8 and 9; Added Wireframe Circle for Figure
- Loading branch information
Showing
10 changed files
with
94 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
<title>Programming 3D Applications in HTML5 and WebGL — Three.js Circle Geometry</title> | ||
|
||
<script src="../libs/jquery-1.9.1/jquery-1.9.1.js"></script> | ||
<script src="../libs/three.js.r58/three.js"></script> | ||
<script src="../libs/requestAnimationFrame/RequestAnimationFrame.js"></script> | ||
<script type="text/javascript"> | ||
|
||
var renderer = null, | ||
scene = null, | ||
camera = null, | ||
cube = null; | ||
|
||
var duration = 5000; // ms | ||
var currentTime = Date.now(); | ||
function animate() { | ||
|
||
var now = Date.now(); | ||
var deltat = now - currentTime; | ||
currentTime = now; | ||
var fract = deltat / duration; | ||
var angle = Math.PI * 2 * fract; | ||
cube.rotation.y += angle; | ||
} | ||
|
||
function run() { | ||
requestAnimationFrame(function() { run(); }); | ||
|
||
// Render the scene | ||
renderer.render( scene, camera ); | ||
|
||
// Spin the cube for next frame | ||
// animate(); | ||
|
||
} | ||
|
||
$(document).ready( | ||
function() { | ||
|
||
var canvas = document.getElementById("webglcanvas"); | ||
|
||
// Create the Three.js renderer and attach it to our canvas | ||
renderer = new THREE.WebGLRenderer( { canvas: canvas, antialias: true } ); | ||
|
||
// Set the viewport size | ||
renderer.setSize(canvas.width, canvas.height); | ||
|
||
// Create a new Three.js scene | ||
scene = new THREE.Scene(); | ||
|
||
// Add a camera so we can view the scene | ||
camera = new THREE.PerspectiveCamera( 45, canvas.width / canvas.height, 1, 4000 ); | ||
scene.add(camera); | ||
|
||
// Add a directional light to show off the object | ||
var light = new THREE.DirectionalLight( 0xffffff, 1.5); | ||
|
||
// Position the light out from the scene, pointing at the origin | ||
light.position.set(0, 0, 1); | ||
scene.add( light ); | ||
|
||
// Now, create a Phong material to show shading; pass in the map | ||
var material = new THREE.MeshPhongMaterial({ | ||
color: 0xffffff, wireframe:true }); | ||
|
||
// Create the cube geometry | ||
var geometry = new THREE.CircleGeometry(2, 16); | ||
|
||
// And put the geometry and material together into a mesh | ||
cube = new THREE.Mesh(geometry, material); | ||
|
||
// Move the mesh back from the camera and tilt it toward the viewer | ||
cube.position.z = -8; | ||
|
||
// Finally, add the mesh to our scene | ||
scene.add( cube ); | ||
|
||
// Run the run loop | ||
run(); | ||
} | ||
); | ||
|
||
</script> | ||
|
||
</head> | ||
<body> | ||
|
||
<canvas id="webglcanvas" style="border: none;background-color:#000000" width="500" height="500"></canvas> | ||
|
||
</body> | ||
|
||
</html> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.