Beispiel #1
0
void MainView2D::createFixtureItem(quint32 fxID, quint16 headIndex, quint16 linkedIndex,
                                   QVector3D pos, bool mmCoords)
{
    if (isEnabled() == false)
        return;

    if (m_gridItem == NULL)
       initialize2DProperties();

    qDebug() << "[MainView2D] Creating fixture with ID" << fxID << headIndex << linkedIndex << "pos:" << pos;

    Fixture *fixture = m_doc->fixture(fxID);
    if (fixture == NULL)
        return;

    quint32 itemID = FixtureUtils::fixtureItemID(fxID, headIndex, linkedIndex);
    QLCFixtureMode *fxMode = fixture->fixtureMode();
    QQuickItem *newFixtureItem = qobject_cast<QQuickItem*>(fixtureComponent->create());
    quint32 itemFlags = m_monProps->fixtureFlags(fxID, headIndex, linkedIndex);

    newFixtureItem->setParentItem(m_gridItem);
    newFixtureItem->setProperty("itemID", itemID);

    if (itemFlags & MonitorProperties::HiddenFlag)
        newFixtureItem->setProperty("visible", false);

    if (fxMode != NULL && fixture->type() != QLCFixtureDef::Dimmer)
    {
        QLCPhysical phy = fxMode->physical();

        //qDebug() << "Current mode fixture heads:" << fxMode->heads().count();
        newFixtureItem->setProperty("headsNumber", fxMode->heads().count());

        if (fixture->channelNumber(QLCChannel::Pan, QLCChannel::MSB) != QLCChannel::invalid())
        {
            int panDeg = phy.focusPanMax();
            if (panDeg == 0) panDeg = 360;
            newFixtureItem->setProperty("panMaxDegrees", panDeg);
        }
        if (fixture->channelNumber(QLCChannel::Tilt, QLCChannel::MSB) != QLCChannel::invalid())
        {
            int tiltDeg = phy.focusTiltMax();
            if (tiltDeg == 0) tiltDeg = 270;
            newFixtureItem->setProperty("tiltMaxDegrees", tiltDeg);
        }
    }

    QPointF itemPos;
    QSizeF size = FixtureUtils::item2DDimension(fixture->type() == QLCFixtureDef::Dimmer ? NULL : fxMode,
                                                m_monProps->pointOfView());

    if (mmCoords == false && (pos.x() != 0 || pos.y() != 0))
    {
        float gridUnits = m_monProps->gridUnits() == MonitorProperties::Meters ? 1000.0 : 304.8;
        itemPos.setX((pos.x() * gridUnits) / m_cellPixels);
        itemPos.setY((pos.y() * gridUnits) / m_cellPixels);
    }

    if (m_monProps->containsItem(fxID, headIndex, linkedIndex))
    {
        itemPos = FixtureUtils::item2DPosition(m_monProps, m_monProps->pointOfView(), pos);
        newFixtureItem->setProperty("rotation",
                                    FixtureUtils::item2DRotation(m_monProps->pointOfView(),
                                                                 m_monProps->fixtureRotation(fxID, headIndex, linkedIndex)));
    }
    else
    {
        itemPos = FixtureUtils::available2DPosition(m_doc, m_monProps->pointOfView(),
                                                    QRectF(itemPos.x(), itemPos.y(), size.width(), size.height()));
        // add the new fixture to the Doc monitor properties
        QVector3D newPos = FixtureUtils::item3DPosition(m_monProps, itemPos, 1000.0);
        m_monProps->setFixturePosition(fxID, headIndex, linkedIndex, newPos);
        m_monProps->setFixtureFlags(fxID, headIndex, linkedIndex, 0);
        Tardis::instance()->enqueueAction(Tardis::FixtureSetPosition, itemID, QVariant(QVector3D(0, 0, 0)), QVariant(newPos));
    }

    newFixtureItem->setProperty("mmXPos", itemPos.x());
    newFixtureItem->setProperty("mmYPos", itemPos.y());
    newFixtureItem->setProperty("mmWidth", size.width());
    newFixtureItem->setProperty("mmHeight", size.height());
    newFixtureItem->setProperty("fixtureName", fixture->name());

    // and finally add the new item to the items map
    m_itemsMap[itemID] = newFixtureItem;

    QByteArray values;
    updateFixture(fixture, values);
}
Beispiel #2
0
Vertex::Vertex()
{
    m_pos    = QVector3D(0.0f, 0.0f, 0.0f);
    m_tex    = QVector2D(0.0f, 0.0f);
    m_normal = QVector3D(0.0f, 0.0f, 0.0f);    
}
MaterialPreview::MaterialPreview(QWidget *parent) :
    QGLWidget(parent)
{

    sphere_ = new Sphere("Preview Sphere", 0, 5, Primitive::float3(1, 1, 0), 1, 50, 50);
    camera_ = new Camera(0, Camera::PERSPECTIVE, false, QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), 45.0f));
    camera_->zoom(7);
}
Beispiel #4
0
QVector2D EnvPortal::GetChildLocal(const QVector3D & p) const
{
    QVector3D local = QVector3D(p.x() - child_pos.x(), 0.0, p.z() - child_pos.z());
    return QVector2D(QVector3D::dotProduct(local, child_t), QVector3D::dotProduct(local, child_n));
}
	/// Returns the vector pointing along the positive local Y axis
	const QVector3D up() const { return mRotation.rotatedVector(QVector3D(0,1,0)); }
