# solved 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 on other sites

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 on other sites

right = Cross(up, forward)

##### Share on other sites

Thanks, guys!

@adam, that worked perfectly.  ROCKIN!  Project moving again, yay

##### 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 on other sites

1 minute ago, Pryme8 said:

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

This was under the assumption that the directions are normalized.

##### Share on other sites

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 on other sites

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

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 on other sites

@Pryme8 You can usually use BABYLON.Axis.Y for up.  It depends on your needs, though.

##### 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 on other sites

If the Up() was Up().negate(), then you would be upside down, and the new direction would STILL be leftward, right(ward)?

##### 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 on other sites

Pitch and roll does not affect yaw.    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 on other sites

Yes it does, so you mean to tell me if I pitch up and then yaw right vs roll right and yaw right vs just yawing right Im going to end up in the same points?

No it is all relative.

##### Share on other sites

I'd use the up direction of the airplane mesh.

##### Share on other sites

That is my point, that its all relative and that wingnuts "right" angle will change depending on his point of reference (his up vector) and if he is doing it it locally vs globally.

##### 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 on other sites

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

##### 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 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 on other sites

BABYLON.Vector3.Cross(imp.rotation.multiply(BABYLON.Vector3.Up()), imp.direction),

??

Gruesome.

imp = arrow mesh, of course.  I think that gets it.  Testing to make sure.

##### Share on other sites

Project is working good (although visually 'busy').  Thanks again guys.

##### 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 on other sites

I take that back.  It would look weird when the plane rotates on local z.  Rotating on local x wouldn't be an issue until you go upside down.

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

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.