Look at #2328

Closed
wants to merge 2 commits into
from

Conversation

4 participants
Contributor

gero3 commented Aug 16, 2012

Add easy methods to Object3D for lookAt: lookAtWorld and lookAtObject

This is implementation + documentation in 2 different commits

Collaborator

WestLangley commented Aug 16, 2012

I don't believe these routines will work if the object doing the looking has a rotated parent.

Do we care, though?

Contributor

gero3 commented Aug 16, 2012

hmm, good find.

Didn't think of that.
I'll have a look at ( ;) ) it when I get ray finished.

Contributor

gero3 commented Aug 17, 2012

@mrdoob

What should we do with this one?? It is correct what @WestLangley says about the fact that this is a problem with a rotated parent.

Owner

mrdoob commented Aug 17, 2012

Wouldn't the solution be something like this?

lookAtObject = function ( object ) {

    var matrix = new THREE.Matrix4().getInverse( this.matrixWorld );
    var target = object.matrixWorld.getPosition();
    inverse.multiplyVector3( target );

    this.matrix.lookAt( target, new THREE.Vector3(), this.up );

    if ( this.rotationAutoUpdate ) {

        this.rotation.setEulerFromRotationMatrix( this.matrix, this.eulerOrder );

    }

}
Collaborator

WestLangley commented Aug 17, 2012

Well, object.lookAt() and camera.lookAt() do not work if the object or camera have a rotated parent, either. So we probably should decide if we want to deal with those issues first.

Owner

mrdoob commented Aug 17, 2012

That's why I named it lookAtObject because in order to do it properly you need to have access to both matrixWorlds, which lookAt() can't do because it expects a vector.

@gero3 You probably meant this:

lookAtObject: function( obj ) {
    this.lookAt(this.worldToLocal(obj.matrixWorld.getPosition()));
},

But, as we discussed, it still does not support rotated parents.

Collaborator

WestLangley commented Aug 17, 2012

@mrdoob

  1. Do you want to add hierarchical support to object.lookAt() and camera.lookAt()?
  2. Are you thinking that @gero3's routines would replace, or be in addition to, object.lookAt()?
Owner

mrdoob commented Aug 17, 2012

Depends of how expensive is the new calculation. If it's the same as the current lookAt (unlikely), then we can replace it. Otherwise, better creating a new lookAtObject method.

Contributor

zz85 commented Aug 29, 2012

hmm... does this seem like a continued discussion of #1752?

how is it going along? lookAt lookAtWorld lookAtObject might be useful.

@gero3 gero3 closed this Jan 10, 2013

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