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.

Is the code wrong?

Postby BluePanda » Sat Aug 05, 2017 9:10 am

When I read the SVertexManipulator.h file, I found the code as follows:
cpp 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:
cpp 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
BluePanda
 
Posts: 4
Joined: Tue Aug 01, 2017 1:11 pm

Re: Is the code wrong?

Postby CuteAlien » Sat Aug 05, 2017 12:02 pm

I'm also not familiar with that code, but "Amount" seems to get the +128 in the constructor.
IRC: #irrlicht on irc.freenode.net
Code snippets, patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Free racer created with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
User avatar
CuteAlien
Admin
 
Posts: 8363
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Is the code wrong?

Postby BluePanda » Sun Aug 06, 2017 7:55 am

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.
BluePanda
 
Posts: 4
Joined: Tue Aug 01, 2017 1:11 pm


Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 1 guest