Sign in to follow this  
Wingnut

Right Angle to a Direction

Recommended Posts

Hi gang.  I have another noob question.

   I have a direction vector (-1, 0, 0).  Let's pretend that is "forward".  (it could be a much more complex direction, too)

If I want to "derive"/calc a LEFT and RIGHT direction... based-upon the first direction, what might be the best way?  Or, ANY way.  :)

Essentially, I need v3.leftFromDirection(firstDirection) and v3.rightFromDirection(firstDirection)

Would that be "left orthogonal" and "right orthogonal"?  I think so.

firstDirection.negate() returns the opposite direction, so that condition is handled.

Can anyone help?  Thx!

Share this post


Link to post
Share on other sites

You need more information.
You need an eye vector, a target/direction vector and an up vector if Im not mistaken... but I might be crazy/dumb.

I think  a * b = |a| *|b|*cos(90deg) = 0, is a thing too for establishing right angles... but I forget how to resolve that when you only have one vector, It should not be to hard though...


>_< this makes me want to go back to school... there was a time where I knew all this off the top of my head.

Share this post


Link to post
Share on other sites

how did you establish your up vector?

what happens when your forward is (0.2, 1000001.2131, 0.0001);

@adam I know the cross product is how you get the right, but what happens when you don't have the up vector just the forward?

Share this post


Link to post
Share on other sites
Just now, adam said:

This was under the assumption that the directions are normalized.

 

Yeah, you would need to normalize it, but Im wondering how to establish the up vector from a weird vector like that to even have something to cross.

Share this post


Link to post
Share on other sites

It works fine, no matter.  I used Cross(BABYLON.Vector3.Up(), firstDirection.negate())  (for a left-aiming direction)

https://www.babylonjs-playground.com/#1ND6TH#35

Line 371 uses P8's value for the top right arrow direction.

In line 401, I call "echoPulsar" with the "left" parameter.  We want to "echo" the upper right arrow... but aiming leftward instead.

Another arrow has been placed on the backside of the red mesh... aiming leftward... when viewed from initial upper-right arrow.

Adam's call is in line 289.  :)  Seems to work.  Ignore the difference in contactPoint/position.  That is expected.

 

 

Share this post


Link to post
Share on other sites

In my mind that makes no sense.  That's working under the assumption that the up direction to the first direction is always 0,1,0. But what if that not really the "up" direction.

@adam That fills in some blanks for me, cool thanks I figured its all relates to your point of reference.

Share this post


Link to post
Share on other sites

I was picturing a spaceship or an airplane, and how as its pitchs and rolls the up vector changes and effects the direction of yaw, so up cant always be 0,1,0 unless you are using a fixed reference point.  Which then the vector's right angle is always in global not local.

Share this post


Link to post
Share on other sites

Pitch and roll does not affect yaw.  :o  If it does, you have a broken airplane. 

Are you thinking about directions... spinning on their z-axis?  Rolled directions?   Yeah, I was there... until I realized that spinning arrows still fly the same direction.

Share this post


Link to post
Share on other sites

Its like Rocket League if anyone plays that game, when you are in ball lock mode your up vector/turn vectors are relative to the ball vs if you are out of ball lock it makes it relative to the camera.

Share this post


Link to post
Share on other sites

So again it comes down to three points your "eye" position, your forward vector and your up vector:

When doing Cross(BABYLON.Vector3.Up(), firstDirection.negate())
your making the assumptions that the eye vector is 0,0,0 and the up is 0,1,0

which limits the number of "right" angles.

Share this post


Link to post
Share on other sites
3 minutes ago, Wingnut said:

Yeah, I should use mesh.rotation.getUp()... errr... something.  :)

YAAAAS!  ^_^ <3

If you want it to be local to the mesh.

if you wanted the "right" to be restricted to one plane the x/z then you would use the global up

Share this post


Link to post
Share on other sites
40 minutes ago, Pryme8 said:

if you wanted the "right" to be restricted to one plane the x/z then you would use the global up

It won't be restricted to one plane.  You would just run into issues when the plane goes upside down.

Share this post


Link to post
Share on other sites

But still, if the camera tilted WITH the plane, or if we were standing on the plane, right would still be right... yes?  Mesh up() tilts WITH the plane.  World up()... maybe not so much so.

(like I have a clue)  :)

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.