mirror of https://github.com/axmolengine/axmol.git
Merge pull request #12363 from super626/v3
Fix terrain lod computing bugs
This commit is contained in:
commit
bb275351f0
|
@ -401,7 +401,7 @@ void Node::updateRotation3D()
|
|||
float x = _rotationQuat.x, y = _rotationQuat.y, z = _rotationQuat.z, w = _rotationQuat.w;
|
||||
_rotationX = atan2f(2.f * (w * x + y * z), 1.f - 2.f * (x * x + y * y));
|
||||
_rotationY = asinf(2.f * (w * y - z * x));
|
||||
_rotationZ_X = atanf(2.f * (w * z + x * y) / (1.f - 2.f * (y * y + z * z)));
|
||||
_rotationZ_X = atan2f(2.f * (w * z + x * y), 1.f - 2.f * (y * y + z * z));
|
||||
|
||||
_rotationX = CC_RADIANS_TO_DEGREES(_rotationX);
|
||||
_rotationY = CC_RADIANS_TO_DEGREES(_rotationY);
|
||||
|
|
|
@ -613,8 +613,9 @@ void Mesh::setLightUniforms(Pass* pass, Scene* scene, const Vec4& color, unsigne
|
|||
if (hasAmbient)
|
||||
{
|
||||
ambient.x /= 255.f; ambient.y /= 255.f; ambient.z /= 255.f;
|
||||
//override the uniform value of u_color using the calculated color
|
||||
glProgramState->setUniformVec4("u_color", Vec4(color.x * ambient.x, color.y * ambient.y, color.z * ambient.z, color.w));
|
||||
}
|
||||
glProgramState->setUniformVec4("u_color", Vec4(color.x * ambient.x, color.y * ambient.y, color.z * ambient.z, color.w));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -159,11 +159,9 @@ void Terrain::onDraw(const Mat4 &transform, uint32_t flags)
|
|||
|
||||
if(_isCameraViewChanged )
|
||||
{
|
||||
auto camPos = camera->getPosition3D();
|
||||
auto camModelMat = camera->getNodeToWorldTransform();
|
||||
camModelMat.transformPoint(&camPos);
|
||||
auto m = camera->getNodeToWorldTransform();
|
||||
//set lod
|
||||
setChunksLOD(camPos);
|
||||
setChunksLOD(Vec3(m.m[12], m.m[13], m.m[14]));
|
||||
}
|
||||
|
||||
if(_isCameraViewChanged )
|
||||
|
@ -265,7 +263,7 @@ void Terrain::setChunksLOD(Vec3 cameraPos)
|
|||
{
|
||||
AABB aabb = _chunkesArray[m][n]->_parent->_worldSpaceAABB;
|
||||
auto center = aabb.getCenter();
|
||||
float dist = Vec3(center.x,0,center.z).distance(Vec3(cameraPos.x,0,cameraPos.z));
|
||||
float dist = Vec2(center.x, center.z).distance(Vec2(cameraPos.x, cameraPos.z));
|
||||
_chunkesArray[m][n]->_currentLod = 3;
|
||||
for(int i =0;i<3;i++)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue