Пример #1
0
Cell *Cell::getNeighborWithImage(char anImage) {
  Cell *neighbors[4];
  unsigned count = 0;
  if (north()->getImage() == anImage) neighbors[count++] = north();
  if (south()->getImage() == anImage) neighbors[count++] = south();
  if (east()->getImage() == anImage) neighbors[count++] = east();
  if (west()->getImage() == anImage) neighbors[count++] = west();
  if (!count) return this;
  else
    return neighbors[Ocean1->random->nextIntBetween(0,count-1)];
}
Пример #2
0
GeoDataCoordinates GeoDataLatLonAltBox::center() const
{
    if ( isEmpty() )
        return GeoDataCoordinates();
    if( crossesDateLine() )
        return GeoDataCoordinates( GeoDataCoordinates::normalizeLon(east() + 2 * M_PI - (east() + 2 * M_PI - west()) / 2),
                                north() - (north() - south()) / 2, 
                                d->m_maxAltitude - (d->m_maxAltitude - d->m_minAltitude) / 2);
    else
        return GeoDataCoordinates( east() - (east() - west()) / 2,
                                north() - (north() - south()) / 2, 
                                d->m_maxAltitude - (d->m_maxAltitude - d->m_minAltitude) / 2);
}
std::vector< Ellipsoid_rasterizer::EuclideanVector >&
Ellipsoid_rasterizer::rasterize() {
  GsTLInt center_id = 
    cursor_.node_id( center_[0], center_[1], center_[2] );
  appli_assert( center_id >= 0 && center_id < int(already_visited_.size()) );

  already_visited_[ center_id ] = true;
  s_.push( center_id );

  EuclideanVector west(-1,0,0);
  EuclideanVector east(1,0,0);
  EuclideanVector south(0,-1,0);
  EuclideanVector north(0,1,0);
  EuclideanVector down(0,0,-1);
  EuclideanVector up(0,0,1);


  // move away from center, until we reach the border of the ellipsoid
  while( ! s_.empty() ) {
    GsTLInt id = s_.top();
    s_.pop();
    GsTLGridNode loc;
    cursor_.coords( id, loc[0], loc[1], loc[2] );
    
    check_node( loc+west );
    check_node( loc+east );
    check_node( loc+north );
    check_node( loc+south );
    check_node( loc+up );
    check_node( loc+down );
        
  }

  return ellipsoid_nodes_;
}
Пример #4
0
Файл: bee.C Проект: cen5bin/acm
int main()
{
  FILE *in = fopen( "bee.in", "r" );
  int field;

  currentStep = 1;
  posX        = 0;
  posY        = -1;
  south( 2 );

  for( int schale = 1; currentStep < 10000; schale ++ )
    {
      northWest( schale );
      north( schale );
      northEast( schale );
      southEast( schale );
      south( schale + 1 );
      southWest( schale );
    }

  while( fscanf( in, "%d", &field )==1 )
    {
      printf( "%d %d\n", fieldX[field], fieldY[field] );
    }

  return 0;
}
Пример #5
0
void ModelExporter::processLight(const scene::INodePtr& node)
{
	// Export lights as small polyhedron
	static const double EXTENTS = 8.0;
	std::vector<model::ModelPolygon> polys;

	Vertex3f up(0, 0, EXTENTS);
	Vertex3f down(0, 0, -EXTENTS);
	Vertex3f north(0, EXTENTS, 0);
	Vertex3f south(0, -EXTENTS, 0);
	Vertex3f east(EXTENTS, 0, 0);
	Vertex3f west(-EXTENTS, 0, 0);

	// Upper semi-diamond
	polys.push_back(createPolyCCW(up, south, east));
	polys.push_back(createPolyCCW(up, east, north));
	polys.push_back(createPolyCCW(up, north, west));
	polys.push_back(createPolyCCW(up, west, south));

	// Lower semi-diamond
	polys.push_back(createPolyCCW(down, south, west));
	polys.push_back(createPolyCCW(down, west, north));
	polys.push_back(createPolyCCW(down, north, east));
	polys.push_back(createPolyCCW(down, east, south));

	Matrix4 exportTransform = node->localToWorld().getPremultipliedBy(_centerTransform);

	_exporter->addPolygons("lights/default", polys, exportTransform);
}
Пример #6
0
void flood_fill(int new_room)
{
	int visited_num, i, j;
	do {
		visited_num = 0;
		for (i = 0; i < N; i++) {			/* for each module */
			for (j = 0; j < M; j++) {
				if (room[i][j] == visited) {
					// printf("[%d %d] ", i, j);
					visited_num++;
					room[i][j] = new_room;
					if (!west(module[i][j]))
						if (room[i][j-1] == nil)
							room[i][j-1] = visited;
					if (!north(module[i][j]))
						if (room[i-1][j] == nil)
							room[i-1][j] = visited;
					if (!east(module[i][j]))
						if (room[i][j+1] == nil)
							room[i][j+1] = visited;
					if (!south(module[i][j]))
						if (room[i+1][j] == nil)
							room[i+1][j] = visited;
				}
			}
		}
		size[new_room] += visited_num;
	} while (visited_num);
}
Пример #7
0
//'@rdname neighbours
//'@export
// [[Rcpp::export]]
DataFrame gh_neighbours(CharacterVector hashes){

  unsigned int input_size = hashes.size();
  CharacterVector north(input_size);
  CharacterVector ne(input_size);
  CharacterVector east(input_size);
  CharacterVector se(input_size);
  CharacterVector south(input_size);
  CharacterVector sw(input_size);
  CharacterVector west(input_size);
  CharacterVector nw(input_size);
  std::vector < std::string > holding(8);

  for(unsigned int i = 0; i < input_size; i++){

    if((i % 10000) == 0){
      Rcpp::checkUserInterrupt();
    }

    if(CharacterVector::is_na(hashes[i])){
      north[i] = NA_REAL;
      ne[i] = NA_REAL;
      east[i] = NA_REAL;
      se[i] = NA_REAL;
      south[i] = NA_REAL;
      sw[i] = NA_REAL;
      west[i] = NA_REAL;
      nw[i] = NA_REAL;
    } else {

      holding = cgeohash::all_neighbours(Rcpp::as<std::string>(hashes[i]));

      north[i] = holding[0];
      ne[i] =  holding[1];
      east[i] =  holding[2];
      se[i] =  holding[3];
      south[i] =  holding[4];
      sw[i] =  holding[5];
      west[i] =  holding[6];
      nw[i] =  holding[7];
    }

  }

  return DataFrame::create(_["north"] = north,
                           _["northeast"] = ne,
                           _["east"] = east,
                           _["southeast"] = se,
                           _["south"] = south,
                           _["southwest"] = sw,
                           _["west"] = west,
                           _["northwest"] = nw,
                           _["stringsAsFactors"] = false);

}
Пример #8
0
QString GeoDataLatLonAltBox::toString( GeoDataCoordinates::Unit unit ) const
{
    switch( unit ){
    case GeoDataCoordinates::Radian:
        return QString( "North: %1; West: %2 MaxAlt: %3\n South: %4; East: %5 MinAlt: %6" )
	    .arg( north() ).arg( west() )
	    .arg( d->m_maxAltitude ).arg( south() )
	    .arg( east() ).arg( d->m_minAltitude ); 
        break;
    case GeoDataCoordinates::Degree:
        return QString( "North: %1; West: %2 MaxAlt: %3\n South: %4; East: %5 MinAlt: %6" )
            .arg( north() * RAD2DEG ).arg( west() * RAD2DEG )
	    .arg( d->m_maxAltitude ).arg( south() * RAD2DEG )
	    .arg( east() * RAD2DEG ).arg( d->m_minAltitude ); 
        break;
    }

    return QString( "GeoDataLatLonAltBox::text(): Error in unit: %1\n" )
	.arg( unit );
}
Пример #9
0
double LatLonConvert::rightGreenich()
{
	if (isGu()) {
		return northGreenich.eastDegree(180);
	}else {
		double d = pixelToDegree((int)scrDaegak());
		NorthGreenichPoint p1, p2;
		p1.set(north(), greenich());
		p1.moveEast(d);
		p1.moveNorth(d);
		p2.set(north(), greenich());
		p2.moveEast(d);
		p2.moveSouth(d);
		double gp = qMax(p1.greenich(), p2.greenich());
		gp = northGreenich.eastDegree(d);

		double dy = mppToDegree();
		double max =  baseWJ(gp, dy) + dy + dy;
		return max;
	}
}
Пример #10
0
void do_op(char C)
{
  switch(C)
  {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9': push(C-'0'); break;
    case '+': addition(); break;
    case '-': subtraction(); break;
    case '*': multiplication(); break;
    case '/': division(); break;
    case '%': modulo(); break;
    case '^': north(); break;
    case '>': east(); break;
    case 'V':
    case 'v': south(); break;
    case '<': west(); break;
    case '?': spin(); break;
    case '!': lnot(); break;
    case '`': gt(); break;
    case '_': hif(); break;
    case '|': vif(); break;
    case '"': tsm(); break;
    case ':': dup(); break;
    case '\\': swap(); break;
    case '$': chomp(); break;
    case '#': jump(); break;
    case 'p': put(); break;
    case 'g': get(); break;
    case 'H': gate(); break;
    case '.': print_i(); break;
    case ',': print_c(); break;
    case '&': input_i(); break;
    case '~': input_c(); break;
    case '@': hacf(); break;
    case '{': left_b(); break;
    case '}': right_b(); break;
    case '[': carry_l(); break;
    case ']': carry_r(); break;
    case ';': empty(); break;
    case 'O': portal_o(); break;
    case 'B': portal_b(); break;
    default: /* DO NOTHING! */ break;
  }
}
Пример #11
0
void _set_wind (const Planet& planet, const Climate_parameters&, Climate_generation_season& season) {
	for (auto& t : tiles(planet)) {
		season.tiles[id(t)].wind = _default_wind(planet, id(t), season.tropical_equator);
		season.tiles[id(t)].wind.direction += north(planet, &t);
	}
	for (auto& t : tiles(planet)) {
		//tile shape in 2d, rotated according to wind direction
		std::vector<Vector2> corners =
			rotation_matrix(north(planet, &t) - season.tiles[id(t)].wind.direction) * polygon(&t, rotation_to_default(planet));

		int e = edge_count(t);
		for (int k=0; k<e; k++) {
			int direction = sign(nth_edge(t, k), &t);
			if (corners[k].x + corners[(k+1)%e].x < 0) direction *= -1;
			season.edges[id(nth_edge(t, k))].wind_velocity -=
				0.5 * direction
				* season.tiles[id(t)].wind.speed
				* std::abs(corners[k].y - corners[(k+1)%e].y)
				/ length(corners[k] - corners[(k+1)%e]);
		}
	}
}
Пример #12
0
double LatLonConvert::leftGreenich()
{
	if (isGu()) {
		return northGreenich.westDegree(180);
	}else {

		double d = pixelToDegree((int)scrDaegak());
		NorthGreenichPoint p1, p2;
		p1.set(north(), greenich());
		p1.moveNorth(d);
		p1.moveWest(d);
		p2.set(north(), greenich());
		p2.moveSouth(d);
		p2.moveWest(d);

		double gp = qMin(p1.greenich(), p2.greenich());
		gp = northGreenich.westDegree(d);

		double dy = mppToDegree();
		double min = baseWJ(gp, dy) - dy;
		return min;
	}
}
Пример #13
0
void menu()// NORTH AND SOUTH BOUND ROUTE
{
     system("cls");
     p("\n\n\n\t\t\t= Cavite Bus Transit =\n\n");
     p("\n\t\t\t Ticket Transaction\n ");
     p("\n\n\tChoose Destination: ");
     p("[ 1 ] NORTH BOUND          [ 2 ] SOUTH BOUND ");
     p("\n\n\tRoute: ");
     s("%d", &y);
     if (y == 1) north();
     else if ( y == 2) south();
     
     else  {p("INVALID CHOICE!"); getch(); system("cls"); menu(); getch(); }
     }
