int main(int argc,char *argv[]) { CkPrintf("init called\n"); CrnInitStream(&rs,0,0); int facesA[nFaces*nPer],facesB[nFaces*nPer]; const int nPoints=aPoints+bPoints; CkVector3d pts[nPoints]; FEM_Print("Fabricating points:"); CkVector3d a2bLocs(randVec(CkVector3d(10.0,90.0,50.0))); print("true offset vector "); print(a2bLocs,15); int i; //Fabricate some test points (just purely random) for (i=0;i<aPoints;i++) { pts[i]=randVec(CkVector3d(5.0,5.0,5.0)); pts[i+a2bPoints]=pts[i]+a2bLocs; } makeFaces(facesA,facesB); //Actually do the match: //verbosematchingDest dest; unionFind uf(nPoints); unionFindDest dest(uf); FEM_Print("Finding offset"); linearOffsetMatcher matcher(nFaces,nPer,facesA,facesB,0, nPoints,pts); FEM_Print("Beginning match"); matcher.match(dest); FEM_Print("Compressing paths"); uf.compress(); FEM_Print("Testing union"); testUnion(nPoints,uf.detach()); FEM_Print("Done"); }
void Petal::setup(){ rot.set( 0, 0, 0 ); rotInc.set( ofRandom(-rotMult, rotMult), ofRandom(-rotMult, rotMult), ofRandom(-rotMult, rotMult) ); petalSize=ofRandom(20,55); damping=0.98; setPicture=int(ofRandom(4)); float phi = ofRandom( 0, TWO_PI ); float costheta = ofRandom( -1.0f, 1.0f ); float rho = sqrt( 1.0f - costheta * costheta ); //0~1, unsigned float x = rho * cos( phi ); float y = rho * sin( phi ); float z = costheta;//-1~1 ofVec3f randVec(x, y, z); pos = randVec * ofRandom( 100.0f, 600.0f ); vel = -randVec; for (int i=0; i<4; i++) { string result = ""; stringstream currentCombo; currentCombo << i; result = currentCombo.str(); petalList.push_back(ofImage()); petalList[i].loadImage(ofToDataPath(result + ".png")); } }
void SunParticle::update() { vel *= damping; pos = pos + vel; lifeSpan++; if(lifeSpan > ageOfDeath){ //reset life counter lifeSpan = 0;; //then give a new random position float phi = ofRandom( 0, TWO_PI ); float costheta = ofRandom( -1.0f, 1.0f ); float rho = sqrt( 1.0f - costheta * costheta ); float x = rho * cos( phi ); float y = rho * sin( phi ); float z = costheta; ofVec3f randVec(x, y, z); pos = randVec * ofRandom( 80.0f, 250.0f ); pos.x = pos.x + ofGetWindowWidth()/2; pos.y = pos.y + ofGetWindowHeight()/2; ofVec3f toCenter = pos - ofVec3f(ofGetWindowSize()/2); toCenter.normalize(); vel = toCenter * ofRandom(0.5, 2); if(explode){ pos = ofVec3f(ofGetWindowSize()/2); vel = ofVec3f(ofRandom(-20, 20), ofRandom(-20, 20), ofRandom(0, 20)); } if(size < 80){ size += 5; } else { size = 0; } } // resetForces(); }
void FlockController::addParticle( int numParticles ){ for( int i=0; i<numParticles; i++ ){ // I was getting bad results, so I looked up uniform sphere distribution and got this: http://mathworld.wolfram.com/SpherePointPicking.html float phi = ofRandom( 0, TWO_PI ); float costheta = ofRandom( -1.0f, 1.0f ); float rho = sqrt( 1.0f - costheta * costheta ); float x = rho * cos( phi ); float y = rho * sin( phi ); float z = costheta; ofVec3f randVec(x, y, z); ofVec3f pos = randVec * ofRandom( 100.0f, 600.0f ); ofVec3f vel = -randVec; Boid b( pos, vel ); boidList.push_back( b ); } }
void FlockController::addParticle(int numParticles) { for( int i=0; i<numParticles; i++){ float phi = ofRandom( 0, TWO_PI ); float costheta = ofRandom( -1.0f, 1.0f ); float rho = sqrt( 1.0f - costheta * costheta ); float x = rho * cos( phi ); float y = rho * sin( phi ); float z = costheta; ofVec3f randVec(x, y, z); ofVec3f pos = randVec * ofRandom( 100.0f, 600.0f ); ofVec3f vel = -randVec; Boid b; b.pos = pos; b.vel = vel; boidList.push_back( b ); } }
Triang randTriang(const bool rectan) { return newTriang(fMul(randVec(), 10), randDir(), randDir(), rectan, 0); }
void createExplosion(vec pos) { playSound(explosion, pos, 20,randgauss(1,.1),3000); // deal damage to nearby objects // apply explosion force to objects for (int i = 0; i < activeObjects.size(); i++) { GameObject* obj = activeObjects[i]; if (obj->isEnemy || obj == p) { float dist = (obj->pos - pos).getLength(); if (dist < 250) { float damage = (250 - dist)*.7; float force = damage * .8; if (force > 25) force = 25; //say("F: " << force); obj->pos += vec(force, 0).rotated((obj->pos - pos).getAngle()); if (obj == p) damage *= .4; // decrease explosion damage for player obj->hurt(damage); } } } // create particles for (int i = 0; i < 10; i++) { vec smokeVel = randVec(1, 1); Color smokeColor = hsvtorgb(0, 0, randnum(0, 1)); Particle* p = new Particle(pos + smokeVel*randnum(80, 135), smokeVel*randnum(0, 1) + randVec(0.1, 1), randint(100, 200), randnum(0.8, 1.2), randnum(2, 3), Color(smokeColor.r, smokeColor.g, smokeColor.b, 80), Color(smokeColor.r, smokeColor.g, smokeColor.b, 0), randgauss(-.01,.002), 0.998); p->setTexture(blob); p->angle = randnum(0, 360); p->angVel = randgauss(0, 1); p->layer = 1; //p->blendMode = BlendAdd; } Color flashColor = hsvtorgb(randnum(30, 60), randnum(0.5, 1), randnum(0.5, 1)); for (int i = 0; i < 10; i++) { Particle* p = new Particle(pos, randVec(0, 1), randint(4, 7), 0.1, randnum(2.5, 4.5), Color(flashColor.r, flashColor.g, flashColor.b, 255), Color(flashColor.r, flashColor.g, flashColor.b, 0)); p->setTexture(blob); p->blendMode = BlendAdd; p->layer = 1; } // break terrain float playerDist = (p->pos - pos).getLength(); screenShake += 500.f / playerDist; if (screenShake > 5) screenShake = 5; destroyTerrainCircle(pos, randgauss(100, 5)); }