Пример #1
0
void BlurPicker::setIndex(qreal index)
{
    m_index = index;

    qreal baseline = 0;
    for (int i = 0; i < m_icons.count(); ++i) {
        ImageItem *icon = m_icons[i];
        qreal a = ((i + m_index) * 2 * M_PI) / m_icons.count();
        qreal xs = 380 * qSin(a);
        qreal ys = 230 * qCos(a);
        QPointF pos(xs, ys);
       // pos = QTransform::scale(0,0.2).map(pos);
//        pos = QTransform().rotate(-20).map(pos);
        pos = QTransform().rotate(-5).map(pos);
        pos -= QPointF(40, 40);
//        pos -= QPoint(10,10);
        icon->setPos(pos);
        baseline = qMax(baseline, ys);
        static_cast<BlurEffect *>(icon->graphicsEffect())->setBaseLine(baseline);
    }

    scene()->update();
}
Пример #2
0
static void qwtDrawStyle1Needle( QPainter *painter,
    const QPalette &palette, QPalette::ColorGroup colorGroup,
    double length )
{
    const double r[] = { 0.4, 0.3, 1, 0.8, 1, 0.3, 0.4 };
    const double a[] = { -45, -20, -15, 0, 15, 20, 45 };

    QPainterPath path;
    for ( int i = 0; i < 7; i++ )
    {
        const double angle = a[i] / 180.0 * M_PI;
        const double radius = r[i] * length;

        const double x = radius * qCos( angle );
        const double y = radius * qSin( angle );

        path.lineTo( x, -y );
    }

    painter->setPen( Qt::NoPen );
    painter->setBrush( palette.brush( colorGroup, QPalette::Light ) );
    painter->drawPath( path );
}
Пример #3
0
QMatrix &QMatrix::rotate(qreal a)
{
    qreal sina = 0;
    qreal cosa = 0;
    if (a == 90. || a == -270.)
        sina = 1.;
    else if (a == 270. || a == -90.)
        sina = -1.;
    else if (a == 180.)
        cosa = -1.;
    else{
        qreal b = deg2rad*a;                        // convert to radians
        sina = qSin(b);               // fast and convenient
        cosa = qCos(b);
    }
    qreal tm11 = cosa*_m11 + sina*_m21;
    qreal tm12 = cosa*_m12 + sina*_m22;
    qreal tm21 = -sina*_m11 + cosa*_m21;
    qreal tm22 = -sina*_m12 + cosa*_m22;
    _m11 = tm11; _m12 = tm12;
    _m21 = tm21; _m22 = tm22;
    return *this;
}
Пример #4
0
static
QPointF calcRadialPos ( const QStyleOptionSlider *dial, qreal offset )
{
	const int width = dial->rect.width();
	const int height = dial->rect.height();
	const int r = qMin(width, height) / 2;
	const int currentSliderPosition = dial->upsideDown ? dial->sliderPosition : (dial->maximum - dial->sliderPosition);
	qreal a = 0;
	if (dial->maximum == dial->minimum)
		a = Q_PI / 2;
	else if (dial->dialWrapping)
		a = Q_PI * 3 / 2 - (currentSliderPosition - dial->minimum) * 2 * Q_PI
			/ (dial->maximum - dial->minimum);
	else
		a = (Q_PI * 8 - (currentSliderPosition - dial->minimum) * 10 * Q_PI
			/ (dial->maximum - dial->minimum)) / 6;
	qreal xc = width / 2.0;
	qreal yc = height / 2.0;
	qreal len = r - calcBigLineSize(r) - 3;
	qreal back = offset * len;
	QPointF pos(QPointF(xc + back * qCos(a), yc - back * qSin(a)));
	return pos;
}
Пример #5
0
QPainterPath GraphicsEdgeItem::shape() const
{
	QPainterPath path;
	QPointF source = mEdgeData->sourceNode()->sceneCoor();
	QPointF dest = mEdgeData->destNode()->sceneCoor();
	QLineF line(source, dest);
	qreal angle = line.angle();
	if(angle>=180)
		angle -= 180;
	qreal dx = mWidth/2.0*qSin(angle);
	qreal dy = mWidth/2.0*qCos(angle);
	QPointF p1(source.x()-dx,source.y()+dy);
	QPointF p2(source.x()+dx,source.y()-dy);
	QPointF p3(dest.x()+dx,dest.y()-dy);
	QPointF p4(dest.x()-dx,dest.y()+dy);
	path.moveTo(p1);
	path.lineTo(p2);
	path.lineTo(p3);
	path.lineTo(p4);
	path.lineTo(p1);
	return path;	
	
}
Пример #6
0
Point Toolbox::arcCenter(const Point& p1, const Point& p2,
                         const Angle& a) noexcept {
  if (a == 0) {
    // there is no arc center...just return the middle of start- and endpoint
    return (p1 + p2) / 2;
  } else {
    // http://math.stackexchange.com/questions/27535/how-to-find-center-of-an-arc-given-start-point-end-point-radius-and-arc-direc
    qreal x0       = p1.getX().toMm();
    qreal y0       = p1.getY().toMm();
    qreal x1       = p2.getX().toMm();
    qreal y1       = p2.getY().toMm();
    qreal angle    = a.mappedTo180deg().toRad();
    qreal angleSgn = (angle >= 0) ? 1 : -1;
    qreal d        = qSqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
    qreal r        = d / (2 * qSin(angle / 2));
    qreal h        = qSqrt(r * r - d * d / 4);
    qreal u        = (x1 - x0) / d;
    qreal v        = (y1 - y0) / d;
    qreal a        = ((x0 + x1) / 2) - h * v * angleSgn;
    qreal b        = ((y0 + y1) / 2) + h * u * angleSgn;
    return Point::fromMm(a, b);
  }
}
Пример #7
0
void DistortionFXFilter::multipleCornersMultithreaded(const Args& prm)
{
    int Width       = prm.orgImage->width();
    int Height      = prm.orgImage->height();
    uchar* data     = prm.orgImage->bits();
    bool sixteenBit = prm.orgImage->sixteenBit();
    int bytesDepth  = prm.orgImage->bytesDepth();
    uchar* pResBits = prm.destImage->bits();

    double nh, nw;

    int    nHalfW   = Width / 2;
    int    nHalfH   = Height / 2;
    double lfRadMax = qSqrt(Height * Height + Width * Width) / 2.0;
    double lfAngle, lfNewRadius, lfCurrentRadius;

    for (int w = prm.start; runningFlag() && (w < prm.stop); ++w)
    {
        // we find the distance from the center
        nh = nHalfH - prm.h;
        nw = nHalfW - w;

        // now, we get the distance
        lfCurrentRadius = qSqrt(nh * nh + nw * nw);
        // we find the angle from the center
        lfAngle = qAtan2(nh, nw) * (double)prm.Factor;

        // ok, we sum angle with accumuled to find a new angle
        lfNewRadius = lfCurrentRadius * lfCurrentRadius / lfRadMax;

        // now we find the exact position's x and y
        nw = (double)nHalfW - (qCos(lfAngle) * lfNewRadius);
        nh = (double)nHalfH - (qSin(lfAngle) * lfNewRadius);

        setPixelFromOther(Width, Height, sixteenBit, bytesDepth, data, pResBits, w, prm.h, nw, nh, prm.AntiAlias);
    }
}
Пример #8
0
	void draw( QPainter &painter, const Slice &slice, const uiCoord2D &pithCoord, const int &intensityThreshold, const TKD::ProjectionType &view )
	{
		painter.save();
		painter.setPen(QColor(255,255,255,127));

		const uint width = painter.window().width();
		const uint height = painter.window().height();

		const qreal angularIncrement = TWO_PI/(qreal)(width);

		uint i, j, x, y;

		if ( view == TKD::Z_PROJECTION )
		{
			for ( j=0 ; j<height ; ++j )
			{
				for ( i=0 ; i<width ; ++i )
				{
					if ( slice.at(j,i) > intensityThreshold ) painter.drawPoint(i,j);
				}
			}
		}
		else if ( view == TKD::CARTESIAN_PROJECTION )
		{
			for ( j=0 ; j<height ; ++j )
			{
				for ( i=0 ; i<width ; ++i )
				{
					x = pithCoord.x + j * qCos(i*angularIncrement);
					y = pithCoord.y + j * qSin(i*angularIncrement);
					if ( slice.at(y,x) > intensityThreshold ) painter.drawPoint(i,j);
				}
			}
		}

		painter.restore();
	}