Пример #14
0
void ViewEvaluator::outputView(GeoPoint* view, string filename) {
    readyFeatures();
    oc->volActor->GetProperty()->SetAmbient(0.3);
    oc->volActor->GetProperty()->SetDiffuse(0.7); //SetShading(0);
    oc->volActor->GetProperty()->SetSpecular(0.7); //SetShading(0);
    oc->volActor->GetProperty()->SetInterpolationToPhong();
oc->volActor->SetVisibility(1);
    vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter = vtkSmartPointer<vtkWindowToImageFilter>::New();
    windowToImageFilter->SetInput(renderWindow);
    vtkSmartPointer<vtkPNGWriter> writer = vtkSmartPointer<vtkPNGWriter>::New();
    writer->SetInput(windowToImageFilter->GetOutput());
    float viewRange = 3;
    vnl_vector<float> pos(3);
    double* upV = new double[3]();
    pos[0] = viewRange * view->getx();
    pos[1] = viewRange * view->gety();
    pos[2] = viewRange * view->getz();
    camera->SetPosition(pos[0], pos[1], pos[2]);

    if (!upSet) {
        upSet = true;
        upV = camera->GetViewUp();
    }
    //upV[0]=0;upV[1]=1;upV[2]=0;
    camera->SetViewUp(upV);
    vnl_vector<float> northPole(3);
    northPole[0] = 0.0001;
    northPole[1] = 1;
    northPole[2] = 0;
    vnl_vector<float> north(3);
    vnl_vector<float> here(3);
    here[0] = pos[0];
    here[1] = pos[1];
    here[2] = pos[2];
    north = northPole - here;
    camera->OrthogonalizeViewUp();
    upV = camera->GetViewUp();
    cout << " up is " << upV[0] << " " << upV[1] << " " << upV[2] << endl;
    cout << " view is " << pos[0] << " " << pos[1] << " " << pos[2] << endl;
    renderWindow->Render();
    windowToImageFilter->Update();
    filename = *(oc->resultsPath) + filename;
    cout << "OUTPUTTING PNG to " << filename << endl;
    writer->SetFileName(filename.c_str());
    writer->Write();


    renderWindow->Render();
    climbDownFeatures();
}
Пример #15
0
int main() {
	int n;
	char s[6];
	while (scanf("%d",&n),n) {
		init();
		while (n--) {
			scanf("%s",s);
			if (strcmp(s,"north")==0) north();
			else if (strcmp(s,"south")==0) south();
			else if (strcmp(s,"east")==0) east();
			else if (strcmp(s,"west")==0) west();
		}
		printf("%d\n",dice[0]);
	}
}
Пример #16
0
zz::map::location zz::map::location::adjacent( zz::map::direction direction ) const {
    switch( direction ) {
    case zz::map::north :
        return north( );
    case zz::map::east :
        return east( );
    case zz::map::south :
        return south( );
    case zz::map::west :
        return west( );
    }
    fprintf( stderr, "invalid direction provided to map::location::adjacent\n" );
    fflush( stderr );
    exit( EXIT_FAILURE );
}
	virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
	{ 
		if( nv->getVisitorType() == osg::NodeVisitor::CULL_VISITOR )
		{ 
			osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(nv);
			osg::Vec3 eye,center,up;
			cv->getCurrentCamera()->getViewMatrixAsLookAt(eye,center,up);

			osg::Vec3 look = center - eye;
			look.z() = 0;
			look.normalize();
			osg::Vec3 north(0,1,0);
			osg::Matrix mat = osg::Matrix::rotate(look,north);
			g_pNorthArrowStateSet->getUniform("matBearing")->set(mat);
		}
		traverse(node,nv);
	}
TEST_F(VecTest, ArithmeticFunc) {
    vec3 east(1, 0, 0);
    vec3 north(0, 1, 0);
    vec3 up( cross(east, north) );
    EXPECT_EQ(up, vec3(0,0,1));
    EXPECT_EQ(dot(east, north), 0);
    EXPECT_EQ(length(east), 1);
    EXPECT_EQ(distance(east, north), sqrtf(2));

    vec3 v0(1,2,3);
    vec3 vn(normalize(v0));
    EXPECT_FLOAT_EQ(1, length(vn));
    EXPECT_FLOAT_EQ(length(v0), dot(v0, vn));

    tvec3<double> vd(east);
    EXPECT_EQ(length(vd), 1);
}
Пример #19
0
void DrawPoint( const Vector2& point, float size )
{
	size *= 0.5f;
	Vector2 north(point + Vector2::UnitY * size );
	Vector2 south(point - Vector2::UnitY * size );
	Vector2 east(point + Vector2::UnitX * size );
	Vector2 west(point - Vector2::UnitX * size );

	float points[] = {
		north.X, north.Y,
		east.X, east.Y,
		south.X, south.Y,
		west.X, west.Y,
	};
	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(2, GL_FLOAT, 0, points);
	glDrawArrays(GL_LINE_LOOP, 0, 4);
}
void LandscapeRenderer::BuildNormArray()
{
	if (m_verts.Size() <= 0)
		return;

	int nextNormId = 0;

	// Go through all the strips...
	for (int i = 0; i < m_strips.Size(); ++i)
	{
		LandTriangleStrip *strip = m_strips[i];

		m_verts[nextNormId++].m_norm = g_upVector;
		m_verts[nextNormId++].m_norm = g_upVector;
		int const maxJ = strip->m_numVerts - 2;
		
		// For each vertex in strip
		for (int j = 0; j < maxJ; j += 2)
		{
			Vector3 const &v1 = m_verts[strip->m_firstVertIndex + j].m_pos;
			Vector3 const &v2 = m_verts[strip->m_firstVertIndex + j + 1].m_pos;
			Vector3 const &v3 = m_verts[strip->m_firstVertIndex + j + 2].m_pos;
			Vector3 const &v4 = m_verts[strip->m_firstVertIndex + j + 3].m_pos;

			Vector3 north(v1 - v2);
			Vector3 northEast(v3 - v2);
			Vector3 east(v4 - v2);

			Vector3 norm1(northEast ^ north);
			norm1.Normalise();
			Vector3 norm2(east ^ northEast);
			norm2.Normalise();

			m_verts[nextNormId++].m_norm = norm1;
			m_verts[nextNormId++].m_norm = norm2;

			int vertIndex = strip->m_firstVertIndex + j + 2;
			AppDebugAssert(nextNormId - 2 == vertIndex);
		}
	}

	int vertIndex = m_verts.NumUsed();
	AppDebugAssert(nextNormId == vertIndex);
}
Пример #21
0
Файл: 502.c Проект: Mine02C4/aoj
int main () {
    int i,n,result;
    char roll[6];
    while (1) {
        scanf("%d", &n);
        if (n==0) return 0;
        dice[kTOP]      = 1;
        dice[kBOTTOM]   = 6;
        dice[kNORTH]    = 5;
        dice[kSOUTH]    = 2;
        dice[kEAST]     = 3;
        dice[kWEST]     = 4;
        result = 1;
        for (i=0;i<n;i++) {
            scanf("%s", roll);
            switch (roll[0]) {
                case 'N':
                    north();
                    break;
                case 'E':
                    east();
                    break;
                case 'W':
                    west();
                    break;
                case 'S':
                    south();
                    break;
                case 'R':
                    right();
                    break;
                case 'L':
                    left();
                    break;
            }
            result += dice[kTOP];
        }
        printf("%d\n", result);

    }
}
Пример #22
0
int main()
{
    WFMath::Vector<3> east(1,0,0), north(0,1,0), west(-1,0,0);
    WFMath::Vector<3> up(0,0,1), down(0,0,-1);

    Quaternion rotation;

    // Normal 90 degree rotation
    rotation = quaternionFromTo(east, north);

    // No rotation to cover special case
    rotation = quaternionFromTo(east, east);

    // Exact 180 to cover special case
    rotation = quaternionFromTo(east, west);

    // Exact 180 to cover other part of same case
    rotation = quaternionFromTo(up, down);

    return 0;
}
Пример #23
0
static void make_see(int levelplayer, t_players *player, int fd, t_env *e)
{
  int count;

  count = 0;
  dprintf(fd, "{");
  while (count < levelplayer + 1)
  {
    if (player->orientation == O)
      west(count, fd, e, player);
    else if (player->orientation == N)
      north(count, fd, e, player);
    else if (player->orientation == E)
      east(count, fd, e, player);
    else if (player->orientation == S)
      south(count, fd, e, player);
    count = count + 1;
    if (count < levelplayer + 1 || count == 0)
      dprintf(fd, ",");
  }
  dprintf(fd, "}\n");
}
Пример #24
0
bool BoardEvaluator::IsFinished(Board &board, Colour *winningColour) {
    for (unsigned int i = 0; i < WIDTH; i++) {
        for (unsigned int j = 0; j < HEIGHT; j++) {
            Counter *counter = board.Space(i, j);
            
            if (counter != NULL) {
                // creating the dirctions to be searched in.
                North       north(i, j);
                South       south(i, j);
                East        east(i, j);
                West        west(i, j);
                NorthEast   northEast(i, j);
                NorthWest   northWest(i, j);
                SouthEast   southEast(i, j);
                SouthWest   southWest(i, j);

                bool retVal             = false;
                Colour retCol           = NULL_COLOUR;
                unsigned int conLength  = CONNECT_LENGTH;
                Colour colour           = (Colour)counter->GetColour();

                if (RecursiveSearch(colour, &north, conLength - 1, board)) {
                    retCol = colour;
                    retVal = true;
                }
                if (RecursiveSearch(colour, &south, conLength - 1, board)) {
                    retCol = colour;
                    retVal = true;
                }
                if (RecursiveSearch(colour, &east, conLength - 1, board)) {
                    retCol = colour;
                    retVal = true;
                }
                if (RecursiveSearch(colour, &west, conLength - 1, board)) {
                    retCol = colour;
                    retVal = true;
                }
                if (RecursiveSearch(colour, &northEast, conLength - 1, board)) {
                    retCol = colour;
                    retVal = true;
                }
                if (RecursiveSearch(colour, &northWest, conLength - 1, board)) {
                    retCol = colour;
                    retVal = true;
                }
                if (RecursiveSearch(colour, &southEast, conLength - 1, board)) {
                    retCol = colour;
                    retVal = true;
                }
                if (RecursiveSearch(colour, &southWest, conLength - 1, board)) {
                    retCol = colour;
                    retVal = true;
                }
                
                if (retVal) {
                    *winningColour = retCol;
                    return true;
                }
            }
        }
    }           
    return false;
}
Пример #25
0
void MobileVRInterface::set_position_from_sensors() {
	_THREAD_SAFE_METHOD_

	// this is a helper function that attempts to adjust our transform using our 9dof sensors
	// 9dof is a misleading marketing term coming from 3 accelerometer axis + 3 gyro axis + 3 magnetometer axis = 9 axis
	// but in reality this only offers 3 dof (yaw, pitch, roll) orientation

	uint64_t ticks = OS::get_singleton()->get_ticks_usec();
	uint64_t ticks_elapsed = ticks - last_ticks;
	float delta_time = (double)ticks_elapsed / 1000000.0;

	// few things we need
	Input *input = Input::get_singleton();
	Vector3 down(0.0, -1.0, 0.0); // Down is Y negative
	Vector3 north(0.0, 0.0, 1.0); // North is Z positive

	// make copies of our inputs
	bool has_grav = false;
	Vector3 acc = input->get_accelerometer();
	Vector3 gyro = input->get_gyroscope();
	Vector3 grav = input->get_gravity();
	Vector3 magneto = scale_magneto(input->get_magnetometer()); // this may be overkill on iOS because we're already getting a calibrated magnetometer reading

	if (sensor_first) {
		sensor_first = false;
	} else {
		acc = scrub(acc, last_accerometer_data, 2, 0.2);
		magneto = scrub(magneto, last_magnetometer_data, 3, 0.3);
	};

	last_accerometer_data = acc;
	last_magnetometer_data = magneto;

	if (grav.length() < 0.1) {
		// not ideal but use our accelerometer, this will contain shakey shakey user behaviour
		// maybe look into some math but I'm guessing that if this isn't available, its because we lack the gyro sensor to actually work out
		// what a stable gravity vector is
		grav = acc;
		if (grav.length() > 0.1) {
			has_grav = true;
		};
	} else {
		has_grav = true;
	};

	bool has_magneto = magneto.length() > 0.1;
	if (gyro.length() > 0.1) {
		/* this can return to 0.0 if the user doesn't move the phone, so once on, it's on */
		has_gyro = true;
	};

	if (has_gyro) {
		// start with applying our gyro (do NOT smooth our gyro!)
		Basis rotate;
		rotate.rotate(orientation.get_axis(0), gyro.x * delta_time);
		rotate.rotate(orientation.get_axis(1), gyro.y * delta_time);
		rotate.rotate(orientation.get_axis(2), gyro.z * delta_time);
		orientation = rotate * orientation;

		tracking_state = ARVRInterface::ARVR_NORMAL_TRACKING;
	};

	///@TODO improve this, the magnetometer is very fidgity sometimes flipping the axis for no apparent reason (probably a bug on my part)
	// if you have a gyro + accelerometer that combo tends to be better then combining all three but without a gyro you need the magnetometer..
	if (has_magneto && has_grav && !has_gyro) {
		// convert to quaternions, easier to smooth those out
		Quat transform_quat(orientation);
		Quat acc_mag_quat(combine_acc_mag(grav, magneto));
		transform_quat = transform_quat.slerp(acc_mag_quat, 0.1);
		orientation = Basis(transform_quat);

		tracking_state = ARVRInterface::ARVR_NORMAL_TRACKING;
	} else if (has_grav) {
		// use gravity vector to make sure down is down...
		// transform gravity into our world space
		grav.normalize();
		Vector3 grav_adj = orientation.xform(grav);
		float dot = grav_adj.dot(down);
		if ((dot > -1.0) && (dot < 1.0)) {
			// axis around which we have this rotation
			Vector3 axis = grav_adj.cross(down);
			axis.normalize();

			Basis drift_compensation(axis, acos(dot) * delta_time * 10);
			orientation = drift_compensation * orientation;
		};
	};

	// JIC
	orientation.orthonormalize();

	last_ticks = ticks;
};
Пример #26
0
main () {
    FILE *fin  = fopen ("castle.in", "r");
    FILE *fout = fopen ("castle.out", "w");
    
    int i, j;
    unsigned int type;

    fscanf (fin, "%d %d", &M, &N);
    for (i = 0; i < N; i++) {
    	for (j = 0; j < M; j++) {
    		fscanf (fin, "%u", &type);
    		module[i][j] = ( unsigned char ) type;
    		room[i][j] = nil;
    		//printf ("%d ", (unsigned char) type);
    	}
    }

    for (i = 0; i < 2500; i++)
    	size[i] = 0;
    max_size = 0;

    find_room();
    fprintf(fout, "%d\n", room_num+1);

    for (i = 0; i <= room_num; i++)
    	if (size[i] > max_size)
    		max_size = size[i];
    fprintf(fout, "%d\n", max_size);

    int new_size;
    for (i = 0; i < N; i++) {
    	for (j = 0; j < M; j++) {
    		if (north(module[i][j]) && i > 0
    			&& room[i][j] != room[i-1][j]) {
    			new_size = size[room[i][j]] + size[room[i-1][j]];
    			if (new_size > new_room_size) {
    				x = i;
    				y = j;
    				direction = 'N';
    				new_room_size = new_size;
    			}
    			else if (new_size == new_room_size) {
    				if (j<y || (j==y && i>x) ) {
    					x = i;
    					y = j;
    					direction = 'N';
    				}
    			}
    		} else if (east(module[i][j]) && j < M-1
    				   && room[i][j] != room[i][j+1]) {
    			new_size = size[room[i][j]] + size[room[i][j+1]];
    			if (new_size > new_room_size) {
    				x = i;
    				y = j;
    				direction = 'E';
    				new_room_size = new_size;
    			}
    			else if (new_size == new_room_size) {
    				if (j<y || (j==y && i>x) ) {
    					x = i;
    					y = j;
    					direction = 'E';
    				}
    			}
    		}
    	}
    }
    fprintf(fout, "%d\n", new_room_size);
    fprintf(fout, "%d %d %c\n", x+1, y+1, direction);


    exit (0);
}
/**
 * \brief The work function
 *
 * This function does the actual work of activating the guide port outputs
 * for a given amount of time.
 */
