Is the code wrong?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
BluePanda
Posts: 4
Joined: Tue Aug 01, 2017 1:11 pm

Is the code wrong?

Post by BluePanda »

When I read the SVertexManipulator.h file, I found the code as follows:

Code: Select all

 
    class SVertexColorContrastBrightnessManipulator : public IVertexManipulator
    {
    public:
        SVertexColorContrastBrightnessManipulator(f32 factor, s32 amount) : Factor(factor), Amount(amount+128) {}
        void operator()(video::S3DVertex& vertex) const
        {
            vertex.Color.setRed(core::clamp(core::round32((vertex.Color.getRed()-128)*Factor)+Amount, 0, 255));
            vertex.Color.setGreen(core::clamp(core::round32((vertex.Color.getGreen()-128)*Factor)+Amount, 0, 255));
            vertex.Color.setBlue(core::clamp(core::round32((vertex.Color.getBlue()-128)*Factor)+Amount, 0, 255));
        }
    private:
        f32 Factor;
        s32 Amount;
    };
 
As the comments saying, it's for adjusts the contrast by the given factor and brightness by a signed amount. Should we add 128 when ending core::round32 operation? Since the contrast and Brightness operation is like this:

Code: Select all

 
    class SVertexColorContrastManipulator : public IVertexManipulator
    {
    public:
        SVertexColorContrastManipulator(f32 factor) : Factor(factor) {}
        void operator()(video::S3DVertex& vertex) const
        {
            vertex.Color.setRed(core::clamp(core::round32((vertex.Color.getRed()-128)*Factor)+128, 0, 255));
            vertex.Color.setGreen(core::clamp(core::round32((vertex.Color.getGreen()-128)*Factor)+128, 0, 255));
            vertex.Color.setBlue(core::clamp(core::round32((vertex.Color.getBlue()-128)*Factor)+128, 0, 255));
        }
    private:
        f32 Factor;
    };
 
    class SVertexColorBrightnessManipulator : public IVertexManipulator
    {
    public:
        SVertexColorBrightnessManipulator(s32 amount) : Amount(amount) {}
        void operator()(video::S3DVertex& vertex) const
        {
            vertex.Color.setRed(core::clamp(vertex.Color.getRed()+Amount, 0u, 255u));
            vertex.Color.setGreen(core::clamp(vertex.Color.getGreen()+Amount, 0u, 255u));
            vertex.Color.setBlue(core::clamp(vertex.Color.getBlue()+Amount, 0u, 255u));
        }
    private:
        s32 Amount;
    };
 
Or, is there any concept that I made mistakes? Very hope to be explained.
Thanks.

A hopeful beginner,
BluePanda
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Is the code wrong?

Post by CuteAlien »

I'm also not familiar with that code, but "Amount" seems to get the +128 in the constructor.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
BluePanda
Posts: 4
Joined: Tue Aug 01, 2017 1:11 pm

Re: Is the code wrong?

Post by BluePanda »

CuteAlien wrote:I'm also not familiar with that code, but "Amount" seems to get the +128 in the constructor.
Hmm, you're right. I made a mistake. How carelessness I was!
And,
Thanks you for your kindness.
Post Reply