-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
FirstPersonControls: Added .lookAt() #15650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Wow, this is literally the exact thing that's been bugging me for the last half hour. Perfect timing 😀 |
|
Wonderful! 👍 |
| this.verticalMax = Math.PI; | ||
|
|
||
| this.autoSpeedFactor = 0.0; | ||
| this.forward = new THREE.Vector3( 0, 0, - 1 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the user changes this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the forward vector is differently. This is necessary if the user passes a ordinary Object3D to the controls. It would be ( 0, 0, 1 ).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe FirstPersonControls is designed to control a camera, so this vector can be hardwired into your method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if used to control other object, it becomes ThirdPersonControls :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe FirstPersonControls is designed to control a camera
Why put a limit on what it can control, if it's as simple as exposing this.forward?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@looeee Absolutely!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's more or less a WebGL/OpenGL convention. (0,0,1) for ordinary objects and (0,0,-1) for cameras, see https://stackoverflow.com/questions/33407209/why-does-the-camera-face-the-negative-end-of-the-z-axis-by-default?rq=1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@looeee I have hardwired the forward vector for now since the controls do not fully support arbitrary objects yet (too bad), see https://jsfiddle.net/q50o1r97/1/. If there is any interest in changing this, I suggest to do this with a separate PR. Same for renaming object to camera in control classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mugen87 OK, but I think it would be good to have clarity on this. Either we do support controlling arbitrary objects with controls, or we don't.
If we do, then it should be noted somewhere - even just as a comment in the files.
If we don't, then we can just rename object to camera.
I'm OK with either.
|
Sorry, I do not see how this can work. It is also not consistent with the three.js API. Are you saying you can't call Is I hope that is the intention -- users should not be setting the camera behind the back of the controls. The proper solution is to make |
No, it's just an example.
You can also call it after initializing the controls.
It worked perfectly on my computer. I think the stackoverflow posts show that there is a demand for action. So your attitude seems a bit counterproductive to me. |
|
In the pattern you are suggesting: camera.lookAt( targetPosition );
controls.setOrientation( camera.quaternion );you are setting the camera orientation, and then telling the controls to set the camera orientation. That is what bothers me... Instead, you can inline If you prefer an exposed method, then adding the following, instead, makes sense to me: controls.lookAt( targetPosition );The second one may be more useful. In either case, you can leverage your proposed code. |
|
@WestLangley they suggested the method rather than inline code because someone might want to change the camera direction after the controls were activated.
apparently users do not think so :) |
|
Let the controls control the camera. controls.lookAt( targetPosition ); |
|
I've had a chance to test this. It's an improvement IMO, but what I would prefer (and what I believe the other controls do) is to respect the camera's orientation and position at the time when the controls are instantiated. If I do: camera.lookAt( someObject.position );
const controls = new FirstPersonControls( camera );The current behaviour is that the camera jumps to a new and unexpected orientation. |
|
|
|
I'll make a note in the migration guide about the changes related to |
|
BTW: I have noticed that |
|
Thanks! |
|
I think we should update the stackoverflow posts, right? |
Fixed #15629