示例#1
0
double HUD_Transform(LWViewportInfo *ViewGlobal, int view, Matrix xf)
{
    double z, mat[9];
    z = HUD_Depth(ViewGlobal, view);
    ViewGlobal->xfrm(view, mat);
    VCPY(xf[0], mat);
    VCPY(xf[1], &(mat[3]) );
    VCPY(xf[2], &(mat[6]) );
    VSCL(xf[0],z);
    VSCL(xf[1],z);
    VSCL(xf[2],z);
    return z;
}
示例#2
0
void co_Arrow(const LWCustomObjAccess *cobjAcc, double pos[3], double vec[3], double mag, int csys)
{
    double endp[3],r[3],v[3],hed[3], c[3];

    VADDS3(endp,pos,vec,mag);
    r[0] = vec[1] - vec[2]; /* perp vector */
    r[1] = vec[2] - vec[0];
    r[2] = vec[0] - vec[1];

    (*cobjAcc->line)(cobjAcc->dispData, pos,endp,csys);
    VADDS3(hed,pos,vec,mag*0.90);
    VCROSS(v,r,vec);  // perp to v,r
    mag *= 0.025;
    VSCL(v,mag);
    VSCL(r,mag);
    VSUB3(c,hed,v);
    VADD(v,hed);
    (*cobjAcc->triangle)(cobjAcc->dispData, v,c,endp,csys);
    VSUB3(c,hed,r);
    VADD(r,hed);
    (*cobjAcc->triangle)(cobjAcc->dispData, r,c,endp,csys);
}
示例#3
0
文件: atmosphere.cpp 项目: dbw/lwpp
void Atmosphere::raymarchEval(lwpp::VolumetricAccess va)
{
   double density = 100.0, falloff = 10.0;
   double integstart = 0.0, integend = 100.0;
   double minstepsize = 0.01, maxstepsize = 100.0;
   double k = 200.0;
   double fogclr[ 3 ];
   int use_lighting = 1, atmos_type = type;

   double dtau, last_dtau, total_tau, rstep, tau, x, y, h, col[ 4 ], trans;
   int nsteps = 0;                  /* record number of integration steps */
   double li[ 3 ], last_li[ 3 ];
   LWVolumeSample sample;           /* differential color & opacity */
   // ORIGINALLY  LWDVector PP;
   lwpp::Point3D PP;
   LWMicropol mp;

   k *= res;
   falloff *= fa;
   density /= den;

   h = hi - lo;
   if ( h == 0 ) return;

   /* if using a texture, initialize the micropolygon */

   if ( useTxtr ) {
      memset( &mp, 0, sizeof( LWMicropol ));
      mp.gNorm[ 1 ] = mp.wNorm[ 1 ] = 1.0;
      mp.oAxis = mp.wAxis = 1;
      mp.oScl[ 0 ] = mp.oScl[ 1 ] = mp.oScl[ 2 ] = 1.0;
   }

   /* get the fog color */

   if ( bck )
   {
	   const double origin[3] = {va.getOrigin().x,va.getOrigin().y, va.getOrigin().z };
	   backdropinfo->backdrop( time, origin, fogclr );
   } else
   {
      VCPY( fogclr, this->col );
   }

   /* assume initially that the ray origin is in the fog */

   sample.dist = va.getNearClip();

   /* below the fog bottom, looking up */

   if ( va.getDirection().y > 0 && va.getOrigin().y < lo ) {
      y = ( lo - va.getOrigin().y );
      x = y / va.getDirection().y;
      sample.dist = sqrt( x * x + y * y );
   }

   /* above the fog top, looking down */

   if ( va.getDirection().y < 0 && va.getOrigin().y > hi ) {
      y = ( hi - va.getOrigin().y );
      x = y / va.getDirection().y;
      sample.dist = sqrt( x * x + y * y );
   }

   /* test if intersection within clipping range */

   if ( sample.dist > va.getFarClip() ) return;

   // ORIGINALLY
   // VADDS3( PP, va.getOrigin(), va.getDirection(), sample.dist );
   PP = ((lwpp::Point3D(va.getOrigin()) + lwpp::Vector3D(va.getDirection())) *  sample.dist);

   y = ( PP.y - lo ) / h;

   /* test if outside fog */

   if (( y > 1 && va.getDirection().y > 0 ) || ( y < 0 && va.getDirection().y < 0 ))
      return;

   dtau = density * GADD( va, PP.asLWDVector(), y, falloff, use_lighting, atmos_type, li );
   rstep = 1.0 / ( k * dtau + 0.001 );
   sample.stride = sample.dist * MAX( MIN( CLAMP( rstep, minstepsize, maxstepsize ),
      va.getFarClip() - sample.dist ), 0.0005 );

   ++nsteps;
   total_tau = 0;

   while (( sample.dist <= va.getFarClip() )
      && ( total_tau * opa < 300 ) && ( nsteps < 200 )) {

      last_dtau = dtau;
      VCPY( last_li, li );
      // ORIGINALLY 
	  // VADDS3( PP, va.getOrigin(), va.getDirection(), sample.dist );

      y = ( upcomp( PP.asLWDVector() ) - lo ) / h;

      /* test if outside fog */

      if (( y > 1 && va.getDirection().y > 0 ) || ( y < 0 && va.getDirection().y < 0 ))
         return;

      dtau = density * GADD( va, PP.asLWDVector(), y, falloff, use_lighting, atmos_type, li );
      if ( !useTxtr ) {
         trans = 0;
         VSCL3( col, fogclr, lum );
      }
      else {
         trans = evalTexture( &mp, PP.asLWDVector(), sample.stride, col, txtr );
         VSCL( col, lum );
      }

      if ( trans != 1.0 ) {
         tau = 0.5 * sample.stride * ( dtau * ( 1.0 - trans ) + last_dtau );
         total_tau += tau;

         /* color */

         sample.color[ 0 ] = 0.5 * col[ 0 ] * sample.stride
            * ( li[ 0 ] * dtau + last_li[ 0 ] * last_dtau );
         sample.color[ 1 ] = 0.5 * col[ 1 ] * sample.stride
            * ( li[ 1 ] * dtau + last_li[ 1 ] * last_dtau );
         sample.color[ 2 ] = 0.5 * col[ 2 ] * sample.stride
            * ( li[ 2 ] * dtau + last_li[ 2 ] * last_dtau );

         /* opacity */

         VSET( sample.opacity, tau * opa );

         /* add volumetric sample to the ray */

         va.addSample( &sample );
      }

      /* new stride = f(dist) */

      rstep = 1.0 / ( k * dtau + 0.001 );
      sample.stride = sample.dist * MAX( MIN( CLAMP( rstep, minstepsize, maxstepsize ),
         va.getFarClip() - sample.dist ), 0.0005 );
      sample.dist += sample.stride;
      nsteps += 1;
   }
}
示例#4
0
static void SuperQ_Draw( sqData *tool, LWWireDrawAccess *draw )
{
   LWFVector top[ 4 ], bot[ 4 ], del;
   int x, y, z, i;

   if ( !tool->active )
      return;

   y = tool->axis;
   x = xax[ tool->axis ];
   z = zax[ tool->axis ];

   /* bounding box */

   draw->moveTo( draw->data, tool->top[ 0 ], LWWIRE_DASH );
   draw->lineTo( draw->data, tool->top[ 1 ], LWWIRE_ABSOLUTE );
   draw->lineTo( draw->data, tool->top[ 2 ], LWWIRE_ABSOLUTE );
   draw->lineTo( draw->data, tool->top[ 3 ], LWWIRE_ABSOLUTE );
   draw->lineTo( draw->data, tool->top[ 0 ], LWWIRE_ABSOLUTE );

   draw->moveTo( draw->data, tool->bot[ 0 ], LWWIRE_DASH );
   draw->lineTo( draw->data, tool->bot[ 1 ], LWWIRE_ABSOLUTE );
   draw->lineTo( draw->data, tool->bot[ 2 ], LWWIRE_ABSOLUTE );
   draw->lineTo( draw->data, tool->bot[ 3 ], LWWIRE_ABSOLUTE );
   draw->lineTo( draw->data, tool->bot[ 0 ], LWWIRE_ABSOLUTE );

   draw->lineTo( draw->data, tool->top[ 0 ], LWWIRE_ABSOLUTE );
   draw->moveTo( draw->data, tool->top[ 3 ], LWWIRE_DASH );
   draw->lineTo( draw->data, tool->bot[ 3 ], LWWIRE_ABSOLUTE );
   draw->moveTo( draw->data, tool->bot[ 2 ], LWWIRE_DASH );
   draw->lineTo( draw->data, tool->top[ 2 ], LWWIRE_ABSOLUTE );
   draw->moveTo( draw->data, tool->top[ 1 ], LWWIRE_DASH );
   draw->lineTo( draw->data, tool->bot[ 1 ], LWWIRE_ABSOLUTE );

   /* center crosshair */

   for ( i = 0; i < 3; i++ ) {
      VCPY( top[ i ], tool->center );
      VCPY( bot[ i ], tool->center);
   }

   VSUB3( del, tool->top[ 0 ], tool->bot[ 2 ] );
   VSCL( del, 0.25f );

   top[ 0 ][ z ] += del[ z ];
   bot[ 0 ][ z ] -= del[ z ];
   top[ 1 ][ x ] += del[ x ];
   bot[ 1 ][ x ] -= del[ x ];
   top[ 2 ][ y ] += del[ y ];
   bot[ 2 ][ y ] -= del[ y ];

   draw->moveTo( draw->data, top[ 0 ], LWWIRE_SOLID );
   draw->lineTo( draw->data, bot[ 0 ], LWWIRE_ABSOLUTE );
   draw->moveTo( draw->data, top[ 1 ], LWWIRE_SOLID );
   draw->lineTo( draw->data, bot[ 1 ], LWWIRE_ABSOLUTE );
   draw->moveTo( draw->data, top[ 2 ], LWWIRE_SOLID );
   draw->lineTo( draw->data, bot[ 2 ], LWWIRE_ABSOLUTE );

   /* handles for toroid hole */

   if ( tool->shape ) {
      VCPY( del, tool->center );
      draw->moveTo( draw->data, del, LWWIRE_DASH );
      draw->lineTo( draw->data, tool->holex, LWWIRE_ABSOLUTE );
      draw->circle( draw->data, 0.025, LWWIRE_SCREEN );
      draw->moveTo( draw->data, del, LWWIRE_DASH );
      draw->lineTo( draw->data, tool->holez, LWWIRE_ABSOLUTE );
      draw->circle( draw->data, 0.025, LWWIRE_SCREEN );
   }

   tool->dirty = 0;
}
示例#5
0
void raymarchEval( const LWVolumeAccess *va, AtmosphereData *dat )
{
   double density = 100.0, falloff = 10.0;
   double integstart = 0.0, integend = 100.0;
   double minstepsize = 0.01, maxstepsize = 100.0;
   double k = 200.0;
   double fogclr[ 3 ];
   int use_lighting = 1, atmos_type = dat->type;

   double dtau, last_dtau, total_tau, rstep, tau, x, y, h, col[ 4 ], trans;
   int nsteps = 0;                  /* record number of integration steps */
   double li[ 3 ], last_li[ 3 ];
   LWVolumeSample sample;           /* differential color & opacity */
   LWDVector PP;
   LWMicropol mp;


   k *= dat->res;
   falloff *= dat->fa;
   density /= dat->den;

   h = dat->hi - dat->lo;
   if ( h == 0 ) return;

   /* if using a texture, initialize the micropolygon */

   if ( dat->useTxtr ) {
      memset( &mp, 0, sizeof( LWMicropol ));
      mp.gNorm[ 1 ] = mp.wNorm[ 1 ] = 1.0;
      mp.oAxis = mp.wAxis = 1;
      mp.oScl[ 0 ] = mp.oScl[ 1 ] = mp.oScl[ 2 ] = 1.0;
   }

   /* get the fog color */

   if ( dat->bck )
      backdropinfo->backdrop( dat->time, va->dir, fogclr );
   else
      VCPY( fogclr, dat->col );

   /* assume initially that the ray origin is in the fog */

   sample.dist = va->nearClip;

   /* below the fog bottom, looking up */

   if ( va->dir[ 1 ] > 0 && va->o[ 1 ] < dat->lo ) {
      y = ( dat->lo - va->o[ 1 ] );
      x = y / va->dir[ 1 ];
      sample.dist = sqrt( x * x + y * y );
   }

   /* above the fog top, looking down */

   if ( va->dir[ 1 ] < 0 && va->o[ 1 ] > dat->hi ) {
      y = ( dat->hi - va->o[ 1 ] );
      x = y / va->dir[ 1 ];
      sample.dist = sqrt( x * x + y * y );
   }

   /* test if intersection within clipping range */

   if ( sample.dist > va->farClip ) return;

   VADDS3( PP, va->o, va->dir, sample.dist );
   y = ( upcomp( PP ) - dat->lo ) / h;

   /* test if outside fog */

   if (( y > 1 && va->dir[ 1 ] > 0 ) || ( y < 0 && va->dir[ 1 ] < 0 ))
      return;

   dtau = density * GADD( va, PP, y, falloff, use_lighting, atmos_type, li );
   rstep = 1.0 / ( k * dtau + 0.001 );
   sample.stride = sample.dist * MAX( MIN( CLAMP( rstep, minstepsize, maxstepsize ),
      va->farClip - sample.dist ), 0.0005 );

   ++nsteps;
   total_tau = 0;

   while (( sample.dist <= va->farClip )
      && ( total_tau * dat->opa < 300 ) && ( nsteps < 200 )) {

      last_dtau = dtau;
      VCPY( last_li, li );
      VADDS3( PP, va->o, va->dir, sample.dist );

      y = ( upcomp( PP ) - dat->lo ) / h;

      /* test if outside fog */

      if (( y > 1 && va->dir[ 1 ] > 0 ) || ( y < 0 && va->dir[ 1 ] < 0 ))
         return;

      dtau = density * GADD( va, PP, y, falloff, use_lighting, atmos_type, li );
      if ( !dat->useTxtr ) {
         trans = 0;
         VSCL3( col, fogclr, dat->lum );
      }
      else {
         trans = evalTexture( &mp, PP, sample.stride, col, dat->txtr );
         VSCL( col, dat->lum );
      }

      if ( trans != 1.0 ) {
         tau = 0.5 * sample.stride * ( dtau * ( 1.0 - trans ) + last_dtau );
         total_tau += tau;

         /* color */

         sample.color[ 0 ] = 0.5 * col[ 0 ] * sample.stride
            * ( li[ 0 ] * dtau + last_li[ 0 ] * last_dtau );
         sample.color[ 1 ] = 0.5 * col[ 1 ] * sample.stride
            * ( li[ 1 ] * dtau + last_li[ 1 ] * last_dtau );
         sample.color[ 2 ] = 0.5 * col[ 2 ] * sample.stride
            * ( li[ 2 ] * dtau + last_li[ 2 ] * last_dtau );

         /* opacity */

         VSET( sample.opacity, tau * dat->opa );

         /* add volumetric sample to the ray */

         va->addSample( va->ray, &sample );
      }

      /* new stride = f(dist) */

      rstep = 1.0 / ( k * dtau + 0.001 );
      sample.stride = sample.dist * MAX( MIN( CLAMP( rstep, minstepsize, maxstepsize ),
         va->farClip - sample.dist ), 0.0005 );
      sample.dist += sample.stride;
      nsteps += 1;
   }
}