Add dynamic snapping resolution

master
rubenwardy 2015-07-26 14:51:23 +01:00
parent 857b3a8b31
commit aebb5b3d4c
7 changed files with 25 additions and 11 deletions

View File

@ -2,6 +2,9 @@
# snap to pixels
snapping = true
# The resolution the nodebox snaps to (can be overriden per node)
default_snap_res = 16
# limiting stops node boxes going out of node bounds
limiting = true

View File

@ -87,6 +87,7 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}
conf->set("snapping", "true");
conf->set("default_snap_res", "16");
conf->set("limiting", "true");
conf->set("fractional_positions", "false");
conf->set("driver", "opengl");

View File

@ -393,11 +393,19 @@ void CDR::update(NBEditor* editor, bool drag, rect<s32> offset)
// Call required function
editor->fillProperties();
int snap_res = node->snap_res;
if (snap_res == -1) {
static const int set_snap_res =
editor->state->settings->getInt("default_snap_res");
snap_res = set_snap_res;
}
if (actualType < CDR_XZ) {
if (editor->state->settings->getBool("snapping")) {
wpos.X = (f32)floor((wpos.X + 0.5) * 16 + 0.5) / 16 - 0.5;
wpos.Y = (f32)floor((wpos.Y + 0.5) * 16 + 0.5) / 16 - 0.5;
wpos.Z = (f32)floor((wpos.Z + 0.5) * 16 + 0.5) / 16 - 0.5;
wpos.X = (f32)floor((wpos.X + 0.5) * snap_res + 0.5) / snap_res - 0.5;
wpos.Y = (f32)floor((wpos.Y + 0.5) * snap_res + 0.5) / snap_res - 0.5;
wpos.Z = (f32)floor((wpos.Z + 0.5) * snap_res + 0.5) / snap_res - 0.5;
// (X + 0.5) round relative to (-0.5, -0.5, -0.5)
// ie: (-0.5, -0.5, -0.5) goes to (0, 0, 0)
@ -410,7 +418,7 @@ void CDR::update(NBEditor* editor, bool drag, rect<s32> offset)
editor->state->keys[KEY_LCONTROL] == EKS_DOWN);
} else {
box->move(editor->state, actualType, wpos,
editor->state->settings->getBool("snapping"));
(editor->state->settings->getBool("snapping")?snap_res:0));
}
node->remesh(box);

View File

@ -6,7 +6,8 @@ Node::Node(IrrlichtDevice* device, EditorState* state, unsigned int id) :
state(state),
_selected(-1),
_nid(id),
_box_count(0)
_box_count(0),
snap_res(-1)
{
for (int i = 0; i < 6; i++) {
images[i] = NULL;

View File

@ -40,6 +40,7 @@ public:
vector3di position;
std::string name;
std::vector<NodeBox*> boxes;
int snap_res;
private:
// Data
int _selected;

View File

@ -91,7 +91,7 @@ void NodeBox::moveFace(EditorState* editor, ECDR_DIR type,
}
void NodeBox::move(EditorState* editor, ECDR_DIR type, vector3df position,
bool do_snap)
const int snap_res)
{
vector3df new_one = one;
vector3df new_two = two;
@ -157,11 +157,11 @@ void NodeBox::move(EditorState* editor, ECDR_DIR type, vector3df position,
}
}
if (do_snap) {
if (snap_res > 0) {
vector3df snapped_one(
(f32)floor((new_one.X + 0.5) * 16 + 0.5) / 16 - 0.5,
(f32)floor((new_one.Y + 0.5) * 16 + 0.5) / 16 - 0.5,
(f32)floor((new_one.Z + 0.5) * 16 + 0.5) / 16 - 0.5);
(f32)floor((new_one.X + 0.5) * snap_res + 0.5) / snap_res - 0.5,
(f32)floor((new_one.Y + 0.5) * snap_res + 0.5) / snap_res - 0.5,
(f32)floor((new_one.Z + 0.5) * snap_res + 0.5) / snap_res - 0.5);
new_two += snapped_one - new_one;
new_one = snapped_one;
}

View File

@ -46,7 +46,7 @@ public:
void moveFace(EditorState* editor, ECDR_DIR type,
vector3df position, bool both);
void move(EditorState* editor, ECDR_DIR type, vector3df position,
bool do_snap=false);
const int snap_res=0);
void rotate(EAxis axis);
void flip(EAxis axis);