@@ -173,7 +173,7 @@ void Camera::SetPosition(vec3 pos, bool keep_target) | |||||
if (keep_target) | if (keep_target) | ||||
SetView(pos, GetTarget(), GetUp()); | SetView(pos, GetTarget(), GetUp()); | ||||
else | else | ||||
SetView(GetView() * mat4::translate(pos - m_position)); | |||||
SetView(GetView() * mat4::translate(m_position - pos)); | |||||
m_position = pos; | m_position = pos; | ||||
} | } | ||||
@@ -98,7 +98,8 @@ vec3 Debug::ScreenToWorld(vec3 pos, mat4 view, mat4 proj) | |||||
} | } | ||||
//Draw stuff in World | //Draw stuff in World | ||||
//-- LINE: 3D -2D - 3D_to_2D | |||||
//-- LINE: 3D -2D - 3D_to_2D -------------------------------------------------- | |||||
void Debug::DrawLine(vec3 a, vec3 b) { Debug::DrawLine(a, b, g_scene->GetLineColor()); } | void Debug::DrawLine(vec3 a, vec3 b) { Debug::DrawLine(a, b, g_scene->GetLineColor()); } | ||||
void Debug::DrawLine(vec2 a, vec3 b, float az) { Debug::DrawLine(a, b, g_scene->GetLineColor(), az); } | void Debug::DrawLine(vec2 a, vec3 b, float az) { Debug::DrawLine(a, b, g_scene->GetLineColor(), az); } | ||||
void Debug::DrawLine(vec2 a, vec2 b, float az, float bz) { Debug::DrawLine(a, b, g_scene->GetLineColor(), az, bz); } | void Debug::DrawLine(vec2 a, vec2 b, float az, float bz) { Debug::DrawLine(a, b, g_scene->GetLineColor(), az, bz); } | ||||
@@ -106,7 +107,56 @@ void Debug::DrawLine(vec3 a, vec3 b, vec4 color) { g_scene->A | |||||
void Debug::DrawLine(vec2 a, vec3 b, vec4 color, float az) { g_scene->AddLine(a, b, color, az); } | void Debug::DrawLine(vec2 a, vec3 b, vec4 color, float az) { g_scene->AddLine(a, b, color, az); } | ||||
void Debug::DrawLine(vec2 a, vec2 b, vec4 color, float az, float bz){ g_scene->AddLine(a, b, color, az, bz); } | void Debug::DrawLine(vec2 a, vec2 b, vec4 color, float az, float bz){ g_scene->AddLine(a, b, color, az, bz); } | ||||
//-- ARROW: 3D -2D - 3D_to_2D | |||||
//-- GIZMO -------------------------------------------------------------------- | |||||
void Debug::DrawGizmo(vec3 pos, vec3 x, vec3 y, vec3 z, float size) | |||||
{ | |||||
Debug::DrawLine(pos, pos + x * size, Color::red); | |||||
Debug::DrawLine(pos, pos + y * size, Color::green); | |||||
Debug::DrawLine(pos, pos + z * size, Color::blue); | |||||
} | |||||
void Debug::DrawGizmo(vec2 pos, vec3 x, vec3 y, vec3 z, float size, float posz) | |||||
{ | |||||
Debug::DrawLine(pos, pos + x.xy * size, Color::red, posz, posz + x.z * size); | |||||
Debug::DrawLine(pos, pos + y.xy * size, Color::green, posz, posz + y.z * size); | |||||
Debug::DrawLine(pos, pos + z.xy * size, Color::blue, posz, posz + z.z * size); | |||||
} | |||||
//-- GRID --------------------------------------------------------------------- | |||||
void Debug::DrawGrid(vec3 pos, vec3 x, vec3 y, vec3 z, float size, bool draw_3d) | |||||
{ | |||||
float seg_sz = g_scene->GetLineSegmentSize(); | |||||
int seg_nb = lol::max((int)(size / seg_sz), 1); | |||||
seg_sz = size / (float)seg_nb; | |||||
//Draw Gizmo | |||||
Debug::DrawGizmo(pos, x, y, z, size); | |||||
Debug::DrawLine(pos, pos - x * size, Color::gray); | |||||
Debug::DrawLine(pos, pos - y * size, Color::gray); | |||||
Debug::DrawLine(pos, pos - z * size, Color::gray); | |||||
//grid | |||||
for (float i = -seg_nb; i <= seg_nb; i++) | |||||
{ | |||||
if (i != 0) | |||||
{ | |||||
float iter = seg_sz * ((float)i); | |||||
Debug::DrawLine(vec3(-size, 0, iter), vec3(size, 0, iter), Color::gray_dark); | |||||
Debug::DrawLine(vec3(iter, 0, -size), vec3(iter, 0, size), Color::gray_dark); | |||||
if (draw_3d) | |||||
{ | |||||
Debug::DrawLine(vec3(0, -size, iter), vec3(0, size, iter), Color::gray_dark); | |||||
Debug::DrawLine(vec3(0, iter, -size), vec3(0, iter, size), Color::gray_dark); | |||||
Debug::DrawLine(vec3(-size, iter, 0), vec3(size, iter, 0), Color::gray_dark); | |||||
Debug::DrawLine(vec3(iter, -size, 0), vec3(iter, size, 0), Color::gray_dark); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
//-- ARROW: 3D -2D - 3D_to_2D ------------------------------------------------- | |||||
void Debug::DrawArrow(vec3 a, vec3 b, vec2 s) { Debug::DrawArrow(a, b, vec3(s.x, s.y, s.y)); } | void Debug::DrawArrow(vec3 a, vec3 b, vec2 s) { Debug::DrawArrow(a, b, vec3(s.x, s.y, s.y)); } | ||||
void Debug::DrawArrow(vec2 a, vec3 b, vec2 s, float az) { Debug::DrawArrow(a, b.xy, vec3(s.x, s.y, s.y), az, b.z); } | void Debug::DrawArrow(vec2 a, vec3 b, vec2 s, float az) { Debug::DrawArrow(a, b.xy, vec3(s.x, s.y, s.y), az, b.z); } | ||||
void Debug::DrawArrow(vec2 a, vec2 b, vec2 s, float az, float bz) { Debug::DrawArrow(a, b, vec3(s.x, s.y, s.y), az, bz); } | void Debug::DrawArrow(vec2 a, vec2 b, vec2 s, float az, float bz) { Debug::DrawArrow(a, b, vec3(s.x, s.y, s.y), az, bz); } | ||||
@@ -161,7 +211,7 @@ void Debug::DrawArrow(vec2 a, vec2 b, vec3 s, vec4 color, float az, float bz) | |||||
Debug::DrawLine(b - (z + y).xy, b - (z - y).xy, color, bz - (z + y).z, bz - (z - y).z); | Debug::DrawLine(b - (z + y).xy, b - (z - y).xy, color, bz - (z + y).z, bz - (z - y).z); | ||||
} | } | ||||
//-- BOX: 3D -2D - 3D_to_2D | |||||
//-- BOX: 3D -2D - 3D_to_2D --------------------------------------------------- | |||||
void Debug::DrawBox(box3 a) { Debug::DrawBox(a.A, a.B, g_scene->GetLineColor()); } | void Debug::DrawBox(box3 a) { Debug::DrawBox(a.A, a.B, g_scene->GetLineColor()); } | ||||
void Debug::DrawBox(box2 a) { Debug::DrawBox(a.A, a.B, g_scene->GetLineColor()); } | void Debug::DrawBox(box2 a) { Debug::DrawBox(a.A, a.B, g_scene->GetLineColor()); } | ||||
void Debug::DrawBox(box3 a, vec4 color) { Debug::DrawBox(a.A, a.B, color); } | void Debug::DrawBox(box3 a, vec4 color) { Debug::DrawBox(a.A, a.B, color); } | ||||
@@ -219,7 +269,7 @@ void Debug::DrawBox(vec2 a, float s, mat2 transform, vec4 color) | |||||
Debug::DrawBox(a - b, a + b, transform, color); | Debug::DrawBox(a - b, a + b, transform, color); | ||||
} | } | ||||
//-- CIRCLE | |||||
//-- CIRCLE ------------------------------------------------------------------- | |||||
void Debug::DrawCircle(vec2 a, float s) { Debug::DrawCircle(a, s * vec2(1.f, g_renderer->GetXYRatio()), g_scene->GetLineColor()); } | void Debug::DrawCircle(vec2 a, float s) { Debug::DrawCircle(a, s * vec2(1.f, g_renderer->GetXYRatio()), g_scene->GetLineColor()); } | ||||
void Debug::DrawCircle(vec3 a, vec3 n) { Debug::DrawCircle(a, n, g_scene->GetLineColor()); } | void Debug::DrawCircle(vec3 a, vec3 n) { Debug::DrawCircle(a, n, g_scene->GetLineColor()); } | ||||
void Debug::DrawCircle(vec2 a, vec2 s) { Debug::DrawCircle(a, s * vec2(1.f, g_renderer->GetXYRatio()), g_scene->GetLineColor()); } | void Debug::DrawCircle(vec2 a, vec2 s) { Debug::DrawCircle(a, s * vec2(1.f, g_renderer->GetXYRatio()), g_scene->GetLineColor()); } | ||||
@@ -274,7 +324,7 @@ void Debug::DrawCircle(vec2 a, vec2 x, vec2 y, vec4 color) | |||||
} | } | ||||
} | } | ||||
//-- SPHERE | |||||
//-- SPHERE ------------------------------------------------------------------- | |||||
void Debug::DrawSphere(vec3 a, float s) { Debug::DrawSphere(a, s, g_scene->GetLineColor()); } | void Debug::DrawSphere(vec3 a, float s) { Debug::DrawSphere(a, s, g_scene->GetLineColor()); } | ||||
void Debug::DrawSphere(vec3 a, float s, vec4 color) { Debug::DrawSphere(a, vec3::axis_x * s, vec3::axis_y * s, vec3::axis_z * s, color); } | void Debug::DrawSphere(vec3 a, float s, vec4 color) { Debug::DrawSphere(a, vec3::axis_x * s, vec3::axis_y * s, vec3::axis_z * s, color); } | ||||
void Debug::DrawSphere(vec3 a, vec3 x, vec3 y, vec3 z) { Debug::DrawSphere(a, x, y, z, g_scene->GetLineColor()); } | void Debug::DrawSphere(vec3 a, vec3 x, vec3 y, vec3 z) { Debug::DrawSphere(a, x, y, z, g_scene->GetLineColor()); } | ||||
@@ -291,7 +341,7 @@ void Debug::DrawSphere(vec3 a, vec3 x, vec3 y, vec3 z, vec4 color) | |||||
Debug::DrawCircle(a, y, (z - x) * .707f, color); | Debug::DrawCircle(a, y, (z - x) * .707f, color); | ||||
} | } | ||||
//-- CAPSULE | |||||
//-- CAPSULE ------------------------------------------------------------------ | |||||
void Debug::DrawCapsule(vec3 a, float s, vec3 h) { Debug::DrawCapsule(a, s, h, g_scene->GetLineColor()); } | void Debug::DrawCapsule(vec3 a, float s, vec3 h) { Debug::DrawCapsule(a, s, h, g_scene->GetLineColor()); } | ||||
void Debug::DrawCapsule(vec3 a, vec3 x, vec3 y, vec3 z, vec3 h) { Debug::DrawCapsule(a, x, y, z, h, g_scene->GetLineColor()); } | void Debug::DrawCapsule(vec3 a, vec3 x, vec3 y, vec3 z, vec3 h) { Debug::DrawCapsule(a, x, y, z, h, g_scene->GetLineColor()); } | ||||
void Debug::DrawCapsule(vec3 a, float s, vec3 h, vec4 color) | void Debug::DrawCapsule(vec3 a, float s, vec3 h, vec4 color) | ||||
@@ -327,7 +377,7 @@ void Debug::DrawCapsule(vec3 a, vec3 x, vec3 y, vec3 z, vec3 h, vec4 color) | |||||
} | } | ||||
} | } | ||||
//-- VIEW PROJ | |||||
//-- VIEW PROJ ---------------------------------------------------------------- | |||||
void Debug::DrawViewProj(mat4 view, mat4 proj) { Debug::DrawViewProj(view, proj, g_scene->GetLineColor()); } | void Debug::DrawViewProj(mat4 view, mat4 proj) { Debug::DrawViewProj(view, proj, g_scene->GetLineColor()); } | ||||
void Debug::DrawViewProj(mat4 view_proj) { Debug::DrawViewProj(view_proj, g_scene->GetLineColor()); } | void Debug::DrawViewProj(mat4 view_proj) { Debug::DrawViewProj(view_proj, g_scene->GetLineColor()); } | ||||
void Debug::DrawViewProj(mat4 view, mat4 proj, vec4 color) | void Debug::DrawViewProj(mat4 view, mat4 proj, vec4 color) | ||||
@@ -103,6 +103,8 @@ void EasyMesh::MeshConvert() | |||||
m_submeshes.Push(new SubMesh(shader, vdecl)); | m_submeshes.Push(new SubMesh(shader, vdecl)); | ||||
m_submeshes.Last()->SetIndexBuffer(ibo); | m_submeshes.Last()->SetIndexBuffer(ibo); | ||||
m_submeshes.Last()->SetVertexBuffer(0, vbo); | m_submeshes.Last()->SetVertexBuffer(0, vbo); | ||||
m_state = MeshRender::CanRender; | |||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
@@ -33,12 +33,6 @@ LOL_SAFE_ENUM(CSGUsage, | |||||
Xor | Xor | ||||
); | ); | ||||
LOL_SAFE_ENUM(Axis, | |||||
X, | |||||
Y, | |||||
Z | |||||
); | |||||
LOL_SAFE_ENUM(MeshTransform, | LOL_SAFE_ENUM(MeshTransform, | ||||
Taper, | Taper, | ||||
Twist, | Twist, | ||||
@@ -207,11 +207,12 @@ bool GdiPlusImageCodec::Save(Image *image, char const *path) | |||||
} | } | ||||
u8vec4 *psrc = image->Lock<PixelFormat::RGBA_8>(); | u8vec4 *psrc = image->Lock<PixelFormat::RGBA_8>(); | ||||
u8vec4 *psrc0 = psrc; | |||||
u8vec4 *pdst = static_cast<u8vec4 *>(bdata.Scan0); | u8vec4 *pdst = static_cast<u8vec4 *>(bdata.Scan0); | ||||
for (int y = 0; y < size.y; y++) | for (int y = 0; y < size.y; y++) | ||||
for (int x = 0; x < size.x; x++) | for (int x = 0; x < size.x; x++) | ||||
*pdst++ = (*psrc++).bgra; | *pdst++ = (*psrc++).bgra; | ||||
image->Unlock(pdst); | |||||
image->Unlock(psrc0); | |||||
b->UnlockBits(&bdata); | b->UnlockBits(&bdata); | ||||
if (b->Save(wpath, &clsid, nullptr) != Gdiplus::Ok) | if (b->Save(wpath, &clsid, nullptr) != Gdiplus::Ok) | ||||
@@ -16,14 +16,17 @@ namespace lol | |||||
/* | /* | ||||
* Hardcoded constants for colours | * Hardcoded constants for colours | ||||
*/ | */ | ||||
vec4 const Color::black = vec4(0, 0, 0, 1); | |||||
vec4 const Color::red = vec4(1, 0, 0, 1); | |||||
vec4 const Color::green = vec4(0, 1, 0, 1); | |||||
vec4 const Color::yellow = vec4(1, 1, 0, 1); | |||||
vec4 const Color::blue = vec4(0, 0, 1, 1); | |||||
vec4 const Color::magenta = vec4(1, 0, 1, 1); | |||||
vec4 const Color::cyan = vec4(0, 1, 1, 1); | |||||
vec4 const Color::white = vec4(1, 1, 1, 1); | |||||
vec4 const Color::black = vec4(0, 0, 0, 1); | |||||
vec4 const Color::red = vec4(1, 0, 0, 1); | |||||
vec4 const Color::green = vec4(0, 1, 0, 1); | |||||
vec4 const Color::yellow = vec4(1, 1, 0, 1); | |||||
vec4 const Color::blue = vec4(0, 0, 1, 1); | |||||
vec4 const Color::magenta = vec4(1, 0, 1, 1); | |||||
vec4 const Color::cyan = vec4(0, 1, 1, 1); | |||||
vec4 const Color::white = vec4(1, 1, 1, 1); | |||||
vec4 const Color::gray_dark = vec4(.25f, .25f, .25f, 1); | |||||
vec4 const Color::gray = vec4(.5f, .5f, .5f, 1); | |||||
vec4 const Color::gray_light= vec4(.75f, .75f, .75f, 1); | |||||
/* | /* | ||||
* Conversion from colours to hexadecimal | * Conversion from colours to hexadecimal | ||||
@@ -114,7 +114,11 @@ public: | |||||
protected: | protected: | ||||
void Update() { m_previous = m_current; m_current = IsBound() ? RetrieveCurrentValue() : 0.0f; } | |||||
void Update() | |||||
{ | |||||
m_previous = m_current; | |||||
m_current = IsBound() ? RetrieveCurrentValue() : 0.0f; | |||||
} | |||||
float RetrieveCurrentValue(); | float RetrieveCurrentValue(); | ||||
/** m1 is the InputDevice, m2 is the axis index on the InputDevice, m3 and m4 are an optional key indices to bind one or two keys over the axis */ | /** m1 is the InputDevice, m2 is the axis index on the InputDevice, m3 and m4 are an optional key indices to bind one or two keys over the axis */ | ||||
@@ -16,6 +16,18 @@ | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
template<typename T, typename ARRAY> | |||||
void array_base<T, ARRAY>::Shuffle() | |||||
{ | |||||
auto n = Count(); | |||||
auto ni = n; | |||||
while (n > 0) | |||||
{ | |||||
ni = lol::rand(n--) | 0; | |||||
Swap(ni, n); | |||||
} | |||||
} | |||||
template<typename T, typename ARRAY> | template<typename T, typename ARRAY> | ||||
void array_base<T, ARRAY>::Sort(int sort) | void array_base<T, ARRAY>::Sort(int sort) | ||||
{ | { | ||||
@@ -368,6 +368,7 @@ public: | |||||
m_reserved = toreserve; | m_reserved = toreserve; | ||||
} | } | ||||
void Shuffle(); | |||||
void Sort(int sort); | void Sort(int sort); | ||||
void SortQuickSwap(ptrdiff_t start, ptrdiff_t stop); | void SortQuickSwap(ptrdiff_t start, ptrdiff_t stop); | ||||
@@ -51,6 +51,11 @@ void DrawLine(vec2 a, vec2 b, float az=-1.f, float bz=-1.f); | |||||
void DrawLine(vec3 a, vec3 b, vec4 color); | void DrawLine(vec3 a, vec3 b, vec4 color); | ||||
void DrawLine(vec2 a, vec3 b, vec4 color, float az=-1.f); | void DrawLine(vec2 a, vec3 b, vec4 color, float az=-1.f); | ||||
void DrawLine(vec2 a, vec2 b, vec4 color, float az=-1.f, float bz=-1.f); | void DrawLine(vec2 a, vec2 b, vec4 color, float az=-1.f, float bz=-1.f); | ||||
//-- GIZMO | |||||
void DrawGizmo(vec3 pos, vec3 x, vec3 y, vec3 z, float size); | |||||
void DrawGizmo(vec2 pos, vec3 x, vec3 y, vec3 z, float size, float posz = -1.f); | |||||
//-- GRID | |||||
void DrawGrid(vec3 pos, vec3 x, vec3 y, vec3 z, float size, bool draw_3d=false); | |||||
//-- ARROW | //-- ARROW | ||||
void DrawArrow(vec3 a, vec3 b, vec2 s); | void DrawArrow(vec3 a, vec3 b, vec2 s); | ||||
void DrawArrow(vec2 a, vec3 b, vec2 s, float az=-1.f); | void DrawArrow(vec2 a, vec3 b, vec2 s, float az=-1.f); | ||||
@@ -327,7 +327,7 @@ public: | |||||
/* | /* | ||||
* Some predefined colours | * Some predefined colours | ||||
*/ | */ | ||||
static const vec4 black, red, green, yellow, blue, magenta, cyan, white; | |||||
static const vec4 black, red, green, yellow, blue, magenta, cyan, white, gray_dark, gray, gray_light; | |||||
}; | }; | ||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -26,6 +26,18 @@ | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
struct AxisBase | |||||
{ | |||||
enum Type | |||||
{ | |||||
X = 0, Y, Z, MAX, XY = 2, XYZ = 3, | |||||
}; | |||||
protected: | |||||
static inline char const *GetDescription() { return "X,Y,Z,MAX,XY,XYZ"; } | |||||
static inline char const **GetCustomString() { return nullptr; } | |||||
}; | |||||
typedef SafeEnum<AxisBase> Axis; | |||||
#define LOL_BOX_TYPEDEFS(tname, suffix) \ | #define LOL_BOX_TYPEDEFS(tname, suffix) \ | ||||
template <typename T> struct tname; \ | template <typename T> struct tname; \ | ||||
typedef tname<float> suffix; \ | typedef tname<float> suffix; \ | ||||
@@ -339,8 +339,9 @@ void TickerData::GameThreadTick() | |||||
} | } | ||||
/* Tick objects for the game loop */ | /* Tick objects for the game loop */ | ||||
for (int g = Entity::GAMEGROUP_BEGIN; g < Entity::GAMEGROUP_END; ++g) | |||||
for (int i = 0; i < data->m_list[g].Count(); ++i) | |||||
for (int g = Entity::GAMEGROUP_BEGIN; g < Entity::GAMEGROUP_END && !data->quit /* Stop as soon as required */; ++g) | |||||
{ | |||||
for (int i = 0; i < data->m_list[g].Count() && !data->quit /* Stop as soon as required */; ++i) | |||||
{ | { | ||||
Entity *e = data->m_list[g][i]; | Entity *e = data->m_list[g][i]; | ||||
@@ -361,6 +362,7 @@ void TickerData::GameThreadTick() | |||||
#endif | #endif | ||||
} | } | ||||
} | } | ||||
} | |||||
Profiler::Stop(Profiler::STAT_TICK_GAME); | Profiler::Stop(Profiler::STAT_TICK_GAME); | ||||
} | } | ||||
@@ -370,7 +372,7 @@ void TickerData::DrawThreadTick() | |||||
Profiler::Start(Profiler::STAT_TICK_DRAW); | Profiler::Start(Profiler::STAT_TICK_DRAW); | ||||
/* Tick objects for the draw loop */ | /* Tick objects for the draw loop */ | ||||
for (int g = Entity::DRAWGROUP_BEGIN; g < Entity::DRAWGROUP_END; ++g) | |||||
for (int g = Entity::DRAWGROUP_BEGIN; g < Entity::DRAWGROUP_END && !data->quit /* Stop as soon as required */; ++g) | |||||
{ | { | ||||
switch (g) | switch (g) | ||||
{ | { | ||||
@@ -382,7 +384,8 @@ void TickerData::DrawThreadTick() | |||||
break; | break; | ||||
} | } | ||||
for (int i = 0; i < data->m_list[g].Count(); ++i) | |||||
//Stop as soon as required | |||||
for (int i = 0; i < data->m_list[g].Count() && !data->quit /* Stop as soon as required */; ++i) | |||||
{ | { | ||||
Entity *e = data->m_list[g][i]; | Entity *e = data->m_list[g][i]; | ||||
@@ -21,10 +21,6 @@ namespace lol | |||||
WorldEntity::WorldEntity() | WorldEntity::WorldEntity() | ||||
{ | { | ||||
m_position = vec3::zero; | |||||
m_rotation = quat(1); | |||||
m_velocity = vec3::zero; | |||||
m_rotation_velocity = vec3::zero; | |||||
m_bbox[0] = m_bbox[1] = vec3::zero; | m_bbox[0] = m_bbox[1] = vec3::zero; | ||||
} | } | ||||
@@ -28,10 +28,10 @@ public: | |||||
virtual char const *GetName(); | virtual char const *GetName(); | ||||
public: | public: | ||||
vec3 m_position; | |||||
vec3 m_velocity; | |||||
quat m_rotation; | |||||
vec3 m_rotation_velocity; | |||||
vec3 m_position = vec3::zero; | |||||
vec3 m_velocity = vec3::zero; | |||||
quat m_rotation = quat(1); | |||||
vec3 m_rotation_velocity = vec3::zero; | |||||
vec3 m_bbox[2]; | vec3 m_bbox[2]; | ||||
protected: | protected: | ||||