소스 검색

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 년 전
부모
커밋
ffd147a855

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

@@ -240,9 +240,15 @@ namespace Polycode {
 				
 				
 			Number rotationSpeed;
 			Number rotationSpeed;
 							
 							
-			int emitterType;											
+			int emitterType;
+			
+			bool getIgnoreParentMatrix();			
+			void setIgnoreParentMatrix(bool val);
+											
 		protected:
 		protected:
 		
 		
+			bool ignoreParentMatrix;
+		
 			int blendingMode;
 			int blendingMode;
 		
 		
 			bool isScreenEmitter;
 			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->dirVector = this->dirVector;
 	_clone->gravVector = this->gravVector;
 	_clone->gravVector = this->gravVector;
 	_clone->deviation = this->deviation;
 	_clone->deviation = this->deviation;
+
+	_clone->setIgnoreParentMatrix(getIgnoreParentMatrix());
 				
 				
 	_clone->brightnessDeviation = this->brightnessDeviation;
 	_clone->brightnessDeviation = this->brightnessDeviation;
 	_clone->particleSize = this->particleSize;
 	_clone->particleSize = this->particleSize;
@@ -163,6 +165,7 @@ ParticleEmitter::ParticleEmitter(const String& imageFile, Mesh *particleMesh, in
 	isScreenEmitter = false;
 	isScreenEmitter = false;
 	dirVector = direction;
 	dirVector = direction;
 	gravVector = gravity;
 	gravVector = gravity;
+	ignoreParentMatrix = false;
 	this->emitterType = emitterType;
 	this->emitterType = emitterType;
 	this->emitSpeed = emitSpeed;
 	this->emitSpeed = emitSpeed;
 	this->deviation = deviation;
 	this->deviation = deviation;
@@ -211,6 +214,18 @@ ParticleEmitter::ParticleEmitter(const String& imageFile, Mesh *particleMesh, in
 	useScaleCurves = false;	
 	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() {
 Texture *ParticleEmitter::getParticleTexture() {
 	return particleTexture;
 	return particleTexture;
 }
 }
@@ -233,7 +248,7 @@ void ParticleEmitter::createParticles() {
 	Particle *particle;	
 	Particle *particle;	
 	for(int i=0; i < numParticles; i++) {
 	for(int i=0; i < numParticles; i++) {
 		particle = new Particle(particleType, isScreenEmitter, particleMaterial, particleTexture, pMesh);
 		particle = new Particle(particleType, isScreenEmitter, particleMaterial, particleTexture, pMesh);
-		particle->particleBody->ignoreParentMatrix = true;
+		particle->particleBody->ignoreParentMatrix = ignoreParentMatrix;
 		particle->velVector = dirVector;
 		particle->velVector = dirVector;
 		particle->dirVector = dirVector;
 		particle->dirVector = dirVector;
 		particle->deviation = deviation;
 		particle->deviation = deviation;
@@ -320,7 +335,7 @@ void ParticleEmitter::setParticleCount(int count) {
 		Particle *particle;
 		Particle *particle;
 		for(int i=0; i  < oldSize; i++) {
 		for(int i=0; i  < oldSize; i++) {
 			particle = new Particle(particleType, isScreenEmitter, particleMaterial, particleTexture, pMesh);
 			particle = new Particle(particleType, isScreenEmitter, particleMaterial, particleTexture, pMesh);
-			particle->particleBody->ignoreParentMatrix = true;			
+			particle->particleBody->ignoreParentMatrix = ignoreParentMatrix;
 			particle->velVector = dirVector;
 			particle->velVector = dirVector;
 			particle->dirVector = dirVector;
 			particle->dirVector = dirVector;
 			particle->deviation = deviation;
 			particle->deviation = deviation;
@@ -373,7 +388,10 @@ void ParticleEmitter::resetParticle(Particle *particle) {
 	
 	
 	Vector3	startVector;
 	Vector3	startVector;
 	
 	
-	Vector3 compoundScale = getParticleCompoundScale();
+	Vector3 compoundScale(1.0, 1.0, 1.0);
+	if(ignoreParentMatrix) {
+		compoundScale = getParticleCompoundScale();
+	}
 	
 	
 	particle->dirVector = dirVector;
 	particle->dirVector = dirVector;
 //	if(emitterMesh) {
 //	if(emitterMesh) {
@@ -397,9 +415,13 @@ void ParticleEmitter::resetParticle(Particle *particle) {
 	particle->brightnessDeviation = 1.0f - ( (-brightnessDeviation) + ((brightnessDeviation*2) * ((Number)rand()/RAND_MAX)));
 	particle->brightnessDeviation = 1.0f - ( (-brightnessDeviation) + ((brightnessDeviation*2) * ((Number)rand()/RAND_MAX)));
 	
 	
 //	particle->velVector = concatMatrix.rotateVector(particle->velVector);	
 //	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->Translate(startVector);
 	particle->particleBody->rebuildTransformMatrix();	
 	particle->particleBody->rebuildTransformMatrix();	
 	
 	
@@ -471,7 +493,10 @@ void ParticleEmitter::updateEmitter() {
 	Particle *particle;
 	Particle *particle;
 	Number normLife;
 	Number normLife;
 	
 	
-	Vector3 compoundScale = getParticleCompoundScale();
+	Vector3 compoundScale(1.0, 1.0, 1.0);
+	if(ignoreParentMatrix) {
+		compoundScale = getParticleCompoundScale();
+	}
 	
 	
 	for(int i=0;i < numParticles; i++) {	
 	for(int i=0;i < numParticles; i++) {	
 		particle = particles[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->rotationFollowsPath = (*emitterEntry)["rotationFollowsPath"]->boolVal;
 				placingEmitter->useScaleCurves = (*emitterEntry)["useScaleCurves"]->boolVal;
 				placingEmitter->useScaleCurves = (*emitterEntry)["useScaleCurves"]->boolVal;
 				placingEmitter->useColorCurves = (*emitterEntry)["useColorCurves"]->boolVal;
 				placingEmitter->useColorCurves = (*emitterEntry)["useColorCurves"]->boolVal;
+				
+				bool boolVal;
+				if(emitterEntry->readBool("ignoreParentMatrix", &boolVal)) {
+					placingEmitter->setIgnoreParentMatrix(boolVal);
+				}
 									
 									
 				placingEmitter->setParticleBlendingMode((*emitterEntry)["particleBlendMode"]->intVal);			
 				placingEmitter->setParticleBlendingMode((*emitterEntry)["particleBlendMode"]->intVal);			
 				
 				

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

@@ -461,6 +461,7 @@ class ScreenParticleSheet : public PropSheet {
 
 
 		TextureProp *textureProp;
 		TextureProp *textureProp;
 		ComboProp *blendingProp;
 		ComboProp *blendingProp;
+		BoolProp *ignoreParentMatrixProp;
 		NumberProp *numParticlesProp;
 		NumberProp *numParticlesProp;
 		NumberProp *lifespanProp;
 		NumberProp *lifespanProp;
 		NumberProp *particleScaleProp;		
 		NumberProp *particleScaleProp;		
@@ -492,6 +493,7 @@ class ScreenParticleSheet : public PropSheet {
 		bool lastEnableProp;
 		bool lastEnableProp;
 		Number lastPerlinSize;
 		Number lastPerlinSize;
 		Number lastSpeedMod;
 		Number lastSpeedMod;
+		bool lastIgnoreParentMatrix;
 		bool lastRotationFollowsPath;
 		bool lastRotationFollowsPath;
 		bool lastUseScaleCurves;
 		bool lastUseScaleCurves;
 		bool lastUseColorCurves;		
 		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("Premultiplied");
 	blendingProp->comboEntry->addComboItem("Multiply");
 	blendingProp->comboEntry->addComboItem("Multiply");
 
 
+	ignoreParentMatrixProp = new BoolProp("No parent matrix");
+	addProp(ignoreParentMatrixProp);
+	
 	numParticlesProp = new NumberProp("Num particles");
 	numParticlesProp = new NumberProp("Num particles");
 	addProp(numParticlesProp);
 	addProp(numParticlesProp);
 		
 		
@@ -1440,7 +1443,7 @@ ScreenParticleSheet::ScreenParticleSheet() : PropSheet("PARTICLE EMITTER", "Scre
 	addProp(colorCurveProp);
 	addProp(colorCurveProp);
 	
 	
 	emitter = NULL;
 	emitter = NULL;
-	propHeight = 650;
+	propHeight = 680;
 }
 }
 
 
 void ScreenParticleSheet::handleEvent(Event *event) {
 void ScreenParticleSheet::handleEvent(Event *event) {
@@ -1546,7 +1549,12 @@ void ScreenParticleSheet::handleEvent(Event *event) {
 		emitter->rotationFollowsPath = lastRotationFollowsPath;		
 		emitter->rotationFollowsPath = lastRotationFollowsPath;		
 		dispatchEvent(new Event(), Event::CHANGE_EVENT);
 		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) {
 	if(event->getDispatcher() == useScaleCurvesProp  && event->getEventCode() == Event::CHANGE_EVENT) {
 		lastUseScaleCurves = useScaleCurvesProp->get();
 		lastUseScaleCurves = useScaleCurvesProp->get();
@@ -1588,6 +1596,11 @@ void ScreenParticleSheet::Update() {
 			deviationProp->set(Vector2(emitter->emitterRadius.x, emitter->emitterRadius.y));
 			deviationProp->set(Vector2(emitter->emitterRadius.x, emitter->emitterRadius.y));
 			lastSize = emitter->emitterRadius;
 			lastSize = emitter->emitterRadius;
 		}
 		}
+
+		if(emitter->getIgnoreParentMatrix() != lastIgnoreParentMatrix) {
+			ignoreParentMatrixProp->set(emitter->getIgnoreParentMatrix());
+			lastIgnoreParentMatrix = emitter->getIgnoreParentMatrix();
+		}
 				
 				
 		if(emitter->brightnessDeviation != lastBrightnessDeviation) {
 		if(emitter->brightnessDeviation != lastBrightnessDeviation) {
 			lastBrightnessDeviation = emitter->brightnessDeviation;
 			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("particleCount", (int)emitter->getNumParticles());
 
 
 		emitterEntry->addChild("useScaleCurves", emitter->useScaleCurves);
 		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);
 		saveCurveToObject(emitterEntry->addChild("scaleCurve"), &emitter->scaleCurve);