Restore llmath improvements from archived develop branch:

* Make eligible functions constexpr
* Use constants for vector indices where applicable
* Reformat to match actual coding conventions
master
Ansariel 2025-04-17 19:50:30 +02:00
parent 441c844ec8
commit 4c6afbbb75
28 changed files with 1799 additions and 2031 deletions

View File

@ -31,15 +31,15 @@
class LLUUID; class LLUUID;
static const F32 REGION_WIDTH_METERS = 256.f; static constexpr F32 REGION_WIDTH_METERS = 256.f;
static const S32 REGION_WIDTH_UNITS = 256; static constexpr S32 REGION_WIDTH_UNITS = 256;
static const U32 REGION_WIDTH_U32 = 256; static constexpr U32 REGION_WIDTH_U32 = 256;
const F32 REGION_HEIGHT_METERS = 4096.f; constexpr F32 REGION_HEIGHT_METERS = 4096.f;
const F32 DEFAULT_AGENT_DEPTH = 0.45f; constexpr F32 DEFAULT_AGENT_DEPTH = 0.45f;
const F32 DEFAULT_AGENT_WIDTH = 0.60f; constexpr F32 DEFAULT_AGENT_WIDTH = 0.60f;
const F32 DEFAULT_AGENT_HEIGHT = 1.9f; constexpr F32 DEFAULT_AGENT_HEIGHT = 1.9f;
enum ETerrainBrushType enum ETerrainBrushType
{ {
@ -67,112 +67,112 @@ enum EMouseClickType{
// keys // keys
// Bit masks for various keyboard modifier keys. // Bit masks for various keyboard modifier keys.
const MASK MASK_NONE = 0x0000; constexpr MASK MASK_NONE = 0x0000;
const MASK MASK_CONTROL = 0x0001; // Mapped to cmd on Macs constexpr MASK MASK_CONTROL = 0x0001; // Mapped to cmd on Macs
const MASK MASK_ALT = 0x0002; constexpr MASK MASK_ALT = 0x0002;
const MASK MASK_SHIFT = 0x0004; constexpr MASK MASK_SHIFT = 0x0004;
const MASK MASK_NORMALKEYS = 0x0007; // A real mask - only get the bits for normal modifier keys constexpr MASK MASK_NORMALKEYS = 0x0007; // A real mask - only get the bits for normal modifier keys
const MASK MASK_MAC_CONTROL = 0x0008; // Un-mapped Ctrl key on Macs, not used on Windows constexpr MASK MASK_MAC_CONTROL = 0x0008; // Un-mapped Ctrl key on Macs, not used on Windows
const MASK MASK_MODIFIERS = MASK_CONTROL|MASK_ALT|MASK_SHIFT|MASK_MAC_CONTROL; constexpr MASK MASK_MODIFIERS = MASK_CONTROL|MASK_ALT|MASK_SHIFT|MASK_MAC_CONTROL;
// Special keys go into >128 // Special keys go into >128
const KEY KEY_SPECIAL = 0x80; // special keys start here constexpr KEY KEY_SPECIAL = 0x80; // special keys start here
const KEY KEY_RETURN = 0x81; constexpr KEY KEY_RETURN = 0x81;
const KEY KEY_LEFT = 0x82; constexpr KEY KEY_LEFT = 0x82;
const KEY KEY_RIGHT = 0x83; constexpr KEY KEY_RIGHT = 0x83;
const KEY KEY_UP = 0x84; constexpr KEY KEY_UP = 0x84;
const KEY KEY_DOWN = 0x85; constexpr KEY KEY_DOWN = 0x85;
const KEY KEY_ESCAPE = 0x86; constexpr KEY KEY_ESCAPE = 0x86;
const KEY KEY_BACKSPACE =0x87; constexpr KEY KEY_BACKSPACE =0x87;
const KEY KEY_DELETE = 0x88; constexpr KEY KEY_DELETE = 0x88;
const KEY KEY_SHIFT = 0x89; constexpr KEY KEY_SHIFT = 0x89;
const KEY KEY_CONTROL = 0x8A; constexpr KEY KEY_CONTROL = 0x8A;
const KEY KEY_ALT = 0x8B; constexpr KEY KEY_ALT = 0x8B;
const KEY KEY_HOME = 0x8C; constexpr KEY KEY_HOME = 0x8C;
const KEY KEY_END = 0x8D; constexpr KEY KEY_END = 0x8D;
const KEY KEY_PAGE_UP = 0x8E; constexpr KEY KEY_PAGE_UP = 0x8E;
const KEY KEY_PAGE_DOWN = 0x8F; constexpr KEY KEY_PAGE_DOWN = 0x8F;
const KEY KEY_HYPHEN = 0x90; constexpr KEY KEY_HYPHEN = 0x90;
const KEY KEY_EQUALS = 0x91; constexpr KEY KEY_EQUALS = 0x91;
const KEY KEY_INSERT = 0x92; constexpr KEY KEY_INSERT = 0x92;
const KEY KEY_CAPSLOCK = 0x93; constexpr KEY KEY_CAPSLOCK = 0x93;
const KEY KEY_TAB = 0x94; constexpr KEY KEY_TAB = 0x94;
const KEY KEY_ADD = 0x95; constexpr KEY KEY_ADD = 0x95;
const KEY KEY_SUBTRACT =0x96; constexpr KEY KEY_SUBTRACT =0x96;
const KEY KEY_MULTIPLY =0x97; constexpr KEY KEY_MULTIPLY =0x97;
const KEY KEY_DIVIDE = 0x98; constexpr KEY KEY_DIVIDE = 0x98;
const KEY KEY_F1 = 0xA1; constexpr KEY KEY_F1 = 0xA1;
const KEY KEY_F2 = 0xA2; constexpr KEY KEY_F2 = 0xA2;
const KEY KEY_F3 = 0xA3; constexpr KEY KEY_F3 = 0xA3;
const KEY KEY_F4 = 0xA4; constexpr KEY KEY_F4 = 0xA4;
const KEY KEY_F5 = 0xA5; constexpr KEY KEY_F5 = 0xA5;
const KEY KEY_F6 = 0xA6; constexpr KEY KEY_F6 = 0xA6;
const KEY KEY_F7 = 0xA7; constexpr KEY KEY_F7 = 0xA7;
const KEY KEY_F8 = 0xA8; constexpr KEY KEY_F8 = 0xA8;
const KEY KEY_F9 = 0xA9; constexpr KEY KEY_F9 = 0xA9;
const KEY KEY_F10 = 0xAA; constexpr KEY KEY_F10 = 0xAA;
const KEY KEY_F11 = 0xAB; constexpr KEY KEY_F11 = 0xAB;
const KEY KEY_F12 = 0xAC; constexpr KEY KEY_F12 = 0xAC;
const KEY KEY_PAD_UP = 0xC0; constexpr KEY KEY_PAD_UP = 0xC0;
const KEY KEY_PAD_DOWN = 0xC1; constexpr KEY KEY_PAD_DOWN = 0xC1;
const KEY KEY_PAD_LEFT = 0xC2; constexpr KEY KEY_PAD_LEFT = 0xC2;
const KEY KEY_PAD_RIGHT = 0xC3; constexpr KEY KEY_PAD_RIGHT = 0xC3;
const KEY KEY_PAD_HOME = 0xC4; constexpr KEY KEY_PAD_HOME = 0xC4;
const KEY KEY_PAD_END = 0xC5; constexpr KEY KEY_PAD_END = 0xC5;
const KEY KEY_PAD_PGUP = 0xC6; constexpr KEY KEY_PAD_PGUP = 0xC6;
const KEY KEY_PAD_PGDN = 0xC7; constexpr KEY KEY_PAD_PGDN = 0xC7;
const KEY KEY_PAD_CENTER = 0xC8; // the 5 in the middle constexpr KEY KEY_PAD_CENTER = 0xC8; // the 5 in the middle
const KEY KEY_PAD_INS = 0xC9; constexpr KEY KEY_PAD_INS = 0xC9;
const KEY KEY_PAD_DEL = 0xCA; constexpr KEY KEY_PAD_DEL = 0xCA;
const KEY KEY_PAD_RETURN = 0xCB; constexpr KEY KEY_PAD_RETURN = 0xCB;
const KEY KEY_PAD_ADD = 0xCC; // not used constexpr KEY KEY_PAD_ADD = 0xCC; // not used
const KEY KEY_PAD_SUBTRACT = 0xCD; // not used constexpr KEY KEY_PAD_SUBTRACT = 0xCD; // not used
const KEY KEY_PAD_MULTIPLY = 0xCE; // not used constexpr KEY KEY_PAD_MULTIPLY = 0xCE; // not used
const KEY KEY_PAD_DIVIDE = 0xCF; // not used constexpr KEY KEY_PAD_DIVIDE = 0xCF; // not used
const KEY KEY_BUTTON0 = 0xD0; constexpr KEY KEY_BUTTON0 = 0xD0;
const KEY KEY_BUTTON1 = 0xD1; constexpr KEY KEY_BUTTON1 = 0xD1;
const KEY KEY_BUTTON2 = 0xD2; constexpr KEY KEY_BUTTON2 = 0xD2;
const KEY KEY_BUTTON3 = 0xD3; constexpr KEY KEY_BUTTON3 = 0xD3;
const KEY KEY_BUTTON4 = 0xD4; constexpr KEY KEY_BUTTON4 = 0xD4;
const KEY KEY_BUTTON5 = 0xD5; constexpr KEY KEY_BUTTON5 = 0xD5;
const KEY KEY_BUTTON6 = 0xD6; constexpr KEY KEY_BUTTON6 = 0xD6;
const KEY KEY_BUTTON7 = 0xD7; constexpr KEY KEY_BUTTON7 = 0xD7;
const KEY KEY_BUTTON8 = 0xD8; constexpr KEY KEY_BUTTON8 = 0xD8;
const KEY KEY_BUTTON9 = 0xD9; constexpr KEY KEY_BUTTON9 = 0xD9;
const KEY KEY_BUTTON10 = 0xDA; constexpr KEY KEY_BUTTON10 = 0xDA;
const KEY KEY_BUTTON11 = 0xDB; constexpr KEY KEY_BUTTON11 = 0xDB;
const KEY KEY_BUTTON12 = 0xDC; constexpr KEY KEY_BUTTON12 = 0xDC;
const KEY KEY_BUTTON13 = 0xDD; constexpr KEY KEY_BUTTON13 = 0xDD;
const KEY KEY_BUTTON14 = 0xDE; constexpr KEY KEY_BUTTON14 = 0xDE;
const KEY KEY_BUTTON15 = 0xDF; constexpr KEY KEY_BUTTON15 = 0xDF;
const KEY KEY_NONE = 0xFF; // not sent from keyboard. For internal use only. constexpr KEY KEY_NONE = 0xFF; // not sent from keyboard. For internal use only.
const S32 KEY_COUNT = 256; constexpr S32 KEY_COUNT = 256;
const F32 DEFAULT_WATER_HEIGHT = 20.0f; constexpr F32 DEFAULT_WATER_HEIGHT = 20.0f;
// Maturity ratings for simulators // Maturity ratings for simulators
const U8 SIM_ACCESS_MIN = 0; // Treated as 'unknown', usually ends up being SIM_ACCESS_PG constexpr U8 SIM_ACCESS_MIN = 0; // Treated as 'unknown', usually ends up being SIM_ACCESS_PG
const U8 SIM_ACCESS_PG = 13; constexpr U8 SIM_ACCESS_PG = 13;
const U8 SIM_ACCESS_MATURE = 21; constexpr U8 SIM_ACCESS_MATURE = 21;
const U8 SIM_ACCESS_ADULT = 42; // Seriously Adult Only constexpr U8 SIM_ACCESS_ADULT = 42; // Seriously Adult Only
const U8 SIM_ACCESS_DOWN = 254; constexpr U8 SIM_ACCESS_DOWN = 254;
const U8 SIM_ACCESS_MAX = SIM_ACCESS_ADULT; constexpr U8 SIM_ACCESS_MAX = SIM_ACCESS_ADULT;
// attachment constants // attachment constants
const U8 ATTACHMENT_ADD = 0x80; constexpr U8 ATTACHMENT_ADD = 0x80;
// god levels // god levels
const U8 GOD_MAINTENANCE = 250; constexpr U8 GOD_MAINTENANCE = 250;
const U8 GOD_FULL = 200; constexpr U8 GOD_FULL = 200;
const U8 GOD_LIAISON = 150; constexpr U8 GOD_LIAISON = 150;
const U8 GOD_CUSTOMER_SERVICE = 100; constexpr U8 GOD_CUSTOMER_SERVICE = 100;
const U8 GOD_LIKE = 1; constexpr U8 GOD_LIKE = 1;
const U8 GOD_NOT = 0; constexpr U8 GOD_NOT = 0;
// "agent id" for things that should be done to ALL agents // "agent id" for things that should be done to ALL agents
LL_COMMON_API extern const LLUUID LL_UUID_ALL_AGENTS; LL_COMMON_API extern const LLUUID LL_UUID_ALL_AGENTS;
@ -239,120 +239,120 @@ LL_COMMON_API extern const LLUUID BLANK_OBJECT_NORMAL;
LL_COMMON_API extern const LLUUID BLANK_MATERIAL_ASSET_ID; LL_COMMON_API extern const LLUUID BLANK_MATERIAL_ASSET_ID;
// radius within which a chat message is fully audible // radius within which a chat message is fully audible
const F32 CHAT_NORMAL_RADIUS = 20.f; constexpr F32 CHAT_NORMAL_RADIUS = 20.f;
// media commands // media commands
const U32 PARCEL_MEDIA_COMMAND_STOP = 0; constexpr U32 PARCEL_MEDIA_COMMAND_STOP = 0;
const U32 PARCEL_MEDIA_COMMAND_PAUSE = 1; constexpr U32 PARCEL_MEDIA_COMMAND_PAUSE = 1;
const U32 PARCEL_MEDIA_COMMAND_PLAY = 2; constexpr U32 PARCEL_MEDIA_COMMAND_PLAY = 2;
const U32 PARCEL_MEDIA_COMMAND_LOOP = 3; constexpr U32 PARCEL_MEDIA_COMMAND_LOOP = 3;
const U32 PARCEL_MEDIA_COMMAND_TEXTURE = 4; constexpr U32 PARCEL_MEDIA_COMMAND_TEXTURE = 4;
const U32 PARCEL_MEDIA_COMMAND_URL = 5; constexpr U32 PARCEL_MEDIA_COMMAND_URL = 5;
const U32 PARCEL_MEDIA_COMMAND_TIME = 6; constexpr U32 PARCEL_MEDIA_COMMAND_TIME = 6;
const U32 PARCEL_MEDIA_COMMAND_AGENT = 7; constexpr U32 PARCEL_MEDIA_COMMAND_AGENT = 7;
const U32 PARCEL_MEDIA_COMMAND_UNLOAD = 8; constexpr U32 PARCEL_MEDIA_COMMAND_UNLOAD = 8;
const U32 PARCEL_MEDIA_COMMAND_AUTO_ALIGN = 9; constexpr U32 PARCEL_MEDIA_COMMAND_AUTO_ALIGN = 9;
const U32 PARCEL_MEDIA_COMMAND_TYPE = 10; constexpr U32 PARCEL_MEDIA_COMMAND_TYPE = 10;
const U32 PARCEL_MEDIA_COMMAND_SIZE = 11; constexpr U32 PARCEL_MEDIA_COMMAND_SIZE = 11;
const U32 PARCEL_MEDIA_COMMAND_DESC = 12; constexpr U32 PARCEL_MEDIA_COMMAND_DESC = 12;
const U32 PARCEL_MEDIA_COMMAND_LOOP_SET = 13; constexpr U32 PARCEL_MEDIA_COMMAND_LOOP_SET = 13;
const S32 CHAT_CHANNEL_DEBUG = S32_MAX; const S32 CHAT_CHANNEL_DEBUG = S32_MAX;
// agent constants // agent constants
const U32 CONTROL_AT_POS_INDEX = 0; constexpr U32 CONTROL_AT_POS_INDEX = 0;
const U32 CONTROL_AT_NEG_INDEX = 1; constexpr U32 CONTROL_AT_NEG_INDEX = 1;
const U32 CONTROL_LEFT_POS_INDEX = 2; constexpr U32 CONTROL_LEFT_POS_INDEX = 2;
const U32 CONTROL_LEFT_NEG_INDEX = 3; constexpr U32 CONTROL_LEFT_NEG_INDEX = 3;
const U32 CONTROL_UP_POS_INDEX = 4; constexpr U32 CONTROL_UP_POS_INDEX = 4;
const U32 CONTROL_UP_NEG_INDEX = 5; constexpr U32 CONTROL_UP_NEG_INDEX = 5;
const U32 CONTROL_PITCH_POS_INDEX = 6; constexpr U32 CONTROL_PITCH_POS_INDEX = 6;
const U32 CONTROL_PITCH_NEG_INDEX = 7; constexpr U32 CONTROL_PITCH_NEG_INDEX = 7;
const U32 CONTROL_YAW_POS_INDEX = 8; constexpr U32 CONTROL_YAW_POS_INDEX = 8;
const U32 CONTROL_YAW_NEG_INDEX = 9; constexpr U32 CONTROL_YAW_NEG_INDEX = 9;
const U32 CONTROL_FAST_AT_INDEX = 10; constexpr U32 CONTROL_FAST_AT_INDEX = 10;
const U32 CONTROL_FAST_LEFT_INDEX = 11; constexpr U32 CONTROL_FAST_LEFT_INDEX = 11;
const U32 CONTROL_FAST_UP_INDEX = 12; constexpr U32 CONTROL_FAST_UP_INDEX = 12;
const U32 CONTROL_FLY_INDEX = 13; constexpr U32 CONTROL_FLY_INDEX = 13;
const U32 CONTROL_STOP_INDEX = 14; constexpr U32 CONTROL_STOP_INDEX = 14;
const U32 CONTROL_FINISH_ANIM_INDEX = 15; constexpr U32 CONTROL_FINISH_ANIM_INDEX = 15;
const U32 CONTROL_STAND_UP_INDEX = 16; constexpr U32 CONTROL_STAND_UP_INDEX = 16;
const U32 CONTROL_SIT_ON_GROUND_INDEX = 17; constexpr U32 CONTROL_SIT_ON_GROUND_INDEX = 17;
const U32 CONTROL_MOUSELOOK_INDEX = 18; constexpr U32 CONTROL_MOUSELOOK_INDEX = 18;
const U32 CONTROL_NUDGE_AT_POS_INDEX = 19; constexpr U32 CONTROL_NUDGE_AT_POS_INDEX = 19;
const U32 CONTROL_NUDGE_AT_NEG_INDEX = 20; constexpr U32 CONTROL_NUDGE_AT_NEG_INDEX = 20;
const U32 CONTROL_NUDGE_LEFT_POS_INDEX = 21; constexpr U32 CONTROL_NUDGE_LEFT_POS_INDEX = 21;
const U32 CONTROL_NUDGE_LEFT_NEG_INDEX = 22; constexpr U32 CONTROL_NUDGE_LEFT_NEG_INDEX = 22;
const U32 CONTROL_NUDGE_UP_POS_INDEX = 23; constexpr U32 CONTROL_NUDGE_UP_POS_INDEX = 23;
const U32 CONTROL_NUDGE_UP_NEG_INDEX = 24; constexpr U32 CONTROL_NUDGE_UP_NEG_INDEX = 24;
const U32 CONTROL_TURN_LEFT_INDEX = 25; constexpr U32 CONTROL_TURN_LEFT_INDEX = 25;
const U32 CONTROL_TURN_RIGHT_INDEX = 26; constexpr U32 CONTROL_TURN_RIGHT_INDEX = 26;
const U32 CONTROL_AWAY_INDEX = 27; constexpr U32 CONTROL_AWAY_INDEX = 27;
const U32 CONTROL_LBUTTON_DOWN_INDEX = 28; constexpr U32 CONTROL_LBUTTON_DOWN_INDEX = 28;
const U32 CONTROL_LBUTTON_UP_INDEX = 29; constexpr U32 CONTROL_LBUTTON_UP_INDEX = 29;
const U32 CONTROL_ML_LBUTTON_DOWN_INDEX = 30; constexpr U32 CONTROL_ML_LBUTTON_DOWN_INDEX = 30;
const U32 CONTROL_ML_LBUTTON_UP_INDEX = 31; constexpr U32 CONTROL_ML_LBUTTON_UP_INDEX = 31;
const U32 TOTAL_CONTROLS = 32; constexpr U32 TOTAL_CONTROLS = 32;
const U32 AGENT_CONTROL_AT_POS = 0x1 << CONTROL_AT_POS_INDEX; // 0x00000001 constexpr U32 AGENT_CONTROL_AT_POS = 0x1 << CONTROL_AT_POS_INDEX; // 0x00000001
const U32 AGENT_CONTROL_AT_NEG = 0x1 << CONTROL_AT_NEG_INDEX; // 0x00000002 constexpr U32 AGENT_CONTROL_AT_NEG = 0x1 << CONTROL_AT_NEG_INDEX; // 0x00000002
const U32 AGENT_CONTROL_LEFT_POS = 0x1 << CONTROL_LEFT_POS_INDEX; // 0x00000004 constexpr U32 AGENT_CONTROL_LEFT_POS = 0x1 << CONTROL_LEFT_POS_INDEX; // 0x00000004
const U32 AGENT_CONTROL_LEFT_NEG = 0x1 << CONTROL_LEFT_NEG_INDEX; // 0x00000008 constexpr U32 AGENT_CONTROL_LEFT_NEG = 0x1 << CONTROL_LEFT_NEG_INDEX; // 0x00000008
const U32 AGENT_CONTROL_UP_POS = 0x1 << CONTROL_UP_POS_INDEX; // 0x00000010 constexpr U32 AGENT_CONTROL_UP_POS = 0x1 << CONTROL_UP_POS_INDEX; // 0x00000010
const U32 AGENT_CONTROL_UP_NEG = 0x1 << CONTROL_UP_NEG_INDEX; // 0x00000020 constexpr U32 AGENT_CONTROL_UP_NEG = 0x1 << CONTROL_UP_NEG_INDEX; // 0x00000020
const U32 AGENT_CONTROL_PITCH_POS = 0x1 << CONTROL_PITCH_POS_INDEX; // 0x00000040 constexpr U32 AGENT_CONTROL_PITCH_POS = 0x1 << CONTROL_PITCH_POS_INDEX; // 0x00000040
const U32 AGENT_CONTROL_PITCH_NEG = 0x1 << CONTROL_PITCH_NEG_INDEX; // 0x00000080 constexpr U32 AGENT_CONTROL_PITCH_NEG = 0x1 << CONTROL_PITCH_NEG_INDEX; // 0x00000080
const U32 AGENT_CONTROL_YAW_POS = 0x1 << CONTROL_YAW_POS_INDEX; // 0x00000100 constexpr U32 AGENT_CONTROL_YAW_POS = 0x1 << CONTROL_YAW_POS_INDEX; // 0x00000100
const U32 AGENT_CONTROL_YAW_NEG = 0x1 << CONTROL_YAW_NEG_INDEX; // 0x00000200 constexpr U32 AGENT_CONTROL_YAW_NEG = 0x1 << CONTROL_YAW_NEG_INDEX; // 0x00000200
const U32 AGENT_CONTROL_FAST_AT = 0x1 << CONTROL_FAST_AT_INDEX; // 0x00000400 constexpr U32 AGENT_CONTROL_FAST_AT = 0x1 << CONTROL_FAST_AT_INDEX; // 0x00000400
const U32 AGENT_CONTROL_FAST_LEFT = 0x1 << CONTROL_FAST_LEFT_INDEX; // 0x00000800 constexpr U32 AGENT_CONTROL_FAST_LEFT = 0x1 << CONTROL_FAST_LEFT_INDEX; // 0x00000800
const U32 AGENT_CONTROL_FAST_UP = 0x1 << CONTROL_FAST_UP_INDEX; // 0x00001000 constexpr U32 AGENT_CONTROL_FAST_UP = 0x1 << CONTROL_FAST_UP_INDEX; // 0x00001000
const U32 AGENT_CONTROL_FLY = 0x1 << CONTROL_FLY_INDEX; // 0x00002000 constexpr U32 AGENT_CONTROL_FLY = 0x1 << CONTROL_FLY_INDEX; // 0x00002000
const U32 AGENT_CONTROL_STOP = 0x1 << CONTROL_STOP_INDEX; // 0x00004000 constexpr U32 AGENT_CONTROL_STOP = 0x1 << CONTROL_STOP_INDEX; // 0x00004000
const U32 AGENT_CONTROL_FINISH_ANIM = 0x1 << CONTROL_FINISH_ANIM_INDEX; // 0x00008000 constexpr U32 AGENT_CONTROL_FINISH_ANIM = 0x1 << CONTROL_FINISH_ANIM_INDEX; // 0x00008000
const U32 AGENT_CONTROL_STAND_UP = 0x1 << CONTROL_STAND_UP_INDEX; // 0x00010000 constexpr U32 AGENT_CONTROL_STAND_UP = 0x1 << CONTROL_STAND_UP_INDEX; // 0x00010000
const U32 AGENT_CONTROL_SIT_ON_GROUND = 0x1 << CONTROL_SIT_ON_GROUND_INDEX; // 0x00020000 constexpr U32 AGENT_CONTROL_SIT_ON_GROUND = 0x1 << CONTROL_SIT_ON_GROUND_INDEX; // 0x00020000
const U32 AGENT_CONTROL_MOUSELOOK = 0x1 << CONTROL_MOUSELOOK_INDEX; // 0x00040000 constexpr U32 AGENT_CONTROL_MOUSELOOK = 0x1 << CONTROL_MOUSELOOK_INDEX; // 0x00040000
const U32 AGENT_CONTROL_NUDGE_AT_POS = 0x1 << CONTROL_NUDGE_AT_POS_INDEX; // 0x00080000 constexpr U32 AGENT_CONTROL_NUDGE_AT_POS = 0x1 << CONTROL_NUDGE_AT_POS_INDEX; // 0x00080000
const U32 AGENT_CONTROL_NUDGE_AT_NEG = 0x1 << CONTROL_NUDGE_AT_NEG_INDEX; // 0x00100000 constexpr U32 AGENT_CONTROL_NUDGE_AT_NEG = 0x1 << CONTROL_NUDGE_AT_NEG_INDEX; // 0x00100000
const U32 AGENT_CONTROL_NUDGE_LEFT_POS = 0x1 << CONTROL_NUDGE_LEFT_POS_INDEX; // 0x00200000 constexpr U32 AGENT_CONTROL_NUDGE_LEFT_POS = 0x1 << CONTROL_NUDGE_LEFT_POS_INDEX; // 0x00200000
const U32 AGENT_CONTROL_NUDGE_LEFT_NEG = 0x1 << CONTROL_NUDGE_LEFT_NEG_INDEX; // 0x00400000 constexpr U32 AGENT_CONTROL_NUDGE_LEFT_NEG = 0x1 << CONTROL_NUDGE_LEFT_NEG_INDEX; // 0x00400000
const U32 AGENT_CONTROL_NUDGE_UP_POS = 0x1 << CONTROL_NUDGE_UP_POS_INDEX; // 0x00800000 constexpr U32 AGENT_CONTROL_NUDGE_UP_POS = 0x1 << CONTROL_NUDGE_UP_POS_INDEX; // 0x00800000
const U32 AGENT_CONTROL_NUDGE_UP_NEG = 0x1 << CONTROL_NUDGE_UP_NEG_INDEX; // 0x01000000 constexpr U32 AGENT_CONTROL_NUDGE_UP_NEG = 0x1 << CONTROL_NUDGE_UP_NEG_INDEX; // 0x01000000
const U32 AGENT_CONTROL_TURN_LEFT = 0x1 << CONTROL_TURN_LEFT_INDEX; // 0x02000000 constexpr U32 AGENT_CONTROL_TURN_LEFT = 0x1 << CONTROL_TURN_LEFT_INDEX; // 0x02000000
const U32 AGENT_CONTROL_TURN_RIGHT = 0x1 << CONTROL_TURN_RIGHT_INDEX; // 0x04000000 constexpr U32 AGENT_CONTROL_TURN_RIGHT = 0x1 << CONTROL_TURN_RIGHT_INDEX; // 0x04000000
const U32 AGENT_CONTROL_AWAY = 0x1 << CONTROL_AWAY_INDEX; // 0x08000000 constexpr U32 AGENT_CONTROL_AWAY = 0x1 << CONTROL_AWAY_INDEX; // 0x08000000
const U32 AGENT_CONTROL_LBUTTON_DOWN = 0x1 << CONTROL_LBUTTON_DOWN_INDEX; // 0x10000000 constexpr U32 AGENT_CONTROL_LBUTTON_DOWN = 0x1 << CONTROL_LBUTTON_DOWN_INDEX; // 0x10000000
const U32 AGENT_CONTROL_LBUTTON_UP = 0x1 << CONTROL_LBUTTON_UP_INDEX; // 0x20000000 constexpr U32 AGENT_CONTROL_LBUTTON_UP = 0x1 << CONTROL_LBUTTON_UP_INDEX; // 0x20000000
const U32 AGENT_CONTROL_ML_LBUTTON_DOWN = 0x1 << CONTROL_ML_LBUTTON_DOWN_INDEX; // 0x40000000 constexpr U32 AGENT_CONTROL_ML_LBUTTON_DOWN = 0x1 << CONTROL_ML_LBUTTON_DOWN_INDEX; // 0x40000000
const U32 AGENT_CONTROL_ML_LBUTTON_UP = ((U32)0x1) << CONTROL_ML_LBUTTON_UP_INDEX; // 0x80000000 constexpr U32 AGENT_CONTROL_ML_LBUTTON_UP = ((U32)0x1) << CONTROL_ML_LBUTTON_UP_INDEX; // 0x80000000
// move these up so that we can hide them in "State" for object updates // move these up so that we can hide them in "State" for object updates
// (for now) // (for now)
const U32 AGENT_ATTACH_OFFSET = 4; constexpr U32 AGENT_ATTACH_OFFSET = 4;
const U32 AGENT_ATTACH_MASK = 0xf << AGENT_ATTACH_OFFSET; constexpr U32 AGENT_ATTACH_MASK = 0xf << AGENT_ATTACH_OFFSET;
// RN: this method swaps the upper and lower nibbles to maintain backward // RN: this method swaps the upper and lower nibbles to maintain backward
// compatibility with old objects that only used the upper nibble // compatibility with old objects that only used the upper nibble
#define ATTACHMENT_ID_FROM_STATE(state) ((S32)((((U8)state & AGENT_ATTACH_MASK) >> 4) | (((U8)state & ~AGENT_ATTACH_MASK) << 4))) #define ATTACHMENT_ID_FROM_STATE(state) ((S32)((((U8)state & AGENT_ATTACH_MASK) >> 4) | (((U8)state & ~AGENT_ATTACH_MASK) << 4)))
// DO NOT CHANGE THE SEQUENCE OF THIS LIST!! // DO NOT CHANGE THE SEQUENCE OF THIS LIST!!
const U8 CLICK_ACTION_NONE = 0; constexpr U8 CLICK_ACTION_NONE = 0;
const U8 CLICK_ACTION_TOUCH = 0; constexpr U8 CLICK_ACTION_TOUCH = 0;
const U8 CLICK_ACTION_SIT = 1; constexpr U8 CLICK_ACTION_SIT = 1;
const U8 CLICK_ACTION_BUY = 2; constexpr U8 CLICK_ACTION_BUY = 2;
const U8 CLICK_ACTION_PAY = 3; constexpr U8 CLICK_ACTION_PAY = 3;
const U8 CLICK_ACTION_OPEN = 4; constexpr U8 CLICK_ACTION_OPEN = 4;
const U8 CLICK_ACTION_PLAY = 5; constexpr U8 CLICK_ACTION_PLAY = 5;
const U8 CLICK_ACTION_OPEN_MEDIA = 6; constexpr U8 CLICK_ACTION_OPEN_MEDIA = 6;
const U8 CLICK_ACTION_ZOOM = 7; constexpr U8 CLICK_ACTION_ZOOM = 7;
const U8 CLICK_ACTION_DISABLED = 8; constexpr U8 CLICK_ACTION_DISABLED = 8;
const U8 CLICK_ACTION_IGNORE = 9; constexpr U8 CLICK_ACTION_IGNORE = 9;
// DO NOT CHANGE THE SEQUENCE OF THIS LIST!! // DO NOT CHANGE THE SEQUENCE OF THIS LIST!!
constexpr U32 BEACON_SHOW_MAP = 0x0001; constexpr U32 BEACON_SHOW_MAP = 0x0001;

View File

@ -171,13 +171,13 @@ constexpr U32 MAXADDRSTR = 17; // 123.567.901.345 = 15 chars + \0 +
// recursion tail // recursion tail
template <typename T> template <typename T>
inline auto llmax(T data) constexpr auto llmax(T data)
{ {
return data; return data;
} }
template <typename T0, typename T1, typename... Ts> template <typename T0, typename T1, typename... Ts>
inline auto llmax(T0 d0, T1 d1, Ts... rest) constexpr auto llmax(T0 d0, T1 d1, Ts... rest)
{ {
auto maxrest = llmax(d1, rest...); auto maxrest = llmax(d1, rest...);
return (d0 > maxrest)? d0 : maxrest; return (d0 > maxrest)? d0 : maxrest;
@ -185,20 +185,20 @@ inline auto llmax(T0 d0, T1 d1, Ts... rest)
// recursion tail // recursion tail
template <typename T> template <typename T>
inline auto llmin(T data) constexpr auto llmin(T data)
{ {
return data; return data;
} }
template <typename T0, typename T1, typename... Ts> template <typename T0, typename T1, typename... Ts>
inline auto llmin(T0 d0, T1 d1, Ts... rest) constexpr auto llmin(T0 d0, T1 d1, Ts... rest)
{ {
auto minrest = llmin(d1, rest...); auto minrest = llmin(d1, rest...);
return (d0 < minrest) ? d0 : minrest; return (d0 < minrest) ? d0 : minrest;
} }
template <typename A, typename MIN, typename MAX> template <typename A, typename MIN, typename MAX>
inline A llclamp(A a, MIN minval, MAX maxval) constexpr A llclamp(A a, MIN minval, MAX maxval)
{ {
A aminval{ static_cast<A>(minval) }, amaxval{ static_cast<A>(maxval) }; A aminval{ static_cast<A>(minval) }, amaxval{ static_cast<A>(maxval) };
if ( a < aminval ) if ( a < aminval )
@ -213,13 +213,13 @@ inline A llclamp(A a, MIN minval, MAX maxval)
} }
template <class LLDATATYPE> template <class LLDATATYPE>
inline LLDATATYPE llclampf(LLDATATYPE a) constexpr LLDATATYPE llclampf(LLDATATYPE a)
{ {
return llmin(llmax(a, LLDATATYPE(0)), LLDATATYPE(1)); return llmin(llmax(a, LLDATATYPE(0)), LLDATATYPE(1));
} }
template <class LLDATATYPE> template <class LLDATATYPE>
inline LLDATATYPE llclampb(LLDATATYPE a) constexpr LLDATATYPE llclampb(LLDATATYPE a)
{ {
return llmin(llmax(a, LLDATATYPE(0)), LLDATATYPE(255)); return llmin(llmax(a, LLDATATYPE(0)), LLDATATYPE(255));
} }

View File

@ -164,14 +164,14 @@ private:
FROM mValue; FROM mValue;
public: public:
narrow(FROM value): mValue(value) {} constexpr narrow(FROM value): mValue(value) {}
/*---------------------- Narrowing unsigned to signed ----------------------*/ /*---------------------- Narrowing unsigned to signed ----------------------*/
template <typename TO, template <typename TO,
typename std::enable_if<std::is_unsigned<FROM>::value && typename std::enable_if<std::is_unsigned<FROM>::value &&
std::is_signed<TO>::value, std::is_signed<TO>::value,
bool>::type = true> bool>::type = true>
inline constexpr
operator TO() const operator TO() const
{ {
// The reason we skip the // The reason we skip the
@ -189,7 +189,7 @@ public:
typename std::enable_if<! (std::is_unsigned<FROM>::value && typename std::enable_if<! (std::is_unsigned<FROM>::value &&
std::is_signed<TO>::value), std::is_signed<TO>::value),
bool>::type = true> bool>::type = true>
inline constexpr
operator TO() const operator TO() const
{ {
// two different assert()s so we can tell which condition failed // two different assert()s so we can tell which condition failed

View File

@ -33,23 +33,23 @@
#include "llplane.h" #include "llplane.h"
#include "llvector4a.h" #include "llvector4a.h"
const F32 DEFAULT_FIELD_OF_VIEW = 60.f * DEG_TO_RAD; constexpr F32 DEFAULT_FIELD_OF_VIEW = 60.f * DEG_TO_RAD;
const F32 DEFAULT_ASPECT_RATIO = 640.f / 480.f; constexpr F32 DEFAULT_ASPECT_RATIO = 640.f / 480.f;
const F32 DEFAULT_NEAR_PLANE = 0.25f; constexpr F32 DEFAULT_NEAR_PLANE = 0.25f;
const F32 DEFAULT_FAR_PLANE = 64.f; // far reaches across two horizontal, not diagonal, regions constexpr F32 DEFAULT_FAR_PLANE = 64.f; // far reaches across two horizontal, not diagonal, regions
const F32 MAX_ASPECT_RATIO = 50.0f; constexpr F32 MAX_ASPECT_RATIO = 50.0f;
const F32 MAX_NEAR_PLANE = 1023.9f; // Clamp the near plane just before the skybox ends constexpr F32 MAX_NEAR_PLANE = 1023.9f; // Clamp the near plane just before the skybox ends
const F32 MAX_FAR_PLANE = 100000.0f; //1000000.0f; // Max allowed. Not good Z precision though. constexpr F32 MAX_FAR_PLANE = 100000.0f; //1000000.0f; // Max allowed. Not good Z precision though.
const F32 MAX_FAR_CLIP = 512.0f; constexpr F32 MAX_FAR_CLIP = 512.0f;
const F32 MIN_ASPECT_RATIO = 0.02f; constexpr F32 MIN_ASPECT_RATIO = 0.02f;
const F32 MIN_NEAR_PLANE = 0.1f; constexpr F32 MIN_NEAR_PLANE = 0.1f;
const F32 MIN_FAR_PLANE = 0.2f; constexpr F32 MIN_FAR_PLANE = 0.2f;
// Min/Max FOV values for square views. Call getMin/MaxView to get extremes based on current aspect ratio. // Min/Max FOV values for square views. Call getMin/MaxView to get extremes based on current aspect ratio.
static const F32 MIN_FIELD_OF_VIEW = 5.0f * DEG_TO_RAD; constexpr F32 MIN_FIELD_OF_VIEW = 5.0f * DEG_TO_RAD;
static const F32 MAX_FIELD_OF_VIEW = 175.f * DEG_TO_RAD; constexpr F32 MAX_FIELD_OF_VIEW = 175.f * DEG_TO_RAD;
// An LLCamera is an LLCoorFrame with a view frustum. // An LLCamera is an LLCoorFrame with a view frustum.
// This means that it has several methods for moving it around // This means that it has several methods for moving it around

View File

@ -26,7 +26,6 @@
#include "linden_common.h" #include "linden_common.h"
//#include "vmath.h"
#include "v3math.h" #include "v3math.h"
#include "m3math.h" #include "m3math.h"
#include "v4math.h" #include "v4math.h"

View File

@ -61,7 +61,7 @@ public:
//LLCoordFrame(const F32 *origin, const F32 *rotation); // Assumes "origin" is 1x3 and "rotation" is 1x9 array //LLCoordFrame(const F32 *origin, const F32 *rotation); // Assumes "origin" is 1x3 and "rotation" is 1x9 array
//LLCoordFrame(const F32 *origin_and_rotation); // Assumes "origin_and_rotation" is 1x12 array //LLCoordFrame(const F32 *origin_and_rotation); // Assumes "origin_and_rotation" is 1x12 array
bool isFinite() { return mOrigin.isFinite() && mXAxis.isFinite() && mYAxis.isFinite() && mZAxis.isFinite(); } bool isFinite() const { return mOrigin.isFinite() && mXAxis.isFinite() && mYAxis.isFinite() && mZAxis.isFinite(); }
void reset(); void reset();
void resetAxes(); void resetAxes();

View File

@ -33,7 +33,7 @@
#include "stdtypes.h" #include "stdtypes.h"
#include "v3math.h" #include "v3math.h"
const F32 DEFAULT_INTERSECTION_ERROR = 0.000001f; constexpr F32 DEFAULT_INTERSECTION_ERROR = 0.000001f;
class LLLine class LLLine
{ {

View File

@ -79,7 +79,7 @@ constexpr F32 GIMBAL_THRESHOLD = 0.000436f; // sets the gimballock threshold 0
constexpr F32 FP_MAG_THRESHOLD = 0.0000001f; constexpr F32 FP_MAG_THRESHOLD = 0.0000001f;
// TODO: Replace with logic like is_approx_equal // TODO: Replace with logic like is_approx_equal
inline bool is_approx_zero( F32 f ) { return (-F_APPROXIMATELY_ZERO < f) && (f < F_APPROXIMATELY_ZERO); } constexpr bool is_approx_zero(F32 f) { return (-F_APPROXIMATELY_ZERO < f) && (f < F_APPROXIMATELY_ZERO); }
// These functions work by interpreting sign+exp+mantissa as an unsigned // These functions work by interpreting sign+exp+mantissa as an unsigned
// integer. // integer.
@ -138,30 +138,14 @@ inline F64 llabs(const F64 a)
return F64(std::fabs(a)); return F64(std::fabs(a));
} }
inline S32 lltrunc( F32 f ) constexpr S32 lltrunc(F32 f)
{ {
#if LL_WINDOWS && !defined( __INTEL_COMPILER ) && (ADDRESS_SIZE == 32) return narrow(f);
// Avoids changing the floating point control word.
// Add or subtract 0.5 - epsilon and then round
const static U32 zpfp[] = { 0xBEFFFFFF, 0x3EFFFFFF };
S32 result;
__asm {
fld f
mov eax, f
shr eax, 29
and eax, 4
fadd dword ptr [zpfp + eax]
fistp result
}
return result;
#else
return (S32)f;
#endif
} }
inline S32 lltrunc( F64 f ) constexpr S32 lltrunc(F64 f)
{ {
return (S32)f; return narrow(f);
} }
inline S32 llfloor(F32 f) inline S32 llfloor(F32 f)
@ -274,7 +258,7 @@ constexpr F32 FAST_MAG_BETA = 0.397824734759f;
//constexpr F32 FAST_MAG_ALPHA = 0.948059448969f; //constexpr F32 FAST_MAG_ALPHA = 0.948059448969f;
//constexpr F32 FAST_MAG_BETA = 0.392699081699f; //constexpr F32 FAST_MAG_BETA = 0.392699081699f;
inline F32 fastMagnitude(F32 a, F32 b) constexpr F32 fastMagnitude(F32 a, F32 b)
{ {
a = (a > 0) ? a : -a; a = (a > 0) ? a : -a;
b = (b > 0) ? b : -b; b = (b > 0) ? b : -b;
@ -332,7 +316,7 @@ inline F32 llfastpow(const F32 x, const F32 y)
} }
inline F32 snap_to_sig_figs(F32 foo, S32 sig_figs) constexpr F32 snap_to_sig_figs(F32 foo, S32 sig_figs)
{ {
// compute the power of ten // compute the power of ten
F32 bar = 1.f; F32 bar = 1.f;
@ -350,7 +334,7 @@ inline F32 snap_to_sig_figs(F32 foo, S32 sig_figs)
using std::lerp; using std::lerp;
inline F32 lerp2d(F32 x00, F32 x01, F32 x10, F32 x11, F32 u, F32 v) constexpr F32 lerp2d(F32 x00, F32 x01, F32 x10, F32 x11, F32 u, F32 v)
{ {
F32 a = x00 + (x01-x00)*u; F32 a = x00 + (x01-x00)*u;
F32 b = x10 + (x11-x10)*u; F32 b = x10 + (x11-x10)*u;
@ -358,17 +342,17 @@ inline F32 lerp2d(F32 x00, F32 x01, F32 x10, F32 x11, F32 u, F32 v)
return r; return r;
} }
inline F32 ramp(F32 x, F32 a, F32 b) constexpr F32 ramp(F32 x, F32 a, F32 b)
{ {
return (a == b) ? 0.0f : ((a - x) / (a - b)); return (a == b) ? 0.0f : ((a - x) / (a - b));
} }
inline F32 rescale(F32 x, F32 x1, F32 x2, F32 y1, F32 y2) constexpr F32 rescale(F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
{ {
return lerp(y1, y2, ramp(x, x1, x2)); return lerp(y1, y2, ramp(x, x1, x2));
} }
inline F32 clamp_rescale(F32 x, F32 x1, F32 x2, F32 y1, F32 y2) constexpr F32 clamp_rescale(F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
{ {
if (y1 < y2) if (y1 < y2)
{ {
@ -381,7 +365,7 @@ inline F32 clamp_rescale(F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
} }
inline F32 cubic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 ) constexpr F32 cubic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
{ {
if (x <= x0) if (x <= x0)
return s0; return s0;
@ -394,14 +378,14 @@ inline F32 cubic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
return s0 + (s1 - s0) * (f * f) * (3.0f - 2.0f * f); return s0 + (s1 - s0) * (f * f) * (3.0f - 2.0f * f);
} }
inline F32 cubic_step( F32 x ) constexpr F32 cubic_step( F32 x )
{ {
x = llclampf(x); x = llclampf(x);
return (x * x) * (3.0f - 2.0f * x); return (x * x) * (3.0f - 2.0f * x);
} }
inline F32 quadratic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 ) constexpr F32 quadratic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
{ {
if (x <= x0) if (x <= x0)
return s0; return s0;
@ -415,7 +399,7 @@ inline F32 quadratic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
return (s0 * (1.f - f_squared)) + ((s1 - s0) * f_squared); return (s0 * (1.f - f_squared)) + ((s1 - s0) * f_squared);
} }
inline F32 llsimple_angle(F32 angle) constexpr F32 llsimple_angle(F32 angle)
{ {
while(angle <= -F_PI) while(angle <= -F_PI)
angle += F_TWO_PI; angle += F_TWO_PI;
@ -425,7 +409,7 @@ inline F32 llsimple_angle(F32 angle)
} }
//SDK - Renamed this to get_lower_power_two, since this is what this actually does. //SDK - Renamed this to get_lower_power_two, since this is what this actually does.
inline U32 get_lower_power_two(U32 val, U32 max_power_two) constexpr U32 get_lower_power_two(U32 val, U32 max_power_two)
{ {
if(!max_power_two) if(!max_power_two)
{ {
@ -447,7 +431,7 @@ inline U32 get_lower_power_two(U32 val, U32 max_power_two)
// number of digits, then add one. We subtract 1 initially to handle // number of digits, then add one. We subtract 1 initially to handle
// the case where the number passed in is actually a power of two. // the case where the number passed in is actually a power of two.
// WARNING: this only works with 32 bit ints. // WARNING: this only works with 32 bit ints.
inline U32 get_next_power_two(U32 val, U32 max_power_two) constexpr U32 get_next_power_two(U32 val, U32 max_power_two)
{ {
if(!max_power_two) if(!max_power_two)
{ {
@ -473,7 +457,7 @@ inline U32 get_next_power_two(U32 val, U32 max_power_two)
//get the gaussian value given the linear distance from axis x and guassian value o //get the gaussian value given the linear distance from axis x and guassian value o
inline F32 llgaussian(F32 x, F32 o) inline F32 llgaussian(F32 x, F32 o)
{ {
return 1.f/(F_SQRT_TWO_PI*o)*powf(F_E, -(x*x)/(2*o*o)); return 1.f/(F_SQRT_TWO_PI*o)*powf(F_E, -(x*x)/(2.f*o*o));
} }
//helper function for removing outliers //helper function for removing outliers
@ -526,7 +510,8 @@ inline void ll_remove_outliers(std::vector<VEC_TYPE>& data, F32 k)
// Note: in our code, values labeled as sRGB are ALWAYS gamma corrected linear values, NOT linear values with monitor gamma applied // Note: in our code, values labeled as sRGB are ALWAYS gamma corrected linear values, NOT linear values with monitor gamma applied
// Note: stored color values should always be gamma corrected linear (i.e. the values returned from an on-screen color swatch) // Note: stored color values should always be gamma corrected linear (i.e. the values returned from an on-screen color swatch)
// Note: DO NOT cache the conversion. This leads to error prone synchronization and is actually slower in the typical case due to cache misses // Note: DO NOT cache the conversion. This leads to error prone synchronization and is actually slower in the typical case due to cache misses
inline float linearTosRGB(const float val) { inline float linearTosRGB(const float val)
{
if (val < 0.0031308f) { if (val < 0.0031308f) {
return val * 12.92f; return val * 12.92f;
} }
@ -541,7 +526,8 @@ inline float linearTosRGB(const float val) {
// Note: Stored color values should generally be gamma corrected sRGB. // Note: Stored color values should generally be gamma corrected sRGB.
// If you're serializing the return value of this function, you're probably doing it wrong. // If you're serializing the return value of this function, you're probably doing it wrong.
// Note: DO NOT cache the conversion. This leads to error prone synchronization and is actually slower in the typical case due to cache misses. // Note: DO NOT cache the conversion. This leads to error prone synchronization and is actually slower in the typical case due to cache misses.
inline float sRGBtoLinear(const float val) { inline float sRGBtoLinear(const float val)
{
if (val < 0.04045f) { if (val < 0.04045f) {
return val / 12.92f; return val / 12.92f;
} }

View File

@ -30,7 +30,6 @@
#include "llquaternion.h" #include "llquaternion.h"
//#include "vmath.h"
#include "v3math.h" #include "v3math.h"
#include "v3dmath.h" #include "v3dmath.h"
#include "v4math.h" #include "v4math.h"

View File

@ -45,7 +45,6 @@ class LLVolumeOctree;
#include "lluuid.h" #include "lluuid.h"
#include "v4color.h" #include "v4color.h"
//#include "vmath.h"
#include "v2math.h" #include "v2math.h"
#include "v3math.h" #include "v3math.h"
#include "v3dmath.h" #include "v3dmath.h"

View File

@ -26,7 +26,6 @@
#include "linden_common.h" #include "linden_common.h"
//#include "vmath.h"
#include "v3math.h" #include "v3math.h"
#include "v3dmath.h" #include "v3dmath.h"
#include "v4math.h" #include "v4math.h"

View File

@ -26,7 +26,6 @@
#include "linden_common.h" #include "linden_common.h"
//#include "vmath.h"
#include "v3math.h" #include "v3math.h"
#include "v4math.h" #include "v4math.h"
#include "m4math.h" #include "m4math.h"

View File

@ -26,7 +26,6 @@
#include "linden_common.h" #include "linden_common.h"
//#include "vmath.h"
#include "v2math.h" #include "v2math.h"
#include "v3math.h" #include "v3math.h"
#include "v4math.h" #include "v4math.h"
@ -47,8 +46,8 @@ bool LLVector2::abs()
{ {
bool ret{ false }; bool ret{ false };
if (mV[0] < 0.f) { mV[0] = -mV[0]; ret = true; } if (mV[VX] < 0.f) { mV[VX] = -mV[VX]; ret = true; }
if (mV[1] < 0.f) { mV[1] = -mV[1]; ret = true; } if (mV[VY] < 0.f) { mV[VY] = -mV[VY]; ret = true; }
return ret; return ret;
} }
@ -67,7 +66,7 @@ F32 angle_between(const LLVector2& a, const LLVector2& b)
return angle; return angle;
} }
bool are_parallel(const LLVector2 &a, const LLVector2 &b, float epsilon) bool are_parallel(const LLVector2& a, const LLVector2& b, F32 epsilon)
{ {
LLVector2 an = a; LLVector2 an = a;
LLVector2 bn = b; LLVector2 bn = b;
@ -84,22 +83,22 @@ bool are_parallel(const LLVector2 &a, const LLVector2 &b, float epsilon)
F32 dist_vec(const LLVector2& a, const LLVector2& b) F32 dist_vec(const LLVector2& a, const LLVector2& b)
{ {
F32 x = a.mV[0] - b.mV[0]; F32 x = a.mV[VX] - b.mV[VX];
F32 y = a.mV[1] - b.mV[1]; F32 y = a.mV[VY] - b.mV[VY];
return (F32) sqrt( x*x + y*y ); return (F32) sqrt( x*x + y*y );
} }
F32 dist_vec_squared(const LLVector2& a, const LLVector2& b) F32 dist_vec_squared(const LLVector2& a, const LLVector2& b)
{ {
F32 x = a.mV[0] - b.mV[0]; F32 x = a.mV[VX] - b.mV[VX];
F32 y = a.mV[1] - b.mV[1]; F32 y = a.mV[VY] - b.mV[VY];
return x*x + y*y; return x*x + y*y;
} }
F32 dist_vec_squared2D(const LLVector2& a, const LLVector2& b) F32 dist_vec_squared2D(const LLVector2& a, const LLVector2& b)
{ {
F32 x = a.mV[0] - b.mV[0]; F32 x = a.mV[VX] - b.mV[VX];
F32 y = a.mV[1] - b.mV[1]; F32 y = a.mV[VY] - b.mV[VY];
return x*x + y*y; return x*x + y*y;
} }
@ -113,14 +112,14 @@ LLVector2 lerp(const LLVector2 &a, const LLVector2 &b, F32 u)
LLSD LLVector2::getValue() const LLSD LLVector2::getValue() const
{ {
LLSD ret; LLSD ret;
ret[0] = mV[0]; ret[VX] = mV[VX];
ret[1] = mV[1]; ret[VY] = mV[VY];
return ret; return ret;
} }
void LLVector2::setValue(const LLSD& sd) void LLVector2::setValue(const LLSD& sd)
{ {
mV[0] = (F32) sd[0].asReal(); mV[VX] = (F32) sd[0].asReal();
mV[1] = (F32) sd[1].asReal(); mV[VY] = (F32) sd[1].asReal();
} }

View File

@ -36,7 +36,7 @@ class LLQuaternion;
// Llvector2 = |x y z w| // Llvector2 = |x y z w|
static const U32 LENGTHOFVECTOR2 = 2; static constexpr U32 LENGTHOFVECTOR2 = 2;
class LLVector2 class LLVector2
{ {
@ -82,7 +82,7 @@ class LLVector2
const LLVector2& scaleVec(const LLVector2& vec); // scales per component by vec const LLVector2& scaleVec(const LLVector2& vec); // scales per component by vec
bool isNull(); // Returns true if vector has a _very_small_ length bool isNull() const; // Returns true if vector has a _very_small_ length
bool isExactlyZero() const { return !mV[VX] && !mV[VY]; } bool isExactlyZero() const { return !mV[VX] && !mV[VY]; }
F32 operator[](int idx) const { return mV[idx]; } F32 operator[](int idx) const { return mV[idx]; }
@ -122,7 +122,7 @@ LLVector2 lerp(const LLVector2 &a, const LLVector2 &b, F32 u); // Returns a vect
// Constructors // Constructors
inline LLVector2::LLVector2(void) inline LLVector2::LLVector2()
{ {
mV[VX] = 0.f; mV[VX] = 0.f;
mV[VY] = 0.f; mV[VY] = 0.f;
@ -153,27 +153,27 @@ inline LLVector2::LLVector2(const LLSD &sd)
// Clear and Assignment Functions // Clear and Assignment Functions
inline void LLVector2::clear(void) inline void LLVector2::clear()
{ {
mV[VX] = 0.f; mV[VX] = 0.f;
mV[VY] = 0.f; mV[VY] = 0.f;
} }
inline void LLVector2::setZero(void) inline void LLVector2::setZero()
{ {
mV[VX] = 0.f; mV[VX] = 0.f;
mV[VY] = 0.f; mV[VY] = 0.f;
} }
// deprecated // deprecated
inline void LLVector2::clearVec(void) inline void LLVector2::clearVec()
{ {
mV[VX] = 0.f; mV[VX] = 0.f;
mV[VY] = 0.f; mV[VY] = 0.f;
} }
// deprecated // deprecated
inline void LLVector2::zeroVec(void) inline void LLVector2::zeroVec()
{ {
mV[VX] = 0.f; mV[VX] = 0.f;
mV[VY] = 0.f; mV[VY] = 0.f;
@ -222,31 +222,31 @@ inline void LLVector2::setVec(const F32 *vec)
// LLVector2 Magnitude and Normalization Functions // LLVector2 Magnitude and Normalization Functions
inline F32 LLVector2::length(void) const inline F32 LLVector2::length() const
{ {
return (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1]); return sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY]);
} }
inline F32 LLVector2::lengthSquared(void) const inline F32 LLVector2::lengthSquared() const
{ {
return mV[0]*mV[0] + mV[1]*mV[1]; return mV[VX]*mV[VX] + mV[VY]*mV[VY];
} }
inline F32 LLVector2::normalize(void) inline F32 LLVector2::normalize()
{ {
F32 mag = (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1]); F32 mag = sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY]);
F32 oomag; F32 oomag;
if (mag > FP_MAG_THRESHOLD) if (mag > FP_MAG_THRESHOLD)
{ {
oomag = 1.f/mag; oomag = 1.f/mag;
mV[0] *= oomag; mV[VX] *= oomag;
mV[1] *= oomag; mV[VY] *= oomag;
} }
else else
{ {
mV[0] = 0.f; mV[VX] = 0.f;
mV[1] = 0.f; mV[VY] = 0.f;
mag = 0; mag = 0;
} }
return (mag); return (mag);
@ -259,33 +259,33 @@ inline bool LLVector2::isFinite() const
} }
// deprecated // deprecated
inline F32 LLVector2::magVec(void) const inline F32 LLVector2::magVec() const
{ {
return (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1]); return sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY]);
} }
// deprecated // deprecated
inline F32 LLVector2::magVecSquared(void) const inline F32 LLVector2::magVecSquared() const
{ {
return mV[0]*mV[0] + mV[1]*mV[1]; return mV[VX]*mV[VX] + mV[VY]*mV[VY];
} }
// deprecated // deprecated
inline F32 LLVector2::normVec(void) inline F32 LLVector2::normVec()
{ {
F32 mag = (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1]); F32 mag = sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY]);
F32 oomag; F32 oomag;
if (mag > FP_MAG_THRESHOLD) if (mag > FP_MAG_THRESHOLD)
{ {
oomag = 1.f/mag; oomag = 1.f/mag;
mV[0] *= oomag; mV[VX] *= oomag;
mV[1] *= oomag; mV[VY] *= oomag;
} }
else else
{ {
mV[0] = 0.f; mV[VX] = 0.f;
mV[1] = 0.f; mV[VY] = 0.f;
mag = 0; mag = 0;
} }
return (mag); return (mag);
@ -299,7 +299,7 @@ inline const LLVector2& LLVector2::scaleVec(const LLVector2& vec)
return *this; return *this;
} }
inline bool LLVector2::isNull() inline bool LLVector2::isNull() const
{ {
if (F_APPROXIMATELY_ZERO > mV[VX]*mV[VX] + mV[VY]*mV[VY]) if (F_APPROXIMATELY_ZERO > mV[VX]*mV[VX] + mV[VY]*mV[VY])
{ {
@ -339,81 +339,81 @@ inline LLVector2 operator-(const LLVector2 &a, const LLVector2 &b)
inline F32 operator*(const LLVector2& a, const LLVector2& b) inline F32 operator*(const LLVector2& a, const LLVector2& b)
{ {
return (a.mV[0]*b.mV[0] + a.mV[1]*b.mV[1]); return (a.mV[VX]*b.mV[VX] + a.mV[VY]*b.mV[VY]);
} }
inline LLVector2 operator%(const LLVector2& a, const LLVector2& b) inline LLVector2 operator%(const LLVector2& a, const LLVector2& b)
{ {
return LLVector2(a.mV[0]*b.mV[1] - b.mV[0]*a.mV[1], a.mV[1]*b.mV[0] - b.mV[1]*a.mV[0]); return LLVector2(a.mV[VX]*b.mV[VY] - b.mV[VX]*a.mV[VY], a.mV[VY]*b.mV[VX] - b.mV[VY]*a.mV[VX]);
} }
inline LLVector2 operator/(const LLVector2& a, F32 k) inline LLVector2 operator/(const LLVector2& a, F32 k)
{ {
F32 t = 1.f / k; F32 t = 1.f / k;
return LLVector2( a.mV[0] * t, a.mV[1] * t ); return LLVector2( a.mV[VX] * t, a.mV[VY] * t );
} }
inline LLVector2 operator*(const LLVector2& a, F32 k) inline LLVector2 operator*(const LLVector2& a, F32 k)
{ {
return LLVector2( a.mV[0] * k, a.mV[1] * k ); return LLVector2( a.mV[VX] * k, a.mV[VY] * k );
} }
inline LLVector2 operator*(F32 k, const LLVector2& a) inline LLVector2 operator*(F32 k, const LLVector2& a)
{ {
return LLVector2( a.mV[0] * k, a.mV[1] * k ); return LLVector2( a.mV[VX] * k, a.mV[VY] * k );
} }
inline bool operator==(const LLVector2& a, const LLVector2& b) inline bool operator==(const LLVector2& a, const LLVector2& b)
{ {
return ( (a.mV[0] == b.mV[0]) return ( (a.mV[VX] == b.mV[VX])
&&(a.mV[1] == b.mV[1])); &&(a.mV[VY] == b.mV[VY]));
} }
inline bool operator!=(const LLVector2& a, const LLVector2& b) inline bool operator!=(const LLVector2& a, const LLVector2& b)
{ {
return ( (a.mV[0] != b.mV[0]) return ( (a.mV[VX] != b.mV[VX])
||(a.mV[1] != b.mV[1])); ||(a.mV[VY] != b.mV[VY]));
} }
inline const LLVector2& operator+=(LLVector2& a, const LLVector2& b) inline const LLVector2& operator+=(LLVector2& a, const LLVector2& b)
{ {
a.mV[0] += b.mV[0]; a.mV[VX] += b.mV[VX];
a.mV[1] += b.mV[1]; a.mV[VY] += b.mV[VY];
return a; return a;
} }
inline const LLVector2& operator-=(LLVector2& a, const LLVector2& b) inline const LLVector2& operator-=(LLVector2& a, const LLVector2& b)
{ {
a.mV[0] -= b.mV[0]; a.mV[VX] -= b.mV[VX];
a.mV[1] -= b.mV[1]; a.mV[VY] -= b.mV[VY];
return a; return a;
} }
inline const LLVector2& operator%=(LLVector2& a, const LLVector2& b) inline const LLVector2& operator%=(LLVector2& a, const LLVector2& b)
{ {
LLVector2 ret(a.mV[0]*b.mV[1] - b.mV[0]*a.mV[1], a.mV[1]*b.mV[0] - b.mV[1]*a.mV[0]); LLVector2 ret(a.mV[VX]*b.mV[VY] - b.mV[VX]*a.mV[VY], a.mV[VY]*b.mV[VX] - b.mV[VY]*a.mV[VX]);
a = ret; a = ret;
return a; return a;
} }
inline const LLVector2& operator*=(LLVector2& a, F32 k) inline const LLVector2& operator*=(LLVector2& a, F32 k)
{ {
a.mV[0] *= k; a.mV[VX] *= k;
a.mV[1] *= k; a.mV[VY] *= k;
return a; return a;
} }
inline const LLVector2& operator/=(LLVector2& a, F32 k) inline const LLVector2& operator/=(LLVector2& a, F32 k)
{ {
F32 t = 1.f / k; F32 t = 1.f / k;
a.mV[0] *= t; a.mV[VX] *= t;
a.mV[1] *= t; a.mV[VY] *= t;
return a; return a;
} }
inline LLVector2 operator-(const LLVector2& a) inline LLVector2 operator-(const LLVector2& a)
{ {
return LLVector2( -a.mV[0], -a.mV[1] ); return LLVector2( -a.mV[VX], -a.mV[VY] );
} }
inline void update_min_max(LLVector2& min, LLVector2& max, const LLVector2& pos) inline void update_min_max(LLVector2& min, LLVector2& max, const LLVector2& pos)

View File

@ -36,16 +36,16 @@ LLColor3 LLColor3::grey (0.5f, 0.5f, 0.5f);
LLColor3::LLColor3(const LLColor4& a) LLColor3::LLColor3(const LLColor4& a)
{ {
mV[0] = a.mV[0]; mV[VRED] = a.mV[VRED];
mV[1] = a.mV[1]; mV[VGREEN] = a.mV[VGREEN];
mV[2] = a.mV[2]; mV[VBLUE] = a.mV[VBLUE];
} }
LLColor3::LLColor3(const LLVector4& a) LLColor3::LLColor3(const LLVector4& a)
{ {
mV[0] = a.mV[0]; mV[VRED] = a.mV[VRED];
mV[1] = a.mV[1]; mV[VGREEN] = a.mV[VGREEN];
mV[2] = a.mV[2]; mV[VBLUE] = a.mV[VBLUE];
} }
LLColor3::LLColor3(const LLSD& sd) LLColor3::LLColor3(const LLSD& sd)
@ -55,9 +55,9 @@ LLColor3::LLColor3(const LLSD &sd)
const LLColor3& LLColor3::operator=(const LLColor4& a) const LLColor3& LLColor3::operator=(const LLColor4& a)
{ {
mV[0] = a.mV[0]; mV[VRED] = a.mV[VRED];
mV[1] = a.mV[1]; mV[VGREEN] = a.mV[VGREEN];
mV[2] = a.mV[2]; mV[VBLUE] = a.mV[VBLUE];
return (*this); return (*this);
} }
@ -69,11 +69,16 @@ std::ostream& operator<<(std::ostream& s, const LLColor3 &a)
static F32 hueToRgb(F32 val1In, F32 val2In, F32 valHUeIn) static F32 hueToRgb(F32 val1In, F32 val2In, F32 valHUeIn)
{ {
if ( valHUeIn < 0.0f ) valHUeIn += 1.0f; if (valHUeIn < 0.0f)
if ( valHUeIn > 1.0f ) valHUeIn -= 1.0f; valHUeIn += 1.0f;
if ( ( 6.0f * valHUeIn ) < 1.0f ) return ( val1In + ( val2In - val1In ) * 6.0f * valHUeIn ); if (valHUeIn > 1.0f)
if ( ( 2.0f * valHUeIn ) < 1.0f ) return ( val2In ); valHUeIn -= 1.0f;
if ( ( 3.0f * valHUeIn ) < 2.0f ) return ( val1In + ( val2In - val1In ) * ( ( 2.0f / 3.0f ) - valHUeIn ) * 6.0f ); if ((6.0f * valHUeIn) < 1.0f)
return (val1In + (val2In - val1In) * 6.0f * valHUeIn);
if ((2.0f * valHUeIn) < 1.0f)
return (val2In);
if ((3.0f * valHUeIn) < 2.0f)
return (val1In + (val2In - val1In) * ((2.0f / 3.0f) - valHUeIn) * 6.0f);
return (val1In); return (val1In);
} }
@ -136,18 +141,21 @@ void LLColor3::calcHSL(F32* hue, F32* saturation, F32* luminance) const
if (var_R >= var_Max) if (var_R >= var_Max)
H = del_B - del_G; H = del_B - del_G;
else else if (var_G >= var_Max)
if ( var_G >= var_Max )
H = (1.0f / 3.0f) + del_R - del_B; H = (1.0f / 3.0f) + del_R - del_B;
else else if (var_B >= var_Max)
if ( var_B >= var_Max )
H = (2.0f / 3.0f) + del_G - del_R; H = (2.0f / 3.0f) + del_G - del_R;
if ( H < 0.0f ) H += 1.0f; if (H < 0.0f)
if ( H > 1.0f ) H -= 1.0f; H += 1.0f;
if (H > 1.0f)
H -= 1.0f;
} }
if (hue) *hue = H; if (hue)
if (saturation) *saturation = S; *hue = H;
if (luminance) *luminance = L; if (saturation)
*saturation = S;
if (luminance)
*luminance = L;
} }

View File

@ -38,7 +38,7 @@ class LLVector4;
// LLColor3 = |r g b| // LLColor3 = |r g b|
static const U32 LENGTHOFCOLOR3 = 3; static constexpr U32 LENGTHOFCOLOR3 = 3;
class LLColor3 class LLColor3
{ {
@ -58,21 +58,20 @@ public:
explicit LLColor3(const LLVector4& vector4); // "explicit" to avoid automatic conversion explicit LLColor3(const LLVector4& vector4); // "explicit" to avoid automatic conversion
LLColor3(const LLSD& sd); LLColor3(const LLSD& sd);
LLSD getValue() const LLSD getValue() const
{ {
LLSD ret; LLSD ret;
ret[0] = mV[0]; ret[VRED] = mV[VRED];
ret[1] = mV[1]; ret[VGREEN] = mV[VGREEN];
ret[2] = mV[2]; ret[VBLUE] = mV[VBLUE];
return ret; return ret;
} }
void setValue(const LLSD& sd) void setValue(const LLSD& sd)
{ {
mV[0] = (F32) sd[0].asReal();; mV[VRED] = (F32)sd[VRED].asReal();
mV[1] = (F32) sd[1].asReal();; mV[VGREEN] = (F32)sd[VGREEN].asReal();
mV[2] = (F32) sd[2].asReal();; mV[VBLUE] = (F32)sd[VBLUE].asReal();
} }
void setHSL(F32 hue, F32 saturation, F32 luminance); void setHSL(F32 hue, F32 saturation, F32 luminance);
@ -111,21 +110,15 @@ public:
const LLColor3& operator=(const LLColor4& a); const LLColor3& operator=(const LLColor4& a);
LL_FORCE_INLINE LLColor3 divide(const LLColor3 &col2) LL_FORCE_INLINE LLColor3 divide(const LLColor3& col2) const
{ {
return LLColor3( return LLColor3(mV[VRED] / col2.mV[VRED], mV[VGREEN] / col2.mV[VGREEN], mV[VBLUE] / col2.mV[VBLUE]);
mV[0] / col2.mV[0],
mV[1] / col2.mV[1],
mV[2] / col2.mV[2] );
} }
LL_FORCE_INLINE LLColor3 color_norm() LL_FORCE_INLINE LLColor3 color_norm() const
{ {
F32 l = length(); F32 l = length();
return LLColor3( return LLColor3(mV[VRED] / l, mV[VGREEN] / l, mV[VBLUE] / l);
mV[0] / l,
mV[1] / l,
mV[2] / l );
} }
friend std::ostream& operator<<(std::ostream& s, const LLColor3& a); // Print a friend std::ostream& operator<<(std::ostream& s, const LLColor3& a); // Print a
@ -153,33 +146,32 @@ public:
LLColor3 lerp(const LLColor3& a, const LLColor3& b, F32 u); LLColor3 lerp(const LLColor3& a, const LLColor3& b, F32 u);
void LLColor3::clamp() void LLColor3::clamp()
{ {
// Clamp the color... // Clamp the color...
if (mV[0] < 0.f) if (mV[VRED] < 0.f)
{ {
mV[0] = 0.f; mV[VRED] = 0.f;
} }
else if (mV[0] > 1.f) else if (mV[VRED] > 1.f)
{ {
mV[0] = 1.f; mV[VRED] = 1.f;
} }
if (mV[1] < 0.f) if (mV[VGREEN] < 0.f)
{ {
mV[1] = 0.f; mV[VGREEN] = 0.f;
} }
else if (mV[1] > 1.f) else if (mV[VGREEN] > 1.f)
{ {
mV[1] = 1.f; mV[VGREEN] = 1.f;
} }
if (mV[2] < 0.f) if (mV[VBLUE] < 0.f)
{ {
mV[2] = 0.f; mV[VBLUE] = 0.f;
} }
else if (mV[2] > 1.f) else if (mV[VBLUE] > 1.f)
{ {
mV[2] = 1.f; mV[VBLUE] = 1.f;
} }
} }
@ -187,11 +179,11 @@ void LLColor3::clamp()
F32 distVec(const LLColor3& a, const LLColor3& b); // Returns distance between a and b F32 distVec(const LLColor3& a, const LLColor3& b); // Returns distance between a and b
F32 distVec_squared(const LLColor3& a, const LLColor3& b); // Returns distance squared between a and b F32 distVec_squared(const LLColor3& a, const LLColor3& b); // Returns distance squared between a and b
inline LLColor3::LLColor3(void) inline LLColor3::LLColor3()
{ {
mV[0] = 0.f; mV[VRED] = 0.f;
mV[1] = 0.f; mV[VGREEN] = 0.f;
mV[2] = 0.f; mV[VBLUE] = 0.f;
} }
inline LLColor3::LLColor3(F32 r, F32 g, F32 b) inline LLColor3::LLColor3(F32 r, F32 g, F32 b)
@ -201,7 +193,6 @@ inline LLColor3::LLColor3(F32 r, F32 g, F32 b)
mV[VBLUE] = b; mV[VBLUE] = b;
} }
inline LLColor3::LLColor3(const F32* vec) inline LLColor3::LLColor3(const F32* vec)
{ {
mV[VRED] = vec[VRED]; mV[VRED] = vec[VRED];
@ -213,300 +204,284 @@ inline LLColor3::LLColor3(const char* color_string) // takes a string of format
{ {
if (strlen(color_string) < 6) /* Flawfinder: ignore */ if (strlen(color_string) < 6) /* Flawfinder: ignore */
{ {
mV[0] = 0.f; mV[VRED] = 0.f;
mV[1] = 0.f; mV[VGREEN] = 0.f;
mV[2] = 0.f; mV[VBLUE] = 0.f;
return; return;
} }
char tempstr[7]; char tempstr[7];
strncpy(tempstr, color_string, 6); /* Flawfinder: ignore */ strncpy(tempstr, color_string, 6); /* Flawfinder: ignore */
tempstr[6] = '\0'; tempstr[6] = '\0';
mV[VBLUE] = (F32)strtol(&tempstr[4],NULL,16)/255.f; mV[VBLUE] = (F32)strtol(&tempstr[4], nullptr, 16) / 255.f;
tempstr[4] = '\0'; tempstr[4] = '\0';
mV[VGREEN] = (F32)strtol(&tempstr[2],NULL,16)/255.f; mV[VGREEN] = (F32)strtol(&tempstr[2], nullptr, 16) / 255.f;
tempstr[2] = '\0'; tempstr[2] = '\0';
mV[VRED] = (F32)strtol(&tempstr[0],NULL,16)/255.f; mV[VRED] = (F32)strtol(&tempstr[0], nullptr, 16) / 255.f;
} }
inline const LLColor3& LLColor3::setToBlack(void) inline const LLColor3& LLColor3::setToBlack()
{ {
mV[0] = 0.f; mV[VRED] = 0.f;
mV[1] = 0.f; mV[VGREEN] = 0.f;
mV[2] = 0.f; mV[VBLUE] = 0.f;
return (*this); return (*this);
} }
inline const LLColor3& LLColor3::setToWhite(void) inline const LLColor3& LLColor3::setToWhite()
{ {
mV[0] = 1.f; mV[VRED] = 1.f;
mV[1] = 1.f; mV[VGREEN] = 1.f;
mV[2] = 1.f; mV[VBLUE] = 1.f;
return (*this); return (*this);
} }
inline const LLColor3& LLColor3::set(F32 r, F32 g, F32 b) inline const LLColor3& LLColor3::set(F32 r, F32 g, F32 b)
{ {
mV[0] = r; mV[VRED] = r;
mV[1] = g; mV[VGREEN] = g;
mV[2] = b; mV[VBLUE] = b;
return (*this); return (*this);
} }
inline const LLColor3& LLColor3::set(const LLColor3& vec) inline const LLColor3& LLColor3::set(const LLColor3& vec)
{ {
mV[0] = vec.mV[0]; mV[VRED] = vec.mV[VRED];
mV[1] = vec.mV[1]; mV[VGREEN] = vec.mV[VGREEN];
mV[2] = vec.mV[2]; mV[VBLUE] = vec.mV[VBLUE];
return (*this); return (*this);
} }
inline const LLColor3& LLColor3::set(const F32* vec) inline const LLColor3& LLColor3::set(const F32* vec)
{ {
mV[0] = vec[0]; mV[VRED] = vec[VRED];
mV[1] = vec[1]; mV[VGREEN] = vec[VGREEN];
mV[2] = vec[2]; mV[VBLUE] = vec[VBLUE];
return (*this); return (*this);
} }
// deprecated // deprecated
inline const LLColor3& LLColor3::setVec(F32 r, F32 g, F32 b) inline const LLColor3& LLColor3::setVec(F32 r, F32 g, F32 b)
{ {
mV[0] = r; mV[VRED] = r;
mV[1] = g; mV[VGREEN] = g;
mV[2] = b; mV[VBLUE] = b;
return (*this); return (*this);
} }
// deprecated // deprecated
inline const LLColor3& LLColor3::setVec(const LLColor3& vec) inline const LLColor3& LLColor3::setVec(const LLColor3& vec)
{ {
mV[0] = vec.mV[0]; mV[VRED] = vec.mV[VRED];
mV[1] = vec.mV[1]; mV[VGREEN] = vec.mV[VGREEN];
mV[2] = vec.mV[2]; mV[VBLUE] = vec.mV[VBLUE];
return (*this); return (*this);
} }
// deprecated // deprecated
inline const LLColor3& LLColor3::setVec(const F32* vec) inline const LLColor3& LLColor3::setVec(const F32* vec)
{ {
mV[0] = vec[0]; mV[VRED] = vec[VRED];
mV[1] = vec[1]; mV[VGREEN] = vec[VGREEN];
mV[2] = vec[2]; mV[VBLUE] = vec[VBLUE];
return (*this); return (*this);
} }
inline F32 LLColor3::brightness(void) const inline F32 LLColor3::brightness() const
{ {
return (mV[0] + mV[1] + mV[2]) / 3.0f; return (mV[VRED] + mV[VGREEN] + mV[VBLUE]) / 3.0f;
} }
inline F32 LLColor3::length(void) const inline F32 LLColor3::length() const
{ {
return (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]); return sqrt(mV[VRED] * mV[VRED] + mV[VGREEN] * mV[VGREEN] + mV[VBLUE] * mV[VBLUE]);
} }
inline F32 LLColor3::lengthSquared(void) const inline F32 LLColor3::lengthSquared() const
{ {
return mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]; return mV[VRED] * mV[VRED] + mV[VGREEN] * mV[VGREEN] + mV[VBLUE] * mV[VBLUE];
} }
inline F32 LLColor3::normalize(void) inline F32 LLColor3::normalize()
{ {
F32 mag = (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]); F32 mag = sqrt(mV[VRED] * mV[VRED] + mV[VGREEN] * mV[VGREEN] + mV[VBLUE] * mV[VBLUE]);
F32 oomag; F32 oomag;
if (mag) if (mag)
{ {
oomag = 1.f / mag; oomag = 1.f / mag;
mV[0] *= oomag; mV[VRED] *= oomag;
mV[1] *= oomag; mV[VGREEN] *= oomag;
mV[2] *= oomag; mV[VBLUE] *= oomag;
} }
return (mag); return mag;
} }
// deprecated // deprecated
inline F32 LLColor3::magVec(void) const inline F32 LLColor3::magVec() const
{ {
return (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]); return sqrt(mV[VRED] * mV[VRED] + mV[VGREEN] * mV[VGREEN] + mV[VBLUE] * mV[VBLUE]);
} }
// deprecated // deprecated
inline F32 LLColor3::magVecSquared(void) const inline F32 LLColor3::magVecSquared() const
{ {
return mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]; return mV[VRED] * mV[VRED] + mV[VGREEN] * mV[VGREEN] + mV[VBLUE] * mV[VBLUE];
} }
// deprecated // deprecated
inline F32 LLColor3::normVec(void) inline F32 LLColor3::normVec()
{ {
F32 mag = (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]); F32 mag = sqrt(mV[VRED] * mV[VRED] + mV[VGREEN] * mV[VGREEN] + mV[VBLUE] * mV[VBLUE]);
F32 oomag; F32 oomag;
if (mag) if (mag)
{ {
oomag = 1.f / mag; oomag = 1.f / mag;
mV[0] *= oomag; mV[VRED] *= oomag;
mV[1] *= oomag; mV[VGREEN] *= oomag;
mV[2] *= oomag; mV[VBLUE] *= oomag;
} }
return (mag); return mag;
} }
inline void LLColor3::exp() inline void LLColor3::exp()
{ {
#if 0 #if 0
mV[0] = ::exp(mV[0]); mV[VRED] = ::exp(mV[VRED]);
mV[1] = ::exp(mV[1]); mV[VGREEN] = ::exp(mV[VGREEN]);
mV[2] = ::exp(mV[2]); mV[VBLUE] = ::exp(mV[VBLUE]);
#else #else
mV[0] = (F32)LL_FAST_EXP(mV[0]); mV[VRED] = (F32)LL_FAST_EXP(mV[VRED]);
mV[1] = (F32)LL_FAST_EXP(mV[1]); mV[VGREEN] = (F32)LL_FAST_EXP(mV[VGREEN]);
mV[2] = (F32)LL_FAST_EXP(mV[2]); mV[VBLUE] = (F32)LL_FAST_EXP(mV[VBLUE]);
#endif #endif
} }
inline LLColor3 operator+(const LLColor3& a, const LLColor3& b) inline LLColor3 operator+(const LLColor3& a, const LLColor3& b)
{ {
return LLColor3( return LLColor3(a.mV[VRED] + b.mV[VRED], a.mV[VGREEN] + b.mV[VGREEN], a.mV[VBLUE] + b.mV[VBLUE]);
a.mV[0] + b.mV[0],
a.mV[1] + b.mV[1],
a.mV[2] + b.mV[2]);
} }
inline LLColor3 operator-(const LLColor3& a, const LLColor3& b) inline LLColor3 operator-(const LLColor3& a, const LLColor3& b)
{ {
return LLColor3( return LLColor3(a.mV[VRED] - b.mV[VRED], a.mV[VGREEN] - b.mV[VGREEN], a.mV[VBLUE] - b.mV[VBLUE]);
a.mV[0] - b.mV[0],
a.mV[1] - b.mV[1],
a.mV[2] - b.mV[2]);
} }
inline LLColor3 operator*(const LLColor3& a, const LLColor3& b) inline LLColor3 operator*(const LLColor3& a, const LLColor3& b)
{ {
return LLColor3( return LLColor3(a.mV[VRED] * b.mV[VRED], a.mV[VGREEN] * b.mV[VGREEN], a.mV[VBLUE] * b.mV[VBLUE]);
a.mV[0] * b.mV[0],
a.mV[1] * b.mV[1],
a.mV[2] * b.mV[2]);
} }
inline LLColor3 operator*(const LLColor3& a, F32 k) inline LLColor3 operator*(const LLColor3& a, F32 k)
{ {
return LLColor3( a.mV[0] * k, a.mV[1] * k, a.mV[2] * k ); return LLColor3(a.mV[VRED] * k, a.mV[VGREEN] * k, a.mV[VBLUE] * k);
} }
inline LLColor3 operator*(F32 k, const LLColor3& a) inline LLColor3 operator*(F32 k, const LLColor3& a)
{ {
return LLColor3( a.mV[0] * k, a.mV[1] * k, a.mV[2] * k ); return LLColor3(a.mV[VRED] * k, a.mV[VGREEN] * k, a.mV[VBLUE] * k);
} }
inline bool operator==(const LLColor3& a, const LLColor3& b) inline bool operator==(const LLColor3& a, const LLColor3& b)
{ {
return ( (a.mV[0] == b.mV[0]) return ((a.mV[VRED] == b.mV[VRED]) && (a.mV[VGREEN] == b.mV[VGREEN]) && (a.mV[VBLUE] == b.mV[VBLUE]));
&&(a.mV[1] == b.mV[1])
&&(a.mV[2] == b.mV[2]));
} }
inline bool operator!=(const LLColor3& a, const LLColor3& b) inline bool operator!=(const LLColor3& a, const LLColor3& b)
{ {
return ( (a.mV[0] != b.mV[0]) return ((a.mV[VRED] != b.mV[VRED]) || (a.mV[VGREEN] != b.mV[VGREEN]) || (a.mV[VBLUE] != b.mV[VBLUE]));
||(a.mV[1] != b.mV[1])
||(a.mV[2] != b.mV[2]));
} }
inline const LLColor3& operator*=(LLColor3& a, const LLColor3& b) inline const LLColor3& operator*=(LLColor3& a, const LLColor3& b)
{ {
a.mV[0] *= b.mV[0]; a.mV[VRED] *= b.mV[VRED];
a.mV[1] *= b.mV[1]; a.mV[VGREEN] *= b.mV[VGREEN];
a.mV[2] *= b.mV[2]; a.mV[VBLUE] *= b.mV[VBLUE];
return a; return a;
} }
inline const LLColor3& operator+=(LLColor3& a, const LLColor3& b) inline const LLColor3& operator+=(LLColor3& a, const LLColor3& b)
{ {
a.mV[0] += b.mV[0]; a.mV[VRED] += b.mV[VRED];
a.mV[1] += b.mV[1]; a.mV[VGREEN] += b.mV[VGREEN];
a.mV[2] += b.mV[2]; a.mV[VBLUE] += b.mV[VBLUE];
return a; return a;
} }
inline const LLColor3& operator-=(LLColor3& a, const LLColor3& b) inline const LLColor3& operator-=(LLColor3& a, const LLColor3& b)
{ {
a.mV[0] -= b.mV[0]; a.mV[VRED] -= b.mV[VRED];
a.mV[1] -= b.mV[1]; a.mV[VGREEN] -= b.mV[VGREEN];
a.mV[2] -= b.mV[2]; a.mV[VBLUE] -= b.mV[VBLUE];
return a; return a;
} }
inline const LLColor3& operator*=(LLColor3& a, F32 k) inline const LLColor3& operator*=(LLColor3& a, F32 k)
{ {
a.mV[0] *= k; a.mV[VRED] *= k;
a.mV[1] *= k; a.mV[VGREEN] *= k;
a.mV[2] *= k; a.mV[VBLUE] *= k;
return a; return a;
} }
inline LLColor3 operator-(const LLColor3& a) inline LLColor3 operator-(const LLColor3& a)
{ {
return LLColor3( return LLColor3(1.f - a.mV[VRED], 1.f - a.mV[VGREEN], 1.f - a.mV[VBLUE]);
1.f - a.mV[0],
1.f - a.mV[1],
1.f - a.mV[2] );
} }
// Non-member functions // Non-member functions
inline F32 distVec(const LLColor3& a, const LLColor3& b) inline F32 distVec(const LLColor3& a, const LLColor3& b)
{ {
F32 x = a.mV[0] - b.mV[0]; F32 x = a.mV[VRED] - b.mV[VRED];
F32 y = a.mV[1] - b.mV[1]; F32 y = a.mV[VGREEN] - b.mV[VGREEN];
F32 z = a.mV[2] - b.mV[2]; F32 z = a.mV[VBLUE] - b.mV[VBLUE];
return (F32) sqrt( x*x + y*y + z*z ); return sqrt(x * x + y * y + z * z);
} }
inline F32 distVec_squared(const LLColor3& a, const LLColor3& b) inline F32 distVec_squared(const LLColor3& a, const LLColor3& b)
{ {
F32 x = a.mV[0] - b.mV[0]; F32 x = a.mV[VRED] - b.mV[VRED];
F32 y = a.mV[1] - b.mV[1]; F32 y = a.mV[VGREEN] - b.mV[VGREEN];
F32 z = a.mV[2] - b.mV[2]; F32 z = a.mV[VBLUE] - b.mV[VBLUE];
return x * x + y * y + z * z; return x * x + y * y + z * z;
} }
inline LLColor3 lerp(const LLColor3& a, const LLColor3& b, F32 u) inline LLColor3 lerp(const LLColor3& a, const LLColor3& b, F32 u)
{ {
return LLColor3( return LLColor3(a.mV[VX] + (b.mV[VX] - a.mV[VX]) * u, a.mV[VY] + (b.mV[VY] - a.mV[VY]) * u, a.mV[VZ] + (b.mV[VZ] - a.mV[VZ]) * u);
a.mV[VX] + (b.mV[VX] - a.mV[VX]) * u,
a.mV[VY] + (b.mV[VY] - a.mV[VY]) * u,
a.mV[VZ] + (b.mV[VZ] - a.mV[VZ]) * u);
} }
inline const LLColor3 srgbColor3(const LLColor3 &a) { inline const LLColor3 srgbColor3(const LLColor3& a)
{
LLColor3 srgbColor; LLColor3 srgbColor;
srgbColor.mV[0] = linearTosRGB(a.mV[0]); srgbColor.mV[VRED] = linearTosRGB(a.mV[VRED]);
srgbColor.mV[1] = linearTosRGB(a.mV[1]); srgbColor.mV[VGREEN] = linearTosRGB(a.mV[VGREEN]);
srgbColor.mV[2] = linearTosRGB(a.mV[2]); srgbColor.mV[VBLUE] = linearTosRGB(a.mV[VBLUE]);
return srgbColor; return srgbColor;
} }
inline const LLColor3 linearColor3p(const F32* v) { inline const LLColor3 linearColor3p(const F32* v)
{
LLColor3 linearColor; LLColor3 linearColor;
linearColor.mV[0] = sRGBtoLinear(v[0]); linearColor.mV[VRED] = sRGBtoLinear(v[VRED]);
linearColor.mV[1] = sRGBtoLinear(v[1]); linearColor.mV[VGREEN] = sRGBtoLinear(v[VGREEN]);
linearColor.mV[2] = sRGBtoLinear(v[2]); linearColor.mV[VBLUE] = sRGBtoLinear(v[VBLUE]);
return linearColor; return linearColor;
} }
template<class T> template<class T>
inline const LLColor3 linearColor3(const T& a) { inline const LLColor3 linearColor3(const T& a)
{
return linearColor3p(a.mV); return linearColor3p(a.mV);
} }
template<class T> template<class T>
inline const LLVector3 linearColor3v(const T& a) { inline const LLVector3 linearColor3v(const T& a)
{
return LLVector3(linearColor3p(a.mV).mV); return LLVector3(linearColor3p(a.mV).mV);
} }

View File

@ -30,59 +30,46 @@
#include "v3color.h" #include "v3color.h"
#include "v4color.h" #include "v4color.h"
inline LLColor3 componentDiv(LLColor3 const &left, LLColor3 const & right) inline LLColor3 componentDiv(const LLColor3& left, const LLColor3& right)
{ {
return LLColor3(left.mV[0] / right.mV[0], return LLColor3(left.mV[VRED] / right.mV[VRED], left.mV[VGREEN] / right.mV[VGREEN], left.mV[VBLUE] / right.mV[VBLUE]);
left.mV[1] / right.mV[1],
left.mV[2] / right.mV[2]);
} }
inline LLColor3 componentMult(const LLColor3& left, const LLColor3& right)
inline LLColor3 componentMult(LLColor3 const &left, LLColor3 const & right)
{ {
return LLColor3(left.mV[0] * right.mV[0], return LLColor3(left.mV[VRED] * right.mV[VRED], left.mV[VGREEN] * right.mV[VGREEN], left.mV[VBLUE] * right.mV[VBLUE]);
left.mV[1] * right.mV[1],
left.mV[2] * right.mV[2]);
} }
inline LLColor3 componentExp(const LLColor3& v)
inline LLColor3 componentExp(LLColor3 const &v)
{ {
return LLColor3(exp(v.mV[0]), return LLColor3(exp(v.mV[VRED]), exp(v.mV[VGREEN]), exp(v.mV[VBLUE]));
exp(v.mV[1]),
exp(v.mV[2]));
} }
inline LLColor3 componentPow(LLColor3 const &v, F32 exponent) inline LLColor3 componentPow(const LLColor3& v, F32 exponent)
{ {
return LLColor3(pow(v.mV[0], exponent), return LLColor3(pow(v.mV[VRED], exponent), pow(v.mV[VGREEN], exponent), pow(v.mV[VBLUE], exponent));
pow(v.mV[1], exponent),
pow(v.mV[2], exponent));
} }
inline LLColor3 componentSaturate(LLColor3 const &v) inline LLColor3 componentSaturate(const LLColor3& v)
{ {
return LLColor3(std::max(std::min(v.mV[0], 1.f), 0.f), return LLColor3(std::max(std::min(v.mV[VRED], 1.f), 0.f),
std::max(std::min(v.mV[1], 1.f), 0.f), std::max(std::min(v.mV[VGREEN], 1.f), 0.f),
std::max(std::min(v.mV[2], 1.f), 0.f)); std::max(std::min(v.mV[VBLUE], 1.f), 0.f));
} }
inline LLColor3 componentSqrt(const LLColor3& v)
inline LLColor3 componentSqrt(LLColor3 const &v)
{ {
return LLColor3(sqrt(v.mV[0]), return LLColor3(sqrt(v.mV[VRED]), sqrt(v.mV[VGREEN]), sqrt(v.mV[VBLUE]));
sqrt(v.mV[1]),
sqrt(v.mV[2]));
} }
inline void componentMultBy(LLColor3 & left, LLColor3 const & right) inline void componentMultBy(LLColor3& left, const LLColor3& right)
{ {
left.mV[0] *= right.mV[0]; left.mV[VRED] *= right.mV[VRED];
left.mV[1] *= right.mV[1]; left.mV[VGREEN] *= right.mV[VGREEN];
left.mV[2] *= right.mV[2]; left.mV[VBLUE] *= right.mV[VBLUE];
} }
inline LLColor3 colorMix(LLColor3 const & left, LLColor3 const & right, F32 amount) inline LLColor3 colorMix(const LLColor3& left, const LLColor3& right, F32 amount)
{ {
return (left + ((right - left) * amount)); return (left + ((right - left) * amount));
} }
@ -94,23 +81,22 @@ inline LLColor3 smear(F32 val)
inline F32 color_intens(const LLColor3& col) inline F32 color_intens(const LLColor3& col)
{ {
return col.mV[0] + col.mV[1] + col.mV[2]; return col.mV[VRED] + col.mV[VGREEN] + col.mV[VBLUE];
} }
inline F32 color_max(const LLColor3& col) inline F32 color_max(const LLColor3& col)
{ {
return llmax(col.mV[0], col.mV[1], col.mV[2]); return llmax(col.mV[VRED], col.mV[VGREEN], col.mV[VBLUE]);
} }
inline F32 color_max(const LLColor4& col) inline F32 color_max(const LLColor4& col)
{ {
return llmax(col.mV[0], col.mV[1], col.mV[2]); return llmax(col.mV[VRED], col.mV[VGREEN], col.mV[VBLUE]);
} }
inline F32 color_min(const LLColor3& col) inline F32 color_min(const LLColor3& col)
{ {
return llmin(col.mV[0], col.mV[1], col.mV[2]); return llmin(col.mV[VRED], col.mV[VGREEN], col.mV[VBLUE]);
} }
#endif #endif

View File

@ -30,7 +30,6 @@
#include "v3dmath.h" #include "v3dmath.h"
//#include "vmath.h"
#include "v4math.h" #include "v4math.h"
#include "m4math.h" #include "m4math.h"
#include "m3math.h" #include "m3math.h"
@ -57,13 +56,13 @@ bool LLVector3d::clamp(F64 min, F64 max)
{ {
bool ret{ false }; bool ret{ false };
if (mdV[0] < min) { mdV[0] = min; ret = true; } if (mdV[VX] < min) { mdV[VX] = min; ret = true; }
if (mdV[1] < min) { mdV[1] = min; ret = true; } if (mdV[VY] < min) { mdV[VY] = min; ret = true; }
if (mdV[2] < min) { mdV[2] = min; ret = true; } if (mdV[VZ] < min) { mdV[VZ] = min; ret = true; }
if (mdV[0] > max) { mdV[0] = max; ret = true; } if (mdV[VX] > max) { mdV[VX] = max; ret = true; }
if (mdV[1] > max) { mdV[1] = max; ret = true; } if (mdV[VY] > max) { mdV[VY] = max; ret = true; }
if (mdV[2] > max) { mdV[2] = max; ret = true; } if (mdV[VZ] > max) { mdV[VZ] = max; ret = true; }
return ret; return ret;
} }
@ -74,9 +73,9 @@ bool LLVector3d::abs()
{ {
bool ret{ false }; bool ret{ false };
if (mdV[0] < 0.0) { mdV[0] = -mdV[0]; ret = true; } if (mdV[VX] < 0.0) { mdV[VX] = -mdV[VX]; ret = true; }
if (mdV[1] < 0.0) { mdV[1] = -mdV[1]; ret = true; } if (mdV[VY] < 0.0) { mdV[VY] = -mdV[VY]; ret = true; }
if (mdV[2] < 0.0) { mdV[2] = -mdV[2]; ret = true; } if (mdV[VZ] < 0.0) { mdV[VZ] = -mdV[VZ]; ret = true; }
return ret; return ret;
} }
@ -89,9 +88,9 @@ std::ostream& operator<<(std::ostream& s, const LLVector3d &a)
const LLVector3d& LLVector3d::operator=(const LLVector4 &a) const LLVector3d& LLVector3d::operator=(const LLVector4 &a)
{ {
mdV[0] = a.mV[0]; mdV[VX] = a.mV[VX];
mdV[1] = a.mV[1]; mdV[VY] = a.mV[VY];
mdV[2] = a.mV[2]; mdV[VZ] = a.mV[VZ];
return *this; return *this;
} }
@ -135,7 +134,7 @@ bool LLVector3d::parseVector3d(const std::string& buf, LLVector3d* value)
} }
LLVector3d v; LLVector3d v;
S32 count = sscanf( buf.c_str(), "%lf %lf %lf", v.mdV + 0, v.mdV + 1, v.mdV + 2 ); S32 count = sscanf(buf.c_str(), "%lf %lf %lf", v.mdV + VX, v.mdV + VY, v.mdV + VZ);
if (3 == count) if (3 == count)
{ {
value->setVec(v); value->setVec(v);

View File

@ -54,17 +54,17 @@ class LLVector3d
void setValue(const LLSD& sd) void setValue(const LLSD& sd)
{ {
mdV[0] = sd[0].asReal(); mdV[VX] = sd[0].asReal();
mdV[1] = sd[1].asReal(); mdV[VY] = sd[1].asReal();
mdV[2] = sd[2].asReal(); mdV[VZ] = sd[2].asReal();
} }
LLSD getValue() const LLSD getValue() const
{ {
LLSD ret; LLSD ret;
ret[0] = mdV[0]; ret[0] = mdV[VX];
ret[1] = mdV[1]; ret[1] = mdV[VY];
ret[2] = mdV[2]; ret[2] = mdV[VZ];
return ret; return ret;
} }
@ -127,33 +127,32 @@ class LLVector3d
friend std::ostream& operator<<(std::ostream& s, const LLVector3d& a); // Stream a friend std::ostream& operator<<(std::ostream& s, const LLVector3d& a); // Stream a
static bool parseVector3d(const std::string& buf, LLVector3d* value); static bool parseVector3d(const std::string& buf, LLVector3d* value);
}; };
typedef LLVector3d LLGlobalVec; typedef LLVector3d LLGlobalVec;
inline const LLVector3d &LLVector3d::set(const LLVector3 &vec) inline const LLVector3d &LLVector3d::set(const LLVector3 &vec)
{ {
mdV[0] = vec.mV[0]; mdV[VX] = vec.mV[VX];
mdV[1] = vec.mV[1]; mdV[VY] = vec.mV[VY];
mdV[2] = vec.mV[2]; mdV[VZ] = vec.mV[VZ];
return *this; return *this;
} }
inline const LLVector3d &LLVector3d::setVec(const LLVector3 &vec) inline const LLVector3d &LLVector3d::setVec(const LLVector3 &vec)
{ {
mdV[0] = vec.mV[0]; mdV[VX] = vec.mV[VX];
mdV[1] = vec.mV[1]; mdV[VY] = vec.mV[VY];
mdV[2] = vec.mV[2]; mdV[VZ] = vec.mV[VZ];
return *this; return *this;
} }
inline LLVector3d::LLVector3d(void) inline LLVector3d::LLVector3d(void)
{ {
mdV[0] = 0.f; mdV[VX] = 0.f;
mdV[1] = 0.f; mdV[VY] = 0.f;
mdV[2] = 0.f; mdV[VZ] = 0.f;
} }
inline LLVector3d::LLVector3d(const F64 x, const F64 y, const F64 z) inline LLVector3d::LLVector3d(const F64 x, const F64 y, const F64 z)
@ -199,33 +198,33 @@ inline bool LLVector3d::isFinite() const
inline const LLVector3d& LLVector3d::clear(void) inline const LLVector3d& LLVector3d::clear(void)
{ {
mdV[0] = 0.f; mdV[VX] = 0.f;
mdV[1] = 0.f; mdV[VY] = 0.f;
mdV[2]= 0.f; mdV[VZ] = 0.f;
return (*this); return (*this);
} }
inline const LLVector3d& LLVector3d::clearVec(void) inline const LLVector3d& LLVector3d::clearVec(void)
{ {
mdV[0] = 0.f; mdV[VX] = 0.f;
mdV[1] = 0.f; mdV[VY] = 0.f;
mdV[2]= 0.f; mdV[VZ] = 0.f;
return (*this); return (*this);
} }
inline const LLVector3d& LLVector3d::setZero(void) inline const LLVector3d& LLVector3d::setZero(void)
{ {
mdV[0] = 0.f; mdV[VX] = 0.f;
mdV[1] = 0.f; mdV[VY] = 0.f;
mdV[2] = 0.f; mdV[VZ] = 0.f;
return (*this); return (*this);
} }
inline const LLVector3d& LLVector3d::zeroVec(void) inline const LLVector3d& LLVector3d::zeroVec(void)
{ {
mdV[0] = 0.f; mdV[VX] = 0.f;
mdV[1] = 0.f; mdV[VY] = 0.f;
mdV[2] = 0.f; mdV[VZ] = 0.f;
return (*this); return (*this);
} }
@ -239,17 +238,17 @@ inline const LLVector3d& LLVector3d::set(const F64 x, const F64 y, const F64
inline const LLVector3d& LLVector3d::set(const LLVector3d &vec) inline const LLVector3d& LLVector3d::set(const LLVector3d &vec)
{ {
mdV[0] = vec.mdV[0]; mdV[VX] = vec.mdV[VX];
mdV[1] = vec.mdV[1]; mdV[VY] = vec.mdV[VY];
mdV[2] = vec.mdV[2]; mdV[VZ] = vec.mdV[VZ];
return (*this); return (*this);
} }
inline const LLVector3d& LLVector3d::set(const F64 *vec) inline const LLVector3d& LLVector3d::set(const F64 *vec)
{ {
mdV[0] = vec[0]; mdV[VX] = vec[0];
mdV[1] = vec[1]; mdV[VY] = vec[1];
mdV[2] = vec[2]; mdV[VZ] = vec[2];
return (*this); return (*this);
} }
@ -263,59 +262,59 @@ inline const LLVector3d& LLVector3d::setVec(const F64 x, const F64 y, const F
inline const LLVector3d& LLVector3d::setVec(const LLVector3d& vec) inline const LLVector3d& LLVector3d::setVec(const LLVector3d& vec)
{ {
mdV[0] = vec.mdV[0]; mdV[VX] = vec.mdV[VX];
mdV[1] = vec.mdV[1]; mdV[VY] = vec.mdV[VY];
mdV[2] = vec.mdV[2]; mdV[VZ] = vec.mdV[VZ];
return (*this); return (*this);
} }
inline const LLVector3d& LLVector3d::setVec(const F64* vec) inline const LLVector3d& LLVector3d::setVec(const F64* vec)
{ {
mdV[0] = vec[0]; mdV[VX] = vec[VX];
mdV[1] = vec[1]; mdV[VY] = vec[VY];
mdV[2] = vec[2]; mdV[VZ] = vec[VZ];
return (*this); return (*this);
} }
inline F64 LLVector3d::normVec(void) inline F64 LLVector3d::normVec()
{ {
F64 mag = (F32) sqrt(mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]); F64 mag = sqrt(mdV[VX]*mdV[VX] + mdV[VY]*mdV[VY] + mdV[VZ]*mdV[VZ]);
F64 oomag; F64 oomag;
if (mag > FP_MAG_THRESHOLD) if (mag > FP_MAG_THRESHOLD)
{ {
oomag = 1.f/mag; oomag = 1.f/mag;
mdV[0] *= oomag; mdV[VX] *= oomag;
mdV[1] *= oomag; mdV[VY] *= oomag;
mdV[2] *= oomag; mdV[VZ] *= oomag;
} }
else else
{ {
mdV[0] = 0.f; mdV[VX] = 0.f;
mdV[1] = 0.f; mdV[VY] = 0.f;
mdV[2] = 0.f; mdV[VZ] = 0.f;
mag = 0; mag = 0;
} }
return (mag); return (mag);
} }
inline F64 LLVector3d::normalize(void) inline F64 LLVector3d::normalize()
{ {
F64 mag = (F32) sqrt(mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]); F64 mag = sqrt(mdV[VX]*mdV[VX] + mdV[VY]*mdV[VY] + mdV[VZ]*mdV[VZ]);
F64 oomag; F64 oomag;
if (mag > FP_MAG_THRESHOLD) if (mag > FP_MAG_THRESHOLD)
{ {
oomag = 1.f/mag; oomag = 1.f/mag;
mdV[0] *= oomag; mdV[VX] *= oomag;
mdV[1] *= oomag; mdV[VY] *= oomag;
mdV[2] *= oomag; mdV[VZ] *= oomag;
} }
else else
{ {
mdV[0] = 0.f; mdV[VX] = 0.f;
mdV[1] = 0.f; mdV[VY] = 0.f;
mdV[2] = 0.f; mdV[VZ] = 0.f;
mag = 0; mag = 0;
} }
return (mag); return (mag);
@ -323,24 +322,24 @@ inline F64 LLVector3d::normalize(void)
// LLVector3d Magnitude and Normalization Functions // LLVector3d Magnitude and Normalization Functions
inline F64 LLVector3d::magVec(void) const inline F64 LLVector3d::magVec() const
{ {
return (F32) sqrt(mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]); return sqrt(mdV[VX]*mdV[VX] + mdV[VY]*mdV[VY] + mdV[VZ]*mdV[VZ]);
} }
inline F64 LLVector3d::magVecSquared(void) const inline F64 LLVector3d::magVecSquared() const
{ {
return mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]; return mdV[VX]*mdV[VX] + mdV[VY]*mdV[VY] + mdV[VZ]*mdV[VZ];
} }
inline F64 LLVector3d::length(void) const inline F64 LLVector3d::length() const
{ {
return (F32) sqrt(mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]); return sqrt(mdV[VX]*mdV[VX] + mdV[VY]*mdV[VY] + mdV[VZ]*mdV[VZ]);
} }
inline F64 LLVector3d::lengthSquared(void) const inline F64 LLVector3d::lengthSquared() const
{ {
return mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]; return mdV[VX]*mdV[VX] + mdV[VY]*mdV[VY] + mdV[VZ]*mdV[VZ];
} }
inline LLVector3d operator+(const LLVector3d& a, const LLVector3d& b) inline LLVector3d operator+(const LLVector3d& a, const LLVector3d& b)
@ -357,109 +356,109 @@ inline LLVector3d operator-(const LLVector3d& a, const LLVector3d& b)
inline F64 operator*(const LLVector3d& a, const LLVector3d& b) inline F64 operator*(const LLVector3d& a, const LLVector3d& b)
{ {
return (a.mdV[0]*b.mdV[0] + a.mdV[1]*b.mdV[1] + a.mdV[2]*b.mdV[2]); return (a.mdV[VX]*b.mdV[VX] + a.mdV[VY]*b.mdV[VY] + a.mdV[VZ]*b.mdV[VZ]);
} }
inline LLVector3d operator%(const LLVector3d& a, const LLVector3d& b) inline LLVector3d operator%(const LLVector3d& a, const LLVector3d& b)
{ {
return LLVector3d( a.mdV[1]*b.mdV[2] - b.mdV[1]*a.mdV[2], a.mdV[2]*b.mdV[0] - b.mdV[2]*a.mdV[0], a.mdV[0]*b.mdV[1] - b.mdV[0]*a.mdV[1] ); return LLVector3d( a.mdV[VY]*b.mdV[VZ] - b.mdV[VY]*a.mdV[VZ], a.mdV[VZ]*b.mdV[VX] - b.mdV[VZ]*a.mdV[VX], a.mdV[VX]*b.mdV[VY] - b.mdV[VX]*a.mdV[VY] );
} }
inline LLVector3d operator/(const LLVector3d& a, const F64 k) inline LLVector3d operator/(const LLVector3d& a, const F64 k)
{ {
F64 t = 1.f / k; F64 t = 1.f / k;
return LLVector3d( a.mdV[0] * t, a.mdV[1] * t, a.mdV[2] * t ); return LLVector3d( a.mdV[VX] * t, a.mdV[VY] * t, a.mdV[VZ] * t );
} }
inline LLVector3d operator*(const LLVector3d& a, const F64 k) inline LLVector3d operator*(const LLVector3d& a, const F64 k)
{ {
return LLVector3d( a.mdV[0] * k, a.mdV[1] * k, a.mdV[2] * k ); return LLVector3d( a.mdV[VX] * k, a.mdV[VY] * k, a.mdV[VZ] * k );
} }
inline LLVector3d operator*(F64 k, const LLVector3d& a) inline LLVector3d operator*(F64 k, const LLVector3d& a)
{ {
return LLVector3d( a.mdV[0] * k, a.mdV[1] * k, a.mdV[2] * k ); return LLVector3d( a.mdV[VX] * k, a.mdV[VY] * k, a.mdV[VZ] * k );
} }
inline bool operator==(const LLVector3d& a, const LLVector3d& b) inline bool operator==(const LLVector3d& a, const LLVector3d& b)
{ {
return ( (a.mdV[0] == b.mdV[0]) return ( (a.mdV[VX] == b.mdV[VX])
&&(a.mdV[1] == b.mdV[1]) &&(a.mdV[VY] == b.mdV[VY])
&&(a.mdV[2] == b.mdV[2])); &&(a.mdV[VZ] == b.mdV[VZ]));
} }
inline bool operator!=(const LLVector3d& a, const LLVector3d& b) inline bool operator!=(const LLVector3d& a, const LLVector3d& b)
{ {
return ( (a.mdV[0] != b.mdV[0]) return ( (a.mdV[VX] != b.mdV[VX])
||(a.mdV[1] != b.mdV[1]) ||(a.mdV[VY] != b.mdV[VY])
||(a.mdV[2] != b.mdV[2])); ||(a.mdV[VZ] != b.mdV[VZ]));
} }
inline const LLVector3d& operator+=(LLVector3d& a, const LLVector3d& b) inline const LLVector3d& operator+=(LLVector3d& a, const LLVector3d& b)
{ {
a.mdV[0] += b.mdV[0]; a.mdV[VX] += b.mdV[VX];
a.mdV[1] += b.mdV[1]; a.mdV[VY] += b.mdV[VY];
a.mdV[2] += b.mdV[2]; a.mdV[VZ] += b.mdV[VZ];
return a; return a;
} }
inline const LLVector3d& operator-=(LLVector3d& a, const LLVector3d& b) inline const LLVector3d& operator-=(LLVector3d& a, const LLVector3d& b)
{ {
a.mdV[0] -= b.mdV[0]; a.mdV[VX] -= b.mdV[VX];
a.mdV[1] -= b.mdV[1]; a.mdV[VY] -= b.mdV[VY];
a.mdV[2] -= b.mdV[2]; a.mdV[VZ] -= b.mdV[VZ];
return a; return a;
} }
inline const LLVector3d& operator%=(LLVector3d& a, const LLVector3d& b) inline const LLVector3d& operator%=(LLVector3d& a, const LLVector3d& b)
{ {
LLVector3d ret( a.mdV[1]*b.mdV[2] - b.mdV[1]*a.mdV[2], a.mdV[2]*b.mdV[0] - b.mdV[2]*a.mdV[0], a.mdV[0]*b.mdV[1] - b.mdV[0]*a.mdV[1]); LLVector3d ret( a.mdV[VY]*b.mdV[VZ] - b.mdV[VY]*a.mdV[VZ], a.mdV[VZ]*b.mdV[VX] - b.mdV[VZ]*a.mdV[VX], a.mdV[VX]*b.mdV[VY] - b.mdV[VX]*a.mdV[VY]);
a = ret; a = ret;
return a; return a;
} }
inline const LLVector3d& operator*=(LLVector3d& a, const F64 k) inline const LLVector3d& operator*=(LLVector3d& a, const F64 k)
{ {
a.mdV[0] *= k; a.mdV[VX] *= k;
a.mdV[1] *= k; a.mdV[VY] *= k;
a.mdV[2] *= k; a.mdV[VZ] *= k;
return a; return a;
} }
inline const LLVector3d& operator/=(LLVector3d& a, const F64 k) inline const LLVector3d& operator/=(LLVector3d& a, const F64 k)
{ {
F64 t = 1.f / k; F64 t = 1.f / k;
a.mdV[0] *= t; a.mdV[VX] *= t;
a.mdV[1] *= t; a.mdV[VY] *= t;
a.mdV[2] *= t; a.mdV[VZ] *= t;
return a; return a;
} }
inline LLVector3d operator-(const LLVector3d& a) inline LLVector3d operator-(const LLVector3d& a)
{ {
return LLVector3d( -a.mdV[0], -a.mdV[1], -a.mdV[2] ); return LLVector3d( -a.mdV[VX], -a.mdV[VY], -a.mdV[VZ] );
} }
inline F64 dist_vec(const LLVector3d& a, const LLVector3d& b) inline F64 dist_vec(const LLVector3d& a, const LLVector3d& b)
{ {
F64 x = a.mdV[0] - b.mdV[0]; F64 x = a.mdV[VX] - b.mdV[VX];
F64 y = a.mdV[1] - b.mdV[1]; F64 y = a.mdV[VY] - b.mdV[VY];
F64 z = a.mdV[2] - b.mdV[2]; F64 z = a.mdV[VZ] - b.mdV[VZ];
return (F32) sqrt( x*x + y*y + z*z ); return (F32) sqrt( x*x + y*y + z*z );
} }
inline F64 dist_vec_squared(const LLVector3d& a, const LLVector3d& b) inline F64 dist_vec_squared(const LLVector3d& a, const LLVector3d& b)
{ {
F64 x = a.mdV[0] - b.mdV[0]; F64 x = a.mdV[VX] - b.mdV[VX];
F64 y = a.mdV[1] - b.mdV[1]; F64 y = a.mdV[VY] - b.mdV[VY];
F64 z = a.mdV[2] - b.mdV[2]; F64 z = a.mdV[VZ] - b.mdV[VZ];
return x*x + y*y + z*z; return x*x + y*y + z*z;
} }
inline F64 dist_vec_squared2D(const LLVector3d& a, const LLVector3d& b) inline F64 dist_vec_squared2D(const LLVector3d& a, const LLVector3d& b)
{ {
F64 x = a.mdV[0] - b.mdV[0]; F64 x = a.mdV[VX] - b.mdV[VX];
F64 y = a.mdV[1] - b.mdV[1]; F64 y = a.mdV[VY] - b.mdV[VY];
return x*x + y*y; return x*x + y*y;
} }

View File

@ -28,7 +28,6 @@
#include "v3math.h" #include "v3math.h"
//#include "vmath.h"
#include "v2math.h" #include "v2math.h"
#include "v4math.h" #include "v4math.h"
#include "m4math.h" #include "m4math.h"
@ -58,13 +57,13 @@ bool LLVector3::clamp(F32 min, F32 max)
{ {
bool ret{ false }; bool ret{ false };
if (mV[0] < min) { mV[0] = min; ret = true; } if (mV[VX] < min) { mV[VX] = min; ret = true; }
if (mV[1] < min) { mV[1] = min; ret = true; } if (mV[VY] < min) { mV[VY] = min; ret = true; }
if (mV[2] < min) { mV[2] = min; ret = true; } if (mV[VZ] < min) { mV[VZ] = min; ret = true; }
if (mV[0] > max) { mV[0] = max; ret = true; } if (mV[VX] > max) { mV[VX] = max; ret = true; }
if (mV[1] > max) { mV[1] = max; ret = true; } if (mV[VY] > max) { mV[VY] = max; ret = true; }
if (mV[2] > max) { mV[2] = max; ret = true; } if (mV[VZ] > max) { mV[VZ] = max; ret = true; }
return ret; return ret;
} }
@ -85,9 +84,9 @@ bool LLVector3::clampLength( F32 length_limit )
{ {
length_limit = 0.f; length_limit = 0.f;
} }
mV[0] *= length_limit; mV[VX] *= length_limit;
mV[1] *= length_limit; mV[VY] *= length_limit;
mV[2] *= length_limit; mV[VZ] *= length_limit;
changed = true; changed = true;
} }
} }
@ -116,18 +115,18 @@ bool LLVector3::clampLength( F32 length_limit )
{ {
// yes it can be salvaged --> // yes it can be salvaged -->
// bring the components down before we normalize // bring the components down before we normalize
mV[0] /= max_abs_component; mV[VX] /= max_abs_component;
mV[1] /= max_abs_component; mV[VY] /= max_abs_component;
mV[2] /= max_abs_component; mV[VZ] /= max_abs_component;
normalize(); normalize();
if (length_limit < 0.f) if (length_limit < 0.f)
{ {
length_limit = 0.f; length_limit = 0.f;
} }
mV[0] *= length_limit; mV[VX] *= length_limit;
mV[1] *= length_limit; mV[VY] *= length_limit;
mV[2] *= length_limit; mV[VZ] *= length_limit;
} }
} }
@ -138,13 +137,13 @@ bool LLVector3::clamp(const LLVector3 &min_vec, const LLVector3 &max_vec)
{ {
bool ret{ false }; bool ret{ false };
if (mV[0] < min_vec[0]) { mV[0] = min_vec[0]; ret = true; } if (mV[VX] < min_vec[0]) { mV[VX] = min_vec[0]; ret = true; }
if (mV[1] < min_vec[1]) { mV[1] = min_vec[1]; ret = true; } if (mV[VY] < min_vec[1]) { mV[VY] = min_vec[1]; ret = true; }
if (mV[2] < min_vec[2]) { mV[2] = min_vec[2]; ret = true; } if (mV[VZ] < min_vec[2]) { mV[VZ] = min_vec[2]; ret = true; }
if (mV[0] > max_vec[0]) { mV[0] = max_vec[0]; ret = true; } if (mV[VX] > max_vec[0]) { mV[VX] = max_vec[0]; ret = true; }
if (mV[1] > max_vec[1]) { mV[1] = max_vec[1]; ret = true; } if (mV[VY] > max_vec[1]) { mV[VY] = max_vec[1]; ret = true; }
if (mV[2] > max_vec[2]) { mV[2] = max_vec[2]; ret = true; } if (mV[VZ] > max_vec[2]) { mV[VZ] = max_vec[2]; ret = true; }
return ret; return ret;
} }
@ -156,9 +155,9 @@ bool LLVector3::abs()
{ {
bool ret{ false }; bool ret{ false };
if (mV[0] < 0.f) { mV[0] = -mV[0]; ret = true; } if (mV[VX] < 0.f) { mV[VX] = -mV[VX]; ret = true; }
if (mV[1] < 0.f) { mV[1] = -mV[1]; ret = true; } if (mV[VY] < 0.f) { mV[VY] = -mV[VY]; ret = true; }
if (mV[2] < 0.f) { mV[2] = -mV[2]; ret = true; } if (mV[VZ] < 0.f) { mV[VZ] = -mV[VZ]; ret = true; }
return ret; return ret;
} }
@ -265,33 +264,33 @@ LLVector3 LLVector3::scaledVec(const LLVector3& vec) const
const LLVector3& LLVector3::set(const LLVector3d& vec) const LLVector3& LLVector3::set(const LLVector3d& vec)
{ {
mV[0] = (F32)vec.mdV[0]; mV[VX] = (F32)vec.mdV[VX];
mV[1] = (F32)vec.mdV[1]; mV[VY] = (F32)vec.mdV[VY];
mV[2] = (F32)vec.mdV[2]; mV[VZ] = (F32)vec.mdV[VZ];
return (*this); return (*this);
} }
const LLVector3& LLVector3::set(const LLVector4& vec) const LLVector3& LLVector3::set(const LLVector4& vec)
{ {
mV[0] = vec.mV[0]; mV[VX] = vec.mV[VX];
mV[1] = vec.mV[1]; mV[VY] = vec.mV[VY];
mV[2] = vec.mV[2]; mV[VZ] = vec.mV[VZ];
return (*this); return (*this);
} }
const LLVector3& LLVector3::setVec(const LLVector3d& vec) const LLVector3& LLVector3::setVec(const LLVector3d& vec)
{ {
mV[0] = (F32)vec.mdV[0]; mV[VX] = (F32)vec.mdV[0];
mV[1] = (F32)vec.mdV[1]; mV[VY] = (F32)vec.mdV[1];
mV[2] = (F32)vec.mdV[2]; mV[VZ] = (F32)vec.mdV[2];
return (*this); return (*this);
} }
const LLVector3& LLVector3::setVec(const LLVector4& vec) const LLVector3& LLVector3::setVec(const LLVector4& vec)
{ {
mV[0] = vec.mV[0]; mV[VX] = vec.mV[VX];
mV[1] = vec.mV[1]; mV[VY] = vec.mV[VY];
mV[2] = vec.mV[2]; mV[VZ] = vec.mV[VZ];
return (*this); return (*this);
} }
@ -299,7 +298,7 @@ LLVector3::LLVector3(const LLVector2 &vec)
{ {
mV[VX] = (F32)vec.mV[VX]; mV[VX] = (F32)vec.mV[VX];
mV[VY] = (F32)vec.mV[VY]; mV[VY] = (F32)vec.mV[VY];
mV[VZ] = 0; mV[VZ] = 0.f;
} }
LLVector3::LLVector3(const LLVector3d& vec) LLVector3::LLVector3(const LLVector3d& vec)
@ -319,7 +318,6 @@ LLVector3::LLVector3(const LLVector4 &vec)
LLVector3::LLVector3(const LLVector4a& vec) LLVector3::LLVector3(const LLVector4a& vec)
: LLVector3(vec.getF32ptr()) : LLVector3(vec.getF32ptr())
{ {
} }
LLVector3::LLVector3(const LLSD& sd) LLVector3::LLVector3(const LLSD& sd)
@ -330,17 +328,17 @@ LLVector3::LLVector3(const LLSD& sd)
LLSD LLVector3::getValue() const LLSD LLVector3::getValue() const
{ {
LLSD ret; LLSD ret;
ret[0] = mV[0]; ret[VX] = mV[VX];
ret[1] = mV[1]; ret[VY] = mV[VY];
ret[2] = mV[2]; ret[VZ] = mV[VZ];
return ret; return ret;
} }
void LLVector3::setValue(const LLSD& sd) void LLVector3::setValue(const LLSD& sd)
{ {
mV[0] = (F32) sd[0].asReal(); mV[VX] = (F32) sd[VX].asReal();
mV[1] = (F32) sd[1].asReal(); mV[VY] = (F32) sd[VY].asReal();
mV[2] = (F32) sd[2].asReal(); mV[VZ] = (F32) sd[VZ].asReal();
} }
const LLVector3& operator*=(LLVector3& a, const LLQuaternion& rot) const LLVector3& operator*=(LLVector3& a, const LLQuaternion& rot)
@ -366,7 +364,7 @@ bool LLVector3::parseVector3(const std::string& buf, LLVector3* value)
} }
LLVector3 v; LLVector3 v;
S32 count = sscanf( buf.c_str(), "%f %f %f", v.mV + 0, v.mV + 1, v.mV + 2 ); S32 count = sscanf(buf.c_str(), "%f %f %f", v.mV + VX, v.mV + VY, v.mV + VZ);
if (3 == count) if (3 == count)
{ {
value->setVec(v); value->setVec(v);
@ -410,4 +408,3 @@ bool box_valid_and_non_zero(const LLVector3* box)
} }
return false; return false;
} }

View File

@ -46,7 +46,7 @@ class LLQuaternion;
// LLvector3 = |x y z w| // LLvector3 = |x y z w|
static const U32 LENGTHOFVECTOR3 = 3; static constexpr U32 LENGTHOFVECTOR3 = 3;
class LLVector3 class LLVector3
{ {
@ -181,11 +181,11 @@ LLVector3 lerp(const LLVector3 &a, const LLVector3 &b, F32 u); // Returns a vect
LLVector3 point_to_box_offset(LLVector3& pos, const LLVector3* box); // Displacement from query point to nearest point on bounding box. LLVector3 point_to_box_offset(LLVector3& pos, const LLVector3* box); // Displacement from query point to nearest point on bounding box.
bool box_valid_and_non_zero(const LLVector3* box); bool box_valid_and_non_zero(const LLVector3* box);
inline LLVector3::LLVector3(void) inline LLVector3::LLVector3()
{ {
mV[0] = 0.f; mV[VX] = 0.f;
mV[1] = 0.f; mV[VY] = 0.f;
mV[2] = 0.f; mV[VZ] = 0.f;
} }
inline LLVector3::LLVector3(const F32 x, const F32 y, const F32 z) inline LLVector3::LLVector3(const F32 x, const F32 y, const F32 z)
@ -236,32 +236,32 @@ inline bool LLVector3::isFinite() const
// Clear and Assignment Functions // Clear and Assignment Functions
inline void LLVector3::clear(void) inline void LLVector3::clear()
{ {
mV[0] = 0.f; mV[VX] = 0.f;
mV[1] = 0.f; mV[VY] = 0.f;
mV[2] = 0.f; mV[VZ] = 0.f;
} }
inline void LLVector3::setZero(void) inline void LLVector3::setZero()
{ {
mV[0] = 0.f; mV[VX] = 0.f;
mV[1] = 0.f; mV[VY] = 0.f;
mV[2] = 0.f; mV[VZ] = 0.f;
} }
inline void LLVector3::clearVec(void) inline void LLVector3::clearVec()
{ {
mV[0] = 0.f; mV[VX] = 0.f;
mV[1] = 0.f; mV[VY] = 0.f;
mV[2] = 0.f; mV[VZ] = 0.f;
} }
inline void LLVector3::zeroVec(void) inline void LLVector3::zeroVec()
{ {
mV[0] = 0.f; mV[VX] = 0.f;
mV[1] = 0.f; mV[VY] = 0.f;
mV[2] = 0.f; mV[VZ] = 0.f;
} }
inline void LLVector3::set(F32 x, F32 y, F32 z) inline void LLVector3::set(F32 x, F32 y, F32 z)
@ -273,16 +273,16 @@ inline void LLVector3::set(F32 x, F32 y, F32 z)
inline void LLVector3::set(const LLVector3& vec) inline void LLVector3::set(const LLVector3& vec)
{ {
mV[0] = vec.mV[0]; mV[VX] = vec.mV[VX];
mV[1] = vec.mV[1]; mV[VY] = vec.mV[VY];
mV[2] = vec.mV[2]; mV[VZ] = vec.mV[VZ];
} }
inline void LLVector3::set(const F32* vec) inline void LLVector3::set(const F32* vec)
{ {
mV[0] = vec[0]; mV[VX] = vec[VX];
mV[1] = vec[1]; mV[VY] = vec[VY];
mV[2] = vec[2]; mV[VZ] = vec[VZ];
} }
inline void LLVector3::set(const glm::vec4& vec) inline void LLVector3::set(const glm::vec4& vec)
@ -310,59 +310,59 @@ inline void LLVector3::setVec(F32 x, F32 y, F32 z)
// deprecated // deprecated
inline void LLVector3::setVec(const LLVector3& vec) inline void LLVector3::setVec(const LLVector3& vec)
{ {
mV[0] = vec.mV[0]; mV[VX] = vec.mV[VX];
mV[1] = vec.mV[1]; mV[VY] = vec.mV[VY];
mV[2] = vec.mV[2]; mV[VZ] = vec.mV[VZ];
} }
// deprecated // deprecated
inline void LLVector3::setVec(const F32* vec) inline void LLVector3::setVec(const F32* vec)
{ {
mV[0] = vec[0]; mV[VX] = vec[0];
mV[1] = vec[1]; mV[VY] = vec[1];
mV[2] = vec[2]; mV[VZ] = vec[2];
} }
inline F32 LLVector3::normalize(void) inline F32 LLVector3::normalize()
{ {
F32 mag = (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]); F32 mag = (F32) sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]);
F32 oomag; F32 oomag;
if (mag > FP_MAG_THRESHOLD) if (mag > FP_MAG_THRESHOLD)
{ {
oomag = 1.f/mag; oomag = 1.f/mag;
mV[0] *= oomag; mV[VX] *= oomag;
mV[1] *= oomag; mV[VY] *= oomag;
mV[2] *= oomag; mV[VZ] *= oomag;
} }
else else
{ {
mV[0] = 0.f; mV[VX] = 0.f;
mV[1] = 0.f; mV[VY] = 0.f;
mV[2] = 0.f; mV[VZ] = 0.f;
mag = 0; mag = 0;
} }
return (mag); return (mag);
} }
// deprecated // deprecated
inline F32 LLVector3::normVec(void) inline F32 LLVector3::normVec()
{ {
F32 mag = (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]); F32 mag = sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]);
F32 oomag; F32 oomag;
if (mag > FP_MAG_THRESHOLD) if (mag > FP_MAG_THRESHOLD)
{ {
oomag = 1.f/mag; oomag = 1.f/mag;
mV[0] *= oomag; mV[VX] *= oomag;
mV[1] *= oomag; mV[VY] *= oomag;
mV[2] *= oomag; mV[VZ] *= oomag;
} }
else else
{ {
mV[0] = 0.f; mV[VX] = 0.f;
mV[1] = 0.f; mV[VY] = 0.f;
mV[2] = 0.f; mV[VZ] = 0.f;
mag = 0; mag = 0;
} }
return (mag); return (mag);
@ -370,31 +370,31 @@ inline F32 LLVector3::normVec(void)
// LLVector3 Magnitude and Normalization Functions // LLVector3 Magnitude and Normalization Functions
inline F32 LLVector3::length(void) const inline F32 LLVector3::length() const
{ {
return (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]); return sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]);
} }
inline F32 LLVector3::lengthSquared(void) const inline F32 LLVector3::lengthSquared() const
{ {
return mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]; return mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ];
} }
inline F32 LLVector3::magVec(void) const inline F32 LLVector3::magVec() const
{ {
return (F32) sqrt(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]); return sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]);
} }
inline F32 LLVector3::magVecSquared(void) const inline F32 LLVector3::magVecSquared() const
{ {
return mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]; return mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ];
} }
inline bool LLVector3::inRange( F32 min, F32 max ) const inline bool LLVector3::inRange( F32 min, F32 max ) const
{ {
return mV[0] >= min && mV[0] <= max && return mV[VX] >= min && mV[VX] <= max &&
mV[1] >= min && mV[1] <= max && mV[VY] >= min && mV[VY] <= max &&
mV[2] >= min && mV[2] <= max; mV[VZ] >= min && mV[VZ] <= max;
} }
inline LLVector3 operator+(const LLVector3& a, const LLVector3& b) inline LLVector3 operator+(const LLVector3& a, const LLVector3& b)
@ -411,104 +411,103 @@ inline LLVector3 operator-(const LLVector3 &a, const LLVector3 &b)
inline F32 operator*(const LLVector3& a, const LLVector3& b) inline F32 operator*(const LLVector3& a, const LLVector3& b)
{ {
return (a.mV[0]*b.mV[0] + a.mV[1]*b.mV[1] + a.mV[2]*b.mV[2]); return (a.mV[VX]*b.mV[VX] + a.mV[VY]*b.mV[VY] + a.mV[VZ]*b.mV[VZ]);
} }
inline LLVector3 operator%(const LLVector3& a, const LLVector3& b) inline LLVector3 operator%(const LLVector3& a, const LLVector3& b)
{ {
return LLVector3( a.mV[1]*b.mV[2] - b.mV[1]*a.mV[2], a.mV[2]*b.mV[0] - b.mV[2]*a.mV[0], a.mV[0]*b.mV[1] - b.mV[0]*a.mV[1] ); return LLVector3( a.mV[VY]*b.mV[VZ] - b.mV[VY]*a.mV[VZ], a.mV[VZ]*b.mV[VX] - b.mV[VZ]*a.mV[VX], a.mV[VX]*b.mV[VY] - b.mV[VX]*a.mV[VY] );
} }
inline LLVector3 operator/(const LLVector3& a, F32 k) inline LLVector3 operator/(const LLVector3& a, F32 k)
{ {
F32 t = 1.f / k; F32 t = 1.f / k;
return LLVector3( a.mV[0] * t, a.mV[1] * t, a.mV[2] * t ); return LLVector3( a.mV[VX] * t, a.mV[VY] * t, a.mV[VZ] * t );
} }
inline LLVector3 operator*(const LLVector3& a, F32 k) inline LLVector3 operator*(const LLVector3& a, F32 k)
{ {
return LLVector3( a.mV[0] * k, a.mV[1] * k, a.mV[2] * k ); return LLVector3( a.mV[VX] * k, a.mV[VY] * k, a.mV[VZ] * k );
} }
inline LLVector3 operator*(F32 k, const LLVector3& a) inline LLVector3 operator*(F32 k, const LLVector3& a)
{ {
return LLVector3( a.mV[0] * k, a.mV[1] * k, a.mV[2] * k ); return LLVector3( a.mV[VX] * k, a.mV[VY] * k, a.mV[VZ] * k );
} }
inline bool operator==(const LLVector3& a, const LLVector3& b) inline bool operator==(const LLVector3& a, const LLVector3& b)
{ {
return ( (a.mV[0] == b.mV[0]) return ( (a.mV[VX] == b.mV[VX])
&&(a.mV[1] == b.mV[1]) &&(a.mV[VY] == b.mV[VY])
&&(a.mV[2] == b.mV[2])); &&(a.mV[VZ] == b.mV[VZ]));
} }
inline bool operator!=(const LLVector3& a, const LLVector3& b) inline bool operator!=(const LLVector3& a, const LLVector3& b)
{ {
return ( (a.mV[0] != b.mV[0]) return ( (a.mV[VX] != b.mV[VX])
||(a.mV[1] != b.mV[1]) ||(a.mV[VY] != b.mV[VY])
||(a.mV[2] != b.mV[2])); ||(a.mV[VZ] != b.mV[VZ]));
} }
inline bool operator<(const LLVector3& a, const LLVector3& b) inline bool operator<(const LLVector3& a, const LLVector3& b)
{ {
return (a.mV[0] < b.mV[0] return (a.mV[VX] < b.mV[VX]
|| (a.mV[0] == b.mV[0] || (a.mV[VX] == b.mV[VX]
&& (a.mV[1] < b.mV[1] && (a.mV[VY] < b.mV[VY]
|| ((a.mV[1] == b.mV[1]) || ((a.mV[VY] == b.mV[VY])
&& a.mV[2] < b.mV[2])))); && a.mV[VZ] < b.mV[VZ]))));
} }
inline const LLVector3& operator+=(LLVector3& a, const LLVector3& b) inline const LLVector3& operator+=(LLVector3& a, const LLVector3& b)
{ {
a.mV[0] += b.mV[0]; a.mV[VX] += b.mV[VX];
a.mV[1] += b.mV[1]; a.mV[VY] += b.mV[VY];
a.mV[2] += b.mV[2]; a.mV[VZ] += b.mV[VZ];
return a; return a;
} }
inline const LLVector3& operator-=(LLVector3& a, const LLVector3& b) inline const LLVector3& operator-=(LLVector3& a, const LLVector3& b)
{ {
a.mV[0] -= b.mV[0]; a.mV[VX] -= b.mV[VX];
a.mV[1] -= b.mV[1]; a.mV[VY] -= b.mV[VY];
a.mV[2] -= b.mV[2]; a.mV[VZ] -= b.mV[VZ];
return a; return a;
} }
inline const LLVector3& operator%=(LLVector3& a, const LLVector3& b) inline const LLVector3& operator%=(LLVector3& a, const LLVector3& b)
{ {
LLVector3 ret( a.mV[1]*b.mV[2] - b.mV[1]*a.mV[2], a.mV[2]*b.mV[0] - b.mV[2]*a.mV[0], a.mV[0]*b.mV[1] - b.mV[0]*a.mV[1]); LLVector3 ret( a.mV[VY]*b.mV[VZ] - b.mV[VY]*a.mV[VZ], a.mV[VZ]*b.mV[VX] - b.mV[VZ]*a.mV[VX], a.mV[VX]*b.mV[VY] - b.mV[VX]*a.mV[VY]);
a = ret; a = ret;
return a; return a;
} }
inline const LLVector3& operator*=(LLVector3& a, F32 k) inline const LLVector3& operator*=(LLVector3& a, F32 k)
{ {
a.mV[0] *= k; a.mV[VX] *= k;
a.mV[1] *= k; a.mV[VY] *= k;
a.mV[2] *= k; a.mV[VZ] *= k;
return a; return a;
} }
inline const LLVector3& operator*=(LLVector3& a, const LLVector3& b) inline const LLVector3& operator*=(LLVector3& a, const LLVector3& b)
{ {
a.mV[0] *= b.mV[0]; a.mV[VX] *= b.mV[VX];
a.mV[1] *= b.mV[1]; a.mV[VY] *= b.mV[VY];
a.mV[2] *= b.mV[2]; a.mV[VZ] *= b.mV[VZ];
return a; return a;
} }
inline const LLVector3& operator/=(LLVector3& a, F32 k) inline const LLVector3& operator/=(LLVector3& a, F32 k)
{ {
F32 t = 1.f / k; a.mV[VX] /= k;
a.mV[0] *= t; a.mV[VY] /= k;
a.mV[1] *= t; a.mV[VZ] /= k;
a.mV[2] *= t;
return a; return a;
} }
inline LLVector3 operator-(const LLVector3& a) inline LLVector3 operator-(const LLVector3& a)
{ {
return LLVector3( -a.mV[0], -a.mV[1], -a.mV[2] ); return LLVector3(-a.mV[VX], -a.mV[VY], -a.mV[VZ]);
} }
inline LLVector3::operator glm::vec3() const inline LLVector3::operator glm::vec3() const
@ -524,24 +523,24 @@ inline LLVector3::operator glm::vec4() const
inline F32 dist_vec(const LLVector3& a, const LLVector3& b) inline F32 dist_vec(const LLVector3& a, const LLVector3& b)
{ {
F32 x = a.mV[0] - b.mV[0]; F32 x = a.mV[VX] - b.mV[VX];
F32 y = a.mV[1] - b.mV[1]; F32 y = a.mV[VY] - b.mV[VY];
F32 z = a.mV[2] - b.mV[2]; F32 z = a.mV[VZ] - b.mV[VZ];
return (F32) sqrt( x*x + y*y + z*z ); return sqrt( x*x + y*y + z*z );
} }
inline F32 dist_vec_squared(const LLVector3& a, const LLVector3& b) inline F32 dist_vec_squared(const LLVector3& a, const LLVector3& b)
{ {
F32 x = a.mV[0] - b.mV[0]; F32 x = a.mV[VX] - b.mV[VX];
F32 y = a.mV[1] - b.mV[1]; F32 y = a.mV[VY] - b.mV[VY];
F32 z = a.mV[2] - b.mV[2]; F32 z = a.mV[VZ] - b.mV[VZ];
return x*x + y*y + z*z; return x*x + y*y + z*z;
} }
inline F32 dist_vec_squared2D(const LLVector3& a, const LLVector3& b) inline F32 dist_vec_squared2D(const LLVector3& a, const LLVector3& b)
{ {
F32 x = a.mV[0] - b.mV[0]; F32 x = a.mV[VX] - b.mV[VX];
F32 y = a.mV[1] - b.mV[1]; F32 y = a.mV[VY] - b.mV[VY];
return x*x + y*y; return x*x + y*y;
} }

View File

@ -124,8 +124,7 @@ LLColor4 LLColor4::cyan6(0.2f, 0.6f, 0.6f, 1.0f);
// conversion // conversion
LLColor4::operator LLColor4U() const LLColor4::operator LLColor4U() const
{ {
return LLColor4U( return LLColor4U((U8)llclampb(ll_round(mV[VRED] * 255.f)),
(U8)llclampb(ll_round(mV[VRED]*255.f)),
(U8)llclampb(ll_round(mV[VGREEN] * 255.f)), (U8)llclampb(ll_round(mV[VGREEN] * 255.f)),
(U8)llclampb(ll_round(mV[VBLUE] * 255.f)), (U8)llclampb(ll_round(mV[VBLUE] * 255.f)),
(U8)llclampb(ll_round(mV[VALPHA] * 255.f))); (U8)llclampb(ll_round(mV[VALPHA] * 255.f)));
@ -141,7 +140,7 @@ LLColor4::LLColor4(const LLColor3 &vec, F32 a)
LLColor4::LLColor4(const LLColor4U& color4u) LLColor4::LLColor4(const LLColor4U& color4u)
{ {
const F32 SCALE = 1.f/255.f; constexpr F32 SCALE = 1.f / 255.f;
mV[VRED] = color4u.mV[VRED] * SCALE; mV[VRED] = color4u.mV[VRED] * SCALE;
mV[VGREEN] = color4u.mV[VGREEN] * SCALE; mV[VGREEN] = color4u.mV[VGREEN] * SCALE;
mV[VBLUE] = color4u.mV[VBLUE] * SCALE; mV[VBLUE] = color4u.mV[VBLUE] * SCALE;
@ -158,7 +157,7 @@ LLColor4::LLColor4(const LLVector4& vector4)
const LLColor4& LLColor4::set(const LLColor4U& color4u) const LLColor4& LLColor4::set(const LLColor4U& color4u)
{ {
const F32 SCALE = 1.f/255.f; constexpr F32 SCALE = 1.f / 255.f;
mV[VRED] = color4u.mV[VRED] * SCALE; mV[VRED] = color4u.mV[VRED] * SCALE;
mV[VGREEN] = color4u.mV[VGREEN] * SCALE; mV[VGREEN] = color4u.mV[VGREEN] * SCALE;
mV[VBLUE] = color4u.mV[VBLUE] * SCALE; mV[VBLUE] = color4u.mV[VBLUE] * SCALE;
@ -190,7 +189,7 @@ const LLColor4& LLColor4::set(const LLColor3 &vec, F32 a)
// deprecated -- use set() // deprecated -- use set()
const LLColor4& LLColor4::setVec(const LLColor4U& color4u) const LLColor4& LLColor4::setVec(const LLColor4U& color4u)
{ {
const F32 SCALE = 1.f/255.f; constexpr F32 SCALE = 1.f / 255.f;
mV[VRED] = color4u.mV[VRED] * SCALE; mV[VRED] = color4u.mV[VRED] * SCALE;
mV[VGREEN] = color4u.mV[VGREEN] * SCALE; mV[VGREEN] = color4u.mV[VGREEN] * SCALE;
mV[VBLUE] = color4u.mV[VBLUE] * SCALE; mV[VBLUE] = color4u.mV[VBLUE] * SCALE;
@ -228,30 +227,30 @@ void LLColor4::setValue(const LLSD& sd)
F32 val; F32 val;
bool out_of_range = false; bool out_of_range = false;
val = sd[0].asReal(); val = sd[0].asReal();
mV[0] = llclamp(val, 0.f, 1.f); mV[VRED] = llclamp(val, 0.f, 1.f);
out_of_range = mV[0] != val; out_of_range = mV[VRED] != val;
val = sd[1].asReal(); val = sd[1].asReal();
mV[1] = llclamp(val, 0.f, 1.f); mV[VGREEN] = llclamp(val, 0.f, 1.f);
out_of_range |= mV[1] != val; out_of_range |= mV[VGREEN] != val;
val = sd[2].asReal(); val = sd[2].asReal();
mV[2] = llclamp(val, 0.f, 1.f); mV[VBLUE] = llclamp(val, 0.f, 1.f);
out_of_range |= mV[2] != val; out_of_range |= mV[VBLUE] != val;
val = sd[3].asReal(); val = sd[3].asReal();
mV[3] = llclamp(val, 0.f, 1.f); mV[VALPHA] = llclamp(val, 0.f, 1.f);
out_of_range |= mV[3] != val; out_of_range |= mV[VALPHA] != val;
if (out_of_range) if (out_of_range)
{ {
LL_WARNS() << "LLSD color value out of range!" << LL_ENDL; LL_WARNS() << "LLSD color value out of range!" << LL_ENDL;
} }
#else #else
mV[0] = (F32) sd[0].asReal(); mV[VRED] = (F32)sd[VRED].asReal();
mV[1] = (F32) sd[1].asReal(); mV[VGREEN] = (F32)sd[VGREEN].asReal();
mV[2] = (F32) sd[2].asReal(); mV[VBLUE] = (F32)sd[VBLUE].asReal();
mV[3] = (F32) sd[3].asReal(); mV[VALPHA] = (F32)sd[VALPHA].asReal();
#endif #endif
} }
@ -266,7 +265,6 @@ const LLColor4& LLColor4::operator=(const LLColor3 &a)
return (*this); return (*this);
} }
std::ostream& operator<<(std::ostream& s, const LLColor4& a) std::ostream& operator<<(std::ostream& s, const LLColor4& a)
{ {
s << "{ " << a.mV[VRED] << ", " << a.mV[VGREEN] << ", " << a.mV[VBLUE] << ", " << a.mV[VALPHA] << " }"; s << "{ " << a.mV[VRED] << ", " << a.mV[VGREEN] << ", " << a.mV[VBLUE] << ", " << a.mV[VALPHA] << " }";
@ -275,16 +273,12 @@ std::ostream& operator<<(std::ostream& s, const LLColor4 &a)
bool operator==(const LLColor4& a, const LLColor3& b) bool operator==(const LLColor4& a, const LLColor3& b)
{ {
return ( (a.mV[VRED] == b.mV[VRED]) return ((a.mV[VRED] == b.mV[VRED]) && (a.mV[VGREEN] == b.mV[VGREEN]) && (a.mV[VBLUE] == b.mV[VBLUE]));
&&(a.mV[VGREEN] == b.mV[VGREEN])
&&(a.mV[VBLUE] == b.mV[VBLUE]));
} }
bool operator!=(const LLColor4& a, const LLColor3& b) bool operator!=(const LLColor4& a, const LLColor3& b)
{ {
return ( (a.mV[VRED] != b.mV[VRED]) return ((a.mV[VRED] != b.mV[VRED]) || (a.mV[VGREEN] != b.mV[VGREEN]) || (a.mV[VBLUE] != b.mV[VBLUE]));
||(a.mV[VGREEN] != b.mV[VGREEN])
||(a.mV[VBLUE] != b.mV[VBLUE]));
} }
LLColor3 vec4to3(const LLColor4& vec) LLColor3 vec4to3(const LLColor4& vec)
@ -301,11 +295,16 @@ LLColor4 vec3to4(const LLColor3 &vec)
static F32 hueToRgb(F32 val1In, F32 val2In, F32 valHUeIn) static F32 hueToRgb(F32 val1In, F32 val2In, F32 valHUeIn)
{ {
if ( valHUeIn < 0.0f ) valHUeIn += 1.0f; if (valHUeIn < 0.0f)
if ( valHUeIn > 1.0f ) valHUeIn -= 1.0f; valHUeIn += 1.0f;
if ( ( 6.0f * valHUeIn ) < 1.0f ) return ( val1In + ( val2In - val1In ) * 6.0f * valHUeIn ); if (valHUeIn > 1.0f)
if ( ( 2.0f * valHUeIn ) < 1.0f ) return ( val2In ); valHUeIn -= 1.0f;
if ( ( 3.0f * valHUeIn ) < 2.0f ) return ( val1In + ( val2In - val1In ) * ( ( 2.0f / 3.0f ) - valHUeIn ) * 6.0f ); if ((6.0f * valHUeIn) < 1.0f)
return (val1In + (val2In - val1In) * 6.0f * valHUeIn);
if ((2.0f * valHUeIn) < 1.0f)
return (val2In);
if ((3.0f * valHUeIn) < 2.0f)
return (val1In + (val2In - val1In) * ((2.0f / 3.0f) - valHUeIn) * 6.0f);
return (val1In); return (val1In);
} }
@ -357,7 +356,7 @@ void LLColor4::calcHSL(F32* hue, F32* saturation, F32* luminance) const
} }
else else
{ {
if ( L < 0.5 ) if (L < 0.5f)
S = del_Max / (var_Max + var_Min); S = del_Max / (var_Max + var_Min);
else else
S = del_Max / (2.0f - var_Max - var_Min); S = del_Max / (2.0f - var_Max - var_Min);
@ -368,20 +367,23 @@ void LLColor4::calcHSL(F32* hue, F32* saturation, F32* luminance) const
if (var_R >= var_Max) if (var_R >= var_Max)
H = del_B - del_G; H = del_B - del_G;
else else if (var_G >= var_Max)
if ( var_G >= var_Max )
H = (1.0f / 3.0f) + del_R - del_B; H = (1.0f / 3.0f) + del_R - del_B;
else else if (var_B >= var_Max)
if ( var_B >= var_Max )
H = (2.0f / 3.0f) + del_G - del_R; H = (2.0f / 3.0f) + del_G - del_R;
if ( H < 0.0f ) H += 1.0f; if (H < 0.0f)
if ( H > 1.0f ) H -= 1.0f; H += 1.0f;
if (H > 1.0f)
H -= 1.0f;
} }
if (hue) *hue = H; if (hue)
if (saturation) *saturation = S; *hue = H;
if (luminance) *luminance = L; if (saturation)
*saturation = S;
if (luminance)
*luminance = L;
} }
// static // static
@ -435,7 +437,8 @@ bool LLColor4::parseColor(const std::string& buf, LLColor4* color)
// Make sure all values are between 0 and 1. // Make sure all values are between 0 and 1.
if (v.mV[VRED] > 1.f || v.mV[VGREEN] > 1.f || v.mV[VBLUE] > 1.f || v.mV[VALPHA] > 1.f) if (v.mV[VRED] > 1.f || v.mV[VGREEN] > 1.f || v.mV[VBLUE] > 1.f || v.mV[VALPHA] > 1.f)
{ {
v = v * (1.f / 255.f); constexpr F32 SCALE{ 1.f / 255.f };
v *= SCALE;
} }
color->set(v); color->set(v);
} }

View File

@ -28,7 +28,6 @@
#define LL_V4COLOR_H #define LL_V4COLOR_H
#include "llerror.h" #include "llerror.h"
//#include "vmath.h"
#include "llmath.h" #include "llmath.h"
#include "llsd.h" #include "llsd.h"
@ -38,9 +37,9 @@ class LLVector4;
// LLColor4 = |x y z w| // LLColor4 = |x y z w|
static const U32 LENGTHOFCOLOR4 = 4; static constexpr U32 LENGTHOFCOLOR4 = 4;
static const U32 MAX_LENGTH_OF_COLOR_NAME = 15; //Give plenty of room for additional colors... static constexpr U32 MAX_LENGTH_OF_COLOR_NAME = 15; // Give plenty of room for additional colors...
class LLColor4 class LLColor4
{ {
@ -59,10 +58,10 @@ class LLColor4
LLSD getValue() const LLSD getValue() const
{ {
LLSD ret; LLSD ret;
ret[0] = mV[0]; ret[VRED] = mV[VRED];
ret[1] = mV[1]; ret[VGREEN] = mV[VGREEN];
ret[2] = mV[2]; ret[VBLUE] = mV[VBLUE];
ret[3] = mV[3]; ret[VALPHA] = mV[VALPHA];
return ret; return ret;
} }
@ -111,7 +110,7 @@ class LLColor4
F32 lengthSquared() const; // Returns magnitude squared of LLColor4 F32 lengthSquared() const; // Returns magnitude squared of LLColor4
F32 normalize(); // deprecated -- use normalize() F32 normalize(); // deprecated -- use normalize()
bool isOpaque() { return mV[VALPHA] == 1.f; } bool isOpaque() const { return mV[VALPHA] == 1.f; }
F32 operator[](int idx) const { return mV[idx]; } F32 operator[](int idx) const { return mV[idx]; }
F32& operator[](int idx) { return mV[idx]; } F32& operator[](int idx) { return mV[idx]; }
@ -232,7 +231,6 @@ class LLColor4
inline void clamp(); inline void clamp();
}; };
// Non-member functions // Non-member functions
F32 distVec(const LLColor4& a, const LLColor4& b); // Returns distance between a and b F32 distVec(const LLColor4& a, const LLColor4& b); // Returns distance between a and b
F32 distVec_squared(const LLColor4& a, const LLColor4& b); // Returns distance squared between a and b F32 distVec_squared(const LLColor4& a, const LLColor4& b); // Returns distance squared between a and b
@ -240,7 +238,7 @@ LLColor3 vec4to3(const LLColor4 &vec);
LLColor4 vec3to4(const LLColor3& vec); LLColor4 vec3to4(const LLColor3& vec);
LLColor4 lerp(const LLColor4& a, const LLColor4& b, F32 u); LLColor4 lerp(const LLColor4& a, const LLColor4& b, F32 u);
inline LLColor4::LLColor4(void) inline LLColor4::LLColor4()
{ {
mV[VRED] = 0.f; mV[VRED] = 0.f;
mV[VGREEN] = 0.f; mV[VGREEN] = 0.f;
@ -277,7 +275,6 @@ inline LLColor4::LLColor4(U32 clr)
mV[VALPHA] = (clr >> 24) * (1.0f / 255.0f); mV[VALPHA] = (clr >> 24) * (1.0f / 255.0f);
} }
inline LLColor4::LLColor4(const F32* vec) inline LLColor4::LLColor4(const F32* vec)
{ {
mV[VRED] = vec[VRED]; mV[VRED] = vec[VRED];
@ -334,7 +331,6 @@ inline const LLColor4& LLColor4::set(const LLColor4 &vec)
return (*this); return (*this);
} }
inline const LLColor4& LLColor4::set(const F32* vec) inline const LLColor4& LLColor4::set(const F32* vec)
{ {
mV[VRED] = vec[VRED]; mV[VRED] = vec[VRED];
@ -386,7 +382,6 @@ inline const LLColor4& LLColor4::setVec(const LLColor4 &vec)
return (*this); return (*this);
} }
// deprecated // deprecated
inline const LLColor4& LLColor4::setVec(const F32* vec) inline const LLColor4& LLColor4::setVec(const F32* vec)
{ {
@ -405,19 +400,19 @@ inline const LLColor4& LLColor4::setAlpha(F32 a)
// LLColor4 Magnitude and Normalization Functions // LLColor4 Magnitude and Normalization Functions
inline F32 LLColor4::length(void) const inline F32 LLColor4::length() const
{ {
return (F32) sqrt(mV[VRED]*mV[VRED] + mV[VGREEN]*mV[VGREEN] + mV[VBLUE]*mV[VBLUE]); return sqrt(mV[VRED] * mV[VRED] + mV[VGREEN] * mV[VGREEN] + mV[VBLUE] * mV[VBLUE]);
} }
inline F32 LLColor4::lengthSquared(void) const inline F32 LLColor4::lengthSquared() const
{ {
return mV[VRED] * mV[VRED] + mV[VGREEN] * mV[VGREEN] + mV[VBLUE] * mV[VBLUE]; return mV[VRED] * mV[VRED] + mV[VGREEN] * mV[VGREEN] + mV[VBLUE] * mV[VBLUE];
} }
inline F32 LLColor4::normalize(void) inline F32 LLColor4::normalize()
{ {
F32 mag = (F32) sqrt(mV[VRED]*mV[VRED] + mV[VGREEN]*mV[VGREEN] + mV[VBLUE]*mV[VBLUE]); F32 mag = sqrt(mV[VRED] * mV[VRED] + mV[VGREEN] * mV[VGREEN] + mV[VBLUE] * mV[VBLUE]);
F32 oomag; F32 oomag;
if (mag) if (mag)
@ -427,25 +422,25 @@ inline F32 LLColor4::normalize(void)
mV[VGREEN] *= oomag; mV[VGREEN] *= oomag;
mV[VBLUE] *= oomag; mV[VBLUE] *= oomag;
} }
return (mag); return mag;
} }
// deprecated // deprecated
inline F32 LLColor4::magVec(void) const inline F32 LLColor4::magVec() const
{ {
return (F32) sqrt(mV[VRED]*mV[VRED] + mV[VGREEN]*mV[VGREEN] + mV[VBLUE]*mV[VBLUE]); return sqrt(mV[VRED] * mV[VRED] + mV[VGREEN] * mV[VGREEN] + mV[VBLUE] * mV[VBLUE]);
} }
// deprecated // deprecated
inline F32 LLColor4::magVecSquared(void) const inline F32 LLColor4::magVecSquared() const
{ {
return mV[VRED] * mV[VRED] + mV[VGREEN] * mV[VGREEN] + mV[VBLUE] * mV[VBLUE]; return mV[VRED] * mV[VRED] + mV[VGREEN] * mV[VGREEN] + mV[VBLUE] * mV[VBLUE];
} }
// deprecated // deprecated
inline F32 LLColor4::normVec(void) inline F32 LLColor4::normVec()
{ {
F32 mag = (F32) sqrt(mV[VRED]*mV[VRED] + mV[VGREEN]*mV[VGREEN] + mV[VBLUE]*mV[VBLUE]); F32 mag = sqrt(mV[VRED] * mV[VRED] + mV[VGREEN] * mV[VGREEN] + mV[VBLUE] * mV[VBLUE]);
F32 oomag; F32 oomag;
if (mag) if (mag)
@ -455,102 +450,63 @@ inline F32 LLColor4::normVec(void)
mV[VGREEN] *= oomag; mV[VGREEN] *= oomag;
mV[VBLUE] *= oomag; mV[VBLUE] *= oomag;
} }
return (mag); return mag;
} }
// LLColor4 Operators // LLColor4 Operators
inline LLColor4 operator+(const LLColor4& a, const LLColor4& b) inline LLColor4 operator+(const LLColor4& a, const LLColor4& b)
{ {
return LLColor4( return LLColor4(a.mV[VRED] + b.mV[VRED], a.mV[VGREEN] + b.mV[VGREEN], a.mV[VBLUE] + b.mV[VBLUE], a.mV[VALPHA] + b.mV[VALPHA]);
a.mV[VRED] + b.mV[VRED],
a.mV[VGREEN] + b.mV[VGREEN],
a.mV[VBLUE] + b.mV[VBLUE],
a.mV[VALPHA] + b.mV[VALPHA]);
} }
inline LLColor4 operator-(const LLColor4& a, const LLColor4& b) inline LLColor4 operator-(const LLColor4& a, const LLColor4& b)
{ {
return LLColor4( return LLColor4(a.mV[VRED] - b.mV[VRED], a.mV[VGREEN] - b.mV[VGREEN], a.mV[VBLUE] - b.mV[VBLUE], a.mV[VALPHA] - b.mV[VALPHA]);
a.mV[VRED] - b.mV[VRED],
a.mV[VGREEN] - b.mV[VGREEN],
a.mV[VBLUE] - b.mV[VBLUE],
a.mV[VALPHA] - b.mV[VALPHA]);
} }
inline LLColor4 operator*(const LLColor4& a, const LLColor4& b) inline LLColor4 operator*(const LLColor4& a, const LLColor4& b)
{ {
return LLColor4( return LLColor4(a.mV[VRED] * b.mV[VRED], a.mV[VGREEN] * b.mV[VGREEN], a.mV[VBLUE] * b.mV[VBLUE], a.mV[VALPHA] * b.mV[VALPHA]);
a.mV[VRED] * b.mV[VRED],
a.mV[VGREEN] * b.mV[VGREEN],
a.mV[VBLUE] * b.mV[VBLUE],
a.mV[VALPHA] * b.mV[VALPHA]);
} }
inline LLColor4 operator*(const LLColor4& a, F32 k) inline LLColor4 operator*(const LLColor4& a, F32 k)
{ {
// only affects rgb (not a!) // only affects rgb (not a!)
return LLColor4( return LLColor4(a.mV[VRED] * k, a.mV[VGREEN] * k, a.mV[VBLUE] * k, a.mV[VALPHA]);
a.mV[VRED] * k,
a.mV[VGREEN] * k,
a.mV[VBLUE] * k,
a.mV[VALPHA]);
} }
inline LLColor4 operator/(const LLColor4& a, F32 k) inline LLColor4 operator/(const LLColor4& a, F32 k)
{ {
return LLColor4( return LLColor4(a.mV[VRED] / k, a.mV[VGREEN] / k, a.mV[VBLUE] / k, a.mV[VALPHA]);
a.mV[VRED] / k,
a.mV[VGREEN] / k,
a.mV[VBLUE] / k,
a.mV[VALPHA]);
} }
inline LLColor4 operator*(F32 k, const LLColor4& a) inline LLColor4 operator*(F32 k, const LLColor4& a)
{ {
// only affects rgb (not a!) // only affects rgb (not a!)
return LLColor4( return LLColor4(a.mV[VRED] * k, a.mV[VGREEN] * k, a.mV[VBLUE] * k, a.mV[VALPHA]);
a.mV[VRED] * k,
a.mV[VGREEN] * k,
a.mV[VBLUE] * k,
a.mV[VALPHA]);
} }
inline LLColor4 operator%(F32 k, const LLColor4& a) inline LLColor4 operator%(F32 k, const LLColor4& a)
{ {
// only affects alpha (not rgb!) // only affects alpha (not rgb!)
return LLColor4( return LLColor4(a.mV[VRED], a.mV[VGREEN], a.mV[VBLUE], a.mV[VALPHA] * k);
a.mV[VRED],
a.mV[VGREEN],
a.mV[VBLUE],
a.mV[VALPHA] * k);
} }
inline LLColor4 operator%(const LLColor4& a, F32 k) inline LLColor4 operator%(const LLColor4& a, F32 k)
{ {
// only affects alpha (not rgb!) // only affects alpha (not rgb!)
return LLColor4( return LLColor4(a.mV[VRED], a.mV[VGREEN], a.mV[VBLUE], a.mV[VALPHA] * k);
a.mV[VRED],
a.mV[VGREEN],
a.mV[VBLUE],
a.mV[VALPHA] * k);
} }
inline bool operator==(const LLColor4& a, const LLColor4& b) inline bool operator==(const LLColor4& a, const LLColor4& b)
{ {
return ( (a.mV[VRED] == b.mV[VRED]) return ((a.mV[VRED] == b.mV[VRED]) && (a.mV[VGREEN] == b.mV[VGREEN]) && (a.mV[VBLUE] == b.mV[VBLUE]) && (a.mV[VALPHA] == b.mV[VALPHA]));
&&(a.mV[VGREEN] == b.mV[VGREEN])
&&(a.mV[VBLUE] == b.mV[VBLUE])
&&(a.mV[VALPHA] == b.mV[VALPHA]));
} }
inline bool operator!=(const LLColor4& a, const LLColor4& b) inline bool operator!=(const LLColor4& a, const LLColor4& b)
{ {
return ( (a.mV[VRED] != b.mV[VRED]) return ((a.mV[VRED] != b.mV[VRED]) || (a.mV[VGREEN] != b.mV[VGREEN]) || (a.mV[VBLUE] != b.mV[VBLUE]) || (a.mV[VALPHA] != b.mV[VALPHA]));
||(a.mV[VGREEN] != b.mV[VGREEN])
||(a.mV[VBLUE] != b.mV[VBLUE])
||(a.mV[VALPHA] != b.mV[VALPHA]));
} }
inline const LLColor4& operator+=(LLColor4& a, const LLColor4& b) inline const LLColor4& operator+=(LLColor4& a, const LLColor4& b)
@ -596,25 +552,23 @@ inline const LLColor4& operator%=(LLColor4 &a, F32 k)
return a; return a;
} }
// Non-member functions // Non-member functions
inline F32 distVec(const LLColor4& a, const LLColor4& b) inline F32 distVec(const LLColor4& a, const LLColor4& b)
{ {
LLColor4 vec = a - b; LLColor4 vec = a - b;
return (vec.length()); return vec.length();
} }
inline F32 distVec_squared(const LLColor4& a, const LLColor4& b) inline F32 distVec_squared(const LLColor4& a, const LLColor4& b)
{ {
LLColor4 vec = a - b; LLColor4 vec = a - b;
return (vec.lengthSquared()); return vec.lengthSquared();
} }
inline LLColor4 lerp(const LLColor4& a, const LLColor4& b, F32 u) inline LLColor4 lerp(const LLColor4& a, const LLColor4& b, F32 u)
{ {
return LLColor4( return LLColor4(a.mV[VRED] + (b.mV[VRED] - a.mV[VRED]) * u,
a.mV[VRED] + (b.mV[VRED] - a.mV[VRED]) * u,
a.mV[VGREEN] + (b.mV[VGREEN] - a.mV[VGREEN]) * u, a.mV[VGREEN] + (b.mV[VGREEN] - a.mV[VGREEN]) * u,
a.mV[VBLUE] + (b.mV[VBLUE] - a.mV[VBLUE]) * u, a.mV[VBLUE] + (b.mV[VBLUE] - a.mV[VBLUE]) * u,
a.mV[VALPHA] + (b.mV[VALPHA] - a.mV[VALPHA]) * u); a.mV[VALPHA] + (b.mV[VALPHA] - a.mV[VALPHA]) * u);
@ -622,67 +576,68 @@ inline LLColor4 lerp(const LLColor4 &a, const LLColor4 &b, F32 u)
inline bool LLColor4::operator<(const LLColor4& rhs) const inline bool LLColor4::operator<(const LLColor4& rhs) const
{ {
if (mV[0] != rhs.mV[0]) if (mV[VRED] != rhs.mV[VRED])
{ {
return mV[0] < rhs.mV[0]; return mV[VRED] < rhs.mV[VRED];
} }
if (mV[1] != rhs.mV[1]) if (mV[VGREEN] != rhs.mV[VGREEN])
{ {
return mV[1] < rhs.mV[1]; return mV[VGREEN] < rhs.mV[VGREEN];
} }
if (mV[2] != rhs.mV[2]) if (mV[VBLUE] != rhs.mV[VBLUE])
{ {
return mV[2] < rhs.mV[2]; return mV[VBLUE] < rhs.mV[VBLUE];
} }
return mV[3] < rhs.mV[3]; return mV[VALPHA] < rhs.mV[VALPHA];
} }
void LLColor4::clamp() void LLColor4::clamp()
{ {
// Clamp the color... // Clamp the color...
if (mV[0] < 0.f) if (mV[VRED] < 0.f)
{ {
mV[0] = 0.f; mV[VRED] = 0.f;
} }
else if (mV[0] > 1.f) else if (mV[VRED] > 1.f)
{ {
mV[0] = 1.f; mV[VRED] = 1.f;
} }
if (mV[1] < 0.f) if (mV[VGREEN] < 0.f)
{ {
mV[1] = 0.f; mV[VGREEN] = 0.f;
} }
else if (mV[1] > 1.f) else if (mV[VGREEN] > 1.f)
{ {
mV[1] = 1.f; mV[VGREEN] = 1.f;
} }
if (mV[2] < 0.f) if (mV[VBLUE] < 0.f)
{ {
mV[2] = 0.f; mV[VBLUE] = 0.f;
} }
else if (mV[2] > 1.f) else if (mV[VBLUE] > 1.f)
{ {
mV[2] = 1.f; mV[VBLUE] = 1.f;
} }
if (mV[3] < 0.f) if (mV[VALPHA] < 0.f)
{ {
mV[3] = 0.f; mV[VALPHA] = 0.f;
} }
else if (mV[3] > 1.f) else if (mV[VALPHA] > 1.f)
{ {
mV[3] = 1.f; mV[VALPHA] = 1.f;
} }
} }
// Return the given linear space color value in gamma corrected (sRGB) space // Return the given linear space color value in gamma corrected (sRGB) space
inline const LLColor4 srgbColor4(const LLColor4 &a) { inline const LLColor4 srgbColor4(const LLColor4& a)
{
LLColor4 srgbColor; LLColor4 srgbColor;
srgbColor.mV[0] = linearTosRGB(a.mV[0]); srgbColor.mV[VRED] = linearTosRGB(a.mV[VRED]);
srgbColor.mV[1] = linearTosRGB(a.mV[1]); srgbColor.mV[VGREEN] = linearTosRGB(a.mV[VGREEN]);
srgbColor.mV[2] = linearTosRGB(a.mV[2]); srgbColor.mV[VBLUE] = linearTosRGB(a.mV[VBLUE]);
srgbColor.mV[3] = a.mV[3]; srgbColor.mV[VALPHA] = a.mV[VALPHA];
return srgbColor; return srgbColor;
} }
@ -691,10 +646,10 @@ inline const LLColor4 srgbColor4(const LLColor4 &a) {
inline const LLColor4 linearColor4(const LLColor4& a) inline const LLColor4 linearColor4(const LLColor4& a)
{ {
LLColor4 linearColor; LLColor4 linearColor;
linearColor.mV[0] = sRGBtoLinear(a.mV[0]); linearColor.mV[VRED] = sRGBtoLinear(a.mV[VRED]);
linearColor.mV[1] = sRGBtoLinear(a.mV[1]); linearColor.mV[VGREEN] = sRGBtoLinear(a.mV[VGREEN]);
linearColor.mV[2] = sRGBtoLinear(a.mV[2]); linearColor.mV[VBLUE] = sRGBtoLinear(a.mV[VBLUE]);
linearColor.mV[3] = a.mV[3]; linearColor.mV[VALPHA] = a.mV[VALPHA];
return linearColor; return linearColor;
} }
@ -720,4 +675,3 @@ void LLColor4::write(std::vector<T>& v) const
} }
#endif #endif

View File

@ -26,10 +26,7 @@
#include "linden_common.h" #include "linden_common.h"
//#include "v3coloru.h"
#include "v4coloru.h" #include "v4coloru.h"
#include "v4color.h"
//#include "vmath.h"
#include "llmath.h" #include "llmath.h"
// LLColor4U // LLColor4U
@ -39,48 +36,6 @@ LLColor4U LLColor4U::red (255, 0, 0, 255);
LLColor4U LLColor4U::green( 0, 255, 0, 255); LLColor4U LLColor4U::green( 0, 255, 0, 255);
LLColor4U LLColor4U::blue ( 0, 0, 255, 255); LLColor4U LLColor4U::blue ( 0, 0, 255, 255);
// conversion
/* inlined to fix gcc compile link error
LLColor4U::operator LLColor4()
{
return(LLColor4((F32)mV[VRED]/255.f,(F32)mV[VGREEN]/255.f,(F32)mV[VBLUE]/255.f,(F32)mV[VALPHA]/255.f));
}
*/
// Constructors
/*
LLColor4U::LLColor4U(const LLColor3 &vec)
{
mV[VRED] = vec.mV[VRED];
mV[VGREEN] = vec.mV[VGREEN];
mV[VBLUE] = vec.mV[VBLUE];
mV[VALPHA] = 255;
}
*/
// Clear and Assignment Functions
// LLColor4U Operators
/*
LLColor4U LLColor4U::operator=(const LLColor3 &a)
{
mV[VRED] = a.mV[VRED];
mV[VGREEN] = a.mV[VGREEN];
mV[VBLUE] = a.mV[VBLUE];
// converting from an rgb sets a=1 (opaque)
mV[VALPHA] = 255;
return (*this);
}
*/
std::ostream& operator<<(std::ostream& s, const LLColor4U& a) std::ostream& operator<<(std::ostream& s, const LLColor4U& a)
{ {
s << "{ " << (S32)a.mV[VRED] << ", " << (S32)a.mV[VGREEN] << ", " << (S32)a.mV[VBLUE] << ", " << (S32)a.mV[VALPHA] << " }"; s << "{ " << (S32)a.mV[VRED] << ", " << (S32)a.mV[VGREEN] << ", " << (S32)a.mV[VBLUE] << ", " << (S32)a.mV[VALPHA] << " }";
@ -95,7 +50,7 @@ bool LLColor4U::parseColor4U(const std::string& buf, LLColor4U* value)
return false; return false;
} }
U32 v[4]; U32 v[4]{};
S32 count = sscanf(buf.c_str(), "%u, %u, %u, %u", v + 0, v + 1, v + 2, v + 3); S32 count = sscanf(buf.c_str(), "%u, %u, %u, %u", v + 0, v + 1, v + 2, v + 3);
if (1 == count) if (1 == count)
{ {
@ -115,6 +70,6 @@ bool LLColor4U::parseColor4U(const std::string& buf, LLColor4U* value)
} }
} }
value->set( U8(v[0]), U8(v[1]), U8(v[2]), U8(v[3]) ); value->set(U8(v[VRED]), U8(v[VGREEN]), U8(v[VBLUE]), U8(v[VALPHA]));
return true; return true;
} }