void SpaceObjectShip :: update(qint64 time)
{
  if (mTargetX != -1 && mTargetY != -1)
  {
    double tAngle = angle(mCoordX, mCoordY, mTargetX, mTargetY);
    double dist = distance(mCoordX, mCoordY, mTargetX, mTargetY) / 4;
    double diff = angleDiff(mRotation, tAngle);

    mDirection = turnDirection(mRotation, tAngle);

    if (diff > -dist && diff < dist)
      mTrust = true;
    else
      mTrust = false;

    if (dist < 2)
    {
      mTargetX = -1;
      mTargetY = -1;
      mTrust = false;
      mDirection = 0;
    }
  }


  /* normal calculation of rotation / thrust */
  mRotation += mDirection * (time / 1000.0) * ROT_PER_SEC;

  if (mRotation < 0) mRotation += 360;
  if (mRotation >= 360) mRotation -= 360;

  if (mTrust)
  {
    mCoordX += qCos( DEG2RAD(mRotation) ) * (time / 1000.0) * SPEED_PER_SEC;
    mCoordY += qSin( DEG2RAD(mRotation) ) * (time / 1000.0) * SPEED_PER_SEC;
  }
}
Пример #10
0
void NMPT_simulator::buildModel(int iterations_number)
{
    stone_trajectory.resize(iterations_number);
    duck_trajectory.resize(iterations_number);

    max_iter_achieved = iterations_number;

    stone_trajectory[0].x = 0;
    stone_trajectory[0].y=0;
    stone_trajectory[0].Vx = qCos(qDegreesToRadians(alpha))*V;
    stone_trajectory[0].Vy = qSin(qDegreesToRadians(alpha))*V;

    duck_trajectory[0].x = dX0;
    duck_trajectory[0].Vx = U;

    closest_encounter.first = dX0;
    closest_encounter.second = 0;

    for(int i=1; i<iterations_number; i++)
    {
        moveDuck(i);
        moveStone(i);

        if(stone_trajectory[i].y < 0)
        {
            max_iter_achieved = i;
            resize_trajectory(i);
            break;
        }

        if(abs(stone_trajectory[i].x - duck_trajectory[i].x) < closest_encounter.first)
        {
            closest_encounter.first = abs(stone_trajectory[i].x - duck_trajectory[i].x);
            closest_encounter.second = i;
        }
    }
}
Пример #11
0
qreal ImageProcessor::vectorSum(QImage input, QPoint start, int fakeangle) {
    bool goOn = true;
    QPoint currentPoint;
    qreal returnMe =0.0;
    int length=1;
    qreal angle = (fakeangle/180.0) * M_PI;
    while(goOn) {
        int newX = (int)(start.x() + (length * qCos(angle) ));
        int newY = (int)(start.y() + (length * qSin(angle) ));
        currentPoint = QPoint(newX,newY);
        if(input.valid(currentPoint)) {
            //qreal value =  regionAvg(currentPoint.x(),currentPoint.y(),1,1,input);
            qreal value =  qRed(input.pixel(currentPoint));
            //qDebug()<<"Adding " <<(value/length);
            returnMe += (value/sqrt(length));
            //qDebug()<<"Return me is now " <<returnMe;
            length++;
        } else {
            goOn = false;
        }
    }

    return returnMe;
}
Пример #12
0
void NotificationSound::playSound()
{
    //QSound::play(":/sound/notification_sound.wav");
    //return;
    qreal frequency = ((sFrequency <= 0)?2000:sFrequency);
    qreal mseconds = ((sDuration <= 0)?1000:sDuration);
    quint8 volume = ((sVolume <= 0)?1:sVolume);
    qreal sampleRate = 2.0 * M_PI / (192000./frequency);

    QByteArray bytebuf;
    bytebuf.resize(mseconds * 192);

    for (int i=0; i < bytebuf.size(); i++) {
        bytebuf[i] = (quint8)(qreal(255) * qSin(qreal(i) * sampleRate));
    }


    QDataStream stream(&bytebuf, QIODevice::ReadWrite);

    QAudioFormat format;
    format.setSampleRate(192000);
    format.setChannelCount(1);
    format.setSampleSize(8);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::UnSignedInt);

    QAudioOutput * audio = new QAudioOutput(format, this);
    audio->setVolume(1.0 * (qreal(volume + 1)/4));
    audio->setBufferSize(bytebuf.size());
    audio->start(stream.device());

    QEventLoop loop;
    QTimer::singleShot(mseconds*2, &loop, SLOT(quit()));
    loop.exec();
}
Пример #13
0
/*!
    \fn QTransform & QTransform::rotateRadians(qreal angle, Qt::Axis axis)
    
    Rotates the coordinate system counterclockwise by the given \a angle
    about the specified \a axis and returns a reference to the matrix.
    
    Note that if you apply a QTransform to a point defined in widget
    coordinates, the direction of the rotation will be clockwise
    because the y-axis points downwards.

    The angle is specified in radians.

    \sa setMatrix()
*/
QTransform & QTransform::rotateRadians(qreal a, Qt::Axis axis)
{
    qreal sina = qSin(a);
    qreal cosa = qCos(a);

    if (axis == Qt::ZAxis) {
        if (type() != TxProject) {
            qreal tm11 = cosa*affine._m11 + sina*affine._m21;
            qreal tm12 = cosa*affine._m12 + sina*affine._m22;
            qreal tm21 = -sina*affine._m11 + cosa*affine._m21;
            qreal tm22 = -sina*affine._m12 + cosa*affine._m22;
            affine._m11 = tm11; affine._m12 = tm12;
            affine._m21 = tm21; affine._m22 = tm22;
        } else {
            QTransform result;
            result.affine._m11 = cosa;
            result.affine._m12 = sina;
            result.affine._m22 = cosa;
            result.affine._m21 = -sina;
            *this = result * *this;
        }
        m_dirty |= TxRotate;
    } else {
        QTransform result;
        if (axis == Qt::YAxis) {
            result.affine._m11 = cosa;
            result.m_13 = -sina * inv_dist_to_plane;
        } else {
            result.affine._m22 = cosa;
            result.m_23 = -sina * inv_dist_to_plane;
        }
        m_dirty = TxProject;
        *this = result * *this;
    }
    return *this;
}
Пример #14
0
void Widget::drawObj()//draw obj
{
//    glLoadIdentity();
//    drawTriangle();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(radius*qCos(AngToRad*xRot), yRot, radius*qSin(AngToRad*xRot), 0, 0, 0, 0, 1, 0);

//    glTranslatef(0.0, 0.0, -50.0+zTra);
//    glRotatef(xRot, 1.0, 0.0, 0.0);
//    glRotatef(yRot, 0.0, qCos(yRot*AngToRad), -qSin(yRot*AngToRad));
//    glRotatef(xRot, 0.0,1.0,0.0);
//    glRotatef(zRot, 0.0, 0.0, 1.0);
    glBegin(GL_TRIANGLES);
qglColor(Qt::green);
    for(int i=0;i<ObjFace.length();i++){        
        glVertex3f(ObjFace[i].a.x,ObjFace[i].a.y,ObjFace[i].a.z);
        glVertex3f(ObjFace[i].b.x,ObjFace[i].b.y,ObjFace[i].b.z);
        glVertex3f(ObjFace[i].c.x,ObjFace[i].c.y,ObjFace[i].c.z);
    }
//    QMessageBox::information(NULL, "Title", ObjFace[ObjFace.length()-1].toQString(), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
    glFlush();
    glEnd();
}
Пример #15
0
void Bullet::move(){
    int STEP_SIZE = 5;
    double theta = rotation(); //degrees

    double dy = STEP_SIZE * qSin(qDegreesToRadians(theta));
    double dx = STEP_SIZE * qCos(qDegreesToRadians(theta));

    setPos(x()+dx, y()+dy);

    // get a list of all the items currently colliding with this bullet
    QList<QGraphicsItem *> colliding_items = collidingItems();

    if((x()>720)||(x()<-5)||(y()>720)||(y()<-5)){
        scene()->removeItem(this);
        delete this;
    }

    // if one of the colliding items is an Enemy, destroy both the bullet and the enemy
    for (int i = 0, n = colliding_items.size(); i < n; ++i){
        if (typeid(*(colliding_items[i])) == typeid(Enemy)){

            //remove them from the scene (still on the heap)
            scene()->removeItem(colliding_items[i]);
            scene()->removeItem(this);

            // delete them from the heap to save memory
            delete colliding_items[i];
            delete this;


            // return (all code below refers to a non existent bullet)
            return;
        }
    }

}
Пример #16
0
 virtual double y ( double x ) const
 {
     return qSin( x );
 }