void	AsiGuidePort::run() {
	std::unique_lock<std::mutex>	lock(_mutex);
	// we keep running until the _running variable becomes false
	// we are sure not to miss this event, because we carefully lock
	// the private data of the class all the time
	while (_running) {
		// find the time when the next action should finish
		int	duration = 0;

		// first check for any right ascension movement
		if (0 != _ra) {
			if (_ra > 0) {
				west();
				duration = _ra;
			} else {
				east();
				duration = -_ra;
			}
		} else {
			rastop();
		}

		// check whether any declination movement is needed
		if (0 != _dec) {
			if (_dec > 0) {
				north();
				if (_dec < duration) {
					duration = _dec;
				}
			} else {
				south();
				if (-_dec < duration) {
					duration = -_dec;
				}
			}
		} else {
			decstop();
		}

		// so we are done, and wait for new information
		if (0 == duration) {
			// just wait for new information
			_condition.wait(lock);
		} else {
			// wait for the condition variable for the duration
			// in milliseconds.
			std::cv_status	status = _condition.wait_for(lock,
				std::chrono::milliseconds(duration));
			// if this times out, then we have waited for the
			// duration, so we change the _ra und _dec variables
			// accordingly
			if (status == std::cv_status::timeout) {
				if (_ra > 0) {
					_ra -= duration;
				}
				if (_ra < 0) {
					_ra += duration;
				}
				if (_dec > 0) {
					_dec -= duration;
				}
				if (_dec < 0) {
					_dec += duration;
				}
			}
			// in other cases, i.e. if it does not time out,
			// then new settings for _ra and _dec must have become
			// available, so we just loop around, and pick up the
			// new values
		}
	}
}
Пример #28
0
 LatLng northwest() const { return LatLng(north(), west()); }
