mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-16 23:18:12 +08:00
地形图hittest越界问题
This commit is contained in:
parent
8bdf5cc390
commit
35b940a0fe
@ -158,8 +158,8 @@ void SceneViewer::initializeGL() {
|
||||
terrainFragmentShader.dispose();
|
||||
|
||||
// Test Code Start
|
||||
_sky = new SkyBox("E:\\Repositories\\CollegeProjects\\CGAssignments\\FinalProject\\SkyBoxes");
|
||||
_terrain = new Terrain("E:\\Repositories\\CollegeProjects\\CGAssignments\\FinalProject\\Terrains");
|
||||
_sky = new SkyBox("D:\\ProgrammingFile\\SceneEditor\\SkyBoxes");
|
||||
_terrain = new Terrain("D:\\ProgrammingFile\\SceneEditor\\Terrains");
|
||||
|
||||
_dirLight = new DirLight();
|
||||
|
||||
|
||||
@ -147,6 +147,8 @@ float Terrain::GetHeight(float px, float pz) {
|
||||
|
||||
float ans = (x - fx) * (Point[gx][gz] - Point[x][z]) + Point[x][z];
|
||||
|
||||
//float ans = Point[x][z];
|
||||
|
||||
return ans;
|
||||
}
|
||||
|
||||
@ -166,9 +168,12 @@ glm::vec3 Terrain::GetNormal(glm::vec3 pos) {
|
||||
HitRecord Terrain::hit(const Ray& ray) {
|
||||
glm::vec3 orig = ray.origin();
|
||||
glm::vec3 dir = ray.direction();
|
||||
if (orig.x >= width / 2 || orig.x <= -width / 2 || orig.z >= height / 2 || orig.z <= -height / 2) {
|
||||
return HitRecord();
|
||||
}
|
||||
|
||||
// A good ray step is half of the blockScale
|
||||
glm::vec3 rayStep = dir * (float)width * 0.25f;
|
||||
glm::vec3 rayStep = dir;
|
||||
glm::vec3 rayStartPosition = orig;
|
||||
|
||||
// Linear search - Loop until find a point inside and outside the terrain Vector3
|
||||
@ -179,6 +184,9 @@ HitRecord Terrain::hit(const Ray& ray) {
|
||||
{
|
||||
lastRayPosition = orig;
|
||||
orig += rayStep;
|
||||
if (orig.x >= width / 2 || orig.x <= -width / 2 || orig.z >= height / 2 || orig.z <= -height / 2) {
|
||||
return HitRecord();
|
||||
}
|
||||
map_height = GetHeight(orig.x, orig.z);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user