Beispiel #1
0
void HexMap::generateMountainRange(mt19937& urng)
{
	static sf::Color mt(128, 88, 44);
	static vector<VectorSet> splat = { { { 1, -1 }, { 2, -1 }, { 0, 0 }, { 1, 0 }, { -1, 1 }, { 0, 1 }, { -2, 2 }, { -1, 2 }, { 0, 2 } },
	{ { 1, -2 }, { 0, -1 }, { 1, -1 }, { -1, 0 }, { 0, 0 }, { 1, 0 }, { -1, 1 }, { 0, 1 }, { -1, 2 }, { 0, 2 } },
	{ { 0, -1 }, { 1, -1 }, { -1, 0 }, { 0, 0 }, { 1, 0 }, { -1, 1 }, { 0, 1 } },
	{ { 0, -1 }, { 1, -1 }, { 2, -1 }, { -1, 0 }, { 0, 0 }, { 1, 0 }, { -1, 1 }, { 0, 1 }, { 1, 1 } },
	{ { 0, -2 }, { 1, -2 }, { -1, -1 }, { 0, -1 }, { 1, -1 }, { -1, 0 }, { 0, 0 }, { 1, 0 }, { -1, 1 } },
	{ { -1, -1 }, { 0, -1 }, { -1, 0 }, { 0, 0 }, { 1, 0 }, { -2, 1 }, { -1, 1 }, { 0, 1 } },
	{ { -1, 0 }, { 1, 0 }, { 0, 0 }, { -2, 1 }, { -1, 1 }, { 0, 1 }, { 1, 1 }, { -2, 2 }, { -1, 2 }, { 0, 2 } },
	{ { 0, -2 }, { 1, -2 }, { 0, -1 }, { 1, -1 }, { 2, -1 }, { -1, 0 }, { 0, 0 }, { 1, 0 }, { 0, 1 } } };
	sf::VertexArray va;
	static sf::Vector2f w[4];
	sf::Vector2f offset = { (float)rng::getInt(2, 85, urng), (float)rng::getInt(2, 85, urng) };
	for (int a = 0; a < 100; a++) {
		w[0] = { (float)xRange(urng), (float)yRange(urng) };
		if (isAxialInBounds((sf::Vector2i)w[0]) && getAxial((int)w[0].x, (int)w[0].y).hts->FLAGS[HexTileS::WALKABLE]) {
			break;
		}
	}
	w[3] = { (float)rng::radians(urng), (float)rng::getInt(10, 40, urng) };
	polarToCartesian(w[3]);
	w[3] = roundvf(w[0] + w[3]);
	sf::Vector2f avg = { (w[3] + w[0]) / 2.0f };
	// sqrt(a^2 + b^2)
	int dist = (int)sqrtf(powf(abs(w[3].x - w[0].x), 2.0f) + powf(abs(w[3].x - w[0].x), 2.0f));
	for (int a = 1; a < 3; a++) {
		// Distance between the middle points and the endpoint average cannot be greater
		// than the distance between the endpoints, to prevent any super-sharp curves
		w[a] = { (float)rng::radians(urng), (float)rng::getInt(10, clamp(dist, 10, 40), urng) };
		polarToCartesian(w[a]);
		w[a] = roundvf(w[a] + avg);
	}
	float advance = 1.0f / Bezier::lengthCubic(w);
	VectorSet h;
	sf::Vector2f p;
	for (float f = 0.0f; f < 1.0f; f += advance) {
		Bezier::curveCubic(p, f, w);
		if (!isAxialInBounds((sf::Vector2i)p) || !getAxial((int)p.x, (int)p.y).hts->FLAGS[HexTileS::WALKABLE]) {
			break;
		}
		VectorSet& s = splat[rng::getInt(0, splat.size() - 1, urng)];
		for (auto r : s) {
			h.insert((sf::Vector2i)axialToOffset(roundHex((sf::Vector2f)r + p)));
		}
		p = { 0.0f, 0.0f };
	}
	HexTile* cTile = nullptr;
	for (auto& l : h) {
		cTile = &getOffset(l.x, l.y);
		if (!isOffsetInBounds((sf::Vector2i)l) || !cTile->hts->FLAGS[HexTileS::WALKABLE]) {
			continue;
		}
		//pushTileColor((sf::Vector2i)l, sf::Color::White);
		setTileFeature((sf::Vector2i)l, TileFeatureS::get(TileFeatureS::MOUNTAIN), urng);
		cTile->FLAGS[HexTile::MOUNTAINS] = true;
	}
}
void GLWidget::setLookAtPosition(float x, float y, float z) {
    lookAtPosition_.setX(x);
    lookAtPosition_.setY(y);
    lookAtPosition_.setZ(z);

    polarToCartesian();
}
void GLWidget::setCameraRotation(float x, float y, float z) {
    rotation_.setX(x);
    rotation_.setY(y);
    rotation_.setZ(z);

    polarToCartesian();
}
Beispiel #4
0
features3D::features3D(int id, float range, float bearing, bool exists)
{
	m_id = id;
	m_range = range;
	m_bearing = bearing;
	m_exists = exists;
	polarToCartesian();
}
void GLWidget::wheelEvent(QWheelEvent *event) {
    int degrees = event->delta()/8;
    float radiusDelta = degrees/30.0*zoomDelta_;

    rotation_.setZ(rotation_.z()-radiusDelta);
    if( rotation_.z() <= 0 ) rotation_.setZ(0.0001);

    polarToCartesian();

    updateGL();
}
GLWidget::GLWidget(QWidget *parent) :
    QGLWidget(QGLFormat(QGL::DoubleBuffer),parent) {
    rotation_.setX(90);
    rotation_.setY(180);
    rotation_.setZ(100);

    lookAtPosition_.setX(0);
    lookAtPosition_.setY(0);
    lookAtPosition_.setZ(0);

    zoomDelta_ = 30;
    polarToCartesian();

    drawableObject_ = NULL;
}
void GLWidget::mouseMoveEvent(QMouseEvent *event) {
    int dx = event->x() - lastMousePosition_.x();
    int dy = event->y() - lastMousePosition_.y();

    if (event->buttons() & Qt::LeftButton) {

        rotation_.setX(rotation_.x()-180.0*dy/width());
        rotation_.setY(rotation_.y()+180.0*dx/width());

        if( rotation_.x() >= 180.0 ) rotation_.setX(179.999);
        if( rotation_.x() <= 0 ) rotation_.setX(0.001);

        polarToCartesian();

        updateGL();
    }

    lastMousePosition_ = event->pos();
}
Beispiel #8
0
    void processBlock (AudioSampleBuffer& buffer, MidiBuffer&) override
    {
        // copy the input into a scratch buffer
        AudioSampleBuffer scratch (scratchBuffer.getArrayOfWritePointers(), 1, buffer.getNumSamples());
        scratch.copyFrom(0, 0, buffer, 0, 0, buffer.getNumSamples());

        const Array<SpeakerPosition>& positions = speakerPositions.getReference (currentSpeakerLayout).positions;
        const float* inputBuffer  = scratch.getReadPointer (0);
        const float kMaxDistanceGain = -20.0f;

        for (int speakerIdx = 0; speakerIdx < positions.size(); ++speakerIdx)
        {
            const SpeakerPosition& speakerPos = positions.getReference (speakerIdx);
            float fltDistance = distance (polarToCartesian (speakerPos.radius, speakerPos.phi), polarToCartesian (*radius, (*phi) * 2.0f * float_Pi));
            float gainInDb = kMaxDistanceGain * (fltDistance / 2.0f);
            float gain = std::pow (10.0f, (gainInDb / 20.0f));

            busArrangement.getBusBuffer(buffer, false, 0).copyFrom(speakerIdx, 0, inputBuffer, buffer.getNumSamples(), gain);
        }
    }
Beispiel #9
0
Mat FindContour::curveSmooth(Mat &contourImg,
                int WIN, // half window size for laplacian smoothing
                vector<Point> &border,
                vector<Point> &smooth,
                /*Point cntoid*/vector<Point> &convHull )
{
//    if(contourImg.type() != CV_8UC1){
//        cvtColor( contourImg, contourImg, CV_BGR2GRAY );
//    }
    double width = contourImg.cols;
    double height = contourImg.rows;

    Moments mu = moments(convHull);
//    Moments mu = moments(border);
    Point cntoid = Point2f(mu.m10/mu.m00/* + rect.x*/, mu.m01/mu.m00/* +rect.y*/);

    double d_min = max(width, height)*max(width, height);
    vector<polarPoint> border_polar;
    for (unsigned int n = 0; n < border.size(); n++)
    {
        //find the polar coordinates of the border;
        border_polar.push_back(cartesianToPolar(cntoid, border[n]));

        //find the nearest point to the center on the border
        double d = dist(cntoid, border[n]);
        if(d < d_min){
            d_min = d;
        }
    }
    d_min = sqrt(d_min);

    // sort border_polar by theta
    sort(border_polar.begin(), border_polar.end(), sortByTheta);

    // Laplacian smoothing
    unsigned int border_size = border_polar.size();
    for(unsigned int n = 0; n < border_size; n++){
        //cout << border_polar[n].r << " " << border_polar[n].theta << "  ";

        double avg = 0;
        for(int w = -WIN; w < WIN; w++){
            unsigned int pos = std::fabs((w+n+border_size)%border_size);
            //cout << " pos " << pos << "  ";
            avg += border_polar[pos].r;
        }
        avg = avg/WIN/2;
        polarPoint polar;
        polar.r = avg;
        polar.theta = border_polar[n].theta;
        //cout << polar.r << " " << polar.theta << " ";
        Point p = polarToCartesian(cntoid, polar);
        //circle(color, p, 1, Scalar(255, 255, 0));
        smooth.push_back(p);
        //cout << p.x << " " << p.y << "\n";
    }

    Mat smoothCircle = Mat::zeros(height, width, CV_8UC1);
    fillConvexPoly(smoothCircle, smooth, Scalar(255));
//    fillPoly(smoothCircle, smooth, Scalar(255));
    //imshow("smoothCircle", smoothCircle);

    return smoothCircle;
}
Beispiel #10
0
void ofxSick::analyze() {
	polarToCartesian(scanFront.first.distance, pointsFirst);
	brightnessToColor(scanFront.first.brightness, colorsFirst);
	polarToCartesian(scanFront.second.distance, pointsSecond);
	brightnessToColor(scanFront.second.brightness, colorsSecond);
}
Beispiel #11
0
void convertDatum(double* x, double* y, double* z, struct datum* fromDatum, struct datum* todatum) {
    polarToCartesian(x,y,z, fromDatum);
    helmertTransform(x,y,z, fromDatum, todatum);
    cartesianToPolar(x,y,z, todatum);
}
Beispiel #12
0
void meArm::goDirectlyToCylinder(float theta, float r, float z){
    float x, y;
    polarToCartesian(theta, r, x, y);
    goDirectlyTo(x,y,z);
}
void Speaker::setDirection (const Real inclination, const Real azimuth) {
    direction = polarToCartesian (inclination, azimuth);
}
void GLWidget::setLookAtDistance(float distance) {
    rotation_.setZ(distance);
    polarToCartesian();
}
Beispiel #15
0
//Same as above but for cylindrical polar coodrinates
void meArm::gotoPointCylinder(float theta, float r, float z){
    float x, y;
    polarToCartesian(theta, r, x, y);
    gotoPoint(x,y,z);
}
Beispiel #16
0
void features3D::setPoint(float range, float bearing)
{
	m_range = range;
	m_bearing = bearing;
	polarToCartesian();
}
Speaker::Speaker(const Real inclination, const Real azimuth, const Real directionality)
:   direction (polarToCartesian (inclination, azimuth))
,   directionality (directionality) {
    
}