Просмотр исходного кода

Particles now default to not ignoring parent matrix. Added setter and getter for ignoreParentMatrix option in particle systems. Added screen editor option to toggle ignoreParentMatrix option in particle systems.

Ivan Safrin 12 лет назад
Родитель
Сommit
ffd147a855

+ 7 - 1
Core/Contents/Include/PolyParticleEmitter.h

@@ -240,9 +240,15 @@ namespace Polycode {
 				
 			Number rotationSpeed;
 							
-			int emitterType;											
+			int emitterType;
+			
+			bool getIgnoreParentMatrix();			
+			void setIgnoreParentMatrix(bool val);
+											
 		protected:
 		
+			bool ignoreParentMatrix;
+		
 			int blendingMode;
 		
 			bool isScreenEmitter;

+ 31 - 6
Core/Contents/Source/PolyParticleEmitter.cpp

@@ -109,6 +109,8 @@ void ScreenParticleEmitter::applyClone(Entity *clone, bool deepClone, bool ignor
 	_clone->dirVector = this->dirVector;
 	_clone->gravVector = this->gravVector;
 	_clone->deviation = this->deviation;
+
+	_clone->setIgnoreParentMatrix(getIgnoreParentMatrix());
 				
 	_clone->brightnessDeviation = this->brightnessDeviation;
 	_clone->particleSize = this->particleSize;
@@ -163,6 +165,7 @@ ParticleEmitter::ParticleEmitter(const String& imageFile, Mesh *particleMesh, in
 	isScreenEmitter = false;
 	dirVector = direction;
 	gravVector = gravity;
+	ignoreParentMatrix = false;
 	this->emitterType = emitterType;
 	this->emitSpeed = emitSpeed;
 	this->deviation = deviation;
@@ -211,6 +214,18 @@ ParticleEmitter::ParticleEmitter(const String& imageFile, Mesh *particleMesh, in
 	useScaleCurves = false;	
 }
 
+bool ParticleEmitter::getIgnoreParentMatrix() {
+	return ignoreParentMatrix;
+}
+
+void ParticleEmitter::setIgnoreParentMatrix(bool val) {
+	ignoreParentMatrix = val;
+	for(int i=0; i < particles.size(); i++) {
+		particles[i]->particleBody->ignoreParentMatrix = ignoreParentMatrix;
+	}
+}
+
+
 Texture *ParticleEmitter::getParticleTexture() {
 	return particleTexture;
 }
@@ -233,7 +248,7 @@ void ParticleEmitter::createParticles() {
 	Particle *particle;	
 	for(int i=0; i < numParticles; i++) {
 		particle = new Particle(particleType, isScreenEmitter, particleMaterial, particleTexture, pMesh);
-		particle->particleBody->ignoreParentMatrix = true;
+		particle->particleBody->ignoreParentMatrix = ignoreParentMatrix;
 		particle->velVector = dirVector;
 		particle->dirVector = dirVector;
 		particle->deviation = deviation;
@@ -320,7 +335,7 @@ void ParticleEmitter::setParticleCount(int count) {
 		Particle *particle;
 		for(int i=0; i  < oldSize; i++) {
 			particle = new Particle(particleType, isScreenEmitter, particleMaterial, particleTexture, pMesh);
-			particle->particleBody->ignoreParentMatrix = true;			
+			particle->particleBody->ignoreParentMatrix = ignoreParentMatrix;
 			particle->velVector = dirVector;
 			particle->dirVector = dirVector;
 			particle->deviation = deviation;
@@ -373,7 +388,10 @@ void ParticleEmitter::resetParticle(Particle *particle) {
 	
 	Vector3	startVector;
 	
-	Vector3 compoundScale = getParticleCompoundScale();
+	Vector3 compoundScale(1.0, 1.0, 1.0);
+	if(ignoreParentMatrix) {
+		compoundScale = getParticleCompoundScale();
+	}
 	
 	particle->dirVector = dirVector;
 //	if(emitterMesh) {
@@ -397,9 +415,13 @@ void ParticleEmitter::resetParticle(Particle *particle) {
 	particle->brightnessDeviation = 1.0f - ( (-brightnessDeviation) + ((brightnessDeviation*2) * ((Number)rand()/RAND_MAX)));
 	
 //	particle->velVector = concatMatrix.rotateVector(particle->velVector);	
+
+	if(ignoreParentMatrix) {
+		particle->particleBody->setPosition(concatMatrix.getPosition());
+	} else {
+		particle->particleBody->setPosition(0.0, 0.0, 0.0);
+	}
 	
-	particle->particleBody->setPosition(concatMatrix.getPosition());
-//	particle->particleBody->setPosition(0.0, 0.0, 0.0);
 	particle->particleBody->Translate(startVector);
 	particle->particleBody->rebuildTransformMatrix();	
 	
@@ -471,7 +493,10 @@ void ParticleEmitter::updateEmitter() {
 	Particle *particle;
 	Number normLife;
 	
-	Vector3 compoundScale = getParticleCompoundScale();
+	Vector3 compoundScale(1.0, 1.0, 1.0);
+	if(ignoreParentMatrix) {
+		compoundScale = getParticleCompoundScale();
+	}
 	
 	for(int i=0;i < numParticles; i++) {	
 		particle = particles[i];

+ 5 - 0
Core/Contents/Source/PolyScreenEntityInstance.cpp

@@ -192,6 +192,11 @@ ScreenEntity *ScreenEntityInstance::loadObjectEntryIntoEntity(ObjectEntry *entry
 				placingEmitter->rotationFollowsPath = (*emitterEntry)["rotationFollowsPath"]->boolVal;
 				placingEmitter->useScaleCurves = (*emitterEntry)["useScaleCurves"]->boolVal;
 				placingEmitter->useColorCurves = (*emitterEntry)["useColorCurves"]->boolVal;
+				
+				bool boolVal;
+				if(emitterEntry->readBool("ignoreParentMatrix", &boolVal)) {
+					placingEmitter->setIgnoreParentMatrix(boolVal);
+				}
 									
 				placingEmitter->setParticleBlendingMode((*emitterEntry)["particleBlendMode"]->intVal);			
 				

+ 2 - 0
IDE/Contents/Include/PolycodeProps.h

@@ -461,6 +461,7 @@ class ScreenParticleSheet : public PropSheet {
 
 		TextureProp *textureProp;
 		ComboProp *blendingProp;
+		BoolProp *ignoreParentMatrixProp;
 		NumberProp *numParticlesProp;
 		NumberProp *lifespanProp;
 		NumberProp *particleScaleProp;		
@@ -492,6 +493,7 @@ class ScreenParticleSheet : public PropSheet {
 		bool lastEnableProp;
 		Number lastPerlinSize;
 		Number lastSpeedMod;
+		bool lastIgnoreParentMatrix;
 		bool lastRotationFollowsPath;
 		bool lastUseScaleCurves;
 		bool lastUseColorCurves;		

+ 15 - 2
IDE/Contents/Source/PolycodeProps.cpp

@@ -1388,6 +1388,9 @@ ScreenParticleSheet::ScreenParticleSheet() : PropSheet("PARTICLE EMITTER", "Scre
 	blendingProp->comboEntry->addComboItem("Premultiplied");
 	blendingProp->comboEntry->addComboItem("Multiply");
 
+	ignoreParentMatrixProp = new BoolProp("No parent matrix");
+	addProp(ignoreParentMatrixProp);
+	
 	numParticlesProp = new NumberProp("Num particles");
 	addProp(numParticlesProp);
 		
@@ -1440,7 +1443,7 @@ ScreenParticleSheet::ScreenParticleSheet() : PropSheet("PARTICLE EMITTER", "Scre
 	addProp(colorCurveProp);
 	
 	emitter = NULL;
-	propHeight = 650;
+	propHeight = 680;
 }
 
 void ScreenParticleSheet::handleEvent(Event *event) {
@@ -1546,7 +1549,12 @@ void ScreenParticleSheet::handleEvent(Event *event) {
 		emitter->rotationFollowsPath = lastRotationFollowsPath;		
 		dispatchEvent(new Event(), Event::CHANGE_EVENT);
 	}	
-	
+
+	if(event->getDispatcher() == ignoreParentMatrixProp  && event->getEventCode() == Event::CHANGE_EVENT) {
+		lastIgnoreParentMatrix = ignoreParentMatrixProp->get();
+		emitter->setIgnoreParentMatrix(lastIgnoreParentMatrix);		
+		dispatchEvent(new Event(), Event::CHANGE_EVENT);
+	}	
 	
 	if(event->getDispatcher() == useScaleCurvesProp  && event->getEventCode() == Event::CHANGE_EVENT) {
 		lastUseScaleCurves = useScaleCurvesProp->get();
@@ -1588,6 +1596,11 @@ void ScreenParticleSheet::Update() {
 			deviationProp->set(Vector2(emitter->emitterRadius.x, emitter->emitterRadius.y));
 			lastSize = emitter->emitterRadius;
 		}
+
+		if(emitter->getIgnoreParentMatrix() != lastIgnoreParentMatrix) {
+			ignoreParentMatrixProp->set(emitter->getIgnoreParentMatrix());
+			lastIgnoreParentMatrix = emitter->getIgnoreParentMatrix();
+		}
 				
 		if(emitter->brightnessDeviation != lastBrightnessDeviation) {
 			lastBrightnessDeviation = emitter->brightnessDeviation;

+ 3 - 1
IDE/Contents/Source/PolycodeScreenEditor.cpp

@@ -2638,7 +2638,9 @@ void PolycodeScreenEditor::saveEntityToObjectEntry(ScreenEntity *entity, ObjectE
 		emitterEntry->addChild("particleCount", (int)emitter->getNumParticles());
 
 		emitterEntry->addChild("useScaleCurves", emitter->useScaleCurves);
-		emitterEntry->addChild("useColorCurves", emitter->useColorCurves);		
+		emitterEntry->addChild("useColorCurves", emitter->useColorCurves);
+
+		emitterEntry->addChild("ignoreParentMatrix", emitter->getIgnoreParentMatrix());
 
 		saveCurveToObject(emitterEntry->addChild("scaleCurve"), &emitter->scaleCurve);