Exemple #1
0
	OgreWindow::OgreWindow(OgreModule& module, UiWindow& window, Ogre::RenderWindow& context)
		: RenderWindow(context.getWidth(), context.getHeight(), context.getName(), 0)
		, mModule(module)
		, mWindow(window)
		, mContext(context)
	{
		Ogre::WindowEventUtilities::addWindowEventListener(&mContext, this);

		mContext.getCustomAttribute("WINDOW", &mHandle);
	}
void ApplicationContextAndroid::_fireInputEventAndroid(AInputEvent* event, int wheel) {
    Event evt = {0};

    static TouchFingerEvent lastTouch = {0};

    if(wheel) {
        evt.type = MOUSEWHEEL;
        evt.wheel.y = wheel;
        _fireInputEvent(evt, 0);
        lastTouch.fingerId = -1; // prevent move-jump after pinch is over
        return;
    }

    if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) {
        int32_t action = AMOTION_EVENT_ACTION_MASK & AMotionEvent_getAction(event);

        switch (action) {
        case AMOTION_EVENT_ACTION_DOWN:
            evt.type = FINGERDOWN;
            break;
        case AMOTION_EVENT_ACTION_UP:
            evt.type = FINGERUP;
            break;
        case AMOTION_EVENT_ACTION_MOVE:
            evt.type = FINGERMOTION;
            break;
        default:
            return;
        }

        Ogre::RenderWindow* win = getRenderWindow();

        evt.tfinger.fingerId = AMotionEvent_getPointerId(event, 0);
        evt.tfinger.x = AMotionEvent_getRawX(event, 0) / win->getWidth();
        evt.tfinger.y = AMotionEvent_getRawY(event, 0) / win->getHeight();

        if(evt.type == FINGERMOTION) {
            if(evt.tfinger.fingerId != lastTouch.fingerId)
                return; // wrong finger

            evt.tfinger.dx = evt.tfinger.x - lastTouch.x;
            evt.tfinger.dy = evt.tfinger.y - lastTouch.y;
        }

        lastTouch = evt.tfinger;
    } else {
        if(AKeyEvent_getKeyCode(event) != AKEYCODE_BACK)
            return;

        evt.type = AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN ? KEYDOWN : KEYUP;
        evt.key.keysym.sym = SDLK_ESCAPE;
    }

    _fireInputEvent(evt, 0);
}
VIEW_API void windowAttributes(size_t& handle, u32& width, u32& height)
{
	Ogre::Root* root = Ogre::Root::getSingletonPtr();
	
	if (! root)
		throw std::logic_error
			("View::windowAttributes: Ogre hasn't been initialized yet.");
	
	Ogre::RenderWindow* win = root->getAutoCreatedWindow();

	win->getCustomAttribute("WINDOW", &handle);
	height = win->getHeight();
	width = win->getWidth();
}
//----------------------------------------------------------------------------//
OIS::MultiTouchState& AndroidMultiTouch::getMultiTouchState (int i)
{
    while (i >= mStates.size())
    {
        Ogre::RenderWindow* pRenderWnd =
            static_cast<Ogre::RenderWindow*> (Ogre::Root::getSingleton().getRenderTarget ("OgreWindow"));
        if (pRenderWnd)
        {
            OIS::MultiTouchState state;
            state.width = pRenderWnd->getWidth();
            state.height = pRenderWnd->getHeight();
            mStates.push_back (state);
        }
    }
    return mStates[i];
}
//---------------------------------------------------------------------------------------------
void TEditorMapLogic::HandleFromGraphicEngine_Key( nsGraphicEngine::TKeyEvent* pKeyGE )
{
  bool fast = bool( pKeyGE->modifier & OIS::Keyboard::Shift );
  mPtrControlCamera->SetFast( fast );

  switch( pKeyGE->key )
  {
    case OIS::KC_W:
      mPtrControlCamera->SetMoveForward( pKeyGE->pressed );
      break;
    case OIS::KC_S:
      mPtrControlCamera->SetMoveBackward( pKeyGE->pressed );
      break;
    case OIS::KC_A:
      mPtrControlCamera->SetMoveLeft( pKeyGE->pressed );
      break;
    case OIS::KC_D:
      mPtrControlCamera->SetMoveRight( pKeyGE->pressed );
      break;
    case OIS::KC_Q:
      mPtrControlCamera->SetMoveDown( pKeyGE->pressed );
      break;
    case OIS::KC_E:
      mPtrControlCamera->SetMoveUp( pKeyGE->pressed );
      break;
    case OIS::KC_ESCAPE:
      Exit();
      break;
    case OIS::KC_RETURN:// experimental
    {
      if( OIS::Keyboard::Alt & pKeyGE->modifier )
      {
        Ogre::RenderWindow* pRW = mComp.pGraphicEngine->GetGE()->GetWindow();
        int width = pRW->getWidth();
        int height = pRW->getHeight();
        bool isFullScreen = pRW->isFullScreen();
        pRW->setFullscreen( !isFullScreen, width, height );
      }
    }
    break;
  }
}
Exemple #6
0
void EC_SelectionBox::SetBoundingBox(QRect &view)
{
    if (world_.expired())
        return;
    OgreWorldPtr world = world_.lock();
    Renderer* renderer = world->GetRenderer();
    Ogre::RenderWindow *renderWindow = renderer->GetCurrentRenderWindow();
    float w= (float)renderWindow->getWidth();
    float h= (float)renderWindow->getHeight();
    float left = (float)(view.left()) / w, right = (float)(view.right()) / w;
    float top = (float)(view.top()) / h, bottom = (float)(view.bottom()) / h;
    
    if(left > right) { float tmp; tmp = left; left = right; right = tmp; }
    if(top > bottom) { float tmp; tmp = top; top = bottom; bottom = tmp; }
    // don't do selection box if too small
    if((right - left) * (bottom-top) < 0.0001) return;
    
    // correct coordinates for overlay
    left = left * 2 - 1;
    right = right * 2 - 1;
    top = 1 - top * 2;
    bottom = 1 - bottom * 2;
 
    selectionBox_->clear();
    selectionBox_->begin("BlueTransparent",Ogre::RenderOperation::OT_TRIANGLE_STRIP);
    selectionBox_->position(left, bottom, -1);
    selectionBox_->position(right, bottom, -1);
    selectionBox_->position(left, top, -1);
    selectionBox_->position(right, top, -1);
    selectionBox_->end();
    selectionBox_->begin("",Ogre::RenderOperation::OT_LINE_STRIP);
    selectionBox_->position(left, top, -1);
    selectionBox_->position(right, top, -1);
    selectionBox_->position(right, bottom, -1);
    selectionBox_->position(left, bottom, -1);
    selectionBox_->position(left, top, -1);
    selectionBox_->end();
    
    selectionBox_->setBoundingBox(Ogre::AxisAlignedBox::BOX_INFINITE);
}
    /**
     * This is the most basic "triangle" example, done as a Scene in Ogre.
     */
    Ogre::SceneManager* createTriangleScene() {
        Ogre::SceneManager* scene = mRoot->createSceneManager(Ogre::ST_GENERIC);

        // Configure camera (~ view & projection transforms, i.e. gluLookAt + glOrtho)
        Ogre::Camera* camera = scene->createCamera("MainCamera"); // We can use an arbitrary name here
        camera->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
        camera->setOrthoWindow(2, 2);              // ~ glOrtho(-1, 1, -1, 1)
        camera->setAspectRatio((float) mWindow->getWidth() / mWindow->getHeight());
        camera->setNearClipDistance(0.5);
        camera->setPosition(Ogre::Vector3(0,0,1)); // Move camera away from (0, 0, 0), otherwise the triangle at z=0 will be clipped

        // Now add some geometry to the scene
        Ogre::ManualObject* triangle = scene->createManualObject("Triangle");

        // ~ glBegin, glVertex, glEnd
        // "BaseWhiteNoLighting" is a built-in name for a basic non-lit material
        triangle->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
        triangle->position(0, 0.5, 0);            // ~ glVertex.
                                                  // Contrary to OpenGL we *first* must create the vertex
        triangle->colour(Ogre::ColourValue::Red); // .. and then provide its attributes such as color (~ glColor)
        triangle->position(-0.5, -0.5, 0);
        triangle->colour(Ogre::ColourValue::Green);
        triangle->position(0.5, -0.5, 0);
        triangle->colour(Ogre::ColourValue::Blue);
        triangle->end();

        // Add the created triangle object to the scene graph
        // For this we create a SceneNode object, which will combine information about
        // the object's geometry with its modeling transform
        // (see frameRenderingQueued to understand how to rotate the triangle by changing this transform)
        scene->getRootSceneNode()->createChildSceneNode("Triangle")->attachObject(triangle);

        // Exercise 1: Create new object, add vertices, attach the object to a new SceneNode
        // ...

        return scene;
    }
bool OISManager::init()
{
	OIS::ParamList pl;
	size_t windowHnd = 0;
	std::ostringstream windowHndStr;
	Ogre::RenderWindow* rw = OgreManager::getInstance().getRenderWindow();
	rw->getCustomAttribute("WINDOW", &windowHnd);
	windowHndStr << windowHnd;
	pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));

	_inputManager = OIS::InputManager::createInputSystem( pl );

	 _keyboard = static_cast<OIS::Keyboard*>(_inputManager->createInputObject( OIS::OISKeyboard, true ));
	_mouse = static_cast<OIS::Mouse*>(_inputManager->createInputObject( OIS::OISMouse, true ));
	const OIS::MouseState &ms = _mouse->getMouseState();
	ms.width = static_cast<int>(rw->getWidth());
	ms.height = static_cast<int>(rw->getHeight());

	_keyboard->setEventCallback(this);
	_mouse->setEventCallback(this);

	_L = ScriptManager::getInstance().getLuaVM();
	return true;
}