Exemplo n.º 1
0
//-------------------------------------------------------------
void ConeGeometry::init(DolfinGui *ui)
{
    setPointCount(6);
    setRadiusCount(2);
    setCreated(false);
    setGuiWindow(ui);
    setPoints(new double[getPointCount()]);
    setPoints(new double[getRadiusCount()]);
    setMyType("Cone");
}
Exemplo n.º 2
0
sk_sp<sksg::GeometryNode> AttachPolystarGeometry(const Json::Value& jstar, AttachContext* ctx) {
    SkASSERT(jstar.isObject());

    static constexpr PolyStarAdapter::Type gTypes[] = {
        PolyStarAdapter::Type::kStar, // "sy": 1
        PolyStarAdapter::Type::kPoly, // "sy": 2
    };

    const auto type = ParseDefault(jstar["sy"], 0) - 1;
    if (type < 0 || type >= SkTo<int>(SK_ARRAY_COUNT(gTypes))) {
        LogFail(jstar, "Unknown polystar type");
        return nullptr;
    }

    auto path_node = sksg::Path::Make();
    auto adapter = sk_make_sp<PolyStarAdapter>(path_node, gTypes[type]);

    BindProperty<VectorValue>(jstar["p"], &ctx->fAnimators,
        [adapter](const VectorValue& p) {
            adapter->setPosition(ValueTraits<VectorValue>::As<SkPoint>(p));
        });
    BindProperty<ScalarValue>(jstar["pt"], &ctx->fAnimators,
        [adapter](const ScalarValue& pt) {
            adapter->setPointCount(pt);
        });
    BindProperty<ScalarValue>(jstar["ir"], &ctx->fAnimators,
        [adapter](const ScalarValue& ir) {
            adapter->setInnerRadius(ir);
        });
    BindProperty<ScalarValue>(jstar["or"], &ctx->fAnimators,
        [adapter](const ScalarValue& otr) {
            adapter->setOuterRadius(otr);
        });
    BindProperty<ScalarValue>(jstar["is"], &ctx->fAnimators,
        [adapter](const ScalarValue& is) {
            adapter->setInnerRoundness(is);
        });
    BindProperty<ScalarValue>(jstar["os"], &ctx->fAnimators,
        [adapter](const ScalarValue& os) {
            adapter->setOuterRoundness(os);
        });
    BindProperty<ScalarValue>(jstar["r"], &ctx->fAnimators,
        [adapter](const ScalarValue& r) {
            adapter->setRotation(r);
        });

    return path_node;
}
Exemplo n.º 3
0
    Block()
    {
        setPointCount(point_number);
        setFillColor(sf::Color(200, 100, 100));
        setOutlineColor(sf::Color(255, 100, 100));
        setOutlineThickness(2.f);

        setPoint(0, sf::Vector2f(0, 0));
        setPoint(1, sf::Vector2f(length1, 0));
        setPoint(2, sf::Vector2f(length1 + offset_length, offset_depth));
        setPoint(3, sf::Vector2f(length1 + offset_length + length2, offset_depth));
        setPoint(4, sf::Vector2f(length1 + offset_length * 2 + length2, 0));
        setPoint(5, sf::Vector2f(min_width, 0));

        for(std::size_t i = 0; i < 6; ++i)
            setPoint(11 - i, getPoint(i) + sf::Vector2f(0, min_height));
    }
