示例#1
0
 bool ChargeSystem::solve()
 {
   const double c_smallVelocitiesSq = 0.0001*0.0001;
   const int c_maxIters = 1000000;
   normalize();
   int n = d_particles.size();
   std::vector<PhasePoint> newPP( n );
   int iter = 0;
   do
   {
     for( int i = 0; i < n; ++i)
     {
       PhasePoint& pp = d_particles[i];
       PhasePoint& newpp = newPP[i];
       newpp.d_p = pp.d_p + d_t * pp.d_v;
       makeUnit(newpp.d_p);
       newpp.d_v = pp.d_v + d_t * getForce(i); // unit mass
       newpp.d_v -= (newpp.d_p * newpp.d_v) * newpp.d_p; // dv * dp == 0 always
     }
     d_particles.swap(newPP);
     ++iter;
   } 
   while( movement() > c_smallVelocitiesSq && iter < c_maxIters);
   return iter < c_maxIters;
 }
示例#2
0
文件: cesk.c 项目: sylvarant/RUSE-AM
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:    convertin
 *  Description:    convert the low level values into secure
 * =====================================================================================
 */
LOCAL VALUE convertin(OTHERVALUE ptr,TYPE goal){

    switch(ptr.b->t){

        case OTHERN(BOOLEAN) : {

            // check value
            if(ptr.b->value == RFALSE || ptr.b->value == RTRUE){

                // check type
                if(N(checkType)(ptr,goal)){

                    // build value
			        VALUE v;
				    v.b =  N(makeBoolean)(ptr.b->value);
                    return v;
                }
            }
            DEBUG_PRINT("Boolean conversion failed");
            exit(1);
        }

        case OTHERN(INT) : { 
            if(N(checkType)(ptr,goal)){

                // value check is simply done by taking bytes
			    VALUE v;
			    v.b = N(makeInt)(ptr.z->value);
                return v;          
			}
            DEBUG_PRINT("Int conversion failed");
            exit(1);
        }

        case OTHERN(UNIT) : {
            if(N(checkType)(ptr,goal)){
                VALUE v;
                v.b = makeUnit();
                return v;
            }
            DEBUG_PRINT("Unit conversion failed");
            exit(1);
        }

        default : {
                VALUE v;
                v.b =  makeSI(goal.byte,ptr.b);
                return v;
            }
    }
}
示例#3
0
/**
 * adds a unit to the list
 * adds to the topleft if applicable
 * assumes coordinates are correct
 * returns the unit
 */
