The Coolest function I've written all year

Yep. Writing myself a little plug-in to make my Remote Wonder work when playing DVDs with Media Player Classic.

MPC is OLE compliant, so you can send it commands like

PostMessage( hMediaPlayerClassic, WM_COMMAND, ID_NAVIGATE_ROOTMENU );

The standard VCR/DVD fast-forward/fast-reverse commands are possible by repeatedly sending one of the seek messages you see below. I’ve reserved holding down the remote control button for ID_PLAY_SEEKxWARDSMALL. So one button press to seek medium speed, two button presses to seek fast, and hold to seek slow.

Without further ado

procedure seek_spam( hWin: HWND; msg: integer; dwData: DWORD; r_esult: LRESULT ); stdcall;
  // function
  //   Repeatedly trigger the mpc Seek command at exactly the speed that mpc
  //   can respond to its message queue without locking the plug-in's
  //   process.
  //   Consider:
  //   - No system TIMER object resources are consumed.
  //   - MPC's message queue will not be overflowed.
  //   - The remote control buttons are instantly responsive to the user's
  //     input. The user will not have to wait for backlogged key events to
  //     exhaust themselves before acting on new commands.
  //   Win32 API SendMessageCallback() returns immediately like PostMessage(),
  //   yet still informs the poster that the target has read the message by
  //   means of a callback. To make life interesting, the callback function
  //   is the sending function: *this* function. Because of the non-blocking
  //   nature of the call, this doesn't cause a call-stack overload. Also,
  //   since the system won't call two different functions in the same thread
  //   at the same time, there is no need for a semaphore or other monitor on
  //   the exit variable (seek_speed). Neat, huh?
  //   What that means is that an infinite loop is possible if the proper
  //   exit conditions (which are external to this function) are removed!!!
  //   Exit conditions are:
  //     1. HandleKey().post() is called
  //     2. seek_speed is one of 2 or -2 when entering the RMCTRL_FF/RW
  //        switch below in the HandleKey() function body.
  // arguments
  //   hWin    Must be the handle to the mpc window (hMediaPlayerClassic).
  //   ...     All other arguments are ignored.
  case seek_speed of
    -2: SendMessageCallback( hWin, WM_COMMAND, ID_PLAY_SEEKBACKWARDLARGE,
          0, @seek_spam, 0 );
    -1: SendMessageCallback( hWin, WM_COMMAND, ID_PLAY_SEEKBACKWARDMED,
          0, @seek_spam, 0 );
     0: ;
     1: SendMessageCallback( hWin, WM_COMMAND, ID_PLAY_SEEKFORWARDMED,
          0, @seek_spam, 0 );
     2: SendMessageCallback( hWin, WM_COMMAND, ID_PLAY_SEEKFORWARDLARGE,
          0, @seek_spam, 0 )

If you understand why this is so cool, then you’re a super-geek. Honorary pocket protector to you!

If enough people actually care and want to know why this is cool, I’ll tell you later…

If you are sooo good…

Could you code in Blender a zoom in/out relative to the cursor position like any other major CG app out there?
It is said to be easy but nobody cares

isn’t alt MMB the function you mean, Alvaro?

isn’t alt MMB the function you mean, Alvaro?

No. Zoom +/- relative to the cursor position is a common feature in many CG applications.

Your zoom +/- in mouse weel would be done according to the cursor position in the 3Dwindows (now is just linear zoom +/-). This little difference would make the mouse weel zoom a powerful visualisation tool, because combines two tools in one (zoom and pan)

Is a common feature out there. It’s has been requested. It is relatively easy to implement. I wouldn’t affect current Blender workflow (if you keep the cursor in the center of the 3Dwindows, it would make a linear zoom in/out as before)

sorry for the offtopic.

Very funky function, now to be called a funktion. Always nice to make something work yourself.

Sorry for being completely off-topic:

Your zoom +/- in mouse weel would be done according to the cursor position in the 3Dwindows (now is just linear zoom +/-). This little difference would make the mouse weel zoom a powerful visualisation tool, because combines two tools in one (zoom and pan)

I don’t know if this would annoy me or not. Often I centre the view on my model and zoom in+out from there. That way I can rotate around it more cleanly.

Now, if I had to put my cursor in the centre every time that would slow me down. However, it might speed others up. Perhaps a toggle button for this, with all the other zoom options? It might make sense to have it enabled normally, if it is common in other programs, but it would be nice if older users can keep very basic parts of their workflow unchanged.

Oh, as a side note, the zoom must ONLY take into account the initial position of the cursor, so you can keep the smooth zooming (because otherwise you can’t move the cursor to zoom).


What he means is that Blender zooms in and out along a line that travels directly through the center of the 3D View window to your eyes. If you want to zoom in on something that is not in the direct center of the 3D View you usually have to zoom, pan, zoom, pan, etc. a few times.

What he would like to see is a zoom that moves in and out along a line that travels from where the cursor is (when you begin zooming) out to your eyes. That would make it very easy to zoom in on a detail that is not in the direct center of the 3D View. Just place the cursor over the item you want to examine and MMB drag to zoom in. Or place the cursor on the screen where you want the item to be when you zoom out and MMD drag to zoom out.

I’ve said too often that I’d try to do something, but my ever-increasing course load makes any commitment impossible. In fairness, the mpc plugin I wrote is only about 150-200 lines of code total, not counting whitespace and comments. Classes started yesterday, so I’ll look into it if I can, but no promises.

Also, the functionality you’re asking for isn’t exactly trivial in perspective mode.

I actually thought a function that called itself recursively would just hang up and I was impressed that it doesn’t but I’m guessing maybe it is something better.

It probably wouldn’t have to be much, I impress myself when I get Hello World right. Sometimes I spell either Hello or World wrongly. :slight_smile:

It’s not that hard actually, you just have to zoom on the vector resulting from the projection of the 2d mouse to 3d space.

As far as zooming on the selection center (or 3D cursor) goes, half the work is already done for the “Around Active” viewport rotation option.

It’s just that people don’t care enough/have other things more important to do.


Actually, you’ve got the point. It works because Windows calls my function, which then schedules Windows to call my function again, ad infinitum. In essense it’s an infinite mutual recursion. Stack space is constant because of the client (my fn) server (win32) relationship.

The other neat part is that what stops the recursion is the value of the variable seek_speed. The odd part is that using a variable like this is usually a very bad idea, but in this case, even though there are two threads accessing it (one directly and the other indirectly --making a sort of implied data monitor), there is no possibility of error.

Hmm, so it is. The problem is really all the time it would take me to familiarize myself with the code that does it (since blender code is woefully under-documented) and to implement and test it. My Theory of Numbers class looks like it’s going to really eat my time so right now I just “have other things more important to do”. So sad. :frowning: