SHARE
TWEET

Untitled

a guest Jul 25th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. C implementation of Havel-Herout
  2.  
  3. typedef struct {
  4.     vec3 n0; float d0;
  5.     vec3 n1; float d1;
  6.     vec3 n2; float d2;
  7. } isect_hh_data;
  8. void
  9. isect_hh_pre(vec3 v0, vec3 v1, vec3 v2, isect_hh_data *D) {
  10.     vec3 e1 = v3_sub(v1, v0);
  11.     vec3 e2 = v3_sub(v2, v0);
  12.     D->n0 = v3_cross(e1, e2);
  13.     D->d0 = v3_dot(D->n0, v0);
  14.  
  15.     float inv_denom = 1 / v3_dot(D->n0, D->n0);
  16.  
  17.     D->n1 = v3_scale(v3_cross(e2, D->n0), inv_denom);
  18.     D->d1 = -v3_dot(D->n1, v0);
  19.  
  20.     D->n2 = v3_scale(v3_cross(D->n0, e1), inv_denom);
  21.     D->d2 = -v3_dot(D->n2, v0);
  22. }
  23. inline bool
  24. isect_hh(vec3 o, vec3 d, float *t, vec2 *uv, isect_hh_data *D) {
  25.     float det = v3_dot(D->n0, d);
  26.     float dett = D->d0 - v3_dot(o, D->n0);
  27.     vec3 wr = v3_add(v3_scale(o, det), v3_scale(d, dett));
  28.     uv->x = v3_dot(wr, D->n1) + det * D->d1;
  29.     uv->y = v3_dot(wr, D->n2) + det * D->d2;
  30.     float tmpdet0 = det - uv->x - uv->y;
  31.     int pdet0 = ((int_or_float)tmpdet0).i;
  32.     int pdetu = ((int_or_float)uv->x).i;
  33.     int pdetv = ((int_or_float)uv->y).i;
  34.     pdet0 = pdet0 ^ pdetu;
  35.     pdet0 = pdet0 | (pdetu ^ pdetv);
  36.     if (pdet0 & 0x80000000)
  37.         return false;
  38.     float rdet = 1 / det;
  39.     uv->x *= rdet;
  40.     uv->y *= rdet;
  41.     *t = dett * rdet;
  42.     return *t >= ISECT_NEAR && *t <= ISECT_FAR;
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top