Esempio n. 1
0
void MovingDots::updateDots() {
    //
    // Update positions
    //
    
    const GLint numValidDots = std::min(previousNumDots, currentNumDots);
    const GLfloat dt = GLfloat(currentTime - previousTime) / 1.0e6f;
    const GLfloat dr = dt * previousSpeed / previousFieldRadius;
    
    for (GLint i = 0; i < numValidDots; i++) {
        GLfloat &age = getAge(i);
        age += dt;
        
        if ((age <= previousLifetime) || (previousLifetime == 0.0f)) {
            advanceDot(i, dt, dr);
        } else {
            replaceDot(i, newDirection(previousCoherence), 0.0f);
        }
    }
    
    //
    // Update directions
    //
    
    if (currentCoherence != previousCoherence) {
        for (GLint i = 0; i < numValidDots; i++) {
            getDirection(i) = newDirection(currentCoherence);
        }
    }
    
    //
    // Update lifetimes
    //
    
    if (currentLifetime != previousLifetime) {
        for (GLint i = 0; i < numValidDots; i++) {
            getAge(i) = newAge(currentLifetime);
        }
    }
    
    //
    // Add/remove dots
    //
    
    if (currentNumDots != previousNumDots) {
        dotPositions.resize(currentNumDots * componentsPerDot);
        dotDirections.resize(currentNumDots);
        dotAges.resize(currentNumDots);
        
        for (GLint i = previousNumDots; i < currentNumDots; i++) {
            replaceDot(i, newDirection(currentCoherence), newAge(currentLifetime));
        }
    }
}
Esempio n. 2
0
float planeHitTest( Plane plane,  Ray ray )
{
   vec3 direction = unit(ray.dir);
   vec3 position;
   vec3 normal = unit(plane.normal);
   direction.x = -direction.x;
   direction.y = -direction.y;
   direction.z = -direction.z;
   position.x = ray.pos.x;
   position.y = ray.pos.y;
   position.z = ray.pos.z;

   float vd = dot(normal, direction);
   if((distance < 0 && vd > -0.0001) || (distance > 0 && vd < 0.0001))
      return -1;
   float v0 = dot(newDirection(plane.point, position), plane.normal);
   float t = v0/vd;
   //make sure its pointing right directions
   if( t < 0 )
      t = -t;
   if( t < 0.001)
      return -1;
   return t;

}
Esempio n. 3
0
int createInitRays( Ray **rays, int width, int height, Camera cam )
{
   vec3 right = unit(cam.right);
   vec3 up = unit(cam.up);
   float rightUnitX = right.x;
   float rightUnitY = right.y;
   float rightUnitZ = right.z;
   float upUnitX = up.x;
   float upUnitY = up.y;
   float upUnitZ = up.z;
   vec3 uv = unit(newDirection(cam.lookat, cam.pos));

   *rays = (Ray *) malloc( sizeof(Ray) *height*width );
   for( int i = 0; i < height; i++)
   {
      for( int j = 0; j < width ; j ++ )
      {
         float u = cam.l + (cam.r-cam.l)*( (float)j)/(float)width;
         float v = cam.b + (cam.t-cam.b)*( (float)i)/(float)height;
         float w = -1;
         int c = i*width + j;

         (*rays)[c].pos = cam.pos;
         (*rays)[c].dir.x = u * rightUnitX + v * upUnitX + -w * uv.x;
         (*rays)[c].dir.y = u * rightUnitY + v * upUnitY + -w * uv.y;
         (*rays)[c].dir.z = u * rightUnitZ + v * upUnitZ + -w * uv.z;
         (*rays)[c].i = i;
         (*rays)[c].j = j;
      }
   }
   return width * height;
}
Esempio n. 4
0
//DONE
//given path --> find if next coordinate is outside of map
//not sure if i need to check for size of char array
static int isLegalPathToCamp(path destination) {
    assert(strlen(destination)  <  PATH_LIMIT);
    int isLegal = TRUE;
    int i = 0;
    coordinates oldxy;
    coordinates newxy;
    oldxy.x = 5;
    oldxy.y = 0;
    oldxy.direction = SOUTH_EAST;
    newxy = oldxy;
    //testing if is even legal path input
    while(destination[i] != '\0'  &&  i < PATH_LIMIT) {
        if(!(destination[i] == 'L' ||
             destination[i] == 'R' || destination[i] == 'B')) {
            isLegal = FALSE;
        }
        i++;
    }
    //code for checking size of char array
    //testing if path goes into water
    i = 0;
    while(isLegal == TRUE  &&  destination[i] != '\0'  &&
          i < PATH_LIMIT) {
        newxy = newCoords(newxy, destination[i]);
        newxy.direction = newDirection(newxy.direction,
                                       destination[i]);
        if(isInBounds(newxy) == FALSE) {
            isLegal = FALSE;
        }
        i++;
    }
    return isLegal;
}
int assistServe(int out[],int time,
				int *direction/*-2 for vacant
								0 for pause
								-1,1 respectively for downward and upward*/,
				Input in[],
				int in_size)
{
	int keySitu[3][9]={0}/*to save situation of keys
							[1][]for internal,[2][]for external up,[0][]for external down,[][n]for n+1 floor
							1 for selected, 0 for not*/,
		floor=out[time]-1,
		drt=-2/*direction prepared*//*-2 for vacant*/;

	int transform(Input*,int,int,int,int[][9],int*);
	int newDirection(int[][9],int,int*,int);
	int killOrder(Input in[],int direction, int floor,int size);

	if(!transform(in,in_size,time,floor,keySitu,&drt))/*empty*/{
		*direction=-2;
		out[time+1]=100*out[time];
		return -2;
	}
	else /*not empty*/
	{
		newDirection(keySitu,floor,&*direction,drt);

		if(keySitu[1][floor] ||
			(keySitu[0][floor] && *direction==-1) || 
			(keySitu[2][floor] && *direction==1))//need to pause
		{
			out[time+1]=out[time];
			//kill keySitu
			keySitu[1][floor]=0; 
			if(*direction==-2)
				keySitu[0][floor]=keySitu[2][floor]=0;
			else
				keySitu[1+*direction][floor]=0;

			killOrder(in,*direction,floor,in_size);//kill orders done
			return 0;/*0 for need to pause*/
		}
		else//needn't to pause, that's to move
		{
			if(*direction==-2)//pause at last interval
				*direction=drt;
			if(*direction==-2){
				out[time+1]=out[time];
				return *direction;//return -2 for didn't move
			}
			else{//direction != -2, is to move
				out[time+1]=out[time]+*direction;
				return *direction;
			}
		}
	}
}
Esempio n. 6
0
//DONE
//tests given a path returns the coordinates it points to
static coordinates getCoords(path vertexPath) {
    coordinates xycoord;
    xycoord.x = 5;
    xycoord.y = 0;
    xycoord.direction = SOUTH_EAST;
    int i = 0;
    while(i < PATH_LIMIT  &&  vertexPath[i] != '\0') {  
        xycoord = newCoords(xycoord, vertexPath[i]);
        xycoord.direction = newDirection(xycoord.direction,
                                         vertexPath[i]);
        i++;
    }
    return xycoord;
}
Esempio n. 7
0
void control( void )
{
	while (1)
	{
	 	if ( isWait() )
			waiting();	

		eleStat.dir = newDirection( eleStat.dir, eleStat.floor );

		if ( isStop( eleStat.dir, eleStat.floor ) )
			stop( eleStat.dir, eleStat.floor );


		showDir( eleStat.dir );

		if ( eleStat.dir != 0 && !isStop( eleStat.dir, eleStat.floor ) )
			move( eleStat.dir, &eleStat.floor );
	}			 
}
Esempio n. 8
0
void MovingDots::advanceDot(GLint i, GLfloat dt, GLfloat dr) {
    GLfloat &x = getX(i);
    GLfloat &y = getY(i);
    GLfloat &theta = getDirection(i);
    
    x += dr * std::cos(theta);
    y += dr * std::sin(theta);
    
    if (x*x + y*y > 1.0f) {
        theta = newDirection(previousCoherence);
        
        GLfloat y1 = rand(-1.0f, 1.0f);
        GLfloat x1 = -std::sqrt(1.0f - y1*y1) + rand(0.0f, dr);
        
        x = x1*std::cos(theta) - y1*std::sin(theta);
        y = x1*std::sin(theta) + y1*std::cos(theta);
        
        getAge(i) = newAge(previousLifetime);
    }
}
Esempio n. 9
0
Color directIllumination( Intersection inter, Scene scene )
{
   Color ret;
   ret.r = 0;
   ret.b = 0;
   ret.g = 0;

   for( int i = 0; i < scene.numPointLights; i++ )
   {
      PointLight temp = scene.pointLights[i];
      vec3 lvec = unit(newDirection(temp.pos, inter.hitMark ));

      float nlDot = dot(lvec, inter.normal );
      bool inShadow = false;
      float lightDistance = distance( temp.pos, inter.hitMark );

      //contruct possible hits for shadow ray using bvh
      for( int j = 0; j < scene.numSpheres; j++ )
      {
         Ray shadowRay;
         shadowRay.pos = inter.hitMark;
         shadowRay.dir = lvec;
         float t = sphereHitTest(scene.spheres[j], shadowRay );
         if( t > 0 )
         {
            Intersection info = sphereIntersection( scene.spheres[j], shadowRay, t );
            if(info.hit)
            {
               if( distance( info.hitMark, inter.hitMark ) < lightDistance )
               {
                  inShadow = true;
                  break;
               }
            }
         }
      }

      ObjectInfo shadowInter;
      if( !inShadow )
      {
         vec3 r;
         r.x = -lvec.x + 2 * nlDot * inter.normal.x;
         r.y = -lvec.y + 2 * nlDot * inter.normal.y;
         r.z = -lvec.z + 2 * nlDot * inter.normal.z;
         r = unit(r);
         float rvDot = dot(r, unit(inter.viewVector));
         if(nlDot < 0)
            nlDot = 0;
         if(rvDot < 0)
            rvDot = 0;
         float powRV = pow( rvDot, 1.0/inter.colorInfo.finish_roughness );

         ret.r  =ret.r + temp.color.r * powRV*inter.colorInfo.finish_specular;
         ret.g = ret.g + temp.color.g* powRV*inter.colorInfo.finish_specular;
         ret.b = ret.b + temp.color.b * powRV*inter.colorInfo.finish_specular;
         ret.r+= inter.colorInfo.pigment.r * temp.color.r * nlDot*inter.colorInfo.finish_diffuse;
         ret.g += inter.colorInfo.pigment.g * temp.color.g * nlDot*inter.colorInfo.finish_diffuse;
         ret.b+= inter.colorInfo.pigment.b * temp.color.b * nlDot*inter.colorInfo.finish_diffuse;
         ret = limitColor( ret );
      }
   }
   //1.5 not 1 to increase the directlight which will be balanced in Util/tga.cpp during gamma correction
   float mod = 1;//.2 - finish_reflection - pigment_f*finish_refraction;
   ret.r = ret.r * mod;
   ret.g = ret.g * mod;
   ret.b = ret.b * mod;
   return ret;
}
Esempio n. 10
0
//creates a new (random) start position for a new grain, returns beginning start sample
//sets up size and direction
//max grain size is BUFLENGTH / 3, to avoid recording into grains while they are playing
float newSetup(t_munger *x, int whichVoice, double frames)
{
	float newPosition;
	int i;
	
	x->gvoiceSize[whichVoice] 		= newSize(x, whichVoice);
	x->gvoiceDirection[whichVoice] 	= newDirection(x);
	
	if(x->num_channels == 2) {
		x->gvoiceLPan[whichVoice] 		= ((float)rand() - RAND_MAX * 0.5) * ONE_OVER_MAXRAND * x->gpan_spread + 0.5;
		x->gvoiceRPan[whichVoice]		= 1. - x->gvoiceLPan[whichVoice];
		//make equal power panning....
		//x->gvoiceLPan[whichVoice] 		= powf(x->gvoiceLPan[whichVoice], 0.5);
		//x->gvoiceRPan[whichVoice] 		= powf(x->gvoiceRPan[whichVoice], 0.5);
	}
	else {
		for(i=0;i<x->num_channels;i++) {
			x->gvoiceSpat[whichVoice][i] = x->channelGain[i] + ((float)rand() - RAND_MAX * 0.5) * ONE_OVER_HALFRAND * x->channelGainSpread[i];
		}
	}
	
	x->gvoiceOn[whichVoice] 		= 1;
	x->gvoiceDone[whichVoice]		= 0;
	x->gvoiceGain[whichVoice]		= x->gain + ((float)rand() - RAND_MAX * 0.5) * ONE_OVER_HALFRAND * x->randgain;
	
	x->gvoiceADSRon[whichVoice]		= 0;
	
	if(x->gvoiceSize[whichVoice] < 2.*x->rampLength) {
		x->gvoiceRamp[whichVoice] = .5 * x->gvoiceSize[whichVoice];
		if(x->gvoiceRamp[whichVoice] <= 0.) x->gvoiceRamp[whichVoice] = 1.;
		x->gvoiceOneOverRamp[whichVoice] = 1./x->gvoiceRamp[whichVoice];
	}
	else {
		x->gvoiceRamp[whichVoice] = x->rampLength;
		if(x->gvoiceRamp[whichVoice] <= 0.) x->gvoiceRamp[whichVoice] = 1.;
		x->gvoiceOneOverRamp[whichVoice] = 1./x->gvoiceRamp[whichVoice];
	}
	
	
/*** set start point; tricky, cause of moving buffer, variable playback rates, backwards/forwards, etc.... ***/

	if(!x->externalBuffer) {
		// 1. random positioning and moving buffer (default)
		if(x->position == -1. && x->recordOn == 1) { 
			if(x->gvoiceDirection[whichVoice] == 1) {//going forward			
				if(x->gvoiceSpeed[whichVoice] > 1.) 
					newPosition = x->recordCurrent - x->onethirdBufsize - (float)rand() * ONE_OVER_MAXRAND * x->onethirdBufsize;
				else
					newPosition = x->recordCurrent - (float)rand() * ONE_OVER_MAXRAND * x->onethirdBufsize;//was 2/3rds
			}
			
			else //going backwards
				newPosition = x->recordCurrent - (float)rand() * ONE_OVER_MAXRAND * x->onethirdBufsize;
		}
		
		// 2. fixed positioning and moving buffer	
		else if (x->position >= 0. && x->recordOn == 1) {
			if(x->gvoiceDirection[whichVoice] == 1) {//going forward			
				if(x->gvoiceSpeed[whichVoice] > 1.) 
					//newPosition = x->recordCurrent - x->onethirdBufsize - x->position * x->onethirdBufsize;
					//this will follow more closely...
					newPosition = x->recordCurrent - x->gvoiceSize[whichVoice]*x->gvoiceSpeed[whichVoice] - x->position * x->onethirdBufsize;
					
				else
					newPosition = x->recordCurrent - x->position * x->onethirdBufsize;//was 2/3rds
			}
			
			else //going backwards
				newPosition = x->recordCurrent - x->position * x->onethirdBufsize;
		}
		
		// 3. random positioning and fixed buffer	
		else if (x->position == -1. && x->recordOn == 0) {
			if(x->gvoiceDirection[whichVoice] == 1) {//going forward			
				newPosition = x->recordCurrent - x->onethirdBufsize - (float)rand() * ONE_OVER_MAXRAND * x->onethirdBufsize;
			}	
			else //going backwards
				newPosition = x->recordCurrent - (float)rand() * ONE_OVER_MAXRAND * x->onethirdBufsize;
		}
		
		// 4. fixed positioning and fixed buffer	
		else if (x->position >= 0. && x->recordOn == 0) {
			if(x->gvoiceDirection[whichVoice] == 1) {//going forward			
				newPosition = x->recordCurrent - x->onethirdBufsize - x->position * x->onethirdBufsize;
			} else { //going backwards
				newPosition = x->recordCurrent - x->position * x->onethirdBufsize;
            }
		}
	}
	else {
		if (x->position == -1.) {
			newPosition = (float)rand() * ONE_OVER_MAXRAND * frames;
		} else if (x->position >= 0.) {
            newPosition = x->position * frames;
        } else {
            newPosition = 0.0;
        }
	}
	
	return newPosition;
	
}