[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31140] branches/soc-2010-merwin: more experiments and ramblings
Mike Erwin
significant.bit at gmail.com
Sat Aug 7 12:52:24 CEST 2010
Revision: 31140
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31140
Author: merwin
Date: 2010-08-07 12:52:24 +0200 (Sat, 07 Aug 2010)
Log Message:
-----------
more experiments and ramblings
Modified Paths:
--------------
branches/soc-2010-merwin/experimental/TabletDeviceData.c
branches/soc-2010-merwin/notes/week 10 notes
Added Paths:
-----------
branches/soc-2010-merwin/experimental/helpers.c
branches/soc-2010-merwin/experimental/prev_ndof_view3d.c
branches/soc-2010-merwin/notes/week 11 notes
Modified: branches/soc-2010-merwin/experimental/TabletDeviceData.c
===================================================================
--- branches/soc-2010-merwin/experimental/TabletDeviceData.c 2010-08-07 10:18:59 UTC (rev 31139)
+++ branches/soc-2010-merwin/experimental/TabletDeviceData.c 2010-08-07 10:52:24 UTC (rev 31140)
@@ -49,7 +49,7 @@
// also look at wmEvent fields and size:
-typedef struct wmEvent {
+typedef struct {
struct wmEvent *next, *prev;
short type; /* event code itself (short, is also in keymap) */
@@ -80,12 +80,45 @@
} wmEvent;
+typedef struct {
+ struct wmEvent *next, *prev;
+
+ short type; /* event code itself (short, is also in keymap) */
+ short val; /* press, release, scrollvalue */
+ short x, y; /* mouse pointer position, screen coord */
+ short mval[2]; /* region mouse position, name convention pre 2.5 :) */
+ char ascii; /* from ghost */
+
+ /* previous state */
+ short prevtype;
+ short prevval;
+ short prevx, prevy;
+ double prevclicktime;
+ short prevclickx, prevclicky;
+
+ /* modifier states */
+ short shift : 2;
+ short ctrl : 2;
+ short alt : 2;
+ short oskey : 2; /* oskey is apple or windowskey, value denotes order of pressed */
+ short keymodifier; /* rawkey modifier */
+
+ /* keymap item, set by handler (weak?) */
+ const char *keymap_idname;
+
+ /* custom data */
+ short custom : 7; /* custom data type, stylus, 6dof, see wm_event_types.h */
+ short customdatafree : 1;
+ void *customdata; /* ascii, unicode, mouse coords, angles, vectors, dragdrop info */
+
+} wmEvent2;
+
int main()
{
// nice & compact?
printf("tool = %d bytes\n", sizeof(TabletTool));
printf("data = %d bytes\n", sizeof(TabletToolData));
- printf("wmEvent = %d bytes\n", sizeof(wmEvent));
+ printf("wmEvent2 = %d bytes\n", sizeof(wmEvent2));
puts("---------------------");
Added: branches/soc-2010-merwin/experimental/helpers.c
===================================================================
--- branches/soc-2010-merwin/experimental/helpers.c (rev 0)
+++ branches/soc-2010-merwin/experimental/helpers.c 2010-08-07 10:52:24 UTC (rev 31140)
@@ -0,0 +1,54 @@
+#include <math.h>
+
+// given separate tilts for each axis, compute the overall tilt (ignoring angle)
+float overall_tilt(float tilt_x, float tilt_y)
+ {
+ // will this do the trick?
+ return hypotf(tilt_x, tilt_y);
+ }
+
+
+// returns angular velocity (0..1), fills axis of rotation
+float ndof_to_angle_axis(const float ndof[3], float axis[3])
+ {
+ const float x = ndof[0];
+ const float y = ndof[1];
+ const float z = ndof[2];
+
+ float angular_velocity = sqrtf(x*x + y*y + z*z);
+
+ float scale = 1.f / angular_velocity;
+
+ // normalize
+ axis[0] = scale * x;
+ axis[1] = scale * y;
+ axis[2] = scale * z;
+
+ return angular_velocity;
+ }
+
+// returns angular velocity (-1..+1), fills axis of rotation
+// axis will be in "upper" hemisphere
+float ndof_to_angle_axis_up(const float ndof[3], float axis[3])
+ {
+ const float x = ndof[0];
+ const float y = ndof[1];
+ const float z = ndof[2];
+
+ float angular_velocity = sqrtf(x*x + y*y + z*z);
+
+ float scale = 1.f / angular_velocity;
+
+ if (z > 0)
+ {
+ angular_velocity = -angular_velocity;
+ scale = -scale;
+ }
+
+ // normalize axis
+ axis[0] = scale * x;
+ axis[1] = scale * y;
+ axis[2] = scale * z;
+
+ return angular_velocity;
+ }
Property changes on: branches/soc-2010-merwin/experimental/helpers.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added: branches/soc-2010-merwin/experimental/prev_ndof_view3d.c
===================================================================
--- branches/soc-2010-merwin/experimental/prev_ndof_view3d.c (rev 0)
+++ branches/soc-2010-merwin/experimental/prev_ndof_view3d.c 2010-08-07 10:52:24 UTC (rev 31140)
@@ -0,0 +1,389 @@
+/* ********************* NDOF ************************ */
+/* note: this code is confusing and unclear... (ton) */
+/* **************************************************** */
+
+// ndof scaling will be moved to user setting.
+// In the mean time this is just a place holder.
+
+// Note: scaling in the plugin and ghostwinlay.c
+// should be removed. With driver default setting,
+// each axis returns approx. +-200 max deflection.
+
+// The values I selected are based on the older
+// polling i/f. With event i/f, the sensistivity
+// can be increased for improved response from
+// small deflections of the device input.
+
+
+// lukep notes : i disagree on the range.
+// the normal 3Dconnection driver give +/-400
+// on defaut range in other applications
+// and up to +/- 1000 if set to maximum
+// because i remove the scaling by delta,
+// which was a bad idea as it depend of the system
+// speed and os, i changed the scaling values, but
+// those are still not ok
+
+
+float ndof_axis_scale[6] = {
+ +0.01, // Tx
+ +0.01, // Tz
+ +0.01, // Ty
+ +0.0015, // Rx
+ +0.0015, // Rz
+ +0.0015 // Ry
+};
+
+void filterNDOFvalues(float *sbval)
+{
+ int i=0;
+ float max = 0.0;
+
+ for (i =0; i<6;i++)
+ if (fabs(sbval[i]) > max)
+ max = fabs(sbval[i]);
+ for (i =0; i<6;i++)
+ if (fabs(sbval[i]) != max )
+ sbval[i]=0.0;
+}
+
+// statics for controlling rv3d->dist corrections.
+// viewmoveNDOF zeros and adjusts rv3d->ofs.
+// viewmove restores based on dz_flag state.
+
+int dz_flag = 0;
+float m_dist;
+
+void viewmoveNDOFfly(ARegion *ar, View3D *v3d, int mode)
+{
+ RegionView3D *rv3d= ar->regiondata;
+ int i;
+ float phi;
+ float dval[7];
+ // static fval[6] for low pass filter; device input vector is dval[6]
+ static float fval[6];
+ float tvec[3],rvec[3];
+ float q1[4];
+ float mat[3][3];
+ float upvec[3];
+
+
+ /*----------------------------------------------------
+ * sometimes this routine is called from headerbuttons
+ * viewmove needs to refresh the screen
+ */
+// XXX areawinset(ar->win);
+
+
+ // fetch the current state of the ndof device
+// XXX getndof(dval);
+
+ if (v3d->ndoffilter)
+ filterNDOFvalues(fval);
+
+ // Scale input values
+
+// if(dval[6] == 0) return; // guard against divide by zero
+
+ for(i=0;i<6;i++) {
+
+ // user scaling
+ dval[i] = dval[i] * ndof_axis_scale[i];
+ }
+
+
+ // low pass filter with zero crossing reset
+
+ for(i=0;i<6;i++) {
+ if((dval[i] * fval[i]) >= 0)
+ dval[i] = (fval[i] * 15 + dval[i]) / 16;
+ else
+ fval[i] = 0;
+ }
+
+
+ // force perspective mode. This is a hack and is
+ // incomplete. It doesn't actually effect the view
+ // until the first draw and doesn't update the menu
+ // to reflect persp mode.
+
+ rv3d->persp = RV3D_PERSP;
+
+
+ // Correct the distance jump if rv3d->dist != 0
+
+ // This is due to a side effect of the original
+ // mouse view rotation code. The rotation point is
+ // set a distance in front of the viewport to
+ // make rotating with the mouse look better.
+ // The distance effect is written at a low level
+ // in the view management instead of the mouse
+ // view function. This means that all other view
+ // movement devices must subtract this from their
+ // view transformations.
+
+ if(rv3d->dist != 0.0) {
+ dz_flag = 1;
+ m_dist = rv3d->dist;
+ upvec[0] = upvec[1] = 0;
+ upvec[2] = rv3d->dist;
+ copy_m3_m4(mat, rv3d->viewinv);
+ mul_m3_v3(mat, upvec);
+ sub_v3_v3(rv3d->ofs, upvec);
+ rv3d->dist = 0.0;
+ }
+
+
+ // Apply rotation
+ // Rotations feel relatively faster than translations only in fly mode, so
+ // we have no choice but to fix that here (not in the plugins)
+ rvec[0] = -0.5 * dval[3];
+ rvec[1] = -0.5 * dval[4];
+ rvec[2] = -0.5 * dval[5];
+
+ // rotate device x and y by view z
+
+ copy_m3_m4(mat, rv3d->viewinv);
+ mat[2][2] = 0.0f;
+ mul_m3_v3(mat, rvec);
+
+ // rotate the view
+
+ phi = normalize_v3(rvec);
+ if(phi != 0) {
+ axis_angle_to_quat(q1,rvec,phi);
+ mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, q1);
+ }
+
+
+ // Apply translation
+
+ tvec[0] = dval[0];
+ tvec[1] = dval[1];
+ tvec[2] = -dval[2];
+
+ // the next three lines rotate the x and y translation coordinates
+ // by the current z axis angle
+
+ copy_m3_m4(mat, rv3d->viewinv);
+ mat[2][2] = 0.0f;
+ mul_m3_v3(mat, tvec);
+
+ // translate the view
+
+ sub_v3_v3(rv3d->ofs, tvec);
+
+
+ /*----------------------------------------------------
+ * refresh the screen XXX
+ */
+
+ // update render preview window
+
+// XXX BIF_view3d_previewrender_signal(ar, PR_DBASE|PR_DISPRECT);
+}
+
+void viewmoveNDOF(Scene *scene, ARegion *ar, View3D *v3d, int mode)
+{
+ RegionView3D *rv3d= ar->regiondata;
+ float fval[7];
+ float dvec[3];
+ float sbadjust = 1.0f;
+ float len;
+ short use_sel = 0;
+ Object *ob = OBACT;
+ float m[3][3];
+ float m_inv[3][3];
+ float xvec[3] = {1,0,0};
+ float yvec[3] = {0,-1,0};
+ float zvec[3] = {0,0,1};
+ float phi;
+ float q1[4];
+ float obofs[3];
+ float reverse;
+ //float diff[4];
+ float d, curareaX, curareaY;
+ float mat[3][3];
+ float upvec[3];
+
+ /* Sensitivity will control how fast the view rotates. The value was
+ * obtained experimentally by tweaking until the author didn't get dizzy watching.
+ * Perhaps this should be a configurable user parameter.
+ */
+ float psens = 0.005f * (float) U.ndof_pan; /* pan sensitivity */
+ float rsens = 0.005f * (float) U.ndof_rotate; /* rotate sensitivity */
+ float zsens = 0.3f; /* zoom sensitivity */
+
+ const float minZoom = -30.0f;
+ const float maxZoom = 300.0f;
+
+ //reset view type
+ rv3d->view = 0;
+//printf("passing here \n");
+//
+ if (scene->obedit==NULL && ob && !(ob->mode & OB_MODE_POSE)) {
+ use_sel = 1;
+ }
+
+ if((dz_flag)||rv3d->dist==0) {
+ dz_flag = 0;
+ rv3d->dist = m_dist;
+ upvec[0] = upvec[1] = 0;
+ upvec[2] = rv3d->dist;
+ copy_m3_m4(mat, rv3d->viewinv);
+ mul_m3_v3(mat, upvec);
+ add_v3_v3(rv3d->ofs, upvec);
+ }
+
+ /*----------------------------------------------------
+ * sometimes this routine is called from headerbuttons
+ * viewmove needs to refresh the screen
+ */
+// XXX areawinset(curarea->win);
+
+ /*----------------------------------------------------
+ * record how much time has passed. clamp at 10 Hz
+ * pretend the previous frame occurred at the clamped time
+ */
+// now = PIL_check_seconds_timer();
+ // frametime = (now - prevTime);
+ // if (frametime > 0.1f){ /* if more than 1/10s */
+ // frametime = 1.0f/60.0; /* clamp at 1/60s so no jumps when starting to move */
+// }
+// prevTime = now;
+ // sbadjust *= 60 * frametime; /* normalize ndof device adjustments to 100Hz for framerate independence */
+
+ /* fetch the current state of the ndof device & enforce dominant mode if selected */
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list