projection

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).
Author: Sputnki
License: BSD
Github: sptnk/math/projection.axo

Inlets

frac32 input x coordinate

frac32 input y coordinate

frac32 input z coordinate

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

frac32 mod input for the eye parameter

Outlets

frac32 projected x

frac32 projected y

Parameters

frac32.u.map scaling of the projected coordinate

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

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);
}
Control Rate
int32_t eye = param_eye + inlet_eye;
int32_t scale = param_scale + (inlet_scale);
outlet_Px = calc_Px(inlet_x, inlet_y, inlet_z, scale, eye);
outlet_Py = calc_Py(inlet_x, inlet_y, inlet_z, scale, eye);

Privacy

© 2024 Zrna Research