Exemple #1
0
/*!
 * \brief GLWidget::mousePressEvent
 * Pobiera pozycję kursora na ekranie. Jeśli dodatkowo jest włączony tryb PointMode, dodaje
 * do okna dialogowa współrzędne wskazanego punktu.
 * \param event
 */
void GLWidget::mousePressEvent(QMouseEvent *event)
{
    point_ = event->pos();
    if (addPointMode) {
        QVector3D pos = getPos(point_.x(), point_.y());
        d_->addPoint(pos.x(), pos.y());
        addPointMode = false;
    }
}
void OgreLightNode::setPosition(QVector3D p)
{ 
	m_position.x = p.x(); 
	m_position.y = p.y(); 
	m_position.z = p.z();
	//m_node->resetOrientation();
	m_light->setPosition(m_position);// * (1 / m_zoom));
	updateRotation();	
}
void QSoundSourcePrivate::setPosition(const QVector3D& position)
{
    if (!m_alSource)
        return;
    alSource3f(m_alSource, AL_POSITION, position.x(), position.y(), position.z());
#ifdef DEBUG_AUDIOENGINE
    QAudioEnginePrivate::checkNoError("source set position");
#endif
}
PXCPoint3DF32 IRSHandlerBase::convertQtIRS(const QVector3D &qtVector)
{
    PXCPoint3DF32 irsVector;
    irsVector.x = qtVector.x();
    irsVector.y = qtVector.y();
    irsVector.z = qtVector.z();

    return irsVector;
}
Ogre::String toString(const QVector3D &v)
{
	Ogre::String s="<QVector3D ";
	s+="x="+Ogre::StringConverter::toString((float)v.x())+", ";
	s+="y="+Ogre::StringConverter::toString((float)v.y())+", ";
	s+="z="+Ogre::StringConverter::toString((float)v.z());
	s+=">";
	return s;
}
void QSoundSourcePrivate::setVelocity(const QVector3D& velocity)
{
    if (!m_alSource)
        return;
    alSource3f(m_alSource, AL_VELOCITY, velocity.x(), velocity.y(), velocity.z());
#ifdef DEBUG_AUDIOENGINE
    QAudioEnginePrivate::checkNoError("source set velocity");
#endif
}
void QSoundSourcePrivate::setDirection(const QVector3D& direction)
{
    if (!m_alSource)
        return;
    alSource3f(m_alSource, AL_DIRECTION, direction.x(), direction.y(), direction.z());
#ifdef DEBUG_AUDIOENGINE
    QAudioEnginePrivate::checkNoError("source set direction");
#endif
}
void SS3DWidget::camMoveCenter(const QVector3D& tt)
{
	QVector3D xv = QVector3D::crossProduct((m_cam_center - m_cam_eye), m_cam_up).normalized();
	QVector3D yv = QVector3D::crossProduct(xv, (m_cam_center - m_cam_eye)).normalized();
	QVector3D zv = (m_cam_center  - m_cam_eye).normalized();
	QVector3D trans = xv * tt.x() + yv * tt.y() + zv * tt.z();
	m_cam_eye += trans;
	m_cam_center += trans;
}
void SurfaceSet::paintROI(){
    glColor3f(0,0,0);
    glPointSize(15);
    glBegin(GL_POINTS);
    for (int i = 0; i < afnis.at(0)->nodes.length(); i++){
        QVector3D p = afnis.at(cs)->nodes.at(i);
        if (roi->contains(i)) glVertex3f(p.x(),p.y(),p.z());
    }
    glEnd();
}
Exemple #10
0
/* render particle system */
void Quiddiards::renderPS(){
	glDisable(GL_LIGHTING);
	for (vector<Particle>::iterator it = ps->getParticles().begin(); it != ps->getParticles().end(); it++){
		float alpha = 1 - it->age / it->life;	//calculate alpha according to particle age
		if (alpha <= 0){
			continue;
		}
		QVector3D pos = it->getCenter();
		QVector3D color = it->color;
		glColor4f(color.x(), color.y(), color.z(), alpha);
		//glColor3f(color.x(), color.y(), color.z());
		glPushMatrix();
		glTranslatef(pos.x(), pos.y(), pos.z());
		gluSphere(quad, it->size, 6, 6);
		glPopMatrix();
	}
	glColor3f(1.0f, 1.0f, 1.0f);
	glEnable(GL_LIGHTING);
}
Exemple #11
0
float Quality::distancePointToRay(const QVector3D& origin, const QVector3D& dir, const QVector3D& point)
{
    QVector3D dirToPoint = QVector3D(point.x() - origin.x(), point.y() - origin.y(), point.z() - origin.z());

    float scalarP = dir.x() * dirToPoint.x() +  dir.y() * dirToPoint.y() + dir.z() * dirToPoint.z();
    float norm = sqrt(dir.x() * dir.x() + dir.y() * dir.y() + dir.z() * dir.z()) *
                 sqrt(dirToPoint.x() * dirToPoint.x() + dirToPoint.y() * dirToPoint.y() + dirToPoint.z() * dirToPoint.z());

    float angle =  acos(scalarP / norm);

    return sin(angle) * Quality::distancePointToPoint(origin, point);
}
Exemple #12
0
bool REIXSSpectrometer::gratingInPosition() const
{
	if(currentGrating_ < 0 || currentGrating_ >= gratingCount())
		return false;

	QVector3D xyz = calibration_.hexapodXYZ(currentGrating_);
	QVector3D rst = calibration_.hexapodRST(currentGrating_);
	QVector3D uvw = calibration_.hexapodUVW(currentGrating_);

	return hexapod_->x()->withinTolerance(xyz.x()) &&
			hexapod_->y()->withinTolerance(xyz.y()) &&
			hexapod_->z()->withinTolerance(xyz.z()) &&
			hexapod_->r()->withinTolerance(rst.x()) &&
			hexapod_->s()->withinTolerance(rst.y()) &&
			hexapod_->t()->withinTolerance(rst.z()) &&
			hexapod_->u()->withinTolerance(uvw.x()) &&
			hexapod_->v()->withinTolerance(uvw.y()) &&
			hexapod_->w()->withinTolerance(uvw.z());
}
/* Build a unit quaternion representing the rotation
 * from u to v. The input vectors need not be normalised. */
