示例#1
0
std::vector <Ball> GetSteps() {
	return {
		Ball(-1, 0),
		Ball(0, 1),
		Ball(0, -1),
		Ball(1, 0),
	};
}
示例#2
0
Ball getGoal(Mat img_in){

 double largest_area=0;
 int largest_contour_index=0;
 Rect bounding_rect;
 Ball goal;

    vector<vector<Point>> contours; // Vector for storing contour
    vector<Vec4i> hierarchy;

	cout<< "Searching for biggest contours" << endl;
    findContours( img_in, contours, hierarchy,CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE ); // Find the contours in the image
    cout<<"asdffgh"<<endl;

	if (contours.data() != NULL)
	{
		cout<< "Found countours" << endl;


     for( int i = 0; i< contours.size(); i++ ) // iterate through each contour.
      {
       double a=contourArea( contours[i],false); //  Find the area of contour
       if(a>largest_area){
       largest_area=a;
       largest_contour_index=i;                //Store the index of largest contour
       bounding_rect=boundingRect(contours[i]); // Find the bounding rectangle for biggest contour
       }
      }

	 if (largest_area < 30)
	 {
		 return Ball(100,100,40);
	 }

      Moments mom = moments(contours[largest_contour_index],false);
      // Get mass center
      goal = Ball(mom.m10/mom.m00, mom.m01/mom.m00, 10);

      Scalar color( 255,255,255);
     drawContours( img_in, contours,largest_contour_index, color, 6 , 8, hierarchy ); // Draw the largest contour using previously stored index.
     rectangle(img_in, bounding_rect,  Scalar(255,255,255),1, 8,0);
     circle(img_in, Point2f(mom.m10/mom.m00, mom.m01/mom.m00), 6, color, -1, 8, 0);

	 contours.clear();
	 hierarchy.clear();

    return goal;

    }

     return Ball(100, 100, 40); 
}
示例#3
0
int main (void){
	int cnum, couche, cplr, i, j, col_num, x, y, ang, dist, thrown[2];
	double sin_table[361], cos_table[361], min_dist;
	double conv = acos(-1)/180;
	bool dbg = 0;
	for(i = 0; i < 361; i++) sin_table[i] = sin(i*conv), cos_table[i] = cos(i*conv);
	scanf("%d",&cnum);
	while(cnum--){
		cplr = couche = thrown[0] = thrown[1] = 0;
		scanf("%s%s",n[0],n[1]);
		for(i = 0; i < 7; i++){
			if(i && ++thrown[cplr] > 3) cplr = 1-cplr;
			scanf("%d%d%d%d",&x,&y,&ang,&dist);
			start = Ball(x,y,cplr,0);
			b[i] = Ball(x+cos_table[ang]*dist,y+sin_table[ang]*dist,cplr,i);
			for(col_num = j = 0; j < i; j++)
				if(colinear(start,b[j],b[i]))
					col[col_num++] = Ball(b[j].x,b[j].y,b[j].plr,b[j].n);
			std::sort(col,col+col_num,closerToStart);
			for(j = 0; j < col_num; j++){
				int aux = col[j].plr;
				b[col[j].n].plr = b[i].plr;
				b[i].plr = aux;
			}
			min_dist = 1<<23;
			for(j = 0; j <= i; j++)
				if(b[j].plr == 2){ couche = j; break;}
			for(j = 0; j <= i; j++){
				if(j == couche) continue;
				double temp = sqdist(b[j],b[couche]);
				if(temp < min_dist){
					min_dist = temp;
					cplr = 1 - b[j].plr;
				}
			}
			if(i == 0) b[i].plr = 2;
		}
		for(i = 0; i < 7; i++)
			if(b[i].plr == 2){
				start = Ball(b[i].x,b[i].y,2,0);
				break;
			}
		std::sort(b,b+7,closerToStart);
		if(b[1].plr == 2) std::swap(b[0],b[1]);
		for(i = 2; b[i].plr == b[1].plr; i++);
		printf("%s %d\n",n[b[1].plr],i-1);
	}
	return 0;
}
示例#4
0
//--------------------------------------------------------------
void ofApp::setup(){

	ofxAccelerometer.setup();

	tick.loadSound("sound/tick.mp3");

	for(int i=0;i<15;i++){
		string n = "";
		if(i<10){
			notes[i].loadSound("notes/0"+ofToString(i)+".mp3");
		}else{
			notes[i].loadSound("notes/"+ofToString(i)+".mp3");
		}

		notes[i].setVolume(0.5f);
		notes[i].setMultiPlay(true);
	}

	//http://jetcityorange.com/musical-notes/
	tick.setVolume(0.5f);
	tick.setMultiPlay(true);

	ofBackground(255,211,0);

	for(int i=0;i<NUM_BALL;++i){
		balls.push_back(Ball());
	}

	ofEnableAlphaBlending();
}
示例#5
0
void MiniGolf::GameInit(){	
	levelPars = resMan->getLevelPars();
	levelNames = resMan->getLevelNames();
	ballMoving = false;
	arrowAngle = 0;
	strokeNum = totalScore = 0;
	objVerts.push_back(gameObjectData->at("ballVert"));
	objVerts.push_back(gameObjectData->at("arrowVert"));
	objVerts.push_back(gameObjectData->at("cupVert"));
	objNorms.push_back(gameObjectData->at("ballNorm"));
	objNorms.push_back(gameObjectData->at("arrowNorm"));
	objNorms.push_back(gameObjectData->at("cupNorm"));
	objColor.push_back(gameObjectData->at("ballColor"));
	objColor.push_back(gameObjectData->at("arrowColor"));
	objColor.push_back(gameObjectData->at("cupColor"));
	objIndices[0] = make_pair(0, 0);
	objIndices[1] = make_pair(1, 1);
	objIndices[2] = make_pair(2, 2);
	setDefaultModelView(defaultView);
		
	cup = Cup();
	ball = Ball();
	cup.setPos(cups[0].x, cups[0].y, cups[0].z);
	modelViews[2] = glm::translate(defaultView,glm::vec3(cup.x, cup.z, cup.y));
	ball.Initialize(tees[0].x, tees[0].y, tees[0].z);
	camManager = new Camera(&ball);
	camManager->setCamPos(5, 5, 7);
	camManager->setCamTarg(0, 0, 0);
}
示例#6
0
void TipsPainter::drawBallTraj(const BallTraj& traj, int queue_number) 
{
	if ((traj.trList.emptyTraj())||(traj.trList.count()==1))
		return; //error

	QPen old = pen();
	setTipTrajectoryPen(traj, queue_number);

	QListIterator<NaturalPoint> iter(traj.trList);
	QRealPoint item2 = iter.next();
	QRealPoint item1(0,0);
	while(iter.hasNext())
	{
		item1 = item2;
		item2 = iter.next();
		drawLine(round(item1), round(item2));
	}

	if (traj.type!=stepping)
		drawBall(Ball(round(item2),traj.radius,traj.type,0), true);

	if (!traj.velMarks.empty())
		drawVelocityDots(traj);

	setPen(old);
}
示例#7
0
LogicManager::LogicManager()
{
	unsigned int nbStoppedBalls = 0;
	this->game = 0;
	this->level = 1;
	this->ball = Ball();
	this->gravity = 1;
}
示例#8
0
文件: Pong.cpp 项目: catlin0123/Pong
/**************************************************************************//**
* @author Paul Blasi, Caitlin Taggart
*
* @par Description:
* Main execution point of the app. Initializes the window and prepares the
* main objects to be drawn on the screen. Also sets up the callback events.
*
* @returns Execution outcome.
*
*****************************************************************************/
int main(int argc, char *argv[])
{
    //set up the window
    glutInit(&argc, argv); 
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutInitWindowSize(SCREEN_WIDTH, SCREEN_HEIGHT);
    glutInitWindowPosition(100, 100); 
    glutCreateWindow("Pong"); 
    glClearColor(0.0, 0.0, 0.0, 1.0);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    //specify callbacks
    glutDisplayFunc(Display);
    glutReshapeFunc(Reshape);
    glutKeyboardFunc(Keyboard);
    glutKeyboardUpFunc(KeyboardUp);
    glutSpecialFunc(SpecialKeys);
    glutSpecialUpFunc(SpecialKeysUp);

    glutTimerFunc(30, Animate, 1);

    //TODO set up players and ball
	BALL = Ball(Point(100, 50),5, WHITE);

    LEFT_PLAYER = Paddle(Point(10, 50), 10, 40, WHITE);
    RIGHT_PLAYER = Paddle(Point(190, 50), 10, 40, WHITE);

    NET = Net(Point(100, 50), VERTICAL, WHITE, 98);

    TOP_WALL = Wall(Point(100, 99), HORIZONTAL, WHITE, 198);
    BOTTOM_WALL = Wall(Point(100, 1), HORIZONTAL, WHITE, 198);
    LEFT_WALL = Wall(Point(1, 50), VERTICAL, WHITE, 98);
    RIGHT_WALL = Wall(Point(199, 50), VERTICAL, WHITE, 98);

    COLLISION_MAN.RegisterCollision(&BALL, &LEFT_PLAYER, BallCollideWithLeftPaddle);
    COLLISION_MAN.RegisterCollision(&BALL, &RIGHT_PLAYER, BallCollideWithRightPaddle);
    COLLISION_MAN.RegisterCollision(&BALL, &TOP_WALL, BallCollideWithWall); 
    COLLISION_MAN.RegisterCollision(&BALL, &BOTTOM_WALL, BallCollideWithWall);
    COLLISION_MAN.RegisterCollision(&BALL, &LEFT_WALL, Score);
    COLLISION_MAN.RegisterCollision(&BALL, &RIGHT_WALL, Score);

    COLLISION_MAN.RegisterCollision(&LEFT_PLAYER, &TOP_WALL, LeftCollideWithWall);
    COLLISION_MAN.RegisterCollision(&LEFT_PLAYER, &BOTTOM_WALL, LeftCollideWithWall);
    COLLISION_MAN.RegisterCollision(&LEFT_PLAYER, &LEFT_WALL, LeftCollideWithWall);
    COLLISION_MAN.RegisterCollision(&LEFT_PLAYER, &NET, LeftCollideWithWall);

    COLLISION_MAN.RegisterCollision(&RIGHT_PLAYER, &TOP_WALL, RightCollideWithWall);
    COLLISION_MAN.RegisterCollision(&RIGHT_PLAYER, &BOTTOM_WALL, RightCollideWithWall);
    COLLISION_MAN.RegisterCollision(&RIGHT_PLAYER, &RIGHT_WALL, RightCollideWithWall);
    COLLISION_MAN.RegisterCollision(&RIGHT_PLAYER, &NET, RightCollideWithWall);

    glutMainLoop(); 

    return 0; 
}
示例#9
0
void World::addTemp(Pos p)
{
	if(!tempOnTop)
	{
		beginMousePos = p;
		currentMousePos = p;
		balls.push_back(Ball(0,0,0, p.x, p.y));
		tempOnTop = true;
	}
}
Vector2D GoalKeeper::GetRearInterposeTarget()const
{
  double xPosTarget = Team()->HomeGoal()->Center().x;

  double yPosTarget = Pitch()->PlayingArea()->Center().y - 
                     Prm.GoalWidth*0.5 + (Ball()->Pos().y*Prm.GoalWidth) /
                     Pitch()->PlayingArea()->Height();

  return Vector2D(xPosTarget, yPosTarget); 
}
示例#11
0
文件: World.cpp 项目: pavelsimo/Pong
 void World::Restart() 
 {
     ChangeState(PLAYING);
     m_ball = Ball(
         m_width * 0.5f, 
         m_height * 0.5f, 
         BALL_WIDTH, 
         BALL_HEIGHT
     );
     m_velBall = math::Vector2(BALL_SPEED, BALL_SPEED);
 }
