shithub: 3dee

Download patch

ref: a8c810950efd587b9f46d6ddfa0de4930939ae9f
parent: 153df8095d25c82adb8e79f2334700b7c1c09044
author: rodri <rgl@antares-labs.eu>
date: Sat Jun 14 06:42:19 EDT 2025

plot3: add camera orbit control

--- a/plot3.c
+++ b/plot3.c
@@ -39,6 +39,7 @@
 
 Mousectl *mctl;
 Keyboardctl *kctl;
+Mouse om;
 Channel *drawc;
 Image *screenb;
 Plot theplot;
@@ -261,12 +262,38 @@
 }
 
 void
+lmb(void)
+{
+	static Quaternion orient = {1,0,0,0};
+	Quaternion Δorient;
+	Point3 v;
+
+	if((om.buttons^mctl->buttons) != 0)
+		return;
+
+	Δorient = orient;
+	qball(screen->r, om.xy, mctl->xy, &orient, nil);
+	Δorient = mulq(Δorient, invq(orient));
+
+	/* orbit camera around the center */
+	v = subpt3(cam->p, theplot.bbox.c);
+	v = vcs2world(cam, qsandwichpt3(Δorient, world2vcs(cam, v)));
+	movecamera(cam, addpt3(theplot.bbox.c, v));
+	aimcamera(cam, theplot.bbox.c);
+
+	redrawb();
+}
+
+void
 mouse(void)
 {
+	if(mctl->buttons & 1)
+		lmb();
 	if(mctl->buttons & 8)
 		zoomin();
 	if(mctl->buttons & 16)
 		zoomout();
+	om = mctl->Mouse;
 }
 
 void
--