Пример #1
0
bool View::intersectRectangle(const float3 &a, const float2 &r) const
{
    // FIXME take angle into account
    float2 zPlaneSize = (0.5f * scale * sizePoints) - getAspect() * a.z;
    return intersectRectangleRectangle(float2(a.x, a.y), r, 
                                       position, zPlaneSize);
}
Пример #2
0
void RenderSystem::init_camera()
{
	//Viewport Infomation
	D3D11_VIEWPORT vp;
	ZeroMemory(&vp, sizeof(D3D11_VIEWPORT));
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;
	vp.Width    = static_cast<FLOAT>(m_ScreenWidth);
	vp.Height   = static_cast<FLOAT>(m_ScreenHeight);
	m_pD3D11DeviceContext->RSSetViewports(1, &vp);

	//MVP Matrix
	XMVECTOR camPos    = XMVectorSet(0.0f, 0.0f, -5.0f, 0.0f);
	XMVECTOR camTarget = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
	XMVECTOR camUp     = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
	XMMATRIX View      = XMMatrixLookAtLH(camPos, camTarget, camUp);
	XMMATRIX Proj      = XMMatrixPerspectiveFovLH(0.4f*3.14f, getAspect(), 1.0f, 1000.0f);
	XMMATRIX Model     = XMMatrixRotationY(60.0f);


	XMStoreFloat4x4(&m_Matrix.model, XMMatrixTranspose(Model) );
	XMStoreFloat4x4(&m_Matrix.view,  XMMatrixTranspose(View) );
	XMStoreFloat4x4(&m_Matrix.proj,  XMMatrixTranspose(Proj) );

}
Пример #3
0
	void RenderSystem::v_Render()
	{
		static const float bgColor[4] = {0.2f, 0.3f, 0.4f, 1.0f};
		glClearBufferfv(GL_COLOR, 0, bgColor);
		static const float one = 1.0f;
		glClearBufferfv(GL_DEPTH, 0, &one);

		update();

		static ogl::MvpMatrix matrix;
		matrix.view  = m_Camera.GetViewMatrix();
		matrix.proj  = glm::perspective(glm::radians(m_Camera.GetZoom() ), getAspect(), 0.1f, 1000.0f);
		matrix.model = glm::mat4(1.0f);

		// 1. Draw scene as normal in multisampled buffers
         
		m_Framebuffer.Bind();

		glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	    m_Cube.Render(matrix);

		// 2. Now blit multisampled buffer(s) to default framebuffers
		glBindFramebuffer(GL_READ_FRAMEBUFFER, m_Framebuffer.GetFbo());
		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);				
		glBlitFramebuffer(0, 0, GetScreenWidth(), GetScreenWidth(), 0, 0, GetScreenWidth(), GetScreenWidth(), GL_COLOR_BUFFER_BIT, GL_NEAREST);     
	}
