Esempio n. 1
0
void CommandCreator::update(const Plan &plan, const GlobalMap &gMap)
{
  // make vector from current position to destination
  const Vector2DCont &vp=plan.getDst().getDstVect();
  // get vector of direction of robot
  const Vector2DCont &vd=gMap.getDir();

  // get angle between robot's direcion vector and destination in
  // radians (clock-wise)
  double angle=vd.getAngle(vp);

  TIERproto::Speed spd(0,0); // speed to set
  if( angle<_params._tolerance ||
      2*M_PI-_params._tolerance<angle)      // misdirection is suficiently
    spd=TIERproto::Speed( 250,  250);       // small not to change dir?
  else
    if(angle<M_PI)           // turn right?
      spd=TIERproto::Speed( 250, -250);
      //spd=TIERproto::Speed(   0,-250);
    else                     // turn left?
      spd=TIERproto::Speed(-250,  250);
      //spd=TIERproto::Speed(-250,   0);

  // critical section - set new speed
  {
    Lock lock(_mutex);
    _spdSet=spd;
  };
};
Esempio n. 2
0
StringDataInformation* toString(const QScriptValue& value, const ParserInfo& info)
{
    StringParsedData spd(info);
    spd.encoding = value.property(PROPERTY_ENCODING).toString();
    spd.termination = ParserUtils::uintFromScriptValue(value.property(PROPERTY_TERMINATED_BY));
    spd.maxByteCount = ParserUtils::uintFromScriptValue(value.property(PROPERTY_MAX_BYTE_COUNT));
    spd.maxCharCount = ParserUtils::uintFromScriptValue(value.property(PROPERTY_MAX_CHAR_COUNT));
    return DataInformationFactory::newString(spd);
}
Esempio n. 3
0
void EntitiesResponse::sendServerControlState(BitStream &bs) const
{
    Vector3 spd(1,80,1);
    Vector3 zeroes;
    bool m_flying=false;
    bool m_dazed=false;
    // user entity
    Entity *ent = m_client->char_entity();
    CscCommon_Sub28 struct_csc;
    memset(&struct_csc,0,sizeof(struct_csc));
    static int vla=1;
    int g=rand()&0xff;
    for(int i=0; i<3; ++i)
        struct_csc.a.v[i] = g+vla;
    vla+=1;
    struct_csc.b.max_speed = struct_csc.a.max_speed = 5.0f;
    struct_csc.b.gravitational_constant = struct_csc.a.gravitational_constant = 3.0f;
    //    for(int i=3; i<5; ++i)
    //        struct_csc.a.v[i] = rand()&0xf;
    bool update_part_1=true;
    bool update_part_2=false;
    bs.StoreBits(1,update_part_1);
    if(update_part_1)
    {
        //rand()&0xFF
        bs.StoreBits(8,vla); // value stored in control state field_134
        // after input_send_time_initialized, this value is enqueued as CSC_9's control_flags
        // This is entity speed vector !!
        NetStructure::storeVector(bs,spd);

        bs.StoreFloat(1.0f); // speed rel back
        bs.StoreBitArray((uint8_t *)&struct_csc,sizeof(CscCommon_Sub28)*8);
        bs.StoreFloat(0.1f);
        bs.StoreBits(1,m_flying); // key push bits ??
        bs.StoreBits(1,m_dazed); // key push bits ??
        bs.StoreBits(1,0); // key push bits ??
        bs.StoreBits(1,0); // key push bits ??
        bs.StoreBits(1,0); // key push bits ??
        bs.StoreBits(1,0); // key push bits ??
    }
    // Used to force the client to a position/speed/pitch/rotation by server
    bs.StoreBits(1,update_part_2);
    if(update_part_2)
    {
        bs.StorePackedBits(1,0); // sets g_client_pos_id_rel
        NetStructure::storeVector(bs,spd);
        NetStructure::storeVectorConditional(bs,zeroes);  // vector3 -> speed ? likely

        NetStructure::storeFloatConditional(bs,0); // Pitch not used ?
        NetStructure::storeFloatConditional(bs,ent->inp_state.pyr.x); // Pitch
        NetStructure::storeFloatConditional(bs,0); // Roll
        bs.StorePackedBits(1,0); // sets the lowest bit in CscCommon::flags
    }
}
Esempio n. 4
0
void CommandCreator::doTask(void)
{
  TIERproto::Speed spd(0,0);          // this copy is needed because of very
                                      // high command sending times...
  // critical section - make copy of speed setting
  {
    Lock lock(_mutex);
    spd=_spdSet;
  };

  // apply settings
  if( !_params._proto.spdst(spd) )    // set new speed to robot
    _params._listener.onCommError("CommandCreator::doTask(): "
                                  "proto.spdst() failed");
  usleep(200*1000);                   // 200[ms] - this is needed since radio
                                      // modems seems not to handle more...
};
void myApp02::init() {

	globalAmbient = Col3f(1, .1, .1);
	shadowsOn();
	// wall
	plane = GroundPlane(Vec3(), Vec3(), Dim2f(8, 7), Col4f(1, 1, 0, 1), 1, 1, "orange.jpg");
	//Plane.textureOn();
	plane.setBumpMap("white_tile.jpg");
	plane.setTextureScale(Vec2f(.5));
	//Plane.setAmbientMaterial(Col4f(.02, .02, .02, 1.0));
	plane.setSpecularMaterial(Col4f(.1, .1, .1, 1.0));
	plane.setShininess(100);


	//tube = ProtoTube();

	float radius = .107;
	Vec3f v(0, 0, 0);

	int segments = 10; // 60;
	v = Vec3f(0, 0, 0);
	Vec3f spd(0, 0, 0);

	//cps.push_back(v);
	float turbulence = .1f;
	Dim3f size(4.25, 4.25, 4.25);


	float startY = -.5;

	int ribCount = 3;// 17;
	float ribSpan = 4.5;
	float ribRadius = 0;
	float ribRadiusMax = 2.0;
	float ribTheta = 0;

	float ribGap = ribSpan / ribCount;

	for (int i = 0; i < ribCount; ++i){

		float theta = 0, weaveTheta = 0;
		std::vector <Vec3> cps;
		Spline3 spline;
		ribRadius = fabs(sin(ribTheta) * ribRadiusMax);
		for (int j = 0; j < segments; ++j){
			//spd = Vec3(random(-turbulence*.1, turbulence*.1), 0, random(-turbulence*.1, turbulence*.1));
			//v = spd + Vec3f(sin(theta)*2+random(-turbulence, turbulence), startY+=.1, cos(theta)*2+random(-turbulence, turbulence));
			//cps.push_back(Vec3(v.x, v.y, v.z));
			cps.push_back(Vec3(sin(theta) * ribRadius, -ribSpan / 2 + ribGap*i + sin(weaveTheta) * .15, cos(theta) * ribRadius));
			theta += TWO_PI / segments;
			//weaveTheta += j*j*j*.125 * PI / 180;
			weaveTheta += TWO_PI / segments * (ribRadius * 4);
		}
		//trace("ribradius = ", ribRadius*4);
		ribTheta += PI / ribCount;

		//spline = Spline3(cps, 4, false, .5);
		spline = Spline3(cps, 5, false, .5);

		TransformFunction t1 = TransformFunction(TransformFunction::SINUSOIDAL, Tup2f(.02, .95 + (ribRadius*random(.07, .31))), 1/*int(random(1, 3))*/);

		ribs.push_back(ProtoTube(Vec3f(), Vec3f(), Dim3f(1), Col4f(1), spline, .09, 12, t1, true, "pitted.jpg", Vec2f(1, random(.0825, .2))));
		ribs.at(i).setIsClosed(0);
		ribs.at(i).setSpecularMaterial(Col4f(.4, .275, .1, 1));
		ribs.at(i).setShininess(6);
		ribs.at(i).setBumpMap("pitted.jpg");

		// rib tendrils
		std::vector <Vec3> ribCps;
		for (int j = 0; j < ribs.at(i).getFrenetFrameLength(); j += int(random(1, 3))){
			for (int k = 0; k < ribs.at(i).getCrossSectionDetail(); k += int(random(1, 3))){
				ribCps.push_back(ribs.at(i).getVertices().at(j*ribs.at(i).getCrossSectionDetail() + k).pos);
			}
		}

		Spline3 ribSpline = Spline3(ribCps, 2, false, .5);
		TransformFunction ribT = TransformFunction(TransformFunction::SINUSOIDAL, Tup2f(random(.05, .2), random(..3, .5)), int(random(5, 12)));
		ribBands.push_back(ProtoTube(Vec3f(), Vec3f(), Dim3f(1), Col4f(1), ribSpline, .09, 12, ribT, true, "vascular.jpg", Vec2f(1, random(.0825, 1))));
		ribBands.at(i).setIsClosed(0);
		ribBands.at(i).setSpecularMaterial(Col4f(.8, .275, .1, 1));
		ribBands.at(i).setShininess(5);
		ribBands.at(i).setBumpMap("vascular.jpg");
	}

	
	//yRot = xRot = 0;
	//xRotLast = yRotLast = 0;
	//mouseXIn = mouseYIn = 0;

}
Esempio n. 6
0
int main(int argc, const char * argv[])
{
//    cout << "Setting program parameters..."<<endl;
//
//    int order = 4;
//    int nx[4] = {51, 101, 201, 401};
//    double err1[4];
//    int ny = 1;
//    int nz = 1;
//    for (int n = 0; n < 4; n++) {
//        double h = 2*M_PI/(nx[n]-1);
//        myData u(nx[n],ny,nz),ux(nx[n],ny,nz),uxx(nx[n],ny,nz);
//        
//        for (int i = 0; i < u.Nx(); i++) {
//            double a = sin(i*h);
//            double b = cos(i*h);
//            for (int j = 0; j < u.Ny(); j++) {
//                for (int k = 0; k < u.Nz(); k++) {
//                    u(i,j,k) = a;
//                    ux(i,j,k) = b;
//                    uxx(i,j,k) = -a;
//                }
//            }
//        }
//
//        
//        
//        myData vx = u.D1(h, order, X_DIR);
////        myData vxx = u.D2(h, order, X_DIR);
//    
//        myData w = vx - ux;
////        w = vxx - uxx;
//        err1[n] = w.Norm()*sqrt(h);
////        err1[n] = w.Norm()*h;
//        
//        for (int i = 0; i < u.Nx(); i++)
//            for (int j = 0; j < u.Ny(); j++)
//                for (int k = 0; k < u.Nz(); k++)
//                    cout<<w(i,j,k)<<endl;
//    }
//
//    for (int i = 0; i < 4; i++)
//        cout<<"Error :"<<err1[i]<<endl;
//    
//    for (int i = 0; i < 4; i++)
//        cout<<"Value :"<<log2(err1[i])<<endl;
//    
//    for (int i = 0; i < 3; i++)
//        cout<<"D1 :"<<log2(err1[i]) - log2(err1[i+1])<<endl;
    

    double h = 0.04;
    int order = 2;
    double tEnd = 2;
    double dt_coef = 0.1;
    
    for (int i = 0; i < argc; i++) {
        if (strcmp(argv[i],"-o") == 0)
            order = atoi(argv[i+1]);
        if (strcmp(argv[i],"-h") == 0)
            h = atof(argv[i+1]);
        if (strcmp(argv[i],"-dt") == 0)
            dt_coef = atof(argv[i+1]);
        if (strcmp(argv[i],"-t") == 0)
            tEnd = atof(argv[i+1]);
        if (strcmp(argv[i],"--help") == 0){
            cout<<"Useage : ./fdm [options]"<<endl;
            cout<<"\t -o : order of accuracy (Default is 2)"<<endl;
            cout<<"\t -h : spatial step size (Default is 0.04)"<<endl;
            cout<<"\t -dt : time step size coefficient(Default is c = 0.1 in dt = c*h)"<<endl;
            cout<<"\t -t : Final calculation time (Default is 2)"<<endl;
            return 0;
        }
    }
    double dt = dt_coef*h;
    
    cout<<"Initialising..."<<endl;
    cout<<"Order of accuracy: "<<order<<endl;
    cout<<"Spatial step size: "<<h<<endl;
    cout<<"Time step: "<<dt<<endl;
    cout<<"Final time: "<<tEnd<<endl;
    
    FDM::pmlSolver pmlSol(h,dt,order);
    FDM::solver refSol(h,dt,order);
    
    pmlSol.Set_EndTime(tEnd);
    refSol.Set_EndTime(tEnd);
    

    int LN_X = 2;
    int LN_Y = 1;
    int LN_Z = 1;
    
    int ref_LN_Y = 2;
    
    vector<double> x_layers(LN_X + 1);
    x_layers[0] = 0;
    x_layers[1] = 0.5;
    x_layers[2] = 1;    

    vector<double> y_layers(ref_LN_Y + 1);
    y_layers[0] = 0;
    y_layers[1] = 1;
    y_layers[2] = 6;
    
    vector<double> z_layers(LN_Z + 1);
    z_layers[0] = 0;
    z_layers[1] = 1;
    
    vector<double> pml_y_layers(LN_Y + 1);
    pml_y_layers[0] = 0;
    pml_y_layers[1] = 1;
    
    vector<double> ref_spd(LN_X*ref_LN_Y*LN_Z);
    ref_spd[0] = 1;
    ref_spd[1] = 1;
    ref_spd[2] = 1;
    ref_spd[3] = 1;
    
    vector<double> spd(LN_X*LN_Y*LN_Z);
    spd[0] = 1;
    spd[1] = 1;

    refSol.Set_Domain(x_layers, y_layers, z_layers, ref_spd);
    pmlSol.Set_Domain(x_layers, pml_y_layers, z_layers, spd);
    
    refSol.Set_FourceFunction(RikerWavelet, NULL);
    pmlSol.Set_FourceFunction(RikerWavelet, NULL);

    pmlSol.Set_Plotter(plot, NULL);
//////////
//    pmlSol.Set_Initializer(start, NULL);
//    pmlSol.Set_Finilizer(finale, NULL);
//    pmlSol.Set_FourceFunction(MMS, NULL);
//    pmlSol.Set_DampingCoeff(false,0);
//
//    refSol.Set_Initializer(start, NULL);
//    refSol.Set_Finilizer(finale, NULL);
//    refSol.Set_FourceFunction(MMS, NULL);
    
    Vdata pml = pmlSol.run();
    Vdata ref = refSol.run();
    double err = 0;
    double val = 0;

    for (int i = 0; i < LN_X; i++) {
        for (int j = 0; j < ref_LN_Y - 1; j++) {
            for (int k = 0; k < LN_Z; k++) {
                int ind = idx(i, j, k);
                val = (pml[ind]-ref[ind]).NormSquare();
                err+=val;
            }
        }
    }
    
    err = sqrt(err)*sqrt(h*h*h);
    cout << "-----------------------"<<endl;
    cout<<"Error:"<<err<<endl;
    cout<<"log2(error):"<<log2(err)<<endl;
    cout << "-----------------------"<<endl;
    
    return 0;
}
Esempio n. 7
0
int main()
{
    base::AtExitManager exit_manager;
    base::CommandLine::Init(0, NULL);
    BaseInitLoggingImpl(L"debug.log", base::LOG_ONLY_TO_FILE,
        base::LOCK_LOG_FILE, base::DELETE_OLD_LOG_FILE);

    int loga = base::Log2Floor(1);

    base::Environment* e = base::Environment::Create();
    std::string sys_path;
    e->GetVar("path", &sys_path);

    base::CPU cpu;

    bool finite = base::IsFinite(1.01);

    base::FilePath path;
    std::vector<std::wstring> components;
    path.GetComponents(&components);
    path.Append(L"c:");
    path.Append(L"pWRD");
    path.Append(L"testDir");
    path.Append(L"\\wlw.txt");
    path.GetComponents(&components);
    bool absolute = path.IsAbsolute();

    base::FilePath path2(L"wlwtxt");
    path2.GetComponents(&components);
    absolute = path2.IsAbsolute();

    base::FilePath search_path(L"C:\\");
    base::CountFilesCreatedAfter(search_path, base::Time::Now());

    int err = base::EnsureDirectoryForFile(path, NULL);
    base::Delete(base::FilePath(L"c:\\pWRD"), true);

    FileVersionInfo* fvi = FileVersionInfo::CreateFileVersionInfoForCurrentModule();
    if(fvi)
    {
        std::wstring file_ver = fvi->file_version();
        delete fvi;
    }

    base::FileEnumerator file_iter(search_path, false,
        base::FileEnumerator::DIRECTORIES, L"3rd");
    for(base::FilePath current=file_iter.Next(); !current.Empty();
        current=file_iter.Next())
    {
        std::wcout << current.value() << std::endl;
        base::FileEnumerator::FindInfo fi;
        file_iter.GetFindInfo(&fi);
        if(file_iter.IsDirectory(fi))
        {
            int64 size = base::ComputeDirectorySize(current);
            std::wcout << L"Directory size is: " << size << std::endl;
            size = base::ComputeFilesSize(current, L"");
            std::wcout << L"Files size is: " << size << std::endl;
        }
    }

    Pickle p;
    p.WriteInt(1);
    p.WriteString("I'm wlw!");
    p.WriteWString(L"I'm WLW!");
    int p_i;
    std::string p_str;
    std::wstring p_wstr;
    void* iter = NULL;
    p.ReadInt(&iter, &p_i);
    p.ReadString(&iter, &p_str);
    p.ReadWString(&iter, &p_wstr);

    base::RegKey reg(HKEY_CURRENT_USER, L"Environment", KEY_QUERY_VALUE);
    std::wstring reg_temp;
    if(reg.Valid())
    {
        reg.ReadValue(L"TEMP", &reg_temp);
    }

    CoInitialize(NULL);
    base::ScopedComPtr<IDropTargetHelper, &IID_IDropTargetHelper> scomp;
    if(SUCCEEDED(scomp.CreateInstance(CLSID_DragDropHelper)))
    {
        scomp = NULL;
    }
    CoUninitialize();

    scoped_ptr<double> spd(new double(3.1));
    spd.reset();

    base::Singleton<FooClass>::get()->Bar();

    int cvt = 0;
    base::StringToInt("123", &cvt);
    std::string str_d = base::DoubleToString(2.123);

    base::StringPiece s1;
    assert(s1.length() == 0);
    assert(s1.size() == 0);
    assert(s1.data() == NULL);

    base::StringPiece s2("I love you");
    assert(s2.find('I') != base::StringPiece::npos);

    std::vector<std::string> v;
    base::SplitString("wlw&el", '&', &v);

    std::vector<std::string> subst;
    subst.push_back("10");
    subst.push_back("20");
    subst.push_back("30");
    std::string add = ReplaceStringPlaceholders("$2+$1=$3", subst, NULL);
    string16 bytes = FormatBytes(5*1024, DATA_UNITS_KIBIBYTE, true);

    std::string profile = base::StringPrintf("wlw's age is %d", 29);

    LOG(WARNING) << "This is a warning!";
    //DCHECK(1 == 0);

    base::Time::EnableHighResolutionTimer(true);
    base::Time t = base::Time::Now();
    base::Time::Exploded te;
    t.LocalExplode(&te);
    base::TimeTicks tt = base::TimeTicks::Now();
    base::TimeTicks tth = base::TimeTicks::HighResNow();

    std::string utf8 = WideToUTF8(L"wan lian wen - мРа╛нд");
    std::wstring wide = UTF8ToWide(utf8);

    DictionaryValue root;
    root.SetString("global.pages.homepage", "http://goateleporter.com");
    std::string homepage = "http://google.com";
    root.GetString("global.pages.homepage", &homepage);

    Version* ver = Version::GetVersionFromString("2.0.0.1");
    delete ver;

    base::WinVersion version = base::GetWinVersion();

    std::wstring user_sid;
    base::GetUserSidString(&user_sid);

    std::string base64;
    base::Base64Encode("I'm wlw.", &base64);
    std::string md5 = MD5String("I'm wlw.");
    std::string sha1 = base::SHA1HashString("I'm wlw.");
    std::string sha2 = base::SHA256HashString("I'm wlw.");

    std::string json = base::GetDoubleQuotedJson("a<>b;\nb = 0;");
    std::string json_write;
    base::JSONWriter::Write(&root, false, &json_write);
    Value* json_read = base::JSONReader::Read(json_write, false);
    delete json_read;

    Tuple3<int, double, bool> t3 = MakeTuple(10, 2.5, false);

    ObjClass obj;
    Callback0::Type* callback = NewCallback(&obj, &ObjClass::Bar);
    callback->Run();
    delete callback;

    thred.Start();
    thred.message_loop()->PostDelayedTask(new PrintTask(), 1000);

    MessageLoop msg_loop;
    msg_loop.PostDelayedTask(new MainThreadPrintTask(), 3000);
    msg_loop.Run();

    thred.Stop();

    return 0;
}
Esempio n. 8
0
int Main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    static const struct option options[] =
    {
	{ "help", no_argument, NULL, 'h' },
	{ "threads", required_argument, NULL, 't' },
	{ NULL, 0, NULL, 0 }
    };

    unsigned int nthreads = 32;

    int option_index;
    int option;
    while ((option = getopt_long(argc, argv, "ht:", options, &option_index))
	   != -1)
    {
	switch (option)
	{
	case 'h':
	    Usage(stdout);
	    return 0;
	case 't':
	    nthreads = (unsigned int)strtoul(optarg, NULL, 10);
	    break;
	default:
	    Usage(stderr);
	    return 1;
	}
    }

    const char *media_root;
    const char *flac_root = "";

    switch ((int)(argc-optind)) // How many more arguments?
    {
    case 2:
	media_root = argv[optind];
	flac_root  = argv[optind+1];
	break;
    case 1:
	media_root = argv[optind];
	break;
    default:
	Usage(stderr);
	return 1;
    }

    util::http::Client http_client;
    db::steam::Database sdb(mediadb::FIELD_COUNT);
    sdb.SetFieldInfo(mediadb::ID, 
		     db::steam::FIELD_INT|db::steam::FIELD_INDEXED);
    sdb.SetFieldInfo(mediadb::PATH,
		     db::steam::FIELD_STRING|db::steam::FIELD_INDEXED);
    sdb.SetFieldInfo(mediadb::ARTIST,
		     db::steam::FIELD_STRING|db::steam::FIELD_INDEXED);
    sdb.SetFieldInfo(mediadb::ALBUM,
		     db::steam::FIELD_STRING|db::steam::FIELD_INDEXED);
    sdb.SetFieldInfo(mediadb::GENRE,
		     db::steam::FIELD_STRING|db::steam::FIELD_INDEXED);

    util::WorkerThreadPool wtp(util::WorkerThreadPool::LOW, nthreads);
    db::local::Database db(&sdb, &http_client, &wtp);

    db::local::FileScanner ifs(media_root, flac_root, &sdb, &db, &wtp);

    mediadb::Registry registry;

    ScanProgressDialog spd(&db, &registry);
    spd.show();
    ifs.AddObserver(&spd);

    unsigned int rc = ifs.StartScan();
    assert(rc == 0);
    if (rc)
    {
	fprintf(stderr, "Scanning failed: %u\n", rc);
	exit(1);
    }

    return app.exec();
}