QQuaternion fromTwoVectors(QVector3D u, QVector3D v)
{
    float norm_u_norm_v = sqrt(QVector3D::dotProduct(u, u) * QVector3D::dotProduct(v, v));
    float real_part = norm_u_norm_v + QVector3D::dotProduct(u, v);
    QVector3D w;
    if (real_part < 1.e-6f * norm_u_norm_v)
    {
        /* If u and v are exactly opposite, rotate 180 degrees
         * around an arbitrary orthogonal axis. Axis normalisation
         * can happen later, when we normalise the quaternion. */
        real_part = 0.0f;
        w = fabs(u.x()) > fabs(u.z()) ? QVector3D(-u.y(), u.x(), 0.f)
                                      : QVector3D(0.f,   -u.z(), u.y());
    } else {
        /* Otherwise, build quaternion the standard way. */
        w = QVector3D::crossProduct(u, v);
    }
    return QQuaternion(real_part, w).normalized();
}
void GLRasterTexture::add(const QVector3D &v, const QVector2D &tc)
{
    GLfloat *p = m_data.data() + m_count;
    *p++ = v.x();
    *p++ = v.y();
    *p++ = v.z();
    *p++ = tc.x();
    *p++ = tc.y();
    m_count += DATA_DIMENSIONS;
}
Exemple #15
0
/**
* Get polygon oriented bounding box
**/
void Polygon3D::getLoopOBB(Loop3D &pin, QVector3D &size, QMatrix4x4 &xformMat){
	float alpha = 0.0f;			
	float deltaAlpha = 0.05*3.14159265359f;
	float bestAlpha;

	Loop3D rotLoop;
	QMatrix4x4 rotMat;
	QVector3D minPt, maxPt;
	QVector3D origMidPt;
	QVector3D boxSz;
	QVector3D bestBoxSz;
	float curArea;
	float minArea = FLT_MAX;

	rotLoop = pin;
	Polygon3D::getLoopAABB(rotLoop, minPt, maxPt);
	origMidPt = 0.5f*(minPt + maxPt);

	//while(alpha < 0.5f*_PI){
	int cSz = pin.size();
	QVector3D difVec;
	for(int i=0; i<pin.size(); ++i){
		difVec = (pin.at((i+1)%cSz) - pin.at(i)).normalized();
		alpha = atan2(difVec.x(), difVec.y());
		rotMat.setToIdentity();				
		rotMat.rotate(57.2957795f*(alpha), 0.0f, 0.0f, 1.0f);//57.2957795 rad2degree				

		transformLoop(pin, rotLoop, rotMat);
		boxSz = Polygon3D::getLoopAABB(rotLoop, minPt, maxPt);
		curArea = boxSz.x() * boxSz.y();
		if(curArea < minArea){
			minArea = curArea;
			bestAlpha = alpha;
			bestBoxSz = boxSz;
		}
		//alpha += deltaAlpha;
	}

	xformMat.setToIdentity();											
	xformMat.rotate(57.2957795f*(bestAlpha), 0.0f, 0.0f, 1.0f);//57.2957795 rad2degree
	xformMat.setRow(3, QVector4D(origMidPt.x(), origMidPt.y(), origMidPt.z(), 1.0f));			
	size = bestBoxSz;
}//
void ViewportViewPlan::initializeViewport(const QVector3D& min, const QVector3D& max, int width, int height)
{
    float breadth = max.y() - min.y();

    // calculate the midpoint of the bounding box
    _midpoint = 0.5 * (min + max);

    QVector3D panpoint(_midpoint);
    panpoint.setX(panpoint.x() + _panX);
    panpoint.setY(panpoint.y() + _panY);

    float aspect_ratio = 1.0;
    if (height != 0)
        aspect_ratio = width / static_cast<float>(height);
    float hi, margin;

    _proj = QMatrix4x4();

    // find view extents using aspect ratio
    if (_midpoint.x() / aspect_ratio >= breadth) {
        margin = _midpoint.x() * .01 * _margin;
        hi = (_midpoint.x() / aspect_ratio + margin) / _zoom;
        float x = (_midpoint.x() + margin) / _zoom;
        _proj.ortho(-x, x, -hi, hi, 0.1f, 40.0f);
    }
    else {
        margin = breadth * .01 * _margin;
        hi = (breadth * aspect_ratio + margin) / _zoom;
        float y = (breadth + margin) / _zoom;
        _proj.ortho(-hi, hi, -y, y, 0.1f, 40.0f);
    }
    
    // find the camera location
    _camera_location = QVector3D(panpoint.x(), panpoint.y(), max.z() + 20);
    
    // view matrix
    QMatrix4x4 view;
    view.lookAt(_camera_location, QVector3D(panpoint.x(), panpoint.y(), 0), QVector3D(0,1,0));
    
    _view = view;

    finishSetup();
}
Exemple #17
0
void ctMatrix4::Scale(QVector3D t_scl)
{
    QMatrix4x4 tmp;
    tmp.setToIdentity();

    tmp(0, 0) = t_scl.x();
    tmp(1, 1) = t_scl.y();
    tmp(2, 2) = t_scl.z();
    m_matrix *= tmp;
}
Exemple #18
0
void MainView2D::setGridSize(QVector3D sz)
{
    switch(m_monProps->pointOfView())
    {
        case MonitorProperties::TopView:
            m_gridSize = QSize(sz.x(), sz.z());
        break;
        case MonitorProperties::LeftSideView:
        case MonitorProperties::RightSideView:
            m_gridSize = QSize(sz.z(), sz.y());
        break;
        //case MonitorProperties::Undefined:
        //case MonitorProperties::FrontView:
        default:
            m_gridSize = QSize(sz.x(), sz.y());
        break;
    }
    emit gridSizeChanged();
}
Exemple #19
0
float PerlinGenerator::noise(QVector3D& point)
{
    int ix = MathHelper::toInt(floor(point.x()));

    float fx0 = point.x() - ix;
    float fx1 = fx0 - 1.0f;
    float wx  = smooth(fx0);

    int iy = MathHelper::toInt(floor(point.y()));

    float fy0 = point.y() - iy;
    float fy1 = fy0 - 1.0f;
    float wy  = smooth(fy0);

    int iz = MathHelper::toInt(floor(point.z()));

    float fz0 = point.z() - iz;
    float fz1 = fz0 - 1.0f;
    float wz  = smooth(fz0);

    float vx0 = lattice(ix, iy, iz, QVector3D(fx0, fy0, fz0));
    float vx1 = lattice(ix + 1, iy, iz, QVector3D(fx1, fy0, fz0));
    float vy0 = lerp(QVector3D(wx, vx0, vx1));

    vx0 = lattice(ix, iy + 1, iz, QVector3D(fx0, fy1, fz0));
    vx1 = lattice(ix + 1, iy + 1, iz, QVector3D(fx1, fy1, fz0));

    float vy1 = lerp(QVector3D(wx, vx0, vx1));
    float vz0 = lerp(QVector3D(wy, vy0, vy1));

    vx0 = lattice(ix, iy, iz + 1, QVector3D(fx0, fy0, fz1));
    vx1 = lattice(ix + 1, iy, iz + 1, QVector3D(fx1, fy0, fz1));
    vy0 = lerp(QVector3D(wx, vx0, vx1));

    vx0 = lattice(ix, iy + 1, iz + 1, QVector3D(fx0, fy1, fz1));
    vx1 = lattice(ix + 1, iy + 1, iz + 1, QVector3D(fx1, fy1, fz1));
    vy1 = lerp(QVector3D(wx, vx0, vx1));

    float vz1 = lerp(QVector3D(wy, vy0, vy1));

    return lerp(QVector3D(wz, vz0, vz1));
}
Exemple #20
0
/*
    multLookAt -- Create a matrix to make an object, such as
        a camera, "look at" another object or location, from
        a specified position.

    Algorithm:
        The desired transformation is obtained with this 4x4 matrix:
            |  [xaxis] 0  |
            |    [up]  0  |
            |   [-at]  0  |
            |   [eye]  1  |
        Where 'xaxis', 'up' and 'at' are the new X, Y, and Z axes of
        the transforned object, respectively, and 'eye' is the input
        new location of the transformed object.

    Assumptions:
        The camera geometry is defined to be facing
        the negative Z axis.

    Usage:
        multLookAt creates a matrix and multiplies it onto the
        current matrix stack. Typical usage would be as follows:

            glMatrixMode (GL_MODELVIEW);
            // Define the usual view transformation here using
            //   gluLookAt or whatever.
            glPushMatrix();
            multLookAt (orig[0], orig[1], orig[2],
                at[0], at[1], at[2],
                up[0], up[1], up[2]);
            // Define "camera" object geometry here
            glPopMatrix();

    Warning: Results become undefined as (at-eye) approaches
        coincidence with (up).
*/
void multLookAt (float m[],
                 const QVector3D & ieye,
                 const QVector3D & iat,
                 const QVector3D & iup)
{
    // Compute our new look at vector, which will be
    //   the new negative Z axis of our transformed object.
    QVector3D atVec;
    atVec = ieye-iat;
    atVec.normalize();

    QVector3D xVec = QVector3D::crossProduct(atVec, iup);
    xVec.normalize();

    // Calculate the new up vector, which will be the
    //   positive Y axis of our transformed object. Note
    //   that it will lie in the same plane as the new
    //   look at vector and the old up vector.
    QVector3D upVec = QVector3D::crossProduct(xVec, atVec);

    // Account for the fact that the geometry will be defined to
    //   point along the negative Z axis.
    atVec *=  -1.f;

    // Fill out the rest of the 4x4 matrix
    m[0] = xVec.x();
    m[1] = xVec.y();
    m[2] = xVec.z();
    m[3] = 0.f;     // xaxis is m[0..2]
    m[4] = upVec.x();
    m[5] = upVec.y();
    m[6] = upVec.z();
    m[7] = 0.f;     // up is m[4..6]
    m[8] = atVec.x();
    m[9] = atVec.y();
    m[10] = atVec.z();
    m[11] = 0.f;    // -at is m[8..10]
    m[12] = ieye.x();
    m[13] = ieye.y();
    m[14] = ieye.z();
    m[15] = 1.f;
}
Exemple #21
0
void AxisRenderer::drawCamLine(QVector3D from, QVector3D to, QGLShaderProgram &program, const AxisCamera &camera)
{
    const GLfloat color[] ={1.0f, 0.0f, 0.0f, 1.0f}; //default red color

    //temp vector to hold line verticies
    std::vector<GLfloat> bufferData;

    //from verticies
    bufferData.push_back(from.x());
    bufferData.push_back(from.y());
    bufferData.push_back(from.z());
    bufferData.push_back(1.0f);

    //to verticies
    bufferData.push_back(to.x());
    bufferData.push_back(to.y());
    bufferData.push_back(to.z());
    bufferData.push_back(1.0f);

    program.bind();

    //create and fill line buffer with verticies
    QGLBuffer line(QGLBuffer::VertexBuffer);
    line.create();
    line.bind();
    line.allocate(bufferData.data(), sizeof(GLfloat) * 8);

    //get locations
    GLuint colorLoc = program.uniformLocation("color");
    Q_ASSERT(colorLoc != -1);
    GLuint mvpLoc = program.uniformLocation("modelToCamera");
    Q_ASSERT(mvpLoc != -1);

    //setup line for drawing
    line.bind();
    program.enableAttributeArray("vertex");
    program.setAttributeBuffer("vertex", GL_FLOAT, 0, 4);
    program.setUniformValueArray(colorLoc, color, 1, 4);
    program.setUniformValueArray(mvpLoc, &(camera.getProjMatrix()), 1);

    glDrawArrays(GL_LINES, 0, 2);
}
Exemple #22
0
void Box3D::includePoint(QVector3D p)
{
    const float EPS = 0.00001;
    if (_valid) {
        _min = Point3(std::min(_min.x(), p.x() - EPS),
                      std::min(_min.y(), p.y() - EPS),
                      std::min(_min.z(), p.z() - EPS));
        _max = Point3(std::max(_max.x(), p.x() + EPS),
                      std::max(_max.y(), p.y() + EPS),
                      std::max(_max.z(), p.z() + EPS));
    } else {
        _min = Point3(p.x() - EPS,
                      p.y() - EPS,
                      p.z() - EPS);
        _max = Point3(p.x() + EPS,
                      p.y() + EPS,
                      p.z() + EPS);
        _valid = true;
    }
}
bool QQuickVector3DValueType::fuzzyEquals(const QVector3D &vec, qreal epsilon) const
{
    qreal absEps = qAbs(epsilon);
    if (qAbs(v.x() - vec.x()) > absEps)
        return false;
    if (qAbs(v.y() - vec.y()) > absEps)
        return false;
    if (qAbs(v.z() - vec.z()) > absEps)
        return false;
    return true;
}
Exemple #24
0
static void _normalVectorToXYVectors( const QVector3D &pNormal, QVector3D &pXVector, QVector3D &pYVector )
{
  // Here we define the two perpendicular vectors that define the local
  // 2D space on the plane. They will act as axis for which we will
  // calculate the projection coordinates of a 3D point to the plane.
  if ( pNormal.z() > 0.001 || pNormal.z() < -0.001 )
  {
    pXVector = QVector3D( 1, 0, -pNormal.x() / pNormal.z() );
  }
  else if ( pNormal.y() > 0.001 || pNormal.y() < -0.001 )
  {
    pXVector = QVector3D( 1, -pNormal.x() / pNormal.y(), 0 );
  }
  else
  {
    pXVector = QVector3D( -pNormal.y() / pNormal.x(), 1, 0 );
  }
  pXVector.normalize();
  pYVector = QVector3D::normal( pNormal, pXVector );
}
Exemple #25
0
void Camera::shift(const QVector3D &shift)
{
    qreal k = (m_cameraPos - m_targetCamera).length() * 0.01;
    m_cameraPos += -k*shift.x()* m_right +
                    k*shift.y()* m_up;

    if(!m_isFreeMode)
        calcCameraAxis();

    matrixByAxisCamera(m_cameraMatrix, m_cameraPos, m_right, m_up);
}
Exemple #26
0
void Camera::lookAt(QVector3D lookPos)
{
    // Reconstruct pitch/yaw from the look direction
    const QVector3D lookDir= (lookPos - _position).normalized();

    const float theta= acosf(lookDir.y());
    const float phi= atan2f(lookDir.z(), lookDir.x());

    setPitch(90.0f - (theta * 180.0f / M_PI));
    setYaw  (90.0f - (phi   * 180.0f / M_PI));
}
Exemple #27
0
Connection::Connection( QVector3D fn, QVector3D diff, float v ) :
    fn( fn ),
    diff( diff ),
    v( v )
{
       QVector3D diffn = diff.normalized();

       r=qAbs(diffn.x());
       g=qAbs(diffn.y());
       b=qAbs(diffn.z());
}
void QtGLComponent::updateBoundingBox(const QVector3D& vert)
{
    if (vert.x() < m_boundMinus.x())
        m_boundMinus.setX(vert.x());

    if (vert.y() < m_boundMinus.y())
        m_boundMinus.setY(vert.y());

    if (vert.z() < m_boundMinus.z())
        m_boundMinus.setZ(vert.z());

    if (vert.x() > m_boundPlus.x())
        m_boundPlus.setX(vert.x());

    if (vert.y() > m_boundPlus.y())
        m_boundPlus.setY(vert.y());

    if (vert.z() > m_boundPlus.z())
        m_boundPlus.setZ(vert.z());
}
Exemple #29
0
void ModelInterface::initialize(const aiScene* scene)
{
    QVector<QVector3D> vertices;
    QVector<QVector3D> _bones;

    /// Vertices
    for(int i = 0; i < scene->mNumMeshes; ++i)
    {
        for(int j = 0; j < scene->mMeshes[i]->mNumVertices; ++j)
            vertices.append(QVector3D(scene->mMeshes[i]->mVertices[j].x, scene->mMeshes[i]->mVertices[j].y, scene->mMeshes[i]->mVertices[j].z));
    }

    // find min and max
    QVector3D minVertex;
    QVector3D maxVertex;

    for(int i = 0; i < vertices.count(); ++i)
    {
        if(vertices[i].x() < minVertex.x()) // min X
            minVertex.setX(vertices[i].x());

        if(vertices[i].y() < minVertex.y()) // min Y
            minVertex.setY(vertices[i].y());

        if(vertices[i].z() < minVertex.z()) // min Z
            minVertex.setZ(vertices[i].z());

        if(vertices[i].x() > maxVertex.x()) // max X
            maxVertex.setX(vertices[i].x());

        if(vertices[i].y() > maxVertex.y()) // max Y
            maxVertex.setY(vertices[i].y());

        if(vertices[i].z() > maxVertex.z()) // max Z
            maxVertex.setZ(vertices[i].z());
    }

    header.boundingBoxMin = minVertex;
    header.boundingBoxMax = maxVertex;
    header.center         = (maxVertex + minVertex) / 2;
}
Exemple #30
0
/*!
    Creates a normalized quaternion that corresponds to rotating through
    \a angle degrees about the specified 3D \a axis.
*/
QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D& axis, qreal angle)
{
    // Algorithm from:
    // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q56
    // We normalize the result just in case the values are close
    // to zero, as suggested in the above FAQ.
    qreal a = (angle / 2.0f) * M_PI / 180.0f;
    qreal s = qSin(a);
    qreal c = qCos(a);
    QVector3D ax = axis.normalized();
    return QQuaternion(c, ax.x() * s, ax.y() * s, ax.z() * s).normalized();
}