From 757579fb18167990c339934289b33fd01ce552c7 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Mon, 14 Aug 2023 17:02:34 +0200 Subject: [PATCH] matrix dialog now used for models::rotation --- control.cpp | 2 +- history.cpp | 2 +- hyperpoint.cpp | 4 ++++ hypgraph.cpp | 4 ++-- legacy.cpp | 7 ++++++ models.cpp | 62 +++++++++++++------------------------------------- quit.cpp | 4 ++-- tour.cpp | 6 ++--- 8 files changed, 36 insertions(+), 55 deletions(-) diff --git a/control.cpp b/control.cpp index 7d643334..ed004623 100644 --- a/control.cpp +++ b/control.cpp @@ -430,7 +430,7 @@ EX void full_rotate_camera(int dir, ld val) { EX void full_rotate_view(ld h, ld v) { if(history::on && !rug::rug_control()) - models::rotation += h * camera_rot_speed; + models::rotation = spin(h * camera_rot_speed) * models::rotation; else { rotate_view(cspin(0, 1, v * camera_rot_speed)); didsomething = true; diff --git a/history.cpp b/history.cpp index dca30375..a2ba27a1 100644 --- a/history.cpp +++ b/history.cpp @@ -453,7 +453,7 @@ EX namespace history { if(1) { // block for RAII dynamicval dv(vid, vid); - dynamicval dr(models::rotation, 0); + dynamicval dr(models::rotation, Id); dynamicval di(inHighQual, true); renderbuffer glbuf(bandfull, bandfull, vid.usingGL); diff --git a/hyperpoint.cpp b/hyperpoint.cpp index b16f3ee7..6e9530d9 100644 --- a/hyperpoint.cpp +++ b/hyperpoint.cpp @@ -221,6 +221,10 @@ struct trans23 { dim = 4; t.v3 = v3 * T.v3; return t; } + friend trans23 operator * (transmatrix M, trans23 T) { + trans23 t(M); + return M * T; + } }; /** mirror image */ diff --git a/hypgraph.cpp b/hypgraph.cpp index fd2ccbad..282954f1 100644 --- a/hypgraph.cpp +++ b/hypgraph.cpp @@ -2073,10 +2073,10 @@ EX void spinEdge(ld aspd) { } else if(keep_vertical()) { hyperpoint h = vertical_vector(); - downspin = -atan2(h[0], h[1]); if(ds.qty && GDIM == 2) { - downspin += models::rotation * degree; + h = rot_inverse(models::rotation.get()) * h; } + downspin = -atan2(h[0], h[1]); if(ds.qty) { cyclefix(downspin, 0); downspin = downspin * min(ds.speed, (double)1); diff --git a/legacy.cpp b/legacy.cpp index 334e58b6..cca08f46 100644 --- a/legacy.cpp +++ b/legacy.cpp @@ -363,6 +363,13 @@ int read_legacy_args() { shift(); println(hlog, "-ballangle not implemented"); // shift_arg_formula(vpconf.ballangle); } + else if(argis("-crot")) { + PHASEFROM(2); + shift(); shift(); shift(); println(hlog, "-crot not implemented"); + /* shift_arg_formula(models::rotation); + if(GDIM == 3) shift_arg_formula(models::rotation_xz); + if(GDIM == 3) shift_arg_formula(models::rotation_xy2); */ + } else return 1; return 0; } diff --git a/models.cpp b/models.cpp index 1904ab47..c042b083 100644 --- a/models.cpp +++ b/models.cpp @@ -142,9 +142,7 @@ projection_configuration::projection_configuration() { EX namespace models { - EX ld rotation = 0; - EX ld rotation_xz = 90; - EX ld rotation_xy2 = 90; + EX trans23 rotation; EX int do_rotate = 1; EX bool model_straight, model_straight_yz; @@ -157,8 +155,8 @@ EX namespace models { EX void scr_to_ori(transmatrix& h) { if(!model_straight) h = iso_inverse(pconf.mori().get()) * h; } EX transmatrix rotmatrix() { - if(GDIM == 2 || gproduct) return spin(rotation * degree); - return spin(rotation_xy2 * degree) * cspin(0, 2, -rotation_xz * degree) * spin(rotation * degree); + if(gproduct) return rotation.v2; + return rotation.get(); } int spiral_id = 7; @@ -356,30 +354,6 @@ EX namespace models { }; } - EX void edit_rotation(ld& which) { - dialog::editNumber(which, 0, 360, 90, 0, XLAT("rotation"), - "This controls the automatic rotation of the world. " - "It affects the line animation in the history mode, and " - "lands which have a special direction. Note that if finding this special direction is a part of the puzzle, " - "it works only in the cheat mode."); - dialog::get_di().dialogflags |= sm::CENTER; - dialog::get_di().extra_options = [] () { - dialog::addBreak(100); - dialog::addBoolItem_choice("line animation only", models::do_rotate, 0, 'N'); - dialog::addBoolItem_choice("gravity lands", models::do_rotate, 1, 'G'); - dialog::addBoolItem_choice("all directional lands", models::do_rotate, 2, 'D'); - if(GDIM == 3) { - dialog::addBreak(100); - dialog::addSelItem(XLAT("XY plane"), fts(models::rotation) + "°", 'A'); - dialog::add_action([] { popScreen(); edit_rotation(models::rotation); }); - dialog::addSelItem(XLAT("XZ plane"), fts(models::rotation_xz) + "°", 'B'); - dialog::add_action([] { popScreen(); edit_rotation(models::rotation_xz); }); - dialog::addSelItem(XLAT("XY plane #2"), fts(models::rotation_xy2) + "°", 'C'); - dialog::add_action([] { popScreen(); edit_rotation(models::rotation_xy2); }); - } - }; - } - EX void model_list() { cmode = sm::SIDE | sm::MAYDARK | sm::CENTER; gamescreen(); @@ -456,14 +430,10 @@ EX namespace models { if(nonisotropic && !sl2) dialog::addBoolItem_action(XLAT("geodesic movement in Sol/Nil"), nisot::geodesic_movement, 'G'); - dialog::addBoolItem(XLAT("rotation"), do_rotate == 2, 'r'); - if(do_rotate == 0) dialog::lastItem().value = XLAT("NEVER"); - if(GDIM == 2) - dialog::lastItem().value += " " + its(rotation) + "°"; - else - dialog::lastItem().value += " " + its(rotation) + "°" + its(rotation_xz) + "°" + its(rotation_xy2) + "°"; - dialog::add_action([] { edit_rotation(rotation); }); - + add_edit((GDIM == 2 || gproduct) ? rotation.v2 : rotation.v3); + if(do_rotate == 0) { dialog::lastItem().value = XLAT("NEVER"); dialog::lastItem().type = dialog::diItem; } + else { dialog::lastItem().value = ONOFF(do_rotate == 2); } + bool vr_settings = vrhr::active() && set_vr_settings; if(vrhr::active()) { @@ -870,12 +840,6 @@ EX namespace models { PHASEFROM(2); shift_arg_formula(vpconf.rotational_nil); } - else if(argis("-crot")) { - PHASEFROM(2); - shift_arg_formula(models::rotation); - if(GDIM == 3) shift_arg_formula(models::rotation_xz); - if(GDIM == 3) shift_arg_formula(models::rotation_xy2); - } else if(argis("-clip")) { PHASEFROM(2); shift_arg_formula(vpconf.clip_min); @@ -968,9 +932,15 @@ EX namespace models { addsaver(polygonal::coefi[i], "polynomial "+its(i)+".imag"); } - param_f(models::rotation, "rotation", "conformal rotation"); - addsaver(models::rotation_xz, "conformal rotation_xz"); - addsaver(models::rotation_xy2, "conformal rotation_2"); + auto setrot = [] { + dialog::addBreak(100); + dialog::addBoolItem_choice("line animation only", models::do_rotate, 0, 'N'); + dialog::addBoolItem_choice("gravity lands", models::do_rotate, 1, 'G'); + dialog::addBoolItem_choice("all directional lands", models::do_rotate, 2, 'D'); + }; + + param_matrix(models::rotation.v2, "rotation", 2)->editable("conformal rotation", "", 'r')->set_extra(setrot); + param_matrix(models::rotation.v3, "rotation3", 3)->editable("conformal rotation in 3D", "", 'r')->set_extra(setrot); addsaver(models::do_rotate, "conformal rotation mode", 1); param_f(pconf.halfplane_scale, "hp", "halfplane scale", 1); diff --git a/quit.cpp b/quit.cpp index 99403b85..02a80817 100644 --- a/quit.cpp +++ b/quit.cpp @@ -236,9 +236,9 @@ EX hint hints[] = { popScreen(); auto m = pmodel; pmodel = mdBand; - int r = models::rotation; + auto r = models::rotation; bool h = history::includeHistory; - models::rotation = 0; + models::rotation = Id; history::includeHistory = true; history::create_playerpath(); cancel = [m,r,h] () { diff --git a/tour.cpp b/tour.cpp index 0ac57b46..9704e561 100644 --- a/tour.cpp +++ b/tour.cpp @@ -829,8 +829,8 @@ EX slide default_slides[] = { if(mode == 1) pmodel = mdHalfplane, smart = vid.use_smart_range, vid.use_smart_range = 2; if(mode == 2) - models::rotation = cwt.at->land == laDungeon ? 0 : 2; - if(mode == 3) pmodel = mdDisk, models::rotation = 0, vid.use_smart_range = smart; + models::rotation = cwt.at->land == laDungeon ? Id : spin(M_PI); + if(mode == 3) pmodel = mdDisk, models::rotation = Id, vid.use_smart_range = smart; } }, {"Curvature", 29, LEGAL::ANY, @@ -978,7 +978,7 @@ EX slide default_slides[] = { "memory.", [] (presmode mode) { static int smart; - if(mode == 1) pmodel = mdBand, history::create_playerpath(), models::rotation = 0, + if(mode == 1) pmodel = mdBand, history::create_playerpath(), models::rotation = Id, smart = vid.use_smart_range, vid.use_smart_range = 2; if(mode == 3) { history::clear(), pmodel = mdDisk;