My brains jammed to think about that wrap function, and I think if you want function that wraps screen like in old video games, then is that C implementation really correct?
They say that Wrap(-1, 1, 4) should return 3, but if you have traveled two steps over border of the screen (1 -> 0, 0 -> -1), then you should come up two steps from other border (4 -> 3, 3 -> 2). So Wrap(-1, 1, 4) should be 2. C implementation is only for integers, but if you also need to use floats then, Wrap(0.5, 1, 4) should be 3.5, and Wrap(4.5, 1, 4) should be 1.5. Because if Wrap(0, 1, 4) = 4, then what would be Wrap(0.5, 1, 4) and Wrap(-0.5, 1, 4)? They cannot both be 3.5!! C implementation connects borders with one step between them, my implementation connects the borders with zero steps. So that Wrap(0.999, 1, 4) = 3.999, Wrap(4.001, 1, 4) = 1.001, Wrap(1,1,4) = 1 and Wrap(4,1,4)=4. So I think this gives correct answers: Private Function MyWrap(fX As Float, fLowerBound As Float, fUpperBound As Float) As Float Dim fRange As Float = fUpperBound - fLowerBound If fX < fLowerBound Then Return fUpperBound - Abs(fmod((fX - fLowerBound), fRange)) Else If fX > fUpperBound Then Return fmod(fX - fLowerBound, fRange) + fLowerBound Else Return fX Endif End It needs declaration of fmod: Private Extern fmod(fNumber As Float, fDenom As Float) As Float In "libm:6" Jussi On Fri, Oct 11, 2013 at 12:50 AM, Kevin Fishburne < [email protected]> wrote: > On 10/10/2013 05:07 AM, Fabien Bodard wrote: > >> Maybe some parts of your rendering engine must in final be in a lib like >> gb.sge >> > > Is there a reference doc for that component? I don't see it in the wiki, > but seem to remember someone mentioning it on the list before. > > My code's pretty specialized for my project, but some of it could > conceivably be made more friendly for general purpose game engine use. I've > attached the Audio, Calculate, Render and Wisp modules. There are some bugs > in there (and some logic craziness) but what else is new? The Wrap_Single > procedure in the Calculate module is messed up, FYI. I tried to adapt the > Wrap_Short code to it by truncating the fractional part then adding it back > in at the end, but apparently it creates some imprecision and makes my > camera orientation twitch. :/ > > > -- > Kevin Fishburne > Eight Virtues > www: http://sales.eightvirtues.com > e-mail: [email protected] > phone: (770) 853-6271 > > > > ------------------------------------------------------------------------------ > October Webinars: Code for Performance > Free Intel webinars can help you accelerate application performance. > Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most > from > the latest Intel processors and coprocessors. See abstracts and register > > http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk > _______________________________________________ > Gambas-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/gambas-user > > ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk _______________________________________________ Gambas-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gambas-user
