in Education by
I created a raycaster that allows me to pick an object from the scene with my mouse like such: this.raycaster = new THREE.Raycaster() // then in onMouseDown event this.raycaster.setFromCamera(this.mouse, this.camera) let intersects = this.raycaster.intersectObjects(this.scene.children) It works as expected when I translate the camera and when I yaw the camera, however, once I pitch the camera, the raycaster intersects the object away from where the object is rendered on screen. If I look above the object, the raycaster intersects the object above where it is rendered. If I look below the object, the raycaster intersects the object below where it is rendered. this.yaw = new THREE.Object3D() this.pitch = new THREE.Object3D() this.camera = new THREE.PerspectiveCamera(70, this.width / this.height, 0.01, 50) this.yaw.add(this.pitch.add(this.camera)) this.scene = new THREE.Scene().add(this.yaw) // then in onMouseMove event if (this.state === this.STATE.PAN) { this.yaw.translateX(-this.mouseDelta.x) this.yaw.translateZ(-this.mouseDelta.y) } if (this.state === this.STATE.ROTATE) { this.yaw.rotation.y -= this.mouseDelta.x this.pitch.rotation.x -= this.mouseDelta.y } I tried disabling all transformations except the pitch and the problem still persists. I think the problem may be with the raycaster and not the objects themselves, as it wouldn't make sense for the objects to render in one location but be intersected in another. What am I doing wrong? Is the raycaster maybe not casting from the camera's origin after rotating? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The raycaster was detecting an intersection when I clicked above the object while pointing the camera above the object because the mouse.y coordinates were not normalized correctly. // Incorrect this.mouse.y = (e.clientY / window.innerHeight) * 2 - 1 // Correct this.mouse.y = -(e.clientY / window.innerHeight) * 2 + 1 By excluding the negation, my mouse.y position was effectively mirrored within the scene. So if I clicked the top most point of the scene, the raycaster would be mirrored to detect intersections at the bottom most point of the scene. This wasn't an issue when there was no pitching because I was testing on box geometry placed level to the camera. Thus any mirroring done onto the raycaster would still detect a collision since the geometry was symmetric.

Related questions

0 votes
    This question already has answers here: How to split a string with angularJS (4 answers) Closed 5 years ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: How to split a string with angularJS (4 answers) Closed 5 years ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: How to split a string with angularJS (4 answers) Closed 5 years ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 19, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: When to use ":"(colon) operator in javascript vs "=" operator ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: When to use ":"(colon) operator in javascript vs "=" operator ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I'm trying to use the sensor's API with react and I can't seen to be able to make it work ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I'm trying to use the sensor's API with react and I can't seen to be able to make it work ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
0 votes
    I have a function that has more than 1400+ crypto pairs and I have to send an API against each ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 5, 2022 in Education by JackTerrance
0 votes
    is there a way to validate the pattern of an input by it's event object (without using a form)? ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 5, 2022 in Education by JackTerrance
0 votes
    is there a way to validate the pattern of an input by it's event object (without using a form)? ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    Course Results (${courseResponseList.getCourses().size()}) Want to show above div. jquery script. jQuery. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    The user gives various entries in the fields. Then when he pushes the create button I wrote a function ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    Course Results (${courseResponseList.getCourses().size()}) Want to show above div. jquery script. jQuery. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    The user gives various entries in the fields. Then when he pushes the create button I wrote a function ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    This question already has an answer here: Object.assign getters and setters in constructor (1 answer) Closed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
...