Skip to content

Conversation

@Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Jan 27, 2019

Fixed #15629

@looeee
Copy link
Collaborator

looeee commented Jan 27, 2019

Wow, this is literally the exact thing that's been bugging me for the last half hour. Perfect timing 😀

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Jan 27, 2019

Wonderful! 👍

this.verticalMax = Math.PI;

this.autoSpeedFactor = 0.0;
this.forward = new THREE.Vector3( 0, 0, - 1 );
Copy link
Collaborator

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?

Copy link
Collaborator Author

@Mugen87 Mugen87 Jan 27, 2019

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 ).

Copy link
Collaborator

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.

Copy link
Contributor

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 :)

Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@looeee Absolutely!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@looeee @Mugen87 I think the proper question is why the hell forward needs to be different for camera vs other objects? Why can't it just be 0,0,-1 for everything?

Copy link
Collaborator Author

@Mugen87 Mugen87 Jan 28, 2019

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

Copy link
Collaborator Author

@Mugen87 Mugen87 Jan 28, 2019

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.

Copy link
Collaborator

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.

@WestLangley
Copy link
Collaborator

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 setOrientation() without calling camera.lookAt() first?

Is camera.lookAt() and setOrientation() supposed to be called only once prior to initializing the controls?

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 setOrientation() private, and to set the camera orientation in the controls constructor.

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Jan 27, 2019

Are you saying you can't call setOrientation() without calling camera.lookAt() first?

No, it's just an example.

Is camera.lookAt() and setOrientation() supposed to be called only once prior to initializing the controls?

You can also call it after initializing the controls.

Sorry, I do not see how this can work. It is also not consistent with the three.js API.

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.

@WestLangley
Copy link
Collaborator

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 setOrientation(), and set the camera orientation in the controls constructor. Doing so would be consistent with the OP's request in #15629.

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.

@makc
Copy link
Contributor

makc commented Jan 27, 2019

@WestLangley they suggested the method rather than inline code because someone might want to change the camera direction after the controls were activated.

users should not be setting the camera behind the back of the controls

apparently users do not think so :)

@WestLangley
Copy link
Collaborator

Let the controls control the camera.

controls.lookAt( targetPosition );

@looeee
Copy link
Collaborator

looeee commented Jan 28, 2019

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.
With this change, I can now do controls.setOrientation( camera.quaternion ) to fix this, which is an improvement. But I'd rather that just happens automatically, which again, I think is the case for other controls.

@Mugen87 Mugen87 changed the title FirstPersonControls: Added .setOrientation() FirstPersonControls: Added .lookAt() Jan 28, 2019
@Mugen87
Copy link
Collaborator Author

Mugen87 commented Jan 28, 2019

FirstPersonControls.lookAt() sounds good! I have changed the PR and also implemented @looeee's suggestion. setOrientation() is now a private function and called in the ctor. This means it's now possible to respect the original orientation of the camera.

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Jan 28, 2019

I'll make a note in the migration guide about the changes related to FirstPersonControls when this gets merged.

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Jan 28, 2019

BTW: I have noticed that FirstPersonControls.constrainVertical has somewhat a confusing effect when using .lookAt(). It alters the value of phi and thus the result of .lookAt(). I mean it produces the expected result but users should aware about this fact when setting constrainVertical to true.

@mrdoob mrdoob added this to the r101 milestone Jan 28, 2019
@mrdoob mrdoob merged commit 2451173 into mrdoob:dev Jan 28, 2019
@mrdoob
Copy link
Owner

mrdoob commented Jan 28, 2019

Thanks!

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Jan 28, 2019

I think we should update the stackoverflow posts, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants