Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Snapping pieces of "track" together

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Snapping pieces of "track" together

    I've been playing with an idea for a few days now in my "spare time" and have run into some problems. The basic concept is to let users build "tracks" from a part library. This is quite simple to do when you have straights and 90 angles, but when I start throwing in curves that are say 45 deg rounded it becomes more difficult.

    Has anyone worked on a project where you would snap parts together in an arbitrary fashion, and if so do you mind sharing some of your wisdom (or source code )?

  2. #2

    Snapping pieces of "track" together

    A bit more information that I think I have found. I think I would be best to store vectors for connection edges associated with "tracks" and utilize those along with relative positioning. Does this seem to make sense, or is there a better way?

  3. #3

    Snapping pieces of "track" together

    Is there some kind of tiled map involved, where you place these parts onto or I am thinking in the wrong direction?

  4. #4

    Snapping pieces of "track" together

    I can't actually utilize a tile map of any kind in this case. Think of it this way; you have a piece of land and have to build roads and train tracks around the land. You have a library of track pieces (cuz roads are easy) and you must stay inside their contraints. For example you know that a O27-8 curve is 1/8th of a 27" circle, course you could have O27-16 or O27-4 as well as O31-8, etc... So the placement is freeform. But if you place a piece next to another piece they should "snap" together to form a loose group. That way I can grab an entire group and rotate them free form to any angle.

    Basically a model railroad track layout software scheme. Problem is all model railroad layout software is closed source and pay-ware . This design isn't my final goal, but its my first goal as it seems the difficult part to get out of the way.

  5. #5

    Snapping pieces of "track" together

    Ok, so it doesn't matter what kind of track (size, angle) you use, as long as they are of the same type, they should connect. And not only with a single connection, but also to make a set complete.

  6. #6

    Snapping pieces of "track" together

    Your on the right track (all puns intended). Though you may have different sized track types on the same screen, they would never connect with one another.

    A picture might be worth 1000 words in this case:


    As you can see, the magenta track is the same as the black only rotated 17 degrees. But, when you go to add another piece of track to the layout you now have much more complicated math. I'm thinking I need to keep a set of connection vectors for each track piece, call them connections, each connection would know of two points and how they should be placed in relation to the root connection. This way I can rotate the root connection and calculate the child connections. Unfortunately, the math is a bit above my head, especially when I start getting into strange curves.

    I did figure out that to "Snap" the pieces together I had to iterate my known list of connections and see what the closest one was, then check that distance against my Snap distance to see if I should snap the piece to any other pieces.

  7. #7

    Snapping pieces of "track" together

    Do you have fixed sized and angled pieces? If so, then isn't it so that it doesn't matter which angle the entire set is to match a single piece?

    Ok, here's an idea



    Consider the image above. I first select a piece (1/3 of a 90 degree piece) which I want to use and then select the piece I want it to connect to. The game calculates the correct angle (30 I believe) and connects the piece.
    In case the entire set is rotated with a given degree, just internally reset the entire set to 0 degrees, and make the match, then revert the set back to the rotation value it was before the match and you're good.

  8. #8

    Snapping pieces of "track" together

    Thats pretty much what I want to do (btw: Do you have the source to that) except that I want it to be done with drag and drop and not such pretty graphics in the end .

    PS: I have managed to get most of this working quite well, in fact I'm only a few short steps away from having something to show off. The hardest part now is drawing an arc from a known 3 points (Center, Start, and End) knowing that the Arc might not be a true circular piece.

  9. #9

    Snapping pieces of "track" together

    So I suppose it's all a matter of getting the math right, now.

    Quote Originally Posted by jdarling
    (btw: Do you have the source to that).
    Sry, that was just something I made up in Photoshop. There's no sourcecode I'm afraid.

    Looking forward to the endresult

  10. #10
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Snapping pieces of "track" together

    What you also can try is to generate tracks from a line. you know the direction of a line, than you can just generate some... This way it's totally freeform and not to hard to make I thing as you have your "connection points"
    NecroSOFT - End of line -

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •