updated fighting game sample
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -101,6 +101,7 @@ namespace wiIntersect_BindLua
|
||||
|
||||
Luna<AABB_BindLua>::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<AABB_BindLua>::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<Vector_BindLua>::push(L, new Vector_BindLua(XMLoadFloat3(&aabb.getMin())));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user