void PMBullet::move() { QList<QGraphicsItem *> colliding_enemies=collidingItems(); for(size_t i=0, n=colliding_enemies.size();i<n;i++){ if((typeid(*(colliding_enemies[i]))==typeid(Enemy))||typeid(*(colliding_enemies[i]))==typeid(AttackableEnemy)){ if(typeid(*(colliding_enemies[i]))==typeid(Enemy)){ dynamic_cast<Enemy*>(colliding_enemies[i])->IsSlowedBy(SlowPower); dynamic_cast<Enemy*>(colliding_enemies[i])->IsHitBy(AttackPower); } else if(typeid(*(colliding_enemies[i]))==typeid(AttackableEnemy)){ dynamic_cast<AttackableEnemy*>(colliding_enemies[i])->IsSlowedBy(SlowPower); dynamic_cast<AttackableEnemy*>(colliding_enemies[i])->IsHitBy(AttackPower); } playSound("Hit"); //sound for hit game->scene->removeItem(this); QTimer::singleShot(3000,this,SLOT(callDestructor())); return; } } double theta = rotation(); //set theta double dy = STEP_SIZE*qSin(qDegreesToRadians(theta)); double dx = STEP_SIZE*qCos(qDegreesToRadians(theta)); setPos(x()+dx,y()+dy); }
/*! \since 5.5 Creates a quaternion that corresponds to a rotation of \a roll degrees around the z axis, \a pitch degrees around the x axis, and \a yaw degrees around the y axis (in that order). \sa getEulerAngles() */ QQuaternion QQuaternion::fromEulerAngles(float pitch, float yaw, float roll) { // Algorithm from: // http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q60 pitch = qDegreesToRadians(pitch); yaw = qDegreesToRadians(yaw); roll = qDegreesToRadians(roll); pitch *= 0.5f; yaw *= 0.5f; roll *= 0.5f; const float c1 = std::cos(yaw); const float s1 = std::sin(yaw); const float c2 = std::cos(roll); const float s2 = std::sin(roll); const float c3 = std::cos(pitch); const float s3 = std::sin(pitch); const float c1c2 = c1 * c2; const float s1s2 = s1 * s2; const float w = c1c2 * c3 + s1s2 * s3; const float x = c1c2 * s3 + s1s2 * c3; const float y = s1 * c2 * c3 - c1 * s2 * s3; const float z = c1 * s2 * c3 - s1 * c2 * s3; return QQuaternion(w, x, y, z); }
//=================================================================== void Camera::updatePosition() { // position the viewing the scene if (mPhi >= 89.9) mPhi = 89.9; if (mPhi <= -89.9) mPhi = -89.9; double rtheta = qDegreesToRadians(mTheta); double rphi = qDegreesToRadians(mPhi); double x = mR * qSin(rtheta) * qCos(rphi); double z = mR * qCos(rtheta) * qCos(rphi); double y = mR * qSin(rphi); mPos.setX(x); mPos.setZ(z); mPos.setY(y); mTarget.setX(-x + mDeltaX); mTarget.setY(-y + mDeltaY); mTarget.setZ(-z); mTarget.normalize(); }
void WordContainer::move() { //moves WC every tick of timer by defined step and calculated angle int stepSize = 15; double alpha = angleToMove;//rotation(); //converting to degrees, angle has to be a double double dy = stepSize * qSin(qDegreesToRadians(alpha)); double dx = stepSize * qCos(qDegreesToRadians(alpha)); QGraphicsItem::setPos(this->x()+dx,this->y()+dy); //check if stopp move of WC checkIfStopMovement(); }
static QMatrix4x4 CreateMatrix(PositionDesc & desc) { QMatrix4x4 cameraMatrix; cameraMatrix.setToIdentity(); QVector3D position(desc._xPos, desc._yPos, desc._zPos); cameraMatrix.rotate(desc._azimuth, 0, 0, 1); QVector3D vec(0, 0, 1); QVector3D vec2(cos(qDegreesToRadians(desc._azimuth)), sin(qDegreesToRadians(desc._azimuth)), 0); QVector3D axis = QVector3D::crossProduct(vec, vec2); cameraMatrix.rotate(desc._elevation, axis); cameraMatrix.translate(position); return cameraMatrix; }
void ebullet::move() { QList<QGraphicsItem *> colliding_items = collidingItems(); // if one of the colliding items is an Enemy, destroy both the bullet and the enemy for (int jjj = 0, n = colliding_items.size(); jjj < n; ++jjj){ if (typeid(*(colliding_items[jjj])) == typeid(player)){ pl->dechp(40);///////////////////////////////// scene()->removeItem(this); //free(this); delete this; return; } } if((pos().x()>scene()->sceneRect().width() )||(pos().y()>scene()->sceneRect().height()) ){ scene()->removeItem(this); // free(this); delete this; qDebug()<<"DELETED"; return; } int STEP_SIZE = 15; double theta = rotation(); // degrees double dy = STEP_SIZE * qSin(qDegreesToRadians(theta)); double dx = STEP_SIZE * qCos(qDegreesToRadians(theta)); setPos(x()+dx, y()+dy); }
void Simulation::startMovingGripperNegativeV() { xChanger.setValue(gripper_.xOffset()); yChanger.setValue(gripper_.yOffset()); // Calculate X and Y components // Positive V is 90ยบ counterclockwise of the fingertip 2 direction const double xPart = MOVE_RATE * std::cos(gripper_.angle() + qDegreesToRadians(270.0)); const double yPart = -MOVE_RATE * std::sin(gripper_.angle() + qDegreesToRadians(270.0)); xChanger.setRate(xPart); yChanger.setRate(yPart); xChanger.start(); yChanger.start(); }
static bool parseCylinder(const char* cylinderDef, float* cylinder) { bool ok = std::sscanf( cylinderDef, "%f,%f,%f,%f,%f,%f,%f,%f,%f,%f", cylinder + 0, cylinder + 1, cylinder + 2, cylinder + 3, cylinder + 4, cylinder + 5, cylinder + 6, cylinder + 7, cylinder + 8, cylinder + 9) == 10; if (ok) { cylinder[7] = qDegreesToRadians(cylinder[7]); cylinder[8] = qDegreesToRadians(cylinder[8]); cylinder[9] = qDegreesToRadians(cylinder[9]); } return ok; }
void EnemyEntity::shoot(int speed, e_ptr target, float deg) { float xDiff = target->getX() - x; float yDiff = target->getY() - (y +( sprite->getHeight()/2)); float rads = atan2f(xDiff,yDiff); int gunX = getX(); int gunY = getY() + (sprite->getHeight()/2); e_ptr shot(new EnemyShotEntity(game, gunX, gunY, polarity)); shot->setHorizontalMovement(speed * sin(rads + qDegreesToRadians(deg))); shot->setVerticalMovement(speed * cos(rads + qDegreesToRadians(deg))); game->getEntities().push_back(shot); }
//=================================================================== void AnnulusMesh::makeMesh() { // calculates the vertices of the mesh PolygonMesh polOu(mRou, mSeg, this); PolygonMesh polIn(mRin, mSeg, this); float angStep = qDegreesToRadians(360. / mSeg); float ang = 0.0; int index = 0; for (int count = 0; count < polOu.verticesCount() / 3; count++) { addVertex(polOu.vertices().at(index)); addVertex(polOu.vertices().at(index+1)); polIn.vertex(index).setU(0.5 + mRin/mRou * 0.5 * qCos(ang)); polIn.vertex(index).setV(0.5 + mRin/mRou * 0.5 * qSin(ang)); addVertex(polIn.vertices().at(index)); addVertex(polOu.vertices().at(index+1)); polIn.vertex(index+1).setU(0.5 + mRin/mRou * 0.5 * qCos(ang + angStep)); polIn.vertex(index+1).setV(0.5 + mRin/mRou * 0.5 * qSin(ang + angStep)); addVertex(polIn.vertices().at(index+1)); addVertex(polIn.vertices().at(index)); index +=3; ang += angStep; } computeNormal(); }
Object* OgrFileImport::importPointGeometry(MapPart* map_part, OGRFeatureH feature, OGRGeometryH geometry) { auto style = OGR_F_GetStyleString(feature); auto symbol = getSymbol(Symbol::Point, style); if (symbol->getType() == Symbol::Point) { auto object = new PointObject(symbol); object->setPosition(toMapCoord(OGR_G_GetX(geometry, 0), OGR_G_GetY(geometry, 0))); map_part->addObject(object); return object; } else if (symbol->getType() == Symbol::Text) { const auto& description = symbol->getDescription(); auto length = description.length(); auto split = description.indexOf(QLatin1Char(' ')); Q_ASSERT(split > 0); Q_ASSERT(split < length); auto label = description.right(length - split - 1); if (label.startsWith('{') && label.endsWith('}')) { label.remove(0,1); label.chop(1); int index = OGR_F_GetFieldIndex(feature, label.toLatin1()); if (index >= 0) { label = QString(OGR_F_GetFieldAsString(feature, index)); } } if (!label.isEmpty()) { auto object = new TextObject(symbol); object->setAnchorPosition(toMapCoord(OGR_G_GetX(geometry, 0), OGR_G_GetY(geometry, 0))); // DXF observation label.replace(QRegularExpression("(\\\\[^;]*;)*", QRegularExpression::MultilineOption), QString::null); label.replace(QLatin1String("^I"), "\t"); object->setText(label); bool ok; auto anchor = QStringRef(&description, 1, 2).toInt(&ok); if (ok) { applyLabelAnchor(anchor, object); } auto angle = QStringRef(&description, 3, split-3).toFloat(&ok); if (ok) { object->setRotation(qDegreesToRadians(angle)); } map_part->addObject(object); return object; } } return nullptr; }
b2Shape *RectangleFixture::getShape() { b2PolygonShape* shape = new b2PolygonShape(); shape->SetAsBox(m_width / (m_world->getPixelsPerMeter() * 2.0), m_height / (m_world->getPixelsPerMeter() * 2.0), b2Vec2(0, 0), qDegreesToRadians(m_angle)); return shape; }
void Animation::transformCamera(float dx, float dy) { bool a = timer.isActive(); if (a) timer.stop(); weak_ptr<Camera> camera = animationScene->camera(); if (camera.expired()) return; shared_ptr<Camera> activeCamera = camera.lock(); activeCamera->transform(MatrixRotateY(qDegreesToRadians(-dx/2)).create()); activeCamera->transform(MatrixRotateX(qDegreesToRadians(dy/2)).create()); animationScene->renderModels(); if (a) timer.start(); }
void ControllerTrackedComponent::receiveEntityRotation(IModelTrackedTrajectory * trajectory, double angle, uint frameNumber) { TrackedTrajectory* traj = dynamic_cast<TrackedTrajectory*>(trajectory); if (traj) { IModelTrackedPoint* pointLike = dynamic_cast<IModelTrackedPoint*>(traj->getChild(frameNumber)); if (pointLike) { pointLike->setDeg(float(angle)); pointLike->setRad(float(qDegreesToRadians(angle))); } } }
void BurstShot::steerShot(double delta) { if(angleDistance > 0){ angle = angle + (rotatesSpeed * delta) > angleDistance + angle ? targetAngle : angle + (rotatesSpeed * delta); }else{ angle = angle - (rotatesSpeed * delta) < angleDistance + angle ? targetAngle : angle - (rotatesSpeed * delta); } // angle = angleDistance > 0? angle + (rotatesSpeed * delta) : // angle - (rotatesSpeed * delta); setHorizontalMovement(qSin(qDegreesToRadians(angle)) * shotSpeed); setVerticalMovement(qCos(qDegreesToRadians(angle)) * shotSpeed); // rotatesSpeed += 90*delta; shotSpeed += 2000*delta; }
void LineOfSightGraphics::computeXPoints() { qreal quarterOfPi = qDegreesToRadians(45.0f); // Compute the coordinates of the two X points X1.setY(-length * qCos(quarterOfPi)); X1.setX(-length * qSin(quarterOfPi)); X2.setX(length * qCos(quarterOfPi) + O2.x()); X2.setY(length * qCos(quarterOfPi) + O2.y()); radius = qSqrt((baseWidth * baseWidth / 2)) + length; }
/*! Creates a normalized quaternion that corresponds to rotating through \a angle degrees about the specified 3D \a axis. \sa getAxisAndAngle() */ QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D& axis, float 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. float a = qDegreesToRadians(angle / 2.0f); float s = std::sin(a); float c = std::cos(a); QVector3D ax = axis.normalized(); return QQuaternion(c, ax.x() * s, ax.y() * s, ax.z() * s).normalized(); }
void Bullet_enemy::move() { QList<QGraphicsItem *> colliding_tower=this->collidingItems(); //bullet collides, get colliding item lists for(size_t i=0, n=colliding_tower.size();i<n;i++){ Tower* tower=dynamic_cast<Tower *>(colliding_tower[i]); //only tower item can be casted if(tower){ //if colliding item is tower tower->IsHitBy(AttackPower*2); //hit the tower Activated(0); //stop to move game->scene->removeItem(this); delete image; delete this; return; } } double theta = rotation(); //set theta double dy = STEP*qSin(qDegreesToRadians(theta)); //set x_step size, y_step size double dx = STEP*qCos(qDegreesToRadians(theta)); setPos(x()+dx,y()+dy); //move }
/*! Creates a normalized quaternion that corresponds to rotating through \a angle degrees about the 3D axis (\a x, \a y, \a z). \sa getAxisAndAngle() */ QQuaternion QQuaternion::fromAxisAndAngle (float x, float y, float z, float angle) { float length = std::sqrt(x * x + y * y + z * z); if (!qFuzzyIsNull(length - 1.0f) && !qFuzzyIsNull(length)) { x /= length; y /= length; z /= length; } float a = qDegreesToRadians(angle / 2.0f); float s = std::sin(a); float c = std::cos(a); return QQuaternion(c, x * s, y * s, z * s).normalized(); }
void enemy::move_forward(){ // if close to dest, rotate to next dest QLineF ln(pos(),destination); if (ln.length() < 5){ point_index++; if (point_index>=points.size()){ qDebug()<<"Damn bukiki, back at it again with the barakis!"; return; } destination = points[point_index]; rotateToPoint(destination); } // move enemy forward at current angle 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); }
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; } } }
void ray_options::set_angle(qreal deg) { ui->angle_dial->blockSignals(true); ui->angle_spinbox->blockSignals(true); ui->angle_dial->setValue( (((int) deg) + 90) % 360 ); ui->angle_spinbox->setValue(deg); ui->angle_dial->blockSignals(false); ui->angle_spinbox->blockSignals(false); r->set_direction(qDegreesToRadians(deg)); backgroung->recalc_ray_num(r_num); backgroung->update(); }
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; } } }
static inline bool myFuzzyCompareRadians(float p1, float p2) { static const float fPI = float(M_PI); if (p1 < -fPI) p1 += 2.0f * fPI; else if (p1 > fPI) p1 -= 2.0f * fPI; if (p2 < -fPI) p2 += 2.0f * fPI; else if (p2 > fPI) p2 -= 2.0f * fPI; return qAbs(qAbs(p1) - qAbs(p2)) <= qDegreesToRadians(0.05f); }
void Body::updateBeforePhysics() { if (!isActive()) { return; } if (mFixturesDirty) { createFixtures(); mFixturesDirty = false; mTransformDirty = true; } if (mTransformDirty) { Actor* actor = getActor(); if (actor) { QPointF pos = actor->position(); mBody->SetTransform(b2Vec2(pos.x(), pos.y()), qDegreesToRadians(actor->rotation())); } mTransformDirty = false; } }
void Arc::init() { // Calculates startangle and spanangle lineBC = QLineF(p2, p3); lineAC = QLineF(p1, p3); lineBA = QLineF(p2, p1); rad = qAbs(lineBC.length()/(2 * qSin(qDegreesToRadians (lineAC.angleTo(lineBA))))); bisectorBC = QLineF(lineBC.pointAt(0.5), lineBC.p2()); bisectorBC.setAngle(lineBC.normalVector().angle()); bisectorBA = QLineF(lineBA.pointAt(0.5), lineBA.p2()); bisectorBA.setAngle(lineBA.normalVector().angle()); bisectorBA.intersect(bisectorBC, ¢er); circle = QRectF(center.x() - rad, center.y() - rad, rad * 2, rad * 2); lineOA = QLineF(center, p1); lineOB = QLineF(center, p2); lineOC = QLineF(center, p3); startAngle = lineOA.angle(); spanAngle = lineOA.angleTo(lineOC); /** * Make sure that the span angle covers all three points with the * second point in the middle */ if (qAbs(spanAngle) < qAbs(lineOA.angleTo(lineOB)) || qAbs(spanAngle) < qAbs(lineOB.angleTo(lineOC))) { // swap the end point and invert the spanAngle startAngle = lineOC.angle(); spanAngle = 360 - spanAngle; } int w = 10; boundingRectTemp = circle.adjusted(-w, -w, w, w); }
void QQuickShapeConicalGradientShader::updateState(const RenderState &state, QSGMaterial *mat, QSGMaterial *) { QQuickShapeConicalGradientMaterial *m = static_cast<QQuickShapeConicalGradientMaterial *>(mat); if (state.isOpacityDirty()) program()->setUniformValue(m_opacityLoc, state.opacity()); if (state.isMatrixDirty()) program()->setUniformValue(m_matrixLoc, state.combinedMatrix()); QQuickShapeGenericStrokeFillNode *node = m->node(); const QPointF centerPoint = node->m_fillGradient.a; const GLfloat angle = -qDegreesToRadians(node->m_fillGradient.v0); program()->setUniformValue(m_angleLoc, angle); program()->setUniformValue(m_translationPointLoc, centerPoint); const QQuickShapeGradientCache::Key cacheKey(node->m_fillGradient.stops, QQuickShapeGradient::RepeatSpread); QSGTexture *tx = QQuickShapeGradientCache::currentCache()->get(cacheKey); tx->bind(); }
void WTFWidget::drawInnerArrow(QPainter& painter) { if(_innerPercent == 0) return; QRect rect = this->contentsRect(); QPoint center = rect.center(); painter.save(); painter.translate(center); painter.rotate(90 * _innerPercent); QColor arrowColor = QColor::fromRgb(0xff,0xff,0xff,0xff * _innerPercent); QPen pen = QPen(arrowColor); pen.setWidth(2); painter.setPen(pen); int left = - CIRCLE_INNER_RADIUS; int top = - CIRCLE_INNER_RADIUS; QRect arcRect = QRect(left,top,CIRCLE_INNER_RADIUS * 2, CIRCLE_INNER_RADIUS * 2); painter.drawArc(arcRect,90 * 16,270 * 16); // start draw arrow qreal arrowBorderLen = 8; QPainterPath path; QPoint topPoint(0, - CIRCLE_INNER_RADIUS - arrowBorderLen/2); path.moveTo(topPoint); qreal distance = (arrowBorderLen / 2) / qTan(qDegreesToRadians((double)30)); QPoint rightPoint(distance,-CIRCLE_INNER_RADIUS); path.lineTo(rightPoint); QPoint bottomPoint(0, - CIRCLE_INNER_RADIUS + arrowBorderLen/2); path.lineTo(bottomPoint); path.closeSubpath(); painter.fillPath(path,QBrush(arrowColor)); painter.translate(-center.x(),-center.y()); painter.restore(); }
GeometryData* flatArrow(float length, float width, float headProportion, const QColor &col, bool nullNormals) { GeometryData* geom = new GeometryData(); geom->setDrawMode(GL_TRIANGLES); geom->setShaderOverride(PerVertexColorShader::staticName()); geom->setDataFormat(GeometryData::PositionNormalColor); // Get the first side. GeometryData* side1 = singleFlatArrow(length, width, headProportion, col, nullNormals); geom->append(*side1); // If we have null normals, we can just create double-sided triangles. if ( nullNormals ) { geom->appendIndexTriangle(0,1,2,true); geom->appendIndexTriangle(0,2,3,true); geom->appendIndexTriangle(4,5,6,true); } // Otherwise we need a new side. else { side1->transform(Math::matrixRotateX(qDegreesToRadians(180.0f))); geom->append(*side1); for ( int i = 0; i < 2; i++ ) { int b = i*7; geom->appendIndexTriangle(b+0,b+1,b+2); geom->appendIndexTriangle(b+0,b+2,b+3); geom->appendIndexTriangle(b+4,b+5,b+6); } } delete side1; return geom; }
RTRMatrix33 RTRGeometry::inverseRotationMatrix(double angleX, double angleY, double angleZ) { RTRMatrix33 rotateX, rotateY, rotateZ; rotateX.fill(0); rotateX(0, 0) = 1; rotateX(2, 2) = rotateX(1, 1) = qCos(qDegreesToRadians(-angleX)); rotateX(1, 2) = qSin(qDegreesToRadians(-angleX)); rotateX(2, 1) = -rotateX(1, 2); rotateY.fill(0); rotateY(1, 1) = 1; rotateY(0, 0) = rotateY(2, 2) = qCos(qDegreesToRadians(-angleY)); rotateY(2, 0) = qSin(qDegreesToRadians(-angleY)); rotateY(0, 2) = -rotateY(2, 0); rotateZ.fill(0); rotateZ(2, 2) = 1; rotateZ(0, 0) = rotateZ(1, 1) = qCos(qDegreesToRadians(-angleZ)); rotateZ(0, 1) = qSin(qDegreesToRadians(-angleZ)); rotateZ(1, 0) = -rotateZ(0, 1); return rotateZ*rotateY*rotateX; }