Пример #17
0
//--------------------------------------------------------------- d2aCallback
extern "C" int d2aCallback(const void *inputBuffer, void *outputBuffer,
                           unsigned long framesToProcess,
                           const PaStreamCallbackTimeInfo* timeInfo,
                           PaStreamCallbackFlags statusFlags,
                           void *userData )
{
  paUserData *udata=(paUserData*)userData;
  short *wptr = (short*)outputBuffer;
  unsigned int i;
  static int n;
  static int ic=0;
  static bool btxok0=false;
  static bool bTune0=false;
  static int nStart=0;
  static double phi=0.;
  double tsec,tstart,dphi;
  int nsec;
  int nTRperiod=udata->nTRperiod;

  // Get System time
  qint64 ms = QDateTime::currentMSecsSinceEpoch() % 86400000;
  tsec = 0.001*ms;
  nsec = ms/1000;
  qreal dPhase=iqPhase/5729.57795131;
  qreal amp=1.0 + 0.0001*iqAmp;
  qreal xAmp=txPower*295.00*qSqrt(2.0 - amp*amp);
  qreal yAmp=txPower*295.00*amp;
  static int nsec0=0;

  if(bTune) {
    ic=0;
    dphi=6.28318530718*1270.46/11025.0;
  }
  if(bTune0 and !bTune) btxok=false;
  bTune0=bTune;

  if(nsec!=nsec0) {
//    qDebug() << txPower << iqAmp << iqPhase << amp << xAmp << yAmp << dPhase << bTune;
//    qDebug() << "A" << nsec%60 << bTune << btxok;
//    ic=0;
    nsec0=nsec;
  }

  if(btxok and !btxok0) {       //Start (or re-start) a transmission
    n=nsec/nTRperiod;
    tstart=tsec - n*nTRperiod - 1.0;

    if(tstart<1.0) {
      ic=0;                      //Start of Tx cycle, set starting index to 0
      nStart=n;
    } else {
      if(n != nStart) { //Late start in new Tx cycle: compute starting index
        ic=(int)(tstart*11025.0);
        ic=2*ic;
        nStart=n;
      }
    }
  }
  btxok0=btxok;

  if(btxok) {
    for(i=0 ; i<framesToProcess; i++ )  {
        short int i2a=iwave[ic++];
        short int i2b=iwave[ic++];
      if(ic > nwave) {i2a=0; i2b=0;}
//      i2 = 500.0*(i2/32767.0 + 5.0*gran());      //Add noise (tests only!)
//    if(bIQxt) {
      if(1) {
        if(bTune) {
          phi += dphi;
        } else {
          phi=qAtan2(qreal(i2a),qreal(i2b));
        }
        i2a=xAmp*qCos(phi);
        i2b=yAmp*qSin(phi + dPhase);
//        qDebug() << xAmp << yAmp << phi << i2a << i2b;
      }
//      i2a=0.01*txPower*i2a;
//      i2b=0.01*txPower*i2b;
      *wptr++ = i2a;                     //left
      *wptr++ = i2b;                     //right
    }
  } else {
    for(i=0 ; i<framesToProcess; i++ )  {
      *wptr++ = 0;
      *wptr++ = 0;
      ic++; ic++;
    }
  }
  if(ic > nwave) {
    btxok=0;
    ic=0;
  }
  return 0;
}
Пример #18
0
/*!
    \since 4.4

    Returns a QLineF with the given \a length and \a angle.

    The first point of the line will be on the origin.

    Positive values for the angles mean counter-clockwise while negative values
    mean the clockwise direction. Zero degrees is at the 3 o'clock position.
*/
QLineF QLineF::fromPolar(qreal length, qreal angle)
{
    const qreal angleR = angle * M_2PI / 360.0;
    return QLineF(0, 0, qCos(angleR) * length, -qSin(angleR) * length);
}
Пример #19
0
void MathPlot::setupScatterStyleDemo(QCustomPlot *customPlot)
{

  customPlot->legend->setVisible(true);
  customPlot->legend->setFont(QFont("Helvetica", 9));
  customPlot->legend->setRowSpacing(-3);
  QVector<QCPScatterStyle::ScatterShape> shapes;
  shapes << QCPScatterStyle::ssCross;
  shapes << QCPScatterStyle::ssPlus;
  shapes << QCPScatterStyle::ssCircle;
  shapes << QCPScatterStyle::ssDisc;
  shapes << QCPScatterStyle::ssSquare;
  shapes << QCPScatterStyle::ssDiamond;
  shapes << QCPScatterStyle::ssStar;
  shapes << QCPScatterStyle::ssTriangle;
  shapes << QCPScatterStyle::ssTriangleInverted;
  shapes << QCPScatterStyle::ssCrossSquare;
  shapes << QCPScatterStyle::ssPlusSquare;
  shapes << QCPScatterStyle::ssCrossCircle;
  shapes << QCPScatterStyle::ssPlusCircle;
  shapes << QCPScatterStyle::ssPeace;
  shapes << QCPScatterStyle::ssCustom;

  QPen pen;
  // add graphs with different scatter styles:
  for (int i=0; i<shapes.size(); ++i)
  {
    customPlot->addGraph();
    pen.setColor(QColor(sin(i*0.3)*100+100, sin(i*0.6+0.7)*100+100, sin(i*0.4+0.6)*100+100));
    // generate data:
    QVector<double> x(10), y(10);
    for (int k=0; k<10; ++k)
    {
      x[k] = k/10.0 * 4*3.14 + 0.01;
      y[k] = 7*sin(x[k])/x[k] + (shapes.size()-i)*5;
    }
    customPlot->graph()->setData(x, y);
    customPlot->graph()->rescaleAxes(true);
    customPlot->graph()->setPen(pen);
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
    customPlot->graph()->setName(QCPScatterStyle::staticMetaObject.enumerator(QCPScatterStyle::staticMetaObject.indexOfEnumerator("ScatterShape")).valueToKey(shapes.at(i)));
#endif
    customPlot->graph()->setLineStyle(QCPGraph::lsLine);
    // set scatter style:
    if (shapes.at(i) != QCPScatterStyle::ssCustom)
    {
      customPlot->graph()->setScatterStyle(QCPScatterStyle(shapes.at(i), 10));
    }
    else
    {
      QPainterPath customScatterPath;
      for (int i=0; i<3; ++i)
        customScatterPath.cubicTo(qCos(2*M_PI*i/3.0)*9, qSin(2*M_PI*i/3.0)*9, qCos(2*M_PI*(i+0.9)/3.0)*9, qSin(2*M_PI*(i+0.9)/3.0)*9, 0, 0);
      customPlot->graph()->setScatterStyle(QCPScatterStyle(customScatterPath, QPen(), QColor(40, 70, 255, 50), 10));
    }
  }
  // set blank axis lines:
  customPlot->rescaleAxes();
  customPlot->xAxis->setTicks(false);
  customPlot->yAxis->setTicks(false);
  customPlot->xAxis->setTickLabels(false);
  customPlot->yAxis->setTickLabels(false);
  // make top right axes clones of bottom left axes:
  customPlot->axisRect()->setupFullAxesBox();
}
Пример #20
0
void Meteor::init(const float& radiantAlpha, const float& radiantDelta,
		  const float& speed, const QList<ColorPair> colors)
{
	// meteor velocity in km/s
	m_speed = speed;

	// find the radiant in horizontal coordinates
	Vec3d radiantAltAz;
	StelUtils::spheToRect(radiantAlpha, radiantDelta, radiantAltAz);
	radiantAltAz = m_core->j2000ToAltAz(radiantAltAz);
	float radiantAlt, radiantAz;
	// S is zero, E is 90 degrees (SDSS)
	StelUtils::rectToSphe(&radiantAz, &radiantAlt, radiantAltAz);

	// meteors won't be visible if radiant is below 0degrees
	if (radiantAlt < 0.f)
	{
		return;
	}

	// define the radiant coordinate system
	// rotation matrix to align z axis with radiant
	m_matAltAzToRadiant = Mat4d::zrotation(radiantAz) * Mat4d::yrotation(M_PI_2 - radiantAlt);

	// select a random initial meteor altitude in the horizontal system [MIN_ALTITUDE, MAX_ALTITUDE]
	float initialAlt = MIN_ALTITUDE + (MAX_ALTITUDE - MIN_ALTITUDE) * ((float) qrand() / ((float) RAND_MAX + 1));

	// calculates the max z-coordinate for the currrent radiant
	float maxZ = meteorZ(M_PI_2 - radiantAlt, initialAlt);

	// meteor trajectory
	// select a random xy position in polar coordinates (radiant system)

	float xyDist = maxZ * ((double) qrand() / ((double) RAND_MAX + 1)); // [0, maxZ]
	float theta = 2 * M_PI * ((double) qrand() / ((double) RAND_MAX + 1)); // [0, 2pi]

	// initial meteor coordinates (radiant system)
	m_position[0] = xyDist * qCos(theta);
	m_position[1] = xyDist * qSin(theta);
	m_position[2] = maxZ;
	m_posTrain = m_position;

	// store the initial z-component (radiant system)
	m_initialZ = m_position[2];

	// find the initial meteor coordinates in the horizontal system
	Vec3d positionAltAz = m_position;
	positionAltAz.transfo4d(m_matAltAzToRadiant);

	// find the angle from horizon to meteor
	float meteorAlt = qAsin(positionAltAz[2] / positionAltAz.length());

	// this meteor should not be visible if it is above the maximum altitude
	// or if it's below the horizon!
	if (positionAltAz[2] > MAX_ALTITUDE || meteorAlt <= 0.f)
	{
		return;
	}

	// determine the final z-component and the min distance between meteor and observer
	if (radiantAlt < 0.0262f) // (<1.5 degrees) earth grazing meteor ?
	{
		// earth-grazers are rare!
		// introduce a probabilistic factor just to make them a bit harder to occur
		float prob = ((float) qrand() / ((float) RAND_MAX + 1));
		if (prob > 0.3f) {
			return;
		}

		// limit lifetime to 12sec
		m_finalZ = -m_position[2];
		m_finalZ = qMax(m_position[2] - m_speed * 12.f, (double) m_finalZ);

		m_minDist = xyDist;
	}
	else
	{
		// limit lifetime to 12sec
		m_finalZ = meteorZ(M_PI_2 - meteorAlt, MIN_ALTITUDE);
		m_finalZ = qMax(m_position[2] - m_speed * 12.f, (double) m_finalZ);

		m_minDist = qSqrt(m_finalZ * m_finalZ + xyDist * xyDist);
	}

	// a meteor cannot hit the observer!
	if (m_minDist < MIN_ALTITUDE) {
		return;
	}

	// select random magnitude [-3; 4.5]
	float Mag = (float) qrand() / ((float) RAND_MAX + 1) * 7.5f - 3.f;

	// compute RMag and CMag
	RCMag rcMag;
	m_core->getSkyDrawer()->computeRCMag(Mag, &rcMag);
	m_absMag = rcMag.radius <= 1.2f ? 0.f : rcMag.luminance;
	if (m_absMag == 0.f) {
		return;
	}

	// most visible meteors are under about 184km distant
	// scale max mag down if outside this range
	float scale = qPow(184.0 / m_minDist, 2);
	m_absMag *= qMin(scale, 1.0f);

	// build the color vector
	buildColorVectors(colors);

	m_alive = true;
}
void dtkComposerNodeNumberOperatorUnarySin::run(void)
{
    double *value = d->receiver.data<double>();
    *value = qSin(*value);
    d->emitter.setData<double>(value);
}
Пример #22
0
/**
 * Easing function where the value grows sinusoidally. Note that the calculated  end value will be 0 rather than 1.
 */
