我想绕X轴相机在YZ平面上,同时寻找在(0, 0, 0)
点。 原来, lookAt
函数的行为怪异。 当旋转180°,几何跳到另一侧意外之后。 你能解释一下为什么出现这种情况,以及如何避免呢?
你可以看到的jsfiddle的现场演示: http://jsfiddle.net/ysmood/dryEa/
class Stage
constructor: ->
window.requestAnimationFrame =
window.requestAnimationFrame or
window.webkitRequestAnimationFrame or
window.mozRequestAnimationFrame
@init_scene()
@make_meshes()
init_scene: ->
@scene = new THREE.Scene
# Renderer
width = window.innerWidth;
height = window.innerHeight;
@renderer = new THREE.WebGLRenderer({
canvas: document.querySelector('.scene')
})
@renderer.setSize(width, height)
# Camera
@camera = new THREE.PerspectiveCamera(
45, # fov
width / height, # aspect
1, # near
1000 # far
)
@scene.add(@camera)
make_meshes: ->
size = 20
num = 1
geo = new THREE.CylinderGeometry(0, size, size)
material = new THREE.MeshNormalMaterial()
mesh = new THREE.Mesh(geo, material)
mesh.rotation.z = Math.PI / 2
@scene.add(mesh)
draw: =>
angle = Date.now() * 0.001
radius = 100
@camera.position.set(
0,
radius * Math.cos(angle),
radius * Math.sin(angle)
)
@camera.lookAt(new THREE.Vector3())
@renderer.render(@scene, @camera)
requestAnimationFrame(@draw)
stage = new Stage
stage.draw()