Cool VL Viewer forum
http://sldev.free.fr/forum/

@camdrawcolor seems to stack instead of replace the previous
http://sldev.free.fr/forum/viewtopic.php?f=7&t=1975
Page 1 of 1

Author:  kathrine [ 2019-10-26 13:21:10 ]
Post subject:  @camdrawcolor seems to stack instead of replace the previous

The specification says
Quote:
Specify the color of the fog : "@camdrawcolor:<red>;<green>;<blue>=<y/n>"

Implemented in v2.9

When this command issues, the color of the fog designed by @camdrawmin and @camdrawmax is set to <red>, <green>, <blue>. Those three values are between 0.0 and 1.0, the default being black ("0;0;0"). When several objects issue this command, the resulting color is a mix of all.


But using the following code, the results are unexpected, when a single object sets the colour:
Try putting it in an attachment, then issue in chat the following set:
Code:
/9 puppymode
/9 fogred
/9 fogpink

=> Turquoise fog, not pink

Code:
/9 puppymode
/9 fogpink
/9 fogred

=> Turquoise fog, not red

When switching it off via @clear it resets and can be set anew.

I would expect it to replace the colour, when issued from the same object.

Code:
integer chat = 9;
integer listener = 0;
integer puppymode = 0;

// switch to puppy mode
change_mode() {
    if (puppymode == 0) {
        llOwnerSay("@clear");
        return;
    }
   
    string restrictions = "@camdistmax:10=n,camdrawmin:1=n,camdrawmax:5=n,camdrawalphamin:0.6=n,camdrawalphamax:0.9=n,camdrawcolour:1.0;0.3;0.7=n";
    llOwnerSay(restrictions);
}

change_fog_color(string col) {
    if (col == "red") {
        llOwnerSay("@camdrawcolor:1;0;0=n");
    } else if (col == "pink") {
        llOwnerSay("@camdrawcolor:1.0;0.4;0.6=n");
    } else if (col == "black") {
        llOwnerSay("@camdrawcolor:1.0;0.3;0.7=n");
    }
}

default
{
    state_entry() { listener = llListen(chat, "", NULL_KEY, "");  }

    on_rez(integer i) { change_mode(); }
   
    attach(key id) { if (id != NULL_KEY) { change_mode(); }   }

    listen(integer chan, string name, key id, string msg) {
        if (llSubStringIndex(msg, "puppymode") != -1) {
            puppymode = (puppymode + 1) % 2;
            change_mode();
        }
        if (llSubStringIndex(msg, "fog") != -1) {
            string col = llGetSubString(msg, 3, 10);
            change_fog_color(col);
        }       
    }   
}

Author:  Henri Beauchamp [ 2019-10-27 09:42:44 ]
Post subject:  Re: @camdrawcolor seems to stack instead of replace the prev

After looking at the code (both Marine's and how I backported it: see the getMixedColors() method in mkrlinterface.cpp), the way this feature works is by "adding" the new color to the current draw colors list (*): the colors are "added" together (after a conversion in H/S/L components), then averaged (kind of). While I agree it is unintuitive and may (literally) "look" strange, this is how Marine implemented it (intended or not).

Also, there is no distinction between the objects applying the colors: all objects can issue a color change and all changes are "mixed" together...

I suggest you raise your concern by opening an issue on Marine's RLV code repository (I suppose a @setcamdrawcolor command could be added, that would overwrite all existing colors for the object that emits it).

(*) You may however remove a color, by using the '=rem' action in the RLV command. E.g., if you add Red with 'llOwnerSay("@camdrawcolor:1;0;0=add")' you can later remove it (possibly before applying a new color) with 'llOwnerSay("@camdrawcolor:1;0;0=rem")'...

Author:  Henri Beauchamp [ 2019-10-27 10:21:47 ]
Post subject:  Re: @camdrawcolor seems to stack instead of replace the prev

And here is how to modify your script to achieve the desired results:
Code:
integer chat = 9;
integer listener = 0;
integer puppymode = FALSE;
string last_color = "";

set_draw_color(string color) {
    if (last_color != "") {
        llOwnerSay("@camdrawcolor:" + last_color + "=rem");
    }
    last_color = color;
    llOwnerSay("@camdrawcolor:" + color + "=add");
}

// switch to puppy mode
change_mode() {
    if (!puppymode) {
        llOwnerSay("@clear");
        return;
    }

    string restrictions = "@camdistmax:10=n,camdrawmin:1=n,camdrawmax:5=n,camdrawalphamin:0.6=n,camdrawalphamax:0.9=n";
    llOwnerSay(restrictions);
    set_draw_color("1.0;0.3;0.7");
}

change_fog_color(string col) {
    if (col == "red") {
        set_draw_color("1;0;0");
    } else if (col == "pink") {
        set_draw_color("1.0;0.4;0.6");
    } else if (col == "black") {
        set_draw_color("0.0;0.0;0.0");
    }
}

default {
    state_entry() {
        listener = llListen(chat, "", NULL_KEY, "");
    }

    on_rez(integer i) {
        change_mode();
    }
   
    attach(key id) {
        if (id != NULL_KEY) {
            change_mode();
        } else {
            llOwnerSay("@clear");
        }
    }

    listen(integer chan, string name, key id, string msg) {
        if (llSubStringIndex(msg, "puppymode") != -1) {
            puppymode = !puppymode;
            change_mode();
            return;
        }
        if (llSubStringIndex(msg, "fog") != -1) {
            string col = llGetSubString(msg, 3, 10);
            change_fog_color(col);
        }
    }
}

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/