projection s

Projects a 3D coordinate in a 2D system. Plane attribute allows to select which coordinate to project (the remaining coordinate corresponds to the eye coordinate). S-rate Scale and eye are interpolated.
Author: Sputnki
License: BSD
Github: sptnk/math/projection s.axo

Inlets

frac32buffer input x coordinate

frac32buffer input x coordinate

frac32buffer input x coordinate

frac32 mod input for the scale parameter (bitshifted left by 4 bits)

frac32 mod input for the eye parameter

Outlets

frac32buffer projected x

frac32buffer projected y

Parameters

frac32.s.map coordinate of the eye along the camera axis

frac32.u.map scaling of the projected coordinate

Attributes

combo plane of projection

Declaration
int32_t calc_Px(int32_t x, int32_t y, int32_t z, int32_t scale, int32_t eye) {
  float num;
  float den;
#if (attr_plane == 1) // plane xy, depth z
  {
    num = x;
    den = (eye)-z;
  }
#elif (attr_plane == 2) // plane yz, depth x
  {
    num = y;
    den = (eye)-x;
  }
#elif (attr_plane == 3) // plane zx, depth y
  {
    num = z;
    den = (eye)-y;
  }
#endif

  return (int32_t)scale * num / den;
}
int32_t calc_Py(int32_t x, int32_t y, int32_t z, int32_t scale, int32_t eye) {
  float num;
  float den;
#if (attr_plane == 1) // plane xy, depth z
  {
    num = y;
    den = (eye)-z;
  }
#elif (attr_plane == 2) // plane yz, depth x
  {
    num = z;
    den = (eye)-x;
  }
#elif (attr_plane == 3) // plane zx, depth y
  {
    num = x;
    den = (eye)-y;
  }
#endif

  return ((int32_t)scale * num / den);
}

int32_t eye = 0;
int32_t scale = 0;
Control Rate
int32_t eye_increment = param_eye + inlet_eye - eye >> 4;
int32_t scale_increment = param_scale + (inlet_scale)-scale >> 4;

for (int i = 0; i < BUFSIZE; i++) {
  outlet_Px[i] = calc_Px(inlet_x[i], inlet_y[i], inlet_z[i], scale, eye);
  outlet_Py[i] = calc_Py(inlet_x[i], inlet_y[i], inlet_z[i], scale, eye);

  eye += eye_increment;
  scale += scale_increment;
}

Privacy

© 2024 Zrna Research