1
This commit is contained in:
parent
34d91a7942
commit
66410aefce
@ -5,18 +5,6 @@
|
|||||||
#include <glm/gtx/intersect.hpp>
|
#include <glm/gtx/intersect.hpp>
|
||||||
#include <glm/vec3.hpp>
|
#include <glm/vec3.hpp>
|
||||||
|
|
||||||
void TestGlm()
|
|
||||||
{
|
|
||||||
glm::vec3 orig(0.0, 0.0, 0.0);
|
|
||||||
glm::vec3 dir(1.0, 1.0, 0);
|
|
||||||
glm::vec3 v0(0.0, 1.0, 0);
|
|
||||||
glm::vec3 v1(1.3, 1.0, 0);
|
|
||||||
glm::vec3 v2(0.0, 2.0, 0);
|
|
||||||
glm::vec3 baryPosition;
|
|
||||||
bool ret = glm::intersectRayTriangle(orig, dir, v0, v1, v2, baryPosition);
|
|
||||||
int i = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IntersectSegmentCircle(Vector2D p0, Vector2D p1, Vector2D pos, float rad)
|
bool IntersectSegmentCircle(Vector2D p0, Vector2D p1, Vector2D pos, float rad)
|
||||||
{
|
{
|
||||||
Vector2D t = p1 - p0;
|
Vector2D t = p1 - p0;
|
||||||
|
@ -14,4 +14,3 @@ bool CalcAabbAabbSafePoint(Vector2D a_min, Vector2D a_max, Vector2D b_min, Vecto
|
|||||||
Vector2D& new_pos);
|
Vector2D& new_pos);
|
||||||
bool CalcAabbCircleSafePoint(Vector2D a_min, Vector2D a_max, Vector2D b_pos, float b_rad,
|
bool CalcAabbCircleSafePoint(Vector2D a_min, Vector2D a_max, Vector2D b_pos, float b_rad,
|
||||||
Vector2D& new_pos);
|
Vector2D& new_pos);
|
||||||
void TestGlm();
|
|
||||||
|
@ -5,13 +5,75 @@
|
|||||||
#include "human.h"
|
#include "human.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
|
#include "collider.h"
|
||||||
|
#include "collision.h"
|
||||||
|
|
||||||
void MovementComponent::RayDetection()
|
void MovementComponent::RayDetection()
|
||||||
{
|
{
|
||||||
|
Clear();
|
||||||
if (owner->entity_type == ET_Bullet) {
|
if (owner->entity_type == ET_Bullet) {
|
||||||
Bullet* bullet = (Bullet*)owner;
|
Bullet* bullet = (Bullet*)owner;
|
||||||
} else if (owner->entity_type == ET_Player) {
|
} else if (owner->entity_type == ET_Player) {
|
||||||
Human* hum = (Human*)owner;
|
Human* hum = (Human*)owner;
|
||||||
|
start_point = hum->pos;
|
||||||
|
{
|
||||||
|
Vector2D left_dir = hum->move_dir;
|
||||||
|
left_dir.Rotate(-90);
|
||||||
|
left_dir.Normalize();
|
||||||
|
Vector2D right_dir = hum->move_dir;
|
||||||
|
right_dir.Rotate(+90);
|
||||||
|
right_dir.Normalize();
|
||||||
|
|
||||||
|
Vector2D left_p0 = left_dir * (hum->meta->i->radius() + 1);
|
||||||
|
Vector2D left_p1 = left_p0 + hum->move_dir * (MAP_CELL_WIDTH - 64);
|
||||||
|
Vector2D right_p0 = right_dir * (hum->meta->i->radius() + 1);
|
||||||
|
Vector2D right_p1 = right_p0 + hum->move_dir * (MAP_CELL_WIDTH - 64);
|
||||||
|
|
||||||
|
for (auto& grid : hum->grid_list) {
|
||||||
|
for (Entity* entity : grid->entity_list) {
|
||||||
|
switch (entity->entity_type) {
|
||||||
|
case ET_Obstacle:
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
(hum->last_collision_door == nullptr || hum->last_collision_door != entity)
|
||||||
|
){
|
||||||
|
AabbCollider aabb_box;
|
||||||
|
entity->GetAabbBox(aabb_box);
|
||||||
|
if (IntersectSegmentAabb(left_p0, left_p1,
|
||||||
|
aabb_box.owner->pos + aabb_box._min,
|
||||||
|
aabb_box.owner->pos + aabb_box._max) ||
|
||||||
|
IntersectSegmentAabb(right_p0, right_p1,
|
||||||
|
aabb_box.owner->pos + aabb_box._min,
|
||||||
|
aabb_box.owner->pos + aabb_box._max)
|
||||||
|
) {
|
||||||
|
detection_objects.insert(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ET_Building:
|
||||||
|
{
|
||||||
|
AabbCollider aabb_box;
|
||||||
|
entity->GetAabbBox(aabb_box);
|
||||||
|
if (IntersectSegmentAabb(left_p0, left_p1,
|
||||||
|
aabb_box.owner->pos + aabb_box._min,
|
||||||
|
aabb_box.owner->pos + aabb_box._max) ||
|
||||||
|
IntersectSegmentAabb(right_p0, right_p1,
|
||||||
|
aabb_box.owner->pos + aabb_box._min,
|
||||||
|
aabb_box.owner->pos + aabb_box._max)
|
||||||
|
) {
|
||||||
|
detection_objects.insert(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user