Esempio n. 1
0
void Asteroids::OnMouseDragged(int x, int y)
{
    GLVector2i mouseVector(GLVector2i(x, mGameDisplay->GetHeight() - y));
//        mSpaceship->Shoot();


//        mGameWorld->AddObject(CreateAsteroid(x,y));
//        mGameWorld->AddObject(CreateAsteroid());
//        mAsteroidCount++;
    const int zl = mGameWindow->GetZoomLevel();
    GLVector3f m2w((x - mGameDisplay->GetWidth()/2)/zl + mCameraFocus->x, (mGameDisplay->GetHeight()/2 - y)/zl + mCameraFocus->y, 0.0);

    mSelectionBox->SetMouse(GLVector2i(x,y));
    mSelectionBox->SetWorldCoord1(m2w);

//    if(mMoveCamera) {
//        GLVector2i m = GLVector2i(x - mGameWorld->GetWidth(), (y - mGameWorld->GetHeight()) * -1);
//        float delta = sqrt(pow((m.x - mCameraFocus.x),2) * pow((m.y - mCameraFocus.y),2));
//        delta = delta/10.0;
////        mCameraFocus;
//        cout << "Delta       : " << delta << endl;
//        cout << "Mouse Vector: " << m << endl;
//        mCameraFocus += m*delta;
//    }
//    cout << "Camera Focus: " << mCameraFocus << endl;
//    cout << endl;
}
Esempio n. 2
0
void printTimeCodes(const Option &opt, TrackEditor &track)
{
#ifdef _WIN32
    utf8_codecvt_facet u8codec;
    std::wstring wname = m2w(opt.timecodeFile, utf8_codecvt_facet());
    FILE *fp = std::strcmp(opt.timecodeFile, "-")
               ? _wfopen(wname.c_str(), L"w")
               : stdout;
#else
    FILE *fp = std::strcmp(opt.timecodeFile, "-")
               ? std::fopen(opt.timecodeFile, "w")
               : stdout;
#endif
    if (!fp)
        throw std::runtime_error("Can't open timecode file");
    uint32_t timeScale = track.GetTimeScale();
    std::fputs("# timecode format v2\n", fp);
    if (track.GetFrameCount()) {
        uint64_t off = track.CTS(0);
        for (size_t i = 0; i < track.GetFrameCount(); ++i) {
            uint64_t cts = track.CTS(i) - off;
            std::fprintf(fp, "%.15g\n",
                static_cast<double>(cts) / timeScale * 1000.0);
        }
    }
    std::fclose(fp);
}
static void test_comstl_C_BSTR_create_len_a(void)
{
    char const alphabet[] = "abcdefghijklmnopqrstuvwxyz";

    { size_t i; for(i = 0; i != dimensionof(alphabet); ++i)
    {
        BSTR const s = comstl_C_BSTR_create_len_a(alphabet, i);

        XTESTS_TEST_WIDE_STRING_EQUAL_N(m2w(alphabet), s, (int)i);
        XTESTS_TEST_INTEGER_EQUAL(i, SysStringLen(s));
        XTESTS_TEST_INTEGER_EQUAL(SysStringLen(s), comstl_C_BSTR_len(s));

        comstl_C_BSTR_destroy(s);
    }}
}
int main()
{
     /*使用wcstombs和mbstowcs之前必须调用setlocale,以便决定内码*/
     setlocale(LC_ALL,"zh_CN.utf8"); //默认设置为utf8,即转换为utf8的多字节
     /*假定有一个Unicode(UTF-16LE)编码的文件,将其打开,重新编码为ANSI
,写入aa.txt中,再继续编码回Unicode,写入aw.txt中*/
     /*如果不存在a.txt文件,则程序出错,没有做错误处理*/
     char* filename = "text.file.uni";
     char* filenamea = "aa.txt";
     char* filenamew = "aw.txt";
     FILE*     input=fopen( filename, "rb");
     FILE*     inputa=fopen( filenamea, "wb");
     FILE*     inputw=fopen( filenamew, "wb");
     /*BOE设置,UTF-16LE的BOE为FEFF,如果不先将其读取出来,wcstombs会调用失败*/
     unsigned short BOM ;
     fread(&BOM,sizeof(unsigned short),1,input);
     fwrite(&BOM,sizeof(unsigned short),1,inputw);
     unsigned short word = 0;
     unsigned short *buffer = (unsigned short *)malloc(sizeof(unsigned short)*BUFF_SIZE);
     unsigned short *pBuffer = buffer;
     printf("%d\n",sizeof(wchar_t));
     int count = 0;
     /*开始读取文件*/
     while((count=readUnicodeLine(buffer,BUFF_SIZE,input))!=-1)
     {
       if(count>0){
         //当前行有数据
         char *buf = w2m(buffer);
         printf("%s\n",buf);
         fprintf(inputa,"%s\n",buf);
         int len;
         wchar_t * bufWideChar = m2w(buf,&len);
         fwrite(buffer,sizeof(wchar_t),count,inputw);
         free(bufWideChar);
         free(buf);
       }
     }
     /*后续处理*/
     free(buffer);
     fclose(input);
     fclose(inputa);
     fclose(inputw);
     return 0;
}
Esempio n. 5
0
void loadTimecodeV2(Option &option, size_t count)
{
    std::wstring wfname = m2w(option.timecodeFile, utf8_codecvt_facet());

    HANDLE fh = CreateFileW(wfname.c_str(), GENERIC_READ,
        FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
    if (fh == INVALID_HANDLE_VALUE)
        throw std::runtime_error("Can't open timecode file");

    DWORD nread;
    char buffer[8192];
    std::stringstream ss;
    while (ReadFile(fh, buffer, sizeof buffer, &nread, 0) && nread > 0)
        ss.write(buffer, nread);
    CloseHandle(fh);

    ss.seekg(0);
    parseTimecodeV2(option, ss, count);
}
static void test_comstl_C_BSTR_create_a_2()
{
    char const* const strings[] =
    {
            ""
        ,   "a"
        ,   "abc"
        ,   "abcdefghijklmnopqrstuvwxyz"
        ,   "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    };

    { size_t i; for(i = 0; i != dimensionof(strings); ++i)
    {
        BSTR const s = comstl_C_BSTR_create_a(strings[i]);

        XTESTS_TEST_WIDE_STRING_EQUAL(m2w(strings[i]), s);
        XTESTS_TEST_INTEGER_EQUAL(strlen(strings[i]), SysStringLen(s));
        XTESTS_TEST_INTEGER_EQUAL(SysStringLen(s), comstl_C_BSTR_len(s));

        comstl_C_BSTR_destroy(s);
    }}
}
Esempio n. 7
0
void Asteroids::OnMouseButton(int button, int state, int x, int y)
{

    if(state == GLUT_DOWN)
    {
        if(button == GLUT_RIGHT_BUTTON)
        {
            mMoveCamera = true;

            // Calculate world coordinates
            const int zl = mGameWindow->GetZoomLevel();
            GLVector3f m2w((x - mGameDisplay->GetWidth()/2)/zl + mCameraFocus->x, (mGameDisplay->GetHeight()/2 - y)/zl + mCameraFocus->y, 0.0);

            SmartPtr<GameObject> checkSelect = mGameWorld->GetOnClickSelect(m2w);
            SmartPtr<Order> o = NULL;
            if(checkSelect.GetPtr() == NULL) {
                o = new Order(ORDER_MOVE);
                o->SetDestination(m2w);
            } else {
                o = new Order(ORDER_ATTACK);
                o->SetTarget(checkSelect);
            }
            mGameWorld->AssignOrderToSelected(o);
        }
        if(button == GLUT_LEFT_BUTTON)
        {
//            cout << endl;
//            cout << "GLUT MOUSE: " << x << "\t" << y << endl;

//            GLVector2i mouseVector(GLVector2i(x, mGameDisplay->GetHeight() - y));
//            cout << "GUI COORDS: " << mouseVector.x << "\t" << mouseVector.y << endl;

//            float dw = mGameDisplay->GetWidth();
//            float dh = mGameDisplay->GetHeight();
//            cout << "DISPLAY WH: " << dw << "\t" << dh << endl;

            // Get game zoom level
//            cout << "ZOOM LEVEL: " << zl << endl;

//            GLVector3f mouse2world((x - dw/2)/zl + mCameraFocus->x, (dh/2 - y)/zl + mCameraFocus->y, 0.0);
//
//            cout << "M2W COORDS: " << mouse2world.x << "\t" << mouse2world.y << endl;
//            cout << "CAM  FOCUS: " << mCameraFocus->x << "\t" << mCameraFocus->y << endl;

//            mGameWorld->AddObject(CreateAsteroid(x,y));
//            mGameWorld->AddObject(CreateAsteroid());
//            mAsteroidCount++;

            // get zoom level of the game to calculate world coordinates
            const int zl = mGameWindow->GetZoomLevel();
            // Calculate the world coordinate corresponding to mouse coordinates (m2w = mouse to world).
            GLVector3f m2w((x - mGameDisplay->GetWidth()/2)/zl + mCameraFocus->x, (mGameDisplay->GetHeight()/2 - y)/zl + mCameraFocus->y, 0.0);


            // Make the selection box visible
            mSelectionBox->SetVisible(true);
            // Set the starting point for the box to be the mouse coordinates
            mSelectionBox->SetStart(GLVector2i(x,y));
            // Set the second point of the box (where mouse is) to also be the mouse coordinates to reset it
            mSelectionBox->SetMouse(GLVector2i(x,y));
            // Set the world coordinates coresponding to  the mouse coordinates
            mSelectionBox->SetWorldCoord1(m2w);
            mSelectionBox->SetWorldCoord2(m2w);

            SmartPtr<GameObject> selectedGO = mGameWorld->GetOnClickSelect(m2w);
            if(selectedGO.GetPtr() != NULL){
                if(selectedGO->GetType() == GameObjectType("Drone"))
                {
                    selectedGO->MakeSelected();
                }
            }
            cout << "CLICK FOUND: " << selectedGO.GetPtr() << endl;

            //mGameWorld->AddObject(CreateAsteroid(mouse2world.x, mouse2world.y));
//            SmartPtr<GameObject> a = CreateAsteroid(mGameWorld->GetHeight(), mGameWorld->GetWidth());
            //a->SetVelocity(GLVector3f(0.0,-100.0,0.0));
            //mGameWorld->AddObject(a);
            //mAsteroidCount++;
        }
    }
    else if (state == GLUT_UP)
    {
        mSelectionBox->SetVisible(false);
        mMoveCamera = false;
    }
}