Пример #4
0
/**************************************
Debug Function.
***************************************/
void Camera::debug(){
    system("clear");
    cout << " Eye:    " << getEyeX() << "  " << getEyeY() << "  " << getEyeZ() << endl;
    cout << " Center: " << getCenterX() << "  " << getCenterY() << "  " << getCenterZ() << endl;
    cout << " Up:     " << getUpX() << "  " << getUpY() << "  " << getUpZ() << endl;
    cout << endl;
    cout << " Perspective: " << getFovy() << "  " << getAspect() << "  " << getZNear() << "  " << getZFar() << endl;
}
Пример #5
0
F32 LLSnapshotLivePreview::getImageAspect()
{
	if (!getCurrentImage())
	{
		return 0.f;
	}

	return getAspect() ;	
}
Пример #6
0
void LLViewerCamera::updateCameraLocation(const LLVector3 &center,
											const LLVector3 &up_direction,
											const LLVector3 &point_of_interest)
{
	// do not update if avatar didn't move
	if (!LLViewerJoystick::getInstance()->getCameraNeedsUpdate())
	{
		return;
	}

	LLVector3 last_position;
	LLVector3 last_axis;
	last_position = getOrigin();
	last_axis = getAtAxis();

	mLastPointOfInterest = point_of_interest;

	// constrain to max distance from avatar
	LLVector3 camera_offset = center - gAgent.getPositionAgent();

	LLViewerRegion * regp = gAgent.getRegion();
	F32 water_height = (NULL != regp) ? regp->getWaterHeight() : 0.f;

	LLVector3 origin = center;
	if (origin.mV[2] > water_height)
	{
		origin.mV[2] = llmax(origin.mV[2], water_height+0.20f);
	}
	else
	{
		origin.mV[2] = llmin(origin.mV[2], water_height-0.20f);
	}

	setOriginAndLookAt(origin, up_direction, point_of_interest);

	mVelocityDir = center - last_position ; 
	F32 dpos = mVelocityDir.normVec() ;
	LLQuaternion rotation;
	rotation.shortestArc(last_axis, getAtAxis());

	F32 x, y, z;
	F32 drot;
	rotation.getAngleAxis(&drot, &x, &y, &z);

	mVelocityStat.addValue(dpos);
	mAngularVelocityStat.addValue(drot);
	
	mAverageSpeed = mVelocityStat.getMeanPerSec() ;
	mAverageAngularSpeed = mAngularVelocityStat.getMeanPerSec() ;
	mCosHalfCameraFOV = cosf(0.5f * getView() * llmax(1.0f, getAspect()));

	// update pixel meter ratio using default fov, not modified one
	mPixelMeterRatio = getViewHeightInPixels()/ (2.f*tanf(mCameraFOVDefault*0.5));
	// update screen pixel area
	mScreenPixelArea =(S32)((F32)getViewHeightInPixels() * ((F32)getViewHeightInPixels() * getAspect()));
}
Пример #7
0
void
QFCItem::setup(void)
{
    FieldContainer *pFCAsp = getFC().getAspectCPtr(getAspect());

    if(!pFCAsp)
        return;

    UInt32 uiNumFields = pFCAsp->getType().getNumFieldDescs();
    
    for(UInt32  fieldId = 1; fieldId <= uiNumFields; ++fieldId)
    {
        FieldDescription *pDesc     = 
            pFCAsp->getType().getFieldDescription     (fieldId);
        Field            *pField    = pFCAsp->getField(fieldId);
        
        if(isSFFieldContainerPtr(pField))
        {
            if(stringcmp(pDesc->getCName(), "parent" ) == 0)
                continue;

            SFFieldContainerPtr *pSFFCPtr = 
                reinterpret_cast<SFFieldContainerPtr *>(pField);

            if(pSFFCPtr->getValue() != NullFC)
            {
                setExpandable(this);
                break;
            }
        }
        else if(isMFFieldContainerPtr(pField))
        {
            MFFieldContainerPtr *pMFFCPtr =
                reinterpret_cast<MFFieldContainerPtr *>(pField);

            if(stringcmp(pDesc->getCName(), "parents") == 0)
            {
                if(pMFFCPtr->size() > 1)
                {
                    setExpandable(this);
                    break;
                }
            }
            else
            {
                if(pMFFCPtr->size() > 0)
                {
                    setExpandable(this);
                    break;
                }
            }
        }
    }

    Inherited::setup();
}
Пример #8
0
void
QFCItem::expand(void)
{
    if(childCount() != 0)
        return;

    FieldContainer *pFCAsp = getFC().getAspectCPtr(getAspect());

    if(!pFCAsp)
        return;

    FieldContainerType &fcType      = pFCAsp->getType();
    UInt32              uiNumFields = fcType.getNumFieldDescs();

    for(UInt32 fieldId = 1; fieldId <= uiNumFields; ++fieldId)
    {
        FieldDescription *pFieldDesc = fcType.getFieldDescription(fieldId);
        Field            *pField     = pFCAsp->getField          (fieldId);
        
        //add Items for all referenced containers (except parents)
        if(isSFFieldContainerPtr(pField))
        {
            if(stringcmp(pFieldDesc->getCName(), "parent" ) == 0)
                continue;

            addRefedContainer(
                reinterpret_cast<SFFieldContainerPtr *>(pField));
        }
        else if(isMFFieldContainerPtr(pField))
        {
            if(stringcmp(pFieldDesc->getCName(), "parents") == 0)
            {
                addParents(
                    reinterpret_cast<MFFieldContainerPtr *>(pField));
            }
            else
            {
                addRefedContainer(
                    reinterpret_cast<MFFieldContainerPtr *>(pField), 
                    pFieldDesc   );
            }
        }

        //add attachments
        if(stringcmp(pFieldDesc->getCName(), "attachments") == 0)
        {
            addAttachments(dynamic_cast<SFAttachmentMap *>(pField));
        }
    }

    PNOTICE << endLog;
}
Пример #9
0
void
QSFieldView::setAspect(UInt32 uiAspect)
{
    if(uiAspect == getAspect())
        return;

    endEdit();

    delete _pLabel;
    delete _pEditor;

    Inherited::setAspect(uiAspect);

    initSelf();
}
Пример #10
0
void LLViewerCamera::calcProjection(const F32 far_distance) const
{
	F32 fov_y, z_far, z_near, aspect, f;
	fov_y = getView();
	z_far = far_distance;
	z_near = getNear();
	aspect = getAspect();

	f = 1/tan(fov_y*0.5f);

	mProjectionMatrix.setZero();
	mProjectionMatrix.mMatrix[0][0] = f/aspect;
	mProjectionMatrix.mMatrix[1][1] = f;
	mProjectionMatrix.mMatrix[2][2] = (z_far + z_near)/(z_near - z_far);
	mProjectionMatrix.mMatrix[3][2] = (2*z_far*z_near)/(z_near - z_far);
	mProjectionMatrix.mMatrix[2][3] = -1;
}
Пример #11
0
void
QMFieldView::setAspect(UInt32 uiAspect)
{
    if(uiAspect == getAspect())
        return;

    endEdit();

    deleteAllLabels();
    delete _pEditor;

    Inherited::setAspect(uiAspect);

    initSelf     ();
    initScrollbar();

    _bContentsChanged = true;
}
Пример #12
0
    void v_Render()
    {
        float t = (float)glfwGetTime();
        static const float black[] = { 0.0f, 0.0f, 0.0f, 1.0f };
        static const float one = 1.0f;

        glUseProgram(flock_update_program);

        vmath::vec3 goal = vmath::vec3(sinf(t * 0.34f),
                                       cosf(t * 0.29f),
                                       sinf(t * 0.12f) * cosf(t * 0.5f));

        goal = goal * vmath::vec3(35.0f, 25.0f, 60.0f);

        glUniform3fv(uniforms.update.goal, 1, goal);

        glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, flock_buffer[frame_index]);
        glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, flock_buffer[frame_index ^ 1]);

        glDispatchCompute(NUM_WORKGROUPS, 1, 1);

        glViewport(0, 0, GetScreenWidth(), GetScreenHeight());
        glClearBufferfv(GL_COLOR, 0, black);
        glClearBufferfv(GL_DEPTH, 0, &one);

        glUseProgram(flock_render_program);

        vmath::mat4 mv_matrix = vmath::lookat(vmath::vec3(0.0f, 0.0f, -400.0f),
                                              vmath::vec3(0.0f, 0.0f, 0.0f),
                                              vmath::vec3(0.0f, 1.0f, 0.0f));
        vmath::mat4 proj_matrix = vmath::perspective(60.0f,
                                                     getAspect(),
                                                     0.1f,
                                                     3000.0f);
        vmath::mat4 mvp = proj_matrix * mv_matrix;

        glUniformMatrix4fv(uniforms.render.mvp, 1, GL_FALSE, mvp);

        glBindVertexArray(flock_render_vao[frame_index]);

        glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 8, FLOCK_SIZE);

        frame_index ^= 1;
    }
