Ejemplo n.º 1
0
// Agrega una translacion 3D
void EntityTransform::addTranslation(Vector3d position)
{
	//auxMatrix.setIdentity();

	transformMatrix(1,4) = -position.x;
	transformMatrix(2,4) = position.y;
	transformMatrix(3,4) = position.z;

	//transformMatrix = transformMatrix * auxMatrix;
}
Ejemplo n.º 2
0
///////////////////////////////////////////////////////////////////////////////
//
// return sum of squares of errors, where 
//
// e^2 = (M'^{-1T}RTM^{-1} - F).(M'^{-1T}RTM^{-1} - F)
//
// where the dot product means element-wise multiplication and summing.
//
///////////////////////////////////////////////////////////////////////////////
double RTSolver::operator()(VecDoub_I &p) {
   transformMatrix T(cross_prod,p[0],p[1],p[2]);	// translation matrix
   double e2;
   int i,j;

   R = transformMatrix(xrotate,p[3]) *
     transformMatrix(yrotate,p[4]) *
     transformMatrix(zrotate,p[5]);
   T = NPT*R*T*N - F;
   e2 = elemental_dot_prod(T,T);
   return(e2);
}
    void operator()(ResourceDatabase* db)
    {
      if (stripfy())
        setRemoveDoubles(true);

      std::vector< vl::ref<vl::Geometry> > geom;
      db->get<Geometry>(geom);
      for(unsigned int i=0; i<geom.size(); ++i)
      {
        if (discardOriginalNormals())
          geom[i]->setNormalArray(NULL);

        if (computeNormals() && !geom[i]->normalArray())
          geom[i]->computeNormals();

        if (removeDoubles())
          DoubleVertexRemover().removeDoubles(geom[i].get());

        if (sortVertices())
          geom[i]->sortVertices();

        if (stripfy())
          TriangleStripGenerator().stripfy(geom[i].get(), 22, true, false, true);

        if (convertToDrawArrays())
          geom[i]->convertDrawCallToDrawArrays();

        geom[i]->setDisplayListEnabled(useDisplayLists());
        geom[i]->setVBOEnabled(useVBOs());

        if (transformGeometry())
          geom[i]->transform(transformMatrix(),true);
      }
    }
