コード例 #1
0
ファイル: Win32EGLWindow.cpp プロジェクト: wangyanxing/Demi3D
    static INT_PTR CALLBACK windowProc(HWND hwnd, uint32 msg, WPARAM wParam, LPARAM lParam)
    {
        DiWin32EGLWindow* window = (DiWin32EGLWindow*)LongToPtr(GetWindowLongPtr(hwnd, GWLP_USERDATA));
        DiRenderWindow* renderWnd = DiBase::Driver->FindRenderWindow(DiWndHandle(hwnd));

        if (window && window->DestroyingWindow())
            return 0;

        switch (msg)
        {
        case WM_CREATE:
            ::UpdateWindow(hwnd);
            break;

        case WM_CLOSE:
            DiBase::CommandMgr->ExecuteCommand("quit");
            break;
        case WM_ACTIVATE:
        {
            bool active = (LOWORD(wParam) != WA_INACTIVE);
            if (active)
            {
                if (renderWnd)
                    renderWnd->GetRenderBuffer()->SetActive(true);
            }
            else
            {
                if (renderWnd)
                    renderWnd->GetRenderBuffer()->SetActive(false);
            }
            break;
        }
    
        case WM_COPYDATA:
        {
            const char* str = (const char*)(((COPYDATASTRUCT*)lParam)->lpData);
            DiString s(str, ((COPYDATASTRUCT*)lParam)->cbData);
            DiBase::CommandMgr->ExecuteCommand(s.c_str());
            break;
        }

        default:
            return ::DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    }
コード例 #2
0
ファイル: InputManager.cpp プロジェクト: wangyanxing/Demi3D
    void DiInputManager::captureInput()
    {
        if (mMouse)
        {
            mMouse->capture();

            DiRenderWindow* rw = Driver->GetMainRenderWindow();
            setInputViewSize(rw->GetWidth(), rw->GetHeight());
        }
        if(mKeyboard)
            mKeyboard->capture();
        
#if OIS_WITH_MULTITOUCH
        if(mMultiTouch)
            mMultiTouch->capture();
#endif
        if(mAccelerometer)
            mAccelerometer->capture();
    }
コード例 #3
0
ファイル: CameraHelper.cpp プロジェクト: redkaras/Demi3D
    bool DiCameraHelper::Update( float elapsed )
    {
        if (!mEnabled)
        {
            return false;
        }

        if (mStyle == CS_FREELOOK)
        {
            DiVec3 accel = DiVec3::ZERO;
            if (mGoingForward) 
            {
                accel += mCamera->GetDirection();
            }
            if (mGoingBack)    accel -= mCamera->GetDirection();
            if (mGoingRight)    accel += mCamera->GetRight();
            if (mGoingLeft)    accel -= mCamera->GetRight();
            if (mGoingUp)        accel += mCamera->GetUp();
            if (mGoingDown)    accel -= mCamera->GetUp();

            float topSpeed = mFastMove ? mTopSpeed * 20 : mTopSpeed;
            if (accel.squaredLength() != 0)
            {
                accel.normalise();
                mVelocity += accel * topSpeed * elapsed * 10;
            }
            else 
            {
                mVelocity -= mVelocity * elapsed * 10;
            }

            float tooSmall = std::numeric_limits<float>::epsilon();

            if (mVelocity.squaredLength() > topSpeed * topSpeed)
            {
                mVelocity.normalise();
                mVelocity *= topSpeed;
            }
            else if (mVelocity.squaredLength() < tooSmall * tooSmall)
            {
                mVelocity = DiVec3::ZERO;
            }

            if (mVelocity != DiVec3::ZERO) 
            {
                mCamera->Move(mVelocity * elapsed);
            }
        }
        else if (mStyle == CS_SMOOTH)
        {
            if (Driver && mMousePos.x >= 0 && mMousePos.y >= 0)
            {
                DiRenderWindow* window = Driver->GetMainRenderWindow();
                int x = (mMousePos.x - window->GetWidth() / 2);
                int y = (mMousePos.y - window->GetHeight() / 2);
                DiVec3 pos = mCamera->GetPosition();
                pos.x += (x - pos.x) * 0.01f;
                pos.y += (-y - pos.y) * 0.01f;
                mCamera->SetPosition(pos);
                mCamera->LookAt(0, 0, 0);
            }
        }

        return true;
    }