bool TurbulenceParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps) { if(getBeacon() != NULL) { Matrix BeaconToWorld(getBeacon()->getToWorld()); Vec3f translation, tmp; Quaternion tmp2; BeaconToWorld.getTransform(translation,tmp2,tmp,tmp2); Pnt3f particlePos = System->getPosition(ParticleIndex); Real32 distanceFromAffector = particlePos.dist(Pnt3f(translation.x(),translation.y(),translation.z())); if((getMaxDistance() < 0.0) || (distanceFromAffector <= getMaxDistance())) //only affect the particle if it is in range { Real32 Xparam, Yparam, Zparam; Pnt3f pos(System->getPosition(ParticleIndex)); getPerlinDistribution()->setPhase(getPhase()[0]); Xparam = getPerlinDistribution()->generate(pos[0]); getPerlinDistribution()->setPhase(getPhase()[1]); Yparam = getPerlinDistribution()->generate(pos[1]); getPerlinDistribution()->setPhase(getPhase()[2]); Zparam = getPerlinDistribution()->generate(pos[2]); Vec3f fieldAffect(Vec3f(Xparam, Yparam, Zparam)); fieldAffect = fieldAffect * (getAmplitude()* (elps/(OSG::osgClamp<Real32>(1.0f,std::pow(distanceFromAffector,getAttenuation()),TypeTraits<Real32>::getMax())))); System->setVelocity(System->getVelocity(ParticleIndex) + fieldAffect, ParticleIndex); } // end distance conditional } // end null beacon conditional return false; }
/** This is the main interface to update the world. This function calls * update(), and checks then for the end of the race. Note that race over * handling can not necessarily be done in update(), since not all * data structures might have been updated (e.g.LinearWorld must * call World::update() first, to get updated kart positions. If race * over would be handled in World::update, LinearWorld had no opportunity * to update its data structures before the race is finished). * \param dt Time step size. */ void World::updateWorld(float dt) { if (m_schedule_pause) { pause(m_scheduled_pause_phase); m_schedule_pause = false; } else if (m_schedule_unpause) { unpause(); m_schedule_unpause = false; } if (m_self_destruct) { delete this; return; } // Don't update world if a menu is shown or the race is over. if( getPhase() == FINISH_PHASE || getPhase() == IN_GAME_MENU_PHASE ) return; update(dt); if( (!isFinishPhase()) && isRaceOver()) { enterRaceOverState(); } } // updateWorld
void aHandler(void* args) { // Get the gpio handle from the args mraa::Gpio *encA = (mraa::Gpio*)args; int a = aState; int b = bState; int newA = encA->read(); aState = newA; int prevPhase = getPhase(a, b); int curPhase = getPhase(newA, b); updateTick(prevPhase, curPhase); }
void bHandler(void* args) { // Get the gpio handle from the args mraa::Gpio *encB = (mraa::Gpio*)args; int a = aState; int b = bState; int newB = encB->read(); bState = newB; int prevPhase = getPhase(a, b); int curPhase = getPhase(a, newB); updateTick(prevPhase, curPhase); }
// ------------ Conversion between time and phase SUMOTime MSSimpleTrafficLightLogic::getPhaseIndexAtTime(SUMOTime simStep) const { SUMOTime position = 0; if (myStep > 0) { for (int i = 0; i < myStep; i++) { position = position + getPhase(i).duration; } } position = position + simStep - getPhase(myStep).myLastSwitch; position = position % myDefaultCycleTime; assert(position <= myDefaultCycleTime); return position; }
/* * Class: org_jbox2d_collision_broadphase_BroadPhaseJNI * Method: destroyProxy * Signature: (I)V */ JNIEXPORT void JNICALL Java_org_jbox2d_collision_broadphase_BroadPhaseJNI_destroyProxy (JNIEnv *env, jobject obj, jint proxy) { b2BroadPhase* tree = getPhase(env, obj); jobject data = (jobject) tree->GetUserData(proxy); env->DeleteGlobalRef(data); tree->DestroyProxy(proxy); }
void MFReconstruct::decodePatterns() { int w = cameraWidth; int h = cameraHeight; cv::Mat out(h,w,CV_64FC1); for(int row = 0; row < h; row++){ for(int col = 0; col < w; col++){ double phase = 0.0;//表示图像上(w,h)点在相位展开图上的相位值,每次循环进行一次初始化 getPhase(row, col, phase); if(mask.at<uchar>(row, col)){ ///if the pixel is not shadow, it's mask = 1, reconstruct out.at<double>(row,col) = phase; camPixels[(row*cameraWidth+col)].push_back(phase); } else out.at<double>(row,col) = 0; } } ///输出相位图 cv::normalize(out,out,255.0,0.0,cv::NORM_MINMAX); if (!processl) cv::imwrite(savePath_.toStdString()+"/L.png",out); else cv::imwrite(savePath_.toStdString()+"/R.png",out); }
bool TrafficLight::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) { switch (variable) { case TRACI_ID_LIST: return wrapper->wrapStringList(objID, variable, getIDList()); case ID_COUNT: return wrapper->wrapInt(objID, variable, getIDCount()); case TL_RED_YELLOW_GREEN_STATE: return wrapper->wrapString(objID, variable, getRedYellowGreenState(objID)); case TL_CONTROLLED_LANES: return wrapper->wrapStringList(objID, variable, getControlledLanes(objID)); case TL_CURRENT_PHASE: return wrapper->wrapInt(objID, variable, getPhase(objID)); case VAR_NAME: return wrapper->wrapString(objID, variable, getPhaseName(objID)); case TL_CURRENT_PROGRAM: return wrapper->wrapString(objID, variable, getProgram(objID)); case TL_PHASE_DURATION: return wrapper->wrapDouble(objID, variable, getPhaseDuration(objID)); case TL_NEXT_SWITCH: return wrapper->wrapDouble(objID, variable, getNextSwitch(objID)); case TL_CONTROLLED_JUNCTIONS: return wrapper->wrapStringList(objID, variable, getControlledJunctions(objID)); default: return false; } }
/* * Class: org_jbox2d_collision_broadphase_BroadPhaseJNI * Method: freeNative * Signature: ()V */ JNIEXPORT void JNICALL Java_org_jbox2d_collision_broadphase_BroadPhaseJNI_freeNative (JNIEnv *env, jobject obj) { b2BroadPhase* phase = getPhase(env, obj); DeleteHelper helper(env); phase->Iterate(&helper); free(phase); }
void RandomMovementParticleAffector::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details) { Inherited::changed(whichField, origin, details); if(whichField & PersistanceFieldMask) { getPerlinDistribution()->setPersistance(getPersistance()); } else if (whichField & FrequencyFieldMask) { getPerlinDistribution()->setFrequency(getFrequency()); } else if (whichField & InterpolationTypeFieldMask) { getPerlinDistribution()->setInterpolationType(getInterpolationType()); } else if (whichField & OctavesFieldMask) { getPerlinDistribution()->setOctaves(getOctaves()); } else if (whichField & AmplitudeFieldMask ) { getPerlinDistribution()->setAmplitude(getAmplitude()); } else if (whichField & PhaseFieldMask ) { getPerlinDistribution()->setPhase(getPhase()[0]); } }
/** Localize the ball on the navigation mesh. */ void SoccerWorld::updateBallPosition(int ticks) { if (isRaceOver()) return; if (!ballNotMoving()) { // Only update heading if the ball is moving m_ball_heading = atan2f(m_ball_body->getLinearVelocity().getX(), m_ball_body->getLinearVelocity().getZ()); } if (Track::getCurrentTrack()->hasNavMesh()) { m_ball_track_sector ->update(getBallPosition(), true/*ignore_vertical*/); if (!m_ball_track_sector->isOnRoad() && getPhase() == RACE_PHASE) { m_ball_invalid_timer += ticks; // Reset the ball and karts if out of navmesh after 2 seconds if (m_ball_invalid_timer >= stk_config->time2Ticks(2.0f)) { m_ball_invalid_timer = 0; m_ball->reset(); for (unsigned int i = 0; i < m_karts.size(); i++) moveKartAfterRescue(m_karts[i]); if (UserConfigParams::m_arena_ai_stats) getKart(8)->flyUp(); } } else m_ball_invalid_timer = 0; } } // updateBallPosition
void MSSOTLTrafficLightLogic::checkPhases() { for (int step = 0; step < (int)getPhases().size(); step++) { if (getPhase(step).isUndefined()) { MsgHandler::getErrorInstance()->inform("Step " + toString(step) + " of traffic light logic " + myID + " phases declaration has its type undeclared!"); } } }
/* * Class: org_jbox2d_collision_broadphase_BroadPhaseJNI * Method: getUserData * Signature: (I)Ljava/lang/Object; */ JNIEXPORT jobject JNICALL Java_org_jbox2d_collision_broadphase_BroadPhaseJNI_getUserData( JNIEnv *env, jobject obj, jint proxy) { //printf("Getting user data for proxy at %d\n", proxy); b2BroadPhase* tree = getPhase(env, obj); jobject data = (jobject) tree->GetUserData(proxy); //printf("User data at %llx\n", // (unsigned long long int) (holder->m_orig - (jobject) NULL)); return data; }
void PhaseVocoder::process(double *src, double *mag, double *theta) { FFTShift( m_n, src); m_fft->process(0, src, m_realOut, m_imagOut); getMagnitude( m_n/2, mag, m_realOut, m_imagOut); getPhase( m_n/2, theta, m_realOut, m_imagOut); }
bool GameState::operator==(const GameState& other) const { return true && _isRedPlayerSet(mgen::SHALLOW) == other._isRedPlayerSet(mgen::SHALLOW) && _isBluePlayerSet(mgen::SHALLOW) == other._isBluePlayerSet(mgen::SHALLOW) && _isPhaseSet(mgen::SHALLOW) == other._isPhaseSet(mgen::SHALLOW) && getRedPlayer() == other.getRedPlayer() && getBluePlayer() == other.getBluePlayer() && getPhase() == other.getPhase(); }
/* * Class: org_jbox2d_collision_broadphase_BroadPhaseJNI * Method: query * Signature: (Lorg/jbox2d/callbacks/TreeCallback;FFFF)V */ JNIEXPORT void JNICALL Java_org_jbox2d_collision_broadphase_BroadPhaseJNI_query (JNIEnv *env, jobject obj, jobject callback, jfloat lowerX, jfloat lowerY, jfloat upperX, jfloat upperY) { b2BroadPhase* tree = getPhase(env, obj); b2AABB bounds; bounds.lowerBound.Set(lowerX, lowerY); bounds.upperBound.Set(upperX, upperY); TreeCallbackHelper helper(env, callback); tree->Query(&helper, bounds); }
void VolumeDisplayUnit::setSlabThickness(int thickness) { // Make sure thickness is within valid bounds. Must be between 1 and the maximum number of slices on the curren view. int admittedThickness = qBound(1, thickness, getNumberOfSlices()); m_sliceHandler->setSlabThickness(admittedThickness); m_imagePipeline->setSlice(m_volume->getImageIndex(getSlice(), getPhase())); m_imagePipeline->setSlabThickness(admittedThickness); }
/** General update function called once per frame. * \param dt Time step size. */ void OverWorld::update(float dt) { // Skip annoying waiting without a purpose // Make sure to do all things that would normally happen in the // update() method of the base classes. if (getPhase() < GO_PHASE) { setPhase(RACE_PHASE); // Normally done in WorldStatus::update(), during phase SET_PHASE, // so we have to start music 'manually', since we skip all phases. World::getWorld()->getTrack()->startMusic(); if (UserConfigParams::m_music) music_manager->startMusic(); m_karts[0]->startEngineSFX(); } World::update(dt); World::updateTrack(dt); const unsigned int kart_amount = (unsigned int)m_karts.size(); // isn't it cool, on the overworld nitro is free! for(unsigned int n=0; n<kart_amount; n++) { m_karts[n]->setEnergy(100.0f); } /* TrackObjectManager* tom = getTrack()->getTrackObjectManager(); PtrVector<TrackObject>& objects = tom->getObjects(); for(unsigned int i=0; i<objects.size(); i++) { TrackObject* obj = objects.get(i); if(!obj->isGarage()) continue; float m_distance = obj->getDistance(); Vec3 m_garage_pos = obj->getPosition(); Vec3 m_kart_pos = getKart(0)->getXYZ(); if ((m_garage_pos-m_kart_pos).length_2d() > m_distance) { obj->reset(); } } */ if (m_return_to_garage) { m_return_to_garage = false; race_manager->exitRace(); KartSelectionScreen* s = OfflineKartSelectionScreen::getInstance(); s->setMultiplayer(false); s->setFromOverworld(true); StateManager::get()->resetAndGoToScreen(s); throw AbortWorldUpdateException(); } } // update
/* * Class: org_jbox2d_collision_broadphase_BroadPhaseJNI * Method: updatePairs * Signature: (Lorg/jbox2d/callbacks/PairCallback;)V */ JNIEXPORT void JNICALL Java_org_jbox2d_collision_broadphase_BroadPhaseJNI_updatePairs (JNIEnv *env, jobject obj, jobject callback) { if (callback == NULL) { return; } b2BroadPhase* phase = getPhase(env, obj); PairCallbackHelper helper(env, callback); phase->UpdatePairs(&helper); }
void MSSOTLTrafficLightLogic::setupCTS() { for (int phaseStep = 0; phaseStep < (int)getPhases().size(); phaseStep++) { if (getPhase(phaseStep).isTarget()) { targetPhasesCTS[phaseStep] = 0; lastCheckForTargetPhase[phaseStep] = MSNet::getInstance()->getCurrentTimeStep(); targetPhasesLastSelection[phaseStep] = 0; } } }
/* * Class: org_jbox2d_collision_broadphase_BroadPhaseJNI * Method: raycast * Signature: (Lorg/jbox2d/collision/broadphase/RaycastWrapper;FFFFF)V */ JNIEXPORT void JNICALL Java_org_jbox2d_collision_broadphase_BroadPhaseJNI_raycast (JNIEnv *env, jobject obj, jobject callback, jfloat p1x, jfloat p1y, jfloat p2x, jfloat p2y, jfloat maxFraction) { b2BroadPhase* tree = getPhase(env, obj); TreeRaycastHelper helper(env, callback); b2RayCastInput input; input.p1.Set(p1x, p1y); input.p2.Set(p2x, p2y); input.maxFraction = maxFraction; tree->RayCast(&helper, input); }
void MSSOTLTrafficLightLogic::setToATargetPhase() { for (int step = 0; step < (int)getPhases().size(); step++) { if (getPhase(step).isTarget()) { setStep(step); lastChain = step; return; } } MsgHandler::getErrorInstance()->inform("No phase of type target found for traffic light logic " + myID + " The logic could malfunction. Check phases declaration."); }
/* * Class: org_jbox2d_collision_broadphase_BroadPhaseJNI * Method: moveProxy * Signature: (IFFFFFF)V */ JNIEXPORT void JNICALL Java_org_jbox2d_collision_broadphase_BroadPhaseJNI_moveProxy (JNIEnv *env, jobject obj, jint proxy, jfloat lowerX, jfloat lowerY, jfloat upperX, jfloat upperY, jfloat dispX, jfloat dispY) { b2BroadPhase* tree = getPhase(env, obj); b2AABB bounds; bounds.lowerBound.Set(lowerX, lowerY); bounds.upperBound.Set(upperX, upperY); b2Vec2 disp; disp.Set(dispX, dispY); tree->MoveProxy(proxy, bounds, disp); }
void TurbulenceParticleAffector::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details) { Inherited::changed(whichField, origin, details); if(distributionIsNotInitialized()) { getPerlinDistribution()->setFrequency(getFrequency()); getPerlinDistribution()->setPersistance(getPersistance()); getPerlinDistribution()->setOctaves(getOctaves()); getPerlinDistribution()->setAmplitude(1.0f); getPerlinDistribution()->setInterpolationType(getInterpolationType()); getPerlinDistribution()->setPhase(getPhase()[0]); getPerlinDistribution()->setUseSmoothing(true); } if(whichField & PersistanceFieldMask) { getPerlinDistribution()->setPersistance(getPersistance()); } else if (whichField & FrequencyFieldMask) { getPerlinDistribution()->setFrequency(getFrequency()); } else if (whichField & InterpolationTypeFieldMask) { getPerlinDistribution()->setInterpolationType(getInterpolationType()); } else if (whichField & OctavesFieldMask) { getPerlinDistribution()->setOctaves(getOctaves()); } else if (whichField & AmplitudeFieldMask ) { getPerlinDistribution()->setAmplitude(1.0f); } else if (whichField & PhaseFieldMask ) { getPerlinDistribution()->setPhase(getPhase()[0]); } }
SUMOTime MSSimpleTrafficLightLogic::getOffsetFromIndex(int index) const { assert(index < (int)myPhases.size()); if (index == 0) { return 0; } SUMOTime pos = 0; for (int i = 0; i < index; i++) { pos += getPhase(i).duration; } return pos; }
/* * Class: org_jbox2d_collision_broadphase_BroadPhaseJNI * Method: createProxy * Signature: (FFFFLjava/lang/Object;)I */ JNIEXPORT jint JNICALL Java_org_jbox2d_collision_broadphase_BroadPhaseJNI_createProxy( JNIEnv *env, jobject obj, jfloat lowerX, jfloat lowerY, jfloat upperX, jfloat upperY, jobject userData) { b2BroadPhase* tree = getPhase(env, obj); b2AABB bounds; bounds.lowerBound.Set(lowerX, lowerY); bounds.upperBound.Set(upperX, upperY); int32 id = tree->CreateProxy(bounds, env->NewGlobalRef(userData)); //printf("Created proxy at %d with user data at %llx\n", id, // (long long unsigned int) (userData - (jobject) NULL)); return (jint) id; }
//ray addition (field not used in recent implementation, changing) int ray_addition(struct c2f* arg, int tag, double dz){ int ret=tag; double wvl=arg->xray.wavelength; //wavelength int i,j; //counter int N=arg->field->components; //Number of points double L=arg->crl.aperture; //Lens aperure int pix=arg->detector.number; //pixels in detector double w=arg->detector.width; //detector width double ph; //phase double A; //amplitude double y2; //position on detector double y; //position on lens complex double val; //complex value to add intensities struct field field; field.size=NULL; field.values=NULL; fprintf(stderr, "warning: using %s.\n", __FUNCTION__); field.size = malloc(arg->field->dimensions*sizeof(int)); field.values = malloc((arg->field->components)*sizeof(complex double)); copy_field(arg->field, &field); ////if (ray_add) printf("ray_add det.width=%fm pix=%d det_delta=%f \n ", w, pix, w/pix); //print N=field.components; // delta=L/N; // deltaf=1./(delta*N); for (j=0;j<pix;j++){ val=0.; y2=(-0.5*pix+j)*w/pix; for (i=0;i<N;i++){ A=cabs(arg->field->values[i]); y=((-0.5*N)+i)*L/N; //d=taylor_sqrt_opd((y2-y),dz,5)); //d=sqrt((y1[j]-y)*(y1[j]-y)+dz*dz)-dz; ph=getPhase(wvl,(y2-y),dz); //ADDITION val=val+A*cexp(I*ph); }//loop on lens points arg->detector.intensity[j]=cabs(val)*cabs(val); }//loop on detector pix copy_field(&field, arg->field); write_intensity_file(arg->detector.intensity, "int.txt", pix, w); if (field.size) free(field.size); field.size=NULL; if (field.values) free(field.values); field.values=NULL; return ret; }
void RandomMovementParticleAffector::onCreate(const RandomMovementParticleAffector *source) { if(source != NULL) { //Shader Chunk PerlinNoiseDistribution1DRefPtr TheNoiseDist = PerlinNoiseDistribution1D::create(); TheNoiseDist->setFrequency(getFrequency()); TheNoiseDist->setPersistance(getPersistance()); TheNoiseDist->setOctaves(getOctaves()); TheNoiseDist->setAmplitude(getAmplitude()); TheNoiseDist->setInterpolationType(getInterpolationType()); TheNoiseDist->setPhase(getPhase().x()); TheNoiseDist->setUseSmoothing(true); setPerlinDistribution(TheNoiseDist); } }
int MSSimpleTrafficLightLogic::getIndexFromOffset(SUMOTime offset) const { offset = offset % myDefaultCycleTime; if (offset == myDefaultCycleTime) { return 0; } SUMOTime testPos = 0; for (int i = 0; i < (int)myPhases.size(); i++) { testPos = testPos + getPhase(i).duration; if (testPos > offset) { return i; } if (testPos == offset) { assert((int)myPhases.size() > (i + 1)); return (i + 1); } } return 0; }
/* * Class: org_jbox2d_collision_broadphase_BroadPhaseJNI * Method: getFat * Signature: (I)Lorg/jbox2d/collision/broadphase/AABB2; */ JNIEXPORT jobject JNICALL Java_org_jbox2d_collision_broadphase_BroadPhaseJNI_getFat( JNIEnv *env, jobject obj, jint proxy) { b2BroadPhase* tree = getPhase(env, obj); b2AABB aabb = tree->GetFatAABB(proxy); if (aabb2class == 0) { aabb2class = env->FindClass("org/jbox2d/collision/broadphase/AABB2"); aabb2class = (jclass) env->NewGlobalRef(aabb2class); aabblx = env->GetFieldID(aabb2class, "lx", "F"); aabbly = env->GetFieldID(aabb2class, "ly", "F"); aabbux = env->GetFieldID(aabb2class, "ux", "F"); aabbuy = env->GetFieldID(aabb2class, "uy", "F"); } jobject ret = env->AllocObject(aabb2class); env->SetFloatField(ret, aabblx, aabb.lowerBound.x); env->SetFloatField(ret, aabbly, aabb.lowerBound.y); env->SetFloatField(ret, aabbux, aabb.upperBound.x); env->SetFloatField(ret, aabbuy, aabb.upperBound.y); return ret; }