So, here is what happens when the user clicks on the terrain in draw mode:
float cursor_x,
cursor_z;
// pick screen
int pick = dbPickObject( MouseX, MouseY, Terrain.Object(), Terrain.Object() );
if ( pick == Terrain.Object() )
{
dbPickScreen ( MouseX, MouseY, dbGetPickDistance() );
cursor_x = dbCameraPositionX() + dbGetPickVectorX();
cursor_z = dbCameraPositionZ() + dbGetPickVectorZ();
}
// calculate draw coordinates
float x = dbLimbPositionX( Terrain.Object(), limb ) - ( Terrain.TileSizeX() / 2 ),
z = dbLimbPositionZ( Terrain.Object(), limb ) - ( Terrain.TileSizeZ() / 2 );
float dx = cursor_x - x,
dz = cursor_z - z;
float u = dx * ( Terrain.AlphaMapWidth( limb ) / Terrain.TileSizeX() ) + PickOffset,
v = dz * ( Terrain.AlphaMapHeight( limb ) / Terrain.TileSizeZ() ) + PickOffset;
What you get from this are the results
u &
v. I use them to draw pixels (in various brushes/sizes) to draw on an alpha map. This alpha map (a bitmap image) is used to blend different textures together in a shader for the final render of the terrain.
Well, this is something from the very interns of this programs, so something may not make lots of sense to others. But it works well.
I hope it gives you some ideas.
Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.