Managing class structure?

This is a problem I run into a lot lately; I am unsure how to merge or otherwise organise classes which depend on eachother. For example I am playing with some soft body physics atm (experimenting with verlet integration) and I made point, stick and spring classes. As you can see in the vid below I made various structures from those. Now I would like to make higher level classes for these; a rope class, a cloth class etc, but these would depend on the lower level point and stick classes.

Now this becomes a lot less portable and inconvenient if I would like to use this in another project, because I would need to copy over all the seperate class tabs. At some point I imagine it will become quite a mess of tabs as well.

Idealy I would just have one verletStructure class responsible for ropes, cloth etc contained in one tab, but that would mean merging all those previously mentioned classes into one relatively huge tab. How do you handle such matters and what would you do in the case I described? One big handy class or many smaller interdependant classes?

https://www.youtube.com/watch?v=Dk3gkdCi-zU

I can’t answer the question, but I like the vid. Can I have the codes plz

One thing you can do is to keep all these tabs in a project, and when you want to use them in another project, set a reference to the project with these tabs, and Codea will include them when it runs.

Thanks ignaz, I wasn’t aware we could just link projects together! That’s quite a nice solution, the only drawback being that in order to change change behaviour of the classes I’d have to switch projects. But I guess the overall cleanness outweighs that minor complaint.

@TokOut
I noticed my youtube vid recommended a tutorial video about verlet integration, using pretty much the same aproach as I did. I used vectors but the behaviour is exactly the same.

The main difference of verlet integration as opposed to euler, is that you don’t update the velocity at every event (collisions for example), but rather it’s position. Then when all position adjustments are done, the verlet integration calculates it’s velocity by subtracting the current position from the old position. When dealing with lots of conflicting updates (many balls colliding for example) it results in much more stable behaviour.

Check out the video I mentioned. https://youtube.com/watch?v=3HjO_RGIjCU

The video is about javascript which translates well to LUA and the math is universal. I’d be happy to help if you get stuck! :slight_smile:

@Kirl - to change behaviour, you just need to copy in the tab that needs changing, this will override the external project reference. Then you can make then changes you need, and copy and paste back to the original tab when done.

Setting a reference is as easy as pressing the + at top right of the Codea editor and ticking the project you want a “dependency” for.

Note - the main tab in your referenced project is excluded, so any code you have put in there is ignored.