I've implemented terrain deformation and painting in my map editor, but when I added a meshDecal to highlight the terrain square that is currently selected by the mouse pointer I noticed that deformation is done beside, and not under, the mouse pointer.
At first I thought it would be some asynchronus issue with CEGUI, but the meshDecal is properly placed under the mouse pointer.
It also depends on the position of the camera on the map if the terrain is deformed above or beside the selected square....
Solved the problem
In
void PagingLandScapeSceneManager::deformHeight (const Ogre::Vector3 &impact)
the impact point's x and z values are converted to int
const int X = static_cast<int> (impact.x / mOptions->scale.x);
const int Z = static_cast<int> (impact.z / mOptions->scale.z);
to get the "base vertex" for the deformation.
For positive x and z values this will be the top left vertex of the square that you clicked on, for negative values the lower right.
Therefore the position of the deformed vertices will differ from deformations done on other sides of the x and/or z axis.
E.g.:
Brusharraywidth = 2;
Brusharrayheight = 2;
Click on the square defined by the vertices (1,1), (1,2), (2,1), (2,2)
->impact(1.5, 1.5) // x and z values only
->
x and z will be 1 if converted to int; the "base vertex" for deformation will be (1, 1), the left upper vertex of the square
->
the deformed vertices will be be:
(0,0), (0,1),(1,0),(1,1)
and that's beside the square you clicked on
I solved the problem by changing
const int X = static_cast<int> (impact.x / mOptions->scale.x);
const int Z = static_cast<int> (impact.z / mOptions->scale.z);
to
const int X = static_cast<int>(ceilf(impact.x / mOptions->scale.x));
const int Z = static_cast<int>(ceilf(impact.z / mOptions->scale.z));
ceiling will make sure that the "base vertex" is the lower right vertex of the square that is located at the impact point.
For bigger brush sizes you probably won't notice the offset of one square, but nevertheless I wonder why nobody noticed it.