Terrain normals after rotation

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Atoboldom
Posts: 1
Joined: Wed Nov 07, 2007 5:03 pm

Terrain normals after rotation

Post by Atoboldom »

Hello,

I just got a problem with terrain. The normals seem to not be affected by rotation.
When i display terrain normals i can see they do not match terrain inclination.
That make lighting fail with shadows at wrong place.

Here is how I added my terrain with rotation.

Code: Select all

smgr->addTerrainSceneNode("map.bmp", 0, -1, pos, irr::core::vector3df(0, -90, 0));

I checked CTerrainSceneNode.cpp and I found that CTerrainSceneNode::setScale calls calculateNormals.
I'm surprised that setRotation doesn't call it since a rotation modifies normals as scaling does.
So I modified it like this :

Code: Select all

void CTerrainSceneNode::setRotation(const core::vector3df& rotation)
{
    TerrainData.Rotation = rotation;
    applyTransformation();
    calculateNormals(RenderBuffer); // I added this line
    ForceRecalculation = true;
}
This works, normals seems ok and shading confirms it.

I'm using irrlicht 1.8.

Is that a bug from irrlicht ? Is my fix correct ?
Dareltibus
Posts: 115
Joined: Mon May 17, 2010 7:42 am

Re: Terrain normals after rotation

Post by Dareltibus »

terrains are not thinked for being rotated. What if users calling "setRotation" don't know that calling that method will re-calculate normals? They will complain about huge slowdown (thousands squareroots can be a pain for realtime apps).

Anyway normals should be relative only to local mesh, so normals works indipendently of mesh rotation. If rotating mesh mess-up normals there's something wrong. Probably searching in to applyTransform is better)
Post Reply