Ejemplo n.º 4
0
void KGameSvgDocument::setTransformMatrix(QMatrix& matrix, const MatrixOptions& options)
{
    QString transformBuffer, tmp;
    QMatrix null = QMatrix();

    if (options == ApplyToCurrentMatrix)
    {
        matrix = transformMatrix() * matrix;
    }

    transformBuffer = QLatin1String( "matrix(" );
    transformBuffer += tmp.setNum(matrix.m11(),'g',7) + QLatin1Char( ',' );
    transformBuffer += tmp.setNum(matrix.m12(),'g',7) + QLatin1Char( ',' );
    transformBuffer += tmp.setNum(matrix.m21(),'g',7) + QLatin1Char( ',' );
    transformBuffer += tmp.setNum(matrix.m22(),'g',7) + QLatin1Char( ',' );
    transformBuffer += tmp.setNum(matrix.dx(),'g',7) + QLatin1Char( ',' );
    transformBuffer += tmp.setNum(matrix.dy(),'g',7) + QLatin1Char( ')' );

    if ((transform() == QLatin1String( "Element has no transform attribute." )) && (matrix == null))
    {
        // Do not write a meaningless matrix to DOM
    }
    else
    {
        setTransform(transformBuffer);
    }
}
Ejemplo n.º 5
0
// Copied with minor modifications from qtdeclarative/src/quick/items/qquickwindow.cpp
QMouseEvent *TouchDispatcher::touchToMouseEvent(
        QEvent::Type type, const QTouchEvent::TouchPoint &p,
        ulong timestamp, Qt::KeyboardModifiers modifiers,
        bool transformNeeded)
{
    QQuickItem *item = m_targetItem.data();

    // The touch point local position and velocity are not yet transformed.
    QMouseEvent *me = new QMouseEvent(type, transformNeeded ? item->mapFromScene(p.scenePos()) : p.pos(),
                                      p.scenePos(), p.screenPos(), Qt::LeftButton,
                                      (type == QEvent::MouseButtonRelease ? Qt::NoButton : Qt::LeftButton),
                                      modifiers);
    me->setAccepted(true);
    me->setTimestamp(timestamp);
    QVector2D transformedVelocity = p.velocity();
    if (transformNeeded) {
        QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
        QMatrix4x4 transformMatrix(itemPrivate->windowToItemTransform());
        transformedVelocity = transformMatrix.mapVector(p.velocity()).toVector2D();
    }

    // Add these later if needed:
    //QGuiApplicationPrivate::setMouseEventCapsAndVelocity(me, event->device()->capabilities(), transformedVelocity);
    //QGuiApplicationPrivate::setMouseEventSource(me, Qt::MouseEventSynthesizedByQt);
    return me;
}
Ejemplo n.º 6
0
TEST_P(CompositorWorkerTest, applyingMutationsMultipleElements) {
  registerMockedHttpURLLoad("compositor-proxy-basic.html");
  navigateTo(m_baseURL + "compositor-proxy-basic.html");

  Document* document = frame()->document();

  {
    forceFullCompositingUpdate();

    Element* proxiedElement = document->getElementById("proxied-transform");
    WebLayer* proxiedLayer = webLayerFromElement(proxiedElement);
    EXPECT_TRUE(proxiedLayer->compositorMutableProperties() &
                CompositorMutableProperty::kTransform);
    EXPECT_FALSE(proxiedLayer->compositorMutableProperties() &
                 (CompositorMutableProperty::kScrollLeft |
                  CompositorMutableProperty::kScrollTop |
                  CompositorMutableProperty::kOpacity));
    EXPECT_TRUE(proxiedLayer->elementId());

    TransformationMatrix transformMatrix(11, 12, 13, 14, 21, 22, 23, 24, 31, 32,
                                         33, 34, 41, 42, 43, 44);
    CompositorMutation mutation;
    mutation.setTransform(TransformationMatrix::toSkMatrix44(transformMatrix));

    proxiedElement->updateFromCompositorMutation(mutation);

    forceFullCompositingUpdate();
    const String& cssValue =
        document->domWindow()
            ->getComputedStyle(proxiedElement, String())
            ->getPropertyValueInternal(CSSPropertyTransform);
    EXPECT_EQ(
        "matrix3d(11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, "
        "44)",
        cssValue);
  }
  {
    Element* proxiedElement = document->getElementById("proxied-opacity");
    WebLayer* proxiedLayer = webLayerFromElement(proxiedElement);
    EXPECT_TRUE(proxiedLayer->compositorMutableProperties() &
                CompositorMutableProperty::kOpacity);
    EXPECT_FALSE(proxiedLayer->compositorMutableProperties() &
                 (CompositorMutableProperty::kScrollLeft |
                  CompositorMutableProperty::kScrollTop |
                  CompositorMutableProperty::kTransform));
    EXPECT_TRUE(proxiedLayer->elementId());

    CompositorMutation mutation;
    mutation.setOpacity(0.5);

    proxiedElement->updateFromCompositorMutation(mutation);

    forceFullCompositingUpdate();
    const String& cssValue = document->domWindow()
                                 ->getComputedStyle(proxiedElement, String())
                                 ->getPropertyValueInternal(CSSPropertyOpacity);
    EXPECT_EQ("0.5", cssValue);
  }
}
Ejemplo n.º 7
0
void EntityTransform::addRotationY( float angle )
{
	//10% de mejora de rendimiento
	if(angle == 0)
	{
		return;
	}

	angle *= Math::DEGTORAD; // Radianes

	float cosAngle = Math::cos(angle);
	float sinAngle = Math::sin(angle);
	transformMatrix(1,1) = cosAngle;
	transformMatrix(3,1) = sinAngle * -1;
	transformMatrix(1,3) = sinAngle;
	transformMatrix(3,3) = cosAngle;
}
Ejemplo n.º 8
0
void Projection::render() {
    QMatrix4x4 matrix = transformMatrix()
            * scaleMatrix(m_scene->width(), -m_scene->height(), 1)
            * shiftMatrix(0, m_scene->height(), 0);

    m_scene->clear();
    renderFigure(matrix);
}
Ejemplo n.º 9
0
void Projection::render(QGraphicsScene *scene) {
    QMatrix4x4 matrix = transformMatrix()
            * scaleMatrix(scene->width(), -scene->height(), 1)
            * shiftMatrix(0, scene->height(), 0);

    scene->clear();

    renderSegments(scene, unitCube(), matrix);
    renderSegments(scene, axes(), matrix);
}
Ejemplo n.º 10
0
// NB: From QQuickWindow
void TouchDispatcher::transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints, const QTransform &transform)
{
    QMatrix4x4 transformMatrix(transform);
    for (int i=0; i<touchPoints.count(); i++) {
        QTouchEvent::TouchPoint &touchPoint = touchPoints[i];
        touchPoint.setRect(transform.mapRect(touchPoint.sceneRect()));
        touchPoint.setStartPos(transform.map(touchPoint.startScenePos()));
        touchPoint.setLastPos(transform.map(touchPoint.lastScenePos()));
        touchPoint.setVelocity(transformMatrix.mapVector(touchPoint.velocity()).toVector2D());
    }
}
Ejemplo n.º 11
0
void SceneGraph::LeafMeshNode::draw(const glm::mat4x4 &modelViewMatrix, const glm::mat4x4 &projectionMatrix)
{
    glm::mat4x4 localModelView = transformMatrix() * modelViewMatrix;
    glm::mat4x4 localProjection = projectionMatrix;
    glm::mat4x4 normalMatrix = glm::transpose(glm::inverse(localModelView));
    glm::mat4x4 MVP = localProjection * modelViewMatrix;
    for (unsigned int i = 0; i < mNumMeshes; ++i) {
        mRenderStates[i]->bind(localModelView, localProjection, MVP, normalMatrix);
        mMeshes[i]->draw();
        mRenderStates[i]->unbind();
    }
}
Ejemplo n.º 12
0
///////////////////////////////////////////////////////////////////////////////
//
// Constructor/solver
// f  = the fundamental matrix between two views
// m  = the intrinsic matrix of the reference camera
// mp = the intrinsic matrix of the second camera (M')
// 
// on construction, 'this' is set to be equal to the camera matrix of
// the second view.
//
// If F is exact, we have that 
// F = M'^{-1}RTM^{-1}
// so, if we let r be the residual matrix:
// r = M'^{-1}RTM^{-1} - F
// where
// M'^{-1T} 	= transpose of the inverse intrinsic matrix of the 2nd camera
// R		= rotation matrix (from reference to second view)
// T		= translation cross-product matrix (TQ = t x Q)
// M^{-1}	= inverse intrinsic matrix of the reference camera
// F		= the fundamental matrix
//
// then R and T are the unknowns with 6 degrees of freedom.
// These are calculated by minimising the sum of the squres of the elements
// of r. The camera matrix pair is then given by
//
// P = M[I|0] and P'=M'R[I|-t]
//
// So P' is the camera matrix we require.
//
///////////////////////////////////////////////////////////////////////////////
RTSolver::RTSolver(Matrix<double> &f,
		   Matrix<double> &m,
		   Matrix<double> &mp) : 
  transformMatrix(camera),
  N(inverse_intrinsic, m[0][0], m[1][1], m[0][2], m[1][2]),
  NPT(inverse_intrinsic, mp[0][0], mp[1][1], mp[0][2], mp[1][2])
 {
   transformMatrix	I(identity);
   Frprmn<RTSolver>	mySolver(*this, 1e-8);	// solver
   VecDoub 		p(6); 			// parameters for solver
   coord		t(3);			// translation vector

   F = f;
   NPT.transpose();

   // --- initial guess
   // -----------------
   p[0] = 1.2;
   p[1] = 0.0;
   p[2] = 0.0;
   p[3] = 0.0;
   p[4] = 0.0;
   p[5] = 0.0;

   // --- solve
   // ---------
   p = mySolver.minimize(p);

   // --- extract solution
   // --------------------
   t[0] = -p[0];
   t[1] = -p[1];
   t[2] = -p[2];
   R = transformMatrix(xrotate,p[3]) *
     transformMatrix(yrotate,p[4]) *
     transformMatrix(zrotate,p[5]);

   P() = mp*R*(I|t);
}
Ejemplo n.º 13
0
void KGameSvgDocument::shear(double xRadians, double yRadians, const MatrixOptions& options)
{
    QMatrix matrix;

    if (options == ApplyToCurrentMatrix)
    {
        matrix = transformMatrix().QMatrix::shear(xRadians, yRadians);
    }
    else
    {
        matrix = QMatrix();
        matrix.QMatrix::shear(xRadians, yRadians);
    }
    setTransformMatrix(matrix, ReplaceCurrentMatrix);
}
Ejemplo n.º 14
0
void KGameSvgDocument::translate(int xPixels, int yPixels, const MatrixOptions& options)
{
    QMatrix matrix;

    if (options == ApplyToCurrentMatrix)
    {
        matrix = transformMatrix().QMatrix::translate(xPixels, yPixels);
    }
    else
    {
        matrix = QMatrix();
        matrix.QMatrix::translate(xPixels, yPixels);
    }
    setTransformMatrix(matrix, ReplaceCurrentMatrix);
}
Ejemplo n.º 15
0
void KGameSvgDocument::rotate(double degrees, const MatrixOptions& options)
{
    QMatrix matrix;

    if (options == ApplyToCurrentMatrix)
    {
        matrix = transformMatrix().QMatrix::rotate(degrees);
    }
    else
    {
        matrix = QMatrix();
        matrix.QMatrix::rotate(degrees);
    }
    setTransformMatrix(matrix, ReplaceCurrentMatrix);
}
Ejemplo n.º 16
0
void EntityTransform::addOpenGLMatrix()
{
	// Convierte la matriz a formato GLfLoat
	GLfloat matrix[16];
	int num_celda = 0;
	for(int i = 1; i <= 4; i++)
	{
		for(int j = 1; j <= 4; j++)
		{
			matrix[num_celda] = transformMatrix(j,i);
			num_celda++;
		}
	}

	//glMultTransposeMatrixf(matrix); // casca :(
	glMultMatrixf(matrix);
}
Ejemplo n.º 17
0
//------------------------------------------------------------------------------------
// Creates and initializes the main window for application
//------------------------------------------------------------------------------------
Window::Window(QWidget *parent):QDialog(parent)
{
    //We create an instance of GLWidget component we built in glwidget.h
	m_glWidget = new GLWidget;
	
	//Setup application interface. Creates all the required components and sliders.
	setupUi(this);

    //We need to attach our m_glWidget to glWidgetArea
    //All our drawings will be on glWidgetArea
    glWidgetArea->setWidget(m_glWidget);

    stack_size = 0;


    //Setting up all the SIGNALS and SLOTS
    doubleSpinBox->setRange(-1000,1000);
    doubleSpinBox_2->setRange(-1000,1000);
    doubleSpinBox_3->setRange(-1000,1000);
    doubleSpinBox_4->setRange(-1000,1000);
    doubleSpinBox_5->setRange(-1000,1000);
    doubleSpinBox_6->setRange(-1000,1000);
    doubleSpinBox_7->setRange(-1000,1000);
    doubleSpinBox_8->setRange(-1000,1000);
    doubleSpinBox_9->setRange(-1000,1000);


    connect(clearButton, SIGNAL(clicked()), m_glWidget, SLOT(ClearInput()));
    connect(doubleSpinBox, SIGNAL(valueChanged(double)), m_glWidget, SLOT(setM11(double)));
    connect(doubleSpinBox_2, SIGNAL(valueChanged(double)), m_glWidget, SLOT(setM12(double)));
    connect(doubleSpinBox_3, SIGNAL(valueChanged(double)), m_glWidget, SLOT(setM13(double)));
    connect(doubleSpinBox_4, SIGNAL(valueChanged(double)), m_glWidget, SLOT(setM21(double)));
    connect(doubleSpinBox_5, SIGNAL(valueChanged(double)), m_glWidget, SLOT(setM22(double)));
    connect(doubleSpinBox_6, SIGNAL(valueChanged(double)), m_glWidget, SLOT(setM23(double)));
    connect(doubleSpinBox_7, SIGNAL(valueChanged(double)), m_glWidget, SLOT(setM31(double)));
    connect(doubleSpinBox_8, SIGNAL(valueChanged(double)), m_glWidget, SLOT(setM32(double)));
    connect(doubleSpinBox_9, SIGNAL(valueChanged(double)), m_glWidget, SLOT(setM33(double)));
    connect(btnTransform,SIGNAL(clicked()), m_glWidget, SLOT(transformMatrix()));
    connect(store, SIGNAL(clicked()), this, SLOT(on_store()));
    connect(push, SIGNAL(clicked()), this, SLOT(on_push()));
    connect(pop, SIGNAL(clicked()), this, SLOT(on_pop()));
    connect(apply, SIGNAL(clicked()), this, SLOT(on_stack()));

}
Ejemplo n.º 18
0
void KGameSvgDocument::scale(double xFactor, double yFactor, const MatrixOptions& options)
{
    QMatrix matrix;
    if ((xFactor == 0) || (yFactor == 0))
    {
        kWarning () << "KGameSvgDocument::scale: You cannnot scale by zero";
    }

    if (options == ApplyToCurrentMatrix)
    {
        matrix = transformMatrix().QMatrix::scale(xFactor, yFactor);
    }
    else
    {
        matrix = QMatrix();
        matrix.QMatrix::scale(xFactor, yFactor);
    }
    setTransformMatrix(matrix, ReplaceCurrentMatrix);
}
Ejemplo n.º 19
0
TEST_P(CompositorWorkerTest, applyingMutationsMultipleProperties) {
  registerMockedHttpURLLoad("compositor-proxy-basic.html");
  navigateTo(m_baseURL + "compositor-proxy-basic.html");

  Document* document = frame()->document();

  forceFullCompositingUpdate();

  Element* proxiedElement =
      document->getElementById("proxied-transform-and-opacity");
  WebLayer* proxiedLayer = webLayerFromElement(proxiedElement);
  EXPECT_TRUE(proxiedLayer->compositorMutableProperties() &
              CompositorMutableProperty::kTransform);
  EXPECT_TRUE(proxiedLayer->compositorMutableProperties() &
              CompositorMutableProperty::kOpacity);
  EXPECT_FALSE(proxiedLayer->compositorMutableProperties() &
               (CompositorMutableProperty::kScrollLeft |
                CompositorMutableProperty::kScrollTop));
  EXPECT_TRUE(proxiedLayer->elementId());

  TransformationMatrix transformMatrix(11, 12, 13, 14, 21, 22, 23, 24, 31, 32,
                                       33, 34, 41, 42, 43, 44);
  std::unique_ptr<CompositorMutation> mutation =
      wrapUnique(new CompositorMutation);
  mutation->setTransform(TransformationMatrix::toSkMatrix44(transformMatrix));
  mutation->setOpacity(0.5);

  proxiedElement->updateFromCompositorMutation(*mutation);
  {
    const String& transformValue =
        document->domWindow()
            ->getComputedStyle(proxiedElement, String())
            ->getPropertyValueInternal(CSSPropertyTransform);
    EXPECT_EQ(
        "matrix3d(11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, "
        "44)",
        transformValue);

    const String& opacityValue =
        document->domWindow()
            ->getComputedStyle(proxiedElement, String())
            ->getPropertyValueInternal(CSSPropertyOpacity);
    EXPECT_EQ("0.5", opacityValue);
  }

  // Verify that updating one property does not impact others
  mutation = wrapUnique(new CompositorMutation);
  mutation->setOpacity(0.8);

  proxiedElement->updateFromCompositorMutation(*mutation);
  {
    const String& transformValue =
        document->domWindow()
            ->getComputedStyle(proxiedElement, String())
            ->getPropertyValueInternal(CSSPropertyTransform);
    EXPECT_EQ(
        "matrix3d(11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, "
        "44)",
        transformValue);

    const String& opacityValue =
        document->domWindow()
            ->getComputedStyle(proxiedElement, String())
            ->getPropertyValueInternal(CSSPropertyOpacity);
    EXPECT_EQ("0.8", opacityValue);
  }
}
Ejemplo n.º 20
0
///////////////////////////////////////////////////////////////////////////////
//
// calculate rate of change of error with parameters, de2/dp, at p and
// put result in 'deriv'.
//
// Uses the identity d(sum_n(y_n^2))/dx = sum_n(2y_n * dy_n/dx)
//
// and the identities d(sin(t))/dt = sin(t + PI/2) and 
// d(cos(t))/dt = cos(t + PI/2)
//
///////////////////////////////////////////////////////////////////////////////
void RTSolver::df(VecDoub_I &p, VecDoub_O &deriv) {
   transformMatrix T(cross_prod,p[0],p[1],p[2]);	// translation matrix
   transformMatrix e;
   transformMatrix NPT_R;
   transformMatrix T_N;
   transformMatrix de_dp;

   R = 	
     transformMatrix(xrotate,p[3]) *
     transformMatrix(yrotate,p[4]) *
     transformMatrix(zrotate,p[5]);
   NPT_R = NPT*R;
   T_N   = T*N;
   e = NPT_R*T_N - F;

   de_dp = 0.0; de_dp[1][2] = -1.0; de_dp[2][1] = 1.0;
   deriv[0] = 2.0*elemental_dot_prod(e, NPT_R*de_dp*N);

   de_dp = 0.0; de_dp[0][2] = 1.0; de_dp[2][0] = -1.0;
   deriv[1] = 2.0*elemental_dot_prod(e, NPT_R*de_dp*N);

   de_dp = 0.0; de_dp[0][1] = -1.0; de_dp[1][0] = 1.0;
   deriv[2] = 2.0*elemental_dot_prod(e, NPT_R*de_dp*N);

   de_dp = 
     transformMatrix(xrotate,p[3] + PI/2) * 
     transformMatrix(yrotate,p[4]) *
     transformMatrix(zrotate,p[5]);
   deriv[3] = 2.0*elemental_dot_prod(e, NPT*de_dp*T_N);

   de_dp = 
     transformMatrix(xrotate,p[3]) * 
     transformMatrix(yrotate,p[4] + PI/2) *
     transformMatrix(zrotate,p[5]);
   deriv[4] = 2.0*elemental_dot_prod(e, NPT*de_dp*T_N);

   de_dp = 
     transformMatrix(xrotate,p[3]) * 
     transformMatrix(yrotate,p[4]) *
     transformMatrix(zrotate,p[5] + PI/2);
   deriv[5] = 2.0*elemental_dot_prod(e, NPT*de_dp*T_N);
}