예제 #1
0
/*************************************************************************
    Positions the GeometryBuffer based graph
*************************************************************************/
void CustomShapesDrawingSample::positionCustomGeometryFPSGraph()
{
    CEGUI::Renderer* renderer = CEGUI::System::getSingleton().getRenderer();
    const CEGUI::Rectf scrn(glm::vec2(0, 0), renderer->getDisplaySize());

    d_FPSGraphGeometryBuffer->setClippingRegion(scrn);
    d_FPSGraphGeometryBuffer->setTranslation(glm::vec3(250.0f, 250.0f, 0.0f));
}
예제 #2
0
Layer2D::Layer2D():m_pRootBuff(&CEGUI::System::getSingleton().getGUISheet()->getGeometryBuffer()),m_pCustomBuff(0),
    m_IsMatrixValid(false)
{
    CEGUI::Renderer *pCEGUIRender = CEGUI::System::getSingleton().getRenderer();
    const CEGUI::Rect scrn(CEGUI::Vector2(0, 0), pCEGUIRender->getDisplaySize());
    //render::Interface *pInterface = render::Interface::GetInstance();
    //LPDIRECT3DDEVICE9 pDevice = pInterface->GetDevice();
    //m_p2DBuff = new CEGUI::Direct3D9GeometryBuffer(pDevice);
    m_pRootBuff->setClippingRegion(scrn);

}
예제 #3
0
    void InputManager::mouseMoved(MouseEvent* e)
	{
		if (isCeguiActive() && mBuffered)
		{			
			e->consume();

			CEGUI::Renderer* renderer  = System::getSingleton().getRenderer();
			System::getSingleton().injectMouseMove(
				e->getRelX() * renderer->getWidth(), 
				e->getRelY() * renderer->getHeight());			

			if (mPickObjects)
				updatePickedObject(e->getX(), e->getY());
		}       
	}
