From 9e5da826ebcec801b11eefca036bfa408492d4c6 Mon Sep 17 00:00:00 2001 From: rodri Date: Wed, 1 Feb 2023 16:04:54 +0000 Subject: vmodeled: added the ability to rotate a model. --- vmodeled/main.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'vmodeled') diff --git a/vmodeled/main.c b/vmodeled/main.c index 54001f8..32dae42 100644 --- a/vmodeled/main.c +++ b/vmodeled/main.c @@ -24,6 +24,7 @@ struct VModel RFrame worldrf; VModel *model; +double θ; double scale = 1; void resized(void); @@ -131,8 +132,13 @@ drawvmodel(Image *dst, VModel *mdl) scale, 0, 1, 0, scale, 1, 0, 0, 1, + }, R = { + cos(θ), -sin(θ), 1, + sin(θ), cos(θ), 1, + 0, 0, 1, }; + mulm(S, R); p = mdl->pts; for(s = mdl->strokefmt; s != 0 && p-mdl->pts < mdl->npts; s++) switch(*s){ @@ -168,8 +174,24 @@ redraw(void) } void -rmb(Mousectl *, Keyboardctl *) +rmb(Mousectl *mc, Keyboardctl *) { + Point2 p; + double oldmθ, oldθ; + + p = fromscreen(mc->xy); + oldmθ = atan2(p.y, p.x); + oldθ = θ; + + for(;;){ + readmouse(mc); + if(mc->buttons != 4) + break; + p = fromscreen(mc->xy); + θ = oldθ + (atan2(p.y, p.x) - oldmθ); + fprint(2, "θ %g\n", θ); + redraw(); + } } void @@ -178,7 +200,7 @@ lmb(Mousectl *mc, Keyboardctl *) Point2 mpos; mpos = fromscreen(mc->xy); - fprint(2, "%v\n", mpos); + fprint(2, "mpos %v\n", mpos); } void -- cgit v1.2.3