diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp
index a7c410d72..541c62f99 100644
--- a/Editor/Editor.cpp
+++ b/Editor/Editor.cpp
@@ -467,10 +467,10 @@ void EditorComponent::Load()
}
});
loader->onFinished([=] {
- main->ActivatePath(this, 0.2f, wiColor::Black);
+ main->ActivatePath(this, 0.2f, wiColor::Black());
weatherWnd->UpdateFromRenderer();
});
- main->ActivatePath(loader, 0.2f, wiColor::Black);
+ main->ActivatePath(loader, 0.2f, wiColor::Black());
ResetHistory();
}
}).detach();
diff --git a/Editor/LightWindow.cpp b/Editor/LightWindow.cpp
index daa32738e..367aa2d25 100644
--- a/Editor/LightWindow.cpp
+++ b/Editor/LightWindow.cpp
@@ -177,7 +177,8 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui)
LightComponent* light = wiRenderer::GetScene().lights.GetComponent(entity);
if (light != nullptr)
{
- light->color = XMFLOAT3(powf(args.color.x, 1.f / 2.2f), powf(args.color.y, 1.f / 2.2f), powf(args.color.z, 1.f / 2.2f));
+ XMFLOAT3 col = args.color.toFloat3();
+ light->color = XMFLOAT3(powf(col.x, 1.f / 2.2f), powf(col.y, 1.f / 2.2f), powf(col.z, 1.f / 2.2f));
}
});
lightWindow->AddWidget(colorPicker);
diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp
index a0e7400f6..c4b03141d 100644
--- a/Editor/MaterialWindow.cpp
+++ b/Editor/MaterialWindow.cpp
@@ -254,7 +254,10 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui)
colorPicker->OnColorChanged([&](wiEventArgs args) {
MaterialComponent* material = wiRenderer::GetScene().materials.GetComponent(entity);
if (material != nullptr)
- material->SetBaseColor(XMFLOAT4(powf(args.color.x, 1.f / 2.2f), powf(args.color.y, 1.f / 2.2f), powf(args.color.z, 1.f / 2.2f), material->GetOpacity()));
+ {
+ XMFLOAT3 col = args.color.toFloat3();
+ material->SetBaseColor(XMFLOAT4(powf(col.x, 1.f / 2.2f), powf(col.y, 1.f / 2.2f), powf(col.z, 1.f / 2.2f), material->GetOpacity()));
+ }
});
materialWindow->AddWidget(colorPicker);
diff --git a/Editor/ObjectWindow.cpp b/Editor/ObjectWindow.cpp
index 7d4239c99..a62cd8cc9 100644
--- a/Editor/ObjectWindow.cpp
+++ b/Editor/ObjectWindow.cpp
@@ -79,7 +79,8 @@ ObjectWindow::ObjectWindow(wiGUI* gui) : GUI(gui)
ObjectComponent* object = wiRenderer::GetScene().objects.GetComponent(entity);
if (object != nullptr)
{
- object->color = XMFLOAT4(powf(args.color.x, 1.f / 2.2f), powf(args.color.y, 1.f / 2.2f), powf(args.color.z, 1.f / 2.2f), object->color.w);
+ XMFLOAT3 col = args.color.toFloat3();
+ object->color = XMFLOAT4(powf(col.x, 1.f / 2.2f), powf(col.y, 1.f / 2.2f), powf(col.z, 1.f / 2.2f), object->color.w);
}
});
objectWindow->AddWidget(colorPicker);
diff --git a/Editor/OceanWindow.cpp b/Editor/OceanWindow.cpp
index cc8ecde51..66b459e79 100644
--- a/Editor/OceanWindow.cpp
+++ b/Editor/OceanWindow.cpp
@@ -157,7 +157,8 @@ OceanWindow::OceanWindow(wiGUI* gui) :GUI(gui)
if (wiRenderer::GetScene().weathers.GetCount() > 0)
{
WeatherComponent& weather = wiRenderer::GetScene().weathers[0];
- weather.oceanParameters.waterColor = XMFLOAT3(powf(args.color.x, 1.f / 2.2f), powf(args.color.y, 1.f / 2.2f), powf(args.color.z, 1.f / 2.2f));
+ XMFLOAT3 col = args.color.toFloat3();
+ weather.oceanParameters.waterColor = XMFLOAT3(powf(col.x, 1.f / 2.2f), powf(col.y, 1.f / 2.2f), powf(col.z, 1.f / 2.2f));
}
});
oceanWindow->AddWidget(colorPicker);
diff --git a/Editor/WeatherWindow.cpp b/Editor/WeatherWindow.cpp
index ebb2e41c7..5b21bea4a 100644
--- a/Editor/WeatherWindow.cpp
+++ b/Editor/WeatherWindow.cpp
@@ -238,7 +238,7 @@ WeatherWindow::WeatherWindow(wiGUI* gui) : GUI(gui)
ambientColorPicker->SetEnabled(true);
ambientColorPicker->OnColorChanged([&](wiEventArgs args) {
auto& weather = GetWeather();
- weather.ambient = XMFLOAT3(args.color.x, args.color.y, args.color.z);
+ weather.ambient = args.color.toFloat3();
});
weatherWindow->AddWidget(ambientColorPicker);
@@ -250,7 +250,7 @@ WeatherWindow::WeatherWindow(wiGUI* gui) : GUI(gui)
horizonColorPicker->SetEnabled(true);
horizonColorPicker->OnColorChanged([&](wiEventArgs args) {
auto& weather = GetWeather();
- weather.horizon = XMFLOAT3(args.color.x, args.color.y, args.color.z);
+ weather.horizon = args.color.toFloat3();
});
weatherWindow->AddWidget(horizonColorPicker);
@@ -263,7 +263,7 @@ WeatherWindow::WeatherWindow(wiGUI* gui) : GUI(gui)
zenithColorPicker->SetEnabled(true);
zenithColorPicker->OnColorChanged([&](wiEventArgs args) {
auto& weather = GetWeather();
- weather.zenith = XMFLOAT3(args.color.x, args.color.y, args.color.z);
+ weather.zenith = args.color.toFloat3();
});
weatherWindow->AddWidget(zenithColorPicker);
diff --git a/Tests/Tests.cpp b/Tests/Tests.cpp
index a731dbf60..8db03f937 100644
--- a/Tests/Tests.cpp
+++ b/Tests/Tests.cpp
@@ -262,7 +262,7 @@ void TestsRenderer::RunFontTest()
font_aligned = font;
font_aligned.props.posY += font.textHeight() * 2;
font_aligned.props.size = 38;
- font_aligned.props.shadowColor = wiColor::Red;
+ font_aligned.props.shadowColor = wiColor::Red();
font_aligned.props.h_align = WIFALIGN_CENTER;
font_aligned.SetText("Center aligned, red shadow, bigger");
addFont(&font_aligned);
@@ -270,7 +270,7 @@ void TestsRenderer::RunFontTest()
static wiFont font_aligned2;
font_aligned2 = font_aligned;
font_aligned2.props.posY += font_aligned.textHeight() + 10;
- font_aligned2.props.shadowColor = wiColor::Purple;
+ font_aligned2.props.shadowColor = wiColor::Purple();
font_aligned2.props.h_align = WIFALIGN_RIGHT;
font_aligned2.SetText("Right aligned, purple shadow");
addFont(&font_aligned2);
@@ -290,7 +290,7 @@ void TestsRenderer::RunFontTest()
font_japanese = font_aligned2;
font_japanese.props.posY += font_aligned2.textHeight();
font_japanese.style = wiFont::AddFontStyle("yumin.ttf");
- font_japanese.props.shadowColor = wiColor::Transparent;
+ font_japanese.props.shadowColor = wiColor::Transparent();
font_japanese.props.h_align = WIFALIGN_CENTER;
font_japanese.props.size = 34;
font_japanese.SetText(ss.str());
diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp
index cd29d239b..941577af9 100644
--- a/WickedEngine/MainComponent.cpp
+++ b/WickedEngine/MainComponent.cpp
@@ -93,13 +93,13 @@ void MainComponent::ActivatePath(RenderPath* component, float fadeSeconds, const
return;
}
- if (activeComponent != nullptr)
+ if (activePath != nullptr)
{
- activeComponent->Stop();
+ activePath->Stop();
}
component->Start();
- activeComponent = component;
+ activePath = component;
});
}
diff --git a/WickedEngine/MainComponent.h b/WickedEngine/MainComponent.h
index bcb338b8a..f18093f79 100644
--- a/WickedEngine/MainComponent.h
+++ b/WickedEngine/MainComponent.h
@@ -10,7 +10,7 @@ class RenderPath;
class MainComponent
{
protected:
- RenderPath* activeComponent = nullptr;
+ RenderPath* activePath = nullptr;
float targetFrameRate = 60;
bool frameskip = true;
bool initialized = false;
@@ -31,7 +31,7 @@ public:
// This will activate a RenderPath as the active one, so it will run its Update, FixedUpdate, Render and Compose functions
// You can set a fade time and fade screen color so that switching components will happen when the screen is faded out. Then it will fade back to the new component
void ActivatePath(RenderPath* component, float fadeSeconds = 0, const wiColor& fadeColor = wiColor(0,0,0,255));
- inline RenderPath* GetActivePath(){ return activeComponent; }
+ inline RenderPath* GetActivePath(){ return activePath; }
// You can use this as a self-contained resource manager if you want to avoid using the wiResourceManager::GetGlobal()
wiResourceManager Content;
diff --git a/WickedEngine/MainComponent_BindLua.cpp b/WickedEngine/MainComponent_BindLua.cpp
index 234cbb0f8..01ed42de9 100644
--- a/WickedEngine/MainComponent_BindLua.cpp
+++ b/WickedEngine/MainComponent_BindLua.cpp
@@ -143,13 +143,13 @@ int MainComponent_BindLua::SetActivePath(lua_State *L)
fadeSeconds = wiLua::SGetFloat(L, 2);
if (argc > 2)
{
- fadeColor.r = wiLua::SGetInt(L, 3);
+ fadeColor.setR((uint8_t)wiLua::SGetInt(L, 3));
if (argc > 3)
{
- fadeColor.g = wiLua::SGetInt(L, 4);
+ fadeColor.setG((uint8_t)wiLua::SGetInt(L, 4));
if (argc > 4)
{
- fadeColor.b = wiLua::SGetInt(L, 5);
+ fadeColor.setB((uint8_t)wiLua::SGetInt(L, 5));
}
}
}
diff --git a/WickedEngine/RenderPath3D.cpp b/WickedEngine/RenderPath3D.cpp
index c07c24f6a..e2edb83f3 100644
--- a/WickedEngine/RenderPath3D.cpp
+++ b/WickedEngine/RenderPath3D.cpp
@@ -567,7 +567,7 @@ void RenderPath3D::RenderComposition(wiRenderTarget& shadedSceneRT, wiRenderTarg
}
else
{
- fx.setMaskMap(wiTextureHelper::getColor(wiColor::Gray));
+ fx.setMaskMap(wiTextureHelper::getColor(wiColor::Gray()));
}
if (getMotionBlurEnabled())
{
diff --git a/WickedEngine/RenderPath3D_PathTracing.cpp b/WickedEngine/RenderPath3D_PathTracing.cpp
index 57319324d..fb43f4b27 100644
--- a/WickedEngine/RenderPath3D_PathTracing.cpp
+++ b/WickedEngine/RenderPath3D_PathTracing.cpp
@@ -171,7 +171,7 @@ void RenderPath3D_PathTracing::Compose()
fx.quality = QUALITY_BILINEAR;
fx.process.setToneMap(true);
fx.setDistortionMap(wiTextureHelper::getBlack()); // tonemap shader uses signed distortion mask, so black = no distortion
- fx.setMaskMap(wiTextureHelper::getColor(wiColor::Gray));
+ fx.setMaskMap(wiTextureHelper::getColor(wiColor::Gray()));
wiImage::Draw(rtAccumulation.GetTexture(), fx, GRAPHICSTHREAD_IMMEDIATE);
diff --git a/WickedEngine/WickedEngine_SHARED.vcxitems b/WickedEngine/WickedEngine_SHARED.vcxitems
index 44c2dbba0..4a1ac25f8 100644
--- a/WickedEngine/WickedEngine_SHARED.vcxitems
+++ b/WickedEngine/WickedEngine_SHARED.vcxitems
@@ -658,7 +658,6 @@
-
diff --git a/WickedEngine/WickedEngine_SHARED.vcxitems.filters b/WickedEngine/WickedEngine_SHARED.vcxitems.filters
index 6ca2953d7..56ba6a706 100644
--- a/WickedEngine/WickedEngine_SHARED.vcxitems.filters
+++ b/WickedEngine/WickedEngine_SHARED.vcxitems.filters
@@ -1760,9 +1760,6 @@
ENGINE\Helpers
-
- ENGINE\Helpers
-
ENGINE\Helpers
diff --git a/WickedEngine/wiColor.cpp b/WickedEngine/wiColor.cpp
deleted file mode 100644
index 9e749d790..000000000
--- a/WickedEngine/wiColor.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-#include "wiColor.h"
-#include "wiMath.h"
-
-wiColor::wiColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a) :r(r), g(g), b(b), a(a)
-{
- rgb = createRGB(r, g, b);
- rgba = createRGBA(r, g, b, a);
- R = r / 255.f;
- G = g / 255.f;
- B = b / 255.f;
- A = a / 255.f;
-}
-
-unsigned long wiColor::createRGB(int r, int g, int b)
-{
- return ((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff);
-}
-unsigned long wiColor::createRGBA(int r, int g, int b, int a)
-{
- return ((r & 0xff) << 24) + ((g & 0xff) << 16) + ((b & 0xff) << 8)
- + (a & 0xff);
-}
-
-wiColor wiColor::fromFloat(float r, float g, float b, float a)
-{
- return wiColor((unsigned char)(r * 255), (unsigned char)(g * 255), (unsigned char)(b * 255), (unsigned char)(a * 255));
-}
-wiColor wiColor::lerp(const wiColor& a, const wiColor& b, float i)
-{
- XMFLOAT4& retF = wiMath::Lerp(XMFLOAT4(a.R, a.G, a.B, a.A), XMFLOAT4(b.R, b.G, b.B, b.A), i);
- return wiColor::fromFloat(retF.x, retF.y, retF.z, retF.w);
-}
-
-
-wiColor wiColor::Red = wiColor(255, 0, 0, 255);
-wiColor wiColor::Green = wiColor(0, 255, 0, 255);
-wiColor wiColor::Blue = wiColor(0, 0, 255, 255);
-wiColor wiColor::Black = wiColor(0, 0, 0, 255);
-wiColor wiColor::White = wiColor(255, 255, 255, 255);
-wiColor wiColor::Yellow = wiColor(255, 255, 0, 255);
-wiColor wiColor::Purple = wiColor(255, 0, 255, 255);
-wiColor wiColor::Cyan = wiColor(0, 255, 255, 255);
-wiColor wiColor::Transparent = wiColor(0, 0, 0, 0);
-wiColor wiColor::Gray = wiColor(127, 127, 127, 255);
-wiColor wiColor::Ghost = wiColor(127, 127, 127, 127);
-wiColor wiColor::Booger = wiColor(127, 127, 127, 200);
-
diff --git a/WickedEngine/wiColor.h b/WickedEngine/wiColor.h
index d6dab2dc6..af9be5b1f 100644
--- a/WickedEngine/wiColor.h
+++ b/WickedEngine/wiColor.h
@@ -1,33 +1,68 @@
#pragma once
+#include "CommonInclude.h"
+#include "wiMath.h"
-class wiColor
+struct wiColor
{
-public:
- wiColor(unsigned char r = 0, unsigned char g = 0, unsigned char b = 0, unsigned char a = 255);
- ~wiColor(){}
+ uint32_t rgba = 0;
- float R, G, B, A;
- unsigned char r, g, b, a;
- unsigned long rgb, rgba;
+ constexpr wiColor(uint32_t rgba) :rgba(rgba) {}
+ constexpr wiColor(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0, uint8_t a = 255) : rgba((r << 0) | (g << 8) | (b << 16) | (a << 24)) {}
- unsigned long createRGB(int r, int g, int b);
- unsigned long createRGBA(int r, int g, int b, int a);
+ constexpr uint8_t getR() const { return (rgba >> 0) & 0xFF; }
+ constexpr uint8_t getG() const { return (rgba >> 8) & 0xFF; }
+ constexpr uint8_t getB() const { return (rgba >> 16) & 0xFF; }
+ constexpr uint8_t getA() const { return (rgba >> 24) & 0xFF; }
- static wiColor fromFloat(float r = 0, float g = 0, float b = 0, float a = 1);
- static wiColor lerp(const wiColor& a, const wiColor& b, float i);
+ constexpr void setR(uint8_t value) { wiColor(value, getG(), getB(), getA()); }
+ constexpr void setG(uint8_t value) { wiColor(getR(), value, getB(), getA()); }
+ constexpr void setB(uint8_t value) { wiColor(getR(), getG(), value, getA()); }
+ constexpr void setA(uint8_t value) { wiColor(getR(), getG(), getB(), value); }
- static wiColor Red;
- static wiColor Green;
- static wiColor Blue;
- static wiColor Black;
- static wiColor White;
- static wiColor Yellow;
- static wiColor Purple;
- static wiColor Cyan;
- static wiColor Transparent;
- static wiColor Gray;
- static wiColor Ghost;
- static wiColor Booger;
+ constexpr XMFLOAT3 toFloat3() const
+ {
+ return XMFLOAT3(
+ ((rgba >> 0) & 0xFF) / 255.0f,
+ ((rgba >> 8) & 0xFF) / 255.0f,
+ ((rgba >> 16) & 0xFF) / 255.0f
+ );
+ }
+ constexpr XMFLOAT4 toFloat4() const
+ {
+ return XMFLOAT4(
+ ((rgba >> 0) & 0xFF) / 255.0f,
+ ((rgba >> 8) & 0xFF) / 255.0f,
+ ((rgba >> 16) & 0xFF) / 255.0f,
+ ((rgba >> 24) & 0xFF) / 255.0f
+ );
+ }
+
+ static constexpr wiColor fromFloat4(const XMFLOAT4& value)
+ {
+ return wiColor((uint8_t)(value.x * 255), (uint8_t)(value.y * 255), (uint8_t)(value.z * 255), (uint8_t)(value.w * 255));
+ }
+ static constexpr wiColor fromFloat3(const XMFLOAT3& value)
+ {
+ return wiColor((uint8_t)(value.x * 255), (uint8_t)(value.y * 255), (uint8_t)(value.z * 255));
+ }
+
+ static constexpr wiColor lerp(const wiColor& a, const wiColor& b, float i)
+ {
+ return fromFloat4(wiMath::Lerp(a.toFloat4(), b.toFloat4(), i));
+ }
+
+ static constexpr wiColor Red() { return wiColor(255, 0, 0, 255); }
+ static constexpr wiColor Green() { return wiColor(0, 255, 0, 255); }
+ static constexpr wiColor Blue() { return wiColor(0, 0, 255, 255); }
+ static constexpr wiColor Black() { return wiColor(0, 0, 0, 255); }
+ static constexpr wiColor White() { return wiColor(255, 255, 255, 255); }
+ static constexpr wiColor Yellow() { return wiColor(255, 255, 0, 255); }
+ static constexpr wiColor Purple() { return wiColor(255, 0, 255, 255); }
+ static constexpr wiColor Cyan() { return wiColor(0, 255, 255, 255); }
+ static constexpr wiColor Transparent() { return wiColor(0, 0, 0, 0); }
+ static constexpr wiColor Gray() { return wiColor(127, 127, 127, 255); }
+ static constexpr wiColor Ghost() { return wiColor(127, 127, 127, 127); }
+ static constexpr wiColor Booger() { return wiColor(127, 127, 127, 200); }
};
diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp
index 0c794b062..c78a41003 100644
--- a/WickedEngine/wiFont.cpp
+++ b/WickedEngine/wiFont.cpp
@@ -538,14 +538,14 @@ void wiFont::Draw(GRAPHICSTHREAD threadID)
FontCB cb;
- if (newProps.shadowColor.a > 0)
+ if (newProps.shadowColor.getA() > 0)
{
// font shadow render:
XMStoreFloat4x4(&cb.g_xFont_Transform, XMMatrixTranspose(
XMMatrixTranslation((float)newProps.posX + 1, (float)newProps.posY + 1, 0)
* device->GetScreenProjection()
));
- cb.g_xFont_Color = float4(newProps.shadowColor.R, newProps.shadowColor.G, newProps.shadowColor.B, newProps.shadowColor.A);
+ cb.g_xFont_Color = newProps.shadowColor.toFloat4();
device->UpdateBuffer(&constantBuffer, &cb, threadID);
device->DrawIndexed(quadCount * 6, 0, 0, threadID);
@@ -556,7 +556,7 @@ void wiFont::Draw(GRAPHICSTHREAD threadID)
XMMatrixTranslation((float)newProps.posX, (float)newProps.posY, 0)
* device->GetScreenProjection()
));
- cb.g_xFont_Color = float4(newProps.color.R, newProps.color.G, newProps.color.B, newProps.color.A);
+ cb.g_xFont_Color = newProps.color.toFloat4();
device->UpdateBuffer(&constantBuffer, &cb, threadID);
device->DrawIndexed(quadCount * 6, 0, 0, threadID);
diff --git a/WickedEngine/wiMath.cpp b/WickedEngine/wiMath.cpp
index c2e438c3d..3f8016600 100644
--- a/WickedEngine/wiMath.cpp
+++ b/WickedEngine/wiMath.cpp
@@ -2,94 +2,6 @@
namespace wiMath
{
- float Length(const XMFLOAT2& v)
- {
- return sqrtf(v.x*v.x + v.y*v.y);
- }
- float Length(const XMFLOAT3& v)
- {
- return sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
- }
- float Distance(const XMFLOAT2& v1, const XMFLOAT2& v2)
- {
- XMVECTOR& vector1 = XMLoadFloat2(&v1);
- XMVECTOR& vector2 = XMLoadFloat2(&v2);
- return XMVectorGetX(XMVector2Length(vector2 - vector1));
- }
- float Distance(const XMFLOAT3& v1, const XMFLOAT3& v2)
- {
- XMVECTOR& vector1 = XMLoadFloat3(&v1);
- XMVECTOR& vector2 = XMLoadFloat3(&v2);
- return Distance(vector1, vector2);
- }
- float DistanceSquared(const XMFLOAT3& v1, const XMFLOAT3& v2)
- {
- XMVECTOR& vector1 = XMLoadFloat3(&v1);
- XMVECTOR& vector2 = XMLoadFloat3(&v2);
- return DistanceSquared(vector1, vector2);
- }
- float DistanceEstimated(const XMFLOAT3& v1, const XMFLOAT3& v2)
- {
- XMVECTOR& vector1 = XMLoadFloat3(&v1);
- XMVECTOR& vector2 = XMLoadFloat3(&v2);
- return DistanceEstimated(vector1, vector2);
- }
- float Distance(const XMVECTOR& v1, const XMVECTOR& v2)
- {
- XMVECTOR& vectorSub = XMVectorSubtract(v1, v2);
- XMVECTOR& length = XMVector3Length(vectorSub);
-
- float Distance = 0.0f;
- XMStoreFloat(&Distance, length);
- return Distance;
- }
- float DistanceSquared(const XMVECTOR& v1, const XMVECTOR& v2)
- {
- XMVECTOR& vectorSub = XMVectorSubtract(v1, v2);
- XMVECTOR& length = XMVector3LengthSq(vectorSub);
-
- float Distance = 0.0f;
- XMStoreFloat(&Distance, length);
- return Distance;
- }
- float DistanceEstimated(const XMVECTOR& v1, const XMVECTOR& v2)
- {
- XMVECTOR& vectorSub = XMVectorSubtract(v1, v2);
- XMVECTOR& length = XMVector3LengthEst(vectorSub);
-
- float Distance = 0.0f;
- XMStoreFloat(&Distance, length);
- return Distance;
- }
- XMFLOAT3 getVectorHalfWayPoint(const XMFLOAT3& a, const XMFLOAT3& b)
- {
- return XMFLOAT3((a.x + b.x)*0.5f, (a.y + b.y)*0.5f, (a.z + b.z)*0.5f);
- }
-
- bool Collision2D(const XMFLOAT2& hitBox1Pos, const XMFLOAT2& hitBox1Siz, const XMFLOAT2& hitBox2Pos, const XMFLOAT2& hitBox2Siz)
- {
- if (hitBox1Pos.x + hitBox1Siz.x < hitBox2Pos.x)
- return false;
- else if (hitBox1Pos.x > hitBox2Pos.x + hitBox2Siz.x)
- return false;
- else if (hitBox1Pos.y + hitBox1Siz.y < hitBox2Pos.y)
- return false;
- else if (hitBox1Pos.y > hitBox2Pos.y + hitBox2Siz.y)
- return false;
-
- return true;
- }
- UINT GetNextPowerOfTwo(UINT x)
- {
- --x;
- x |= x >> 1;
- x |= x >> 2;
- x |= x >> 4;
- x |= x >> 8;
- x |= x >> 16;
- return ++x;
- }
-
float TriangleArea(const XMVECTOR& A, const XMVECTOR& B, const XMVECTOR& C)
{
// Heron's formula:
@@ -111,53 +23,6 @@ namespace wiMath
}
- float InverseLerp(float value1, float value2, float pos)
- {
- return (pos - value1) / (value2 - value1);
- }
- float Lerp(float value1, float value2, float amount)
- {
- return value1 + (value2 - value1) * amount;
- }
- XMFLOAT2 Lerp(const XMFLOAT2& a, const XMFLOAT2& b, float i)
- {
- return XMFLOAT2(Lerp(a.x, b.x, i), Lerp(a.y, b.y, i));
- }
- XMFLOAT3 Lerp(const XMFLOAT3& a, const XMFLOAT3& b, float i)
- {
- return XMFLOAT3(Lerp(a.x, b.x, i), Lerp(a.y, b.y, i), Lerp(a.z, b.z, i));
- }
- XMFLOAT4 Lerp(const XMFLOAT4& a, const XMFLOAT4& b, float i)
- {
- return XMFLOAT4(Lerp(a.x, b.x, i), Lerp(a.y, b.y, i), Lerp(a.z, b.z, i), Lerp(a.w, b.w, i));
- }
- XMFLOAT4 Slerp(const XMFLOAT4& a, const XMFLOAT4& b, float i)
- {
- XMVECTOR _a = XMLoadFloat4(&a);
- XMVECTOR _b = XMLoadFloat4(&b);
- XMVECTOR result = XMQuaternionSlerp(_a, _b, i);
- XMFLOAT4 retVal;
- XMStoreFloat4(&retVal, result);
- return retVal;
- }
- XMFLOAT3 Max(const XMFLOAT3& a, const XMFLOAT3& b){
- return XMFLOAT3(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z));
- }
- XMFLOAT3 Min(const XMFLOAT3& a, const XMFLOAT3& b){
- return XMFLOAT3(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z));
- }
- float Clamp(float val, float min, float max)
- {
- if (val < min) return min;
- else if (val > max) return max;
- return val;
- }
- float SmoothStep(float value1, float value2, float amount)
- {
- amount = Clamp((amount - value1) / (value2 - value1), 0.0f, 1.0f);
- return amount*amount*amount*(amount*(amount * 6 - 15) + 10);
- }
-
XMFLOAT3 getCubicHermiteSplinePos(const XMFLOAT3& startPos, const XMFLOAT3& endPos
, const XMFLOAT3& startTangent, const XMFLOAT3& endTangent
, float atInterval){
diff --git a/WickedEngine/wiMath.h b/WickedEngine/wiMath.h
index a081d6d94..1b5f69e34 100644
--- a/WickedEngine/wiMath.h
+++ b/WickedEngine/wiMath.h
@@ -5,28 +5,138 @@
namespace wiMath
{
- float Length(const XMFLOAT2& v);
- float Length(const XMFLOAT3& v);
- float Distance(const XMFLOAT2& v1, const XMFLOAT2& v2);
- float Distance(const XMFLOAT3& v1,const XMFLOAT3& v2);
- float DistanceSquared(const XMFLOAT3& v1,const XMFLOAT3& v2);
- float DistanceEstimated(const XMFLOAT3& v1, const XMFLOAT3& v2);
- float Distance(const XMVECTOR& v1, const XMVECTOR& v2);
- float DistanceSquared(const XMVECTOR& v1, const XMVECTOR& v2);
- float DistanceEstimated(const XMVECTOR& v1, const XMVECTOR& v2);
- XMFLOAT3 getVectorHalfWayPoint(const XMFLOAT3& a, const XMFLOAT3& b);
- bool Collision2D(const XMFLOAT2& hitBox1Pos, const XMFLOAT2& hitBox1Siz, const XMFLOAT2& hitBox2Pos, const XMFLOAT2& hitBox2Siz);
- float InverseLerp(float value1, float value2, float pos);
- float Lerp(float value1, float value2, float amount);
- XMFLOAT2 Lerp(const XMFLOAT2&,const XMFLOAT2&, float);
- XMFLOAT3 Lerp(const XMFLOAT3&,const XMFLOAT3&, float);
- XMFLOAT4 Lerp(const XMFLOAT4&, const XMFLOAT4&, float);
- XMFLOAT4 Slerp(const XMFLOAT4&,const XMFLOAT4&, float);
- XMFLOAT3 Max(const XMFLOAT3& a, const XMFLOAT3& b);
- XMFLOAT3 Min(const XMFLOAT3& a, const XMFLOAT3& b);
- float Clamp(float val, float min, float max);
- UINT GetNextPowerOfTwo(UINT x);
- float SmoothStep(float value1, float value2, float amount);
+ inline float Length(const XMFLOAT2& v)
+ {
+ return sqrtf(v.x*v.x + v.y*v.y);
+ }
+ inline float Length(const XMFLOAT3& v)
+ {
+ return sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
+ }
+ inline float Distance(const XMVECTOR& v1, const XMVECTOR& v2)
+ {
+ XMVECTOR& vectorSub = XMVectorSubtract(v1, v2);
+ XMVECTOR& length = XMVector3Length(vectorSub);
+
+ float Distance = 0.0f;
+ XMStoreFloat(&Distance, length);
+ return Distance;
+ }
+ inline float DistanceSquared(const XMVECTOR& v1, const XMVECTOR& v2)
+ {
+ XMVECTOR& vectorSub = XMVectorSubtract(v1, v2);
+ XMVECTOR& length = XMVector3LengthSq(vectorSub);
+
+ float Distance = 0.0f;
+ XMStoreFloat(&Distance, length);
+ return Distance;
+ }
+ inline float DistanceEstimated(const XMVECTOR& v1, const XMVECTOR& v2)
+ {
+ XMVECTOR& vectorSub = XMVectorSubtract(v1, v2);
+ XMVECTOR& length = XMVector3LengthEst(vectorSub);
+
+ float Distance = 0.0f;
+ XMStoreFloat(&Distance, length);
+ return Distance;
+ }
+ inline float Distance(const XMFLOAT2& v1, const XMFLOAT2& v2)
+ {
+ XMVECTOR& vector1 = XMLoadFloat2(&v1);
+ XMVECTOR& vector2 = XMLoadFloat2(&v2);
+ return XMVectorGetX(XMVector2Length(vector2 - vector1));
+ }
+ inline float Distance(const XMFLOAT3& v1, const XMFLOAT3& v2)
+ {
+ XMVECTOR& vector1 = XMLoadFloat3(&v1);
+ XMVECTOR& vector2 = XMLoadFloat3(&v2);
+ return Distance(vector1, vector2);
+ }
+ inline float DistanceSquared(const XMFLOAT3& v1, const XMFLOAT3& v2)
+ {
+ XMVECTOR& vector1 = XMLoadFloat3(&v1);
+ XMVECTOR& vector2 = XMLoadFloat3(&v2);
+ return DistanceSquared(vector1, vector2);
+ }
+ inline float DistanceEstimated(const XMFLOAT3& v1, const XMFLOAT3& v2)
+ {
+ XMVECTOR& vector1 = XMLoadFloat3(&v1);
+ XMVECTOR& vector2 = XMLoadFloat3(&v2);
+ return DistanceEstimated(vector1, vector2);
+ }
+ inline constexpr XMFLOAT3 getVectorHalfWayPoint(const XMFLOAT3& a, const XMFLOAT3& b)
+ {
+ return XMFLOAT3((a.x + b.x)*0.5f, (a.y + b.y)*0.5f, (a.z + b.z)*0.5f);
+ }
+ inline constexpr float InverseLerp(float value1, float value2, float pos)
+ {
+ return (pos - value1) / (value2 - value1);
+ }
+ inline constexpr float Lerp(float value1, float value2, float amount)
+ {
+ return value1 + (value2 - value1) * amount;
+ }
+ inline constexpr XMFLOAT2 Lerp(const XMFLOAT2& a, const XMFLOAT2& b, float i)
+ {
+ return XMFLOAT2(Lerp(a.x, b.x, i), Lerp(a.y, b.y, i));
+ }
+ inline constexpr XMFLOAT3 Lerp(const XMFLOAT3& a, const XMFLOAT3& b, float i)
+ {
+ return XMFLOAT3(Lerp(a.x, b.x, i), Lerp(a.y, b.y, i), Lerp(a.z, b.z, i));
+ }
+ inline constexpr XMFLOAT4 Lerp(const XMFLOAT4& a, const XMFLOAT4& b, float i)
+ {
+ return XMFLOAT4(Lerp(a.x, b.x, i), Lerp(a.y, b.y, i), Lerp(a.z, b.z, i), Lerp(a.w, b.w, i));
+ }
+ inline XMFLOAT4 Slerp(const XMFLOAT4& a, const XMFLOAT4& b, float i)
+ {
+ XMVECTOR _a = XMLoadFloat4(&a);
+ XMVECTOR _b = XMLoadFloat4(&b);
+ XMVECTOR result = XMQuaternionSlerp(_a, _b, i);
+ XMFLOAT4 retVal;
+ XMStoreFloat4(&retVal, result);
+ return retVal;
+ }
+ inline constexpr XMFLOAT3 Max(const XMFLOAT3& a, const XMFLOAT3& b) {
+ return XMFLOAT3(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z));
+ }
+ inline constexpr XMFLOAT3 Min(const XMFLOAT3& a, const XMFLOAT3& b) {
+ return XMFLOAT3(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z));
+ }
+ inline constexpr float Clamp(float val, float min, float max)
+ {
+ if (val < min) return min;
+ else if (val > max) return max;
+ return val;
+ }
+ inline constexpr float SmoothStep(float value1, float value2, float amount)
+ {
+ amount = Clamp((amount - value1) / (value2 - value1), 0.0f, 1.0f);
+ return amount * amount*amount*(amount*(amount * 6 - 15) + 10);
+ }
+ inline constexpr bool Collision2D(const XMFLOAT2& hitBox1Pos, const XMFLOAT2& hitBox1Siz, const XMFLOAT2& hitBox2Pos, const XMFLOAT2& hitBox2Siz)
+ {
+ if (hitBox1Pos.x + hitBox1Siz.x < hitBox2Pos.x)
+ return false;
+ else if (hitBox1Pos.x > hitBox2Pos.x + hitBox2Siz.x)
+ return false;
+ else if (hitBox1Pos.y + hitBox1Siz.y < hitBox2Pos.y)
+ return false;
+ else if (hitBox1Pos.y > hitBox2Pos.y + hitBox2Siz.y)
+ return false;
+
+ return true;
+ }
+ inline constexpr uint32_t GetNextPowerOfTwo(uint32_t x)
+ {
+ --x;
+ x |= x >> 1;
+ x |= x >> 2;
+ x |= x >> 4;
+ x |= x >> 8;
+ x |= x >> 16;
+ return ++x;
+ }
// A, B, C: trangle vertices
float TriangleArea(const XMVECTOR& A, const XMVECTOR& B, const XMVECTOR& C);
diff --git a/WickedEngine/wiTextureHelper.cpp b/WickedEngine/wiTextureHelper.cpp
index 8c0fc7017..78c3fcd5a 100644
--- a/WickedEngine/wiTextureHelper.cpp
+++ b/WickedEngine/wiTextureHelper.cpp
@@ -43,22 +43,21 @@ namespace wiTextureHelper
// ColorGradeDefault
{
uint8_t data[256 * 16 * 4];
- for (int slice = 0; slice < 16; ++slice)
+ for (uint8_t slice = 0; slice < 16; ++slice)
{
for (int x = 0; x < 16; ++x)
{
for (int y = 0; y < 16; ++y)
{
- wiColor color;
- color.r = x * 16 + x;
- color.g = y * 16 + y;
- color.b = slice * 16 + slice;
+ uint8_t r = x * 16 + x;
+ uint8_t g = y * 16 + y;
+ uint8_t b = slice * 16 + slice;
int gridPos = (slice * 16 + y * 256 + x) * 4;
- data[gridPos] = color.r;
- data[gridPos + 1] = color.g;
- data[gridPos + 2] = color.b;
- data[gridPos + 3] = color.a;
+ data[gridPos] = r;
+ data[gridPos + 1] = g;
+ data[gridPos + 2] = b;
+ data[gridPos + 3] = 255;
}
}
}
@@ -171,10 +170,10 @@ namespace wiTextureHelper
uint8_t data[dataLength];
for (int i = 0; i < dataLength; i += 4)
{
- data[i] = color.r;
- data[i + 1] = color.g;
- data[i + 2] = color.b;
- data[i + 3] = color.a;
+ data[i] = color.getR();
+ data[i + 1] = color.getG();
+ data[i + 2] = color.getB();
+ data[i + 3] = color.getA();
}
Texture2D* texture = nullptr;
diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp
index 721b6eba9..9ebb534a3 100644
--- a/WickedEngine/wiVersion.cpp
+++ b/WickedEngine/wiVersion.cpp
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates
const int minor = 22;
// minor bug fixes, alterations, refactors, updates
- const int revision = 16;
+ const int revision = 17;
long GetVersion()
diff --git a/WickedEngine/wiWidget.cpp b/WickedEngine/wiWidget.cpp
index d76cb762d..4da66ab33 100644
--- a/WickedEngine/wiWidget.cpp
+++ b/WickedEngine/wiWidget.cpp
@@ -26,10 +26,10 @@ wiWidget::wiWidget() : TransformComponent()
state = IDLE;
enabled = true;
visible = true;
- colors[IDLE] = wiColor::Booger;
- colors[FOCUS] = wiColor::Gray;
- colors[ACTIVE] = wiColor::White;
- colors[DEACTIVATING] = wiColor::Gray;
+ colors[IDLE] = wiColor::Booger();
+ colors[FOCUS] = wiColor::Gray();
+ colors[ACTIVE] = wiColor::White();
+ colors[DEACTIVATING] = wiColor::Gray();
scissorRect.bottom = 0;
scissorRect.left = 0;
scissorRect.right = 0;
@@ -232,7 +232,7 @@ wiColor wiWidget::GetColor()
{
wiColor retVal = colors[GetState()];
if (!IsEnabled()) {
- retVal = wiColor::lerp(wiColor::Transparent, retVal, 0.5f);
+ retVal = wiColor::lerp(wiColor::Transparent(), retVal, 0.5f);
}
return retVal;
}
@@ -949,7 +949,7 @@ void wiCheckBox::Render(wiGUI* gui)
// check
if (GetCheck())
{
- wiImage::Draw(wiTextureHelper::getColor(wiColor::lerp(color, wiColor::White, 0.8f))
+ wiImage::Draw(wiTextureHelper::getColor(wiColor::lerp(color, wiColor::White(), 0.8f))
, wiImageEffects(translation.x + scale.x*0.25f, translation.y + scale.y*0.25f, scale.x*0.5f, scale.y*0.5f)
, gui->GetGraphicsThread());
}
@@ -1534,7 +1534,7 @@ bool wiWindow::IsMinimized()
wiColorPicker::wiColorPicker(wiGUI* gui, const std::string& name) :wiWindow(gui, name)
{
SetSize(XMFLOAT2(300, 260));
- SetColor(wiColor::Ghost);
+ SetColor(wiColor::Ghost());
RemoveWidget(resizeDragger_BottomRight);
RemoveWidget(resizeDragger_UpperLeft);
@@ -1655,7 +1655,7 @@ void wiColorPicker::Update(wiGUI* gui, float dt)
wiEventArgs args;
args.clickPos = pointer;
args.fValue = angle;
- args.color = final_color;
+ args.color = wiColor::fromFloat4(final_color);
onColorChanged(args);
}
}
diff --git a/WickedEngine/wiWidget.h b/WickedEngine/wiWidget.h
index e548d733b..e2eb6985d 100644
--- a/WickedEngine/wiWidget.h
+++ b/WickedEngine/wiWidget.h
@@ -21,7 +21,7 @@ struct wiEventArgs
float fValue;
bool bValue;
int iValue;
- XMFLOAT4 color;
+ wiColor color;
std::string sValue;
};