Sign in to follow this  
mrmrcoleman

Trigger/Interpolator questions...

Recommended Posts

I have been reading the Enginuity 5 article about triggers and interpolators and I have a couple of questions about how exactly they work. In my program I have an Screen class which stores a vector of ScreenEntityBase objects which make up the entities within the screens in my UI (Animations/sounds/textures etc). The ScreenEntityBase class itself provides pure virtual methods which are over-ridden by a host of specialisations of the ScreenEntityBase class. I thought that I could also have a vector of Triggers and Interpolators in the Screen class which could be updated each frame and used to control the behaviours of the ScreenEntity's, my question is... Say I create an interpolator to control the alpha value of one of the ScreenEntity's in the ScreenEntityList, how do I go about setting the reference in the interpolator to reference a data member of one of the ScreenEntity objects. I guess what I am asking is, can I have a reference to a data member in another object from an interpolator object? Thanks for any help on this, if I am not particularly clear feel free to ask questions and I will see if I can explain myself a bit better. Kind regards, Mark Coleman

Share this post


Link to post
Share on other sites
Quote:
Original post by mrmrcoleman
I guess what I am asking is, can I have a reference to a data member in another object from an interpolator object?
Yes.

You could do this:
class Interpolator
{
float* value
public:
Interpolator(float* v) : value(v) {}
Update(float delta) { *value += delta; }
};

class SomeClass
{
public:
float value;
};

SomeClass* thing = new SomeClass;
interpolator_list.push_back(Interpolator(&thing->value));


Just remember that "thing->value" goes away at the same time "thing" goes away - look out for hanging pointers.

Share this post


Link to post
Share on other sites
One other thing actually... Most of the data members that I will be wanting to interpolate will be private/protected. How can I then go about achieving the same results as above?

Is the best way to make each of these classes 'friends' with the interpolator class?

Thanks again, Mark Coleman.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this