Exemplo n.º 4
0
kaleidogon::kaleidogon() {

	const int TEXTURE_WIDTH = 1024;
	const int TEXTURE_HEIGHT = 1024;

	// constants for determining random rotation speed
	const int MAX_MULTIPLIER = 600;
	const int MIN_MULTIPLIER = 200;
	const int DIVISOR = 100000;

	setPointCount(NUMBER_OF_VERTICES);

	// make the radius a random number up to 1/8 of the screen width
	srand (time(NULL));
	int screenWidth = sf::VideoMode::getDesktopMode().width;
	int newRadius = (rand() % (screenWidth / 8)) + 1;
	setRadius(newRadius);

	setOrigin(newRadius, newRadius);

	// make the rotation speed a random percent of the clock speed
	int randomMultiplier = (rand() % (MAX_MULTIPLIER - MIN_MULTIPLIER + 1)) + MIN_MULTIPLIER;
	rotationAmount = CLOCKS_PER_SEC * randomMultiplier / DIVISOR;

	// 50% chance of reversing the rotation direction
	if (rand() % 2 == 0) {
		rotationAmount *= -1;
	}

	// get random coordinates of the texture
	int randomx = rand() % (TEXTURE_WIDTH - newRadius + 1);
	int randomy = rand() % (TEXTURE_HEIGHT - newRadius + 1);

	// set the texture with these coordinates
	sf::IntRect texturePart(randomx, randomy, newRadius, newRadius);
	texture.loadFromFile("texture.jpg", texturePart);
	ptTexture = &texture;
	setTexture(ptTexture);
}
Exemplo n.º 5
0
ConvexShape::ConvexShape(unsigned int pointCount)
{
    setPointCount(pointCount);
}
Exemplo n.º 6
0
ConvexShape::ConvexShape(std::size_t pointCount)
{
    setPointCount(pointCount);
}
Exemplo n.º 7
0
NBoxComponent::NBoxComponent()
{
    setPointCount(4);
}
Exemplo n.º 8
0
void sfCircleShape_setPointCount(sfCircleShape* shape, unsigned int count)
{
    CSFML_CALL(shape, setPointCount(count));
}
Exemplo n.º 9
0
bool TimeSeriesMotion::load(const QString &fileName, bool defaults, double scale)
{
    m_accel.clear();

    setFileName(fileName);
    const QString ext = m_fileName.right(3).toUpper();

    // Load the file
    QFile file(m_fileName);
    if (!file.open( QIODevice::ReadOnly | QIODevice::Text )) {
        qWarning() << "Unable to open the time series file:" << qPrintable(m_fileName);
        return false;
    }
    QTextStream stream(&file);

    if (defaults) {
        if (ext == "AT2") {
            // Set format
            setFormat(Rows);
            setStartLine(5);
            setStopLine(0);
            setScale(scale);

            // Read in the header information
            Q_UNUSED(stream.readLine());

            setDescription(stream.readLine());

            Q_UNUSED(stream.readLine());

            QStringList parts = stream.readLine().split(QRegExp("\\s+"));

            bool b;
            const int count = parts.at(0).toInt(&b);
            if (b && count > 1) {
                // Greater than one condition to catch if an acceleration value is read
                setPointCount(count);
            } else {
                qCritical() << "Unable to parse the point count in AT2 file!";
                return false;
            }

            const double timeStep = parts.at(1).toDouble(&b);

            if (b) {
                setTimeStep(timeStep);
            } else {
                qCritical() << "Unable to parse the time step in AT2 file!";
                return false;
            }
        } else {
            // Unknown file format can't process with default settings
            return false;
        }
    } else {
        // Check the input
        if (m_timeStep <= 0) {
            qCritical("Time step must be greater than one");
            return false;
        }
        if (m_startLine < 0) {
            qCritical("Number of header lines must be positive");
            return false;
        }
    }

    // Move back to the start of the stream
    stream.seek(0);

    int lineNum = 1;
    // Skip the header lines
    while (lineNum < m_startLine) {
        Q_UNUSED(stream.readLine());
        ++lineNum;
    }

    // Initialize the length of m_accel
    m_accel.resize(m_pointCount);

    // Process each of the lines
    int index = 0;
    // Read the first line
    QString line =stream.readLine();

    bool finished = false;
    bool stopLineReached = false;

    // Modify the scale for unit conversion
    scale = unitConversionFactor() * m_scale;

    while (!finished && !line.isNull()) {
        // Stop if line exceeds number of lines.  The line number has
        // to be increased by one because the user display starts at
        // line number 1 instead of 0
        if (m_stopLine > 0 &&  m_stopLine <= lineNum+1) {
            stopLineReached = true;
            break;
        }

        // Read the line and split the line
        QRegExp rx("(-?\\d*\\.\\d+(?:[eE][+-]?\\d+)?)");
        int pos = 0;
        QStringList row;

        while ((pos = rx.indexIn(line, pos)) != -1) {
            row << rx.cap(1);
            pos += rx.matchedLength();
        }

        // Process the row based on the format
        bool ok;
        switch (m_format) {
        case Rows:
            // Use all parts of the data
            for(int i = 0; i < row.size(); ++i) {
                if ( index == m_pointCount ) {
                    qWarning("Point count reached before end of data!");
                    finished = true;
                    break;
                }
                // Apply the scale factor and read the acceleration
                m_accel[index] = scale * row.at(i).trimmed().toDouble(&ok);
                // Increment the index
                ++index;
                // Stop if there was an error in the conversion
                if (!ok) {
                    continue;
                }
            }
            break;
                case Columns:
            // Use only the important column, however at the end of the
            // file that column may not exist -- this only happens when the
            // row format is applied, but it still causes the program to
            // crash.
            if ( m_dataColumn - 1 < row.size() ) {
                m_accel[index] = scale * row.at(m_dataColumn-1).trimmed().toDouble(&ok);
            }

            // Increment the index
            ++index;
            break;
        }

        // Throw an error if there was a problem
        if (!ok) {
            qCritical() << "Error converting string to double in line: \n\""
                    << qPrintable(line) << "\"\nCheck starting line.";
            return false;
        }

        // Read the next line
        ++lineNum;
        line = stream.readLine();
    }

    if (m_pointCount != index) {
        if (stopLineReached) {
            qWarning() << "Number of points limited by stop line.";
        } else {
            qCritical() << "Number of points read does not equal specified point count!";
            return false;
        }
    }

    // Compute motion properties
    calculate();

    setIsLoaded(true);
    return true;
}