View File

@ -28,51 +28,43 @@
#define LL_V4COLORU_H #define LL_V4COLORU_H
#include "llerror.h" #include "llerror.h"
//#include "vmath.h"
#include "llmath.h" #include "llmath.h"
//#include "v4color.h"
#include "v3color.h" #include "v3color.h"
#include "v4color.h" #include "v4color.h"
//class LLColor3U;
class LLColor4; class LLColor4;
// LLColor4U = | red green blue alpha | // LLColor4U = | red green blue alpha |
static const U32 LENGTHOFCOLOR4U = 4; static constexpr U32 LENGTHOFCOLOR4U = 4;
class LLColor4U class LLColor4U
{ {
public: public:
U8 mV[LENGTHOFCOLOR4U]; U8 mV[LENGTHOFCOLOR4U];
LLColor4U(); // Initializes LLColor4U to (0, 0, 0, 1) LLColor4U(); // Initializes LLColor4U to (0, 0, 0, 1)
LLColor4U(U8 r, U8 g, U8 b); // Initializes LLColor4U to (r, g, b, 1) LLColor4U(U8 r, U8 g, U8 b); // Initializes LLColor4U to (r, g, b, 1)
LLColor4U(U8 r, U8 g, U8 b, U8 a); // Initializes LLColor4U to (r. g, b, a) LLColor4U(U8 r, U8 g, U8 b, U8 a); // Initializes LLColor4U to (r. g, b, a)
LLColor4U(const U8* vec); // Initializes LLColor4U to (vec[0]. vec[1], vec[2], 1) LLColor4U(const U8* vec); // Initializes LLColor4U to (vec[0]. vec[1], vec[2], 1)
explicit LLColor4U(const LLSD& sd) explicit LLColor4U(const LLSD& sd) { setValue(sd); }
{
setValue(sd);
}
void setValue(const LLSD& sd) void setValue(const LLSD& sd)
{ {
mV[0] = sd[0].asInteger(); mV[VRED] = sd[VRED].asInteger();
mV[1] = sd[1].asInteger(); mV[VGREEN] = sd[VGREEN].asInteger();
mV[2] = sd[2].asInteger(); mV[VBLUE] = sd[VBLUE].asInteger();
mV[3] = sd[3].asInteger(); mV[VALPHA] = sd[VALPHA].asInteger();
} }
LLSD getValue() const LLSD getValue() const
{ {
LLSD ret; LLSD ret;
ret[0] = mV[0]; ret[VRED] = mV[VRED];
ret[1] = mV[1]; ret[VGREEN] = mV[VGREEN];
ret[2] = mV[2]; ret[VBLUE] = mV[VBLUE];
ret[3] = mV[3]; ret[VALPHA] = mV[VALPHA];
return ret; return ret;
} }
@ -119,10 +111,7 @@ public:
static bool parseColor4U(const std::string& buf, LLColor4U* value); static bool parseColor4U(const std::string& buf, LLColor4U* value);
// conversion // conversion
operator LLColor4() const operator LLColor4() const { return LLColor4(*this); }
{
return LLColor4(*this);
}
U32 asRGBA() const; U32 asRGBA() const;
void fromRGBA(U32 aVal); void fromRGBA(U32 aVal);
@ -134,12 +123,10 @@ public:
static LLColor4U blue; static LLColor4U blue;
}; };
// Non-member functions // Non-member functions
F32 distVec(const LLColor4U& a, const LLColor4U& b); // Returns distance between a and b F32 distVec(const LLColor4U& a, const LLColor4U& b); // Returns distance between a and b
F32 distVec_squared(const LLColor4U& a, const LLColor4U& b); // Returns distance squared between a and b F32 distVec_squared(const LLColor4U& a, const LLColor4U& b); // Returns distance squared between a and b
inline LLColor4U::LLColor4U() inline LLColor4U::LLColor4U()
{ {
mV[VRED] = 0; mV[VRED] = 0;
@ -172,13 +159,6 @@ inline LLColor4U::LLColor4U(const U8 *vec)
mV[VALPHA] = vec[VALPHA]; mV[VALPHA] = vec[VALPHA];
} }
/*
inline LLColor4U::operator LLColor4()
{
return(LLColor4((F32)mV[VRED]/255.f,(F32)mV[VGREEN]/255.f,(F32)mV[VBLUE]/255.f,(F32)mV[VALPHA]/255.f));
}
*/
inline const LLColor4U& LLColor4U::setToBlack(void) inline const LLColor4U& LLColor4U::setToBlack(void)
{ {
mV[VRED] = 0; mV[VRED] = 0;
@ -211,10 +191,10 @@ inline const LLColor4U& LLColor4U::set(const U8 x, const U8 y, const U8 z)
inline const LLColor4U& LLColor4U::set(const U8 r, const U8 g, const U8 b, U8 a) inline const LLColor4U& LLColor4U::set(const U8 r, const U8 g, const U8 b, U8 a)
{ {
mV[0] = r; mV[VRED] = r;
mV[1] = g; mV[VGREEN] = g;
mV[2] = b; mV[VBLUE] = b;
mV[3] = a; mV[VALPHA] = a;
return (*this); return (*this);
} }
@ -252,10 +232,10 @@ inline const LLColor4U& LLColor4U::setVec(const U8 x, const U8 y, const U8 z)
// deprecated // deprecated
inline const LLColor4U& LLColor4U::setVec(const U8 r, const U8 g, const U8 b, U8 a) inline const LLColor4U& LLColor4U::setVec(const U8 r, const U8 g, const U8 b, U8 a)
{ {
mV[0] = r; mV[VRED] = r;
mV[1] = g; mV[VGREEN] = g;
mV[2] = b; mV[VBLUE] = b;
mV[3] = a; mV[VALPHA] = a;
return (*this); return (*this);
} }
@ -287,53 +267,41 @@ inline const LLColor4U& LLColor4U::setAlpha(U8 a)
// LLColor4U Magnitude and Normalization Functions // LLColor4U Magnitude and Normalization Functions
inline F32 LLColor4U::length(void) const inline F32 LLColor4U::length() const
{ {
return (F32) sqrt( ((F32)mV[VRED]) * mV[VRED] + ((F32)mV[VGREEN]) * mV[VGREEN] + ((F32)mV[VBLUE]) * mV[VBLUE] ); return sqrt(((F32)mV[VRED]) * mV[VRED] + ((F32)mV[VGREEN]) * mV[VGREEN] + ((F32)mV[VBLUE]) * mV[VBLUE]);
} }
inline F32 LLColor4U::lengthSquared(void) const inline F32 LLColor4U::lengthSquared() const
{ {
return ((F32)mV[VRED]) * mV[VRED] + ((F32)mV[VGREEN]) * mV[VGREEN] + ((F32)mV[VBLUE]) * mV[VBLUE]; return ((F32)mV[VRED]) * mV[VRED] + ((F32)mV[VGREEN]) * mV[VGREEN] + ((F32)mV[VBLUE]) * mV[VBLUE];
} }
// deprecated // deprecated
inline F32 LLColor4U::magVec(void) const inline F32 LLColor4U::magVec() const
{ {
return (F32) sqrt( ((F32)mV[VRED]) * mV[VRED] + ((F32)mV[VGREEN]) * mV[VGREEN] + ((F32)mV[VBLUE]) * mV[VBLUE] ); return sqrt(((F32)mV[VRED]) * mV[VRED] + ((F32)mV[VGREEN]) * mV[VGREEN] + ((F32)mV[VBLUE]) * mV[VBLUE]);
} }
// deprecated // deprecated
inline F32 LLColor4U::magVecSquared(void) const inline F32 LLColor4U::magVecSquared() const
{ {
return ((F32)mV[VRED]) * mV[VRED] + ((F32)mV[VGREEN]) * mV[VGREEN] + ((F32)mV[VBLUE]) * mV[VBLUE]; return ((F32)mV[VRED]) * mV[VRED] + ((F32)mV[VGREEN]) * mV[VGREEN] + ((F32)mV[VBLUE]) * mV[VBLUE];
} }
inline LLColor4U operator+(const LLColor4U& a, const LLColor4U& b) inline LLColor4U operator+(const LLColor4U& a, const LLColor4U& b)
{ {
return LLColor4U( return LLColor4U(a.mV[VRED] + b.mV[VRED], a.mV[VGREEN] + b.mV[VGREEN], a.mV[VBLUE] + b.mV[VBLUE], a.mV[VALPHA] + b.mV[VALPHA]);
a.mV[VRED] + b.mV[VRED],
a.mV[VGREEN] + b.mV[VGREEN],
a.mV[VBLUE] + b.mV[VBLUE],
a.mV[VALPHA] + b.mV[VALPHA]);
} }
inline LLColor4U operator-(const LLColor4U& a, const LLColor4U& b) inline LLColor4U operator-(const LLColor4U& a, const LLColor4U& b)
{ {
return LLColor4U( return LLColor4U(a.mV[VRED] - b.mV[VRED], a.mV[VGREEN] - b.mV[VGREEN], a.mV[VBLUE] - b.mV[VBLUE], a.mV[VALPHA] - b.mV[VALPHA]);
a.mV[VRED] - b.mV[VRED],
a.mV[VGREEN] - b.mV[VGREEN],
a.mV[VBLUE] - b.mV[VBLUE],
a.mV[VALPHA] - b.mV[VALPHA]);
} }
inline LLColor4U operator*(const LLColor4U& a, const LLColor4U& b) inline LLColor4U operator*(const LLColor4U& a, const LLColor4U& b)
{ {
return LLColor4U( return LLColor4U(a.mV[VRED] * b.mV[VRED], a.mV[VGREEN] * b.mV[VGREEN], a.mV[VBLUE] * b.mV[VBLUE], a.mV[VALPHA] * b.mV[VALPHA]);
a.mV[VRED] * b.mV[VRED],
a.mV[VGREEN] * b.mV[VGREEN],
a.mV[VBLUE] * b.mV[VBLUE],
a.mV[VALPHA] * b.mV[VALPHA]);
} }
inline LLColor4U LLColor4U::addClampMax(const LLColor4U& color) inline LLColor4U LLColor4U::addClampMax(const LLColor4U& color)
@ -347,68 +315,17 @@ inline LLColor4U LLColor4U::addClampMax(const LLColor4U &color)
inline LLColor4U LLColor4U::multAll(const F32 k) inline LLColor4U LLColor4U::multAll(const F32 k)
{ {
// Round to nearest // Round to nearest
return LLColor4U( return LLColor4U((U8)ll_round(mV[VRED] * k), (U8)ll_round(mV[VGREEN] * k), (U8)ll_round(mV[VBLUE] * k), (U8)ll_round(mV[VALPHA] * k));
(U8)ll_round(mV[VRED] * k),
(U8)ll_round(mV[VGREEN] * k),
(U8)ll_round(mV[VBLUE] * k),
(U8)ll_round(mV[VALPHA] * k));
} }
/*
inline LLColor4U operator*(const LLColor4U &a, U8 k)
{
// only affects rgb (not a!)
return LLColor4U(
a.mV[VRED] * k,
a.mV[VGREEN] * k,
a.mV[VBLUE] * k,
a.mV[VALPHA]);
}
inline LLColor4U operator*(U8 k, const LLColor4U &a)
{
// only affects rgb (not a!)
return LLColor4U(
a.mV[VRED] * k,
a.mV[VGREEN] * k,
a.mV[VBLUE] * k,
a.mV[VALPHA]);
}
inline LLColor4U operator%(U8 k, const LLColor4U &a)
{
// only affects alpha (not rgb!)
return LLColor4U(
a.mV[VRED],
a.mV[VGREEN],
a.mV[VBLUE],
a.mV[VALPHA] * k );
}
inline LLColor4U operator%(const LLColor4U &a, U8 k)
{
// only affects alpha (not rgb!)
return LLColor4U(
a.mV[VRED],
a.mV[VGREEN],
a.mV[VBLUE],
a.mV[VALPHA] * k );
}
*/
inline bool operator==(const LLColor4U& a, const LLColor4U& b) inline bool operator==(const LLColor4U& a, const LLColor4U& b)
{ {
return ( (a.mV[VRED] == b.mV[VRED]) return ((a.mV[VRED] == b.mV[VRED]) && (a.mV[VGREEN] == b.mV[VGREEN]) && (a.mV[VBLUE] == b.mV[VBLUE]) && (a.mV[VALPHA] == b.mV[VALPHA]));
&&(a.mV[VGREEN] == b.mV[VGREEN])
&&(a.mV[VBLUE] == b.mV[VBLUE])
&&(a.mV[VALPHA] == b.mV[VALPHA]));
} }
inline bool operator!=(const LLColor4U& a, const LLColor4U& b) inline bool operator!=(const LLColor4U& a, const LLColor4U& b)
{ {
return ( (a.mV[VRED] != b.mV[VRED]) return ((a.mV[VRED] != b.mV[VRED]) || (a.mV[VGREEN] != b.mV[VGREEN]) || (a.mV[VBLUE] != b.mV[VBLUE]) || (a.mV[VALPHA] != b.mV[VALPHA]));
||(a.mV[VGREEN] != b.mV[VGREEN])
||(a.mV[VBLUE] != b.mV[VBLUE])
||(a.mV[VALPHA] != b.mV[VALPHA]));
} }
inline const LLColor4U& operator+=(LLColor4U& a, const LLColor4U& b) inline const LLColor4U& operator+=(LLColor4U& a, const LLColor4U& b)
@ -460,13 +377,13 @@ inline F32 distVec_squared(const LLColor4U &a, const LLColor4U &b)
void LLColor4U::setVecScaleClamp(const LLColor4& color) void LLColor4U::setVecScaleClamp(const LLColor4& color)
{ {
F32 color_scale_factor = 255.f; F32 color_scale_factor = 255.f;
F32 max_color = llmax(color.mV[0], color.mV[1], color.mV[2]); F32 max_color = llmax(color.mV[VRED], color.mV[VGREEN], color.mV[VBLUE]);
if (max_color > 1.f) if (max_color > 1.f)
{ {
color_scale_factor /= max_color; color_scale_factor /= max_color;
} }
const S32 MAX_COLOR = 255; constexpr S32 MAX_COLOR = 255;
S32 r = ll_round(color.mV[0] * color_scale_factor); S32 r = ll_round(color.mV[VRED] * color_scale_factor);
if (r > MAX_COLOR) if (r > MAX_COLOR)
{ {
r = MAX_COLOR; r = MAX_COLOR;
@ -475,9 +392,9 @@ void LLColor4U::setVecScaleClamp(const LLColor4& color)
{ {
r = 0; r = 0;
} }
mV[0] = r; mV[VRED] = r;
S32 g = ll_round(color.mV[1] * color_scale_factor); S32 g = ll_round(color.mV[VGREEN] * color_scale_factor);
if (g > MAX_COLOR) if (g > MAX_COLOR)
{ {
g = MAX_COLOR; g = MAX_COLOR;
@ -486,9 +403,9 @@ void LLColor4U::setVecScaleClamp(const LLColor4& color)
{ {
g = 0; g = 0;
} }
mV[1] = g; mV[VGREEN] = g;
S32 b = ll_round(color.mV[2] * color_scale_factor); S32 b = ll_round(color.mV[VBLUE] * color_scale_factor);
if (b > MAX_COLOR) if (b > MAX_COLOR)
{ {
b = MAX_COLOR; b = MAX_COLOR;
@ -497,10 +414,10 @@ void LLColor4U::setVecScaleClamp(const LLColor4& color)
{ {
b = 0; b = 0;
} }
mV[2] = b; mV[VBLUE] = b;
// Alpha shouldn't be scaled, just clamped... // Alpha shouldn't be scaled, just clamped...
S32 a = ll_round(color.mV[3] * MAX_COLOR); S32 a = ll_round(color.mV[VALPHA] * MAX_COLOR);
if (a > MAX_COLOR) if (a > MAX_COLOR)
{ {
a = MAX_COLOR; a = MAX_COLOR;
@ -509,44 +426,42 @@ void LLColor4U::setVecScaleClamp(const LLColor4& color)
{ {
a = 0; a = 0;
} }
mV[3] = a; mV[VALPHA] = a;
} }
void LLColor4U::setVecScaleClamp(const LLColor3& color) void LLColor4U::setVecScaleClamp(const LLColor3& color)
{ {
F32 color_scale_factor = 255.f; F32 color_scale_factor = 255.f;
F32 max_color = llmax(color.mV[0], color.mV[1], color.mV[2]); F32 max_color = llmax(color.mV[VRED], color.mV[VGREEN], color.mV[VBLUE]);
if (max_color > 1.f) if (max_color > 1.f)
{ {
color_scale_factor /= max_color; color_scale_factor /= max_color;
} }
const S32 MAX_COLOR = 255; const S32 MAX_COLOR = 255;
S32 r = ll_round(color.mV[0] * color_scale_factor); S32 r = ll_round(color.mV[VRED] * color_scale_factor);
if (r > MAX_COLOR) if (r > MAX_COLOR)
{ {
r = MAX_COLOR; r = MAX_COLOR;
} }
else else if (r < 0)
if (r < 0)
{ {
r = 0; r = 0;
} }
mV[0] = r; mV[VRED] = r;
S32 g = ll_round(color.mV[1] * color_scale_factor); S32 g = ll_round(color.mV[VGREEN] * color_scale_factor);
if (g > MAX_COLOR) if (g > MAX_COLOR)
{ {
g = MAX_COLOR; g = MAX_COLOR;
} }
else else if (g < 0)
if (g < 0)
{ {
g = 0; g = 0;
} }
mV[1] = g; mV[VGREEN] = g;
S32 b = ll_round(color.mV[2] * color_scale_factor); S32 b = ll_round(color.mV[VBLUE] * color_scale_factor);
if (b > MAX_COLOR) if (b > MAX_COLOR)
{ {
b = MAX_COLOR; b = MAX_COLOR;
@ -555,31 +470,29 @@ void LLColor4U::setVecScaleClamp(const LLColor3& color)
{ {
b = 0; b = 0;
} }
mV[2] = b; mV[VBLUE] = b;
mV[3] = 255; mV[VALPHA] = 255;
} }
inline U32 LLColor4U::asRGBA() const inline U32 LLColor4U::asRGBA() const
{ {
// Little endian: values are swapped in memory. The original code access the array like a U32, so we need to swap here // Little endian: values are swapped in memory. The original code access the array like a U32, so we need to swap here
return (mV[3] << 24) | (mV[2] << 16) | (mV[1] << 8) | mV[0]; return (mV[VALPHA] << 24) | (mV[VBLUE] << 16) | (mV[VGREEN] << 8) | mV[VRED];
} }
inline void LLColor4U::fromRGBA(U32 aVal) inline void LLColor4U::fromRGBA(U32 aVal)
{ {
// Little endian: values are swapped in memory. The original code access the array like a U32, so we need to swap here // Little endian: values are swapped in memory. The original code access the array like a U32, so we need to swap here
mV[ 0 ] = aVal & 0xFF; mV[VRED] = aVal & 0xFF;
aVal >>= 8; aVal >>= 8;
mV[ 1 ] = aVal & 0xFF; mV[VGREEN] = aVal & 0xFF;
aVal >>= 8; aVal >>= 8;
mV[ 2 ] = aVal & 0xFF; mV[VBLUE] = aVal & 0xFF;
aVal >>= 8; aVal >>= 8;
mV[ 3 ] = aVal & 0xFF; mV[VALPHA] = aVal & 0xFF;
} }
#endif #endif

View File

@ -26,7 +26,6 @@
#include "linden_common.h" #include "linden_common.h"
//#include "vmath.h"
#include "v3math.h" #include "v3math.h"
#include "v4math.h" #include "v4math.h"
#include "m4math.h" #include "m4math.h"
@ -64,10 +63,10 @@ bool LLVector4::abs()
{ {
bool ret{ false }; bool ret{ false };
if (mV[0] < 0.f) { mV[0] = -mV[0]; ret = true; } if (mV[VX] < 0.f) { mV[VX] = -mV[VX]; ret = true; }
if (mV[1] < 0.f) { mV[1] = -mV[1]; ret = true; } if (mV[VY] < 0.f) { mV[VY] = -mV[VY]; ret = true; }
if (mV[2] < 0.f) { mV[2] = -mV[2]; ret = true; } if (mV[VZ] < 0.f) { mV[VZ] = -mV[VZ]; ret = true; }
if (mV[3] < 0.f) { mV[3] = -mV[3]; ret = true; } if (mV[VW] < 0.f) { mV[VW] = -mV[VW]; ret = true; }
return ret; return ret;
} }

View File

@ -42,7 +42,7 @@ class LLQuaternion;
// LLVector4 = |x y z w| // LLVector4 = |x y z w|
static const U32 LENGTHOFVECTOR4 = 4; static constexpr U32 LENGTHOFVECTOR4 = 4;
class LLVector4 class LLVector4
{ {
@ -62,19 +62,19 @@ class LLVector4
LLSD getValue() const LLSD getValue() const
{ {
LLSD ret; LLSD ret;
ret[0] = mV[0]; ret[VX] = mV[VX];
ret[1] = mV[1]; ret[VY] = mV[VY];
ret[2] = mV[2]; ret[VZ] = mV[VZ];
ret[3] = mV[3]; ret[VW] = mV[VW];
return ret; return ret;
} }
void setValue(const LLSD& sd) void setValue(const LLSD& sd)
{ {
mV[0] = (F32)sd[0].asReal(); mV[VX] = (F32)sd[VX].asReal();
mV[1] = (F32)sd[1].asReal(); mV[VY] = (F32)sd[VY].asReal();
mV[2] = (F32)sd[2].asReal(); mV[VZ] = (F32)sd[VZ].asReal();
mV[3] = (F32)sd[3].asReal(); mV[VW] = (F32)sd[VW].asReal();
} }
// GLM interop // GLM interop
@ -257,7 +257,7 @@ inline bool LLVector4::isFinite() const
// Clear and Assignment Functions // Clear and Assignment Functions
inline void LLVector4::clear(void) inline void LLVector4::clear()
{ {
mV[VX] = 0.f; mV[VX] = 0.f;
mV[VY] = 0.f; mV[VY] = 0.f;
@ -266,7 +266,7 @@ inline void LLVector4::clear(void)
} }
// deprecated // deprecated
inline void LLVector4::clearVec(void) inline void LLVector4::clearVec()
{ {
mV[VX] = 0.f; mV[VX] = 0.f;
mV[VY] = 0.f; mV[VY] = 0.f;
@ -275,7 +275,7 @@ inline void LLVector4::clearVec(void)
} }
// deprecated // deprecated
inline void LLVector4::zeroVec(void) inline void LLVector4::zeroVec()
{ {
mV[VX] = 0.f; mV[VX] = 0.f;
mV[VY] = 0.f; mV[VY] = 0.f;
@ -386,22 +386,22 @@ inline void LLVector4::setVec(const F32 *vec)
// LLVector4 Magnitude and Normalization Functions // LLVector4 Magnitude and Normalization Functions
inline F32 LLVector4::length(void) const inline F32 LLVector4::length() const
{ {
return (F32) sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]); return sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]);
} }
inline F32 LLVector4::lengthSquared(void) const inline F32 LLVector4::lengthSquared() const
{ {
return mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]; return mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ];
} }
inline F32 LLVector4::magVec(void) const inline F32 LLVector4::magVec() const
{ {
return (F32) sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]); return sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]);
} }
inline F32 LLVector4::magVecSquared(void) const inline F32 LLVector4::magVecSquared() const
{ {
return mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]; return mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ];
} }
@ -538,9 +538,9 @@ inline LLVector4 lerp(const LLVector4 &a, const LLVector4 &b, F32 u)
a.mV[VW] + (b.mV[VW] - a.mV[VW]) * u); a.mV[VW] + (b.mV[VW] - a.mV[VW]) * u);
} }
inline F32 LLVector4::normalize(void) inline F32 LLVector4::normalize()
{ {
F32 mag = (F32) sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]); F32 mag = sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]);
F32 oomag; F32 oomag;
if (mag > FP_MAG_THRESHOLD) if (mag > FP_MAG_THRESHOLD)
@ -552,18 +552,18 @@ inline F32 LLVector4::normalize(void)
} }
else else
{ {
mV[0] = 0.f; mV[VX] = 0.f;
mV[1] = 0.f; mV[VY] = 0.f;
mV[2] = 0.f; mV[VZ] = 0.f;
mag = 0; mag = 0.f;
} }
return (mag); return (mag);
} }
// deprecated // deprecated
inline F32 LLVector4::normVec(void) inline F32 LLVector4::normVec()
{ {
F32 mag = (F32) sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]); F32 mag = sqrt(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]);
F32 oomag; F32 oomag;
if (mag > FP_MAG_THRESHOLD) if (mag > FP_MAG_THRESHOLD)
@ -575,22 +575,23 @@ inline F32 LLVector4::normVec(void)
} }
else else
{ {
mV[0] = 0.f; mV[VX] = 0.f;
mV[1] = 0.f; mV[VY] = 0.f;
mV[2] = 0.f; mV[VZ] = 0.f;
mag = 0; mag = 0.f;
} }
return (mag); return (mag);
} }
// Because apparently some parts of the viewer use this for color info. // Because apparently some parts of the viewer use this for color info.
inline const LLVector4 srgbVector4(const LLVector4 &a) { inline const LLVector4 srgbVector4(const LLVector4& a)
{
LLVector4 srgbColor; LLVector4 srgbColor;
srgbColor.mV[0] = linearTosRGB(a.mV[0]); srgbColor.mV[VX] = linearTosRGB(a.mV[VX]);
srgbColor.mV[1] = linearTosRGB(a.mV[1]); srgbColor.mV[VY] = linearTosRGB(a.mV[VY]);
srgbColor.mV[2] = linearTosRGB(a.mV[2]); srgbColor.mV[VZ] = linearTosRGB(a.mV[VZ]);
srgbColor.mV[3] = a.mV[3]; srgbColor.mV[VW] = a.mV[VW];
return srgbColor; return srgbColor;
} }

View File

@ -115,7 +115,7 @@ public:
void clearChanged(U32 bits) { mChanged &= ~bits; } void clearChanged(U32 bits) { mChanged &= ~bits; }
void setScaleChildOffset(bool scale) { mScaleChildOffset = scale; } void setScaleChildOffset(bool scale) { mScaleChildOffset = scale; }
bool getScaleChildOffset() { return mScaleChildOffset; } bool getScaleChildOffset() const { return mScaleChildOffset; }
LLXform* getParent() const { return mParent; } LLXform* getParent() const { return mParent; }
LLXform* getRoot() const; LLXform* getRoot() const;