Sign in to follow this  
aFalcon

SOLVED: LookAt() -> opposite direction?

Recommended Posts

Hi @aFalcon

Here ya go,

 // Opposite Direction ?
    var lookAtOppositeDirection = true;
    // All rotations or just Y ?
    var negateAllRotations = true;

        scene.onPointerDown = function(evt, pick){
            if(!pick || !pick.hit) return;
            box.lookAt(pick.pickedPoint);

            if(lookAtOppositeDirection){
                if(negateAllRotations){
                    // Opposites all rotations,  x y and z.
                    // e.g. if looking downwards, 
                    // after negate it will look upwards in the opposite direction, 
                    // (visual is same since it's a box.)
                    box.rotation.negate();
                }
                else {
                    // Opposites only rotation y.
                    // e.g. if looking downwards towards x 1,
                    // after, it will look downwards towards x -1.
                    box.rotation.y -= Math.PI;
                }
                
            }
        };

Note; it won't work with rotationQuaternions, i don't use them, so don't know the correct values/calculations to use.

http://playground.babylonjs.com/#CTW4AI#1

Share this post


Link to post
Share on other sites

:)  Love it!

Adam reminded me of something, the other day.  Stare at this for a minute or two.

http://doc.babylonjs.com/classes/3.0/abstractmesh#lookat-targetpoint-yawcor-pitchcor-rollcor-space-rarr-abstractmesh-classes-3-0-abstractmesh-

One might ponder what this would do:   pitchCor = yawCor = rollCor = Math.PI;  I think that would change lookAt()... into lookAwayFrom().  Right?  Maybe not.

Hope this doesn't step on any toes.  If so, Adam did it, not me.  :D

Share this post


Link to post
Share on other sites

You could just look at the opposite point:

let diff = target.position.subtract(mesh.position);
let opposite = mesh.position.add(diff.scale(-1));
mesh.lookAt(opposite);

 

Edited by Gijs
Fixed code

Share this post


Link to post
Share on other sites
14 hours ago, Gijs said:

let diff = target.position.subtract(mesh.position);
let opposite = mesh.position.add(diff.scale(-1));
mesh.lookAt(opposite);

Wow.  That's just... something.  :)  mesh.position.add(diff.scale(-1));  Interesting!

Stuff like that... requires that special world-space math gene.  I don't have one of those.  :D

There's stuff to be learned, there.  Cool.  The rollcor/pitchcor/yawcor = Math.PI... that version is still shorter, but i never tested if it actually works.

aWeirdo's box.rotation.negate() is a pretty interesting idea, too.   All you guys are too cool!

Share this post


Link to post
Share on other sites

Hi @aWeirdo, I see you do great work. Thanks n stuff...

Quaternions. Yay! Yeah, not too much: yaw, pitch, rollin'.... here. :)

Aaand it worked. Thx!

 

Following a motion path... and needed to look the other way!

[Kinda like my life... Jk]; 

 

hooray for negate()!!! Wait, what? negate(that); //something...

[Lolzzz. Back to work!]

 

Hi, @Gijs great @handle. Fun typing. Cool use of add() subract()...and scale()? Oh. Note to self: experiment ... Thx!

 

@Wingnut ya mon, scale(-1);  thanks for pointing that out! -->

Q: your scale is - what now? A: -1. [oh really, great.].

Brain inverts. And mind is erased. Moving on...

"world-space math gene" - heard about that!

-->The magic beans jack used to grow a beanstalk into the clouds, right?

Yeah, Math beans...? Where do we get the MathBeans!?!

:)  magic right? Oh.... maagic! Wink.

[falcon stuffs  "rollcor/pitchcor/yawcor = Math.PI" in pocket].

Thx ... [cool stuff].

Ok, bye guys...

<jokes-not-removed/>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.