This commit is contained in:
2022-03-23 20:09:35 +08:00
13 changed files with 253 additions and 152 deletions

View File

@@ -31,8 +31,8 @@ namespace hgl
#define NULL 0
#endif//
constexpr u16char U16_FULL_SPACE=U16_TEXT(' '); //全角空格
constexpr u32char U32_FULL_SPACE=U32_TEXT(' '); //全角空格
constexpr u16char U16_FULL_WIDTH_SPACE=U16_TEXT(' '); //全角空格
constexpr u32char U32_FULL_WIDTH_SPACE=U32_TEXT(' '); //全角空格
template<typename T>
inline T *zero_new(const int count)
@@ -134,9 +134,6 @@ namespace hgl
return count;
}
#define DEF_RGB_U8_TO_F(r,g,b) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f}
#define DEF_RGBA_U8_TO_F(r,g,b,a) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f,float(a)/255.0f}
constexpr uint HGL_SIZE_1KB =1024;
constexpr uint HGL_SIZE_1MB =HGL_SIZE_1KB*1024;
constexpr uint HGL_SIZE_1GB =HGL_SIZE_1MB*1024;
@@ -334,15 +331,6 @@ namespace hgl
memcpy(&dst,&src,sizeof(T));
}
/**
* 同类型指针数据复制
*/
template<typename T>
inline void hgl_cpy(T *dst,const T *src)
{
memcpy(dst,src,sizeof(T));
}
/**
* 数据类型转换赋值
*/

View File

