Skip to content
Snippets Groups Projects
Commit 8d91c844 authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

finally fixed 3D view flipping

parent 2e74ac56
Branches
No related tags found
No related merge requests found
......@@ -358,7 +358,10 @@ function init_window() {
camera.position.x = mod.x0+Math.sin(mod.thetaz)*mod.r*Math.sin(mod.thetaxy)
camera.position.y = mod.y0+Math.cos(mod.thetaz)*mod.r*Math.sin(mod.thetaxy)
camera.position.z = mod.r*Math.cos(mod.thetaxy)
if (Math.cos(mod.thetaxy) > 0)
camera.up = new THREE.Vector3(Math.sin(mod.thetaz),Math.cos(mod.thetaz),0)
else
camera.up = new THREE.Vector3(-Math.sin(mod.thetaz),-Math.cos(mod.thetaz),0)
camera.lookAt(new THREE.Vector3(mod.x0,mod.y0,0))
camera.updateProjectionMatrix()
renderer.render(scene,camera)
......@@ -381,178 +384,6 @@ function init_window() {
}
}
//
// old_open_view_window
//
function old_open_view_window() {
//
// globals
//
var container,scene,camera,renderer,win,controls
//
// open the window
//
open_window()
//
// open_window
//
function open_window() {
//
// open window
//
win = window.open('')
mod.win = win
//
// load three.js
//
var script = document.createElement('script')
script.type = 'text/javascript'
script.onload = init_window
script.src = 'js/three.js/three.min.js'
mod.div.appendChild(script)
}
//
// init_window
//
function init_window() {
//
// close button
//
var btn = document.createElement('button')
btn.appendChild(document.createTextNode('close'))
btn.style.padding = mods.ui.padding
btn.style.margin = 1
btn.addEventListener('click',function(){
win.close()
mod.win = undefined
})
win.document.body.appendChild(btn)
//
// label text
//
var text = win.document.createTextNode(' left: pan, right: rotate, scroll: zoom')
win.document.body.appendChild(text)
//
// GL container
//
win.document.body.appendChild(document.createElement('br'))
container = win.document.createElement('div')
container.style.overflow = 'hidden'
win.document.body.appendChild(container)
//
// event handlers
//
container.addEventListener('contextmenu',context_menu)
container.addEventListener('mousedown',mouse_down)
container.addEventListener('mouseup',mouse_up)
container.addEventListener('mousemove',mouse_move)
container.addEventListener('wheel',mouse_wheel)
//
// add scene
//
scene = new THREE.Scene()
mod.scene = scene
var width = win.innerWidth
var height = win.innerHeight
var aspect = width/height
var near = 0.1
var far = 1000000
camera = new THREE.PerspectiveCamera(90,aspect,near,far)
mod.camera = camera
scene.add(camera)
//
// add renderer
//
renderer = new THREE.WebGLRenderer({antialias:true})
mod.renderer = renderer
renderer.setClearColor(0xffffff)
renderer.setSize(width,height)
container.appendChild(renderer.domElement)
//
// show the path if available
//
show_path()
}
//
// context_menu
//
function context_menu(evt) {
evt.preventDefault()
evt.stopPropagation()
return (false)
}
//
// mouse_down
//
function mouse_down(evt) {
evt.preventDefault()
evt.stopPropagation()
mod.button = evt.button
mod.x = evt.clientX
mod.y = evt.clientY
}
//
// mouse_up
//
function mouse_up(evt) {
mod.button = undefined
mod.x = evt.clientX
mod.y = evt.clientY
}
//
// mouse_move
//
function mouse_move(evt) {
evt.preventDefault()
evt.stopPropagation()
var dx = evt.clientX-mod.x
var dy = evt.clientY-mod.y
mod.x = evt.clientX
mod.y = evt.clientY
if (mod.button == 0) {
mod.x0 +=
Math.sin(mod.thetaz)*mod.height*dy/win.innerHeight
-Math.cos(mod.thetaz)*mod.width*dx/win.innerWidth
mod.y0 +=
Math.cos(mod.thetaz)*mod.height*dy/win.innerHeight
+Math.sin(mod.thetaz)*mod.width*dx/win.innerWidth
camera.position.x = mod.x0+Math.sin(mod.thetaz)*mod.r*Math.sin(mod.thetaxy)
camera.position.y = mod.y0+Math.cos(mod.thetaz)*mod.r*Math.sin(mod.thetaxy)
camera.position.z = mod.r*Math.cos(mod.thetaxy)
camera.position.z = mod.r*Math.cos(mod.thetaxy)
camera.up = new THREE.Vector3(Math.sin(mod.thetaz),Math.cos(mod.thetaz),0)
camera.lookAt(new THREE.Vector3(mod.x0,mod.y0,0))
camera.updateProjectionMatrix()
renderer.render(scene,camera)
}
else if (mod.button == 2) {
mod.thetaxy += dy/win.innerHeight
mod.thetaz += dx/win.innerWidth
camera.position.x = mod.x0+Math.sin(mod.thetaz)*mod.r*Math.sin(mod.thetaxy)
camera.position.y = mod.y0+Math.cos(mod.thetaz)*mod.r*Math.sin(mod.thetaxy)
camera.position.z = mod.r*Math.cos(mod.thetaxy)
camera.up = new THREE.Vector3(Math.sin(mod.thetaz),Math.cos(mod.thetaz),0)
camera.lookAt(new THREE.Vector3(mod.x0,mod.y0,0))
camera.updateProjectionMatrix()
renderer.render(scene,camera)
}
}
//
// mouse_wheel
//
function mouse_wheel(evt) {
evt.preventDefault()
evt.stopPropagation()
var dy = evt.deltaY/win.innerHeight
mod.r += mod.height*dy
camera.position.x = mod.x0+Math.sin(mod.thetaz)*mod.r*Math.sin(mod.thetaxy)
camera.position.y = mod.y0+Math.cos(mod.thetaz)*mod.r*Math.sin(mod.thetaxy)
camera.position.z = mod.r*Math.cos(mod.thetaxy)
camera.lookAt(new THREE.Vector3(mod.x0,mod.y0,0))
camera.updateProjectionMatrix()
renderer.render(scene,camera)
}
}
//
// return values
//
return ({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment