[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29678] branches/soc-2010-merwin: added working notes, exploratiions and mis-steps

Mike Erwin significant.bit at gmail.com
Fri Jun 25 02:07:04 CEST 2010


Revision: 29678
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29678
Author:   merwin
Date:     2010-06-25 02:07:03 +0200 (Fri, 25 Jun 2010)

Log Message:
-----------
added working notes, exploratiions and mis-steps

Added Paths:
-----------
    branches/soc-2010-merwin/notes/
    branches/soc-2010-merwin/notes/NSEvent.txt
    branches/soc-2010-merwin/notes/week 1 notes
    branches/soc-2010-merwin/notes/week 2 notes
    branches/soc-2010-merwin/notes/week 3 notes
    branches/soc-2010-merwin/notes/week 4 notes
    branches/soc-2010-merwin/notes/week 5 notes

Added: branches/soc-2010-merwin/notes/NSEvent.txt
===================================================================
--- branches/soc-2010-merwin/notes/NSEvent.txt	                        (rev 0)
+++ branches/soc-2010-merwin/notes/NSEvent.txt	2010-06-25 00:07:03 UTC (rev 29678)
@@ -0,0 +1,57 @@
+
+28 May --
+
+
+from NSEvent.h (Tiger+):
+
+enum {        /* event subtypes for mouse events */
+    NSMouseEventSubtype             = NX_SUBTYPE_DEFAULT,
+    NSTabletPointEventSubtype       = NX_SUBTYPE_TABLET_POINT,
+    NSTabletProximityEventSubtype   = NX_SUBTYPE_TABLET_PROXIMITY
+};
+
+/* pointer types for NSTabletProximity events or mouse events with subtype NSTabletProximityEventSubtype*/
+enum {        
+    NSUnknownPointingDevice     = NX_TABLET_POINTER_UNKNOWN,
+    NSPenPointingDevice         = NX_TABLET_POINTER_PEN,
+    NSCursorPointingDevice      = NX_TABLET_POINTER_CURSOR,
+    NSEraserPointingDevice      = NX_TABLET_POINTER_ERASER
+};
+typedef NSUInteger NSPointingDeviceType;
+
+-------------
+
+NSEvent* e;
+
+float x = [e pressure] valid for all mouse (click, drag, release) and tablet prox events
+[e deviceID] for tablet events
+[e absoluteX] in tablet space, similar for Y and Z
+NSPoint tilt = [e tilt] -1 to +1 for x and y
+[e isEnteringProximity] is pen approaching or withdrawing?
+[e timestamp] in milliseconds
+
+And here's what I'm looking for:
+
+/* Enable or disable coalescing of mouse movement events, including mouse moved, mouse dragged, and tablet events.  Coalescing is enabled by default.
+*/
++ (void)setMouseCoalescingEnabled:(BOOL)flag;
++ (BOOL)isMouseCoalescingEnabled;
+
+Wacom's example uses Carbon for this. I never found a CGEvent version, which saddens me...
+
+NSPoint mouse = [NSEvent mouseLocation]; // not immediately useful, but interesting
+
+
+when precision tool starts (mouse/pen down)
+	[NSEvent setMouseCoalescingEnabled: NO];
+
+when precision tool stops (mouse/pen up)
+	[NSEvent setMouseCoalescingEnabled: YES];
+
+---------
+
+No check for mouse subtypes in GHOST_SystemCocoa.mm. It handles only TabletPoint and TabletProximity with handleTabletEvent(). Within this function is the tip vs. eraser test. The handleMouseEvent function tests for tablet subtypes for each of up, down, drag and calls handleTabletEvent if needed. Of these, only handleMouseEvent posts the event to blender, with tablet function only adding certain fields.
+
+Oh! Most likely need a break; after line 1481. Will fix this and start hacking after another sync with head and commit.
+
+Blender code likes to repeat itself... Factor some stuff out?


Property changes on: branches/soc-2010-merwin/notes/NSEvent.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: branches/soc-2010-merwin/notes/week 1 notes
===================================================================
--- branches/soc-2010-merwin/notes/week 1 notes	                        (rev 0)
+++ branches/soc-2010-merwin/notes/week 1 notes	2010-06-25 00:07:03 UTC (rev 29678)
@@ -0,0 +1,266 @@
+
+Hello, blender!
+
+26 May --
+
+Tonight I'm browsing through the code, looking for useful tidbits.
+
+intern/ghost/
+intern/ghost/intern/
+source/blender/blenlib/intern/
+
+in math_vector.c:
+void print_v3(char *str, float v[3])
+
+GHOST_System[Cocoa|Carbon|Win32|X11]
+
+Ghost NDoF manager is weird. Polling, not event driven? Is plugin a regular shared libarary? Mac plugin has internal callback, so more event driven than Windows. Unsure about X11.
+
+No multiple monitors, at least in Cocoa. Also no screen mode setting (just getting) because of Snow Leopard. Why would this be useful anyway?
+
+
+from GHOST_Types.h:
+
+/* Xtilt and Ytilt represent how much the pen is tilted away from 
+ * vertically upright in either the X or Y direction, with X and Y the
+ * axes of the tablet surface.
+ * In other words, Xtilt and Ytilt are components of a vector created by projecting
+ * the pen's angle in 3D space vertically downwards on to the XY plane
+ * --Matt
+ */
+typedef enum {
+	GHOST_kTabletModeNone = 0,
+	GHOST_kTabletModeStylus,
+	GHOST_kTabletModeEraser
+} GHOST_TTabletMode;
+
+typedef struct GHOST_TabletData {
+	GHOST_TTabletMode Active; /* 0=None, 1=Stylus, 2=Eraser */
+	float Pressure;	/* range 0.0 (not touching) to 1.0 (full pressure) */
+	float Xtilt;	/* range 0.0 (upright) to 1.0 (tilted fully against the tablet surface) */
+	float Ytilt;	/* as above */
+} GHOST_TabletData;
+
+...
+
+/* original patch used floats, but the driver return ints and uns. We will calibrate in view, no sense on doing conversions twice */
+/* as all USB device controls are likely to use ints, this is also more future proof */
+//typedef struct {
+//   /** N-degree of freedom device data */
+//   float tx, ty, tz;   /** -x left, +y up, +z forward */
+//   float rx, ry, rz;
+//   float dt;
+//} GHOST_TEventNDOFData;
+
+typedef struct {
+   /** N-degree of freedom device data v2*/
+   int changed;
+   GHOST_TUns64 client;
+   GHOST_TUns64 address;
+   GHOST_TInt16 tx, ty, tz;   /** -x left, +y up, +z forward */
+   GHOST_TInt16 rx, ry, rz;
+   GHOST_TInt16 buttons;
+   GHOST_TUns64 time;
+   GHOST_TUns64 delta;
+} GHOST_TEventNDOFData;
+
+typedef int     (*GHOST_NDOFLibraryInit_fp)();
+typedef void    (*GHOST_NDOFLibraryShutdown_fp)(void* deviceHandle);
+typedef void*   (*GHOST_NDOFDeviceOpen_fp)(void* platformData);
+
+// original patch windows callback. In mac os X version the callback is internal to the plug-in and post an event to main thead.
+// not necessary faster, but better integration with other events. 
+
+//typedef int     (*GHOST_NDOFEventHandler_fp)(float* result7, void* deviceHandle, unsigned int message, unsigned int* wParam, unsigned long* lParam);
+//typedef void     (*GHOST_NDOFCallBack_fp)(GHOST_TEventNDOFDataV2 *VolDatas);
+
+------
+
+Regarding the above code: do all supported ndof devices use similar integer values? Support SpaceNav only? Why not normalize to floats and send those, like before? Separate ndof button events? Separate tablet button events?
+
+Device plugin should send events to blender, simple as that. Init plugin with a function to inject events into the main blender app. No shared data areas, no callbacks, just events! See how the SpaceNav plugins do it now, and go from there. Didn't see anything about tablet buttons in existing code. Are these mapped to key combos by the driver? I know it's possible to pass raw button events to specific apps, and would prefer to do it that way. 
+
+Ask Matt about blender event system, after a bit of reading. How are events propogated? Use Cocoa as reference point, as he's also a Mac programmer. Can I just send events to blender, and it routes them to interested parties? I hope so.
+
+
+from gpencil_paint.c:
+
+/* check if the current mouse position is suitable for adding a new point */
+static short gp_stroke_filtermval (tGPsdata *p, int mval[2], int pmval[2])
+{
+	int dx= abs(mval[0] - pmval[0]);
+	int dy= abs(mval[1] - pmval[1]);
+	
+	/* if buffer is empty, just let this go through (i.e. so that dots will work) */
+	if (p->gpd->sbuffer_size == 0)
+		return 1;
+	
+	/* check if mouse moved at least certain distance on both axes (best case) */
+	else if ((dx > MIN_MANHATTEN_PX) && (dy > MIN_MANHATTEN_PX))
+		return 1;
+	
+	/* check if the distance since the last point is significant enough */
+	// future optimisation: sqrt here may be too slow?
+	else if (sqrt(dx*dx + dy*dy) > MIN_EUCLIDEAN_PX)
+		return 1;
+	
+	/* mouse 'didn't move' */
+	else
+		return 0;
+}
+
+and my version:
+
+static short gp_stroke_filtermval (tGPsdata *p, int mval[2], int pmval[2])
+{
+	/* if buffer is empty, just let this go through (i.e. so that dots will work) */
+	if (p->gpd->sbuffer_size == 0)
+		return 1;
+	else {
+		/* check if the distance since the last point is significant enough
+		   no need for abs() or sqrt(), and don't bother checking Manhattan distance (ok?) */
+
+		int dx= mval[0] - pmval[0];
+		int dy= mval[1] - pmval[1];
+	
+		if ((dx*dx + dy*dy) > (MIN_EUCLIDEAN_PX * MIN_EUCLIDEAN_PX))
+			return 1;
+	}
+
+	/* pencil 'didn't move' if we make it this far */
+	return 0;
+}
+
+---------
+
+Looking through tuples/vectors/points (intern/moto/include/). Messy, but ok. Point is-a Vector is-a Tuple, for each of 2, 3, 4 dimensions.
+
+  MoTo - 3D Motion Toolkit 
+  Copyright (C) 2000  Gino van den Bergen <gino at acm.org>
+
+Tuple:
+	get/set one or all components
+	test for equality
+	simple output
+	no copy constructor...
+
+Vector2:
+	members:
+	+=(Vector) -=(Vector) *=(Scalar) /=(Scalar),
+	dot, mag, mag2, absolute, normalize, normalized, scale(x,y), scaled(x,y) fuzzyZero
+	angle(v), cross(v), triple(v1,v2), closestAxis
+
+	static:
+	random
+	
+	non-members:
+	+(v,v) -(v,v) -(v) *(s,v) *(v,s) /(v,s)
+	dot, len, len2, fuzzyZero, fuzzyEqual, angle, cross, triple
+
+Well... author should've made up mind about member vs. non-member, and with arg order (thinking of the duplicate *()). Also, make up your mind about single or double precision. Let the compiler cast to internal format. Well-placed consts! Overdose of inline. Non-member functions simply call member functions. Ew. Vec2 declares cross product (which puzzled me) but no implementation. Same for triple product and random. Vectors duplicate Tuple constructors. Is that necessary with public inheritance? 
+
+Vector3 diff:
+	noiseGate(threshold): sets near-zero vectors to zero (mag <= threshold^2)
+	safe_normalized(): more cautious
+	scale(x,y,z), scaled(x,y,z)
+	*(v,v): same as dot
+	absolute: flips each component into 1st octant
+	implements cross and triple products
+
+Vector3::random() uses spherical coordinates. Compare with my old version. Also not sure about blender's angle-from-vectors code.
+
+Vector4 diff:
+	no cross or triple products, also no random
+
+Moving on to the Point classes...
+
+Point2:
+	same constructors as Vector2 and Tuple2
+	+=(v) -=(v)
+	=(v) copy constructor
+	dist(p) dist2(p)
+	lerp
+	
+	non-members:
+	+(p,v), -(p,v) return points
+	-(p,p) returns vector
+	dist(p,p), dist2(p,p)
+	lerp
+
+Point3 diff:
+	=(v), =(p) copy constructors... why both?
+
+Quaternion is derived from Vector4, but I won't tackle that.
+
+-------
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list