Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

csxpcm

Problem understanding an algorithm used in LOTR contest

This topic is 5922 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello all, Im having problems understanding a piece of code in one of the entries by mirko teran revnikar (the winning entry). I was hoping some of you, who have looked through the source may have a better understanding of it. The effect right at the beginning whereby the screen splits into a series of blocks and changes is what''s causing me confusion. The code is in "UnityPaletteTemplate.h" the section of code I''m struggling with is: template Type UPaletteTemplate::Get( float position ) { Type result; if ( count==0 ) return result; // error: no entry if ( cur != count ) return result; // error: not full if ( position <= key[ 0 ] ) return data[ 0 ]; // before start index if ( position >= key[ count-1 ] ) return data[ count-1 ]; // after end index int pos1 = 0; // start position while ( key[ pos1 ] < position ) pos1++;// find end position int pos0 = pos1 - 1; // set start position float delta = absf(key[ pos1 ] - key[ pos0 ]);// set index distance position -= key[ pos0 ]; // get distance on segment const float bal = position / delta; // balance const float oneMinusBal = 1.0f - bal; // 1-balance result = ( data[ pos0 ] * oneMinusBal ) + ( data[ pos1 ] * bal ); return result; // return result } Could someone explain this to me, is is an implementation of a ''map''. What does the ''balance'' mean? Ive tried working it out on paper with a set of keys and data to try and figure out how it works, but i just dont understand what it is calcualting. Any ideas anyone? Any help much appreciated. Thanks in advance -cs

Share this post


Link to post
Share on other sites
Advertisement
''balance'' means something like interpolation factor or "lerp".

if you have 2 vectors
0,1,2 and 1,2,3
with interpoiation 0.5 you get:

result = ([0,1,2] * (1 - 0.5)) + ([1,2,3] * 0.5) // (=[0.5, 1.5, 2.5])

and it''s not implementation of map. It''s more like 1D texture. But you can store any type of data in it. Not just colors.


You should never let your fears become the boundaries of your dreams.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!