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