diff --git a/Documentation/ScriptingAPI-Documentation.md b/Documentation/ScriptingAPI-Documentation.md index 5b8850bf9..f6d2c6229 100644 --- a/Documentation/ScriptingAPI-Documentation.md +++ b/Documentation/ScriptingAPI-Documentation.md @@ -496,6 +496,7 @@ A ray is defined by an origin Vector and a normalized direction Vector. It can b #### AABB Axis Aligned Bounding Box. Can be intersected with other primitives. - [constructor]AABB(opt Vector min,max) -- if no argument is given, it will be infinitely inverse that can't intersect +- Intersects2D(AABB aabb) : bool result -- omit the z component for intersection check for more precise 2D intersection - Intersects(AABB aabb) : bool result - Intersects(Sphere sphere) : bool result - Intersects(Ray ray) : bool result diff --git a/WickedEngine/wiIntersect.cpp b/WickedEngine/wiIntersect.cpp index 670a08586..82eadb322 100644 --- a/WickedEngine/wiIntersect.cpp +++ b/WickedEngine/wiIntersect.cpp @@ -86,6 +86,24 @@ AABB::INTERSECTION_TYPE AABB::intersects(const AABB& b) const { return INTERSECTS; } +AABB::INTERSECTION_TYPE AABB::intersects2D(const AABB& b) const { + + XMFLOAT3 aMin = getMin(), aMax = getMax(); + XMFLOAT3 bMin = b.getMin(), bMax = b.getMax(); + + if (bMin.x >= aMin.x && bMax.x <= aMax.x && + bMin.y >= aMin.y && bMax.y <= aMax.y) + { + return INSIDE; + } + + if (aMax.x < bMin.x || aMin.x > bMax.x) + return OUTSIDE; + if (aMax.y < bMin.y || aMin.y > bMax.y) + return OUTSIDE; + + return INTERSECTS; +} bool AABB::intersects(const XMFLOAT3& p) const { XMFLOAT3 max = getMax(); XMFLOAT3 min = getMin(); diff --git a/WickedEngine/wiIntersect.h b/WickedEngine/wiIntersect.h index 120559170..4bfefd076 100644 --- a/WickedEngine/wiIntersect.h +++ b/WickedEngine/wiIntersect.h @@ -30,6 +30,7 @@ struct AABB XMMATRIX getAsBoxMatrix() const; float getArea() const; float getRadius() const; + INTERSECTION_TYPE intersects2D(const AABB& b) const; INTERSECTION_TYPE intersects(const AABB& b) const; bool intersects(const XMFLOAT3& p) const; bool intersects(const RAY& ray) const; diff --git a/WickedEngine/wiIntersect_BindLua.cpp b/WickedEngine/wiIntersect_BindLua.cpp index 88edc121b..7ee5d51bd 100644 --- a/WickedEngine/wiIntersect_BindLua.cpp +++ b/WickedEngine/wiIntersect_BindLua.cpp @@ -101,6 +101,7 @@ namespace wiIntersect_BindLua Luna::FunctionType AABB_BindLua::methods[] = { lunamethod(AABB_BindLua, Intersects), + lunamethod(AABB_BindLua, Intersects2D), lunamethod(AABB_BindLua, GetMin), lunamethod(AABB_BindLua, GetMax), lunamethod(AABB_BindLua, GetCenter), @@ -183,6 +184,24 @@ namespace wiIntersect_BindLua wiLua::SError(L, "[Intersects(AABB), Intersects(Sphere), Intersects(Ray)] no matching arguments! "); return 0; } + int AABB_BindLua::Intersects2D(lua_State* L) + { + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + AABB_BindLua* _aabb = Luna::lightcheck(L, 1); + if (_aabb) + { + //int intersects = (int)aabb.intersects(_aabb->aabb); + //wiLua::SSetInt(L, intersects); + wiLua::SSetBool(L, aabb.intersects2D(_aabb->aabb) != AABB::INTERSECTION_TYPE::OUTSIDE); // int intersection type cannot be checked like bool in lua so we give simple bool result here! + return 1; + } + + } + wiLua::SError(L, "Intersects2D(AABB) not enough arguments! "); + return 0; + } int AABB_BindLua::GetMin(lua_State* L) { Luna::push(L, new Vector_BindLua(XMLoadFloat3(&aabb.getMin()))); diff --git a/WickedEngine/wiIntersect_BindLua.h b/WickedEngine/wiIntersect_BindLua.h index 8c63008f7..31eac0445 100644 --- a/WickedEngine/wiIntersect_BindLua.h +++ b/WickedEngine/wiIntersect_BindLua.h @@ -40,6 +40,7 @@ namespace wiIntersect_BindLua ~AABB_BindLua(); int Intersects(lua_State* L); + int Intersects2D(lua_State* L); int GetMin(lua_State* L); int GetMax(lua_State* L); int GetCenter(lua_State* L); diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 8ad290b18..6b09f3e4e 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 26; // minor bug fixes, alterations, refactors, updates - const int revision = 12; + const int revision = 13; long GetVersion() diff --git a/scripts/fighting_game.lua b/scripts/fighting_game.lua index 34a7df6bd..cd522e63b 100644 --- a/scripts/fighting_game.lua +++ b/scripts/fighting_game.lua @@ -898,7 +898,7 @@ local ResolveCharacters = function(player1, player2) player2.hurt = false for i,hitbox in pairs(player1.hitboxes) do for j,hurtbox in pairs(player2.hurtboxes) do - if(hitbox.Intersects(hurtbox)) then + if(hitbox.Intersects2D(hurtbox)) then player1.hitconfirm = true player2.hurt = true break @@ -907,7 +907,7 @@ local ResolveCharacters = function(player1, player2) end for i,hitbox in ipairs(player2.hitboxes) do for j,hurtbox in ipairs(player1.hurtboxes) do - if(hitbox.Intersects(hurtbox)) then + if(hitbox.Intersects2D(hurtbox)) then player2.hitconfirm = true player1.hurt = true break @@ -916,7 +916,7 @@ local ResolveCharacters = function(player1, player2) end -- Clipping: - if(player1.clipbox.Intersects(player2.clipbox)) then + if(player1.clipbox.Intersects2D(player2.clipbox)) then local center1 = player1.clipbox.GetCenter().GetX() local center2 = player2.clipbox.GetCenter().GetX() local extent1 = player1.clipbox.GetHalfExtents().GetX() @@ -1011,6 +1011,9 @@ runProcess(function() help_text = help_text .. "\nUp: action B" help_text = help_text .. "\nLeft: action C" help_text = help_text .. "\nDown: action D" + help_text = help_text .. "\nJ: player2 will always jump" + help_text = help_text .. "\nC: player2 will always crouch" + help_text = help_text .. "\nI: player2 will be idle" help_text = help_text .. "\n\nMovelist:" help_text = help_text .. "\n\t A : Light Punch" help_text = help_text .. "\n\t B : Heavy Punch"