View Single Post
  #4   Spotlight this post!  
Unread 18-02-2007, 23:35
ace123's Avatar
ace123 ace123 is offline
Registered User
AKA: Patrick Horn
FRC #0008 (Paly Robotics - http://robotics.paly.net/)
Team Role: Programmer
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Palo Alto, CA
Posts: 50
ace123 has a spectacular aura aboutace123 has a spectacular aura about
Send a message via AIM to ace123
Re: Tracking only one Light

The way the example code does it is by taking the leftmost coordinate (x0) and adding a constant to it. This way it ignores the median value of the box.

Code:
int lowright_x = packet.x1, centroid_x = packet.mx, upleft_x = packet.x0, target_width=packet.x1-packet.x0;

if ( target_width > WIDEST_ONE_LIGHT  ) { // looking at two lights?
    targets = 2;
    
    if ( ( lowright_x - centroid_x) < (centroid_x - upleft_x) ) {
        // the centroid is nearer the right 
        target_x = lowright_x- HALF_LIGHT_WIDTH  ;
    } else {
        // the centroid is nearer the left
        target_x = upleft_x + HALF_LIGHT_WIDTH  ;
    }
} else { // the target is NOT wide, it's one light
    targets = 1;
    target_x = centroid_x; // target that light
}
__________________
-Patrick Horn, Paly Robotics

Check out the space simulator called Vega Strike, modelled after the space simulator games Elite and Wing Commander. It's Open Source too!
If you have ever played Wing Commander, or especially Privateer, and had a feeling of nostalga derived from the you will enjoy these two Vega Strike mods: Privateer Gemini Gold and Privateer Remake!
I'm working on adding multiplayer support this year...