Jump to content

SOLVED: LookAt() -> opposite direction?


JackFalcon
 Share

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

Link to comment
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

Link to comment
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!

Link to comment
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/>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...