TheMonsterFromTheDeep / twion

2D vector animation software by a 3D animator (Superseded by Sunset Studio, see link)
https://notabug.org/TheMonsterFromTheDeep/sunset
GNU General Public License v3.0
7 stars 0 forks source link

Overhaul how data is structured #1

Open TheMonsterFromTheDeep opened 6 years ago

TheMonsterFromTheDeep commented 6 years ago

Right now, in the ShapeEditor class, there are a whole bunch of things that look like this:

for(size_t i = 0; i < curvepoints.size(); ++i) {
     /* do something with curvepoints[i] */
}
for(size_t i = 0; i < vecs.size(); ++i) {
    /* do something with vecs[i] */
}

and there are some horrible things like this:

if(curvepoints[i].selected) {
    Vec pos = curvepoints[i].source->location;

    Vec delta0 = *vecs[i * 2].source - pos;
    Vec delta1 = *vecs[i * 2 + 1].source - pos;

    if(abs(delta0.cross_len(delta1)) > 0.0001f) {
        Vec bisec = delta0.bisector(delta1);
        Vec n_delta = bisec.ortho();

        *vecs[i * 2].source = pos + delta0.project(n_delta);
        *vecs[i * 2 + 1].source = pos + delta1.project(n_delta);
    }
}

There are some obvious problems with these sorts of things. In the first case, the problem is simply that the same or similar operation is being carried out twice without any real good reason for doing so.

In the second case, the problem is that the involved indices are super confusing to try to keep track of, and it's made even worse by the fact that a lot of this stuff is undocumented... (sorry. :package:)

And there is another problem that is related to this discussion as well: the new ObjectEditor class needs to do a lot of the same things that the ShapeEditor class does, but right now it doesn't do any of them, because it can't re-use the code from the ShapeEditor class.

So what I'm thinking is that there should be some sort of a parent class that implements translations, rotations, and scales in global space, as well as selection, which both ShapeEditor and ObjectEditor can derive from. The parent class will operate on another interface which provides methods for selection, translation, rotation, and scaling. This interface will be specialized to the data that ShapeEditor and ObjectEditor operate on--namely, vector control points and entities in general.

At somepoint it will also have to have some sort of world space <-> local space transform, so that it will be straightforward to edit e.g. a shape after it has been rotated and translated. (This is important).