English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 02 August 2017, 21:09   #1
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,546
Blink vs Fade

I have a blinking plugin, which i want to fade over time.
the blinking one just alternates between max and min value at the given interval.

the simple code doing the blink is this:
Code:
        //Find which value to use
        if((defInst->frame % (defInst->period * 2)) < defInst->period)
                fResult = defInst->fPer1;
        else
                fResult = defInst->fPer2;
frame = current frame
period = interval ( lets say we can make it the last frame in scene)
fPer1 = min value
fPer2 = max value

is there a simple way to make it fade ?
emufan is offline  
AdSense AdSense  
Old 02 August 2017, 21:33   #2
Photon
Moderator
Photon's Avatar
 
Join Date: Nov 2004
Location: Hult / Sweden
Posts: 4,499
Code:
	fFactor = (defInst->fPer2-defInst->fPer1) / defInst->period;

        if((defInst->frame % (defInst->period * 2)) < defInst->period)
                fResult = defInst->fPer1 + (frame % (defInst->period)) * fFactor;
        else
                fResult = defInst->fPer2 - (frame % (defInst->period)) * fFactor;
Photon is offline  
Old 02 August 2017, 21:57   #3
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,546
*crazy* stuff - thanks alot.
we now have envelope on surface attributes.

Last edited by emufan; 05 August 2017 at 16:41.
emufan is offline  
Old 05 August 2017, 16:44   #4
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,546
i've extended the version above, to do the animation only in a given interval,
defining start and end frame.
somehow it does work, but it looks a bit odd, not sure where i made a mistake:
Code:
XCALL_(void) evaluate(LWInstance inst, ShaderAccess *sa)
{
        BLINKER *defInst = (BLINKER *)(inst);

        //To hold the result
        float fResult;
        float fFactor;
        int start = defInst->period1;
        int end = defInst->period2;

//        if ((defInst->frame < start) || (defInst->frame > end))
//           return (NULL);

        //Find which value to use
        fFactor = (defInst->fPer2-defInst->fPer1) / (defInst->period2-defInst->period1);

        if((defInst->frame % (defInst->period1 * 2)) < defInst->period1)
            fResult = defInst->fPer1 + (defInst->frame % (defInst->period1)) * fFactor;
        else
            fResult = defInst->fPer2 - (defInst->frame % (defInst->period1)) * fFactor;

        //Put it onto the surface
        switch(defInst->uChannel)
        {
        case LUMINOUS:
                if ((defInst->frame < start) || (defInst->frame > end))
                break;
                sa->luminous = fResult;
                break;
        case DIFFUSE:
                if ((defInst->frame < start) || (defInst->frame > end))
                break;
                sa->diffuse = fResult;
                break;
        case SPECULAR:
                if ((defInst->frame < start) || (defInst->frame > end))
                break;
                sa->specular = fResult;
                break;
        case MIRROR:
                if ((defInst->frame < start) || (defInst->frame > end))
                break;
                sa->mirror = fResult;
                break;
        case TRANSP:
                if ((defInst->frame < start) || (defInst->frame > end))
                break;
                sa->transparency = fResult;
                break;
        }

        return;
}
fPer1 and fPer2 are min max value of the surface attribute (eg. luminosity)
frame is the current frame.

#1) i've added the whole fucntion, since i think it must be of importance,
where it checks, if we are in the range (start -> end).
but it does still some weird blinking at some point, instead of fading all the time.

does it look right, is the math with period1/period2 and start/end correct?
or is there something wrong?

Last edited by emufan; 05 August 2017 at 17:55.
emufan is offline  
Old 06 August 2017, 15:25   #5
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,546
i replaced all (defInst->period1) with (defInst->period2 - defInst->period1)
it's looking better now, but not yet perfect

#1) removing the range check made it work as i want it to do
needs some more tests with the desired range, but looking good for now.
Attached Images
 

Last edited by emufan; 06 August 2017 at 15:40.
emufan is offline  
AdSense AdSense  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird A500 bootup issue - 1 Power Led blink appiah4 support.Hardware 2 27 January 2017 10:06
Simulating a fade-out on startup MethodGit Coders. General 9 08 January 2014 13:30
Fade 2 black cheat/bug DeAdLy_cOoKiE Nostalgia & memories 2 02 July 2005 12:17
Assembler: Linking binaries with blink redblade Coders. General 0 29 March 2005 11:02
Fade to Black - PC Galahad/FLT Retrogaming General Discussion 12 25 July 2002 18:15

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:34.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Page generated in 0.16231 seconds with 13 queries