Пример #1
0
//
// P_MakeSlope
//
// Alocates and fill the contents of a slope structure.
//
static pslope_t *P_MakeSlope(const v3float_t *o, const v2float_t *d, 
                             const float zdelta, bool isceiling)
{
   pslope_t *ret = (pslope_t *)(Z_Malloc(sizeof(pslope_t), PU_LEVEL, NULL));
   memset(ret, 0, sizeof(*ret));

   ret->o.x = M_FloatToFixed(ret->of.x = o->x);
   ret->o.y = M_FloatToFixed(ret->of.y = o->y);
   ret->o.z = M_FloatToFixed(ret->of.z = o->z);

   ret->d.x = M_FloatToFixed(ret->df.x = d->x);
   ret->d.y = M_FloatToFixed(ret->df.y = d->y);

   ret->zdelta = M_FloatToFixed(ret->zdeltaf = zdelta);

   {
      v3float_t v1, v2, v3, d1, d2;
      float len;

      v1.x = o->x;
      v1.y = o->y;
      v1.z = o->z;

      v2.x = v1.x;
      v2.y = v1.y + 10.0f;
      v2.z = P_GetZAtf(ret, v2.x, v2.y);

      v3.x = v1.x + 10.0f;
      v3.y = v1.y;
      v3.z = P_GetZAtf(ret, v3.x, v3.y);

      if(isceiling)
      {
         M_SubVec3f(&d1, &v1, &v3);
         M_SubVec3f(&d2, &v2, &v3);
      }
      else
      {
         M_SubVec3f(&d1, &v1, &v2);
         M_SubVec3f(&d2, &v3, &v2);
      }

      M_CrossProduct3f(&ret->normalf, &d1, &d2);

      len = (float)sqrt(ret->normalf.x * ret->normalf.x +
                        ret->normalf.y * ret->normalf.y + 
                        ret->normalf.z * ret->normalf.z);

      ret->normalf.x /= len;
      ret->normalf.y /= len;
      ret->normalf.z /= len;
   }

   return ret;
}
Пример #2
0
//
// R_CalcSlope
//
// SoM: Calculates the rslope info from the OHV vectors and rotation/offset 
// information in the plane struct
//
static void R_CalcSlope(visplane_t *pl)
{
   // This is where the crap gets calculated. Yay
   double         xl, yl, tsin, tcos;
   double         ixscale, iyscale;
   rslope_t       *rslope = &pl->rslope;
   texture_t      *tex = textures[pl->picnum];

   if(!pl->pslope)
      return;

   
   tsin = sin(pl->angle);
   tcos = cos(pl->angle);
   
   xl = tex->width;
   yl = tex->height;

   // SoM: To change the origin of rotation, add an offset to P.x and P.z
   // SoM: Add offsets? YAH!
   rslope->P.x = -pl->xoffsf * tcos - pl->yoffsf * tsin;
   rslope->P.z = -pl->xoffsf * tsin + pl->yoffsf * tcos;
   rslope->P.y = P_GetZAtf(pl->pslope, (float)rslope->P.x, (float)rslope->P.z);

   rslope->M.x = rslope->P.x - xl * tsin;
   rslope->M.z = rslope->P.z + xl * tcos;
   rslope->M.y = P_GetZAtf(pl->pslope, (float)rslope->M.x, (float)rslope->M.z);

   rslope->N.x = rslope->P.x + yl * tcos;
   rslope->N.z = rslope->P.z + yl * tsin;
   rslope->N.y = P_GetZAtf(pl->pslope, (float)rslope->N.x, (float)rslope->N.z);

   M_TranslateVec3(&rslope->P);
   M_TranslateVec3(&rslope->M);
   M_TranslateVec3(&rslope->N);

   M_SubVec3(&rslope->M, &rslope->M, &rslope->P);
   M_SubVec3(&rslope->N, &rslope->N, &rslope->P);
   
   M_CrossProduct3(&rslope->A, &rslope->P, &rslope->N);
   M_CrossProduct3(&rslope->B, &rslope->P, &rslope->M);
   M_CrossProduct3(&rslope->C, &rslope->M, &rslope->N);

   // This is helpful for removing some of the muls when calculating light.

   rslope->A.x *= 0.5f;
   rslope->A.y *= 0.5f / view.focratio;
   rslope->A.z *= 0.5f;

   rslope->B.x *= 0.5f;
   rslope->B.y *= 0.5f / view.focratio;
   rslope->B.z *= 0.5f;

   rslope->C.x *= 0.5f;
   rslope->C.y *= 0.5f / view.focratio;
   rslope->C.z *= 0.5f;

   rslope->zat = P_GetZAtf(pl->pslope, pl->viewxf, pl->viewyf);

   // More help from randy. I was totally lost on this... 
   ixscale = view.tan / (float)xl;
   iyscale = view.tan / (float)yl;

   rslope->plight = (slopevis * ixscale * iyscale) / (rslope->zat - pl->viewzf);
   rslope->shade = 256.0f * 2.0f - (pl->lightlevel + 16.0f) * 256.0f / 128.0f;
}