Commit d704c4dede26006e70b8531db09149180709d658
- Diff rendering mode:
- inline
- side by side
index.html
(34 / 20)
  | |||
23 | 23 | <input type="button" id="flipleft" value="flipLeft" /> | |
24 | 24 | <br /> | |
25 | 25 | <input type="button" id="flipright" value="flipRight" /> | |
26 | <br /> | ||
27 | <input type="button" id="magnify" value="Magnify Off"/> | ||
26 | 28 | </div> | |
27 | 29 | <div id="container" style="position:relative;margin:0 auto;padding:0;z-index:0;cursor:pointer;"></div> | |
28 | 30 | <script> | |
29 | 31 | var container; | |
30 | 32 | var camera, scene, renderer, projector, clock, mag_cam; | |
33 | var clientX, clientY, magnify = false; | ||
31 | 34 | ||
32 | 35 | var targetRotationY = 0; | |
33 | 36 | var targetRotationOnMouseDownY = 0; | |
34 | 37 | var targetRotationX = 0; | |
35 | 38 | var targetRotationOnMouseDownX = 0; | |
36 | var rad=700; | ||
39 | var rad = 200; | ||
37 | 40 | var mouse={x:0,y:0}; | |
38 | 41 | var mouseX = 0; | |
39 | 42 | var mouseXOnMouseDown = 0; | |
… | … | ||
47 | 47 | var windowHalfY = window.innerHeight / 2; | |
48 | 48 | var w,h,w2,h2; | |
49 | 49 | var book, test_book; | |
50 | var pagew=300; | ||
51 | var pageh=pagew*10/7; | ||
50 | var pagew = 80; | ||
51 | var pageh = pagew * 10/7; | ||
52 | 52 | var fl,fr; | |
53 | 53 | ||
54 | 54 | var max_allowed_pages = 20; | |
… | … | ||
137 | 137 | book.pages[book.flippedleft-1].flipRight() | |
138 | 138 | prefetch(); | |
139 | 139 | }); | |
140 | var mag = document.getElementById('magnify'); | ||
141 | mag.addEventListener('click', function(event) { | ||
142 | if(magnify == true) { | ||
143 | mag.value = "Magnify Off"; | ||
144 | magnify = false; | ||
145 | } | ||
146 | else { | ||
147 | mag.value = "Magnify On"; | ||
148 | magnify = true; | ||
149 | } | ||
150 | }); | ||
140 | 151 | } | |
141 | 152 | ||
142 | 153 | function prefetch() { | |
143 | 154 | var pageno = book.flippedleft * 2; | |
144 | console.log('page no ', pageno); | ||
145 | 155 | if(test_book.pages < max_allowed_pages) { | |
146 | 156 | return; | |
147 | 157 | } | |
… | … | ||
209 | 209 | } | |
210 | 210 | ||
211 | 211 | function onMousemoveForMag(event) { | |
212 | clientX = event.clientX; | ||
213 | clientY = event.clientY; | ||
212 | 214 | var mousex = ((event.clientX / w) * 2 - 1); | |
213 | 215 | var mousey = - ((event.clientY / h) * 2 - 1); | |
214 | var vec = new THREE.Vector3(mousex, mousey, 0.5); | ||
215 | console.log(mousex, mousey); | ||
216 | var vec = new THREE.Vector3(mousex, mousey, 0); | ||
216 | 217 | projector.unprojectVector(vec, camera); | |
217 | 218 | var raycaster = new THREE.Raycaster(camera.position, vec.sub(camera.position).normalize()); | |
219 | //var intersects = raycaster.intersectObjects(book.pages, true); | ||
218 | 220 | var intersects = raycaster.intersectObject(book, true); | |
219 | 221 | if(intersects.length) { | |
220 | //console.log(intersects); | ||
221 | //var intersected = intersects[0].object; | ||
222 | //console.log(intersected); | ||
223 | //mag_cam.position.copy(intersected.position); | ||
224 | //mag_cam.lookAt(intersected.position); | ||
225 | mag_cam.position.set(0 * book.pageWidth,0 * book.pageHeight, 60); | ||
226 | //console.log(mousex * book.pageWidth, mousey * book.pageHeight); | ||
227 | //console.log(book.pageWidth, book.pageHeight); | ||
228 | //mag_cam.position.set(0,0, 60); | ||
229 | //console.log(book.position); | ||
222 | var pos = intersects[0].point; | ||
223 | //console.log(camera.position); | ||
224 | //var dir_vec = vec.sub(camera.position).normalize(); | ||
225 | //console.log(dir_vec); | ||
226 | //var ray = new THREE.Raycaster(camera.position, dir_vec); | ||
227 | //var distance = -camera.position.z / dir_vec.z; | ||
228 | //var pos = camera.position.clone().add(dir_vec.multiplyScalar(distance)); | ||
229 | //console.log(pos); | ||
230 | mag_cam.position.set(pos.x+25, pos.y, 10); | ||
230 | 231 | } | |
231 | 232 | } | |
232 | 233 | ||
… | … | ||
244 | 244 | targetRotationY=mouseX; | |
245 | 245 | mouseY=(( event.clientY / h ) * 2 - 1); | |
246 | 246 | targetRotationX=mouseY; | |
247 | console.log(mouseX, mouseY); | ||
248 | 247 | } | |
249 | 248 | ||
250 | 249 | function onDocumentMouseUp( event ) { | |
… | … | ||
282 | 282 | renderer.render( scene, camera); | |
283 | 283 | ||
284 | 284 | // right side | |
285 | renderer.setViewport(SCREEN_WIDTH - 300, 50, 200, 200 ); | ||
286 | renderer.render( scene, mag_cam); | ||
285 | if(magnify) { | ||
286 | renderer.setViewport(SCREEN_WIDTH - 300, 50, 200, 200); | ||
287 | renderer.render( scene, mag_cam); | ||
288 | } | ||
287 | 289 | ||
288 | 290 | } | |
289 | 291 | ||
… | … | ||
296 | 296 | camera.position.x = rad * Math.sin( targetRotationY*multy ) * Math.cos( targetRotationX*multx ); | |
297 | 297 | camera.position.y = rad * Math.sin( targetRotationX*multx ); | |
298 | 298 | camera.position.z = rad * Math.cos( targetRotationY*multy ) * Math.cos( targetRotationX*multx ); | |
299 | //controls.update(clock.getDelta()); | ||
300 | 299 | camera.lookAt(scene.position); | |
301 | 300 | render2(); | |
302 | 301 | } |
js/FlipBook3D.js
(1 / 1)
  | |||
65 | 65 | this.isFlippedRight=true; | |
66 | 66 | this.flippingLeft=false | |
67 | 67 | this.flippingRight=false; | |
68 | this.zz=2; | ||
68 | this.zz=1; | ||
69 | 69 | this.pageColor=col; | |
70 | 70 | this.sides={bottom:3,top:2, right:0,left:1, front:4,back:5}; | |
71 | 71 |