示例#12
0
JNIEXPORT void JNICALL Java_net_catchball_CatchBallRenderer_nativeInit
  (JNIEnv * env, jclass cls, jstring apkPath) {
  const char* str;
  jboolean isCopy;
  str = env->GetStringUTFChars(apkPath, &isCopy);
  loadAPK(str);

  int width, height;
  texture = loadTextureFromPNG("assets/sprites/texture.png", width, height);
  int bblue = loadTextureFromPNG("assets/sprites/button blue.png", width, height);
  int bred = loadTextureFromPNG("assets/sprites/button red.png", width, height);
//  int houseTexture = loadTextureFromPNG("assets/sprites/house.png", width, height);
  int meteor_b = loadTextureFromPNG("assets/sprites/meteor.png", width, height);
  int meteor_y = loadTextureFromPNG("assets/sprites/meteor-y.png", width, height);
  int meteor_r = loadTextureFromPNG("assets/sprites/meteor-r.png", width, height);
  int meteor_g = loadTextureFromPNG("assets/sprites/meteor-g.png", width, height);
  int ballTexture = loadTextureFromPNG("assets/sprites/ball.png", width, height);

  printGLString("Version", GL_VERSION);
  printGLString("Vendor", GL_VENDOR);
  printGLString("Renderer", GL_RENDERER);
  printGLString("Extensions", GL_EXTENSIONS);

  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  glEnable(GL_BLEND);
  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_TEXTURE_2D);
  glClearColor(0,0,0,0);
  glColor4f(1,1,1,1);
  glDisable(GL_DEPTH_TEST);
  glDisable(GL_CULL_FACE);
  
	Texture texr(RED,meteor_r);
	Texture texg(GREEN,meteor_g);
	Texture texy(YELLOW,meteor_y);
	Texture texb(BRONZE,meteor_b);

LOGI("textures created");
//  house = House(world.getWorld());
//  house.setTexture(houseTexture);
  ball = Ball(world);
  ball.setTexture(ballTexture);
LOGI("Ball created");
  meteors = meteorManager(world.getWorld());
LOGI("Meteors created");
//  meteors.setTexture(meteor);
  meteors.addTexture(texb);
  meteors.addTexture(texr);
  meteors.addTexture(texy);
  meteors.addTexture(texg);
//  buttons.setTextures(bblue, bred);
LOGI("Textures for meteors added");
}
示例#13
0
文件: mgl_3d.cpp 项目: LuaDist/iup
//-----------------------------------------------------------------------------
//
//	CloudP series
//
//-----------------------------------------------------------------------------
void mglGraph::AVertex(mreal x,mreal y,mreal z, mreal a,mreal alpha)
{
	mglColor c;
	if(!ScalePoint(x,y,z) || isnan(a))	return;
	a = GetA(a);
	if(OnCoord)	c = GetC(x,y,z);
	else		c = GetC(a,false);
	a = alpha>0 ? (a+1)*(a+1)/4 : -(a-1)*(a-1)/4;
//	a = alpha>0 ? (a+1)/2 : (a-1)/2;
	if(a)	Ball(x,y,z,c,-alpha*a);
}
示例#14
0
Controller::Controller(int n, int debug) {
  number = n;
  balls = (Ball *)malloc(n * sizeof(Ball));
  for (int i = 0; i < n; i++) {
    if(debug) {
      std::cout << (i + 1) << ".";
    }
    balls[i] = Ball(debug);
  }
  this->debug = debug;
}
示例#15
0
//--------------------------------------------------------------
void santiSoundize::mouseDragged(int x, int y, int button){
    float theta         = ofRandom(0,360);
    ofVec2f location    = ofVec2f(x,y);
    ofVec2f velocity    = ofVec2f(sin(theta),cos(theta));
    ofColor color       = ofColor(ofRandom(255), ofRandom(255), ofRandom(255));
    velocity           *= ofRandom(2,4);

    std::vector<int> FFTids;
    for (int i = 0; i < 4; i++)
        FFTids.push_back(int(ofRandom(m_nBandsToGet)));
    m_balls.push_back(Ball(location,velocity,color,20,FFTids));
}
示例#16
0
std::vector<Ball> Referee::getBallsList() const
{
	// use rule here
	// read the file get config info
	std::ifstream fin;
    switch(game_rule){
        case EIGHT_BALL:
            fin.open(EIGHT_BALL_CONFIG_FILENAME);
            break;

        case NINE_BALL:
            fin.open(NINE_BALL_CONFIG_FILENAME);
            break;

        case SNOOKER:
            fin.open(SNOOKER_CONFIG_FILENAME);
            break;

        default:
            fin.open("config.txt");
            break;
     }
	std::string str;
	while (fin >> str)
	{
		if (str == "ballsList")
		{
			break;
		}
	}
	int number;
	fin >> number;
	std::vector<Ball> ballsList;
	for (int i = 0; i < number; ++i)
	{
		float x, y;
		int R, G, B;
		std::string name;
		fin >> x;
		fin >> y;
		fin >> R;
		fin >> G;
		fin >> B;
		fin >> name;
		Ball ball = Ball(Vector2(x, y), ballRadius);
		ball.setColor(QColor(R, G, B));
		ball.setName(name);
		ballsList.push_back(ball);
	}
	fin.close();
	return ballsList;
}
示例#17
0
Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog),
    m_ball(Ball(Coordinate(250, 250, 500, 500), 20, 0, 10, 10)),
    m_counter(0)
{
    ui->setupUi(this);
    this->resize(500, 500);
    this->setStyleSheet("background-color: #82CAFF;");
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(nextFrame()));
    timer->start(16);
}
示例#18
0
/*
	Name:	spawnNewBalls
	Desc:	spawns a new ball if the obstacle list determines it needs one.
			It trys to allow a buffer so that new balls don't simply immediatly respawn once they leave the screen.
			Would lead to clumping.
	Args:	None
	Rtrn:	None
*/
void Game::spawnNewBalls()
{
	int random = rand() % m_maxBalls - m_minBalls;
	int comparison = m_obstacles.GetCount() - m_minBalls;

	if(random >= comparison && comparison != 10)
	{
		sf::Vector2f pos = seedRandomBallPosition();
		int hue = rand() % 359;
		int vel = ((rand() % 3) + 2);
		m_obstacles.Append(Ball(pos,sf::Vector2f(vel*-1, vel), ColorUtil::HueToRGB(hue), hue));
	}
}
示例#19
0
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
    int bSize = balls.size();
    if (bSize < 1) {
        Ball b;
        float radius = ofGetHeight() / 3;
        b.setPos(ofPoint(mouseX, mouseY));
        b.setRadius(radius);
        b.setSpeed(ofPoint(ofRandom(-10, 10), ofRandom(-10, 10)));
        balls.push_back(b);
    }
    for (int i = 0; i < bSize; i++) {
        ofPoint pos = balls[i].getPos();
        float radius = balls[i].getRadius();
        float dist = ofDist(pos.x, pos.y, mouseX, mouseY);
        if (dist < radius) {
            balls[i].setRadius(radius * 0.6);
            balls[i].setPos(ofPoint(pos.x - radius * 0.7, pos.y));
            balls[i].setSpeed(ofPoint(ofRandom(-radius / 50, radius / 50), ofRandom(-radius / 50, radius / 150)));
            Ball b1 = Ball();
            b1.setRadius(radius * 0.6);
            b1.setPos(ofPoint(pos.x + radius * 0.7, pos.y));
            b1.setSpeed(ofPoint(ofRandom(-radius / 50, radius / 50), ofRandom(-radius / 50, radius / 50)));
            balls.push_back(b1);
            
            Ball b2 = Ball();
            b2.setRadius(radius * 0.6);
            b2.setPos(ofPoint(pos.x, pos.y - radius * 0.7));
            b2.setSpeed(ofPoint(ofRandom(-radius / 50, radius / 50), ofRandom(-radius / 50, radius / 50)));
            balls.push_back(b2);
            
            Ball b3 = Ball();
            b3.setRadius(radius * 0.6);
            b3.setPos(ofPoint(pos.x, pos.y + radius * 0.7));
            b3.setSpeed(ofPoint(ofRandom(-radius / 50, radius / 50), ofRandom(-radius / 50, radius / 50)));
            balls.push_back(b3);
            
        }
    }
}
示例#20
0
//--------------------------------------------------------------
void soundizeMeApp::setup(){
    

    
    
    ofSetCircleResolution(100);
    
    ofEnableSmoothing();

    ofSetFrameRate(30);

  
    m_nBandsToGet = 1024;
    int * arr = new int[m_nBandsToGet*4];
    for (int i = 0; i < m_nBandsToGet*4; i++){
        arr[i] = i % m_nBandsToGet;
    }
    random_shuffle(&arr[m_nBandsToGet * 0 ], &arr[m_nBandsToGet * 1]);
    random_shuffle(&arr[m_nBandsToGet * 1 ], &arr[m_nBandsToGet * 2]);
    random_shuffle(&arr[m_nBandsToGet * 2 ], &arr[m_nBandsToGet * 3]);
    random_shuffle(&arr[m_nBandsToGet * 3 ], &arr[m_nBandsToGet * 4]);

    m_fftSmoothed = new float[m_nBandsToGet];
    for (int i = 0; i < m_nBandsToGet; i++){
        m_fftSmoothed[i] = 0;
    }

   


    for (int i = 0; i < m_nBandsToGet/8 ; i++)
    {
        float theta         = ofRandom(0,360);
        ofVec2f location    = ofVec2f(ofRandomWidth(),ofRandomHeight());
        ofVec2f velocity    = ofVec2f(sin(theta),cos(theta));
        ofColor color       = ofColor(ofRandom(255), ofRandom(255), ofRandom(255));
        velocity           *= ofRandom(0.5,2);

        std::vector<int> FFTids;
        FFTids.push_back(arr[m_nBandsToGet * 0 + i]);
        FFTids.push_back(arr[m_nBandsToGet * 1 + i]);
        FFTids.push_back(arr[m_nBandsToGet * 2 + i]);
        FFTids.push_back(arr[m_nBandsToGet * 3 + i]);

        
        m_balls.push_back(Ball(location,velocity,color,20,FFTids));
    }

   
  
}
示例#21
0
文件: Blobs02.cpp 项目: MrMdR/julapy
void Blobs02 :: addBall( float bx, float by, float radius )
{
	float ballMass;
	float ballBounce;
	float ballFriction;
	
	ballMass		= 10;
	ballBounce		= 1.0;
	ballFriction	= 0.9;
	
	balls.push_back( Ball() );
	balls.back().circleRadius	= radius;
	balls.back().circle			= ofxBox2dCircle();
	balls.back().circle.setPhysics( ballMass, ballBounce, ballFriction );
	balls.back().circle.setup( box2d.getWorld(), bx, by, radius );
}
示例#22
0
vector <Ball> getBalls(Mat img_in){

	vector<Ball> balls;

	IplImage* img_in1 = new IplImage(img_in);

	CvMemStorage* storage = cvCreateMemStorage(0);

        // hough detector works better with some smoothing of the image
        cvSmooth( img_in1,img_in1, CV_GAUSSIAN, 9, 9 );

		// Element to define dilation shape (basically a matrix)
		IplConvKernel* element = cvCreateStructuringElementEx(9,9, 4, 4, CV_SHAPE_ELLIPSE);

		// Suurenda veits palli (valgeid alasid)
		cvDilate(img_in1, img_in1 ,element , 4);

		CvSeq* circles = cvHoughCircles(img_in1, storage, CV_HOUGH_GRADIENT, 2,
                                        img_in1->height/4, 100, 50, 10, 400);



		for (int i = 0; i < circles-> total; i++)
        {
            float* p = (float*)cvGetSeqElem( circles, i );

			printf("Ball! x=%f y=%f r=%f\n\r" ,p[0],p[1],p[2] );

			Ball current_ball = Ball(p[0],p[1],p[2]);

			cout << " X, Y radiaanides " << current_ball.getX_degR() <<" "<< current_ball.getY_degR() << endl;

			balls.push_back(current_ball);

			circle( img_in, cvPoint(cvRound(p[0]),cvRound(p[1])),
                            3, CV_RGB(255,255,0), -1, 8, 0 );

			circle( img_in, cvPoint(cvRound(p[0]),cvRound(p[1])),
                            cvRound(p[2]), CV_RGB(255,0,0), 3, 8, 0 );

		}

		sort(balls.begin(),balls.end());


	return balls;
}
示例#23
0
//--------------------------------------------------------------
void ofApp::draw(){
    Gui.draw();
    
    for(int i=0; i<p.size(); i++) {
        p[i].draw();
    }
    
    ofSetColor(0, 0, 0, clarity);
    ofFill();
    ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight());
    
    ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
    
    ofSetColor(255, 255, 255, alpha);
    
    shape.shape1(width2, abs(cos(ofGetElapsedTimef()/7))*100, angle3, 1.04, maxSize);
    
    ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2);
    
    for (int j = 0; j < 480; j+=space) {
        for (int i = 0; i < 640; i+=space){
            float distance = kinect.getDistanceAt(i, j);
            float distance2 = kinect2.getDistanceAt(i, j);
            
            if(distance>0 && distance<1000)
            {
                balls.push_back(Ball());
                
                ofFill();
                balls[i].draw(i*6-kinect.width-500, j*5-kinect.height-300, distance*-2.0, radius);
              
//                cout << "x_" << distance << endl;
            }
            
            if(distance2>0 && distance2<1000)
            {
                balls2.push_back(Ball2());
                
                ofFill();
                balls2[i].draw(i*6-kinect2.width-500, j*5-kinect2.height-300, distance2*-2.0, radius);
            }
            
//            cout << "xx" << abs(distance - distance2) << endl;
         
        }
    }
}
示例#24
0
void initRendering(char** argv)
{
	glClearColor(0.678431, 0.847059, 0.901961, 1.0);
	glShadeModel(GL_SMOOTH);

	glEnable(GL_DEPTH_TEST);
	ReadMap("hole.01.db");
	
	ImportObj temp;
	ImportObj Tee = getTeeBuffer();
	load_obj("BallSmall.obj", temp.Vertices, temp.Indices, glm::vec3(0, 0.08, 0));
	temp.CalculateNormals();
	GolfBall = Ball(temp, Tee.Coordinate, getTiles()[getTeeBuffer().TileID - 1]);
	//The starting tile is the tile of the Tee

	setShaders();
}
示例#25
0
void Pong::init(ofRectangle _space) {
    ofPoint center = ofPoint(_space.getCenter().x * width,_space.getCenter().y * height);
    space.setFromCenter(center,
                        _space.width* width * 0.85,
                        _space.height * height * 0.85);

    fbo.allocate(width, height);
    fbo.begin();
    ofClear(0);
    fbo.end();

    ball = Ball(&space, &player1, &player2);
    ofAddListener( ball.goal , this, &Pong::point);
    pixel = space.width/40;

    reset();
}
示例#26
0
vector <Ball> getBallsC(Mat img_in){

 vector<Ball> balls;

 double largest_area=0;
 int largest_contour_index=0;
 Rect bounding_rect;
 Ball ball;

    vector<vector<Point>> contours; // Vector for storing contour
    vector<Vec4i> hierarchy;

	cout<< "Searching for biggest contours" << endl;
    findContours( img_in, contours, hierarchy,CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE ); // Find the contours in the image
    cout<<"asdffgh"<<endl;

	if (contours.data() != NULL)
	{
		cout<< "Found countours" << endl;

     Moments mom;
     for( int i = 0; i< contours.size(); i++ ) // iterate through each contour.
      {
       double a=contourArea( contours[i],false);//  Find the area of contour
      mom = moments(contours[largest_contour_index],false);
      double r = sqrt(a/3.14159);
      // Get mass center
      ball = Ball(mom.m10/mom.m00, mom.m01/mom.m00, 10);
      balls.push_back(ball);
      }

     Scalar color( 255,255,255);
     drawContours( img_in, contours,largest_contour_index, color, 6 , 8, hierarchy ); // Draw the largest contour using previously stored index.
     rectangle(img_in, bounding_rect,  Scalar(255,255,255),1, 8,0);
     circle(img_in, Point2f(mom.m10/mom.m00, mom.m01/mom.m00), 6, color, -1, 8, 0);

	 contours.clear();
	 hierarchy.clear();
      }


      sort(balls.begin(),balls.end());

 return balls;

}
示例#27
0
void GameWorld::addBall(int num)
{
	for (int i = 0;i < num;i++) {
		int type = i % 2 == 0 ? POSITIVE_BALL : NEGATIVE_BALL;
		//type = POSITIVE_BALL;
		Color4f color;
		switch (type)
		{
		case POSITIVE_BALL:
			color.red = 50/255.0;
			color.green = 225/255.0;
			color.blue = 50/255.0;
			break;
		case NEGATIVE_BALL:
			color.red = 100/255.0;
			color.green = 0;
			color.blue = 255/255.0;
			break;
		default:
			break;
		}
		double friction = 0.5;
		Vector3d direction;
		direction.x = rand() % 100;
		direction.z = rand() % 100;
		direction.y = 0.0;
		Vector3d position;
		position.x = rand() % 100;
		position.y = 5.0;
		position.z = rand() % 100;
		for (int j = 0;j < ballVector.size();j++) {
			Vector3d ballPos = ballVector[j].position;
			Vector3d deltpos = position - ballPos;
			if (deltpos.length() <= 10.0) {
				position.x = rand() % 100;
				position.y = 5.0;
				position.z = rand() % 100;
				break;
			}
		}
		Ball newball = Ball(5.0, friction, 60, direction,position, color, type);
		ballVector.push_back(newball);
	}
}
示例#28
0
Server::Server(void *surf, const Configuration& conf)
 : Framework(surf, conf, UNINITIALIZED), ballouttimer(-1), ballspeed(6.0)
{
	ball.push_back(Ball(this));
	player.push_back(new Player(this, "Mr. Wand", BACK, field.getLength()/2.0f));
	// Mr. Wand is cheating!
	player[0]->setSize(3.5, 3.5); // *****************
	player[0]->run();
	resetScore();
	output.addMessage(Interface::WAITING_FOR_OPPONENT);

	server = initNetwork(conf.version, conf.playername, conf.port);
	loopback = Client::initNetwork(conf.version, "localhost", conf.port, conf.playername);

	if (server == -1 || loopback == -1)
		shutdown();

	loop();
}
void GoalKeeper::Update()
{ 
  //run the logic for the current state
  m_pStateMachine->Update();

  //calculate the combined force from each steering behavior 
  Vector2D SteeringForce = m_pSteering->Calculate();



  //Acceleration = Force/Mass
  Vector2D Acceleration = SteeringForce / m_dMass;

  //update velocity
  m_vVelocity += Acceleration;

  //make sure player does not exceed maximum velocity
  m_vVelocity.Truncate(m_dMaxSpeed);

  //update the position
  m_vPosition += m_vVelocity;


  //enforce a non-penetration constraint if desired
  if(Prm.bNonPenetrationConstraint)
  {
    EnforceNonPenetrationContraint(this, AutoList<PlayerBase>::GetAllMembers());
  }

  //update the heading if the player has a non zero velocity
  if ( !m_vVelocity.isZero())
  {    
    m_vHeading = Vec2DNormalize(m_vVelocity);

    m_vSide = m_vHeading.Perp();
  }

  //look-at vector always points toward the ball
  if (!Pitch()->GoalKeeperHasBall())
  {
   m_vLookAt = Vec2DNormalize(Ball()->Pos() - Pos());
  }
}
void PacanariDamaman::GameInit(){	
	levelPars = resMan->getLevelPars();
	levelNames = resMan->getLevelNames();
	ballMoving = nextLevelCheat = swingDir = false;
	arrowAngle = rightAngle = leftAngle = 0;
	strokeNum = totalScore = 0;
	objVerts.push_back(gameObjectData->at("ballVert"));
	objVerts.push_back(gameObjectData->at("cupVert"));
	objVerts.push_back(gameObjectData->at("pacanariBodyVert"));
	objVerts.push_back(gameObjectData->at("pacanariCollarVert"));
	objVerts.push_back(gameObjectData->at("pacanariLimbVert"));
	objNorms.push_back(gameObjectData->at("ballNorm"));
	objNorms.push_back(gameObjectData->at("cupNorm"));
	objNorms.push_back(gameObjectData->at("pacanariBodyNorm"));
	objNorms.push_back(gameObjectData->at("pacanariCollarNorm"));
	objNorms.push_back(gameObjectData->at("pacanariLimbNorm"));
	objColor.push_back(gameObjectData->at("ballColor"));
	objColor.push_back(gameObjectData->at("cupColor"));
	objColor.push_back(gameObjectData->at("pacanariBodyColor"));
	objColor.push_back(gameObjectData->at("pacanariCollarColor"));
	objColor.push_back(gameObjectData->at("pacanariLimbColor"));
	objIndices[0] = make_pair(0, 0);
	objIndices[1] = make_pair(1, 1);
	objIndices[2] = make_pair(2, 2);
	objIndices[3] = make_pair(3, 3);
	objIndices[4] = make_pair(4, 4);
	objIndices[5] = make_pair(5, 4);
	objIndices[6] = make_pair(6, 4);
	objIndices[7] = make_pair(7, 4);
	setDefaultModelView(defaultView);
		
	cup = Cup();
	ball = Ball();
	cup.setPos(cups[0].x, cups[0].y, cups[0].z);
	modelViews[1] = glm::translate(defaultView,glm::vec3(cup.x, cup.z, cup.y));
	ball.Initialize(tees[0].x, tees[0].y, tees[0].z);
	camManager = new Camera(&ball);


}