max123 Posted November 21, 2016 Share Posted November 21, 2016 Given position and rotation Vector3-s, how do you convert to cartesian? I've found a C++ solution, but I get strange results in BJS Quote Link to comment Share on other sites More sharing options...
max123 Posted November 21, 2016 Author Share Posted November 21, 2016 Here's a PG to demonstrate what I'm after http://www.babylonjs-playground.com/#1NE4XO Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 21, 2016 Share Posted November 21, 2016 hehe... you and getzel are working on lookAt and billboardMode at the same time. Getz is wondering why lookAt and billboardMode use only Quats and don't report in Euler at mesh.rotation property... like camera.rotation does with a set .target does. Protractor ops. ANYWAY... all that crap aside... I have some stolen SC/Cartesian stuff in: http://www.babylonjs-playground.com/#J6ZLH#3 See lines 45-57. It is used in the particle system custom start-position function in lines 10-16. It makes the dome-o-particles. Not my code. Creds included in source. Hope this helps. Quote Link to comment Share on other sites More sharing options...
max123 Posted November 21, 2016 Author Share Posted November 21, 2016 Tried your suggestion, @Wingnut, but still no joy.. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 21, 2016 Share Posted November 21, 2016 Ok, let's look at this nightmare playground you have going here. Not sure why you are wanting spherical coordinates... but let's see if my little mind can figure this out, or beg to the correct forum helpers. http://www.babylonjs-playground.com/#1NE4XO#1 I didn't change much of anything. I just started studying your ray. Every time I have used rays, I follow it with a scene.pickWithRay... but that is just used to gather a wrapper called pickingInfo/pickInfo. So, I thought about your custom ray. There is lots of contorted math going-on in the ray2 function. All of it is over my head... but, I guess that is where you wanted to use spherical coords. It's all algebraically cool with me. heh Here is one small thing that my pee brain saw, though. var r2 = new Ray2(box.position, box._rotationQuaternion.toEulerAngles(), scene); Hmm. Are you trying to get the direction a mesh is facing, using its gotten-from-quat euler .rotation value? I'm no pro, but doesn't the 2nd param need to be a direction instead of an orientation? Do you possibly need to use the rotation values... to calculate a "forward vector" first, and then use THAT as the ray's 2nd param? Possibly, you need to convert a rotation, to a direction? This crap makes my brain hurt, but I'll do guessing with the best of 'em, too. I don't mind embarrassing myself in public. Hopefully, smarter people will comment, soon. Quote Link to comment Share on other sites More sharing options...
max123 Posted November 21, 2016 Author Share Posted November 21, 2016 What I'm trying to do here is to visualize a Ray. Since my math is abysmal, doing so will help me (and hopefully other mathematically-challenged devs) see if my Rays are indeed going in the direction I intend them to go. BTW, you've lost me on direction vs orientation question... Aren't they the same thing? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 21, 2016 Share Posted November 21, 2016 Hello to visualize a ray, you can use (like in your example) CreateLines. But beware, the function requires points and not direction so: var line = BABYLON.Mesh.CreateLines("rayLine", [ray.origin, ray.origin.add(ray.direction)], scene); Quote Link to comment Share on other sites More sharing options...
max123 Posted November 21, 2016 Author Share Posted November 21, 2016 Thanks @Deltakosh, this is what I get though:http://www.babylonjs-playground.com/#1NE4XO#2 I must be doing something stupid Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 21, 2016 Share Posted November 21, 2016 Rotation in your example is not a direction. It is just 3 angles. It is like I'd say: - Go to the north west (it is a direction, I can point to it) OR - Turn 80 degree on the left (It is a rotation) Both can represent the same thing but cannot be exchanged max123 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 21, 2016 Share Posted November 21, 2016 Here is better approach: http://www.babylonjs-playground.com/#1NE4XO#3 Wingnut and max123 2 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 21, 2016 Share Posted November 21, 2016 [Wingy hugs transformNormal... cuz Deltakosh saved Wingy's big fat project... with that, years ago.] When you make a spacecraft... using physics applyImpulse vernier thrusters for 3-axis attitude control, you need transformNormal MUCH. The spacecraft can get Quat-rotated in any strange orientation, but when it comes time to TRANSLATE (position, not rotation)... you want the thrust to come directly out of the side, bottom, front/back... of the spacecraft. The needed force-vector for .positional impulsings... needs to be transformed by the current craft.rotationQuaternion... or else the positioning thrusts won't happen in the correct direction. http://www.html5gamedevs.com/topic/20350-moving-and-rotate-a-physic-object-from-a-newbie/?do=findComment&comment=115583 A little talk about my flyer. (snore). Top section of code... looks similar to DK's solution... transformNormal. (yay) Designed specifically for keeping ducks in a row. Keepin' ya squared-up with your locals. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
max123 Posted November 22, 2016 Author Share Posted November 22, 2016 Thanks, @Deltakosh! It's working... Almost Here's another PG: http://www.babylonjs-playground.com/#1NE4XO#11 If you look at line 32, the function r2.getRay().intersectsBox(b2._boundingInfo.boundingBox) returns false for some reason. On the side note, I think the title of this topic is now misleading; it would be useful for others of mods renamed it to smth like "Rays/rotations/directions" Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 22, 2016 Share Posted November 22, 2016 Hi Max and fellow campfire projecteers. http://www.babylonjs-playground.com/#1NE4XO#12 Watch console. It appears that your white lines are not aligned with your ray. Ya got a little troubleshooting still to do. Good luck. Cool project, by the way... I really like it. I can foresee a future Babylon.Tools.showRayLines(ray) ... feature. Soon, you're going to earn your "BJS Core Contributor" merit badge. Quote Link to comment Share on other sites More sharing options...
max123 Posted November 22, 2016 Author Share Posted November 22, 2016 You're right, @Wingnut, my rays are still pointing at my arse Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 22, 2016 Share Posted November 22, 2016 "Tie me picking ray down, sport... tie me picking ray down." Good news, for ya. Rumor has it that you already got your BJS Core Contributor merit badge... because you got "co-creator" rating on the new multi-picking feature. Congrats! Max: a cleaner solution would be an all-penetrating ray returning an array of pickedMesh objects ordered on hit-first basis. Deltakosh: Please let me introduce: scene.multiPick and scene.multiPickWithRay: http://www.babylonjs-playground.com/#7CPS7 You guys rock! Thanks to you both! Well done. I got CC merit badge with light.setDirectionToTarget() ... line 70 here. I didn't code it, but it was something I needed, and I found the solve on the web. Then Deltakosh asked if "we" could use it for core, and I was SO PROUD that I nearly died! (I'm a bit of a simpleton - I get excited over little things, sometimes.) heh. (Wingy uses a power buffer and a little Carnauba wax on your shiny new badge.) Quote Link to comment Share on other sites More sharing options...
max123 Posted November 22, 2016 Author Share Posted November 22, 2016 Ha-ha, I'm hardly a "co-creator" - it was Delta who implemented the whole shebang, - but thanks!! Back to the ray... It looks like it returns "false" where it should return "true" because box2 is moved: if comment out line 25 b2.position.x = -2; then everything works as expected. Is there a way to tell BJS's engine "hey, the position of this bloody box has changed. can you now update yourself please and stop using the old pos for calculations?" Quote Link to comment Share on other sites More sharing options...
Wingnut Posted November 22, 2016 Share Posted November 22, 2016 Ahh, but are you assuming something, here? Even when the thing was clearly not working right... you were getting TRUE when the white lines shoot straight down. Now you move the box to directly under the white lines, and suddenly... you think the ray is working correctly. But really, its doing exactly the same thing... showing true when white lines aim -Y-ish. I would look for a problem with your ray never getting aimed at all, and thus stuck in straight down condition. *shrug* I think ray direction != white lines. Ya know... your project is really a two-piece thing. One piece is... view a direction vector as a linesMesh with arrowhead with vector magnitude==line length. The other piece is "playing with rays" But direction vectors... really don't have an origin, right? No starting point, but their ending point is magnitude away-from its starting point... which doesnt exist. Quote Link to comment Share on other sites More sharing options...
max123 Posted November 22, 2016 Author Share Posted November 22, 2016 Hmm... The ray doesn't just point down though:http://www.babylonjs-playground.com/#1NE4XO#13 When it passes through the box which is @ (0,0,0), it logs "true". Wingnut 1 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.