|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
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? |
|
#2
|
||||
|
||||
|
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
}
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. Last edited by Bongle : 27-01-2012 at 08:36. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|