static UnitsList addUnit(int x, int y, enum unitType type) {
	UnitsList newUnit = makeUnit(x, y, type);
		
	if(isEmptyList(globalUnitsList)) globalUnitsList = newUnit;
	else {
		newUnit->next = globalUnitsList;
		globalUnitsList->previous = newUnit;
		globalUnitsList = newUnit;
	}
	
	// adding to the topleft if it should be there.
	if (x <= 10 && y <= 10)
		topleft[x][y] = mark(type, actualPlayer);
	
	return newUnit;
}
示例#4
0
void calcColor(double *xx, double *yy, double *zz, double initR, double initG, double initB){
  
  double ambient = .2;
  double diffuse;
  double D = .5;
  double specularPower = 50;
  double specular;
  
  double vec1[3];
  double vec2[3];
  double normalV[3];
  double lightV[3];
  double r[3];
  
  double eyeV[3];
  
  int i;
  lightV[0] = lightPos[0] - xx[0];
  lightV[1] = lightPos[1] - yy[0];
  lightV[2] = lightPos[2] - zz[0];
  
  specular = (1 - ambient - D);
  
  vec1[0] = xx[1] - xx[0] ;
  vec1[1] = yy[1] - yy[0] ;
  vec1[2] = zz[1] - zz[0] ;
  
  vec2[0] = xx[2] - xx[0] ;
  vec2[1] = yy[2] - yy[0] ;
  vec2[2] = zz[2] - zz[0] ;
  
  eyeV[0] = 0 - xx[0] ;
  eyeV[1] = 0 - yy[0] ;
  eyeV[2] = 0 - zz[0] ;
  
  makeUnit(vec1);
  makeUnit(vec2);
  makeUnit(lightV);
  makeUnit(eyeV);
  
  crossProduct(normalV, vec1, vec2);
  
  makeUnit(normalV);
 		if(objectIsReversed[thisObj]){
  		for(i = 0; i < 3; i++){
  			normalV[i] = -normalV[i];
  		}
  		
  	}
  
  
  //printf("vec1: %lf %lf %lf\n", vec1[0], vec1[1], vec1[2]);
  
  double alpha = dotProduct(normalV, lightV);
  double intensity;
    if(alpha >= 0){
      diffuse = alpha;
    }else{
      diffuse = 0;
    }	
    
    for(i = 0; i < 3; i++){
      r[i] = 2*(alpha*normalV[i]) - lightV[i];
    }
    
    double beta = dotProduct(eyeV, r);
    if(beta >= 0){
      specular = beta;
    }else{
      specular = 0;
    }
    
    //printf("diffuse: %lf\n", diffuse);
    //printf("diffuse: %lf\n", diffuse);
    
    intensity = ambient + diffuse * D + pow(specular, specularPower) ;
  //}
  
  double rd, gn, bl;
  
  rd = initR * intensity;
  gn = initG * intensity;
  bl = initB * intensity;
  
  G_rgb(rd, gn, bl);
  
}
示例#5
0
int main( int argc, char *argv[] )
{
	unsigned int frames = 0;
	int   res;
	Mat4	projection_matrix;

	Mat4  viewMat;
	Mat4  rotMat;
	Mat4  modelMat;
	float aspect;
	float	dw, dh;
	
	int	debug_flag = 0;
	
	bcm_host_init();
	res = WinCreate( &g_sc );
	if( !res ) 
	{
		printf( "Create window error!\n" );
		return 0;
	}
	res = SurfaceCreate(&g_sc);
	if( !res ) 
	{
		printf( "Create surface error!\n" );
		return 0;
	}
	
	makeUnit(&viewMat);

	aspect = (float)g_sc.width / (float)g_sc.height;
	
	//makeProjectionMatrix(&g_sp.VpMatrix, 1, 65536, 53, aspect);
	//setPosition(&viewMat, 0, -4, -24 );

	dw = 0.5f * aspect;
	dh = 0.5f;

	perspectiveMatrix( -dw, +dw, -dh, +dh, 1, 160, &g_sp.VpMatrix );
	setPosition(&viewMat, 0, -12, -32 );

	//print_mat4( &g_sp.VpMatrix );

	mulMatrix(&g_sp.VpMatrix, &g_sp.VpMatrix, &viewMat);
	
	makeUnit(&modelMat);
	
	mulMatrix( &projection_matrix, &modelMat, &g_sp.VpMatrix );

	makeUnit(&rotMat);
	setRotationY(&rotMat, 0.5); /* 30 degree/sec */

	pmd_file = NULL;
	vmd_file = NULL;
	if( argc < 2 )
	{
		printf( "File Error!\n" );
		printf( "Argment1 : Pmd or Pmx file.\n" );
		printf( "Argment2 : Vmd file.\n" );
		return 0;
	}
	if( argc > 1 )
		pmd_file = argv[ 1 ];
	
	if( argc > 2 )
		vmd_file = argv[ 2 ];

	init();

	if( argc > 3 && argv[ 3 ] )
	{
		if( strncmp( argv[ 3 ], "-D", 2 ) == 0 )
			debug_flag = 1;
	}
	
	//print_mat4( &projection_matrix );

	glEnable(GL_DEPTH_TEST);
	glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );

	Mat4 delta_mat;
	makeUnit( &delta_mat );
	
	if( argc > 4 )
	{
		int	i, j;
		char	cmd_string[ 255 ] = { 0 };
		for( i = 3; i < argc; i ++ )
		{
			int	length = 0;
			strcpy( cmd_string, argv[ i ] );
			puts( cmd_string );
			length = strlen( cmd_string );
			cmd_string[ length ] = ' ';
			cmd_string[ length + 1 ] = '&';
			cmd_string[ length + 2 ] = '\0';
			
			system( cmd_string );
		}
	}
	
	fps = new Fps();
	fps->set_fps( _fps_ );
	
	/* 1200frame / 60fps = 20sec */
	//while( frames < 1200 ) 
	while( !p->get_vmd( 0 )->is_end() || ( !vmd_file && frames < 160 ) )
	//while( 1 )
	{
		Mat4 pl_matrix;
		glViewport(0, 0, g_sc.width, g_sc.height);
		
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		/* X Rotation */
		mulMatrix( &pl_matrix, &projection_matrix, &delta_mat );
		//glUniformMatrix4fv(g_sp.uModelMatrix, 1, GL_FALSE, modelMat.m);

		p->set_projection_matrix( pl_matrix.m );
		draw();
		/*
		char c = get_keyboard();
		
		makeUnit( &delta_mat );
		switch( c )
		{
		case 'w':	setPosition( &delta_mat, 0, 0, +4 );	break;
		case 's':	setPosition( &delta_mat, 0, 0, -4 );	break;
		case 'a':	setRotationY( &delta_mat, +0.5 );	break;
		case 'd':	setRotationY( &delta_mat, -0.5 );	break;
		}
		*/

		eglSwapBuffers(g_sc.display, g_sc.surface);
		frames ++;		

		//glutTimerFunc( fps->get_wait_time() * 1000.0f, timer, 0 );
		usleep( 1600 );
		if( debug_flag )
			fps->draw();
	}
  
	printf( "Ending process!\n" );
  
	end();
  
	return 0;
}
示例#6
0
 void ChargeSystem::normalize()
 {
   std::for_each(d_particles.begin(), d_particles.end(), [](PhasePoint& io_pnt) { makeUnit(io_pnt.d_p); } );
 }