Jump to content

Search the Community

Showing results for tags 'snap-to'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 1 result

  1. Hi guys So I've been wrestling with a problem for a little while and hoping to cast it out there for your thoughts. As part of an app I am developing i wanted to introduce snap-to functionality such that when a mesh was dragged within certain distance of another, the dragged mesh would snap into same orientation as the other - basically 2 "allowed" faces would point at each other and the mesh would be positioned so these faces were adjacent. As a pre-cursor to this I created the playground scene below to prove the concept. Basically this creates 2 static boxes, the second rotated randomnly in relation to the first. When you click the mouse anywhere in the scene it should rotate the first box to match the orientation of the second and translate it into same position for easy validation that the alignment it has worked. The approach is a function that takes 4 parameters (ignore the fifth for now); mesh1, mesh 1 face number, mesh2, mesh 2 face number. The function calculates the normal of those faces, the angle between the normals and the rotation axis and rotates mesh1 so that the faces align and then moves the mesh1 to mesh2.position. So far so good and this seems to be working ok. Click the scene and the box faces align and box 1 moves to same position as box 2. Obviously although the faces are now pointing in the same direction they are likely to be skewed around their now common normal/axis. So the intention was to call the function a second time this time specifying 2 new faces, perpendicular to the original 2 faces that are now pointing in same direction. This should calculate the angle between those 2 new faces and the axis around which to rotate (which should be the normal to the original 2 faces). This is where it goes wrong - when line 177 is uncommented to call the function a second time it causes the boxes to go out of alignment and repeated clicking causes it to randomnly point in different directions. In theory it should correct itself on each click but it does not. Any thoughts on whether the logic is sound and on the execution? I am re-rendering the scene after the first alignment call, but I do wonder whether it is not fully re-computed the vertex data and therefore the normals used to calculate the new angle of rotation/axis of rotation are wrong. Thoughts? http://www.babylonjs-playground.com/#1JX3ZX#83
×
×
  • Create New...