Ver Fonte

Working on the particles

Panagiotis Christopoulos Charitos há 15 anos atrás
pai
commit
cd66ad9762

+ 1 - 2
src/Math/Mat3.inl.h

@@ -503,8 +503,7 @@ inline void Mat3::setRotationZ(float rad)
  * the slow code is in comments and above the comments the optimized one
  * If we analize the mat3 we can extract the 3 unit vectors rotated by the mat3. The 3 rotated vectors are in mat's
  * columns. This means that: mat3.colomn[0] == i*mat3. rotateXAxis() rotates rad angle not from i vector (aka x axis)
- * but
- * from the vector from colomn 0
+ * but from the vector from colomn 0
  */
 inline void Mat3::rotateXAxis(float rad)
 {

+ 2 - 2
src/Scene/Controllers/SkelAnimCtrl.h

@@ -1,5 +1,5 @@
-#ifndef _SKEL_ANIM_CTRL_H_
-#define _SKEL_ANIM_CTRL_H_
+#ifndef SKEL_ANIM_CTRL_H
+#define SKEL_ANIM_CTRL_H
 
 #include "Common.h"
 #include "Vec.h"

+ 26 - 4
src/Scene/ParticleEmitter.cpp

@@ -38,12 +38,25 @@ void ParticleEmitter::init(const char* filename)
 }
 
 
+//======================================================================================================================
+// updateWorldStuff                                                                                                    =
+//======================================================================================================================
+void ParticleEmitter::updateWorldStuff()
+{
+	updateWorldTransform();
+	update();
+}
+
+
 //======================================================================================================================
 // update                                                                                                              =
 //======================================================================================================================
 void ParticleEmitter::update()
 {
-	float crntTime = SDL_GetTicks() / 1000.0;
+	float crntTime = app->getTicks() / 1000.0;
+
+	// Opt: We dont have to make extra calculations if the ParticleEmitter's rotation is the identity
+	bool identRot = (worldTransform.getRotation() == Mat3::getIdentity()) ? true : false;
 
 	// deactivate the dead particles
 	for(uint i=0; i<particles.size(); i++)
@@ -102,7 +115,10 @@ void ParticleEmitter::update()
 					forceDir = forceDirection;
 				}
 				forceDir.normalize();
-				forceDir = worldTransform.getRotation() * forceDir; // the forceDir depends on the particle emitter rotation
+
+				if(!identRot)
+					forceDir = worldTransform.getRotation() * forceDir; // the forceDir depends on the particle emitter rotation
+
 				Vec3 force;
 
 				if(forceMagnitudeMargin != 0.0)
@@ -144,7 +160,12 @@ void ParticleEmitter::update()
 			{
 				pos = startingPos;
 			}
-			pos.transform(worldTransform);
+
+			if(identRot)
+				pos += worldTransform.getOrigin();
+			else
+				pos.transform(worldTransform);
+
 			btTransform trf;
 			trf.setIdentity();
 			trf.setOrigin(toBt(pos));
@@ -152,7 +173,8 @@ void ParticleEmitter::update()
 
 			// do the rest
 			++partNum;
-			if(partNum >= particlesPerEmittion) break;
+			if(partNum >= particlesPerEmittion)
+				break;
 		} // end for all particles
 
 		timeOfPrevEmittion = crntTime;

+ 8 - 6
src/Scene/ParticleEmitter.h

@@ -29,17 +29,19 @@ class ParticleEmitter: public SceneNode, public ParticleEmitterPropsStruct
 				void render();
 		};
 
-		// the changeable vars
+	public:
+		ParticleEmitter();
+		void render();
+		void init(const char* filename);
+		void deinit() {}
+		void updateWorldStuff();
+
+	private:
 		ptr_vector<Particle> particles;
 		float timeOfPrevUpdate;
 		float timeOfPrevEmittion;
 		RsrcPtr<ParticleEmitterProps> particleEmitterProps;
 
-		// funcs
-		ParticleEmitter();
-		void render();
-		void init(const char* filename);
-		void deinit() {}
 		void update();
 };
 

+ 25 - 25
src/Scene/SceneNode.h

@@ -15,12 +15,8 @@ class Controller;
 /// Scene node
 class SceneNode
 {
-	PROPERTY_RW(Transform, localTransform, setLocalTransform, getLocalTransform); ///< The transformation in local space
-	PROPERTY_RW(Transform, worldTransform, setWorldTransform, getWorldTransform); ///< The transformation in world space (local combined with parent transformation)
-
-	// data
 	public:
-		enum Type
+		enum NodeType
 		{
 			NT_GHOST,
 			NT_LIGHT,
@@ -31,33 +27,19 @@ class SceneNode
 			NT_PARTICLE_EMITTER
 		};
 
-		/*Vec3  translationLspace;
-		Mat3  rotationLspace;
-		float scaleLspace;
-
-		Vec3  translationWspace;
-		Mat3  rotationWspace;
-		float scaleWspace;
-
-		Mat4 transformationWspace;*/
+	PROPERTY_RW(Transform, localTransform, setLocalTransform, getLocalTransform); ///< The transformation in local space
+	PROPERTY_RW(Transform, worldTransform, setWorldTransform, getWorldTransform); ///< The transformation in world space (local combined with parent transformation)
 
+	public:
 		SceneNode* parent;
 		Vec<SceneNode*> childs;
-
-		Type type;
-
+		NodeType type;
 		bvolume_t* bvolumeLspace;
 		bvolume_t* bvolumeWspace;
-
 		bool isCompound;
-
-	// funcs
-	private:
-		void commonConstructorCode(); ///< Cause we cannot call constructor from other constructor
 		
-	public:
-		SceneNode(Type type_): type(type_) { commonConstructorCode(); }
-		SceneNode(Type type_, SceneNode* parent): type(type_) { commonConstructorCode(); parent->addChild(this); }
+		SceneNode(NodeType type_);
+		SceneNode(NodeType type_, SceneNode* parent);
 		virtual ~SceneNode();
 		virtual void render() = 0;
 		virtual void init(const char*) = 0; ///< init using a script
@@ -72,7 +54,25 @@ class SceneNode
 		void moveLocalZ(float distance);
 		void addChild(SceneNode* node);
 		void removeChild(SceneNode* node);
+
+	private:
+		void commonConstructorCode(); ///< Cause we cannot call constructor from other constructor
 };
 
 
+inline SceneNode::SceneNode(NodeType type_):
+	type(type_)
+{
+	commonConstructorCode();
+}
+
+
+inline SceneNode::SceneNode(NodeType type_, SceneNode* parent):
+	type(type_)
+{
+	commonConstructorCode();
+	parent->addChild(this);
+}
+
+
 #endif

+ 2 - 2
src/Scene/SkelNode.h

@@ -1,5 +1,5 @@
-#ifndef _SKEL_NODE_H_
-#define _SKEL_NODE_H_
+#ifndef SKEL_NODE_H
+#define SKEL_NODE_H
 
 #include "Common.h"
 #include "SceneNode.h"