Examples of Setting Effect Direction
Single-Axis Effects
Setting up the direction for a single-axis effect is extremely simple, because there is really nothing to specify. You put the DIEFF_CARTESIAN flag in the dwFlags member of the DIEFFECT structure and set rglDirection to point to a single LONG containing the value 0.
The following example sets up the direction and axis parameters for an x-axis effect:
DIEFFECT eff;
LONG lZero = 0; // No direction
DWORD dwAxis = DIJOFS_X; // x-axis effect
ZeroMemory(&eff, sizeof(DIEFFECT));
eff.cAxes = 1; // One axis
eff.dwFlags =
DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; // Flags
eff.rglDirection = &lZero; // Direction
eff.rgdwAxes = &dwAxis; // Axis for effect
Two-Axis Effects with Polar Coordinates
Setting up the direction for a polar two-axis effect is only a little more complicated. You set the DIEFF_POLAR flag in dwFlags and set rglDirection to point to an array of two LONGs. The first element in this array is the direction you want the effect to come from. The second element in the array must be zero.
The following example sets up the direction and axis parameters for a two-axis effect coming from the east:
DIEFFECT eff;
LONG rglDirection = { 90 * DI_DEGREES, 0 }; // 90 degrees from
// north, i.e. east
DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y }; // x- and y-axis
ZeroMemory(&eff, sizeof(DIEFFECT));
eff.cAxes = 2; // Two axes
eff.dwFlags =
DIEFF_POLAR | DIEFF_OBJECTOFFSETS; // Flags
eff.rglDirection = rglDirection; // Direction
eff.rgdwAxes = rgdwAxes; // Axis for effect
Two-Axis Effects with Cartesian Coordinates
Setting up the direction for a Cartesian two-axis effect is a bit trickier, but not by much. You set the DIEFF_CARTESIAN flag in dwFlags and again set rglDirection to point to an array of two LONGs. This time the first element in the array is the x-coordinate of the direction vector, and the second is the y-coordinate.
The following example sets up the direction and axis parameters for a two-axis effect coming from the east:
DIEFFECT eff;
LONG rglDirection = { 1, 0 }; // Positive x = east
DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y }; // x- and y-axis
ZeroMemory(&eff, sizeof(DIEFFECT));
eff.cAxes = 2; // Two axes
eff.dwFlags =
DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; // Flags
eff.rglDirection = rglDirection; // Direction
eff.rgdwAxes = rgdwAxes; // Axis for effect