1
This commit is contained in:
parent
8e7b10c959
commit
640e2ebaaf
@ -2,6 +2,10 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include <glm/gtx/euler_angles.hpp>
|
||||
|
||||
#include "bullet.h"
|
||||
#include "room.h"
|
||||
#include "obstacle.h"
|
||||
@ -64,16 +68,35 @@ void Bullet::Initialize()
|
||||
#ifdef DEBUG
|
||||
if (DebugCmd::Enable() && sender.Get() && sender.Get()) {
|
||||
glm::vec3 hit_pos;
|
||||
bool hited = room->map_instance->SceneRaycast
|
||||
float ray_length;
|
||||
bool hit = room->map_instance->SceneRaycast
|
||||
(GetPos().ToGlmVec3(),
|
||||
dir,
|
||||
gun_meta->range(),
|
||||
hit_pos);
|
||||
if (hited) {
|
||||
hit_pos,
|
||||
ray_length);
|
||||
if (hit) {
|
||||
DebugCmd::CreateSphere(sender.Get(),
|
||||
hit_pos,
|
||||
glm::vec3(10, 10, 10),
|
||||
room->AllocUniid());
|
||||
#if 1
|
||||
auto transform =
|
||||
glm::rotate(
|
||||
glm::mat4(1.0),
|
||||
glm::radians(45.0f),
|
||||
//glm::radians(angle),
|
||||
glm::vec3(0.0f, 1.0f, 0.0f)
|
||||
);
|
||||
#else
|
||||
glm::mat4 transform = glm::eulerAngleYXZ(dir1.y, dir1.x, dir1.z);
|
||||
#endif
|
||||
glm::quat q = glm::toQuat(transform);
|
||||
DebugCmd::CreateCube(sender.Get(),
|
||||
GetPos().ToGlmVec3(),
|
||||
glm::vec3(10, 10, 10),
|
||||
q,
|
||||
room->AllocUniid());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -56,6 +56,7 @@ void DebugCmd::CreateCube(Creature* c,
|
||||
msg.add_params(rotation.z);
|
||||
msg.add_params(rotation.w);
|
||||
|
||||
a8::XPrintf("r:%f,%f,%f,%f\n", {rotation.x, rotation.y, rotation.z, rotation.w});
|
||||
msg.add_params(uniid);
|
||||
|
||||
c->AsPlayer()->SendNotifyMsg(msg);
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include <glm/gtx/euler_angles.hpp>
|
||||
|
||||
namespace mc
|
||||
{
|
||||
|
@ -884,7 +884,8 @@ void MapInstance::LoadHouse()
|
||||
bool MapInstance::SceneRaycast(const glm::vec3& orig,
|
||||
const glm::vec3& dir,
|
||||
float max_distance,
|
||||
glm::vec3& hit_pos)
|
||||
glm::vec3& hit_pos,
|
||||
float& ray_length)
|
||||
{
|
||||
if (max_distance <= 0.001f) {
|
||||
return false;
|
||||
@ -896,6 +897,7 @@ bool MapInstance::SceneRaycast(const glm::vec3& orig,
|
||||
float len = 0.0f;
|
||||
bool result = false;
|
||||
bool end = false;
|
||||
int tri_count = 0;
|
||||
do {
|
||||
glm::vec3 curr_pos = orig + dir * len;
|
||||
if (len > max_distance) {
|
||||
@ -916,28 +918,30 @@ bool MapInstance::SceneRaycast(const glm::vec3& orig,
|
||||
CellNode *node, *tmp;
|
||||
list_for_each_entry_safe(node, tmp, head, entry) {
|
||||
if (node->tri->check_flag != raycast_index) {
|
||||
glm::vec3 pos;
|
||||
bool hited = glm::intersectLineTriangle
|
||||
glm::vec2 bary_position;
|
||||
float distance;
|
||||
bool hit = glm::intersectRayTriangle
|
||||
(orig,
|
||||
dir,
|
||||
node->tri->vert0,
|
||||
node->tri->vert1,
|
||||
node->tri->vert2,
|
||||
pos
|
||||
bary_position,
|
||||
distance
|
||||
);
|
||||
node->tri->check_flag = raycast_index;
|
||||
if (hited) {
|
||||
float distance = GlmHelper::Norm(pos - orig);
|
||||
++tri_count;
|
||||
if (hit) {
|
||||
if (nearest_node) {
|
||||
if (distance < nearest_distance) {
|
||||
nearest_node = node;
|
||||
nearest_distance = distance;
|
||||
nearest_pt = pos;
|
||||
nearest_pt = orig + dir * distance;
|
||||
}
|
||||
} else if (distance <= max_distance) {
|
||||
nearest_node = node;
|
||||
nearest_distance = distance;
|
||||
nearest_pt = pos;
|
||||
nearest_pt = orig + dir * distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -952,7 +956,11 @@ bool MapInstance::SceneRaycast(const glm::vec3& orig,
|
||||
} while (!end);
|
||||
|
||||
if (result) {
|
||||
#ifdef DEBUG
|
||||
a8::XPrintf("nearest_node:%s tri_count:%d\n", {nearest_node->tri->node->name, tri_count});
|
||||
#endif
|
||||
hit_pos = nearest_pt;
|
||||
ray_length = nearest_distance;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -57,7 +57,8 @@ class MapInstance : public std::enable_shared_from_this<MapInstance>
|
||||
void CheckTerrain(Creature* c, int same_poly_flags, const std::vector<dtPolyRef>& spec_polys);
|
||||
void TraverseHouseList(std::function<void (HouseInfo*)> func);
|
||||
bool PtInHouse(const glm::vec3& pt, glm::vec3& nearest_pt);
|
||||
bool SceneRaycast(const glm::vec3& orig, const glm::vec3& dir, float max_distance, glm::vec3& hit_pos);
|
||||
bool SceneRaycast(const glm::vec3& orig, const glm::vec3& dir, float max_distance,
|
||||
glm::vec3& hit_pos, float& ray_length);
|
||||
|
||||
private:
|
||||
void CreateThings();
|
||||
|
@ -238,7 +238,7 @@ static void InternalCreateBullet(BulletInfo& bullet_info)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG1
|
||||
DebugCmd::CreateSphere(c,
|
||||
glm::vec3(
|
||||
bullet_info.bullet_born_pos.x,
|
||||
|
Loading…
x
Reference in New Issue
Block a user