Rik's Treehouse > Babbling in Binary > My Software > Orphanware > R2DToo > R2DToo Help > For the Programmer > onAgentDraw

onAgentDraw

Declaration
Parameters
Remarks
Revisions
Example

Declaration

void __stdcall onAgentDraw(
    int x,              // x-coordinate of agent
    int y,              // y-coordinate of agent
    pState state,       // array of agent state variables
    unsigned short &r,  // red intensity
    unsigned short &g,  // green intensity
    unsigned short &b   // blue intensity
);
Top of page

Parameters

x,y
Coordinates of agent.
state
Array of agent state variables.
r
Intensity of red colour. Passed by reference.
g
Intensity of green colour. Passed by reference.
b
Intensity of blue colour. Passed by reference.
Top of page

Remarks

This function must be provided by the model. It is called by the simulation to set the drawing colour for each site of the portal, depending on the state of the agent at the site. On enter r, g and b hold the colour after the last refresh and on exit they should hold the new colour values (each in the range 0..255). Each site defaults to black (r,g,b)=(0,0,0) on simulation start.

Note: it may seem more rational to assign each agent color state variables and have them updated simultaneously with the agent instead of providing this routine to update the color separately, but there is a reason for this approach: it is potentially faster. Since the graphic updates are detached from agent updates (except at the fastest framerate) there could be many agent updates between every frame. Performing all the calculations to set the agent color for frames which are never drawn would then be wasting CPU time.

Top of page

Revisions

API v1.5
  • new! Replaces colorAgent.
Top of page

Example

void __stdcall onAgentDraw(int x, int y, pState state, unsigned short &r, unsigned short &g, unsigned short &b) { if (state[0]) { // alive b=255; // newborns start blue if (++r>255) r=255; else return; // then go to violet if (++g>255) g=255; else return; // finally go to white } else { // dead: fade to black if (r-- == 0) r=0; if (g-- == 0) g=0; if (b-- == 0) b=0; } }
Top of page
[Rik's Office Hours] [Contact Rik]
Last updated: Fri Apr 30 2004, 1:42pm