Wingnut Posted December 15, 2017 Share Posted December 15, 2017 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! JackFalcon 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted December 15, 2017 Share Posted December 15, 2017 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. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
adam Posted December 15, 2017 Share Posted December 15, 2017 right = Cross(up, forward) JackFalcon and Wingnut 2 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 15, 2017 Author Share Posted December 15, 2017 Thanks, guys! @adam, that worked perfectly. ROCKIN! Project moving again, yay Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted December 15, 2017 Share Posted December 15, 2017 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? Quote Link to comment Share on other sites More sharing options...
adam Posted December 15, 2017 Share Posted December 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted December 15, 2017 Share Posted December 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 15, 2017 Author Share Posted December 15, 2017 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. Pryme8 and JackFalcon 2 Quote Link to comment Share on other sites More sharing options...
adam Posted December 15, 2017 Share Posted December 15, 2017 @Pryme8 You can usually use BABYLON.Axis.Y for up. It depends on your needs, though. Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted December 15, 2017 Share Posted December 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 15, 2017 Author Share Posted December 15, 2017 If the Up() was Up().negate(), then you would be upside down, and the new direction would STILL be leftward, right(ward)? Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted December 15, 2017 Share Posted December 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 15, 2017 Author Share Posted December 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted December 15, 2017 Share Posted December 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
adam Posted December 15, 2017 Share Posted December 15, 2017 I'd use the up direction of the airplane mesh. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted December 15, 2017 Share Posted December 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted December 15, 2017 Share Posted December 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 15, 2017 Author Share Posted December 15, 2017 Yeah, I should use mesh.rotation.getUp()... errr... something. Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted December 15, 2017 Share Posted December 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted December 15, 2017 Share Posted December 15, 2017 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 Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 15, 2017 Author Share Posted December 15, 2017 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. Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 15, 2017 Author Share Posted December 15, 2017 https://www.babylonjs-playground.com/#1ND6TH#38 Project is working good (although visually 'busy'). Thanks again guys. Quote Link to comment Share on other sites More sharing options...
adam Posted December 15, 2017 Share Posted December 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
adam Posted December 15, 2017 Share Posted December 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 15, 2017 Author Share Posted December 15, 2017 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) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.