@@ -58,6 +58,7 @@ namespace hgl
return String<T>::newOf(fullname,p-fullname);
}
/**
* 组合文件名.<Br>
* 根据离散的每一级目录名称和最终名称合成完整文件名

View File

@@ -77,9 +77,46 @@ namespace hgl
return double(floor(value*per))/per;
}
inline constexpr float half_to_float(const uint16 &h)
inline const float half_to_float(const uint16 &h)
{
return ((h&0x8000)<<16) | (((h&0x7c00)+0x1C000)<<13) | ((h&0x03FF)<<13);
union
{
float f;
uint32 u;
}x;
x.u=(((h&0x8000)<<16) | (((h&0x7c00)+0x1C000)<<13) | ((h&0x03FF)<<13));
return x.f;
}
inline void half_to_float(uint32 *target,const uint16 *source,uint32 count)
{
while (count--)
{
*target = (((*source & 0x8000) << 16) | (((*source & 0x7c00) + 0x1C000) << 13) | ((*source & 0x03FF) << 13));
++target;
++source;
}
}
inline void half_to_uint16(uint16 *target, const uint16 *source, uint32 count)
{
union
{
float f;
uint32 u;
}x;
while (count--)
{
x.u = (((*source & 0x8000) << 16) | (((*source & 0x7c00) + 0x1C000) << 13) | ((*source & 0x03FF) << 13));
*target=x.f*65535;
++target;
++source;
}
}
inline constexpr uint16 float_to_half(const float &f)

View File

@@ -68,14 +68,6 @@ namespace hgl
float znear,
float zfar);
/**
* 产生一个lookat变换矩阵
* @param eye 眼睛位置
* @param target 目标位置
* @param up 向上向量
*/
Matrix4f lookat(const Vector3f &eye,const Vector3f &target,const Vector3f &up);
inline Matrix4f translate(const Vector3f &v)
{
return glm::translate(Matrix4f(1.0f),v);

View File

@@ -94,13 +94,19 @@ namespace hgl
}
template<typename T>
inline T clamp(const T &v,const T &min_v,const T &max_v)
inline T clamp(const T v,const T min_v,const T max_v)
{
if(v<min_v)return min_v;
if(v>max_v)return max_v;
return v;
}
template<typename T>
inline const T clamp(const T in)
{
return clamp<double>(in,0.0f,1.0f);
}
template<typename T>
inline T normalized(const T &v)
{

View File

@@ -2,9 +2,24 @@
#define HGL_COLOR_TABLE_INCLUDE
#include<hgl/platform/Platform.h>
#include<hgl/TypeFunc.h>
#include<hgl/type/Color4f.h>
namespace hgl
{
void GetSpectralColor(double &r,double &g,double &b,const double l); ///<根据光谱值获取对应的RGB值
#define DEF_RGB_U8_TO_F(r,g,b) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f}
#define DEF_RGBA_U8_TO_F(r,g,b,a) {float(r)/255.0f,float(g)/255.0f,float(b)/255.0f,float(a)/255.0f}
inline constexpr uint8 RGB2Lum(const uint8 red,const uint8 green,const uint8 blue)
{
return float(red)*0.299+float(green)*0.587+float(blue)*0.114;
}
inline constexpr float RGB2Lumf(const float red,const float green,const float blue)
{
return red*0.299+green*0.587+blue*0.114;
}
const Color3f GetSpectralColor(const double l); ///<根据光谱值获取对应的RGB值
/**
* 颜色数据定义
@@ -32,10 +47,8 @@ namespace hgl
AppleGreen, ///<苹果绿
Aqua, ///<浅绿色
AquaMarine, ///<碧绿色
ArdenRed, ///<雅顿红(注商业使用需获得Elizabeth Arden公司授权)
Azure, ///<天蓝色
BananaMania, ///<香蕉黄(芯)
BananaYellow, ///<香蕉黄(皮)
Beige, ///<米色
@@ -46,6 +59,7 @@ namespace hgl
BlueViolet, ///<紫罗兰色
Brown, ///<褐色
BurlyWood, ///<实木色
CadetBlue, ///<军兰色
CaribbeanGreen, ///<加勒比海绿
Chartreuse, ///<黄绿色
@@ -56,14 +70,18 @@ namespace hgl
Cornsilk, ///<米绸色
Crimson, ///<暗深红
Cyan, ///<青色
DarkBlue, ///<暗蓝色
DarkCharcoal, ///<炭黑色
DarkCyan, ///<暗青色
DarkGoldenrod, ///<暗金黄
DarkGray, ///<暗灰色
DarkGreen, ///<暗绿色
DarkGrey, ///<暗白色
DarkGunmetal, ///<黑炮铜
DarkKhaki, ///<暗黄褐色
DarkMagenta, ///<暗洋红
DarkMidnightBlue, ///<暗夜蓝
DarkOliveGreen, ///<暗橄榄绿
DarkOrange, ///<暗桔黄
DarkOrchid, ///<暗紫色
@@ -75,11 +93,15 @@ namespace hgl
DarkSlateGrey, ///<暗灰绿
DarkTurquoise, ///<暗宝石绿
DarkViolet, ///<暗紫罗兰
DeepPink, ///<深粉红
DeepSkyBlue, ///<深天蓝
DimGray, ///<暗灰色
DimGrey, ///<暗灰白
DodgerBlue, ///<闪兰色
EerieBlack, ///<怪异黑
FireBrick, ///<火砖色
FloralWhite, ///<花白色
ForestGreen, ///<森林绿
@@ -87,6 +109,7 @@ namespace hgl
FrenchBlue, ///<法国兰
FrenchLilac, ///<法国丁香色
Fuchsia, ///<紫红色
Gainsboro, ///<淡灰色
GhostWhite, ///<幽灵白
Gold, ///<金色
@@ -96,22 +119,27 @@ namespace hgl
Green, ///<绿色
GreenYellow, ///<蓝绿色
Grey, ///<灰白色
HollywoodCerise, ///<好莱坞樱桃红
Honeydew, ///<蜜色
HotPink, ///<火热粉
HunterGreen, ///<猎人绿
IndianGreen, ///<印度绿
IndianRed, ///<印度红
IndianYellow, ///<印度黄
Indigo, ///<靛青色
Ivory, ///<象牙白
Khaki, ///<黄褐色
Lavender, ///<淡紫色
LavenderBlush, ///<淡紫红
LawnGreen, ///<草绿色
Lemon, ///<柠檬色
LemonYellow, ///<柠檬黄
LemonChiffon, ///<柠檬绸
LightBlue, ///<亮蓝色
LightCoral, ///<亮珊瑚色
LightCyan, ///<亮青色
@@ -127,12 +155,16 @@ namespace hgl
LightSlateGrey, ///<亮蓝白
LightSteelBlue, ///<亮钢兰
LightYellow, ///<亮黄色
Lime, ///<酸橙色
LimeGreen, ///<橙绿色
Linen, ///<亚麻色
Lion, ///<獅子棕
Magenta, ///<红紫色
Maroon, ///<粟色
MaastrichtBlue, ///<马斯特里赫特蓝色
MediumAquamarine, ///<间绿色
MediumBlue, ///<间兰色
MediumOrchid, ///<间淡紫
@@ -142,6 +174,7 @@ namespace hgl
MediumSpringGreen, ///<间春绿
MediumTurquoise, ///<间绿宝石
MediumVioletRed, ///<间紫罗兰
MidNightBlue, ///<中灰蓝
Mint, ///<薄荷色
MintCream, ///<薄荷霜
@@ -162,16 +195,15 @@ namespace hgl
NavajoWhite, ///<纳瓦白
Navy, ///<海军色
NiveaBlue, ///<妮维雅蓝(注商业使用需获得Beiersdorf AG授权)
NokiaBlue, ///<诺基亚蓝
OldLace, ///<老花色
Olive, ///<橄榄色
Olivedrab, ///<深绿褐色
Orange, ///<橙色
OrangeRed, ///<红橙色
Orchid, ///<淡紫色
OxfordBlue, ///<牛津蓝
PaleGoldenrod, ///<苍麒麟色
PaleGreen, ///<苍绿色
PaleTurquoise, ///<苍宝石绿
@@ -193,16 +225,15 @@ namespace hgl
PowderBlue, ///<粉蓝色
Purple, ///<紫色
Red, ///<红色
Rose, ///<玫瑰红
RosyBrown, ///<褐玫瑰红
RoyalBlue, ///<皇家蓝
Ruby, ///<宝石红
SaddleBrown, ///<重褐色
Salmon, ///<鲜肉色
SamsungBlue, ///<三星蓝
SandyBrown, ///<沙褐色
SeaGreen, ///<海绿色
SeaShell, ///<海贝色
@@ -216,35 +247,61 @@ namespace hgl
SpringGreen, ///<春绿色
SteelBlue, ///<钢兰色
SUSEBlack, ///<SUSE
SUSEGreen, ///<SUSE绿
SUSEPineGreen, ///<SUSE松绿色
SUSEJungleGreen, ///<SUSE从林绿
SUSEMidnightBlue, ///<SUSE午夜蓝
SUSEWaterholeBlue, ///<SUSE水洞蓝
SUSEMint, ///<SUSE薄荷绿
SUSEPersimmon, ///<SUSE柿子红
SUSEFog, ///<SUSE雾色
Tan, ///<茶色
Teal, ///<水鸭色
Thistle, ///<蓟色
TiffanyBlue, ///<蒂芙尼蓝(知更鸟蛋蓝/勿忘我蓝)(注商业使用需获取Tiffany公司授权)
TiffanyBlue, ///<蒂芙尼蓝(知更鸟蛋蓝/勿忘我蓝)
Tomato, ///<西红柿色
Turquoise, ///<青绿色
UbuntuOrange, ///<Ubuntu橙色
UbuntuLightAubergine,
UbuntuMidAubergine,
UbuntuDarkAubergine,
UbuntuLightAubergine, ///<Ubuntu亮茄皮紫
UbuntuMidAubergine, ///<Ubuntu中茄皮紫
UbuntuDarkAubergine, ///<Ubuntu暗茄皮紫
UbuntuWarmGrey, ///<Ubuntu暖灰色
UbuntuCoolGrey, ///<Ubuntu冷灰色
UbuntuTextGrey, ///<Ubuntu文本灰
CanonicalAubergine, ///<Canonical茄皮紫
Violet, ///<紫罗兰色
Wheat, ///<浅黄色
White, ///<白色
WhiteSmoke, ///<烟白色
Yellow, ///<黄色
YellowGreen, ///<黄绿色
BEGIN_RANGE =AliceBlue,
END_RANGE =YellowGreen,
RANGE_SIZE =(END_RANGE-BEGIN_RANGE)+1
ENUM_CLASS_RANGE(AliceBlue,YellowGreen)
};//enum COLOR_ENUM
extern COLOR_DEF prv_color[size_t(COLOR::RANGE_SIZE)];
inline const Color3f GetColor3f(const enum class COLOR &ce)
{
const COLOR_DEF &c=prv_color[size_t(ce)];
return Color3f(c.r,c.g,c.b);
}
inline const Color4f GetColor4f(const enum class COLOR &ce,const float &alpha)
{
const COLOR_DEF &c=prv_color[size_t(ce)];
return Color4f(c.r,c.g,c.b,alpha);
}
}//namespace hgl
#endif//HGL_COLOR_TABLE_INCLUDE

View File

@@ -1,7 +1,6 @@
#ifndef HGL_COLOR_3_FLOAT_INCLUDE
#define HGL_COLOR_3_FLOAT_INCLUDE
#include<hgl/type/Color.h>
namespace hgl
{
/**
@@ -13,17 +12,23 @@ namespace hgl
public:
float r,g,b; ///<rgb 三原色
union
{
struct
{
float r,g,b; ///<rgb 三原色
};
float rgb[3];
};
public:
Color3f(){r=0,g=0,b=0;} ///<本类构造函数
Color3f(COLOR ce){Use(ce);} ///<本类构造函数
Color3f(float l){r=l,g=l,b=l;Clamp();} ///<本类构造函数
Color3f(float vr,float vg,float vb){r=vr,g=vg,b=vb;Clamp();} ///<本类构造函数
Color3f(const Color3f &v){r=v.r;g=v.g;b=v.b;Clamp();} ///<本类构造函数
void Use(COLOR);
void Zero(){r=0,g=0,b=0;} ///<全清为0
void One() {r=1,g=1,b=1;} ///<全清为1
void Rand(); ///<全随机
@@ -54,7 +59,6 @@ namespace hgl
//操作符重载
void operator = (const float *v){r=*v++;g=*v++;b=*v;}
void operator = (COLOR ce){Use(ce);}
bool operator == (const Color3f &);
bool operator != (const Color3f &);

View File

@@ -2,6 +2,7 @@
#define HGL_COLOR_4_FLOAT_INCLUDE
#include<hgl/type/Color3f.h>
#include<hgl/type/DataType.h>
namespace hgl
{
#define HGL_FLOAT_TO_U32(c1,c2,c3,c4) uint32( \
@@ -24,18 +25,23 @@ namespace hgl
public:
float r,g,b,a; ///<rgba 4原色
union
{
struct
{
float r,g,b,a; ///<rgba 4原色
};
float rgba[4];
};
public:
Color4f(){r=0,g=0,b=0,a=1;} ///<本类构造函数
Color4f(COLOR ce){Use(ce,1);} ///<本类构造函数
Color4f(COLOR ce,float ta){Use(ce,ta);} ///<本类构造函数
Color4f(float v){r=v,g=v,b=v,a=1;Clamp();} ///<本类构造函数
Color4f(float vr,float vg,float vb,float va){r=vr,g=vg,b=vb;a=va;Clamp();} ///<本类构造函数
Color4f(const Color3f &v,float va=1){Set(v,va);} ///<本类构造函数
void Use(COLOR,float);
void Zero(){r=0,g=0,b=0,a=0;} ///<全清为0
void One() {r=1,g=1,b=1,a=1;} ///<全清为1
@@ -65,7 +71,6 @@ namespace hgl
void operator = (const float *v){r=*v++;g=*v++;b=*v++;a=*v;}
void operator = (const Color3f &v){r=v.r;g=v.g;b=v.b;a=1;}
void operator = (const Color4f &v){r=v.r;g=v.g;b=v.b;a=v.a;}
void operator = (COLOR ce){Use(ce,a);}
bool operator == (const Color4f &);
bool operator != (const Color4f &);

View File

@@ -46,7 +46,7 @@ namespace hgl
* 参见https://unicode.org/Public/emoji/12.0/emoji-data.txt
*/
template<typename T>
const bool isemoji(const T ch)
const bool isemoji(const T &ch)
{
if(ch==0x23)return(true); //#
if(ch==0x2A)return(true); //*
@@ -62,7 +62,7 @@ namespace hgl
* 测试当前字符是否为小写字母
*/
template<typename T>
const bool islower(const T ch)
const bool islower(const T &ch)
{
return(ch>='a'&&ch<='z');
}
@@ -71,7 +71,7 @@ namespace hgl
* 测试当前字符是否为大写字母
*/
template<typename T>
const bool isupper(const T ch)
const bool isupper(const T &ch)
{
return(ch>='A'&&ch<='Z');
}
@@ -80,7 +80,7 @@ namespace hgl
* 测试当前字符是否为字母
*/
template<typename T>
const bool isalpha(const T ch)
const bool isalpha(const T &ch)
{
return(islower(ch)||isupper(ch));
}
@@ -89,7 +89,7 @@ namespace hgl
* 测试当前字符是否为10进制数字
*/
template<typename T>
const bool isdigit(const T ch)
const bool isdigit(const T &ch)
{
return(ch>='0'&&ch<='9');
}
@@ -98,7 +98,7 @@ namespace hgl
* 测试当前字符串是否为10进制数字以及小数点、正负符号、指数字符
*/
template<typename T>
const bool isfloat(const T ch)
const bool isfloat(const T &ch)
{
return isdigit(ch)
||ch=='-'
@@ -111,7 +111,7 @@ namespace hgl
}
template<typename T>
const bool isinteger(const T ch)
const bool isinteger(const T &ch)
{
return isdigit(ch)
||ch=='-'
@@ -122,7 +122,7 @@ namespace hgl
* 测试当前字符是否为16进制数用字符(0-9,A-F)
*/
template<typename T>
const bool isxdigit(const T ch)
const bool isxdigit(const T &ch)
{
return((ch>='0'&&ch<='9')
||(ch>='a'&&ch<='f')
@@ -156,7 +156,7 @@ namespace hgl
* 是否为斜杠
*/
template<typename T>
const bool isslash(const T ch)
const bool isslash(const T &ch)
{
if(ch=='\\')return(true);
if(ch=='/')return(true);
@@ -164,14 +164,17 @@ namespace hgl
return(false);
}
template<typename T> inline const bool isspace(const T &);
/**
* 是否为不显示可打印字符(' ','\t','\r','\f','\v','\n')
*/
template<>
inline const bool isspace(const u32char &ch)
{
return(ch==0
||ch==U' ' //半角空格
||ch==U32_FULL_SPACE //全角空格
||ch==U32_FULL_WIDTH_SPACE //全角空格
||ch==U'\a'
||ch==U'\b'
||ch==U'\f'
@@ -184,11 +187,12 @@ namespace hgl
/**
* 是否为不显示可打印字符(' ','\t','\r','\f','\v','\n')
*/
template<>
inline const bool isspace(const u16char &ch)
{
return(ch==0
||ch==U16_TEXT(' ') //半角空格
||ch==U16_FULL_SPACE //全角空格
||ch==U16_FULL_WIDTH_SPACE //全角空格
||ch==U16_TEXT('\a')
||ch==U16_TEXT('\b')
||ch==U16_TEXT('\f')
@@ -201,7 +205,8 @@ namespace hgl
/**
* 是否为不显示可打印字符(' ','\t','\r','\f','\v','\n')
*/
inline const bool isspace(const char ch)
template<>
inline const bool isspace(const char &ch)
{
return(ch==0
||ch==' ' //半角空格
@@ -215,6 +220,7 @@ namespace hgl
}
#ifdef char8_t
template<>
inline const bool isspace(const char8_t ch)
{
return(ch==0
@@ -233,7 +239,7 @@ namespace hgl
* 测试当前字符是否为字母或数字
*/
template<typename T>
const bool isalnum(const T ch)
const bool isalnum(const T &ch)
{
return(isalpha(ch)||isdigit(ch));
}
@@ -242,7 +248,7 @@ namespace hgl
* 测试当前字符是否为代码可用字符(仅字母,数字,下划线,常用于文件名之类)
*/
template<typename T>
const bool iscodechar(const T ch)
const bool iscodechar(const T &ch)
{
return(isalnum(ch)||ch=='_');
}
@@ -251,7 +257,7 @@ namespace hgl
* 测试当前字符是否不是代码可用字符(仅字母,数字,下划线,常用于文件名之类)
*/
template<typename T>
const bool notcodechar(const T ch)
const bool notcodechar(const T &ch)
{
return(!iscodechar(ch));
}
@@ -260,7 +266,7 @@ namespace hgl
* 测试当前字符是否为BASE64编码字符
*/
template<typename T>
const bool isbase64(const T c)
const bool isbase64(const T &c)
{
return (c == 43 || // +
(c >= 47 && c <= 57) || // /-9
@@ -1148,11 +1154,11 @@ namespace hgl
* 截去字符串前端所有的指定字符
* @param src 源字符串指针
* @param len 源字符串长度(同样用于返回结果字符串长度)
* @param trimfunc 截取字符判断函数(默认isspace)
* @param trimfunc 截取字符判断函数(默认isspace<T>)
* @return 新的字符串起始指针
*/
template<typename T>
const T *trimleft(const T *src,int &len,const bool (*trimfunc)(const T)=isspace<T>)
const T *trimleft(const T *src,int &len,const bool (*trimfunc)(const T &)=isspace<T>)
{
const T *p=src;
@@ -1172,11 +1178,11 @@ namespace hgl
* 截去字符串尾端所有的指定字符
* @param src 源字符串指针
* @param len 源字符串长度(同样用于返回结果字符串长度)
* @param trimfunc 截取字符判断函数(默认isspace)
* @param trimfunc 截取字符判断函数(默认isspace<T>)
* @return 新的字符串起始指针
*/
template<typename T>
const T *trimright(const T *src,int &len,const bool (*trimfunc)(const T)=isspace<T>)
const T *trimright(const T *src,int &len,const bool (*trimfunc)(const T &)=isspace<T>)
{
const T *p=src+len-1;
@@ -1196,11 +1202,11 @@ namespace hgl
* 截去字符串前端和尾端的所有指定字符
* @param src 源字符串指针
* @param len 源字符串长度(同样用于返回结果字符串长度)
* @param trimfunc 截取字符判断函数(默认isspace)
* @param trimfunc 截取字符判断函数(默认isspace<T>)
* @return 新的字符串起始指针
*/
template<typename T>
const T *trim(const T *src,int &len,const bool (*trimfunc)(const T)=isspace)
const T *trim(const T *src,int &len,const bool (*trimfunc)(const T &)=isspace<T>)
{
const T *sp=src;
const T *ep=src+len-1;
@@ -1227,11 +1233,11 @@ namespace hgl
* 截取字符串前端的字符串
* @param src 源字符串指针
* @param len 源字符串长度(同样用于返回结果字符串长度)
* @param clipfunc 不可用字符判断函数(默认isspace)
* @param clipfunc 不可用字符判断函数(默认isspace<T>)
* @return 新的字符串起始指针
*/
template<typename T>
const T *clipleft(const T *src,int &len,const bool (*clipfunc)(const T)=isspace)
const T *clipleft(const T *src,int &len,const bool (*clipfunc)(const T &)=isspace<T>)
{
const T *p=src;
@@ -1249,11 +1255,11 @@ namespace hgl
* 截去字符串尾端的字符串
* @param src 源字符串指针
* @param len 源字符串长度(同样用于返回结果字符串长度)
* @param clipfunc 不可用字符判断函数(默认isspace)
* @param clipfunc 不可用字符判断函数(默认isspace<T>)
* @return 新的字符串起始指针
*/
template<typename T>
const T *clipright(const T *src,int &len,const bool (*clipfunc)(const T)=isspace)
const T *clipright(const T *src,int &len,const bool (*clipfunc)(const T &)=isspace<T>)
{
const T *p=src+len-1;

View File

@@ -26,10 +26,8 @@ namespace hgl
DEF_COLOR(AppleGreen, 141,182, 0,"苹果绿")
DEF_COLOR(Aqua, 0,255,255,"浅绿色")
DEF_COLOR(AquaMarine, 127,255,212,"碧绿色")
DEF_COLOR(ArdenRed, 202, 23, 36,"雅顿红") //取自美国官网LOGO图片
DEF_COLOR(Azure, 240,255,255,"天蓝色")
DEF_COLOR(BananaMania, 250,231,181,"香蕉黄(芯)")
DEF_COLOR(BananaYellow, 255,225, 53,"香蕉黄(皮)")
DEF_COLOR(Beige, 245,245,220,"米色")
@@ -40,6 +38,7 @@ namespace hgl
DEF_COLOR(BlueViolet, 138, 43,226,"紫罗兰蓝")
DEF_COLOR(Brown, 165, 42, 42,"褐色")
DEF_COLOR(BurlyWood, 222,184,135,"实木色")
DEF_COLOR(CadetBlue, 95,158,160,"军兰色")
DEF_COLOR(CaribbeanGreen, 0,204,153,"加勒比海绿")
DEF_COLOR(Chartreuse, 127,255, 0,"黄绿色")
@@ -50,14 +49,18 @@ namespace hgl
DEF_COLOR(Cornsilk, 255,248,220,"米绸色")
DEF_COLOR(Crimson, 220, 20, 60,"暗深红")
DEF_COLOR(Cyan, 0,255,255,"青色")
DEF_COLOR(DarkBlue, 0, 0,139,"暗蓝色")
DEF_COLOR(DarkCharcoal, 47, 49, 51,"炭黑色")
DEF_COLOR(DarkCyan, 0,139,139,"暗青色")
DEF_COLOR(DarkGoldenrod, 184,134, 11,"暗金黄")
DEF_COLOR(DarkGray, 169,169,169,"暗灰色")
DEF_COLOR(DarkGreen, 0,100, 0,"暗绿色")
DEF_COLOR(DarkGrey, 169,169,169,"暗白色")
DEF_COLOR(DarkGunmetal, 30, 37, 41,"黑炮铜")
DEF_COLOR(DarkKhaki, 189,183,107,"暗黄褐色")
DEF_COLOR(DarkMagenta, 139, 0,139,"暗洋红")
DEF_COLOR(DarkMidnightBlue, 0, 51,103,"暗夜蓝")
DEF_COLOR(DarkOliveGreen, 85,107, 47,"暗橄榄绿")
DEF_COLOR(DarkOrange, 255,140, 0,"暗桔黄")
DEF_COLOR(DarkOrchid, 153, 50,204,"暗紫色")
@@ -69,11 +72,15 @@ namespace hgl
DEF_COLOR(DarkSlateGrey, 47, 79, 79,"暗灰绿")
DEF_COLOR(DarkTurquoise, 0,206,209,"暗宝石绿")
DEF_COLOR(DarkViolet, 148, 0,211,"暗紫罗兰")
DEF_COLOR(DeepPink, 255, 20,147,"深粉红")
DEF_COLOR(DeepSkyBlue, 0,191,255,"深天蓝")
DEF_COLOR(DimGray, 105,105,105,"暗灰色")
DEF_COLOR(DimGrey, 105,105,105,"暗灰白")
DEF_COLOR(DodgerBlue, 30,144,255,"闪兰色")
DEF_COLOR(EerieBlack, 23, 29, 32,"怪异黑")
DEF_COLOR(FireBrick, 178, 34, 34,"火砖色")
DEF_COLOR(FloralWhite, 255,250,240,"花白色")
DEF_COLOR(ForestGreen, 34,139, 34,"森林绿")
@@ -81,6 +88,7 @@ namespace hgl
DEF_COLOR(FrenchBlue, 0,114,187,"法国兰")
DEF_COLOR(FrenchLilac, 134, 96,142,"法国丁香色")
DEF_COLOR(Fuchsia, 255, 0,255,"紫红色")
DEF_COLOR(Gainsboro, 220,220,220,"淡灰色")
DEF_COLOR(GhostWhite, 248,248,255,"幽灵白")
DEF_COLOR(Gold, 255,215, 0,"金色")
@@ -90,22 +98,27 @@ namespace hgl
DEF_COLOR(Green, 0,128, 0,"绿色")
DEF_COLOR(GreenYellow, 173,255, 47,"蓝绿色")
DEF_COLOR(Grey, 128,128,128,"灰白色")
DEF_COLOR(HollywoodCerise, 244, 0,161,"好莱坞樱桃红")
DEF_COLOR(Honeydew, 240,255,240,"蜜色")
DEF_COLOR(HotPink, 255,105,180,"火热粉")
DEF_COLOR(HunterGreen, 53, 94, 59,"猎人绿")
DEF_COLOR(IndianGreen, 19,136, 8,"印度绿")
DEF_COLOR(IndianRed, 205, 92, 92,"印度红")
DEF_COLOR(IndianYellow, 227,168, 87,"印度黄")
DEF_COLOR(Indigo, 75, 0,130,"靛青色")
DEF_COLOR(Ivory, 255,255,240,"象牙白")
DEF_COLOR(Khaki, 240,230,140,"黄褐色")
DEF_COLOR(Lavender, 230,230,250,"淡紫色")
DEF_COLOR(LavenderBlush, 255,240,245,"淡紫红")
DEF_COLOR(LawnGreen, 124,252, 0,"草绿色")
DEF_COLOR(Lemon, 255,247, 0,"柠檬色")
DEF_COLOR(LemonYellow, 255,244, 79,"柠檬黄")
DEF_COLOR(LemonChiffon, 255,250,205,"柠檬绸")
DEF_COLOR(LightBlue, 173,216,230,"亮蓝色")
DEF_COLOR(LightCoral, 240,128,128,"亮珊瑚色")
DEF_COLOR(LightCyan, 224,255,255,"亮青色")
@@ -121,12 +134,16 @@ namespace hgl
DEF_COLOR(LightSlateGrey, 119,136,153,"亮蓝白")
DEF_COLOR(LightSteelBlue, 176,196,222,"亮钢兰")
DEF_COLOR(LightYellow, 255,255,224,"亮黄色")
DEF_COLOR(Lime, 0,255, 0,"酸橙色")
DEF_COLOR(LimeGreen, 50,205, 50,"橙绿色")
DEF_COLOR(Linen, 250,240,230,"亚麻色")
DEF_COLOR(Lion, 193,154,107,"獅子棕")
DEF_COLOR(Magenta, 255, 0,255,"红紫色")
DEF_COLOR(Maroon, 128, 0, 0,"粟色")
DEF_COLOR(MaastrichtBlue, 0, 26, 56,"马斯特里赫特蓝色")
DEF_COLOR(MediumAquamarine, 102,205,170,"间绿色")
DEF_COLOR(MediumBlue, 0, 0,205,"间兰色")
DEF_COLOR(MediumOrchid, 186, 85,211,"间淡紫")
@@ -136,6 +153,7 @@ namespace hgl
DEF_COLOR(MediumSpringGreen, 0,250,154,"间春绿")
DEF_COLOR(MediumTurquoise, 72,209,204,"间绿宝石")
DEF_COLOR(MediumVioletRed, 199, 21,133,"间紫罗兰")
DEF_COLOR(MidNightBlue, 25, 25,112,"中灰蓝")
DEF_COLOR(Mint, 62,180,137,"薄荷色")
DEF_COLOR(MintCream, 245,255,250,"薄荷霜")
@@ -156,16 +174,18 @@ namespace hgl
DEF_COLOR(NavajoWhite, 255,222,173,"纳瓦白")
DEF_COLOR(Navy, 0, 0,128,"海军色")
DEF_COLOR(NiveaBlue, 0, 19,111,"妮维雅蓝") //取自妮维雅蓝国际官网
DEF_COLOR(NokiaBlue, 18, 65,145,"诺基亚蓝") //取自诺基亚官网
DEF_COLOR(OldLace, 253,245,230,"老花色")
DEF_COLOR(Olive, 128,128, 0,"橄榄色")
DEF_COLOR(Olivedrab, 107,142, 35,"深绿褐色")
DEF_COLOR(Orange, 255,165, 0,"橙色")
DEF_COLOR(OrangeRed, 255, 69, 0,"红橙色")
DEF_COLOR(Orchid, 218,112,214,"淡紫色")
/**
* @see https://en.wikipedia.org/wiki/Oxford_Blue_(colour).
*/
DEF_COLOR(OxfordBlue, 0, 33, 71,"牛津蓝")
DEF_COLOR(PaleGoldenrod, 238,232,170,"苍麒麟色")
DEF_COLOR(PaleGreen, 152,251,152,"苍绿色")
DEF_COLOR(PaleTurquoise, 175,238,238,"苍宝石绿")
@@ -186,16 +206,15 @@ namespace hgl
DEF_COLOR(PowderBlue, 176,224,230,"粉蓝色")
DEF_COLOR(Purple, 128, 0,128,"紫色")
DEF_COLOR(Red, 255, 0, 0,"红色")
DEF_COLOR(Rose, 255, 0,127,"玫瑰红")
DEF_COLOR(RosyBrown, 188,143,143,"褐玫瑰红")
DEF_COLOR(RoyalBlue, 65,105,225,"皇家蓝")
DEF_COLOR(Ruby, 224, 17, 95,"宝石红")
DEF_COLOR(SaddleBrown, 139, 69, 19,"重褐色")
DEF_COLOR(Salmon, 250,128,114,"鲜肉色")
DEF_COLOR(SamsungBlue, 20, 40,160,"三星蓝") //取自三星官网
DEF_COLOR(SandyBrown, 244,164, 96,"沙褐色")
DEF_COLOR(SeaGreen, 46,139, 87,"海绿色")
DEF_COLOR(SeaShell, 255,245,238,"海贝色")
@@ -208,22 +227,53 @@ namespace hgl
DEF_COLOR(Snow, 255,250,250,"雪白色")
DEF_COLOR(SpringGreen, 0,255,127,"春绿色")
DEF_COLOR(SteelBlue, 70,130,180,"钢兰色")
/**
* @see https:brand.suse.com/brand-system/color-palette.
*/
DEF_COLOR(SUSEPineGreen, 12, 50, 44,"SUSE松绿色")
DEF_COLOR(SUSEJungleGreen, 48,186,120,"SUSE从林绿")
DEF_COLOR(SUSEMidnightBlue, 25, 32,114,"SUSE午夜蓝")
DEF_COLOR(SUSEWaterholeBlue, 36, 83,255,"SUSE水洞蓝")
DEF_COLOR(SUSEMint, 144,235,205,"SUSE薄荷绿")
DEF_COLOR(SUSEPersimmon, 254,124, 63,"SUSE柿子红")
DEF_COLOR(SUSEFog, 247,247,247,"SUSE雾色")
DEF_COLOR(Tan, 210,180,140,"茶色")
DEF_COLOR(Teal, 0,128,128,"水鸭色")
DEF_COLOR(Thistle, 216,191,216,"蓟色")
DEF_COLOR(TiffanyBlue, 129,216,208,"蒂芙尼蓝") //取自zh.wikipedia.org/zh-cn/蒂芙尼蓝
/**
* @see zh.wikipedia.org/zh-cn/蒂芙尼蓝
*/
DEF_COLOR(TiffanyBlue, 129,216,208,"蒂芙尼蓝")
DEF_COLOR(Tomato, 255, 99, 71,"西红柿色")
DEF_COLOR(Turquoise, 64,224,208,"青绿色")
/**
* @see https://design.ubuntu.com/brand/colour-palette/.
*/
DEF_COLOR(UbuntuOrange, 233, 84, 32,"Ubuntu橙")
DEF_COLOR(UbuntuLightAubergine, 119, 33,111,"Ubuntu亮茄皮紫")
DEF_COLOR(UbuntuMidAubergine, 94, 39, 80,"Ubuntu中茄皮紫")
DEF_COLOR(UbuntuDarkAubergine, 44, 0, 30,"Ubuntu暗茄皮紫")
DEF_COLOR(UbuntuWarmGrey, 174,167,159,"Ubuntu暖灰色")
DEF_COLOR(UbuntuCoolGrey, 51, 51, 51,"Ubuntu冷灰色")
DEF_COLOR(UbuntuTextGrey, 17, 17, 17,"Ubuntu文本灰")
DEF_COLOR(CanonicalAubergine, 119, 41, 83,"Canonical茄皮紫")
DEF_COLOR(Violet, 238,130,238,"紫罗兰色")
DEF_COLOR(Wheat, 245,222,179,"浅黄色")
DEF_COLOR(White, 255,255,255,"白色")
DEF_COLOR(WhiteSmoke, 245,245,245,"烟白色")
DEF_COLOR(Yellow, 255,255, 0,"黄色")
DEF_COLOR(YellowGreen, 154,205, 50,"黄绿色")
DEF_COLOR(End, 0 ,0 ,0,"")
};
#undef DEF_COLOR
@@ -231,15 +281,14 @@ namespace hgl
/**
* 根据光谱值获取对应的RGB值
* @param l 光谱值(从400到700)
* @return r/g/b 该光谱对应的RGB(0至1)
*/
void GetSpectralColor(double &r,double &g,double &b,const double l)
const Color3f GetSpectralColor(const double l)
{
double t;
r=0.0;
g=0.0;
b=0.0;
double r=0.0;
double g=0.0;
double b=0.0;
if ((l>=400.0)&&(l<410.0)) { t=(l-400.0)/(410.0-400.0); r= +(0.33*t)-(0.20*t*t); }
else if ((l>=410.0)&&(l<475.0)) { t=(l-410.0)/(475.0-410.0); r=0.14 -(0.13*t*t); }
@@ -253,5 +302,7 @@ namespace hgl
if ((l>=400.0)&&(l<475.0)) { t=(l-400.0)/(475.0-400.0); b= +(2.20*t)-(1.50*t*t); }
else if ((l>=475.0)&&(l<560.0)) { t=(l-475.0)/(560.0-475.0); b=0.7 -( t)+(0.30*t*t); }
return Color3f(r,g,b);
}
}//namespace hgl

View File

@@ -1,15 +1,7 @@
#include<hgl/type/Color3f.h>
#include<hgl/type/Color.h>
namespace hgl
{
void Color3f::Use(COLOR ce)
{
const COLOR_DEF *pc=prv_color+size_t(ce);
r=pc->r;
g=pc->g;
b=pc->b;
}
void Color3f::Clamp()
{
if(r<0)r=0;if(r>1)r=1;
@@ -40,7 +32,7 @@ namespace hgl
//--------------------------------------------------------------------------------------------------
void Color3f::Grey(float v1,float v2,float v3)
{
float lum=v1*0.299+v2*0.587+v3*0.114;
float lum=RGB2Lum(v1,v2,v3);
r=lum;
g=lum;
@@ -49,7 +41,7 @@ namespace hgl
//--------------------------------------------------------------------------------------------------
void Color3f::Grey()
{
float lum=r*0.299+g*0.587+b*0.114;
float lum=RGB2Lum(r,g,b);
r=lum;
g=lum;

View File

@@ -1,16 +1,7 @@
#include<hgl/type/Color4f.h>
#include<hgl/type/Color.h>
namespace hgl
{
void Color4f::Use(COLOR ce,float ta)
{
const COLOR_DEF *pc=prv_color+size_t(ce);
r=pc->r;
g=pc->g;
b=pc->b;
a=ta;
}
void Color4f::Clamp()
{
if(r<0)r=0;if(r>1)r=1;
@@ -42,7 +33,7 @@ namespace hgl
//--------------------------------------------------------------------------------------------------
void Color4f::Grey()
{
float lum=r*0.299+g*0.587+b*0.114;
float lum=RGB2Lum(r,g,b);
r=lum;
g=lum;

View File

@@ -102,33 +102,4 @@ namespace hgl
0.0f
);
}
Matrix4f lookat(const Vector3f &eye,const Vector3f &target,const Vector3f &up)
{
Vector3f forward=normalize(target-eye);
Vector3f right=normalize(cross(forward,up));
Vector3f nup=cross(right,forward);
return Matrix4f( right.x,
nup.x,
-forward.x,
0.0f,
right.y,
nup.y,
-forward.y,
0.0f,
right.z,
nup.z,
-forward.z/2.0f,
0.0f,
dot(eye,right ),
dot(eye,nup ),
dot(eye,forward),
1.0f
);
}
}//namespace hgl