static qreal easeSineCurve(qreal t)
{
    return (qSin(((t * M_PI * 2)) - M_PI_2) + 1) / 2;
}
Пример #23
0
static inline qreal qt_sinProgress(qreal value)
{
    return qSin((value * M_PI) - M_PI_2) / 2 + qreal(0.5);
}
Пример #24
0
void
ClassicStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const
{
    if (cc != QStyle::CC_Dial) {
        QCommonStyle::drawComplexControl(cc, opt, p, widget);
        return;
    }

    const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(opt);
    if (dial == NULL)
        return;

    float angle = DIAL_MIN + (DIAL_RANGE * (float(dial->sliderValue - dial->minimum) /
                   (float(dial->maximum - dial->minimum))));
    int degrees = int(angle * 180.0 / M_PI);
    int ns = dial->tickInterval;
    int numTicks = 1 + (dial->maximum + ns - dial->minimum) / ns;
    int size = dial->rect.width() < dial->rect.height() ? dial->rect.width() : dial->rect.height();
    int scale = 1;
    int width = size * scale;
    int indent = (int)(width * 0.15 + 1);

    QPalette pal = opt->palette;
    QColor knobColor = pal.mid().color(); //pal.background().color();
    QColor meterColor = (dial->state & State_Enabled) ? pal.highlight().color() : pal.mid().color();
    QPen pen;
    QColor c;

    p->save();
    p->setRenderHint(QPainter::Antialiasing, true);
    p->translate(1+(dial->rect.width()-size)/2, 1+(dial->rect.height()-size)/2);

    // Knob body and face...

    pen.setColor(knobColor);
    pen.setWidth(scale * 2);
    pen.setCapStyle(Qt::FlatCap);
    p->setPen(pen);

    QRadialGradient gradient(size/2, size/2, size-indent, size/2-indent, size/2-indent);
    gradient.setColorAt(0, knobColor.light());
    gradient.setColorAt(1, knobColor.dark());
    p->setBrush(gradient);
    p->drawEllipse(indent, indent, width-2*indent, width-2*indent);

    // The bright metering bit...

    c = meterColor;
    pen.setColor(c);
    pen.setWidth(indent);
    p->setPen(pen);

    int arcLen = -(degrees - 45) * 16;
    if (arcLen == 0) arcLen = -16;
    p->drawArc(indent/2, indent/2, width-indent, width-indent, (180 + 45) * 16, arcLen);
    p->setBrush(Qt::NoBrush);

    // Tick notches...

    if (dial->subControls & QStyle::SC_DialTickmarks) {
    	//	std::cerr << "Notches visible" << std::endl;
    	pen.setColor(pal.dark().color());
    	pen.setWidth(scale);
    	p->setPen(pen);
    	for (int i = 0; i < numTicks; ++i) {
            int div = numTicks;
            if (div > 1) --div;
            drawTick(p, DIAL_MIN + (DIAL_MAX - DIAL_MIN) * i / div, width, true);
    	}
    }

    // Shadowing...

    pen.setWidth(scale);
    p->setPen(pen);

    // Knob shadow...

    int shadowAngle = -720;
    c = knobColor.dark();
    for (int arc = 120; arc < 2880; arc += 240)
    {
        pen.setColor(c);
        p->setPen(pen);
        p->drawArc(indent, indent, width-2*indent, width-2*indent, shadowAngle
                        + arc, 240);
        p->drawArc(indent, indent, width-2*indent, width-2*indent, shadowAngle
                        - arc, 240);
        c = c.light(110);
    }

    // Scale shadow...

    shadowAngle = 2160;
    c = pal.dark().color();
    for (int arc = 120; arc < 2880; arc += 240) {
    	pen.setColor(c);
    	p->setPen(pen);
    	p->drawArc(scale/2, scale/2,
    			width-scale, width-scale, shadowAngle + arc, 240);
    	p->drawArc(scale/2, scale/2,
    			width-scale, width-scale, shadowAngle - arc, 240);
    	c = c.light(108);
    }

    // Undraw the bottom part...

    pen.setColor(pal.background().color());
    pen.setWidth(scale * 4);
    p->setPen(pen);
    p->drawArc(scale/2, scale/2,
		  width-scale, width-scale, -45 * 16, -90 * 16);

    // Pointer notch...

    float hyp = float(width) / 2.0;
    float len = hyp - indent;
    --len;

    float x0 = hyp;
    float y0 = hyp;

    float x = hyp - len * qSin(angle);
    float y = hyp + len * qCos(angle);

    c = pal.dark().color();
    pen.setColor((dial->state & State_Enabled) ? c.dark(130) : c);
    pen.setWidth(scale * 2);
    p->setPen(pen);
    p->drawLine(int(x0), int(y0), int(x), int(y));

    // done
    p->restore();
}
QRect QAccessibleDial::rect(int child) const
{
    QRect rect;
    if (!dial()->isVisible())
        return rect;
    switch (child) {
    case Self:
        return QAccessibleWidgetEx::rect(child);
    case SpeedoMeter: {
        // Mixture from qcommonstyle.cpp (focus rect).
        int width = dial()->width();
        int height = dial()->height();
        qreal radius = qMin(width, height) / 2.0;
        qreal delta = radius / 6.0;
        qreal dx = delta + (width - 2 * radius) / 2.0;
        qreal dy = delta + (height - 2 * radius) / 2.0;
        rect = QRect(int(dx), int(dy), int(radius * 2 - 2 * delta), int(radius * 2 - 2 * delta));
        if (dial()->notchesVisible()) {
            rect.translate(int(-radius / 6), int(-radius / 6));
            rect.setWidth(rect.width() + int(radius / 3));
            rect.setHeight(rect.height() + int(radius / 3));
        }
        break;
    }
    case SliderHandle: {
        // Mixture from qcommonstyle.cpp and qdial.cpp.
        int sliderValue = !dial()->invertedAppearance() ? dial()->value()
                                                        : (dial()->maximum() - dial()->value());
        qreal angle = 0;
        if (dial()->maximum() == dial()->minimum()) {
            angle = Q_PI / 2;
        } else if (dial()->wrapping()) {
            angle = Q_PI * 3 / 2 - (sliderValue - dial()->minimum()) * 2 * Q_PI
                    / (dial()->maximum() - dial()->minimum());
        } else {
            angle = (Q_PI * 8 - (sliderValue - dial()->minimum()) * 10 * Q_PI
                    / (dial()->maximum() - dial()->minimum())) / 6;
        }

        int width = dial()->rect().width();
        int height = dial()->rect().height();
        int radius = qMin(width, height) / 2;
        int xc = width / 2;
        int yc = height / 2;
        int bigLineSize = radius / 6;
        if (bigLineSize < 4)
            bigLineSize = 4;
        if (bigLineSize > radius / 2)
            bigLineSize = radius / 2;
        int len = radius - bigLineSize - 5;
        if (len < 5)
            len = 5;
        int back = len / 2;

        QPolygonF arrow(3);
        arrow[0] = QPointF(0.5 + xc + len * qCos(angle),
                           0.5 + yc - len * qSin(angle));
        arrow[1] = QPointF(0.5 + xc + back * qCos(angle + Q_PI * 5 / 6),
                           0.5 + yc - back * qSin(angle + Q_PI * 5 / 6));
        arrow[2] = QPointF(0.5 + xc + back * qCos(angle - Q_PI * 5 / 6),
                           0.5 + yc - back * qSin(angle - Q_PI * 5 / 6));
        rect = arrow.boundingRect().toRect();
        break;
    }
    default:
        return QRect();
    }

    QPoint globalPos = dial()->mapToGlobal(QPoint(0,0));
    return QRect(globalPos.x() + rect.x(), globalPos.y() + rect.y(), rect.width(), rect.height());
}
Пример #26
0
QMap<int, double> TutorialUnit::moveHaptic(QMap<int, double> axes)
{
    QMap<int, double> force;
    if(axes.empty()){
        stop();
        return force;
    }

    if(mHapticStartAxes.empty()){
        mHapticStartAxes = axes;
        mStartPosition = QPointF(getPosition().x, getPosition().y);
    }

    qDebug() << "=========================";
    qDebug() << "Start: " << mHapticStartAxes[Tc::Haptic::AxisX] << "," << mHapticStartAxes[Tc::Haptic::AxisX];
    qDebug() << "Current: " << axes[Tc::Haptic::AxisX] << "," << axes[Tc::Haptic::AxisX];

    axes[Tc::Haptic::AxisX] -= mHapticStartAxes[Tc::Haptic::AxisX];
    axes[Tc::Haptic::AxisY] -= mHapticStartAxes[Tc::Haptic::AxisY];
    axes[Tc::Haptic::AxisZ] -= mHapticStartAxes[Tc::Haptic::AxisZ];

    QPointF p(axes[Tc::Haptic::AxisX], axes[Tc::Haptic::AxisY]);
    qDebug() << "Delta: " << axes[Tc::Haptic::AxisX] << "," << axes[Tc::Haptic::AxisX];

    // 1. Converte p to the rotated coordinate system
    // Rotation around "z"-axis, all values in radian
    // => R = [[cos(yaw),-sin(yaw)][sin(yaw), cos(yaw)]]
    // => x' = p.x() * cos(yaw) - p.y() * sin(yaw)
    //    y' = p.x() * sin(yaw) + p.y() * cos(yaw)
    double yawRad = qDegreesToRadians(mHapticStartAxes[Tc::Haptic::AxisYaw]);
    QPointF pNew(p.x() * qCos(yawRad) + p.y() * qSin(yawRad), p.x() * -qSin(yawRad) + p.y() * qCos(yawRad));

    double targetX = qBound<double>(0.0, mStartPosition.x() + pNew.x() * IMAGE_WIDTH, IMAGE_WIDTH);
    double targetY = qBound<double>(0.0, mStartPosition.y() + pNew.y() * IMAGE_HEIGHT, IMAGE_HEIGHT);
    QPointF targetPosition(targetX, targetY);

    qDebug() << "New: " << pNew.x() << "," << pNew.y() << " (" << mHapticStartAxes[Tc::Haptic::AxisYaw] << ")";
    qDebug() << "Target: " << targetX << "," << targetY;

    //qDebug() << p << ";" << targetPosition;

    //setPosition(targetPosition);

    return force;

    // Create return value

    // Check if robot is in "bounds"
    /*QPointF currentPosition = QPointF(getPosition().x, getPosition().y);
    QRect workspace = QRect(50,50,500,300);

    if(currentPosition.x() < workspace.left()){
        // Robot left workspace on left hand side
        force[Tc::Haptic::AxisX] = abs(currentPosition.x()-workspace.left())*10.0;
    } else if(workspace.right() < currentPosition.x()){
        // Robot left workspace on right hand side
        force[Tc::Haptic::AxisX] = abs(currentPosition.x()-workspace.right())*-10.0;
    }

    if(currentPosition.y() < workspace.top()){
        // Robot left workspace on the top
        force[Tc::Haptic::AxisY] = abs(currentPosition.y()-workspace.top())*-10.0;
    } else if(workspace.bottom() < currentPosition.y()){
        // Robot left workspace on the bottom
        force[Tc::Haptic::AxisY] = abs(currentPosition.y()-workspace.bottom())*10.0;
    }*/


}
Пример #27
0
void Enemy::move_forward()
{
    QLineF ln(pos(),dest);
    if(ln.length() < 5){
     if(point_index<points.size()-1){
        point_index++;
        dest = points[point_index];
        rotateToPoint(dest);}
    }




    int STEP_SIZE = 5;
    double theta = rotation(); // degrees

    double dy = STEP_SIZE * qSin(qDegreesToRadians(theta));
    double dx = STEP_SIZE * qCos(qDegreesToRadians(theta));

     QList<QGraphicsItem *> colliding_items = collidingItems();

    for (int i = 0, n = colliding_items.size(); i < n; ++i){
         if (typeid(*(colliding_items[i])) == typeid(Bullet)){
            scene()->removeItem(colliding_items[i]);
            delete colliding_items[i];
            this->set_Health(game->getShootdmg());
            if(this->Health <= 0){
            scene()->removeItem(this);
            delete this;
            game->score->increase();
            game->hscore->increase();
            }
            return;
        }
        if (typeid(*(colliding_items[i])) == typeid(slowdart)){




            scene()->removeItem(colliding_items[i]);
            this->timer->start(60*game->getSlowtime());
            delete colliding_items[i];



            return;
        }
        if (typeid(*(colliding_items[i])) == typeid(Home)){


            if(game->health->getHealth()!=10){
            scene()->removeItem(this);
            delete this;
            game->health->decrease(10);}
            else{
                scene()->removeItem(this);
                delete this;
                game->health->decrease(10);
                delete (game);
                go = new gameover;
                go->show();


            }
            return;
        }

        if (typeid(*(colliding_items[i])) == typeid(triplearrow)){
            scene()->removeItem(colliding_items[i]);
            delete colliding_items[i];
            this->set_Health(game->getBluedmg());
            if(this->Health <= 0){
            scene()->removeItem(this);
            delete this;
            game->score->increase();
            game->hscore->increase();
            }




            return;
        }
    }
    setPos(x()+dx, y()+dy);
}
Пример #28
0
//void robotField::moveRobot(int x, int y)
//{
//    robot->moveBy(x,y);
//    // ѕеремещаем робота обновл¤ем координаты
//    calculateCenter();
//   // robot->setTransformOriginPoint(*robotCenter);
//    qDebug()<<robot->x()<<" "<<robot->y()<<"\n";
//    //qDebug()<<robotCenter->x()<<" "<<robotCenter->y()<<"\n";
//}
void robotField::moveRobot(int distance)
{
    robot->moveBy(qCos(degrees(robot->rotation()))*distance,qSin(degrees(robot->rotation())*distance));
    qDebug()<<robot->x()<<" "<<robot->y()<<"\n";
}
Пример #29
0
qreal soundFunc(qreal val)
{
    return 1.0 / (2.3) * (qSin(val) + qSin(2.0 * val) + 0.3*qCos(1.312*val));
}
Пример #30
0
void QQuickSvgParser::pathArc(QPainterPath &path,
                    qreal               rx,
                    qreal               ry,
                    qreal               x_axis_rotation,
                    int         large_arc_flag,
                    int         sweep_flag,
                    qreal               x,
                    qreal               y,
                    qreal curx, qreal cury)
{
    qreal sin_th, cos_th;
    qreal a00, a01, a10, a11;
    qreal x0, y0, x1, y1, xc, yc;
    qreal d, sfactor, sfactor_sq;
    qreal th0, th1, th_arc;
    int i, n_segs;
    qreal dx, dy, dx1, dy1, Pr1, Pr2, Px, Py, check;

    rx = qAbs(rx);
    ry = qAbs(ry);

    sin_th = qSin(x_axis_rotation * (Q_PI / 180.0));
    cos_th = qCos(x_axis_rotation * (Q_PI / 180.0));

    dx = (curx - x) / 2.0;
    dy = (cury - y) / 2.0;
    dx1 =  cos_th * dx + sin_th * dy;
    dy1 = -sin_th * dx + cos_th * dy;
    Pr1 = rx * rx;
    Pr2 = ry * ry;
    Px = dx1 * dx1;
    Py = dy1 * dy1;
    /* Spec : check if radii are large enough */
    check = Px / Pr1 + Py / Pr2;
    if (check > 1) {
        rx = rx * qSqrt(check);
        ry = ry * qSqrt(check);
    }

    a00 =  cos_th / rx;
    a01 =  sin_th / rx;
    a10 = -sin_th / ry;
    a11 =  cos_th / ry;
    x0 = a00 * curx + a01 * cury;
    y0 = a10 * curx + a11 * cury;
    x1 = a00 * x + a01 * y;
    y1 = a10 * x + a11 * y;
    /* (x0, y0) is current point in transformed coordinate space.
       (x1, y1) is new point in transformed coordinate space.

       The arc fits a unit-radius circle in this space.
    */
    d = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0);
    sfactor_sq = 1.0 / d - 0.25;
    if (sfactor_sq < 0) sfactor_sq = 0;
    sfactor = qSqrt(sfactor_sq);
    if (sweep_flag == large_arc_flag) sfactor = -sfactor;
    xc = 0.5 * (x0 + x1) - sfactor * (y1 - y0);
    yc = 0.5 * (y0 + y1) + sfactor * (x1 - x0);
    /* (xc, yc) is center of the circle. */

    th0 = qAtan2(y0 - yc, x0 - xc);
    th1 = qAtan2(y1 - yc, x1 - xc);

    th_arc = th1 - th0;
    if (th_arc < 0 && sweep_flag)
        th_arc += 2 * Q_PI;
    else if (th_arc > 0 && !sweep_flag)
        th_arc -= 2 * Q_PI;

    n_segs = qCeil(qAbs(th_arc / (Q_PI * 0.5 + 0.001)));

    for (i = 0; i < n_segs; i++) {
        pathArcSegment(path, xc, yc,
                       th0 + i * th_arc / n_segs,
                       th0 + (i + 1) * th_arc / n_segs,
                       rx, ry, x_axis_rotation);
    }
}