Пример #1
0
void ParticleRender::drawParticles(const ParticleList &particles) {
	ci::gl::ScopedTextureBind	stb(mTexture);
	// Prevent writing to the depth buffer, which will block out
	// pixels that are supposed to be transparent.
	ci::gl::ScopedDepthWrite	sdw(false);
	ci::gl::ScopedBlendAlpha	sba;
	ci::gl::color(1.0f, 1.0f, 1.0f, 1.0f);

	size_t						k = 0, size = particles.size();
	while (size >= BUFFER_SIZE) {
		drawParticles(k, k + BUFFER_SIZE, particles);
		k += BUFFER_SIZE;
		size -= BUFFER_SIZE;
	}
	drawParticles(k, particles.size(), particles);
}
Пример #2
0
void tracker::draw(int debug, int kinectWidth, int kinectHeight) {
	if (debug == 0) {
		float ox = 10 + ofMap(posSmooth.x, 0, kinectWidth, 0, 400);
		float oy = 320 + ofMap(posSmooth.y, 0, kinectHeight, 0, 300);
		ofFill();
		ofSetColor(255, 0, 0);
		ofCircle(ox, oy, 2);
		ofCircle(ox + 410, oy, 5);
		ofDrawBitmapString("blob id:" + ofToString(id), ox+5, oy+5);
	} else {
		float ox = posScreen.x;
		float oy = posScreen.y;
		float hw = ofGetWidth()/2;
		r = 63 + (int)((1-min(ox/hw, 1.0f))*189);
		g = 63 + (int)(abs((ox>hw ? ox-(hw*2) : ox) / hw) * 189);
		b = 63 + (int)(max(( (ox - hw) / hw), 0.0f) * 189);
		ofFill();
		ofSetColor(r, g, b);
		ofCircle(ox, oy, size);
		ofNoFill();
		ofCircle(ox, oy, size);
		size += (sizeTarget - size)*0.2;
		if (debug == 1) {
			ofSetColor(255, 255, 255);
			ofDrawBitmapString("blob id:" + ofToString(id), ox+10, oy+5);
		}
		if (debug == 2)
			drawParticles();
	}
}
static Bool
wizardPaintOutput (CompScreen           *s,
		const ScreenPaintAttrib *sa,
		const CompTransform     *transform,
		Region                  region,
		CompOutput              *output,
		unsigned int            mask)
{
    Bool           status;
    CompTransform  sTransform;

    WIZARD_SCREEN (s);

    UNWRAP (ws, s, paintOutput);
    status = (*s->paintOutput) (s, sa, transform, region, output, mask);
    WRAP (ws, s, paintOutput, wizardPaintOutput);

    if (!ws->ps || !ws->ps->active)
	return status;

    matrixGetIdentity (&sTransform);

    transformToScreenSpace (s, output, -DEFAULT_Z_CAMERA, &sTransform);

    glPushMatrix ();
    glLoadMatrixf (sTransform.m);

    drawParticles (s, ws->ps);

    glPopMatrix ();

    glColor4usv (defaultColor);

    return status;
}
Пример #4
0
void navigateToWaypoint(float xtarget, float ytarget)
{
    while(!atTarget(xtarget, x) || (!atTarget(ytarget, y)))
    {
        float distance = calcDistance(xtarget, ytarget);
        float angle = calcAngle(xtarget, ytarget);

        float driveDistance = 0; //initialise
        if (distance < stepDistance)
        {
            driveDistance = distance;
        }
        else
        {
            driveDistance = stepDistance;
        }

        // co-ordinate system is different so cos and sin are swapped - take from current location not origin
        float tempWaypointX = x + (driveDistance * cos(angle));
        float tempWaypointY = y + (driveDistance * sin(angle));


        driveToWaypoint(tempWaypointX, tempWaypointY);
        monteCarlo();

        eraseDisplay();
        drawMap();
        drawParticles();
        wait1Msec(100);

    }

    PlayTone(784, 15);
}
Пример #5
0
void drawGame(Game* game)
{
	setDrawColor(game, game->clearColor);
	SDL_RenderClear(game->renderer);
	
	drawBackground(game);
	
	for(int i = 0; i < MAX_ENTITIES_PER_GAME; ++i)
		if(game->entities[i].alive)
			drawEntity(game, &game->entities[i]);
			
	drawBehaviorPools(game, &game->behaviorPools);
	drawParticles(game);
	
	sortRenderQueue(game);
	flushRenderQueue(game);

	SDL_RenderPresent(game->renderer);
	
	game->frameTimer += game->delta;
	game->frameCounter++;
	if(game->frameTimer > 1)
	{
		game->frameTimer -= 1;
		if(game->frameTimer > 1)
			game->frameTimer = 0;
			
		game->fps = game->frameCounter;
		game->frameCounter = 0;
	}
}
Пример #6
0
/* display function - GLUT display callback function
 *		clears the screen, sets the camera position, draws the ground plane and movable box
 */
void display(void)
{
    
	//float origin[] = {0,0,0,1};
	float m_amb[] = {0.33, 0.22, 0.03, 1.0};
	float m_dif[] = {1, 0, 0, 1.0};
	float m_spec[] = {0.99, 0.91, 0.81, 1.0};
	float shiny = 60;
    
    
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
    
    
	gluLookAt(camPos[0], camPos[1], camPos[2], 0,0,0, 0,1,0);
    glColor3f(1,1,1);
    
    
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, m_amb);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, m_dif);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, m_spec);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shiny);
    
    drawParticles();
    
    drawObjects();
    
    drawMenu();
    

	glutSwapBuffers();
}
Пример #7
0
//--------------------------------------------------------------
void ofApp::draw(){
	ofClear(0,0);
	if (doDrawCamBackground.get())
		drawSource();
		
		
	if (!toggleGuiDraw) {
		ofHideCursor();
		drawComposite();
	}
	else {
		ofShowCursor();
		switch(drawMode.get()) {
			case DRAW_COMPOSITE: drawComposite(); break;
			case DRAW_PARTICLES: drawParticles(); break;
			case DRAW_FLUID_FIELDS: drawFluidFields(); break;
			case DRAW_FLUID_DENSITY: drawFluidDensity(); break;
			case DRAW_FLUID_VELOCITY: drawFluidVelocity(); break;
			case DRAW_FLUID_PRESSURE: drawFluidPressure(); break;
			case DRAW_FLUID_TEMPERATURE: drawFluidTemperature(); break;
			case DRAW_FLUID_DIVERGENCE: drawFluidDivergence(); break;
			case DRAW_FLUID_VORTICITY: drawFluidVorticity(); break;
			case DRAW_FLUID_BUOYANCY: drawFluidBuoyance(); break;
			case DRAW_FLUID_OBSTACLE: drawFluidObstacle(); break;
			case DRAW_FLOW_MASK: drawMask(); break;
			case DRAW_OPTICAL_FLOW: drawOpticalFlow(); break;
			case DRAW_SOURCE: drawSource(); break;
			case DRAW_MOUSE: drawMouseForces(); break;
			case DRAW_VELDOTS: drawVelocityDots(); break;
		}
		drawGui();
	}
}
Пример #8
0
void Render::drawParticleSystem(const b2ParticleSystem *s, float worldScale) noexcept
{
    assert(s->GetParticleGroupCount() > 0);
    float depth = ((Matter*)(s->GetParticleGroupList()->GetUserData()))->getDepth();
    float displayedScale = ((ParticleSystem*)(s->GetParticleGroupList()->GetUserData()))->getDisplayedRadiusScale();
    drawParticles(s->GetPositionBuffer(), PARTICLE_RADIUS * displayedScale / worldScale, s->GetColorBuffer(), s->GetParticleCount(), depth);
}
Пример #9
0
void ParticleTrace :: draw ( bool bUpdated )
{
	if( !bImageLoaded )
		return;
	
	ofEnableAlphaBlending();
	
    //----
    
    glPushMatrix();
    glTranslatef( imgRectCurrent.x, imgRectCurrent.y, 0 );

	drawSourceImage();
	drawToTraceImage( bUpdated );
    drawTraceImage();
	drawParticles( bUpdated );
    
    glPopMatrix();
    
    //----

    drawRectOutline( activeRect );
    drawRectOutline( imgRectCurrent );
	drawSamples();
}
Пример #10
0
void main(void) {
  int gd = CUSTOM, gm = CUSTOM_MODE(1024,768);
  int page = 0;
  g_mousestate curState;
  g_mousestate oldState;
  int scrolling = 0;
  
  initgraph(&gd, &gm, "");
  
  initParticles(particles);
  
  while(!anykeypressed()) {
    getmousestate(&curState);
    if((curState.buttons & MOUSE_LEFTBUTTON) == 0) {
      scrolling = 0;
    } else {
      if(scrolling == 0) {
        scrolling = 1;
        getmousestate(&oldState);
      } else {
        orgX -= -curState.x + oldState.x;
        orgY += -curState.y + oldState.y;
        oldState = curState;
      }
    }
    updateParticles(particles, particles2);
	setactivepage(1 - page);
    clearviewport();
	drawParticles(particles);
	setvisualpage(1 - page);
    page = 1 - page;
	delay(4);
  }
  closegraph();
}
void ParticleExplosionNode2::draw(std::stack<QMatrix4x4> &MVStack, QMatrix4x4 cameraMatrix, QMatrix4x4 projectionMatrix, QOpenGLShaderProgram *shader) {
    //If the node is a leaf, draw its contents
    if(leaf) {
        GBuffer::activeGBuffer()->drawToFinal();
        Shaders::bind(Shaders::particleProgram);
//    Scene::passLights(cameraMatrix, Shaders::phongProgram);
        MVStack.push(MVStack.top());

        MVStack.top().translate(this->translation);

        //Convert the quat to a matrix, may be a performance leak.
        QMatrix4x4 tempRot;
        tempRot.rotate(this->rotation.normalized());
        MVStack.top() *= tempRot;

		lastCameraRotation = Camera::M4toQuat(cameraMatrix);

        glUniformMatrix4fv(Shaders::particleProgram->uniformLocation("modelViewMatrix"), 1, GL_FALSE, MVStack.top().constData());
        glUniformMatrix4fv(Shaders::particleProgram->uniformLocation("perspectiveMatrix"), 1, GL_FALSE, projectionMatrix.constData());

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, sprite);
        glUniform1i(Shaders::particleProgram->uniformLocation("sprite"), 0);

        drawParticles();

        MVStack.pop();
        Shaders::release(Shaders::particleProgram);
        GBuffer::activeGBuffer()->bindGeometryPass();
    } else {
        //Else, recurse into its children
        std::for_each(children.begin(), children.end(), [&MVStack, cameraMatrix, projectionMatrix, shader](SceneGraph *s){s->draw(MVStack, cameraMatrix, projectionMatrix, shader);});
    }
}
Пример #12
0
void View::paintParticlesGL()
{
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE);//could use GL_SRC_ALPHA, experiment
    updateParticleManagers();
    drawParticles();
    glDisable(GL_BLEND);
}
Пример #13
0
void View::paintParticles(){
    //possibly clear some buffers

    glEnable(GL_BLEND);
    updateParticleManagers();
    drawParticles();
    glDisable(GL_BLEND);
}
Пример #14
0
void display()
{
    handleFps();
    
    if(show_betaballs)
    	drawBetaBalls();
    else
        drawParticles();
    
}
Пример #15
0
task main()
{
	eraseDisplay();

	drawMap();

	drawParticles();

	wait1Msec(5000);

}
Пример #16
0
//--------------------------------------------------------------
void testApp::draw() {
	ofBackgroundGradient(ofColor(10,10,10), ofColor::black, OF_GRADIENT_CIRCULAR);
    easyCam.begin();
    drawFloor();
    drawParticles();

    easyCam.end();
    kinect.drawDepth(0, 0, 160, 120);
//    background.drawSmoothedBg(0, 130, 160, 120);
    drawDebugText();
}
Пример #17
0
void Water3D::draw(){
    
    static double deg = 30;
    deg += 0.1;
    glRotated(45, 1, 1, 0);
    glRotated(deg, 0, 1, 0);
    glScaled(1.0/1500.0, 1.0/1500.0, 1.0/1500.0);
    //drawCellTypes();
    //drawMAC();
    drawParticles();
    //drawCenterVelocities();
    //drawFaceVelocities();
}
Пример #18
0
// ------------ Draw
void wavesScene::draw(){
    drawBackground();

    if(gradientWaves.isEnabled) {
        gradientWaves.draw();
        drawPeople();
    }
    if(stencilWaves.isEnabled) stencilWaves.draw();
    ofEnableAlphaBlending();
    if(stencilWaves.isEnabled) {
        drawParticles();
    }
}
void drawParticleSystems (CompWindow * w)
{
    ANIMADDON_WINDOW (w);

    if (aw->eng.numPs && !WINDOW_INVISIBLE(w))
    {
	int i = 0;

	for (i = 0; i < aw->eng.numPs; i++)
	{
	    if (aw->eng.ps[i].active)
		drawParticles (w, &aw->eng.ps[i]);
	}
    }
}
Пример #20
0
//--------------------------------------------------------------
void FluidManager::draw(int _mode){
    
    switch(_mode) {
        case DRAW_COMPOSITE: drawComposite(); break;
        case DRAW_PARTICLES: drawParticles(); break;
        case DRAW_FLUID_FIELDS: drawFluidFields(); break;
        case DRAW_FLUID_DENSITY: drawFluidDensity(); break;
//        case DRAW_FLUID_TEMPERATURE: drawFluidTemperature(); break;
//        case DRAW_FLUID_DIVERGENCE: drawFluidDivergence(); break;
//        case DRAW_FLUID_VORTICITY: drawFluidVorticity(); break;
//        case DRAW_FLUID_BUOYANCY: drawFluidBuoyance(); break;
        case DRAW_FLUID_OBSTACLE: drawFluidObstacle(); break;
//        case DRAW_OPTICAL_FLOW: drawOpticalFlow(); break;
        case DRAW_SOURCE: drawSource(); break;
    }

}
Пример #21
0
void
drawParticleSystems(CompScreen *s, CompWindow *w)
{
   ANIM_WINDOW(w);

   if (aw->numPs)
     {
        int i = 0;

        for (i = 0; i < aw->numPs; i++)
          {
             if (aw->ps[i].active && !WINDOW_INVISIBLE(w))
               {
                  drawParticles(s, w, &aw->ps[i]);
               }
          }
     }
}
Пример #22
0
void draw() {
    
    // The camera will modify the view of everything between camera.being()
    // and camera.end().  
    camera.begin();
    
    // Draw the bounding box.
    drawBoundingBox();
    
    // Draw the particles.
    drawParticles();
    
    // Draw lines connecting the particles.
    drawParticleLines();
    
    // End the camera.
    camera.end();
    
}
Пример #23
0
void display(void) {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    cgGLBindProgram(cg_vertex_program);
    checkForCgError("binding vertex program");

    cgGLEnableProfile(cg_vertex_profile);
    checkForCgError("enabling vertex profile");
    // parameter

    //cgGLSetParameter1f(cg_parameter_vertex_scale_factor, 0.7);
    //cgGLSetParameter1f(cg_parameter_vertex_rotation, rotation);

    // Zeit die seit dem rendern des letzten Bildes vergangen ist:
    cgGLEnableTextureParameter(cg_parameter_vertex_time);
    t = diff_seconds();
    glVertex2f(0.0f, 0.0f);
    glTexCoord1f(Particle->t);
    cgGLDisableTextureParameter(cg_parameter_vertex_time);
    // Berechnung der Framerate mit Hilfe der Zeitmessungsfunktion:
    frames++;
    timer += t;
    if (timer > 1.0) {
        printf("Frames per second: %i\n", frames);
        timer -= 1.0;
        frames = 0;

        printf("Number of particles: %d\n", water_list.size());
    }
    //cgGLEnableTextureParameter(cg_parameter_vertex_velocity);
    drawParticles(water_list,water_tex);
    //glVertex2f(0.0f, 0.0f);
    //glTexCoord3fv(Particle->velocity);
    //cgGLDisableTextureParameter(cg_parameter_vertex_velocity);



    cgGLDisableProfile(cg_vertex_profile);
    checkForCgError("disabling vertex profile");

    glutSwapBuffers();
}
Пример #24
0
//--------------------------------------------------------------
void ofApp::draw()
{
    ofClear(0,0);
    
    if (!toggleGuiDraw) {
        ofHideCursor();
        drawComposite();
    }
    else {
        ofShowCursor();
        switch(drawMode.get()) {
            case DRAW_COMPOSITE: drawComposite(); break;
            case DRAW_PARTICLES: drawParticles(); break;
            case DRAW_FLUID_DENSITY: drawFluidDensity(); break;
            case DRAW_VELDOTS: drawVelocityDots(); break;
        }
        drawGui();
    }
    
    if (debug) {
        tuioClient.drawCursors();
    }
}
Пример #25
0
task main() {
	clearDebugStream();
	nMotorEncoder[LEFT_WHEEL] = 0;
	nMotorEncoder[RIGHT_WHEEL] = 0;

	bPlaySounds = true;
	set_starting_position(84.0, 30.0, 0.0);

	drawMap();

	StartTask(vehicle_compute_position);
	//StartTask(vehicle_draw_position);

	navigate_to_waypoint(104, 30);
	drawParticles();
	navigate_to_waypoint(124, 30);
	drawParticles();
	navigate_to_waypoint(144, 30);
	drawParticles();
	navigate_to_waypoint(180, 30);
	drawParticles();
	navigate_to_waypoint(180, 54);
	drawParticles();
	navigate_to_waypoint(164, 54);
	drawParticles();
	navigate_to_waypoint(126, 54);
	drawParticles();
	// Moved left
	// Going up
	navigate_to_waypoint(126, 74);
	drawParticles();
	navigate_to_waypoint(126, 94);
	drawParticles();
	navigate_to_waypoint(126, 104);
	drawParticles();
	navigate_to_waypoint(126, 124);
	drawParticles();
	navigate_to_waypoint(126, 144);
	drawParticles();
	navigate_to_waypoint(126, 168);
	drawParticles();
	navigate_to_waypoint(126, 148);
	drawParticles();
	navigate_to_waypoint(126, 126);
	drawParticles();
	// From here, move in 20 cm ranges
	navigate_to_waypoint(30, 54);
	drawParticles();
	navigate_to_waypoint(84, 54);
	drawParticles();
	navigate_to_waypoint(84, 30);
	drawParticles();

  StopTask(vehicle_compute_position);
  //StopTask(vehicle_draw_position);

  wait10Msec(60000); // wait 1MIN
}
int main( int argc, char *argv[] ) {

    int webcamRun = 0;
    
    CvCapture *capture = 0;
    CvCapture *stereoCapture = 0;
    
    CvCapture **cptPtr = &capture;
    CvCapture **scptPtr = &stereoCapture;
    
    initCaptureFiles( argc, argv, cptPtr, scptPtr, &webcamRun, &enable3D );
  
  
  
  char locationMean[300];
  char locationCov[300];
  strncpy( locationMean, argv[1], 300 );
  strncpy(  locationCov, argv[2], 300 );
  
  
  
  /* check for stereo file */  
  
  
  
  if( !enable3D ) {
    displayStereoFrame   = 0;
    displayPositionFrame = 0;
    depthScaling         = 0;
  }
  
    
  /* Fast-forwards through the video to the action */
  int kl;
  for( kl = 0; kl < 100 && webcamRun == 0; kl++ ) {
    cvQueryFrame( capture );
    if( enable3D ) cvQueryFrame( stereoCapture );
  }
    
    
  /*
      Housekeeping
  */
  
  int maxBox[10];
  // this should be in the relevant file
  //! Create matrix files to hold intermediate calculations for likelihood
  
  
  
  


  /* this should have its own matrix setup function and not be hard-coded */
  //! Create N-dimensional matrices to hold mean and cov data
  int backMeanSizes[] = {_sizeY,_sizeX,4,_numResponses};
  int backCovSizes[]  = {_sizeY,_sizeX,4,_numResponses};

  CvMatND *backMean = cvCreateMatND( 4, backMeanSizes, CV_32F );
  CvMatND *backCov  = cvCreateMatND( 4, backCovSizes,  CV_32F );

  /* Fix this */
  if( webcamRun ) {
    backMean = (CvMatND*) cvLoad( "D:/Will/Dropbox/My Dropbox/Project/Matlab/backMean.xml", NULL, NULL, NULL );
    backCov  = (CvMatND*) cvLoad( "D:/Will/Dropbox/My Dropbox/Project/Matlab/backCov.xml", NULL, NULL, NULL );
  } else {
    backMean = (CvMatND*) cvLoad( locationMean, NULL, NULL, NULL );
    backCov  = (CvMatND*) cvLoad( locationCov, NULL, NULL, NULL );
  }
  
  /* end here */
  
  
  CvMat *imgLikelihood = cvCreateMat( 48, 64, CV_32F );
  


  img  = cvLoadImage( "foreground8/image (1).jpg", CV_LOAD_IMAGE_COLOR );
  yImg = cvLoadImage( "foreground8/image (1).jpg", CV_LOAD_IMAGE_COLOR );
  cvNamedWindow( "Tracker", CV_WINDOW_AUTOSIZE );
  
  
  /* Condensation stuff */
  ConDens = cvCreateConDensation( DP, MP, nSamples );
  
  bx = 320; by = 240;
	//hm = 0; //vm = 0;

  /* Initialize the random number generator */
	rng_state = cvRNG(0xffffffff);
 
  initializeCondensation();
  
  /* This allows us to change the probabiity with which Condensation alters each variable */
  cvRandInit( &(ConDens->RandS[0]), -75, 75, 0, CV_RAND_UNI);
  cvRandInit( &(ConDens->RandS[1]),  -5,  5, 1, CV_RAND_UNI);
  cvRandInit( &(ConDens->RandS[2]),  -5,  5, 2, CV_RAND_UNI);
  cvRandInit( &(ConDens->RandS[3]),  -2,  2, 3, CV_RAND_UNI);
  
  cvRandInit( &(ConDens->RandS[4]), -75, 75, 4, CV_RAND_UNI);
  cvRandInit( &(ConDens->RandS[5]),  -5,  5, 5, CV_RAND_UNI);
  cvRandInit( &(ConDens->RandS[6]),  -5,  5, 6, CV_RAND_UNI);
  cvRandInit( &(ConDens->RandS[7]),  -2,  2, 7, CV_RAND_UNI);
  
  /*
    If we have depth scaling, the depth controls the width & height of the box
    So we don't want any randomness
  */
  if( depthScaling ) {
    cvRandInit( &(ConDens->RandS[3]),  0,  0, 3, CV_RAND_UNI);
    cvRandInit( &(ConDens->RandS[7]),  0,  0, 7, CV_RAND_UNI);
  }

  
  IplImage* heatFrame = NULL;
  heatFrame = cvQueryFrame( capture );
  if(enable3D) cvQueryFrame( stereoCapture ); // making sure they stay in sync (and init positionFrame)
  
  
  int frameNumb = 0;
  // int mjk;
  // for( mjk = 0; mjk < 320; mjk++ ) {
    // cvQueryFrame( capture );
    // cvQueryFrame( stereoCapture );
    // frameNumb++;
  // }
  

  
  positionFrame = cvCreateImage(cvSize(640, 510), 8, 3);
  
  
  int trailLength = 20;
  int planX1Pos[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  int planX2Pos[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  int planZ1Pos[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  int planZ2Pos[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  

  int key = 0;
  double totalTime = 0;
  int totalFrames = 0;
  
  
  
  while( key != 'q' ) {
  
    // stopCount++;
    // strcpy(frameNameTemp, frameName);
    // itoa(stopCount, frameCount, 10);
    // strcat( frameNameTemp, frameCount);
    // strcat(frameNameTemp, ".jpg");
    // cvSaveImage(frameNameTemp, positionFrame, 0);
    
    
    /* Start timing */
    clock_t start = clock();
        
        frameNumb++;
        printf("Frame %d\n", frameNumb);
        if( frameNumb == 210 ) {
          for( ; frameNumb < 290; frameNumb++ ) {
            cvQueryFrame( capture );
            cvQueryFrame( stereoCapture );
          }
        }
        
        if( frameNumb == 350 ) {
          return(0);
        }
        
        /* Get the first video frame, and maybe stereo frame */
        frame = cvQueryFrame( capture );
        if(enable3D) stereoFrame = cvQueryFrame( stereoCapture );
        
        
        /* Double-check that we haven't reached the end */
        if( !frame ) break;
        if( enable3D ) if( !stereoFrame ) break;
        
        
        /* Compute likelihoods for new frame, using mean and cov */
        likelihood( frame, backMean, backCov, imgLikelihood );
        
        /* Update the Condensation model using new likelihoods */
        updateCondensation( 0, 0, imgLikelihood, maxBox );

        /* Maybe display the Condensation particles */
        if( displayParticles ) 
          drawParticles();

        /* Draw tracking boxes onto the video and stereo video frame */
        drawTrackingBoxes( 0, maxBox, frame, stereoFrame );
        drawTrackingBoxes( 1, maxBox, frame, stereoFrame );

        /* Show the latest video frame (with boxes and particles) */
        cvShowImage( "Tracker", frame );

        /* Maybe show latest stereo depth frame */
        if( displayStereoFrame )
          cvShowImage( "Stereo", stereoFrame );
      
        /* Maybe show latest position map */
        if( displayPositionFrame )
          drawPositionTrail( maxBox, trailLength, 
                             depth, 
                             planX1Pos, planX2Pos, planZ1Pos, 
                             planZ2Pos, positionFrame );
        
        /* Maybe show the heat map of the input image (the likelihood for each patch) */
        if( displayHeatFrame ) {
          drawHeatmap( maxBox, imgLikelihood, heatFrame );
          cvShowImage( "Heat", heatFrame );
        }
        
        /* Update previous x, y positions */
        prevX[0] = maxBox[0]; prevY[0] = maxBox[1];
        prevX[1] = maxBox[4]; prevY[1] = maxBox[5];
        
        
        /* Calculate fps and average fps */
        printf("fps: %3.1f, ", (double)1/(((double)clock() - start) / CLOCKS_PER_SEC));
        totalTime = totalTime + (double)1/(((double)clock() - start) / CLOCKS_PER_SEC);
        totalFrames++;
        printf(" average fps %3.1f", totalTime/totalFrames);
        
        /* Check for key presses */
        key = cvWaitKey( 50 );
        
        /* Enable debugging mode */
        if( key == 'd' ) {
          debug = 1;
          printf("\n*********\n\nDebug: ON\n\n*********\n");
        }
        
        /* Enable debugging mode */
        if( key == 'p' ) {
          if( stateDraw )
            stateDraw = 0;
          else
            stateDraw = 1;
          printf("\n*********\n\nParticle Drawing Toggled\n\n*********\n");
        }

    }
  
  printf("\n\nquitting");

//cvReleaseVideoWriter( &writerTracker );
cvReleaseImage( &img );
cvReleaseImage( &frame );
cvDestroyWindow( "Tracker" );
cvDestroyWindow( "Heat" );
cvDestroyWindow( "Stereo" );
cvDestroyWindow( "Position" );

return(0);

}
Пример #27
0
void draw()
{
	drawMap();
	drawPosition(x, y);
	drawParticles();
}
Пример #28
0
void engine_run(struct enginevars *vars, int *types, int typeLength , enum engine_runtime runtime) {
	
	int x;
	
	struct timespec hold;
	hold.tv_sec  = 0;
	hold.tv_nsec = 1666666;
	
	glTf_x = 0.0f;
	glTf_y = 0.0f;
	glTf_z = 0.0f;
	
	glrf_x = 0.0f;
	glrf_y = 0.0f;
	glrf_z = 0.0f;
	
	angle  = 0.0f;
	
	SDL_GLContext glcontext = SDL_GL_CreateContext(Window);
	
	glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
	glMatrixMode(GL_MODELVIEW);
	
	if (runtime == NORMAL) {
	
		while (systemFinished == 0) {
		
			glClear(GL_COLOR_BUFFER_BIT);
			glLoadIdentity();
	
			for ( x = 0; x < typeLength; x++ ) {
		
				switch (types[x]) {
				
					case 1: drawParticles( &vars->readyElectron , &vars->readyProton ); break;
					case 2: draw_default_flat_plane(); break;
			
				}
		
			}
			
			SDL_GL_SwapWindow(Window);
			nanosleep( &hold , NULL );
		
		}
		
	} else {
	
		while (systemFinished == 0) {
		
			glClear(GL_COLOR_BUFFER_BIT);
			glLoadIdentity();
			
			SDL_GL_SwapWindow(Window);
			nanosleep( &hold , NULL );
			
		}
		
	}
	SDL_GL_DeleteContext(glcontext);
	
}
//-----------------------------------------------------------------------------------------
//
void ParticleSystemInstancedGeometryGPU::draw( ofCamera* _camera )
{
	drawParticles( &particleDraw, _camera );
}
Пример #30
0
int
main(int argc, char *argv[])
{
    SDL_Window *window;         /* main window */
    SDL_GLContext context;
    //int w, h;
    Uint32 startFrame;          /* time frame began to process */
    Uint32 endFrame;            /* time frame ended processing */
    Uint32 delay;               /* time to pause waiting to draw next frame */
    int done;                   /* should we clean up and exit? */

    /* initialize SDL */
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        fatalError("Could not initialize SDL");
    }
    /* seed the random number generator */
    srand(time(NULL));
    /*      
       request some OpenGL parameters
       that may speed drawing
     */
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
    SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0);
    SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
    //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);

    /* create main window and renderer */
    window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
                                SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN |
                                SDL_WINDOW_BORDERLESS);
    context = SDL_GL_CreateContext(window);

    /* load the particle texture */
    initializeTexture();

    /*      check if GL_POINT_SIZE_ARRAY_OES is supported
       this is used to give each particle its own size
     */
    pointSizeExtensionSupported = SDL_GL_ExtensionSupported("GL_OES_point_size_array");

    /* set up some OpenGL state */
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    SDL_GetWindowSize(window, &screen_w, &screen_h);
    glViewport(0, 0, screen_w, screen_h);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrthof((GLfloat) 0,
             (GLfloat) screen_w,
             (GLfloat) screen_h,
             (GLfloat) 0, 0.0, 1.0);

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

    glEnable(GL_POINT_SPRITE_OES);
    glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, 1);

    if (pointSizeExtensionSupported) {
        /* we use this to set the sizes of all the particles */
        glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
    } else {
        /* if extension not available then all particles have size 10 */
        glPointSize(10);
    }

    done = 0;
    /* enter main loop */
    while (!done) {
        startFrame = SDL_GetTicks();
        SDL_Event event;
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT) {
                done = 1;
            }
            if (event.type == SDL_MOUSEBUTTONDOWN) {
                int x, y;
                SDL_GetMouseState(&x, &y);
                spawnEmitterParticle(x, y);
            }
        }
        stepParticles();
        drawParticles();
        SDL_GL_SwapWindow(window);
        endFrame = SDL_GetTicks();

        /* figure out how much time we have left, and then sleep */
        delay = MILLESECONDS_PER_FRAME - (endFrame - startFrame);
        if (delay > MILLESECONDS_PER_FRAME) {
            delay = MILLESECONDS_PER_FRAME;
        }
        if (delay > 0) {
            SDL_Delay(delay);
        }
    }

    /* delete textures */
    glDeleteTextures(1, &particleTextureID);
    /* shutdown SDL */
    SDL_Quit();

    return 0;
}