Re: polymorphism; dummy parameters
On May 4, 3:18 am, vsgdp <cloud00...@yahoo.com> wrote:
DirectionalLight, PointLight, SpotLight, AreaLight. The area light
implementation requires some special data the others do not; this data
also varies over time so I can't just set it at construction time. I
can't set the area light's specific data at runtime either without
knowing its specific type (defeats polymorphism). So I am thinking
the best solution would be to just pass the data to the pure virtual
function, even though only area lights will use the data.
These things are much easier with a concrete example :-)
A normal OO approach would be to move the management of the changes
into a separate hierarchy (I guess that you're changing the parameters
during the course of animating the model).
You can now pass the manager (think of it like a puppet master where
the light is the puppet it is controlling) into the method, but in C++
you're going to need a downcast which feels icky.
A better way is to have all interaction occur within the puppet master
objects which then set the model elements for each frame. Now instead
of creating a model element on its own you always create a pair of
model element and its puppet master. The user interacts with the
puppet master, but the model elements can still be hived off for
rendering of individual frames (and the rendering code will be the
same, only the animation control will change).
K