jeudi 17 février 2022

Design patterns for mathematical visualisation tool in C++

I am writing a visualisation tool for creating mathematical animations for a YouTube channel that I want to create. The tool will eventually have similar functionality to Manim, except that I am implementing everything using OpenGL in C++.

I have already developed the base functionality for visualising models via the OpenGL pipeline. However, I am a bit stuck with designing an animation manager to conveniently choreograph multiple models over the timeline of an animation. This is because I am still developing an intuition for when to apply specific design patterns in different contexts. So far, I have applied the Observer Pattern as follows - I have a Visualiser class which holds pointers to Models and, amongst other things, keeps track of the global timestamp of the animation. Each model holds a shared pointer to the Visualiser object that points to it, to be able to observe the timestamp of a given frame and compute a local time parameter for the lifetime of the model (e.g. for the purpose of moving the model along a parametrised trajectory). I would like to equip each model object with the following actions over its lifetime (Model is an abstract class with these virtual methods):

  1. Scaling.
  2. Translating
  3. Rotating about an axis
  4. Ramping up - i.e. visualising the construction of the model at the beginning of its lifetime (e.g. tracing the perimeter of a circle)
  5. Ramping down - i.e. visualising the destruction of the model at the end of its lifetime.
  6. Transforming to a different model (e.g. smooth transformation from a circle to a square)
  7. Transform from a different model (instead of ramping up)
  8. Transform to a different colour

I would like to implement an interface (in Model?) that allows me to implement an arbitrary combination of the above actions. Each Model will be specified a start and end time corresponding to the global timestamp in Visualiser, and each action will be given a start time and a duration for the action (except for ramp up/down, which will only be given a duration). I am leaning towards using the Decorator Pattern here, but I am not sure how to adapt it to this context.

I would appreciate any advice on which design patterns would be best for the above scenario.

Aucun commentaire:

Enregistrer un commentaire