Tool(d, k, m),
terrain(t),
marker((GL::VERTEX3, GL::COLOR4_UBYTE)),
+ marker_orientation(0),
dragging(false),
drag_start(0)
{
designer.get_layout_3d().get_scene().add(*this);
- float ts = terrain.get_type().get_tile_size();
- GL::MeshBuilder bld(marker);
- bld.begin(GL::TRIANGLE_STRIP);
- bld.vertex(-ts/2, 0, -ts/4);
- bld.vertex(ts/2, 0, -ts/4);
- bld.vertex(-ts/2, 0, ts/4);
- bld.vertex(ts/2, 0, ts/4);
- bld.end();
- bld.begin(GL::TRIANGLE_STRIP);
- bld.vertex(0, -ts/2, -ts/4);
- bld.vertex(0, ts/2, -ts/4);
- bld.vertex(0, -ts/2, ts/4);
- bld.vertex(0, ts/2, ts/4);
- bld.end();
+ update_marker();
}
TerrainTool::~TerrainTool()
designer.get_layout_3d().get_scene().remove(*this);
}
+void TerrainTool::update_marker()
+{
+ marker.clear();
+ GL::MeshBuilder bld(marker);
+
+ float ts = terrain.get_type().get_tile_size();
+ if(shift_held)
+ {
+ bld.begin(GL::TRIANGLE_STRIP);
+ bld.vertex(0, ts/2, ts/4);
+ bld.vertex(0, ts/2, -ts/4);
+ bld.vertex(0, 0, ts/4);
+ bld.vertex(0, 0, -ts/4);
+ bld.vertex(ts/2, 0, ts/4);
+ bld.vertex(ts/2, 0, -ts/4);
+ bld.end();
+ }
+ else
+ {
+ bld.begin(GL::TRIANGLE_STRIP);
+ bld.vertex(-ts/2, 0, ts/4);
+ bld.vertex(-ts/2, 0, -ts/4);
+ bld.vertex((edit_size+0.5)*ts, 0, ts/4);
+ bld.vertex((edit_size+0.5)*ts, 0, -ts/4);
+ bld.end();
+ bld.begin(GL::TRIANGLE_STRIP);
+ bld.vertex(0, -ts/2, ts/4);
+ bld.vertex(0, -ts/2, -ts/4);
+ bld.vertex(0, (edit_size+0.5)*ts, ts/4);
+ bld.vertex(0, (edit_size+0.5)*ts, -ts/4);
+ bld.end();
+ }
+}
+
+void TerrainTool::key_press(unsigned key)
+{
+ bool shift_was_held = shift_held;
+ Tool::key_press(key);
+ if(shift_held!=shift_was_held)
+ update_marker();
+}
+
+void TerrainTool::key_release(unsigned key)
+{
+ bool shift_was_held = shift_held;
+ Tool::key_release(key);
+ if(shift_held!=shift_was_held)
+ update_marker();
+}
+
void TerrainTool::button_press(unsigned btn)
{
if(btn==1)
float elev = terrain.get_node_elevation(highlight_node);
float eg = terrain.get_type().get_elevation_granularity();
elev += eg*d;
- terrain.set_node_elevation(highlight_node, elev, true);
+ terrain.set_node_elevation(highlight_node, elev, !shift_held);
marker_position = terrain.get_node_position(highlight_node);
drag_start = pointer.y;
Ray ray = designer.get_view().create_ray(pointer.x, pointer.y);
highlight_node = terrain.get_closest_node(ray);
marker_position = terrain.get_node_position(highlight_node);
+ marker_orientation = highlight_node.i^(highlight_node.i>>1);
}
}
GL::Renderer::Push push(renderer);
renderer.matrix_stack() *= GL::Matrix::translation(marker_position);
+ renderer.matrix_stack() *= GL::Matrix::rotation(Angle::from_turns(marker_orientation*0.25), 0, 0, 1);
marker.draw(renderer);
}