コード例 #1
0
void textureTrailParticle::update(float forceMag, float timeFactor, ofPoint attractor, float angleRange){
	vel *= drag;
	
//	float xforce = ofSignedNoise((float)ofGetFrameNum() * timeFactor, 1000, unique * 100.0);
//	float yforce = ofSignedNoise((float)ofGetFrameNum() * timeFactor, -1000, unique * 100.0);
//	float zforce = 0;//ofSignedNoise((float)ofGetFrameNum() * timeFactor, 33, unique * 100.0);
//	
//	float speed			= vel.length();

	//We do it by angle so as not to have the fish want to do an instant change of direction.

//	float speed		 = sqrt(vel.x*vel.x + vel.y*vel.y);

	//TODO: clean this shit up - maybe apply force via change in angle with limit to amount of change. 
	
	ofVec3f vec	 = attractor - pos;
	float tAngle     = atan2f(vec.y, vec.x);
	
	float angleShift = (DEG_TO_RAD * angleRange) * ofSignedNoise( ofGetElapsedTimef() * timeFactor , unique * 100.0 );
	float angle		 = tAngle + angleShift;	
				
	ofVec3f force( cos(angle), sin(angle), 0.0);
	force.normalize();

	vel += force * forceMag;
	pos += vel;			

	ofVec3f dist = pos - prevPoint;
	
	if( dist.lengthSquared() >= 0.25 ){
		updateTrail(prevPoint, pos+vel, 1, 20);	
		prevPoint = pos;			
	}

}
コード例 #2
0
ファイル: ElRibbonTrail.cpp プロジェクト: chenbk85/3dlearn
void ElRibbonTrail::nodeUpdated(const ElSceneNode* node)
{
	updateTrail(node->getDerivedPosition());
}