Пример #13
0
void Camera::sethFovy( const FovyValueType fovy)
{
	Camera::AspectValueType aspect;
	Camera::ZNearValueType zNear;
	Camera::ZFarValueType zFar;

	setFovy( fovy );

	if ( getAspect( aspect ) && getZNear( zNear ) && getZFar( zFar ) )
	{
		vgm::MatrixR matrix;
		matrix.setPerspective( fovy, aspect, zNear, zFar );
		setProjection( matrix );
	}
	else
	{
		vgAssertN( false, "sethFovy() called before zNear, zFar and aspect have been initialized.");
	}
}
Пример #14
0
void	Camera :: apply ()
{
	float		m [16];
													// create a coordinate space transform
													// (rotation) matrix
	m [0 ] = sideDir.x;
	m [1 ] = upDir.x;
	m [2 ] = -viewDir.x;
	m [3 ] = 0;

	m [4 ] = sideDir.y;
	m [5 ] = upDir.y;
	m [6 ] = -viewDir.y;
	m [7 ] = 0;

	m [8 ] = sideDir.z;
	m [9 ] = upDir.z;
	m [10] = -viewDir.z;
	m [11] = 0;

	m [12] = 0;
	m [13] = 0;
	m [14] = 0;
	m [15] = 1;

														// set current viewport
	glViewport     ( 0, 0, getWidth (), getHeight () );

	glMatrixMode   ( GL_PROJECTION );					// select projection matrix
	glLoadIdentity ();									// reset projection matrix

														// calculate aspect ratio of the window
	gluPerspective ( getFov (), getAspect (), getZNear (), getZFar () );

	glMatrixMode   ( GL_MODELVIEW );					// select modelview matrix
	glLoadIdentity ();									// reset modelview matrix

	glMultMatrixf ( m );
	glTranslatef  ( -pos.x, -pos.y, -pos.z );
	
	glGetFloatv ( GL_PROJECTION_MATRIX, proj );
}
Пример #15
0
/***************************************
****************************************
Others and the most importants functions
****************************************
****************************************/
void Camera::setPerspective(){
    glEnable(GL_DEPTH_TEST);
    glMatrixMode(GL_PROJECTION);
    gluPerspective(getFovy(),getAspect(),getZNear(),getZFar());
    glutSetCursor(GLUT_CURSOR_NONE);
}
Пример #16
0
bool
QNodeTreeView::getBranchRecursion(const FieldContainerPtr &pFromFC, 
                                        BranchType        &branch  )
{
    if(pFromFC == NullFC)
    {
        return false;
    }
    else if(pFromFC == getRoot())
    {
        return true;
    }
    else
    {
        branch.push_front(pFromFC);

        Field *pParentsField = getParentsField(pFromFC, getAspect());

        if(!pParentsField)
        {
            return false;
        }

        if(pParentsField->getCardinality() == FieldType::SINGLE_FIELD)
        {
            SFFieldContainerPtr *pSFParent =
                reinterpret_cast<SFFieldContainerPtr *>(pParentsField);
            
            if(getBranchRecursion(pSFParent->getValue(), branch))
            {
                return true;
            }
            else
            {
                branch.pop_front();

                return false;
            }
        }
        else
        {
            MFFieldContainerPtr *pMFParent =
                reinterpret_cast<MFFieldContainerPtr *>(pParentsField);
            
            MFFieldContainerPtr::iterator mfIter = pMFParent->begin();
            MFFieldContainerPtr::iterator mfEnd  = pMFParent->end();

            for(; mfIter != mfEnd; ++mfIter)
            {
                if(getBranchRecursion(*mfIter, branch))
                {
                    return true;
                }
                else
                {
                    branch.pop_front();
                }
            }
        }
    }

    return false;
}
Пример #17
0
void LLViewerCamera::setPerspective(BOOL for_selection,
									S32 x, S32 y_from_bot, S32 width, S32 height,
									BOOL limit_select_distance,
									F32 z_near, F32 z_far)
{
	F32 fov_y, aspect;
	fov_y = RAD_TO_DEG * getView();
	BOOL z_default_near, z_default_far = FALSE;
	if (z_far <= 0)
	{
		z_default_far = TRUE;
		z_far = getFar();
	}
	if (z_near <= 0)
	{
		z_default_near = TRUE;
		z_near = getNear();
	}
	aspect = getAspect();

	// Load camera view matrix
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();

	glh::matrix4f proj_mat;

	if (for_selection)
	{
		// make a tiny little viewport
		// anything drawn into this viewport will be "selected"

		GLint viewport[4];
		viewport[0] = gViewerWindow->getWorldViewRectRaw().mLeft;
		viewport[1] = gViewerWindow->getWorldViewRectRaw().mBottom;
		viewport[2] = gViewerWindow->getWorldViewRectRaw().getWidth();
		viewport[3] = gViewerWindow->getWorldViewRectRaw().getHeight();
		
		proj_mat = gl_pick_matrix(x+width/2.f, y_from_bot+height/2.f, (GLfloat) width, (GLfloat) height, viewport);

		if (limit_select_distance)
		{
			// ...select distance from control
			z_far = gSavedSettings.getF32("MaxSelectDistance");
		}
		else
		{
			z_far = gAgent.mDrawDistance;
		}
	}
	else
	{
		// Only override the far clip if it's not passed in explicitly.
		if (z_default_far)
		{
			z_far = MAX_FAR_CLIP;
		}
		glViewport(x, y_from_bot, width, height);
		gGLViewport[0] = x;
		gGLViewport[1] = y_from_bot;
		gGLViewport[2] = width;
		gGLViewport[3] = height;
	}
	
	if (mZoomFactor > 1.f)
	{
		float offset = mZoomFactor - 1.f;
		int pos_y = mZoomSubregion / llceil(mZoomFactor);
		int pos_x = mZoomSubregion - (pos_y*llceil(mZoomFactor));
		glh::matrix4f translate;
		translate.set_translate(glh::vec3f(offset - (F32)pos_x * 2.f, offset - (F32)pos_y * 2.f, 0.f));
		glh::matrix4f scale;
		scale.set_scale(glh::vec3f(mZoomFactor, mZoomFactor, 1.f));

		proj_mat = scale*proj_mat;
		proj_mat = translate*proj_mat;
	}

	calcProjection(z_far); // Update the projection matrix cache

	proj_mat *= gl_perspective(fov_y,aspect,z_near,z_far);

	glLoadMatrixf(proj_mat.m);

	for (U32 i = 0; i < 16; i++)
	{
		gGLProjection[i] = proj_mat.m[i];
	}

	glMatrixMode( GL_MODELVIEW );

	glh::matrix4f modelview((GLfloat*) OGL_TO_CFR_ROTATION);

	GLfloat			ogl_matrix[16];

	getOpenGLTransform(ogl_matrix);

	modelview *= glh::matrix4f(ogl_matrix);
	
	glLoadMatrixf(modelview.m);
	
	if (for_selection && (width > 1 || height > 1))
	{
		// NB: as of this writing, i believe the code below is broken (doesn't take into account the world view, assumes entire window)
		// however, it is also unused (the GL matricies are used for selection, (see LLCamera::sphereInFrustum())) and so i'm not
		// comfortable hacking on it.
		calculateFrustumPlanesFromWindow((F32)(x - width / 2) / (F32)gViewerWindow->getWindowWidthScaled() - 0.5f,
								(F32)(y_from_bot - height / 2) / (F32)gViewerWindow->getWindowHeightScaled() - 0.5f,
								(F32)(x + width / 2) / (F32)gViewerWindow->getWindowWidthScaled() - 0.5f,
								(F32)(y_from_bot + height / 2) / (F32)gViewerWindow->getWindowHeightScaled() - 0.5f);

	}

	// if not picking and not doing a snapshot, cache various GL matrices
	if (!for_selection && mZoomFactor == 1.f)
	{
		// Save GL matrices for access elsewhere in code, especially project_world_to_screen
		//glGetDoublev(GL_MODELVIEW_MATRIX, gGLModelView);
		for (U32 i = 0; i < 16; i++)
		{
			gGLModelView[i] = modelview.m[i];
		}
	}

	updateFrustumPlanes(*this);

	/*if (gSavedSettings.getBOOL("CameraOffset"))
	{
		glMatrixMode(GL_PROJECTION);
		glTranslatef(0,0,-50);
		glRotatef(20.0,1,0,0);
		glMatrixMode(GL_MODELVIEW);
	}*/
}
Пример #18
0
    SettingsWindow::SettingsWindow() :
        WindowBase("openmw_settings_window.layout"),
        mKeyboardMode(true)
    {
        configureWidgets(mMainWidget);

        setTitle("#{sOptions}");

        getWidget(mSettingsTab, "SettingsTab");
        getWidget(mOkButton, "OkButton");
        getWidget(mResolutionList, "ResolutionList");
        getWidget(mFullscreenButton, "FullscreenButton");
        getWidget(mWindowBorderButton, "WindowBorderButton");
        getWidget(mTextureFilteringButton, "TextureFilteringButton");
        getWidget(mAnisotropyBox, "AnisotropyBox");
        getWidget(mControlsBox, "ControlsBox");
        getWidget(mResetControlsButton, "ResetControlsButton");
        getWidget(mKeyboardSwitch, "KeyboardButton");
        getWidget(mControllerSwitch, "ControllerButton");
        getWidget(mWaterTextureSize, "WaterTextureSize");

#ifndef WIN32
        // hide gamma controls since it currently does not work under Linux
        MyGUI::ScrollBar *gammaSlider;
        getWidget(gammaSlider, "GammaSlider");
        gammaSlider->setVisible(false);
        MyGUI::TextBox *textBox;
        getWidget(textBox, "GammaText");
        textBox->setVisible(false);
        getWidget(textBox, "GammaTextDark");
        textBox->setVisible(false);
        getWidget(textBox, "GammaTextLight");
        textBox->setVisible(false);
#endif

        mMainWidget->castType<MyGUI::Window>()->eventWindowChangeCoord += MyGUI::newDelegate(this, &SettingsWindow::onWindowResize);

        mSettingsTab->eventTabChangeSelect += MyGUI::newDelegate(this, &SettingsWindow::onTabChanged);
        mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onOkButtonClicked);
        mTextureFilteringButton->eventComboChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onTextureFilteringChanged);
        mResolutionList->eventListChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onResolutionSelected);

        mWaterTextureSize->eventComboChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onWaterTextureSizeChanged);

        mKeyboardSwitch->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onKeyboardSwitchClicked);
        mControllerSwitch->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onControllerSwitchClicked);

        center();

        mResetControlsButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onResetDefaultBindings);

        // fill resolution list
        int screen = Settings::Manager::getInt("screen", "Video");
        int numDisplayModes = SDL_GetNumDisplayModes(screen);
        std::vector < std::pair<int, int> > resolutions;
        for (int i = 0; i < numDisplayModes; i++)
        {
            SDL_DisplayMode mode;
            SDL_GetDisplayMode(screen, i, &mode);
            resolutions.push_back(std::make_pair(mode.w, mode.h));
        }
        std::sort(resolutions.begin(), resolutions.end(), sortResolutions);
        for (std::vector < std::pair<int, int> >::const_iterator it=resolutions.begin();
             it!=resolutions.end(); ++it)
        {
            std::string str = MyGUI::utility::toString(it->first) + " x " + MyGUI::utility::toString(it->second)
                    + " (" + getAspect(it->first,it->second) + ")";

            if (mResolutionList->findItemIndexWith(str) == MyGUI::ITEM_NONE)
                mResolutionList->addItem(str);
        }
        highlightCurrentResolution();

        std::string tmip = Settings::Manager::getString("texture mipmap", "General");
        mTextureFilteringButton->setCaption(textureMipmappingToStr(tmip));

        int waterTextureSize = Settings::Manager::getInt ("rtt size", "Water");
        if (waterTextureSize >= 512)
            mWaterTextureSize->setIndexSelected(0);
        if (waterTextureSize >= 1024)
            mWaterTextureSize->setIndexSelected(1);
        if (waterTextureSize >= 2048)
            mWaterTextureSize->setIndexSelected(2);

        mWindowBorderButton->setEnabled(!Settings::Manager::getBool("fullscreen", "Video"));

        mKeyboardSwitch->setStateSelected(true);
        mControllerSwitch->setStateSelected(false);
    }
Пример #19
0
void LLViewerCamera::setPerspective(BOOL for_selection,
									S32 x, S32 y_from_bot, S32 width, S32 height,
									BOOL limit_select_distance,
									F32 z_near, F32 z_far)
{
	F32 fov_y, aspect;
	fov_y = RAD_TO_DEG * getView();
	BOOL z_default_far = FALSE;
	if (z_far <= 0)
	{
		z_default_far = TRUE;
		z_far = getFar();
	}
	if (z_near <= 0)
	{
		z_near = getNear();
	}
	aspect = getAspect();

	// Load camera view matrix
	gGL.matrixMode( LLRender::MM_PROJECTION );
	gGL.loadIdentity();

	LLMatrix4a proj_mat;
	proj_mat.setIdentity();

	if (for_selection)
	{
		// make a tiny little viewport
		// anything drawn into this viewport will be "selected"

		const LLRect& rect = gViewerWindow->getWorldViewRectRaw();
		
		const F32 scale_x = rect.getWidth() / F32(width);
		const F32 scale_y = rect.getHeight() / F32(height);
		const F32 trans_x = scale_x + (2.f * (rect.mLeft - x)) / F32(width) - 1.f;
		const F32 trans_y = scale_y + (2.f * (rect.mBottom - y_from_bot)) / F32(height) - 1.f;

		//Generate a pick matrix
		proj_mat.applyScale_affine(scale_x, scale_y, 1.f);
		proj_mat.setTranslate_affine(LLVector3(trans_x, trans_y, 0.f));

		if (limit_select_distance)
		{
			// ...select distance from control
//			z_far = gSavedSettings.getF32("MaxSelectDistance");
// [RLVa:KB] - Checked: 2010-04-11 (RLVa-1.2.0e) | Added: RLVa-1.2.0e
			z_far = (!gRlvHandler.hasBehaviour(RLV_BHVR_FARTOUCH)) ? gSavedSettings.getF32("MaxSelectDistance") : 1.5;
// [/RLVa:KB]
		}
		else
		{
			z_far = gAgentCamera.mDrawDistance;
		}
	}
	else
	{
		// Only override the far clip if it's not passed in explicitly.
		if (z_default_far)
		{
			z_far = MAX_FAR_CLIP;
		}
		glViewport(x, y_from_bot, width, height);
		gGLViewport[0] = x;
		gGLViewport[1] = y_from_bot;
		gGLViewport[2] = width;
		gGLViewport[3] = height;
	}
	
	if (mZoomFactor > 1.f)
	{
		float offset = mZoomFactor - 1.f;
		int pos_y = mZoomSubregion / llceil(mZoomFactor);
		int pos_x = mZoomSubregion - (pos_y*llceil(mZoomFactor));

		proj_mat.applyTranslation_affine(offset - (F32)pos_x * 2.f, offset - (F32)pos_y * 2.f, 0.f);
		proj_mat.applyScale_affine(mZoomFactor,mZoomFactor,1.f);
	}

	calcProjection(z_far); // Update the projection matrix cache

	proj_mat.mul(gGL.genPersp(fov_y,aspect,z_near,z_far));
	
	gGL.loadMatrix(proj_mat);
	
	gGLProjection = proj_mat;

	gGL.matrixMode(LLRender::MM_MODELVIEW );

	LLMatrix4a ogl_matrix;
	getOpenGLTransform(ogl_matrix.getF32ptr());

	LLMatrix4a modelview;
	modelview.setMul(OGL_TO_CFR_ROTATION, ogl_matrix);
	
	gGL.loadMatrix(modelview);
	
	if (for_selection && (width > 1 || height > 1))
	{
		// NB: as of this writing, i believe the code below is broken (doesn't take into account the world view, assumes entire window)
		// however, it is also unused (the GL matricies are used for selection, (see LLCamera::sphereInFrustum())) and so i'm not
		// comfortable hacking on it.
		calculateFrustumPlanesFromWindow((F32)(x - width / 2) / (F32)gViewerWindow->getWindowWidthScaled() - 0.5f,
								(F32)(y_from_bot - height / 2) / (F32)gViewerWindow->getWindowHeightScaled() - 0.5f,
								(F32)(x + width / 2) / (F32)gViewerWindow->getWindowWidthScaled() - 0.5f,
								(F32)(y_from_bot + height / 2) / (F32)gViewerWindow->getWindowHeightScaled() - 0.5f);

	}

	// if not picking and not doing a snapshot, cache various GL matrices
	if (!for_selection && mZoomFactor == 1.f)
	{
		// Save GL matrices for access elsewhere in code, especially project_world_to_screen
		//glGetDoublev(GL_MODELVIEW_MATRIX, gGLModelView);
		glh_set_current_modelview(modelview);
	}

	updateFrustumPlanes(*this);

	/*if (gSavedSettings.getBOOL("CameraOffset"))
	{
		gGL.matrixMode(LLRender::MM_PROJECTION);
		gGL.translatef(0,0,-50);
		gGL.rotatef(20.0,1,0,0);
		gGL.matrixMode(LLRender::MM_MODELVIEW);
	}*/
}
Пример #20
0
void LLViewerCamera::calcProjection(const F32 far_distance) const
{
	mProjectionMatrix = gGL.genPersp( getView()*RAD_TO_DEG, getAspect(), getNear(), far_distance );
}
Пример #21
0
void  RenderSystem::v_OnMouseWheel(WPARAM btnState, int x, int y)
{
	m_Camera.OnMouseWheel(btnState, x, y, getAspect());
}
Пример #22
0
void Frustum::generateFrustumPlanes( Camera* camera, Plane* frustum ) {
	// Generate planes
	float nearHeight = 2 * tan( getFOV() / 2 ) * getNear();
	float nearWidth  = nearHeight * getAspect();
	
	//float farHeight  = 2 * tan( getFOV() / 2 ) * getFar();
	//float farWidth = farHeight * getAspect();
		
	Vector3 fc, nc, tmp;
	
	Vector3 ynh, xnw, X, Y, Z;
	
	Z = Vector3( camera->getCenterOfProjection() );
	Z.sub( Z, camera->getLookAtPoint() );
	Z.normalize();
	
	X.cross( camera->getUp(), Z );
	X.normalize();
	
	Y.cross( Z, X );
	
	ynh = Vector3( Y );
	ynh.scale( nearHeight / 2 );
	
	xnw = Vector3( X );
	xnw.scale( nearWidth / 2 );
	
	tmp = Vector3( Z );
	tmp.scale( getNear() );
	nc = Vector3( camera->getCenterOfProjection() ); 
	nc.sub( nc, tmp );
			
	tmp = Vector3( Z );
	tmp.scale( getFar() );
	fc = Vector3( camera->getCenterOfProjection() );
	fc.sub( fc, tmp );
			
	Vector3 aux, normal;
	
	frustum[ NEAR ].setNormal( Z.getX(), Z.getY(), Z.getZ() );
	frustum[ NEAR ].setPoint( nc );
		
	frustum[ FAR  ].setNormal( -Z.getX(), -Z.getY(), -Z.getZ() );	
	frustum[ FAR  ].setPoint( fc );
	
	aux = Vector3( nc );
	aux.add( aux, ynh );
	frustum[ TOP  ].setPoint( aux );
	
	aux.sub( aux, camera->getCenterOfProjection() );
	aux.normalize();
	normal.cross( aux, X );
	frustum[ TOP  ].setNormal( normal.getX(), normal.getY(), normal.getZ() );
	
	aux = Vector3( nc );
	aux.sub( aux, ynh );
	frustum[ BOTTOM ].setPoint( aux );
	
	aux.sub( aux, camera->getCenterOfProjection() );
	aux.normalize();
	normal.cross( X, aux );
	frustum[ BOTTOM ].setNormal( normal.getX(), normal.getY(), normal.getZ() );
	
	aux = Vector3( nc );
	aux.sub( aux, xnw );
	frustum[ LEFT ].setPoint( aux );
	
	aux.sub( aux, camera->getCenterOfProjection() );
	aux.normalize();
	normal.cross( aux, Y );
	frustum[ LEFT ].setNormal( normal.getX(), normal.getY(), normal.getZ() );
	
	aux = Vector3( nc );
	aux.add( aux, xnw );
	frustum[ RIGHT ].setPoint( aux );
	
	aux.sub( aux, camera->getCenterOfProjection() );
	aux.normalize();
	normal.cross( Y, aux );
	frustum[ RIGHT ].setNormal( normal.getX(), normal.getY(), normal.getZ() );
}