Shadowrun: Awakened 29 September 2011 - Build 871
Functions
vol.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void LoadVol (scalarvol *)
void * newscalarvol (void *intex, vector min, vector max, int xs, int ys, int zs, char *fname, scalarvol *invol)
color scalar_volume_texture (vector *, texture *, ray *)

Function Documentation

void LoadVol ( scalarvol )

Definition at line 291 of file vol.cpp.

References scalarvol::data, MSG_0, MSG_ABORT, MSG_ERR, scalarvol::name, rt_getmem(), rt_ui_message(), scalarvol::xres, scalarvol::yres, and scalarvol::zres.

Referenced by scalar_volume_texture().

                              { 
  FILE * dfile;
  int status;
  char msgtxt[2048];
 
  dfile=fopen(vol->name, "r");
  if (dfile==NULL) {
    char msgtxt[2048];
    sprintf(msgtxt, "Vol: can't open %s for input!!! Aborting\n",vol->name); 
    rt_ui_message(MSG_ERR, msgtxt);
    rt_ui_message(MSG_ABORT, "Rendering Aborted.");
    exit(1);
  }  
 
  sprintf(msgtxt, "loading %dx%dx%d volume set from %s",
      vol->xres, vol->yres, vol->zres, vol->name);
  rt_ui_message(MSG_0, msgtxt);

  vol->data = (unsigned char *)rt_getmem(vol->xres * vol->yres * vol->zres);

  status=fread(vol->data, 1, (vol->xres * vol->yres * vol->zres), dfile);
}
void* newscalarvol ( void *  intex,
vector  min,
vector  max,
int  xs,
int  ys,
int  zs,
char *  fname,
scalarvol invol 
)

Definition at line 87 of file vol.cpp.

References texture::ambient, texture::col, texture::ctr, scalarvol::data, texture::diffuse, texture::img, texture::islight, scalarvol::loaded, scalarvol::name, newbox(), texture::obj, texture::opacity, scalarvol::opacity, texture::rot, rt_getmem(), scalar_volume_texture(), texture::scale, texture::shadowcast, texture::specular, texture::texfunc, texture::uaxs, texture::vaxs, vector::x, scalarvol::xres, vector::y, scalarvol::yres, vector::z, and scalarvol::zres.

Referenced by rt_scalarvol().

                                                                             {
  box * bx;
  texture * tx, * tex;
  scalarvol * vol;

  tex=(texture *)intex;
  tex->shadowcast = 0; /* doesn't cast a shadow */

  tx=(texture *)rt_getmem(sizeof(texture));

  /* is the volume data already loaded? */
  if (invol==NULL) {
    vol=(scalarvol *)rt_getmem(sizeof(scalarvol));
    vol->loaded=0;
    vol->data=NULL;
  }
  else
    vol=invol;

  vol->opacity=tex->opacity;
  vol->xres=xs;
  vol->yres=ys;
  vol->zres=zs;
  strcpy(vol->name, fname);

  tx->ctr.x = 0.0;
  tx->ctr.y = 0.0;
  tx->ctr.z = 0.0;
  tx->rot   = tx->ctr;
  tx->scale = tx->ctr;
  tx->uaxs  = tx->ctr;
  tx->vaxs  = tx->ctr;

  tx->islight = 0;
  tx->shadowcast = 0; /* doesn't cast a shadow */

  tx->col = tex->col;
  tx->ambient  = 1.0;
  tx->diffuse  = 0.0;
  tx->specular = 0.0;
  tx->opacity  = 1.0;
  tx->img = vol;
  tx->texfunc = (color(*)(void *, void *, void *))(scalar_volume_texture);

  bx=newbox(tx, min, max);
  tx->obj = (void *) bx; /* XXX hack! */

  return (void *) bx;
}
color scalar_volume_texture ( vector ,
texture ,
ray  
)

Definition at line 169 of file vol.cpp.

References color::b, ray::d, scalarvol::data, FHUGE, color::g, texture::img, scalarvol::loaded, LoadVol(), box::max, box::min, ray::o, texture::obj, scalarvol::opacity, color::r, shade_transmission(), box::tex, VoxelColor(), vector::x, scalarvol::xres, vector::y, scalarvol::yres, vector::z, and scalarvol::zres.

