Exemple #1
0
void House::CreateRoof(std::vector<Vertex*> &vect, int style,
		       double base, double height)
// style = 0 -> empty
// style = 1 -> 2 pan
// style = 2 -> 4 pan
{
	assert(base != height);
	assert(vect.size() == 4);
	
	std::vector<Vertex*> roofPan;
	
	if (style == 0)
		return;
	else if (style == 1)
	{
		Vertex mid1(GravityCenter(vect[0], vect[1]));
		Vertex mid2(GravityCenter(vect[2], vect[3]));
		
		roofPan.push_back(new Vertex(vect[0]->X(), vect[0]->Y(), base));
		roofPan.push_back(new Vertex(mid1.X(), mid1.Y(), height));
		roofPan.push_back(new Vertex(vect[3]->X(), vect[3]->Y(), base));
		roofPan.push_back(new Vertex(mid2.X(), mid2.Y(), height));
		faces->push_back(new Face(new std::vector<Vertex*>(roofPan)));
		
		roofPan.clear();
		roofPan.push_back(new Vertex(vect[1]->X(), vect[1]->Y(), base));
		roofPan.push_back(new Vertex(mid1.X(), mid1.Y(), height));
		roofPan.push_back(new Vertex(vect[2]->X(), vect[2]->Y(), base));
		roofPan.push_back(new Vertex(mid2.X(), mid2.Y(), height));
		faces->push_back(new Face(new std::vector<Vertex*>(roofPan)));
		
		roofPan.clear();
		roofPan.push_back(new Vertex(vect[0]->X(), vect[0]->Y(), base));
		roofPan.push_back(new Vertex(mid1.X(), mid1.Y(), height));
		roofPan.push_back(new Vertex(vect[1]->X(), vect[1]->Y(), base));
		faces->push_back(new Face(new std::vector<Vertex*>(roofPan)));
		
		roofPan.clear();
		roofPan.push_back(new Vertex(vect[2]->X(), vect[2]->Y(), base));
		roofPan.push_back(new Vertex(mid2.X(), mid2.Y(), height));
		roofPan.push_back(new Vertex(vect[3]->X(), vect[3]->Y(), base));
		faces->push_back(new Face(new std::vector<Vertex*>(roofPan)));
	}
	else if (style == 2)
	{
		Vertex cen(GravityCenter(vect));
		
		unsigned int n = vect.size();
		for(unsigned int i = 0; i < n; i++)
		{
			roofPan.clear();
			roofPan.push_back(new Vertex(vect[i]->X(), 
						     vect[i]->Y(), base));
			roofPan.push_back(new Vertex(vect[(i+1)%n]->X(), 
						     vect[(i+1)%n]->Y(), base));
			roofPan.push_back(new Vertex(cen.X(), cen.Y(), height));
			faces->push_back(new Face(new std::vector<Vertex*>(roofPan)));
		}
	}
}
Exemple #2
0
//Rasterize without facies counts computation
std::vector<Geovalue> HalfEllipsoid::rasterize( int node_id, 
	GsTLGridProperty *propTi, float angle ) 
{
	int i,j,k;
	cursor_->coords( node_id, i, j, k );
	location_3d<int> cen(i, j, k);

	int ii,jj,kk;
	std::vector<Geovalue> gbRaster;
	// rasterize with ellipsim-type approach
	{for ( ii = -rmax_; ii <= rmax_; ii++ ) {
		{for ( jj = -rmax_; jj <= rmax_; jj++ ) {
			if ( lower_half_ == 1 ) {
				for ( kk = -rmin_; kk <= 0; kk++ ) {
					//if( cursor_->check_triplet(i+ii,j+jj,k+kk) ) {
						location_3d<int> loc( i+ii, j+jj, k+kk );
						do_rotation( loc, cen, angle, gbRaster, propTi );
					//}
				}
			} 
			else {
				for ( kk = rmin_; kk >= 0; kk-- ) {
					//if( cursor_->check_triplet(i+ii,j+jj,k+kk) ) {
						location_3d<int> loc( i+ii, j+jj, k+kk );
						do_rotation( loc, cen, angle, gbRaster, propTi );
					//}
				}
			}
		}}
	}}
	return gbRaster;
}
Exemple #3
0
 Position<double> SBShapelet::SBShapeletImpl::centroid() const
 {
     std::complex<double> cen(0.);
     double n = 1.;
     for (PQIndex pq(1,0); !pq.pastOrder(_bvec.getOrder()); pq.incN(), n+=2)
         cen += sqrt(n+1.) * _bvec[pq];
     cen *= sqrt(2.)*_sigma/getFlux();
     return Position<double>(real(cen),-imag(cen));
 }
Exemple #4
0
int main()
{
	Vector *a[8], *b[8], disp(3);
	Vector cen(3), cen2(3);
	int i, j;

	if (makeforms (cen,a,b) != 10)
	  { std::printf ("FAIL\n"); return 1; }
	else
	  std::printf ("PASS\n");


}
void ofxImageThing::draw()
{
	ofPushStyle();
	ofEnableAlphaBlending();
	//ofTranslate(this->changePos);

	ofSetColor(Settings.imgColor);
	
	ofRectangle C;
	ofPoint cen(0,0);
	C.setFromCenter(cen,Settings.width,Settings.height);

	//img.setAnchorPoint(img.getWidth()/2,img.getHeight()/2);
	img.draw(C);

	ofPopStyle();
}
void
AsdkSmiley::list() const
{
    assertReadEnabled();

    AcGePoint3d cen( center() );
    double rad = radius();

    AcDbEntity::list();
    acutPrintf(
        "%12scenter point, X=%9.16q0  Y=%9.16q0  Z=%9.16q0\n"
        "%11s radius %9.16q0\n"
        "%7s eye radius %9.16q0\n"
        "%7s eye height %9.16q0\n"
        "%7s eyes apart %9.16q0\n",
        "", cen[X], cen[Y], cen[Z], "",
        rad, "", meyesize, "",
        meyesheight, "", meyesapart
    );
}
Exemple #7
0
bool GiGraphics::drawPie(const GiContext* ctx, 
                         const Point2d& center, float rx, float ry, 
                         float startAngle, float sweepAngle, 
                         bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || rx < _MGZERO || fabsf(sweepAngle) < 1e-5f)
        return false;
    GiLock lock (&m_impl->drawRefcnt);

    if (ry < _MGZERO)
        ry = rx;

    const Box2d extent (center, rx*2.f, ry*2.f);            // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    Point2d pxs[16];
    int count = mgcurv::arcToBezier(pxs, center,
        rx, ry, startAngle, sweepAngle);
    if (count < 4)
        return false;
    S2D(xf(), modelUnit).TransformPoints(count, pxs);
    Point2d cen(center * S2D(xf(), modelUnit));

    bool ret = rawBeginPath();
    if (ret)
    {
        rawMoveTo(cen.x, cen.y);
        rawLineTo(pxs[0].x, pxs[0].y);
        for (int i = 1; i + 2 < count; i += 3) {
            rawBezierTo(pxs[i].x, pxs[i].y,
                pxs[i+1].x, pxs[i+1].y, pxs[i+2].x, pxs[i+2].y);
        }
        rawClosePath();
        ret = rawEndPath(ctx, true);
    }

    return ret;
}
Exemple #8
0
bool MgDiamond::_setHandlePoint(UInt32 index, const Point2d& pt, float tol)
{
    if (!getFlag(kMgFixedLength)) {
        return MgBaseRect::_setHandlePoint(4 + index % 4, pt, tol);
    }
    
    Point2d cen(getCenter());
    Point2d pnt, ptup, ptside;
    
    pnt = pt * Matrix2d::rotation(-getAngle(), cen);
    mgGetRectHandle(getRect(), 4 + (index + 2) % 4, ptup);
    mgGetRectHandle(getRect(), 4 + (index + 1) % 4, ptside);
    
    float len = ptup.distanceTo(ptside);
    float dy = index % 2 == 0 ? pnt.y - ptup.y : pnt.x - ptup.x;
    float ry = mgMin(len, (float)fabs(dy) / 2);
    float rx = (float)sqrt(len * len - ry * ry);
    Box2d rect(cen, rx * 2, ry * 2);
    setRect(rect.leftTop(), rect.rightBottom(), getAngle(), cen);
    
    return true;
}
Exemple #9
0
//Rasterize with built rotation using equation of rotated ellipse
//Also computes the facies proportions within the rotated raster
std::vector<Geovalue> HalfEllipsoid::rasterize( int node_id, 
	GsTLGridProperty *propTi, float angle, std::vector<float> &facies_props ) 
{
	int i,j,k;
	cursor_->coords( node_id, i, j, k );
	location_3d<int> cen(i, j, k);

	//Initialize vector of facies proportions
	facies_props.insert( facies_props.begin(), min_overlap_.size(), 0.0 );
	int total_nodes = 0;

	int ii,jj,kk;
	std::vector<Geovalue> gbRaster;
	// rasterize with ellipsim-type approach --> with rotation
	{for ( ii = -rmax_; ii <= rmax_; ii++ ) {
		{for ( jj = -rmax_; jj <= rmax_; jj++ ) {
			if ( lower_half_ == 1 ) {
				for ( kk = -rmin_; kk <= 0; kk++ ) {
					location_3d<int> loc( i+ii, j+jj, k+kk );
					do_rotation( loc, cen, angle, gbRaster, propTi, 
						facies_props, total_nodes );
				}
			} 
			else {
				for ( kk = rmin_; kk >= 0; kk-- ) {
					location_3d<int> loc( i+ii, j+jj, k+kk );
					do_rotation( loc, cen, angle, gbRaster, propTi, 
						facies_props, total_nodes );
				}
			}
		}}
	}}
	//Compute facies proportions
	for ( int i=0; i<facies_props.size(); i++ ) {
		facies_props[i] /= total_nodes;
	}
	return gbRaster;
}
Exemple #10
0
int main()
{
    //Create the window
    sf::RenderWindow window(sf::VideoMode(gameWidth, gameHeight, 32),
        "WorchBound", sf::Style::Titlebar|sf::Style::Close);
    window.setVerticalSyncEnabled(true);

    //Create left tank
    sf::RectangleShape tank1;
    sf::Vector2f a(tankSize.x, tankSize.y);
    tank1.setSize(a);
    tank1.setOutlineThickness(1);
    tank1.setOutlineColor(sf::Color(100, 100, 100));
    tank1.setFillColor(sf::Color(29, 33, 13)); //Army Green Color

    //Create right tank
    sf::RectangleShape tank2;
    tank2.setSize(a);
    tank2.setOutlineThickness(1);
    tank2.setOutlineColor(sf::Color(100, 100, 100));
    tank2.setFillColor(sf::Color(29, 33, 13)); //Army Green Color

    //Create cannon
    sf::CircleShape cannon;
    cannon.setRadius(radiusCannon);
    cannon.setOutlineThickness(2);
    cannon.setOutlineColor(sf::Color::Black);
    cannon.setFillColor(sf::Color(224, 223, 219)); //Stainless Steel Color

        //Create colored part of the power bar
    sf::RectangleShape fillPowerbar;
    sf::Vector2f t(powerSize.x,powerSize.y);
    fillPowerbar.setSize(t);
    fillPowerbar.setFillColor(sf::Color::Black);

    //Get and load custom font
    sf::Font customFont;
    if(!customFont.loadFromFile("disparador_stencil.ttf"))
        return EXIT_FAILURE;

    //Make a Text object using the loaded font
    //"WIND" text object
    sf::Text txt;
    txt.setFont(customFont);
    txt.setCharacterSize(200);
    //txt.setPosition(gameWidth/2.f -200, gameHeight/2.f);
    txt.setColor(sf::Color::White);
    txt.setPosition((gameWidth/2.f) - 100,-150);


    //Wind value text object
    sf::Text windVal;
    windVal.setFont(customFont);
    windVal.setCharacterSize(70);
    windVal.setColor(sf::Color::White);
    windVal.setPosition((gameWidth/2.f) - 100,0);

    //Score for Tank 1
    sf::Text score1;
    score1.setFont(customFont);
    score1.setCharacterSize(70);
    score1.setColor(sf::Color::White);
    score1.setPosition((gameWidth/10.f) + 35,0);

    //Score for Tank 2
    sf::Text score2;
    score2.setFont(customFont);
    score2.setCharacterSize(70);
    score2.setColor(sf::Color::White);
    score2.setPosition(8 * (gameWidth/10.f) + 35,0);


    sf::Clock clock;

    //Set gravity as y component for acceleration vector
    acc.y = gravity;
    while(window.isOpen())
    {
        txt.setString("WIND:");
        //Generate Wind
        if(newRound == true)
        {
            Vector wind = wp.generateWind();
            acc.x = wind.x;
            newRound = false;
        }
        //Set wind indication as an arrow
        if(acc.x < 0)
        {
            float intensity = -1 * std::round(acc.x/50);
            string arrow = "<";
            for(int i = 0; i < intensity * 2; i++) arrow = arrow + "-";
            windVal.setString(arrow);
        }
        else if(acc.x > 0)
        {
            float intensity = std::round(acc.x/50);
            string arrow = "";
            for(int i = 0; i < intensity * 2; i++) arrow = arrow + "-";
            arrow = arrow + ">";
            windVal.setString(arrow);
        }
        else if(acc.x == 0) windVal.setString("No wind is occuring");

        //Set the Scoreboard
        score1.setString(std::to_string(score1st));
        score2.setString(std::to_string(score2nd));

        //Set tank position
        tank1.setPosition(gameWidth/10.f, gameHeight - 50);
        tank2.setPosition(8 * gameWidth/10.f, gameHeight - 50);

        sf::Event event;
        while(window.pollEvent(event))
        {
            //When escape key is pressed or window is closed, game ends
            if((event.type == sf::Event::Closed) ||
            ((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape)))
            {
                window.close();
                break;
            }
        }

        //Aiming movement
        if(event.type == sf::Event::MouseMoved)
        {
            if(!setAngle)
            {
                sf::Vector2i pos = sf::Mouse::getPosition(window);
                //float mousey = (float) pos.y;
                if(turn1) tankCenter.x = (gameWidth/10.f) + 35;
                if(turn2) tankCenter.x = (8 * (gameWidth/10.f) + 35);
                tankCenter.y = gameHeight - 25;
                Vector cenToMouse(pos.x - tankCenter.x, pos.y - tankCenter.y);
                Vector norm = cenToMouse.vectorNormalize(cenToMouse);
                Vector relPos = norm.scalarMult(norm, 100);
                Vector actPosition = relPos.vectorAdd(relPos, tankCenter);
                clampx = actPosition.x;
                clampy = actPosition.y;
                //std::cout << x <<endl;
                cannon.setPosition(clampx, clampy);
            }
        }
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
            //Charging power
        {
            if(turn1) fillPowerbar.setPosition(tank1.getPosition().x, tank1.getPosition().y - 30);
            if(turn2) fillPowerbar.setPosition(tank2.getPosition().x - 50, tank1.getPosition().y - 30);
            fillPowerbar.setFillColor(sf::Color::Red);
            if(emptyPowerbar)
            {
                power++;
                if(power == 11)
                {
                    fullPowerbar = true;
                    emptyPowerbar = false;
                }
            }
            if(fullPowerbar)
            {
                power--;
                if(power == 1)
                {
                    fullPowerbar = false;
                    emptyPowerbar = true;
                }
            }
            fillPowerbar.setSize(sf::Vector2f(power * (powerSize.x/10.f), powerSize.y));
            setAngle = true;
        }
        if((event.type == sf::Event::KeyReleased))
            //Charging and aiming is finished
           {
                fillPowerbar.setFillColor(sf::Color::Black);
                fillPowerbar.setPosition(0, 0);
                float deltaY = tankCenter.y - clampy;
                float deltaX = clampx - tankCenter.x;
                if(turn2) deltaX *= -1;
                angle = (std::atan2(deltaY, deltaX) * (180/PI));
                initVelo = wp.initialVelocity((float) power *40.0, angle);
                if(turn2) initVelo.x *= -1;
                isFiring = true;
                first = true;
           }

        //State where the ball is fired
        if(isFiring)
        {
                sf::Vector2f cur = cannon.getPosition();
                Vector c(cur.x, cur.y);
                Vector a;
                a = wp.verletPhysics(c, prevPos, initVelo, acc, dt , first);
                prevPos.x = cur.x;
                prevPos.y = cur.y;
                cannon.setPosition(a.x, a.y);
                //std::cout << a.x << " " << a.y << " " <<endl;
                Vector cen(cur.x + radiusCannon, cur.y + radiusCannon);
                if(turn2) tankCenter.x = (gameWidth/10.f) + 35;
                if(turn1) tankCenter.x = (8 * (gameWidth/10.f) + 35);
                tankCenter.y = gameHeight - 25;
                if(wp.collissionAABBCircle(cen, radiusCannon, tankCenter, tankSize.x, tankSize.y))
                    {
                        if(turn1)
                        {
                            turn1 = false;
                            turn2 = true;
                            score1st++;
                        }
                        else if(turn2)
                        {
                            turn2 = false;
                            turn1 = true;
                            score2nd++;
                        }
                        setAngle = false;
                        power = 2;
                        newRound = true;
                        cannon.setPosition(0,0);
                    }
                if(a.x > gameWidth || a.x < 0)
                    {
                        if(turn1)
                        {
                            turn1 = false;
                            turn2 = true;
                        }
                        else if(turn2)
                        {
                            turn2 = false;
                            turn1 = true;
                        }
                        setAngle = false;
                        power = 2;
                        isFiring = false;
                        newRound = true;
                        cannon.setPosition(0,0);
                    }
                if(a.y > gameHeight || a.y < 0)
                    {
                        if(turn1)
                        {
                            turn1 = false;
                            turn2 = true;
                            setAngle = false;
                            power = 1;
                        }
                        else if(turn2)
                        {
                            turn2 = false;
                            turn1 = true;
                            setAngle = false;
                            power = 1;
                        }
                        setAngle = false;
                        power = 2;
                        isFiring = false;
                        newRound = true;
                        cannon.setPosition(0,0);
                    }
                first = false;

        }


        //Render codes
        //Clears The Screen
        window.clear(sf::Color::Black);

        //Draw objects
        window.draw(tank1);
        window.draw(tank2);
        window.draw(cannon);
        window.draw(fillPowerbar);
        window.draw(txt);
        window.draw(windVal);
        window.draw(score1);
        window.draw(score2);
        //Display on Screen
        window.display();

        //Sleep
        //time translated to seconds
        float post = clock.getElapsedTime().asSeconds();
        if(post < dt)
        {
            sf::Time sle = sf::seconds(dt - post);
            sf::sleep(sle);
        }

        //Restart clock
        clock.restart();
    }
    return EXIT_SUCCESS;
}