Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Comprehensive help for camera code (http://www.chiefdelphi.com/forums/showthread.php?t=101249)

Method 26-01-2012 22:53

Comprehensive help for camera code
 
for(UINT32 x = 0; x < particles->size(); x++)
{
ParticleAnalysisReport& par = (*particles)[x];
if(par.center_mass_x_normalized > 0)
{
//right
}
if(par.center_mass_x_normalized < 0)
{
//left
}
}


This is a part of an example of tracking code.
I do not understand the purpose of the for, or why (*particles)[x] isn't just (*particles)
Is particles->size(); returning the number of particles or something? If so, wouldn't the code make the robot cycle through aiming at the different targets?

Bongle 27-01-2012 08:33

Re: Comprehensive help for camera code
 
It would indeed attempt to drive towards each particle in turn. I forget if I posted that particular code snippet, but what you'd probably want would be something like this, where you select a favourite particle. For example, here's code that selects the biggest particle:

Code:

ParticleAnalysisReport biggest = {0};
for(UINT32 x = 0; x < particles->size(); x++)
{
  ParticleAnalysisReport& par = (*particles)[x];
  if(par.particleArea > biggest.particleArea) // particleArea may not be the right member... I'm going from memory.
  {
    biggest = par;
  }
}
if(biggest .center_mass_x_normalized > 0)
{
//right
}
if(biggest .center_mass_x_normalized < 0)
{
//left
}

Of course, you may not want to drive towards the biggest particle, but rather the most backboard-shaped particle...

For your syntax question:
particles is a pointer to a vector<ParticleAnalysisReport>. Therefore, to call member functions on it like size(), you need to use the arrow operator. To call the square-bracket operator, you need to indirect it using the * first to get yourself a non-pointer vector<ParticleAnalysisReport>.

particles->size() tells you how many particles there are in the list of particles.


All times are GMT -5. The time now is 17:41.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi