2014-04-15 2 views
0

앞에 Z의 좌표 :Three.js를 2D X, 3D X, Y로 Y의 좌표, 나는이 질문을 검토 한 항상 카메라

Mouse/Canvas X, Y to Three.js World X, Y, Z

내 코드에서 구현의 문제는 다른 사람들이 진술 한대로 작동하지 않는 것 같습니다.

반드시 마우스가 아닌 X 및 Y 화면 코드를 통해 카메라 앞에 객체를 배치해야합니다.

이 개체는 미리 정의 된 최대 거리 또는 계산 된 개체 거리에서 카메라 앞의 지정된 거리에 있습니다. 링크 된 질문과 매우 유사하다 당신이 볼 수 있듯이 아직

this.reticlePos.x = 500; 
this.reticlePos.y = 300; 
this.reticlePos.z = 0.5; 

this.projector.unprojectVector(this.reticlePos, this.camera); 

//check for collisions, if collisions set distance to collision distance 
var distance = this.RETICLE_RADIUS; 

var direction = new THREE.Vector3(0, 0, -1); 
direction.applyQuaternion(this.camera.quaternion); 

this.rayCaster.set(this.camera.position, direction); 
var collisionResults = this.rayCaster.intersectObjects(this.sceneController.obstacles); 

if(collisionResults.length !== 0) { 
    // console.log('Ray collides with mesh. Distance :' + collisionResults[0].distance); 
    distance = collisionResults[0].distance - 20; 
} 

// set the reticle position 
var dir = this.reticlePos.clone().sub(this.camera.position).normalize(); 

var pos = this.camera.position.clone().add(dir.multiplyScalar(distance)); 

this.reticleMesh.position.copy(pos); 

:

참고 : 내 카메라 내 장면에서 어떤 위치에 있어야하고 어떤 방향 여기

에 직면하는 것은 내 코드입니다 수 있습니다 카메라 앞에서 물건을 볼 수 없습니다.

이것에 대한 통찰력은 크게 감사하겠습니다.

답변

1

나중에이 질문을 확인하는 사람은 내 자신을 알아 냈습니다. 이 작업을 수행 한 후

this.reticlePos.x = (this.reticlePos.x/window.innerWidth) * 2 - 1; 
this.reticlePos.y = - (this.reticlePos.y/window.innerHeight) * 2 + 1; 

가 :

내 화면이 나는 자이로 스코프에서 일부 입력 데이터를 변환하는 데 필요한 좌표를 얻으려면, 그리고 좌표 나는 여전히 내 계산 화면에 다음을 할 필요 몰랐어요 모든 것이 예상대로 작동합니다.

관련 문제