Beispiel #6
0
RVector RVector::rotate3d(const QQuaternion& quaternion) {
    QVector3D qv = quaternion.rotatedVector(QVector3D(x, y, z));
    *this = RVector(qv.x(), qv.y(), qv.z());
    return *this;
}
Beispiel #7
0
void EnvPortal::SetChildDir(const QVector3D & d)
{
    child_t = MathUtil::GetRotatedAxis(MathUtil::_PI_OVER_2, d, QVector3D(0, 1, 0));
    child_n = d;
    child_b = QVector3D(0, 1, 0);
}
Beispiel #8
0
/*!
    Returns the 3D form of this 2D vector, with the z coordinate set to zero.

    \sa toVector4D(), toPoint()
*/
QVector3D QVector2D::toVector3D() const
{
    return QVector3D(xp, yp, 0.0f, 1);
}
Beispiel #9
0
//------------------------------------------------------------------------------
QGLBuilder&  operator << ( QGLBuilder& builder, const QGLEllipsoid& ellipsoid )
{
   // Determine the number of slices and stacks to generate.
   static int const numberOfSlicesForSubdivisionDepth[] = { 8, 8, 16, 16, 32, 32, 64, 64, 128, 128 };
   static int const numberOfStacksForSubdivisionDepth[] = { 4, 8,  8, 16, 16, 32, 32, 64,  64, 128 };
   const unsigned int numberOfSlices = numberOfSlicesForSubdivisionDepth[ ellipsoid.GetSubdivisionDepth() - 1 ];
   const unsigned int numberOfStacks = numberOfStacksForSubdivisionDepth[ ellipsoid.GetSubdivisionDepth() - 1 ];

   // Precompute sin/cos values for the slices.
   const unsigned int maxSlices = 128 + 1;
   const unsigned int maxStacks = 128 + 1;
   qreal sliceSin[ maxSlices ];
   qreal sliceCos[ maxSlices ];
   for( unsigned int slice = 0;  slice < numberOfSlices;  ++slice )
   {
       const qreal angle = 2 * M_PI * (numberOfSlices - 1 - slice) / numberOfSlices;
       sliceSin[slice] = qFastSin(angle);
       sliceCos[slice] = qFastCos(angle);
   }
   // Join first and last slice.
   sliceSin[numberOfSlices] = sliceSin[0];
   sliceCos[numberOfSlices] = sliceCos[0];


   // Precompute sin/cos values for the stacks.
   qreal stackSin[ maxStacks ];
   qreal stackCos[ maxStacks ];
   for( unsigned int stack = 0;  stack <= numberOfStacks;  ++stack )
   {
       // Efficiently handle end-points which also ensure geometry comes to a point at the poles (no round-off).
       if(      stack == 0 )               { stackSin[stack] = 0.0f;  stackCos[stack] =  1.0f; }
       else if( stack == numberOfStacks )  { stackSin[stack] = 0.0f;  stackCos[stack] = -1.0f; }
       else
       {
          const qreal angle = M_PI * stack / numberOfStacks;
          stackSin[stack] = qFastSin(angle);
          stackCos[stack] = qFastCos(angle);
       }
   }

   // Half the dimensions of the ellipsoid for calculations below (centroid of ellipsoid is 0, 0, 0.)
   const qreal xRadius = 0.5 * ellipsoid.GetXDiameter();
   const qreal yRadius = 0.5 * ellipsoid.GetYDiameter();
   const qreal zRadius = 0.5 * ellipsoid.GetZDiameter();
   const qreal oneOverXRadiusSquared = 1.0 / (xRadius * xRadius);
   const qreal oneOverYRadiusSquared = 1.0 / (yRadius * yRadius);
   const qreal oneOverZRadiusSquared = 1.0 / (zRadius * zRadius);


   // Create the stacks.
   for( unsigned int stack = 0;  stack < numberOfStacks;  ++stack )
   {
      QGeometryData quadStrip;
      for( unsigned int slice = 0;  slice <= numberOfSlices; ++slice )
      {
          // Equation for ellipsoid surface is x^2/xRadius^2 + y^2/yRadius^2 + z^2/zRadius^2 = 1
          // Location of vertices can be specified in terms of "polar coordinates".
          const qreal nextx = xRadius * stackSin[stack+1] * sliceSin[slice];
          const qreal nexty = yRadius * stackSin[stack+1] * sliceCos[slice];
          const qreal nextz = zRadius * stackCos[stack+1];
          quadStrip.appendVertex( QVector3D( nextx, nexty, nextz) );

          // Equation for ellipsoid surface is  Surface = x^2/xRadius^2 + y^2/yRadius^2 + z^2/zRadius^2 - 1
          // Gradient for ellipsoid is  x/xRadius^2*Nx>  +  y/yRadius^2*Ny>  +  z/zRadius^2*Nz>
          // Gradient for sphere simplifies to  x*Nx> + y*Ny> + z*Nz>
          // const qreal nextGradientx =  stackSin[stack+1] * sliceSin[slice];
          // const qreal nextGradienty =  stackSin[stack+1] * sliceCos[slice];
          // const qreal nextGradientz =  stackCos[stack+1];
          const qreal nextGradientx = nextx * oneOverXRadiusSquared;
          const qreal nextGradienty = nexty * oneOverYRadiusSquared;
          const qreal nextGradientz = nextz * oneOverZRadiusSquared;
          const qreal nextGradientMagSquared = nextGradientx * nextGradientx + nextGradienty * nextGradienty + nextGradientz * nextGradientz;
          const qreal oneOverNextGradientMagnitude = 1.0 / sqrt( nextGradientMagSquared );
          quadStrip.appendNormal( oneOverNextGradientMagnitude * QVector3D( nextGradientx,  nextGradienty, nextGradientz ) );
          quadStrip.appendTexCoord( QVector2D(1.0f - qreal(slice) / numberOfSlices, 1.0f - qreal(stack + 1) / numberOfStacks) );

          const qreal x = xRadius * stackSin[stack] * sliceSin[slice];
          const qreal y = yRadius * stackSin[stack] * sliceCos[slice];
          const qreal z = zRadius * stackCos[stack];
          quadStrip.appendVertex( QVector3D( x, y, z) );

          // const qreal gradientx =  stackSin[stack] * sliceSin[slice];
          // const qreal gradienty =  stackSin[stack] * sliceCos[slice];
          // const qreal gradientz =  stackCos[stack];
          const qreal gradientx = x * oneOverXRadiusSquared;
          const qreal gradienty = y * oneOverYRadiusSquared;
          const qreal gradientz = z * oneOverZRadiusSquared;
          const qreal gradientMagSquared = gradientx * gradientx + gradienty * gradienty + gradientz * gradientz;
          const qreal oneOverGradientMagnitude = 1.0 / sqrt( gradientMagSquared );
          quadStrip.appendNormal( oneOverGradientMagnitude * QVector3D(  gradientx, gradienty, gradientz) );
          quadStrip.appendTexCoord( QVector2D(1.0f - qreal(slice) / numberOfSlices,  1.0f - qreal(stack) / numberOfStacks) );
      }

      // The quad strip stretches from pole to pole.
      builder.addQuadStrip( quadStrip );
   }


   return builder;
}
void Orientation_Widget::Init(void)
{
	Quad2d.clear();
	Quad2d.append( QPointF( 0.9192f,  0.8485f) );
	Quad2d.append( QPointF( 0.3000f,  0.2293f) );
	Quad2d.append( QPointF( 0.3000f, -0.2293f) );
	Quad2d.append( QPointF( 0.9192f, -0.8485f) );
	Quad2d.append( QPointF( 0.8485f, -0.9192f) );
	Quad2d.append( QPointF( 0.2293f, -0.3000f) );
	Quad2d.append( QPointF(-0.2293f, -0.3000f) );
	Quad2d.append( QPointF(-0.8485f, -0.9192f) );
	Quad2d.append( QPointF(-0.9192f, -0.8485f) );
	Quad2d.append( QPointF(-0.3000f, -0.2293f) );
	Quad2d.append( QPointF(-0.3000f,  0.2293f) );
	Quad2d.append( QPointF(-0.9192f,  0.8485f) );
	Quad2d.append( QPointF(-0.8485f,  0.9192f) );
	Quad2d.append( QPointF(-0.2293f,  0.3000f) );
	Quad2d.append( QPointF( 0.2293f,  0.3000f) );
	Quad2d.append( QPointF( 0.8485f,  0.9192f) );


	CenterX = CenterY = 0.0f;

	const int sourceLine[] = {		0,1, 1,2, 2,3, 3,4,
									4,5, 5,6, 6,7, 7,8,			// Top shell
									8,9, 9,10, 10,11, 11,12,
									12,13, 13,14, 14,15, 15,0,

									16,17, 17,18, 18,19, 19,20,
									20,21, 21,22, 22,23, 23,24,	// Bottom shell
									24,25, 25,26, 26,27, 27,28,
									28,29, 29,30, 30,31, 31,16,

									0,16, 1,17, 2,18, 3,19,
									4,20, 5,21, 6,22, 7,23,		// Connections between top & bottom
									8,24, 9,25, 10,26, 11,27,
									12,28, 13,29, 14,30, 15,31,

									2,5, 6,9, 10,13, 14,1,		// Connections on arms, top & bottom
									18,21, 22,25, 26,29, 30,17,

									32,33
							};

	QuadLine.clear();
	for( unsigned int i=0; i<sizeof(sourceLine)/sizeof(int); i++ ) {
		QuadLine.append( sourceLine[i] );
	}

	float cubeHeight = 0.8;
	float cubeWidth =  1.2;
	float cubeDepth =  1.2;

	QuadPt.resize(34);
	pt.resize(34);

	for(int i = 0; i < 16; i++) {
		QuadPt[i] =    QVector3D( Quad2d[i].x() * cubeWidth, -cubeHeight * 0.1f, Quad2d[i].y() * cubeDepth );
		QuadPt[i+16] = QVector3D( Quad2d[i].x() * cubeWidth, +cubeHeight * 0.1f, Quad2d[i].y() * cubeDepth );
	}

	QuadPt[32] = QVector3D( 0.0f, 0.0f, 0.3f * cubeDepth );
	QuadPt[33] = QVector3D( 0.0f, 0.0f, 0.5f * cubeDepth );

	bQuat2Valid = false;
}
Beispiel #11
0
Frame3D::Frame3D()
{
    connect(&view, SIGNAL(calibrate()), this, SLOT(calibrate()));
    calibratedX = 0;
    calibratedY = 0;
    calibratedZ = 0;

    engine.registerAspect(new Qt3DRender::QRenderAspect());
    input = new Qt3DInput::QInputAspect;
    engine.registerAspect(input);

    data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view)));
    data.insert(QStringLiteral("eventSource"), QVariant::fromValue(&view));
    engine.setData(data);

    // Root entity
    rootEntity = new Qt3DCore::QEntity();
    rootEntity->setObjectName(QStringLiteral("rootEntity"));
    // cube
    cubeEntity = new Qt3DCore::QEntity(rootEntity);

    // cube shape data
    cube = new Qt3DRender::QCuboidMesh();

    cubeEntity->addComponent(cube);

    // cubeMesh Transform
    cubeTransforms = new Qt3DCore::QTransform();
    cubeTransforms->setTranslation(QVector3D(0.0f, 0.0f, 0.0f));
    cubeTransforms->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1, 1, 1), 0.0f));
    cubeEntity->addComponent(cubeTransforms);

    // Camera
    cameraEntity = new Qt3DCore::QCamera(rootEntity);
    cameraEntity->setObjectName(QStringLiteral("cameraEntity"));
    cameraEntity->lens()->setPerspectiveProjection(60.0f, 16.0f/9.0f, 0.1f, 1000.0f);
    cameraEntity->setPosition(QVector3D(0, 2, 2.0f));
    cameraEntity->setViewCenter(cubeTransforms->translation());
    cameraEntity->setUpVector(QVector3D(0, 1, 0));
    input->setCamera(cameraEntity);

    // FrameGraph
    frameGraph = new Qt3DRender::QFrameGraph();
    techniqueFilter = new Qt3DRender::QTechniqueFilter();
    viewport = new Qt3DRender::QViewport(techniqueFilter);
    clearBuffer = new Qt3DRender::QClearBuffer(viewport);
    cameraSelector = new Qt3DRender::QCameraSelector(clearBuffer);
    (void) new Qt3DRender::QRenderPassFilter(cameraSelector);

    // TechiqueFilter and renderPassFilter are not implement yet
    viewport->setRect(QRectF(0, 0, 1, 1));
    clearBuffer->setBuffers(Qt3DRender::QClearBuffer::ColorDepthBuffer);
    cameraSelector->setCamera(cameraEntity);
    frameGraph->setActiveFrameGraph(techniqueFilter);

    // Setting the FrameGraph
    rootEntity->addComponent(frameGraph);

    // Set root object of the scene
    engine.setRootEntity(rootEntity);
    // Show window
    view.show();
}
void RenderState::draw_flat_box(QVector3D position1, QVector3D position2) {
      draw_line(QVector3D(position1.x(), position1.y(), position1.z()),
                QVector3D(position1.x(), position2.y(), position2.z()),
                this->view_matrix, QMatrix4x4(), QVector3D(1, 1, 1));
      draw_line(QVector3D(position1.x(), position1.y(), position1.z()),
                QVector3D(position2.x(), position1.y(), position2.z()),
                this->view_matrix, QMatrix4x4(), QVector3D(1, 1, 1));
      draw_line(QVector3D(position1.x(), position1.y(), position1.z()),
                QVector3D(position2.x(), position2.y(), position1.z()),
                this->view_matrix, QMatrix4x4(), QVector3D(1, 1, 1));

      draw_line(QVector3D(position2.x(), position1.y(), position1.z()),
                QVector3D(position2.x(), position2.y(), position2.z()),
                this->view_matrix, QMatrix4x4(), QVector3D(1, 1, 1));
      draw_line(QVector3D(position1.x(), position2.y(), position1.z()),
                QVector3D(position2.x(), position2.y(), position2.z()),
                this->view_matrix, QMatrix4x4(), QVector3D(1, 1, 1));
      draw_line(QVector3D(position1.x(), position1.y(), position2.z()),
                QVector3D(position2.x(), position2.y(), position2.z()),
                this->view_matrix, QMatrix4x4(), QVector3D(1, 1, 1));

}
void RenderState::paintGL() {
  this->view_matrix.setToIdentity();
  // whenever content is not loaded, load the content
  if ( !this->shader_program ) { this->load_content(); }
  // enable the scene's depth mask
  glDepthMask(GL_TRUE);
  // clear the depth z = 0.0f -> 1.0f
  glClearDepth(1.0f);
  // enable the scene's depth test
  glEnable(GL_DEPTH_TEST);
  // enable cullmode CCW (counter clockwise)
  glEnable(GL_CULL_FACE);
  // clear the background color for rendering
  glClearColor(104.0/255.0, 104.0/255.0, 104.0/255.0, 1);
  // clear the color and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // transform the camera's position with respect to the rotation matrix
  QVector3D cameraPosition = camera_transformation * QVector3D(0, 0, this->mouse_zoom);

  // define the direction of the camera's up vector
  QVector3D cameraUpDirection = camera_transformation * QVector3D(0, 1.0, 0);

  // implement and transform the camera
  this->view_matrix.lookAt(cameraPosition, QVector3D(), cameraUpDirection);
  this->view_matrix.translate(this->camera_previous);

  // return the position of the ray intersection with the y-axis
  QVector3D camara_zoom = QVector3D(- this->camera_previous.x(),
                                    - this->camera_previous.y(),
                                    - this->camera_previous.z());
  //this->view_matrix.rotate(this->prev_rotation_y, 1, 0, 0);
  //this->view_matrix.rotate(this->prev_rotation_x, 0, 1, 0);
  switch ( type_of_view ) {
   case 0 : camara_zoom.setY( camara_zoom.y() + this->mouse_zoom );
   break;
   case 1 : camara_zoom.setX( camara_zoom.x() - this->mouse_zoom );
   break;
   case 2 : camara_zoom.setZ( camara_zoom.z() + this->mouse_zoom );
   break;
   case 3 : this->view_matrix.rotate(-this->mouse_relative_y_drag, 1.0, 0, 0);
            this->view_matrix.rotate(-this->mouse_relative_x_drag, 0, 1.0, 0);
           // this->view_matrix.rotate(-45-this->mouse_y, 1, 0, 0);

   break;
  }
  QVector3D Pos  = this->intersect_plane(this->raycast_direction, camara_zoom);

  // update current position
  this->current_position->setX(Pos.x());
  this->current_position->setZ(Pos.z());
  this->current_position->setY(Pos.y());

  // draw select box
  if ( (this->mousedown_left) && (this->edit_vertex_enable) ) {
    draw_flat_box(*this->clicked_position, *this->current_position);
  }

  if ( (this->mousedown_left) && (this->translate_enable) ) {
    draw_line(*this->clicked_position,
              *this->current_position,
              this->view_matrix,
              QMatrix4x4(),
              QVector3D(1.0, 1.0, 1.0));
  }

  for (int a = 0; a < CurrentScene::mesh_count(); a++) {
    QMatrix4x4 translation;
    translation.translate(*CurrentScene::get_position(a));
    draw_model(CurrentScene::mesh_draw(a),
               this->view_matrix,
               translation,
               QMatrix4x4(),
               QVector3D(0.3, 0.0, 0.0));
    draw_model_vertices(CurrentScene::mesh_draw(a),
                        this->view_matrix,
                        translation,
                        QMatrix4x4(),
                        QVector3D(1.0, 0.0, 0.0), true);

    draw_model_vertices(CurrentScene::mesh_draw(a),
                        this->view_matrix,
                        translation,
                        QMatrix4x4(),
                        QVector3D(1.0, 1.0, 1.0), false);

  }
  draw_grid();
  if ( this->add_vertex_enable && ( this->type_of_view != 3 ) ) {
    QMatrix4x4 translation;
    translation.translate(Pos);
    draw_model(this->current_mesh,this->view_matrix,
               translation,
               QMatrix4x4(),
               QVector3D());
  }
  // release the program for this frame
  this->shader_program->release();
  // disable the cullmode for the frame
  glDisable(GL_CULL_FACE);
  // disable the depthtest for the frame
  glDisable(GL_DEPTH_TEST);
  // finish up the opengl frame
  glFinish();
}
void RenderState::draw_grid() {
  const int max_lines = 32;
  for ( int x = -max_lines; x < max_lines + 1; x++ ) {
      switch ( type_of_view ) {
        case 0 :
          // draw horisontal lines
          draw_line(QVector3D(x ,0 ,-max_lines),
                    QVector3D(x ,0 ,max_lines),
                    this->view_matrix, QMatrix4x4(),
                    QVector3D(1.0, 1.0, 1.0));
          // draw vertical lines
          draw_line(QVector3D(-max_lines ,0 ,x),
                    QVector3D(max_lines ,0 ,x),
                    this->view_matrix, QMatrix4x4(),
                    QVector3D(1.0, 1.0 ,1.0));
        break;
        case 1 :
          // draw horisontal lines
          draw_line(QVector3D(0, x, -max_lines),
                    QVector3D(0, x, max_lines),
                    this->view_matrix, QMatrix4x4(),
                    QVector3D(1.0, 1.0, 1.0));
          // draw vertical lines
          draw_line(QVector3D(0, -max_lines, x),
                    QVector3D(0, max_lines, x),
                    this->view_matrix, QMatrix4x4(),
                    QVector3D(1.0, 1.0 ,1.0));
        break;
        case 2 :
          // draw horisontal lines
          draw_line(QVector3D(x, -max_lines, 0),
                    QVector3D(x, max_lines, 0),
                    this->view_matrix, QMatrix4x4(),
                    QVector3D(1.0, 1.0, 1.0));
          // draw vertical lines
          draw_line(QVector3D(-max_lines, x, 0),
                    QVector3D(max_lines, x, 0),
                    this->view_matrix, QMatrix4x4(),
                    QVector3D(1.0, 1.0 ,1.0));
        break;
      case 3 :
        // draw horisontal lines
        draw_line(QVector3D(x ,0 ,-max_lines),
                  QVector3D(x ,0 ,max_lines),
                  this->view_matrix, QMatrix4x4(),
                  QVector3D(1.0, 1.0, 1.0));
        // draw vertical lines
        draw_line(QVector3D(-max_lines ,0 ,x),
                  QVector3D(max_lines ,0 ,x),
                  this->view_matrix, QMatrix4x4(),
                  QVector3D(1.0, 1.0 ,1.0));
      break;
    }
  }
}
void GLWidget::rotateCamera(float angle) {
	QQuaternion rot = QQuaternion(cos(angle/2.0), sin(angle/2.0) * QVector3D(0.0, 1.0, 0.0));
	camera->rotate(rot);

}
Beispiel #16
0
void DirectionNode::downWorld(qreal distance) {
    position += QVector3D(0, -distance, 0);
    update();
}
Beispiel #17
0
QVector3D DarkMatter::outDirection(const HitRecord &, Sample, float &pdf, cv::Vec3f &brdf) const
{
    brdf = cv::Vec3f();
    pdf = 0;
    return QVector3D();
}
Beispiel #18
0
void DirectionNode::forwardWorld(qreal distance) {
    position += QVector3D(0, 0, distance);
    update();
}
Beispiel #19
0
void QPaintedSphere3D::createVertices(int rings, int slices)
{
    _indexes.clear();
    _vertices.clear();
    const float dTheta = (M_PI * 2) / static_cast<float>(slices);
    const float dPhi   = M_PI / static_cast<float>(rings);
    const float du     = 1.0f / static_cast<float>(slices);
    const float dv     = 1.0f / static_cast<float>(rings);
    for(int lat = 0; lat < rings + 1; ++lat)
    {
        const float phi = M_PI_2 - static_cast<float>(lat) * dPhi;
        const float cosPhi = qCos(phi);
        const float sinPhi = qSin(phi);
        const float v = 1.0f - static_cast<float>(lat) * dv;

        for(int lon = 0; lon < slices + 1; ++lon)
        {
            const float theta = static_cast<float>(lon) * dTheta;
            const float cosTheta = qCos(theta);
            const float sinTheta = qSin(theta);
            const float u = static_cast<float>(lon) * du;
#if 0
            float vx = _d->radius() * cosTheta * cosPhi;
            float vy = _d->radius() * sinPhi;
            float vz = _d->radius() * sinTheta * cosPhi;
#else

            float vx = cosTheta * cosPhi;
            float vy = sinPhi;
            float vz = sinTheta * cosPhi;
#endif
#if 0
            float vtu = u; //texture coord
            float vtv = v;
            float vnx = cosTheta * cosPhi; //normals
            float vny = sinPhi;
            float vnz = sinTheta * cosPhi;

            float tn1 = sinTheta; //tangents
            float tn2 = 0.0f;
            float tn3 = -cosTheta;
            float tn4 = 1.0f;
#endif
            _vertices << QVector3D(vx, vy, vz);
        }
    }
    const int faces   = (slices << 1) * (rings - 1);
    const int indices = faces * 3;
    int nextRingStartIndex = slices + 1;
    for(int j = 0; j < slices; ++j)
    {
        _indexes << nextRingStartIndex + j;
        _indexes << 0;
        _indexes << nextRingStartIndex + j + 1;
    }
    for(int i = 1; i < (rings - 1); ++i)
    {
        const int ringStartIndex = i * (slices + 1);
        const int nextRingStartIndex = (i + 1) * (slices + 1);
        for(int j = 0; j < slices; ++j)
        {
            _indexes << ringStartIndex + j;
            _indexes << ringStartIndex + j + 1;
            _indexes << nextRingStartIndex + j;
            _indexes << nextRingStartIndex + j;
            _indexes << ringStartIndex + j + 1;
            _indexes << nextRingStartIndex + j + 1;
        }
    }
    const int ringStartIndex = (rings - 1) * (slices + 1);
    nextRingStartIndex = rings * (slices + 1);
    for ( int j = 0; j < slices; ++j )
    {
        _indexes << ringStartIndex + j + 1;
        _indexes << nextRingStartIndex;
        _indexes << ringStartIndex + j;
    }
}
Beispiel #20
0
void DirectionNode::backWorld(qreal distance) {
    position += QVector3D(0, 0, -distance);
    update();
}
Beispiel #21
0
QVector2D EnvPortal::GetParentLocal(const QVector3D & p) const
{
    QVector3D local = QVector3D(p.x() - parent_pos.x(), 0.0, p.z() - parent_pos.z());
    return QVector2D(QVector3D::dotProduct(local, parent_t), QVector3D::dotProduct(local, parent_n));
}
Beispiel #22
0
// TODO(bmonkey): This shouldn't be needed.
QMatrix4x4 DirectionNode::getViewNoTranslation() {
    QMatrix4x4 viewMatrixNoTranslation;
    viewMatrixNoTranslation.lookAt(QVector3D(0, 0, 0), direction(), up);
    return viewMatrixNoTranslation;
}
Beispiel #23
0
	/// Returns the vector pointing along the positive local X axis
	const QVector3D left() const { return mRotation.rotatedVector(QVector3D(1,0,0)); }
