Sign in to follow this  
ErnieDingo

Graphic Editor Timed event

Recommended Posts

HI Guys,

 

I have an idea on how to solve my problem, but I would like to know whether there are better techniques.

 

Problem: When holding down the mouse in my 3d editor (.NET windows 10), I would like to use the length of time held down to trigger events repeatedly that add a value to another value.

 

Explicitly:  When I hold the left mouse button(lmb) down, I would like to increase the alpha blend value of a point over the time I have held the lmb down for.

 

So if 0 to 1 on the blend scale takes 3 seconds to reach full value of "1".  Then after one second it would be .33.  I know it sounds a little bit inaccurate in terms of obtaining an exact alpha value, but I have other functions to deal with that in my editor.  It's really just a alpha blend painting value. 

 

I was going to use a timer to then fire off the mouse down event again, is this best?   

 

Thanks in advance for any ideas, I don't believe I have the right answer, I have a functional one I believe ,just wondering if there are more elegant solutions.

 

 

Share this post


Link to post
Share on other sites

I was going to use a timer to then fire off the mouse down event again, is this best?


That sounds fine to me. It's probably the simplest solution. Just make sure the mouse down handler that the timer calls doesn't restart the timer :) Edited by Nypyren

Share this post


Link to post
Share on other sites

I think the best would be to:

 

OnMousePressed:

    previous_time = current_time

    start updating

 

OnMouseReleased:

    stop updating

 

OnUpdate:

   current_time = getCurrentTime();

   setAlpha( getAlpha() + alpha_per_second * ( current_time - previous_time ) );

   previous_time = current_time;

 

Essentialy: keep updating your object when mouse is pressed on it and in each update use duration of the mouse press from previous update to set desired value.

Share this post


Link to post
Share on other sites

I think the best would be to:
 
OnMousePressed:
    previous_time = current_time
    start updating
 
OnMouseReleased:
    stop updating
 
OnUpdate:
   current_time = getCurrentTime();
   setAlpha( getAlpha() + alpha_per_second * ( current_time - previous_time ) );
   previous_time = current_time;
 
Essentialy: keep updating your object when mouse is pressed on it and in each update use duration of the mouse press from previous update to set desired value.


In the end I've used a timer every 25ms to update the alpha blend value. Works quite well but yes that would work also!

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