Referenced by newscalarvol().

                                                                   {
  color col, col2;
  box * bx;
  flt a, tx1, tx2, ty1, ty2, tz1, tz2;
  flt tnear, tfar;
  flt t, tdist, dt, sum, tt; 
  vector pnt, bln;
  scalarvol * vol;
  flt scalar, transval; 
  int x, y, z;
  unsigned char * ptr;

  bx=(box *) tex->obj;
  vol=(scalarvol *)bx->tex->img;
   
  col.r=0.0;
  col.g=0.0;
  col.b=0.0;
 
  tnear= -FHUGE;
  tfar= FHUGE;
 
  if (ry->d.x == 0.0) {
    if ((ry->o.x < bx->min.x) || (ry->o.x > bx->max.x)) return col;
  }
  else {
    tx1 = (bx->min.x - ry->o.x) / ry->d.x;
    tx2 = (bx->max.x - ry->o.x) / ry->d.x;
    if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; }
    if (tx1 > tnear) tnear=tx1;
    if (tx2 < tfar)   tfar=tx2;
  }
  if (tnear > tfar) return col;
  if (tfar < 0.0) return col;
 
 if (ry->d.y == 0.0) {
    if ((ry->o.y < bx->min.y) || (ry->o.y > bx->max.y)) return col;
  }
  else {
    ty1 = (bx->min.y - ry->o.y) / ry->d.y;
    ty2 = (bx->max.y - ry->o.y) / ry->d.y;
    if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; }
    if (ty1 > tnear) tnear=ty1;
    if (ty2 < tfar)   tfar=ty2;
  }
  if (tnear > tfar) return col;
  if (tfar < 0.0) return col;
 
  if (ry->d.z == 0.0) {
    if ((ry->o.z < bx->min.z) || (ry->o.z > bx->max.z)) return col;
  }
  else {
    tz1 = (bx->min.z - ry->o.z) / ry->d.z;
    tz2 = (bx->max.z - ry->o.z) / ry->d.z;
    if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; }
    if (tz1 > tnear) tnear=tz1;
    if (tz2 < tfar)   tfar=tz2;
  }
  if (tnear > tfar) return col;
  if (tfar < 0.0) return col;
 
  if (tnear < 0.0) tnear=0.0;
 
  tdist=sqrt((flt) (vol->xres*vol->xres + vol->yres*vol->yres + vol->zres*vol->zres));
  tt = (vol->opacity / tdist); 

  bln.x=fabs(bx->min.x - bx->max.x);
  bln.y=fabs(bx->min.y - bx->max.y);
  bln.z=fabs(bx->min.z - bx->max.z);
  
  dt=sqrt(bln.x*bln.x + bln.y*bln.y + bln.z*bln.z) / tdist; 
  sum=0.0;

  /* move the volume residency check out of loop.. */
  if (!vol->loaded) {
    LoadVol(vol);
    vol->loaded=1;
  }
 
  for (t=tnear; t<=tfar; t+=dt) {
    pnt.x=((ry->o.x + (ry->d.x * t)) - bx->min.x) / bln.x;
    pnt.y=((ry->o.y + (ry->d.y * t)) - bx->min.y) / bln.y;
    pnt.z=((ry->o.z + (ry->d.z * t)) - bx->min.z) / bln.z;
 
    x=(int) ((vol->xres - 1.5) * pnt.x + 0.5);
    y=(int) ((vol->yres - 1.5) * pnt.y + 0.5);
    z=(int) ((vol->zres - 1.5) * pnt.z + 0.5);
   
    ptr = vol->data + ((vol->xres * vol->yres * z) + (vol->xres * y) + x);
   
    scalar = (flt) ((flt) 1.0 * ((int) ptr[0])) / 255.0;

    sum += tt * scalar; 

    transval = tt * scalar; 

    col2 = VoxelColor(scalar);

    if (sum < 1.0) {
      col.r += transval * col2.r;
      col.g += transval * col2.g;
      col.b += transval * col2.b;
      if (sum < 0.0) sum=0.0;
    }  
    else { 
      sum=1.0;
    }
  }

  if (sum < 1.0) {      /* spawn transmission rays / refraction */    
    color transcol;

    transcol = shade_transmission(ry, hit, 1.0 - sum);

    col.r += transcol.r; /* add the transmitted ray  */    
    col.g += transcol.g; /* to the diffuse and       */
    col.b += transcol.b; /* transmission total..     */  
  }

  return col;
}

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net