mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-22 02:19:44 +00:00
use double precision for camera position and ray casts
A float position has a step of 6 cm at 1M blocks and of 2 m at 30M: the camera moved by jumps and rays started not where the camera is. worldvec3 (glm::dvec3) is the type of a position in the world. Camera::position, the start and the end of block and entity ray casts and the hit position of the player selection use it. Lua numbers are doubles already, so cameras.set_pos/get_pos, block.raycast, entities.raycast and world.raycast only stop rounding to float. Entities::rayCast intersects a hitbox in the coordinates relative to its position instead of a float AABB in the world space.
This commit is contained in:
parent
89bdadd6aa
commit
ad69663b2e
18 changed files with 86 additions and 71 deletions
|
|
@ -211,10 +211,10 @@ void Chunks::set(
|
|||
}
|
||||
|
||||
voxel* Chunks::rayCast(
|
||||
const glm::vec3& start,
|
||||
const worldvec3& start,
|
||||
const glm::vec3& dir,
|
||||
float maxDist,
|
||||
glm::vec3& end,
|
||||
worldvec3& end,
|
||||
glm::ivec3& norm,
|
||||
glm::ivec3& iend,
|
||||
const blocks_agent::RaycastSettings& settings
|
||||
|
|
@ -224,12 +224,12 @@ voxel* Chunks::rayCast(
|
|||
);
|
||||
}
|
||||
|
||||
glm::vec3 Chunks::rayCastToObstacle(
|
||||
const glm::vec3& start, const glm::vec3& dir, float maxDist
|
||||
worldvec3 Chunks::rayCastToObstacle(
|
||||
const worldvec3& start, const glm::vec3& dir, float maxDist
|
||||
) const {
|
||||
const float px = start.x;
|
||||
const float py = start.y;
|
||||
const float pz = start.z;
|
||||
const double px = start.x;
|
||||
const double py = start.y;
|
||||
const double pz = start.z;
|
||||
|
||||
float dx = dir.x;
|
||||
float dy = dir.y;
|
||||
|
|
@ -286,11 +286,11 @@ glm::vec3 Chunks::rayCastToObstacle(
|
|||
norm,
|
||||
distance
|
||||
) > RayRelation::None) {
|
||||
return start + (dir * glm::vec3(distance));
|
||||
return start + worldvec3(dir) * distance;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return glm::vec3(px + t * dx, py + t * dy, pz + t * dz);
|
||||
return worldvec3(px + t * dx, py + t * dy, pz + t * dz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -316,7 +316,7 @@ glm::vec3 Chunks::rayCastToObstacle(
|
|||
}
|
||||
}
|
||||
}
|
||||
return glm::vec3(px + maxDist * dx, py + maxDist * dy, pz + maxDist * dz);
|
||||
return worldvec3(px + maxDist * dx, py + maxDist * dy, pz + maxDist * dz);
|
||||
}
|
||||
|
||||
void Chunks::setCenter(int32_t x, int32_t z) {
|
||||
|
|
|
|||
|
|
@ -110,17 +110,17 @@ public:
|
|||
void setRotation(int32_t x, int32_t y, int32_t z, uint8_t rotation);
|
||||
|
||||
voxel* rayCast(
|
||||
const glm::vec3& start,
|
||||
const worldvec3& start,
|
||||
const glm::vec3& dir,
|
||||
float maxLength,
|
||||
glm::vec3& end,
|
||||
worldvec3& end,
|
||||
glm::ivec3& norm,
|
||||
glm::ivec3& iend,
|
||||
const blocks_agent::RaycastSettings& settings
|
||||
) const;
|
||||
|
||||
glm::vec3 rayCastToObstacle(
|
||||
const glm::vec3& start, const glm::vec3& dir, float maxDist
|
||||
worldvec3 rayCastToObstacle(
|
||||
const worldvec3& start, const glm::vec3& dir, float maxDist
|
||||
) const;
|
||||
|
||||
const AABB* isObstacleAt(float x, float y, float z) const;
|
||||
|
|
|
|||
|
|
@ -217,18 +217,18 @@ bool blocks_agent::set(
|
|||
template <class Storage>
|
||||
static inline voxel* raycast_blocks(
|
||||
const Storage& chunks,
|
||||
const glm::vec3& start,
|
||||
const worldvec3& start,
|
||||
const glm::vec3& dir,
|
||||
float maxDist,
|
||||
glm::vec3& end,
|
||||
worldvec3& end,
|
||||
glm::ivec3& norm,
|
||||
glm::ivec3& iend,
|
||||
const RaycastSettings& settings
|
||||
) {
|
||||
const auto& blocks = chunks.getContentIndices().blocks;
|
||||
float px = start.x;
|
||||
float py = start.y;
|
||||
float pz = start.z;
|
||||
double px = start.x;
|
||||
double py = start.y;
|
||||
double pz = start.z;
|
||||
|
||||
float dx = dir.x;
|
||||
float dy = dir.y;
|
||||
|
|
@ -271,7 +271,7 @@ static inline voxel* raycast_blocks(
|
|||
(def.selectable || includeNonSelectable) &&
|
||||
((filter == nullptr || filter->find(def.rt.id) == filter->end()) ==
|
||||
settings.blocksFilterExcludeMode)) {
|
||||
end = start + t * dir;
|
||||
end = start + worldvec3(t * dir);
|
||||
iend = {ix, iy, iz};
|
||||
|
||||
if (!def.rt.solid) {
|
||||
|
|
@ -301,7 +301,7 @@ static inline voxel* raycast_blocks(
|
|||
hit = true;
|
||||
distance = boxDistance;
|
||||
norm = boxNorm;
|
||||
end = start + (dir * glm::vec3(distance));
|
||||
end = start + worldvec3(dir) * distance;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -342,17 +342,17 @@ static inline voxel* raycast_blocks(
|
|||
}
|
||||
}
|
||||
iend = {ix, iy, iz};
|
||||
end = start + t * dir;
|
||||
end = start + worldvec3(t * dir);
|
||||
norm = {0, 0, 0};
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
voxel* blocks_agent::raycast(
|
||||
const Chunks& chunks,
|
||||
const glm::vec3& start,
|
||||
const worldvec3& start,
|
||||
const glm::vec3& dir,
|
||||
float maxDist,
|
||||
glm::vec3& end,
|
||||
worldvec3& end,
|
||||
glm::ivec3& norm,
|
||||
glm::ivec3& iend,
|
||||
const RaycastSettings& settings
|
||||
|
|
@ -362,10 +362,10 @@ voxel* blocks_agent::raycast(
|
|||
|
||||
voxel* blocks_agent::raycast(
|
||||
const GlobalChunks& chunks,
|
||||
const glm::vec3& start,
|
||||
const worldvec3& start,
|
||||
const glm::vec3& dir,
|
||||
float maxDist,
|
||||
glm::vec3& end,
|
||||
worldvec3& end,
|
||||
glm::ivec3& norm,
|
||||
glm::ivec3& iend,
|
||||
const RaycastSettings& settings
|
||||
|
|
|
|||
|
|
@ -447,10 +447,10 @@ struct RaycastSettings {
|
|||
/// @return voxel pointer or nullptr
|
||||
voxel* raycast(
|
||||
const Chunks& chunks,
|
||||
const glm::vec3& start,
|
||||
const worldvec3& start,
|
||||
const glm::vec3& dir,
|
||||
float maxDist,
|
||||
glm::vec3& end,
|
||||
worldvec3& end,
|
||||
glm::ivec3& norm,
|
||||
glm::ivec3& iend,
|
||||
const RaycastSettings& settings
|
||||
|
|
@ -469,10 +469,10 @@ voxel* raycast(
|
|||
/// @return voxel pointer or nullptr
|
||||
voxel* raycast(
|
||||
const GlobalChunks& chunks,
|
||||
const glm::vec3& start,
|
||||
const worldvec3& start,
|
||||
const glm::vec3& dir,
|
||||
float maxDist,
|
||||
glm::vec3& end,
|
||||
worldvec3& end,
|
||||
glm::ivec3& norm,
|
||||
glm::ivec3& iend,
|
||||
const RaycastSettings& settings
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue