Exemple #1
0
// Move the camera
bool GLC_TsrMover::move(const GLC_UserInput& userInput)
{
    const GLC_Vector3d VectCur(m_pViewport->mapPosMouse(static_cast<double>(userInput.x()), static_cast<double>(userInput.y())));
    const GLC_Vector3d VectPan= VectCur - m_PreviousVector;	// moving Vector

    GLC_Camera* pCamera= m_pViewport->cameraHandle();

    // Pan the camera
    pCamera->pan(-VectPan);

    // Zoom
    //m_pViewport->reframeFromDeltaCover(userInput.scaleFactor());
    zoom(userInput.scaleFactor());

    // Rotation
    if (!qFuzzyCompare(userInput.rotationAngle(), 0.0))
    {
        GLC_Point3d unProjectedPoint= userInput.unprojectedPoint();

        pCamera->rotateAround(pCamera->forward(), userInput.rotationAngle(), unProjectedPoint);
    }

    m_PreviousVector= VectCur;
    return true;
}
bool GLC_TurnTableMover::move(const GLC_UserInput& userInput)
{
	GLC_Camera* pCamera= GLC_Mover::m_pViewport->cameraHandle();
	// Turn table rotation
	const double rotSpeed= 2.3;
	const double width= static_cast<double> ( GLC_Mover::m_pViewport->viewVSize() );
	const double height= static_cast<double> ( GLC_Mover::m_pViewport->viewHSize() );

	const double alpha = -((static_cast<double>(userInput.x()) - GLC_Mover::m_PreviousVector.x()) / width) * rotSpeed;
	const double beta = ((static_cast<double>(userInput.y()) - GLC_Mover::m_PreviousVector.y()) / height) * rotSpeed;

	// Rotation around the screen vertical axis
	pCamera->rotateAroundTarget(pCamera->defaultUpVector(), alpha * m_Sign);

	// Rotation around the screen horizontal axis
	GLC_Vector3d incidentVector= -pCamera->forward();
	GLC_Vector3d rightVector= incidentVector ^ pCamera->upVector();
	if (!rightVector.isNull())
	{
		pCamera->rotateAroundTarget(rightVector, beta);
	}

	m_PreviousVector.setVect(static_cast<double>(userInput.x()), static_cast<double>(userInput.y()), 0.0);

	return true;
}
// Initialized the mover
void GLC_TurnTableMover::init(const GLC_UserInput& userInput)
{
	GLC_Mover::m_PreviousVector.setVect(static_cast<double>(userInput.x()), static_cast<double>(userInput.y()),0.0);
	GLC_Camera* pCamera= GLC_Mover::m_pViewport->cameraHandle();
	// Calculate angle sign
	m_Sign= pCamera->defaultUpVector() * pCamera->upVector();
	if (m_Sign == 0)
	{
		m_Sign= 1;
	}
	else
	{
		m_Sign= m_Sign / fabs(m_Sign);
	}

	pCamera->setUpCam(pCamera->defaultUpVector() * m_Sign);
}
// Initialized the mover
void GLC_SetTargetMover::init(const GLC_UserInput& userInput)
{
	// Z Buffer component of selected point between 0 and 1
	GLfloat Depth;
	// read selected point
	glReadPixels(userInput.x(), m_pViewport->viewVSize() - userInput.y() , 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &Depth);

	// Test if there is geometry under picking point
	if (!qFuzzyCompare(Depth, 1.0f))
	{	// Geometry find -> Update camera's target position
		const GLC_Point3d target(m_pViewport->unProject(userInput.x(), userInput.y()));
		m_pViewport->cameraHandle()->setTargetCam(target);
	}
	else
	{	// Geometry not find -> panning

		const GLC_Point3d curPos(m_pViewport->mapPosMouse(userInput.x(), userInput.y()));
		const GLC_Point3d prevPos(m_pViewport->mapPosMouse(m_pViewport->viewHSize() / 2, m_pViewport->viewVSize() / 2));
		const GLC_Vector3d VectPan(curPos - prevPos);	// panning vector
		// pan camera
		m_pViewport->cameraHandle()->pan(VectPan);
	}
}
Exemple #5
0
// Move the camera
bool GLC_TsrMover::move(const GLC_UserInput& userInput)
{
	if (!(userInput.normalyzeXTouchCenter() < 0.0) && !(userInput.normalyzeYTouchCenter() < 0.0))
	{
		m_PreviousVector= GLC_Point3d(userInput.normalyzeXTouchCenter(), userInput.normalyzeYTouchCenter(), 0.0);
	}
	else
	{
		qDebug() << "Pas cool";
		if (!userInput.translation().isNull())
		{
			m_PreviousVector= GLC_Vector3d(userInput.translation().getX(), userInput.translation().getY(), 0.0) + m_PreviousVector;			
		}
	}
	
	const double x= m_PreviousVector.x();
	const double y= m_PreviousVector.y();
	//GLC_Point3d center2= m_pViewport->unProject(x * m_pViewport->viewHSize(), y * m_pViewport->viewVSize());
	
	//qDebug() << "touch center= " << x << " , " << y;

	
	if (!qFuzzyCompare(userInput.scaleFactor(), 0))
	{
		GLC_Point dummy(m_pViewport->cameraHandle()->target());
		m_pViewport->setDistMinAndMax(dummy.boundingBox());

		GLC_Point2d nPos= m_pViewport->mapNormalyzeToOpenGLScreen(x, y);
		GLC_Point3d nPos3D(nPos.getX(), nPos.getY(), 1.0);
		GLC_Point3d projected= m_pViewport->compositionMatrix().inverted() * nPos3D;

		m_pViewport->cameraHandle()->zoom(userInput.scaleFactor());

		m_pViewport->setDistMinAndMax(dummy.boundingBox());
		GLC_Point3d projected2= m_pViewport->compositionMatrix().inverted() * nPos3D;
		GLC_Vector3d delta= projected - projected2;
		m_pViewport->cameraHandle()->translate(delta);
	}

	if (!qFuzzyCompare(userInput.rotationAngle(), 0))
	{
		GLC_Point dummy(m_pViewport->cameraHandle()->target());
		m_pViewport->setDistMinAndMax(dummy.boundingBox());

		GLC_Point2d nPos= m_pViewport->mapNormalyzeToOpenGLScreen(x, y);
		GLC_Point3d nPos3D(nPos.getX(), nPos.getY(), 1.0);
		GLC_Point3d center= m_pViewport->compositionMatrix().inverted() * nPos3D;

		GLC_Vector3d axis= m_pViewport->cameraHandle()->forward();

		m_pViewport->cameraHandle()->rotateAround(axis, userInput.rotationAngle(), center);
	}

	if (!userInput.translation().isNull())
	{
		double transX= userInput.translation().getX() * m_pViewport->viewHSize();
		double transY= userInput.translation().getY() * m_pViewport->viewVSize();

		GLC_Vector3d mappedTranslation(-transX, -transY, 0.0);
		// Compute the length of camera's field of view
		const double ChampsVision = m_pViewport->cameraHandle()->distEyeTarget() *  m_pViewport->viewTangent();

		// the side of camera's square is mapped on Vertical length of window
		// Ratio OpenGL/Pixel = dimend GL / dimens Pixel
		const double Ratio= ChampsVision / static_cast<double>(m_pViewport->viewVSize());

		mappedTranslation= mappedTranslation * Ratio;
		m_pViewport->cameraHandle()->pan(mappedTranslation);
	}

	return true;
}
Exemple #6
0
// Initialized the mover
void GLC_TsrMover::init(const GLC_UserInput& userInput)
{
	m_PreviousVector= GLC_Point3d(userInput.normalyzeXTouchCenter(), userInput.normalyzeYTouchCenter(), 0.0);
}
Exemple #7
0
// Initialized the mover
void GLC_TsrMover::init(const GLC_UserInput& userInput)
{
    m_PreviousVector= m_pViewport->mapPosMouse(static_cast<double>(userInput.x()), static_cast<double>(userInput.y()));
}