delete collision.*
This commit is contained in:
parent
46b98a1802
commit
05b384fd47
@ -9,6 +9,7 @@
|
||||
#include <a8/redis.h>
|
||||
#include <a8/timer.h>
|
||||
#include <a8/uuid.h>
|
||||
#include <a8/collision.h>
|
||||
|
||||
#include "framework/cpp/netmsghandler.h"
|
||||
|
||||
@ -19,7 +20,6 @@
|
||||
#include "roommgr.h"
|
||||
#include "player.h"
|
||||
#include "playermgr.h"
|
||||
#include "collision.h"
|
||||
|
||||
#include "ss_msgid.pb.h"
|
||||
#include "ss_proto.pb.h"
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <a8/collision.h>
|
||||
|
||||
#include "entity.h"
|
||||
#include "collider.h"
|
||||
#include "collision.h"
|
||||
|
||||
bool ColliderComponent::IntersectSegment(a8::Vec2& p0, a8::Vec2& p1)
|
||||
{
|
||||
@ -12,19 +13,19 @@ bool ColliderComponent::IntersectSegment(a8::Vec2& p0, a8::Vec2& p1)
|
||||
case CT_Aabb:
|
||||
{
|
||||
AabbCollider* a_aabb = (AabbCollider*)this;
|
||||
return IntersectSegmentAabb(p0,
|
||||
p1,
|
||||
a_aabb->owner->pos + a_aabb->_min,
|
||||
a_aabb->owner->pos + a_aabb->_max);
|
||||
return a8::IntersectSegmentAabb(p0,
|
||||
p1,
|
||||
a_aabb->owner->pos + a_aabb->_min,
|
||||
a_aabb->owner->pos + a_aabb->_max);
|
||||
}
|
||||
break;
|
||||
case CT_Circle:
|
||||
{
|
||||
CircleCollider* a_circle = (CircleCollider*)this;
|
||||
return IntersectSegmentCircle(p0,
|
||||
p1,
|
||||
a_circle->owner->pos + a_circle->pos,
|
||||
a_circle->rad);
|
||||
return a8::IntersectSegmentCircle(p0,
|
||||
p1,
|
||||
a_circle->owner->pos + a_circle->pos,
|
||||
a_circle->rad);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -45,20 +46,20 @@ bool ColliderComponent::Intersect(ColliderComponent* b)
|
||||
case CT_Aabb:
|
||||
{
|
||||
AabbCollider* b_aabb = (AabbCollider*)b;
|
||||
return IntersectAabbAabb(a_aabb->owner->pos + a_aabb->_min,
|
||||
a_aabb->owner->pos + a_aabb->_max,
|
||||
b_aabb->owner->pos + b_aabb->_min,
|
||||
b_aabb->owner->pos + b_aabb->_max
|
||||
);
|
||||
return a8::IntersectAabbAabb(a_aabb->owner->pos + a_aabb->_min,
|
||||
a_aabb->owner->pos + a_aabb->_max,
|
||||
b_aabb->owner->pos + b_aabb->_min,
|
||||
b_aabb->owner->pos + b_aabb->_max
|
||||
);
|
||||
}
|
||||
break;
|
||||
case CT_Circle:
|
||||
{
|
||||
CircleCollider* b_circle = (CircleCollider*)b;
|
||||
return IntersectAabbCircle(a_aabb->owner->pos + a_aabb->_min,
|
||||
a_aabb->owner->pos + a_aabb->_max,
|
||||
b_circle->owner->pos + b_circle->pos,
|
||||
b_circle->rad);
|
||||
return a8::IntersectAabbCircle(a_aabb->owner->pos + a_aabb->_min,
|
||||
a_aabb->owner->pos + a_aabb->_max,
|
||||
b_circle->owner->pos + b_circle->pos,
|
||||
b_circle->rad);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -73,20 +74,20 @@ bool ColliderComponent::Intersect(ColliderComponent* b)
|
||||
case CT_Aabb:
|
||||
{
|
||||
AabbCollider* b_aabb = (AabbCollider*)b;
|
||||
return IntersectAabbCircle(b_aabb->owner->pos + b_aabb->_min,
|
||||
b_aabb->owner->pos + b_aabb->_max,
|
||||
a_circle->owner->pos + a_circle->pos,
|
||||
a_circle->rad);
|
||||
return a8::IntersectAabbCircle(b_aabb->owner->pos + b_aabb->_min,
|
||||
b_aabb->owner->pos + b_aabb->_max,
|
||||
a_circle->owner->pos + a_circle->pos,
|
||||
a_circle->rad);
|
||||
}
|
||||
break;
|
||||
case CT_Circle:
|
||||
{
|
||||
CircleCollider* b_circle = (CircleCollider*)b;
|
||||
return IntersectCircleCircle(
|
||||
a_circle->owner->pos + a_circle->pos,
|
||||
a_circle->rad,
|
||||
b_circle->owner->pos + b_circle->pos,
|
||||
b_circle->rad);
|
||||
return a8::IntersectCircleCircle(
|
||||
a_circle->owner->pos + a_circle->pos,
|
||||
a_circle->rad,
|
||||
b_circle->owner->pos + b_circle->pos,
|
||||
b_circle->rad);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -108,21 +109,21 @@ bool ColliderComponent::CalcSafePoint(ColliderComponent* b, a8::Vec2& new_pos)
|
||||
case CT_Aabb:
|
||||
{
|
||||
AabbCollider* b_aabb = (AabbCollider*)b;
|
||||
return CalcAabbAabbSafePoint(a_aabb->owner->pos + a_aabb->_min,
|
||||
a_aabb->owner->pos + a_aabb->_max,
|
||||
b_aabb->owner->pos + b_aabb->_min,
|
||||
b_aabb->owner->pos + b_aabb->_max,
|
||||
new_pos);
|
||||
return a8::CalcAabbAabbSafePoint(a_aabb->owner->pos + a_aabb->_min,
|
||||
a_aabb->owner->pos + a_aabb->_max,
|
||||
b_aabb->owner->pos + b_aabb->_min,
|
||||
b_aabb->owner->pos + b_aabb->_max,
|
||||
new_pos);
|
||||
}
|
||||
break;
|
||||
case CT_Circle:
|
||||
{
|
||||
CircleCollider* b_circle = (CircleCollider*)b;
|
||||
return CalcAabbAabbSafePoint(a_aabb->owner->pos + a_aabb->_min,
|
||||
a_aabb->owner->pos + a_aabb->_max,
|
||||
b_circle->owner->pos + b_circle->pos,
|
||||
b_circle->rad,
|
||||
new_pos);
|
||||
return a8::CalcAabbAabbSafePoint(a_aabb->owner->pos + a_aabb->_min,
|
||||
a_aabb->owner->pos + a_aabb->_max,
|
||||
b_circle->owner->pos + b_circle->pos,
|
||||
b_circle->rad,
|
||||
new_pos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -135,23 +136,23 @@ bool ColliderComponent::CalcSafePoint(ColliderComponent* b, a8::Vec2& new_pos)
|
||||
case CT_Aabb:
|
||||
{
|
||||
AabbCollider* b_aabb = (AabbCollider*)b;
|
||||
return CalcCircleAabbSafePoint(
|
||||
a_circle->owner->pos + a_circle->pos,
|
||||
a_circle->rad,
|
||||
b_aabb->owner->pos + b_aabb->_min,
|
||||
b_aabb->owner->pos + b_aabb->_max,
|
||||
new_pos);
|
||||
return a8::CalcCircleAabbSafePoint(
|
||||
a_circle->owner->pos + a_circle->pos,
|
||||
a_circle->rad,
|
||||
b_aabb->owner->pos + b_aabb->_min,
|
||||
b_aabb->owner->pos + b_aabb->_max,
|
||||
new_pos);
|
||||
}
|
||||
break;
|
||||
case CT_Circle:
|
||||
{
|
||||
CircleCollider* b_circle = (CircleCollider*)b;
|
||||
return CalcCircleCircleSafePoint(
|
||||
a_circle->owner->pos + a_circle->pos,
|
||||
a_circle->rad,
|
||||
b_circle->owner->pos + b_circle->pos,
|
||||
b_circle->rad,
|
||||
new_pos);
|
||||
return a8::CalcCircleCircleSafePoint(
|
||||
a_circle->owner->pos + a_circle->pos,
|
||||
a_circle->rad,
|
||||
b_circle->owner->pos + b_circle->pos,
|
||||
b_circle->rad,
|
||||
new_pos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1,210 +0,0 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cfloat>
|
||||
#include <glm/gtx/intersect.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include "collision.h"
|
||||
|
||||
bool IntersectSegmentCircle(a8::Vec2 p0, a8::Vec2 p1, a8::Vec2 pos, float rad)
|
||||
{
|
||||
a8::Vec2 t = p1 - p0;
|
||||
float d = std::max(t.Norm(), 0.0001f);
|
||||
a8::Vec2 n = p0 - pos;
|
||||
float v = n.Dot(t);
|
||||
float z = n.Dot(n) - rad*rad;
|
||||
if (z > 0 && v > 0) {
|
||||
return false;
|
||||
}
|
||||
float u = v*v - z;
|
||||
if (u < 0) {
|
||||
return false;
|
||||
}
|
||||
float i = sqrt(u);
|
||||
float x = -v - i;
|
||||
if (x < 0 && (x = -v + i), x <= d) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IntersectSegmentAabb(a8::Vec2 p0, a8::Vec2 p1, a8::Vec2 _min, a8::Vec2 _max)
|
||||
{
|
||||
a8::Vec2 c = (_min + _max) * 0.5f;
|
||||
a8::Vec2 e = _max - c;
|
||||
a8::Vec2 m = (p0 + p1) * 0.5f;
|
||||
a8::Vec2 d = p1 - m;
|
||||
m = m - c;
|
||||
|
||||
float adx = std::abs(d.x);
|
||||
if (std::abs(m.x) > e.x + adx) {
|
||||
return false;
|
||||
}
|
||||
float ady = std::abs(d.y);
|
||||
if (std::abs(m.y) > e.y + ady) {
|
||||
return false;
|
||||
}
|
||||
if (p0.x > p1.x) {
|
||||
float tmp = p0.x;
|
||||
p0.x = p1.x;
|
||||
p1.x = tmp;
|
||||
}
|
||||
if (p0.y > p1.y) {
|
||||
float tmp = p0.y;
|
||||
p0.y = p1.y;
|
||||
p1.y = tmp;
|
||||
}
|
||||
return IntersectAabbAabb(p0, p1, _min, _max);
|
||||
}
|
||||
|
||||
bool IntersectAabbCircle(a8::Vec2 a_min, a8::Vec2 a_max, a8::Vec2 b_pos, float b_rad)
|
||||
{
|
||||
if (b_pos.x >= a_min.x && b_pos.x <= a_max.x &&
|
||||
b_pos.y >= a_min.y && b_pos.y <= a_max.y) {
|
||||
return true;
|
||||
}
|
||||
a8::Vec2 nearest_point(a8::Clamp(b_pos.x, a_min.x, a_max.x),
|
||||
a8::Clamp(b_pos.y, a_min.y, a_max.y));
|
||||
a8::Vec2 i = b_pos - nearest_point;
|
||||
float n = a8::LengthSqr(i);
|
||||
return n < b_rad*b_rad;
|
||||
}
|
||||
|
||||
bool IntersectAabbAabb(a8::Vec2 a_min, a8::Vec2 a_max, a8::Vec2 b_min, a8::Vec2 b_max)
|
||||
{
|
||||
a8::Vec2 a_v = (a_max - a_min) * 0.5f;
|
||||
a8::Vec2 a_center = a_min + a_v;
|
||||
a8::Vec2 b_v = (b_max - b_min) * 0.5f;
|
||||
a8::Vec2 b_center = b_min + b_v;
|
||||
a8::Vec2 z = b_center - a_center;
|
||||
float u = a_v.x + b_v.x - std::abs(z.x);
|
||||
return u > 0;
|
||||
}
|
||||
|
||||
bool IntersectCircleCircle(a8::Vec2 a_pos, float a_rad, a8::Vec2 b_pos, float b_rad)
|
||||
{
|
||||
float t = a_rad + b_rad;
|
||||
a8::Vec2 d = b_pos - a_pos;
|
||||
float n = a8::LengthSqr(d);
|
||||
return n < t*t;
|
||||
}
|
||||
|
||||
bool CircleContainCircle(a8::Vec2 a_pos, float a_rad, a8::Vec2 b_pos, float b_rad)
|
||||
{
|
||||
float distance = (a_pos - b_pos).Norm();
|
||||
return distance < a_rad - b_rad;
|
||||
}
|
||||
|
||||
bool CalcCircleAabbSafePoint(a8::Vec2 a_pos, float b_rad, a8::Vec2 b_min, a8::Vec2 b_max,
|
||||
a8::Vec2& new_pos)
|
||||
{
|
||||
new_pos = a_pos;
|
||||
bool at_left = std::abs(a_pos.x - b_min.x) < std::abs(a_pos.x - b_max.x);
|
||||
bool at_down = std::abs(a_pos.y - b_min.y) < std::abs(a_pos.y - b_max.y);
|
||||
float x_len = at_left ? std::abs(a_pos.x - b_min.x) : std::abs(a_pos.x - b_max.x);
|
||||
float y_len = at_down ? std::abs(a_pos.y - b_min.y) : std::abs(a_pos.y - b_max.y);
|
||||
if (at_left) {
|
||||
if (x_len < y_len) {
|
||||
//左
|
||||
new_pos.x = b_min.x - b_rad - 1;
|
||||
} else {
|
||||
if (at_down) {
|
||||
new_pos.y = b_min.y - b_rad - 1;
|
||||
} else {
|
||||
new_pos.y = b_max.y + b_rad + 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (x_len < y_len) {
|
||||
//右
|
||||
new_pos.x = b_max.x + b_rad + 1;
|
||||
} else {
|
||||
if (at_down) {
|
||||
new_pos.y = b_min.y - b_rad - 1;
|
||||
} else {
|
||||
new_pos.y = b_max.y + b_rad + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CalcCircleCircleSafePoint(a8::Vec2 a_pos, float a_rad, a8::Vec2 b_pos, float b_rad,
|
||||
a8::Vec2& new_pos)
|
||||
{
|
||||
a8::Vec2 dir = a_pos - b_pos;
|
||||
dir.Normalize();
|
||||
new_pos = b_pos + dir*(a_rad + b_rad) + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CalcAabbAabbSafePoint(a8::Vec2 a_min, a8::Vec2 a_max, a8::Vec2 b_min, a8::Vec2 b_max,
|
||||
a8::Vec2& new_pos)
|
||||
{
|
||||
a8::Vec2 a_pos = a_min + (a_max - a_min)/2.0f;
|
||||
new_pos = a_pos;
|
||||
bool at_left = std::abs(a_pos.x - b_min.x) < std::abs(a_pos.x - b_max.x);
|
||||
bool at_down = std::abs(a_pos.y - b_min.y) < std::abs(a_pos.y - b_max.y);
|
||||
float x_len = at_left ? std::abs(a_pos.x - b_min.x) : std::abs(a_pos.x - b_max.x);
|
||||
float y_len = at_down ? std::abs(a_pos.y - b_min.y) : std::abs(a_pos.y - b_max.y);
|
||||
if (at_left) {
|
||||
if (x_len < y_len) {
|
||||
//左
|
||||
new_pos.x = b_min.x - (a_max.x - a_min.x)/2.0f - 1;
|
||||
} else {
|
||||
if (at_down) {
|
||||
new_pos.y = b_min.y - (a_max.y - a_min.y)/2.0f - 1;
|
||||
} else {
|
||||
new_pos.y = b_max.y + (a_max.y - a_min.y)/2.0f + 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (x_len < y_len) {
|
||||
//右
|
||||
new_pos.x = b_max.x + (a_max.x - a_min.x)/2.0f + 1;
|
||||
} else {
|
||||
if (at_down) {
|
||||
new_pos.y = b_min.y - (a_max.y - a_min.y)/2.0f - 1;
|
||||
} else {
|
||||
new_pos.y = b_max.y + (a_max.y - a_min.y)/2.0f + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CalcAabbCircleSafePoint(a8::Vec2 a_min, a8::Vec2 a_max, a8::Vec2 b_pos, float b_rad,
|
||||
a8::Vec2& new_pos)
|
||||
{
|
||||
a8::Vec2 a_pos = a_min + (a_max - a_min)/2.0f;
|
||||
new_pos = a_pos;
|
||||
bool at_left = std::abs(a_min.x - b_pos.x) < std::abs(a_max.x - b_pos.x);
|
||||
bool at_down = std::abs(a_min.y - b_pos.y) < std::abs(a_max.y - b_pos.y);
|
||||
float x_len = at_left ? std::abs(a_min.x - b_pos.x) : std::abs(a_max.x - b_pos.x);
|
||||
float y_len = at_down ? std::abs(a_min.y - b_pos.y) : std::abs(a_max.y - b_pos.y);
|
||||
if (at_left) {
|
||||
if (x_len < y_len) {
|
||||
//左
|
||||
new_pos.x = b_pos.x - (a_max.x - a_min.x)/2.0f - 1;
|
||||
} else {
|
||||
if (at_down) {
|
||||
new_pos.y = b_pos.y - (a_max.y - a_min.y)/2.0f - 1;
|
||||
} else {
|
||||
new_pos.y = b_pos.y + (a_max.y - a_min.y)/2.0f + 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (x_len < y_len) {
|
||||
//右
|
||||
new_pos.x = b_pos.x + (a_max.x - a_min.x)/2.0f + 1;
|
||||
} else {
|
||||
if (at_down) {
|
||||
new_pos.y = b_pos.y - (a_max.y - a_min.y)/2.0f - 1;
|
||||
} else {
|
||||
new_pos.y = b_pos.y + (a_max.y - a_min.y)/2.0f + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
bool IntersectSegmentCircle(a8::Vec2 p0, a8::Vec2 p1, a8::Vec2 pos, float rad);
|
||||
bool IntersectSegmentAabb(a8::Vec2 p0, a8::Vec2 p1, a8::Vec2 _min, a8::Vec2 _max);
|
||||
bool IntersectAabbCircle(a8::Vec2 a_min, a8::Vec2 a_max, a8::Vec2 b_pos, float b_rad);
|
||||
bool IntersectAabbAabb(a8::Vec2 a_min, a8::Vec2 a_max, a8::Vec2 b_min, a8::Vec2 b_max);
|
||||
bool IntersectCircleCircle(a8::Vec2 a_pos, float a_rad, a8::Vec2 b_pos, float b_rad);
|
||||
bool CircleContainCircle(a8::Vec2 a_pos, float a_rad, a8::Vec2 b_pos, float b_rad);
|
||||
bool CalcCircleAabbSafePoint(a8::Vec2 a_pos, float a_rad, a8::Vec2 b_min, a8::Vec2 b_max,
|
||||
a8::Vec2& new_pos);
|
||||
bool CalcCircleCircleSafePoint(a8::Vec2 a_pos, float a_rad, a8::Vec2 b_pos, float b_rad,
|
||||
a8::Vec2& new_pos);
|
||||
bool CalcAabbAabbSafePoint(a8::Vec2 a_min, a8::Vec2 a_max, a8::Vec2 b_min, a8::Vec2 b_max,
|
||||
a8::Vec2& new_pos);
|
||||
bool CalcAabbCircleSafePoint(a8::Vec2 a_min, a8::Vec2 a_max, a8::Vec2 b_pos, float b_rad,
|
||||
a8::Vec2& new_pos);
|
@ -1,6 +1,7 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <a8/mutable_xobject.h>
|
||||
#include <a8/collision.h>
|
||||
|
||||
#include "human.h"
|
||||
#include "cs_proto.pb.h"
|
||||
@ -9,7 +10,6 @@
|
||||
#include "bullet.h"
|
||||
#include "collider.h"
|
||||
#include "loot.h"
|
||||
#include "collision.h"
|
||||
#include "building.h"
|
||||
#include "hero.h"
|
||||
#include "app.h"
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <a8/mutable_xobject.h>
|
||||
#include <a8/timer.h>
|
||||
#include <a8/udplog.h>
|
||||
#include <a8/collision.h>
|
||||
|
||||
#include "playermgr.h"
|
||||
#include "player.h"
|
||||
@ -17,7 +18,6 @@
|
||||
#include "obstacle.h"
|
||||
#include "building.h"
|
||||
#include "loot.h"
|
||||
#include "collision.h"
|
||||
#include "roommgr.h"
|
||||
#include "app.h"
|
||||
#include "hero.h"
|
||||
@ -955,16 +955,16 @@ void Room::UpdateGas()
|
||||
if (pair.second->dead) {
|
||||
continue;
|
||||
}
|
||||
bool b1 = CircleContainCircle(gas_data.pos_old,
|
||||
gas_data.gas_progress,
|
||||
pair.second->pos,
|
||||
pair.second->GetRadius()
|
||||
);
|
||||
bool b2 = CircleContainCircle(gas_data.pos_new,
|
||||
gas_data.rad_new,
|
||||
pair.second->pos,
|
||||
pair.second->GetRadius()
|
||||
);
|
||||
bool b1 = a8::CircleContainCircle(gas_data.pos_old,
|
||||
gas_data.gas_progress,
|
||||
pair.second->pos,
|
||||
pair.second->GetRadius()
|
||||
);
|
||||
bool b2 = a8::CircleContainCircle(gas_data.pos_new,
|
||||
gas_data.rad_new,
|
||||
pair.second->pos,
|
||||
pair.second->GetRadius()
|
||||
);
|
||||
if (!b1 && !b2) {
|
||||
pair.second->poisoning = true;
|
||||
} else {
|
||||
|
2
third_party/a8engine
vendored
2
third_party/a8engine
vendored
@ -1 +1 @@
|
||||
Subproject commit 7d8aad2b14a8b519e624ab44aed24e0b7e4a0ac7
|
||||
Subproject commit 492cb88b82ab0f2cbc7241ce66a0db7db77aab52
|
Loading…
x
Reference in New Issue
Block a user