AZ_MATRIX *user_Ke_build(struct user_partition *Edge_Partition)
{
  double dcenter, doff, sigma = .0001;
  int ii,jj, horv, i, nx, global_id, nz_ptr, Nlocal_edges;

  /* Aztec matrix and temp variables */

  int       *Ke_bindx, *Ke_data_org = NULL;
  double    *Ke_val;
  AZ_MATRIX *Ke_mat;
  int       proc_config[AZ_PROC_SIZE], *cpntr = NULL;
  int       *reordered_glob_edges = NULL, *reordered_edge_externs = NULL;

  Nlocal_edges = Edge_Partition->Nlocal;
  nx = (int) sqrt( ((double) Edge_Partition->Nglobal/2) + .00001);

  Ke_bindx = (int    *) malloc((7*Nlocal_edges+1)*sizeof(int));
  Ke_val   = (double *) malloc((7*Nlocal_edges+1)*sizeof(double));
  Ke_bindx[0] = Nlocal_edges+1;

  dcenter  = 2 + 2.*sigma/((double) ( 3 * nx * nx));
  doff = -1 + sigma/((double) ( 6 * nx * nx));

  for (i = 0; i < Nlocal_edges; i++) {
    global_id = (Edge_Partition->my_global_ids)[i];
    invindex(global_id, &ii, &jj, nx, &horv);
    nz_ptr = Ke_bindx[i];

    Ke_val[i] = dcenter;

    if (horv == HORIZONTAL) {
      if (jj != 0) {
	Ke_bindx[nz_ptr] = north(ii,jj,nx);     Ke_val[nz_ptr++] = doff;
	Ke_bindx[nz_ptr] = east(ii,jj,nx);      Ke_val[nz_ptr++] = -1.;
	if (ii != 0) {Ke_bindx[nz_ptr]=west(ii,jj,nx); Ke_val[nz_ptr++]= 1.;}
	jj--;
      }
      else {
	Ke_val[i] = 1. +  2.*sigma/((double) ( 3 * nx * nx));
	jj = nx-1;
      }
      Ke_bindx[nz_ptr] = east(ii,jj,nx);      Ke_val[nz_ptr++] = 1.;
      if (ii != 0){ Ke_bindx[nz_ptr]=west(ii,jj,nx);  Ke_val[nz_ptr++]=-1.;}
      if (jj != 0){ Ke_bindx[nz_ptr]=south(ii,jj,nx); Ke_val[nz_ptr++]=doff;}
    }
    else {
      if (ii != 0) {
	Ke_bindx[nz_ptr] = north(ii,jj,nx);     Ke_val[nz_ptr++] = -1.;
	Ke_bindx[nz_ptr] = east(ii,jj,nx);      Ke_val[nz_ptr++] = doff;
	if (jj != 0) {Ke_bindx[nz_ptr]=south(ii,jj,nx); Ke_val[nz_ptr++]=1.;}
	ii--;
      }
      else {
	Ke_val[i]  = 1 +  2.*sigma/((double) ( 3 * nx * nx));
	ii = nx-1;
      }
      Ke_bindx[nz_ptr] = north(ii,jj,nx);     Ke_val[nz_ptr++] = 1.;
      if (ii != 0) {Ke_bindx[nz_ptr]=west(ii,jj,nx);  Ke_val[nz_ptr++]=doff;}
      if (jj != 0) {Ke_bindx[nz_ptr]=south(ii,jj,nx); Ke_val[nz_ptr++]=-1.;}
    }
    Ke_bindx[i+1] = nz_ptr;
  }

  AZ_set_proc_config(proc_config, COMMUNICATOR);

  AZ_transform_norowreordering(proc_config, &(Edge_Partition->needed_external_ids),
			       Ke_bindx, Ke_val, Edge_Partition->my_global_ids,
			       &reordered_glob_edges, &reordered_edge_externs, 
			       &Ke_data_org, Nlocal_edges, 0, 0, 0, 
			       &cpntr,	       AZ_MSR_MATRIX);
  AZ_free(reordered_glob_edges);
  AZ_free(reordered_edge_externs);
  Edge_Partition->Nghost = Ke_data_org[AZ_N_external];

  Ke_mat = AZ_matrix_create( Nlocal_edges );
  AZ_set_MSR(Ke_mat, Ke_bindx, Ke_val, Ke_data_org, 0, NULL, AZ_LOCAL);

  return(Ke_mat);
}