Beispiel #24
0
void DirectionNode::rightWorld(qreal distance) {
    position += QVector3D(distance, 0, 0);
    update();
}
Beispiel #25
0
	/// Returns the vector pointing along the positive local Z axis
	const QVector3D direction() const { return mRotation.rotatedVector(QVector3D(0,0,1)); }
Beispiel #26
0
void GLWidget::InitCells()
{
    _cells.clear();
    _gridSpacing = 10;
    _gridSize = QSize(SystemParams::w , SystemParams::h);

    // add one row and one column
    _actualGridSize = QSize((_gridSize.width() - 1) * 2 + 1, (_gridSize.height() - 1) * 2 + 1 );

    _img_width  = (_actualGridSize.width() - 1) * _gridSpacing;
    _img_height = (_actualGridSize.height() - 1) * _gridSpacing;

    // add break lines
    _breakLines.clear();
    _breakLines.push_back(ALine(0, 0, _img_width, 0));
    _breakLines.push_back(ALine(0, 0, 0, _img_height));
    _breakLines.push_back(ALine(_img_width, 0, _img_width, _img_height));
    _breakLines.push_back(ALine(0, _img_height, _img_width, _img_height));
    PrepareLinesVBO(_breakLines, &_breakLinesVbo, &_breakLinesVao, QVector3D(0.0, 0.0, 0.0));


    for(int a = 0; a < _actualGridSize.width(); a++)
        { _cells.push_back(std::vector<CCell>(_actualGridSize.height())); }


    // ONE
    for(int a = 0; a < _actualGridSize.width(); a += 2)
    {
        for(int b = 0; b < _actualGridSize.height(); b += 2)
            { _cells[a][b]._cellSign = CellSign::SIGN_ONE; }
    }

    // TWO
    for(int a = 1; a < _actualGridSize.width(); a += 2)
    {
        for(int b = 1; b < _actualGridSize.height(); b += 2)
            { _cells[a][b]._cellSign = CellSign::SIGN_TWO; }
    }

    // vao
    _cellLines.clear();
    for(int a = 0; a < _actualGridSize.width() - 1; a++)
    {
        for(int b = 0; b < _actualGridSize.height() - 1; b++)
        {
            AVector upLeftPt(a * _gridSpacing, b * _gridSpacing);
            AVector upRightPt((a + 1) * _gridSpacing, b * _gridSpacing);
            AVector bottomLeftPt(a * _gridSpacing, (b + 1) * _gridSpacing);
            AVector bottomRightPt((a + 1) * _gridSpacing, (b + 1) * _gridSpacing);

            _cellLines.push_back(ALine(upLeftPt, upRightPt));
            _cellLines.push_back(ALine(upLeftPt, bottomLeftPt));

            if(a == _actualGridSize.width() - 2)
                { _cellLines.push_back(ALine(upRightPt, bottomRightPt)); }

            if(b == _actualGridSize.height() - 2)
                { _cellLines.push_back(ALine(bottomLeftPt, bottomRightPt)); }
        }
    }
    PrepareLinesVBO(_cellLines, &_cellLinesVbo, &_cellLinesVao, QVector3D(0.0, 0.0, 0.0));

    _shouldUpdateScrolls = true;
}
Beispiel #27
0
Vertex::Vertex(QVector3D pos, QVector2D tex)
{
    m_pos    = pos;
    m_tex    = tex;
    m_normal = QVector3D(0.0f, 0.0f, 0.0f);    
}
Beispiel #28
0
void GLWidget::InitDots()
{
    if(_dotsVao.isCreated()) { _dotsVao.destroy(); }
    _dotsVao.create();
    _dotsVao.bind();

    float radius = 1.0f;

    QVector<VertexData> vertices;

    // ONE
    for(int a = 0; a < _actualGridSize.width(); a += 2)
    {
        for(int b = 0; b < _actualGridSize.height(); b += 2)
        {
            int xCenter = a * _gridSpacing;
            int yCenter = b * _gridSpacing;
            QVector3D vecCol = QVector3D(1, 0, 0);

            vertices.append(VertexData(QVector3D(xCenter, yCenter,  0.0f), QVector2D(), vecCol));
            float addValue = (M_PI * 2.0 / 4);
            for(float a = 0.0; a < M_PI * 2.0; a += addValue)
            {
                float xPt = xCenter + radius * sin(a);
                float yPt = yCenter + radius * cos(a);
                vertices.append(VertexData(QVector3D(xPt, yPt,  0.0f), QVector2D(), vecCol));
            }
            float xPt = xCenter + radius * sin(M_PI * 2.0);
            float yPt = yCenter + radius * cos(M_PI * 2.0);
            vertices.append(VertexData(QVector3D(xPt, yPt,  0.0f), QVector2D(), vecCol));

        }
    }

    // TWO
    for(int a = 1; a < _actualGridSize.width(); a += 2)
    {
        for(int b = 1; b < _actualGridSize.height(); b += 2)
        {
            int xCenter = a * _gridSpacing;
            int yCenter = b * _gridSpacing;
            QVector3D vecCol = QVector3D(0, 0, 1);

            vertices.append(VertexData(QVector3D(xCenter, yCenter,  0.0f), QVector2D(), vecCol));
            float addValue = (M_PI * 2.0 / 4);
            for(float a = 0.0; a < M_PI * 2.0; a += addValue)
            {
                float xPt = xCenter + radius * sin(a);
                float yPt = yCenter + radius * cos(a);
                vertices.append(VertexData(QVector3D(xPt, yPt,  0.0f), QVector2D(), vecCol));
            }
            float xPt = xCenter + radius * sin(M_PI * 2.0);
            float yPt = yCenter + radius * cos(M_PI * 2.0);
            vertices.append(VertexData(QVector3D(xPt, yPt,  0.0f), QVector2D(), vecCol));

        }
    }

    _dotsVbo.create();
    _dotsVbo.bind();
    _dotsVbo.allocate(vertices.data(), vertices.size() * sizeof(VertexData));

    // reuse the variable
    quintptr offset = 0;

    _shaderProgram->enableAttributeArray(_vertexLocation);
    _shaderProgram->setAttributeBuffer(_vertexLocation, GL_FLOAT, 0, 3, sizeof(VertexData));

    offset += sizeof(QVector3D);
    offset += sizeof(QVector2D);

    _shaderProgram->enableAttributeArray(_colorLocation);
    _shaderProgram->setAttributeBuffer(_colorLocation, GL_FLOAT, offset, 3, sizeof(VertexData));

    _dotsVao.release();
}
Beispiel #29
0
//check points
void KinematicPoints::SetCalculatedJointPoints()
{
    regionalPointCalculated = QVector3D(joint02Point.x() + l[3]*c[1]*c23, joint02Point.y()+l[3]*s[1]*c23, joint02Point.z()+l[3]*s23);
    transitionalPointCalculated = QVector3D(regionalPointCalculated.x() + l[4]*c[1]*c234, regionalPointCalculated.y() + l[4]*s[1]*c234, regionalPointCalculated.z()+l[4]*s234);
    toolPointCalculated = QVector3D(transitionalPointCalculated.x() + (l[5]+l[6])*ctheta*cpsi, transitionalPointCalculated.y() + (l[5]+l[6])*ctheta*spsi, transitionalPointCalculated.z()+(l[5]+l[6])*stheta);
}
Beispiel #30
0
void ModelShow::make()
{
    vertices.clear();
    normals.clear();
    Point c[4],n[4],t[4];
    bool m[4];
    int idx[4][2]={{0,0},{1,0},{0,1},{1,1}};

    int num = 0;
    for(int i=1;i<height-1;i++){
        for(int j=1;j<width-1;j++){
            for(int k=0;k<4;k++){
                int id=(i+idx[k][0])*width+(j+idx[k][1]);
                m[k]=image[id].mask;
            }
            if(m[0]&&m[1]&&m[2]){
                num++;
            }
            if(m[1]&&m[3]&&m[2]){
                num++;
            }
        }
    }
    std::cout<<num<<"\n"<<std::flush;
    vertices.reserve(num*3);
    normals.reserve(num*3);

    for(int i=1;i<height-1;i++){
        for(int j=1;j<width-1;j++){
            for(int k=0;k<4;k++){
                int id=(i+idx[k][0])*width+(j+idx[k][1]);
                c[k]=image[id].coor;
                n[k]=image[id].norm;
                t[k]=image[id].text;
                m[k]=image[id].mask;
            }
            if(m[0]&&m[1]&&m[2]){
                /*
                vertices.append(QVector3D(c[0][0],c[0][1],c[0][2]));
                normals.append(QVector3D(n[0][0],n[0][1],n[0][2]));
                vertices.append(QVector3D(c[1][0],c[1][1],c[1][2]));
                normals.append(QVector3D(n[1][0],n[1][1],n[1][2]));
                vertices.append(QVector3D(c[2][0],c[2][1],c[2][2]));
                normals.append(QVector3D(n[2][0],n[2][1],n[2][2]));
                */
                /*重构的世界坐标系--->OpenGL坐标系*/
                vertices.append(QVector3D(c[0][1],-c[0][0],c[0][2]));
                normals.append(QVector3D(n[0][1],-n[0][0],n[0][2]));
                vertices.append(QVector3D(c[1][1],-c[1][0],c[1][2]));
                normals.append(QVector3D(n[1][1],-n[1][0],n[1][2]));
                vertices.append(QVector3D(c[2][1],-c[2][0],c[2][2]));
                normals.append(QVector3D(n[2][1],-n[2][0],n[2][2]));
            }
            if(m[1]&&m[3]&&m[2]){
                /*
                vertices.append(QVector3D(c[1][0],c[1][1],c[1][2]));
                normals.append(QVector3D(n[1][0],n[1][1],n[1][2]));
                vertices.append(QVector3D(c[3][0],c[3][1],c[3][2]));
                normals.append(QVector3D(n[3][0],n[3][1],n[3][2]));
                vertices.append(QVector3D(c[2][0],c[2][1],c[2][2]));
                normals.append(QVector3D(n[2][0],n[2][1],n[2][2]));
                */
                vertices.append(QVector3D(c[1][1],-c[1][0],c[1][2]));
                normals.append(QVector3D(n[1][1],-n[1][0],n[1][2]));
                vertices.append(QVector3D(c[3][1],-c[3][0],c[3][2]));
                normals.append(QVector3D(n[3][1],-n[3][0],n[3][2]));
                vertices.append(QVector3D(c[2][1],-c[2][0],c[2][2]));
                normals.append(QVector3D(n[2][1],-n[2][0],n[2][2]));
            }
        }
    }
}