void ZLViewWidget::onScrollbarPageStep(ZLView::Direction direction, int steps) { if (!myView.isNull()) { bool invert = false; correctDirection(direction, invert); myView->onScrollbarPageStep(direction, invert ? -steps : steps); } }
void ZLViewWidget::onScrollbarPageStep(ZLView::Direction direction, int steps) { if (myView) { bool invert; correctDirection(direction, invert); myView->onScrollbarPageStep(direction, invert ? -steps : steps); } }
void ZLViewWidget::onScrollbarMoved(ZLView::Direction direction, size_t full, size_t from, size_t to) { if (!myView.isNull()) { bool invert = false; correctDirection(direction, invert); if (invert) { size_t tmp = full - from; from = full - to; to = tmp; } myView->onScrollbarMoved(direction, full, from, to); } }
// Perform one step of the simulation. // The current positions and directions are in Px, Py, Vx, and Vy // There are N fish. // The ratio of orientation to attraction is r // The new positions and directions should be placed in // newPx, newPy, newVx, and newVy. // All position/direction vectors have been allocated and are of length N. void fishStep(float *Px, float *Py, float *Vx, float *Vy, int N, float r, float *newPx, float *newPy, float *newVx, float *newVy, float attractRadius) { const float REPULSE_FACTOR=1.0f; const float ATTRACT_FACTOR=attractRadius; //in this: //w_o=r, w_a=1. since normalized. float w_a=1.0, w_o=r; const float speed = 1.0; const float tau = 0.2; const float max_turn=115.0f; const float blind_angle=10.0f; int i,j; //for each "goal" fish: //calculate vector: for(i=0;i<N;i++){ //if fish i finds at least one fish in zone of repulsion: //need to update according to equation: //v_i(t+\tao)=\sum_j\neq i \frac{c_j(t)-c_i(t)}{|c_j(t)-c_i(t)|} //where c_j and c_i are actual locations of the fish. //make a list of indices of fish in that zone(use j as index) //then ,set new v_x[i] and new v_y[i] according to average direction to all //the Px[j] and Py[j] // ELSE: // if agents are not found within zone of repultion, then it will align // itself with...(see paper) // make a list of fish in the zone // set new vx, new vy using weighted average of positions and directions // of those fish. //END::update position float newx_1=0.0f,newy_1=0.0f; float newx_7=0.0f,newy_7=0.0f, newvectx_7=0.0f, newvecty_7=0.0f; int fishInOne=0; int fishInTwo=0; for(j=0;j<N;j++){ //test for blind spot. first calc the vector: float temp_x=Vx[j]-Vx[i]; float temp_y=Vy[j]-Vy[i]; if(fabs(findAngle(Vx[i],Vy[i],temp_x,temp_y))<(RAD((360.0-blind_angle)/2)) ){ //otherwise do nothing.... //if in repulsion: float dist; if((dist=distance(Px[i],Py[i],Px[j],Py[j]))<=REPULSE_FACTOR && i!=j){ //do equation 1(normalized) newx_1-=(Px[j]-Px[i])/dist; newy_1-=(Py[j]-Py[i])/dist; fishInOne=1; } //attraction factor. //according to Stephanie: //"I do not exclude fish i from the list of fish within fish i's zone of //attraction" else if(dist<=ATTRACT_FACTOR){ if(i!=j){ newx_7+=(Px[j]-Px[i])/dist; newy_7+=(Py[j]-Py[i])/dist; } newvectx_7+=(Vx[j])/(norm(Vx[j],Vy[j])); newvecty_7+=(Vy[j])/(norm(Vx[j],Vy[j])); fishInTwo=1; } } } //end calculation for one fish: if(fishInOne){ //ADJUSTING for turning too much: //if new angle is 115 degrees float turn_angle; if(fabs(turn_angle=findAngle(Vx[i],Vy[i],newx_1,newy_1))<=(RAD(max_turn)*tau)){ newVx[i]=newx_1; newVy[i]=newy_1; } else{ //only turn max_turn degrees... //BUT! need to take into account the speed and time step (tau) //115 degress per 1 tau? turn_angle=RAD(max_turn)*(turn_angle<0 ? -1:1)*(tau); newVx[i]=Vx[i]*cos(turn_angle)-sin(turn_angle)*Vy[i]; newVy[i]=Vx[i]*sin(turn_angle)+cos(turn_angle)*Vy[i]; } } else if(fishInTwo){ newx_7*=w_a; newy_7*=w_a; newvectx_7*=w_o; newvecty_7*=w_o; newVx[i]=newx_7+newvectx_7; newVy[i]=newy_7+newvecty_7; float turn_angle; if(fabs(turn_angle=findAngle(Vx[i],Vy[i],newVx[i],newVy[i]))<=(RAD(max_turn)*tau)){ //do nothing } else{ //only turn max_turn degrees... turn_angle=RAD(max_turn)*(turn_angle<0 ? -1:1)*tau; newVx[i]=Vx[i]*cos(turn_angle)-sin(turn_angle)*Vy[i]; newVy[i]=Vx[i]*sin(turn_angle)+cos(turn_angle)*Vy[i]; } } //correctDirection: correctDirection((newVx+i),(newVy+i),Vx[i],Vy[i]); //update locationm, eq(3): newPx[i]=(speed*tau*newVx[i])+Px[i]; newPy[i]=(speed*tau*newVy[i])+Py[i]; } } // end fishStep