예제 #4
0
/*************************************************************************
    Cleans up resources allocated in the initialiseSample call.
*************************************************************************/
void CustomShapesDrawingSample::deinitialise()
{
    // Destroy the GeometryBuffer created for this sample
    CEGUI::Renderer* renderer = CEGUI::System::getSingleton().getRenderer();
    renderer->destroyGeometryBuffer(*d_FPSGraphGeometryBuffer);
    // Destroy the SVGImage created for this sample
    CEGUI::ImageManager& imageManager = CEGUI::ImageManager::getSingleton();
    imageManager.destroy("FPSGraphSVG");
    // Destroy the created custom SVGData
    CEGUI::SVGDataManager& svgDataManager = CEGUI::SVGDataManager::getSingleton();
    svgDataManager.destroy(*d_customSVGData);

    // This destroys the window and its child windows
    WindowManager& winMgr = WindowManager::getSingleton();
    winMgr.destroyWindow(d_root);
}
void
CGUIContextOgre::OnNotify( CORE::CNotifier* notifier   ,
                           const CORE::CEvent& eventID ,
                           CORE::CICloneable* evenData )
{GUCEF_TRACE;

    if ( eventID == GUI::CWindowContext::WindowContextRedrawEvent   ||
         eventID == GUI::CWindowContext::WindowContextActivateEvent  )
    {
        CEGUI::System* guiSystem = m_driver->GetCEGui();
        if ( NULL != guiSystem && NULL != m_ceGuiContext ) 
        {       
            clock_t now = clock();
            float elapsedGuiTime = ( now - m_lastTimeInjection ) * 0.001f;        
            guiSystem->injectTimePulse( elapsedGuiTime );
            m_ceGuiContext->injectTimePulse( elapsedGuiTime );
            m_lastTimeInjection = now;
        
            CEGUI::Renderer* guiRenderer = guiSystem->getRenderer();
            guiRenderer->beginRendering();
        
            m_ceGuiContext->markAsDirty();
            m_ceGuiContext->draw();

            guiRenderer->endRendering();
        }
    }
    else
    if ( eventID == GUI::CWindowContext::WindowContextSizeEvent )
    {        
        GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "GUIContext: Resizing CEGUI GUI context to " + CORE::UInt32ToString( m_windowContext->GetWidth() ) + "x" +
                                                                                                CORE::UInt32ToString( m_windowContext->GetHeight() ) );

		CEGUI::System::getSingleton().notifyDisplaySizeChanged( CEGUI::Sizef( (float) m_windowContext->GetWidth(), (float) m_windowContext->GetHeight() ) );
        //m_ceGuiContext->getRenderTarget().setArea( m_windowContext->GetWidth(), m_windowContext->GetHeight() );

        //CEGUI::Renderer* guiRenderer = m_driver->GetCEGui()->getRenderer();
        //guiRenderer->beginRendering();

        //m_ceGuiContext->markAsDirty();
        //m_ceGuiContext->draw();

        //guiRenderer->endRendering();
    }
}
void OgreNewtonFrameListener::dragCallback( OgreNewt::Body* me, float timestep, int threadindex )
{
	// first find the global point the mouse is at...
	CEGUI::Point mouse = CEGUI::MouseCursor::getSingleton().getPosition();
	CEGUI::Renderer* rend = CEGUI::System::getSingleton().getRenderer();
	
	Ogre::Real mx,my;
	mx = mouse.d_x / rend->getWidth();
	my = mouse.d_y / rend->getHeight();
	Ogre::Ray camray = mCamera->getCameraToViewportRay( mx, my );

	Ogre::Vector3 campt = camray.getPoint( dragDist );

	// now find the global point on the body:
	Ogre::Quaternion bodorient;
	Ogre::Vector3 bodpos;

	me->getPositionOrientation( bodpos, bodorient );

	Ogre::Vector3 bodpt = (bodorient * dragPoint) + bodpos;

	// apply the spring force!
	Ogre::Vector3 inertia;
	Ogre::Real mass;

	me->getMassMatrix( mass, inertia );

	Ogre::Vector3 dragForce = ((campt - bodpt) * mass * 8.0) - me->getVelocity();

	// draw a 3D line between these points for visual effect :)
	remove3DLine();
	mDragLine->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST );
	mDragLine->position( campt );
	mDragLine->position( bodpt );
	mDragLine->end();
	mDragLineNode->attachObject( mDragLine );


	// Add the force!
	me->addGlobalForce( dragForce, bodpt );

	Ogre::Vector3 gravity = Ogre::Vector3(0,-9.8,0) * mass;
	me->addForce( gravity );

}
예제 #7
0
/*************************************************************************
    Sets up everything we need to draw our graph into the GeometryBuffer
*************************************************************************/
void CustomShapesDrawingSample::setupCustomGeometryGraph(CEGUI::GUIContext* guiContext)
{
    CEGUI::Renderer* renderer = CEGUI::System::getSingleton().getRenderer();

    // GeometryBuffer used for drawing in this Sample
    d_FPSGraphGeometryBuffer = &renderer->createGeometryBufferColoured(renderer->createRenderMaterial(DS_SOLID));

    // Calculate and save our custom graph background
    setupCustomGeometryGraphBackground();

    // Clearing this queue actually makes sure it's created(!)
    guiContext->clearGeometry(CEGUI::RQ_OVERLAY);

    // Subscribe handler to render overlay items
    guiContext->subscribeEvent(CEGUI::RenderingSurface::EventRenderQueueStarted,
                               CEGUI::Event::Subscriber(&CustomShapesDrawingSample::drawFPSGraphOverlay,
                                       this));
}
예제 #8
0
void Layer2D::SetupView()
{
    CEGUI::Renderer *pRender = CEGUI::System::getSingleton().getRenderer();
    float width  = pRender->getDisplaySize().d_width;
    float height = pRender->getDisplaySize().d_height;
    if (!m_IsMatrixValid)
    {
        const float fov = 0.523598776f;
        const float w = width;
        const float h = height;
        const float aspect = w / h;
        const float midx = w * 0.5f;
        const float midy = h * 0.5f;
        float fviewDistance = midx / (aspect * 0.267949192431123f);

        D3DXVECTOR3 eye(midx, midy, -fviewDistance);
        D3DXVECTOR3 at(midx, midy, 1);
        D3DXVECTOR3 up(0, -1, 0);

        D3DXMATRIX tmp;
        D3DXMatrixMultiply(&m_matrix,
                           D3DXMatrixLookAtRH(&m_matrix, &eye, &at, &up),
                           D3DXMatrixPerspectiveFovRH(&tmp, fov, aspect,
                                   fviewDistance * 0.5f,
                                   fviewDistance * 2.0f));
        m_IsMatrixValid = true;
    }

    render::Interface *pInterface = render::Interface::GetInstance();
    LPDIRECT3DDEVICE9 pDevice = pInterface->GetDevice();
    D3DVIEWPORT9 vp;
    vp.X = static_cast<DWORD>(0);
    vp.Y = static_cast<DWORD>(0);
    vp.Width = static_cast<DWORD>(width);
    vp.Height = static_cast<DWORD>(height);
    vp.MinZ = 0.0f;
    vp.MaxZ = 1.0f;
    pDevice->SetViewport(&vp);
    pDevice->SetTransform(D3DTS_PROJECTION, &m_matrix);
}
bool OgreNewtonFrameListener::frameStarted(const FrameEvent &evt)
{
	mKeyboard->capture();
	mMouse->capture();

	// ----------------------------------------
	// CAMERA CONTROLS
	// ----------------------------------------
	if ((mKeyboard->isKeyDown(OIS::KC_LSHIFT)) || (mKeyboard->isKeyDown(OIS::KC_RSHIFT)))
	{
		Vector3 trans, strafe, vec;
		Quaternion quat;

		quat = mCamera->getOrientation();

		vec = Vector3(0.0,0.0,-0.5);
		trans = quat * vec;

		vec = Vector3(0.5,0.0,0.0);
		strafe = quat * vec;

		mCamera->pitch( Degree(mMouse->getMouseState().Y.rel * -0.5) );
        mCamera->setFixedYawAxis(true);
		mCamera->yaw( Degree(mMouse->getMouseState().X.rel * -0.5) );

		if (mKeyboard->isKeyDown(OIS::KC_UP))
			mCamera->moveRelative(trans);

		if (mKeyboard->isKeyDown(OIS::KC_DOWN))
			mCamera->moveRelative(trans * -1.0);

		if (mKeyboard->isKeyDown(OIS::KC_LEFT))
			mCamera->moveRelative(strafe * -1.0);

		if (mKeyboard->isKeyDown(OIS::KC_RIGHT))
			mCamera->moveRelative(strafe);
	}


	// ----------------------------------------
	// DRAGGING!
	// ----------------------------------------

	if (!dragging)
	{

		//user pressing the left mouse button?
		if (mMouse->getMouseState().buttonDown(OIS::MB_Left))
		{
			// perform a raycast!
			// start at the camera, and go for 100 units in the Z direction.
			Ogre::Vector3 start, end;

			CEGUI::Point mouse = CEGUI::MouseCursor::getSingleton().getPosition();
			CEGUI::Renderer* rend = CEGUI::System::getSingleton().getRenderer();
	
			Ogre::Real mx,my;
			mx = mouse.d_x / rend->getWidth();
			my = mouse.d_y / rend->getHeight();
			Ogre::Ray camray = mCamera->getCameraToViewportRay(mx,my);

			start = camray.getOrigin();
			end = camray.getPoint( 100.0 );

			OgreNewt::BasicRaycast* ray = new OgreNewt::BasicRaycast( m_World, start, end, true );
			OgreNewt::BasicRaycast::BasicRaycastInfo info = ray->getFirstHit();

			if (info.mBody)
			{
				// a body was found.  first let's find the point we clicked, in local coordinates of the body.
				

				// while dragging, make sure the body can't fall asleep.
				info.mBody->unFreeze();
				//info.mBody->setAutoFreeze(0);

				Ogre::Vector3 bodpos;
				Ogre::Quaternion bodorient;

				info.mBody->getPositionOrientation( bodpos, bodorient );

				// info.mDistance is in the range [0,1].
				Ogre::Vector3 globalpt = camray.getPoint( 100.0 * info.mDistance );
				Ogre::Vector3 localpt = bodorient.Inverse() * (globalpt - bodpos);

				// now we need to save this point to apply the spring force, I'm using the userData of the bodies in this example.
                // (where is it used? probably not needed here...)
#ifndef OGRENEWT_NO_OGRE_ANY
                info.mBody->setUserData( Ogre::Any(this) );
#else
				info.mBody->setUserData( this );
#endif

				// now change the force callback from the standard one to the one that applies the spring (drag) force.
				// this is an example of binding a callback to a member of a specific class.  in previous versions of OgreNewt you were
				// required to use a static member function fr all callbacks... but now through the fantastic FastDelegate library, you can
				// now use callbacks that are members of specific classes.  to do this, use the syntax shown below.  the "this" is a pointer
				// to the specific class, and the 2nd parameter is a pointer to the function you want to use.  you can do this for all
				// body callbacks (ForceAndTorque, Transform, addBuoyancyPlane).
				info.mBody->setCustomForceAndTorqueCallback<OgreNewtonFrameListener>( &OgreNewtonFrameListener::dragCallback, this );

				// save the relevant drag information.
				dragBody = info.mBody;
				dragDist = (100.0 * info.mDistance);
				dragPoint = localpt;

				dragging = true;
			}

			delete ray;

		}

		if (mDragLine)
			remove3DLine();
	}
	else
	{
		// currently dragging!
		if (!mMouse->getMouseState().buttonDown(OIS::MB_Left))
		{
			// no longer holding mouse button, so stop dragging!
			// remove the special callback, and put it back to standard gravity.
			dragBody->setStandardForceCallback();
			//dragBody->setAutoFreeze(1);

			dragBody = NULL;
			dragPoint = Ogre::Vector3::ZERO;
			dragDist = 0.0;

			dragging = false;
		}
	}



    OgreNewt::Debugger& debug(m_World->getDebugger());
    if (mKeyboard->isKeyDown(OIS::KC_F3))
    {
        debug.showDebugInformation();
        debug.startRaycastRecording();
        debug.clearRaycastsRecorded();
    }
    else
    {
        debug.hideDebugInformation();
        debug.clearRaycastsRecorded();
        debug.stopRaycastRecording();
    }



    if (mKeyboard->isKeyDown(OIS::KC_T))
        m_World->setThreadCount( m_World->getThreadCount() % 2 + 1);


	if (mKeyboard->isKeyDown(OIS::KC_ESCAPE))
		return false;

	return true;
}
예제 #10
0
/*************************************************************************
    Win32 'Window Procedure' function
*************************************************************************/
LRESULT CALLBACK Win32AppHelper::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
    case WM_CHAR:
        s_samplesFramework->injectChar((CEGUI::utf32)wParam);
        break;

    case WM_MOUSELEAVE:
        mouseLeaves();
        break;

    case WM_NCMOUSEMOVE:
        mouseLeaves();
        break;

    case WM_MOUSEMOVE:
        mouseEnters();

        s_samplesFramework->injectMousePosition((float)(LOWORD(lParam)), (float)(HIWORD(lParam)));
        break;

    case WM_LBUTTONDOWN:
        s_samplesFramework->injectMouseButtonDown(CEGUI::LeftButton);
        break;

    case WM_LBUTTONUP:
        s_samplesFramework->injectMouseButtonUp(CEGUI::LeftButton);
        break;

    case WM_RBUTTONDOWN:
        s_samplesFramework->injectMouseButtonDown(CEGUI::RightButton);
        break;

    case WM_RBUTTONUP:
        s_samplesFramework->injectMouseButtonUp(CEGUI::RightButton);
        break;

    case WM_MBUTTONDOWN:
        s_samplesFramework->injectMouseButtonDown(CEGUI::MiddleButton);
        break;

    case WM_MBUTTONUP:
        s_samplesFramework->injectMouseButtonUp(CEGUI::MiddleButton);
        break;

    case 0x020A: // WM_MOUSEWHEEL:
        s_samplesFramework->injectMouseWheelChange(static_cast<float>((short)HIWORD(wParam)) / static_cast<float>(120));
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        break;

    case WM_SIZE:
        {
            // get CEGUI::System as a pointer so we can detect if it's not
            // instantiated yet.
            CEGUI::System* cegui_system = CEGUI::System::getSingletonPtr();

            // only continue if CEGUI is up an running and window was not
            // minimised (else it's just a waste of time)
            if ((cegui_system != 0) && (wParam != SIZE_MINIMIZED))
            {
                // get renderer identification string
                CEGUI::Renderer* renderer = cegui_system->getRenderer();
                CEGUI::String id(renderer->getIdentifierString());

                // invoke correct function based on the renderer we have ID'd
#ifdef CEGUI_SAMPLES_USE_DIRECT3D9
                if (id.find("Official Direct3D 9") != id.npos)
                    DeviceReset_Direct3D9(hWnd, renderer);
#endif
#ifdef CEGUI_SAMPLES_USE_DIRECT3D10
                if (id.find("Official Direct3D 10") != id.npos)
                    DeviceReset_Direct3D10(hWnd, renderer);
#endif
#ifdef CEGUI_SAMPLES_USE_DIRECT3D11
                if (id.find("Official Direct3D 11") != id.npos)
                    DeviceReset_Direct3D11(hWnd, renderer);
#endif
#ifdef CEGUI_SAMPLES_USE_DIRECT3D8
                if (id.find("Official Direct3D 8.1") != id.npos)
                    DeviceReset_Direct3D81(hWnd, renderer);
#endif
            }
        }
        break;

    case WM_PAINT:
        {
            HDC         hDC;
            PAINTSTRUCT ps;

            hDC = BeginPaint(hWnd, &ps);
            EndPaint(hWnd, &ps);
            break;
        }

    default:
        return(DefWindowProc(hWnd, message, wParam, lParam));
        break;
    }

    return 0;
}