paysages : Terrain painting WIP.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@562 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2013-04-28 19:34:35 +00:00 committed by ThunderK
parent 53a29d5015
commit b7b483f673
3 changed files with 30 additions and 22 deletions

View file

@ -45,6 +45,9 @@ QGLWidget(parent)
_target_x = 0.0; _target_x = 0.0;
_target_z = 0.0; _target_z = 0.0;
_last_update_x = 0;
_last_update_z = 0;
_current_camera = cameraCreateDefinition(); _current_camera = cameraCreateDefinition();
_top_camera = cameraCreateDefinition(); _top_camera = cameraCreateDefinition();
_temp_camera = cameraCreateDefinition(); _temp_camera = cameraCreateDefinition();
@ -238,6 +241,14 @@ void WidgetHeightMap::timerEvent(QTimerEvent*)
cameraSetZoomToTarget(_top_camera, _zoom); cameraSetZoomToTarget(_top_camera, _zoom);
if (cameraTransitionToAnother(_current_camera, _top_camera, 0.8)) if (cameraTransitionToAnother(_current_camera, _top_camera, 0.8))
{ {
int update_x = (int) (floor(_target_x));
int update_z = (int) (floor(_target_z));
if (update_x - _last_update_x < -10 || update_x - _last_update_x > 10 || update_z - _last_update_z < -10 || update_z - _last_update_z > 10)
{
_dirty = true;
}
updateGL(); updateGL();
} }
@ -252,12 +263,8 @@ void WidgetHeightMap::timerEvent(QTimerEvent*)
double brush_strength; double brush_strength;
TerrainBrush brush; TerrainBrush brush;
Vector3 camera_target = cameraGetTarget(_current_camera); brush.relative_x = _brush_x + _target_x;
double tx = camera_target.x; brush.relative_z = _brush_z + _target_z;
double tz = camera_target.z;
brush.relative_x = _brush_x + tx;
brush.relative_z = _brush_z + tz;
brush.hard_radius = _brush_size * (1.0 - _brush_smoothing); brush.hard_radius = _brush_size * (1.0 - _brush_smoothing);
brush.smoothed_size = _brush_size * _brush_smoothing; brush.smoothed_size = _brush_size * _brush_smoothing;
brush.total_radius = brush.hard_radius + brush.smoothed_size; brush.total_radius = brush.hard_radius + brush.smoothed_size;
@ -310,7 +317,6 @@ void WidgetHeightMap::timerEvent(QTimerEvent*)
} }
else if (wy > 1.0 - limit) else if (wy > 1.0 - limit)
{ {
scrollTopCamera(0.0, force * (wy - (1.0 - limit)) / limit); scrollTopCamera(0.0, force * (wy - (1.0 - limit)) / limit);
} }
} }
@ -404,11 +410,8 @@ void WidgetHeightMap::paintGL()
{ {
gluUnProject(winX, winY, winZ, modelview, projection, viewport, &point.x, &point.y, &point.z); gluUnProject(winX, winY, winZ, modelview, projection, viewport, &point.x, &point.y, &point.z);
if (point.x >= -rx / 2 && point.x <= rx / 2 && point.z >= -rz / 2 && point.z <= rz / 2) _brush_x = point.x - _target_x;
{ _brush_z = point.z - _target_z;
_brush_x = point.x;
_brush_z = point.z;
}
} }
_mouse_moved = false; _mouse_moved = false;
@ -460,7 +463,7 @@ void WidgetHeightMap::paintGL()
} }
glColor3f(0.8 + diff, vertex->painted ? 1.0 : 0.8, 0.8); glColor3f(0.8 + diff, vertex->painted ? 1.0 : 0.8, 0.8);
glNormal3f(vertex->normal.x, vertex->normal.y, vertex->normal.z); glNormal3f(vertex->normal.x, vertex->normal.y, vertex->normal.z);
glVertex3f(vertex->point.x - _target_x, vertex->point.y, vertex->point.z - _target_z); glVertex3f(vertex->point.x, vertex->point.y, vertex->point.z);
} }
} }
glEnd(); glEnd();
@ -480,7 +483,7 @@ void WidgetHeightMap::paintGL()
for (int x = 0; x < rx; x++) for (int x = 0; x < rx; x++)
{ {
_VertexInfo* vertex = _vertices + z * rx + x; _VertexInfo* vertex = _vertices + z * rx + x;
glVertex3f(vertex->point.x - _target_x, vertex->point.y, vertex->point.z - _target_z); glVertex3f(vertex->point.x, vertex->point.y, vertex->point.z);
} }
glEnd(); glEnd();
} }
@ -490,7 +493,7 @@ void WidgetHeightMap::paintGL()
for (int z = 0; z < rz; z++) for (int z = 0; z < rz; z++)
{ {
_VertexInfo* vertex = _vertices + z * rx + x; _VertexInfo* vertex = _vertices + z * rx + x;
glVertex3f(vertex->point.x - _target_x, vertex->point.y, vertex->point.z - _target_z); glVertex3f(vertex->point.x, vertex->point.y, vertex->point.z);
} }
glEnd(); glEnd();
} }
@ -523,7 +526,6 @@ void WidgetHeightMap::paintGL()
while ((error_code = glGetError()) != GL_NO_ERROR) while ((error_code = glGetError()) != GL_NO_ERROR)
{ {
logDebug(QString("[OpenGL] ERROR : ") + (const char*) gluErrorString(error_code)); logDebug(QString("[OpenGL] ERROR : ") + (const char*) gluErrorString(error_code));
} }
} }
@ -548,10 +550,10 @@ void WidgetHeightMap::zoomTopCamera(double dzoom)
{ {
_zoom = 10.0; _zoom = 10.0;
} }
else if (_zoom > 70.0) else if (_zoom > 80.0)
{ {
_zoom = 70.0; _zoom = 80.0;
} }
} }
@ -567,6 +569,9 @@ void WidgetHeightMap::updateVertexInfo()
_memory_stats = terrainGetMemoryStats(_terrain); _memory_stats = terrainGetMemoryStats(_terrain);
_last_update_x = (int) (floor(_target_x));
_last_update_z = (int) (floor(_target_z));
// Update positions // Update positions
for (int x = 0; x < rx; x++) for (int x = 0; x < rx; x++)
{ {
@ -574,8 +579,8 @@ void WidgetHeightMap::updateVertexInfo()
{ {
_VertexInfo* vertex = _vertices + z * rx + x; _VertexInfo* vertex = _vertices + z * rx + x;
dx = _target_x + x - rx / 2; dx = _last_update_x + x - rx / 2;
dz = _target_z + z - rz / 2; dz = _last_update_z + z - rz / 2;
vertex->point.x = (double) dx; vertex->point.x = (double) dx;
vertex->point.z = (double) dz; vertex->point.z = (double) dz;

View file

@ -83,6 +83,9 @@ private:
double _target_x; double _target_x;
double _target_z; double _target_z;
int _last_update_x;
int _last_update_z;
CameraDefinition* _top_camera; CameraDefinition* _top_camera;
CameraDefinition* _temp_camera; CameraDefinition* _temp_camera;
CameraDefinition* _current_camera; CameraDefinition* _current_camera;

View file

@ -130,5 +130,5 @@ START_TEST(test_vectors_spherical)
} }
END_TEST END_TEST
TEST_CASE(euclid, test_euclid_angles, test_vectors_spherical) TEST_CASE(euclid, test_euclid_angles, test_vectors, test_vectors_spherical)