Переглянути джерело

*WIP in ParticleEmitter
*Changes in the buffer objects

Panagiotis Christopoulos Charitos 15 роки тому
батько
коміт
7bd72ff762

Різницю між файлами не показано, бо вона завелика
+ 347 - 343
build/debug/Makefile


+ 2 - 2
build/debug/gen.cfg.py

@@ -1,4 +1,4 @@
-source_paths = [ "../../src/Math/", "../../src/Tokenizer/", "../../src/Misc/", "../../src/", "../../src/Renderer/", "../../src/Scene/", "../../src/Ui/", "../../src/Resources/", "../../src/Util/", "../../src/Controllers/", "../../src/Physics/" ]
+source_paths = [ "../../src/Math/", "../../src/Tokenizer/", "../../src/Misc/", "../../src/", "../../src/Renderer/", "../../src/Scene/", "../../src/Ui/", "../../src/Resources/", "../../src/Util/", "../../src/Controllers/", "../../src/Physics/", "../../src/Renderer/BufferObjects/" ]
 
 include_paths = list(source_paths)
 include_paths.extend( [ "../../../bullet_svn/src/" ] ) # the bullet svn path
@@ -7,7 +7,7 @@ precompiled_headers = []
 executable_name = "AnKi.bin"
 compiler = "g++"
 common_flags = ""
-compiler_flags = "-c -pedantic-errors -pedantic -ansi -Wall -Wextra -W -pipe -O0 -g3 -pg `sdl-config --cflags` -D_DEBUG_ -D_TERMINAL_COLORING__ -D_PLATFORM_LINUX_"
+compiler_flags = "-c -pedantic-errors -pedantic -ansi -Wall -Wextra -W -pipe -O0 -g3 -pg `sdl-config --cflags` -fsingle-precision-constant -D_DEBUG_ -D_TERMINAL_COLORING__ -D_PLATFORM_LINUX_"
 precompiled_headers_flags = "-x c++-header"
 #linker_flags = "-rdynamic -L../../../bullet_svn/src/BulletSoftBody -L../../../bullet_svn/src/BulletDynamics -L../../../bullet_svn/src/BulletCollision -L../../../bullet_svn/src/LinearMath -Wl,-Bstatic -lBulletSoftBody -lBulletDynamics -lBulletCollision -lLinearMath -lGLEW -lSDL_image -lGLU -Wl,-Bdynamic -lSDL -lpthread -lGL -ljpeg -lpng -ltiff -lesd -lcaca -laa -ldirectfb -laudio -lpulse-simple" # a few libs are now static
 linker_flags = "-rdynamic -L../../../bullet_svn/src/BulletSoftBody -L../../../bullet_svn/src/BulletDynamics -L../../../bullet_svn/src/BulletCollision -L../../../bullet_svn/src/LinearMath -Wl,-Bstatic -lBulletSoftBody -lBulletDynamics -lBulletCollision -lLinearMath -lGLEW -lSDL_image -lGLU -Wl,-Bdynamic -lSDL -lGL -ljpeg -lpng -ltiff" # a few libs are now static

+ 13 - 2
shaders/PpsSsao.glsl

@@ -21,6 +21,8 @@ const float rad = 0.006;
 const int SAMPLES = 10; // 10 is good
 const float invSamples = 1.0/float(SAMPLES);
 
+const float MAX_SSAO_DISTANCE = 40.0;
+
 void main(void)
 {
 	// these are the random vectors inside a unit sphere
@@ -29,11 +31,20 @@ void main(void)
 	//const vec3 pSphere[12] = vec3[](vec3(-0.13657719, 0.30651027, 0.16118456),vec3(-0.14714938, 0.33245975, -0.113095455),vec3(0.030659059, 0.27887347, -0.7332209),vec3(0.009913514, -0.89884496, 0.07381549),vec3(0.040318526, 0.40091, 0.6847858),vec3(0.22311053, -0.3039437, -0.19340435),vec3(0.36235332, 0.21894878, -0.05407306),vec3(-0.15198798, -0.38409665, -0.46785462),vec3(-0.013492276, -0.5345803, 0.11307949),vec3(-0.4972847, 0.037064247, -0.4381323),vec3(-0.024175806, -0.008928787, 0.17719103),vec3(0.694014, -0.122672155, 0.33098832));
 	const vec3 pSphere[10] = vec3[](vec3(-0.010735935, 0.01647018, 0.0062425877),vec3(-0.06533369, 0.3647007, -0.13746321),vec3(-0.6539235, -0.016726388, -0.53000957),vec3(0.40958285, 0.0052428036, -0.5591124),vec3(-0.1465366, 0.09899267, 0.15571679),vec3(-0.44122112, -0.5458797, 0.04912532),vec3(0.03755566, -0.10961345, -0.33040273),vec3(0.019100213, 0.29652783, 0.066237666),vec3(0.8765323, 0.011236004, 0.28265962),vec3(0.29264435, -0.40794238, 0.15964167));
 	// grab a normal for reflecting the sample rays later on
+
+
+	float currentPixelDepth = ReadFromTexAndLinearizeDepth( msDepthFai, texCoords, camerarange.x, camerarange.y );
+	/*if( currentPixelDepth * camerarange.y > MAX_SSAO_DISTANCE )
+	{
+		gl_FragColor.a = 1.0;
+		return;
+	}*/
+
 	vec3 fres = normalize((texture2D(noiseMap,texCoords*offset).xyz*2.0) - vec3(1.0));
 
 	vec4 currentPixelSample = texture2D(msNormalFai,texCoords);
 
-	float currentPixelDepth = ReadFromTexAndLinearizeDepth( msDepthFai, texCoords, camerarange.x, camerarange.y );
+
 
 	// current fragment coords in screen space
 	vec3 ep = vec3( texCoords.xy, currentPixelDepth );
@@ -73,5 +84,5 @@ void main(void)
 
 	// output the result
 	float ao = 1.0-totStrength*bl*invSamples;
-	gl_FragColor.a = ao;
+	gl_FragColor.a = ao /** MAX_SSAO_DISTANCE*/;
 }

+ 3 - 1
shaders/PpsSsaoBlur.glsl

@@ -22,7 +22,9 @@ void main()
 	                                     -1.0 * offset, 1.0 * offset, 
 	                                     -2.0 * offset, 2.0 * offset,
 																			 -3.0 * offset, 3.0 * offset/*,
-																			 -4.0 * offset, 4.0 * offset*/ );
+																			 -4.0 * offset, 4.0 * offset,
+																			 -5.0 * offset, 5.0 * offset,
+																			 -6.0 * offset, 6.0 * offset*/ );
 
 	float factor = 0.0;
 	for( int i=0; i<KERNEL_SIZE; i++ )

+ 28 - 1
src/Main.cpp

@@ -32,6 +32,7 @@
 #include "BulletDebuger.h"
 #include "PhyCommon.h"
 #include "Parser.h"
+#include "ParticleEmitter.h"
 
 App* app;
 
@@ -40,6 +41,7 @@ MeshNode* floor__,* sarge,* horse,* crate;
 SkelModelNode* imp;
 PointLight* point_lights[10];
 SpotLight* spot_lights[2];
+ParticleEmitter* partEmitter;
 
 class floor_t: public Camera
 {
@@ -58,6 +60,7 @@ class floor_t: public Camera
 
 // Physics
 BulletDebuger debugDrawer;
+Vec<btRigidBody*> boxes;
 
 #define ARRAY_SIZE_X 5
 #define ARRAY_SIZE_Y 5
@@ -147,9 +150,11 @@ void initPhysics()
 					//if( i=2 ) body->setActivationState(ISLAND_SLEEPING);
 
 					//body->setActivationState(ISLAND_SLEEPING);
-					//body->setGravity( btVector3( 0.0, -1.0, 0.0 ) );
+
 
 					dynamicsWorld->addRigidBody(body);
+					//body->setGravity( toBt( Vec3( Util::randRange(-1.0, 1.0), Util::randRange(-1.0, 1.0), Util::randRange(-1.0, 1.0) ) ) );
+					boxes.push_back( body );
 				}
 			}
 		}
@@ -224,6 +229,11 @@ void init()
 	imp->meshNodes[0]->meshSkelCtrl->skelNode->skelAnimCtrl->skelAnim = Rsrc::skelAnims.load( "models/imp/walk.imp.anim" );
 	imp->meshNodes[0]->meshSkelCtrl->skelNode->skelAnimCtrl->step = 0.8;
 
+	// particle emitter
+	partEmitter = new ParticleEmitter;
+	partEmitter->init( NULL );
+	partEmitter->translationLspace = Vec3( 3.0, 0.0, 0.0 );
+
 	// crate
 	/*crate = new MeshNode;
 	crate->init( "models/crate0/crate0.mesh" );
@@ -251,6 +261,10 @@ void init()
 //=====================================================================================================================================
 int main( int /*argc*/, char* /*argv*/[] )
 {
+	Mat3 m( Mat3::getIdentity() );
+	m.rotateYAxis( M::PI/2 );
+	m.print();
+
 	App::printAppInfo();
 
 	init();
@@ -275,6 +289,7 @@ int main( int /*argc*/, char* /*argv*/[] )
 		if( I::keys[ SDLK_3 ] ) mover = spot_lights[0];
 		if( I::keys[ SDLK_4 ] ) mover = point_lights[1];
 		if( I::keys[ SDLK_5 ] ) mover = spot_lights[1];
+		if( I::keys[ SDLK_6 ] ) mover = partEmitter;
 		if( I::keys[ SDLK_m ] == 1 ) I::warpMouse = !I::warpMouse;
 
 		if( I::keys[SDLK_a] ) mover->moveLocalX( -dist );
@@ -303,6 +318,16 @@ int main( int /*argc*/, char* /*argv*/[] )
 
 		if( I::keys[SDLK_k] ) app->activeCam->lookAtPoint( point_lights[0]->translationWspace );
 
+
+		if( I::keys[SDLK_o] == 1 )
+		{
+			btRigidBody* body = static_cast<btRigidBody*>( boxes[0] );
+			//body->getMotionState()->setWorldTransform( toBt( Mat4( Vec3(0.0, 10.0, 0.0), Mat3::getIdentity(), 1.0 ) ) );
+			body->setWorldTransform( toBt( Mat4( Vec3(0.0, 10.0, 0.0), Mat3::getIdentity(), 1.0 ) ) );
+			//body->clearForces();
+			body->forceActivationState( ACTIVE_TAG );
+		}
+
 		mover->rotationLspace.reorthogonalize();
 
 		//static_cast<btRigidBody*>(dynamicsWorld->getCollisionObjectArray()[1])->getMotionState()->setWorldTransform( toBt(point_lights[0]->transformationWspace) );
@@ -311,6 +336,8 @@ int main( int /*argc*/, char* /*argv*/[] )
 		app->scene->updateAllControllers();
 		app->scene->updateAllWorldStuff();
 
+		partEmitter->update();
+
 
 		app->scene->getPhyWorld()->getDynamicsWorld()->stepSimulation( app->timerTick );
 		app->scene->getPhyWorld()->getDynamicsWorld()->debugDrawWorld();

+ 9 - 3
src/Math/Mat3.h

@@ -30,7 +30,7 @@ class Mat3
 		explicit Mat3( float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22 );
 		explicit Mat3( float arr [] );
 		         Mat3( const Mat3& b );
-		explicit Mat3( const Quat& q ); // 12 muls, 12 adds
+		explicit Mat3( const Quat& q ); ///< @ref Quat to @ref Mat3. 12 muls, 12 adds
 		explicit Mat3( const Euler& eu );
 		explicit Mat3( const Axisang& axisang );
 		// ops with mat3
@@ -52,7 +52,7 @@ class Mat3
 		Mat3  operator / ( float f ) const;
 		Mat3& operator /=( float f );
 		// ops with others
-		Vec3  operator * ( const Vec3& b ) const;  // 9 muls, 6 adds
+		Vec3  operator * ( const Vec3& b ) const;  ///< 9 muls, 6 adds
 		// comparision
 		bool operator ==( const Mat3& b ) const;
 		bool operator !=( const Mat3& b ) const;
@@ -65,10 +65,16 @@ class Mat3
 		void  setColumn( const uint i, const Vec3& v );
 		void  getColumns( Vec3& a, Vec3& b, Vec3& c ) const;
 		Vec3  getColumn( const uint i ) const;
+		Vec3  getXAxis() const;
+		Vec3  getYAxis() const;
+		Vec3  getZAxis() const;
+		void  setXAxis( const Vec3& v3 );
+		void  setYAxis( const Vec3& v3 );
+		void  setZAxis( const Vec3& v3 );
 		void  setRotationX( float rad );
 		void  setRotationY( float rad );
 		void  setRotationZ( float rad );
-		void  rotateXAxis( float rad ); // it rotates "this" in the axis defined by the rotation AND not the world axis
+		void  rotateXAxis( float rad ); ///< It rotates "this" in the axis defined by the rotation AND not the world axis
 		void  rotateYAxis( float rad );
 		void  rotateZAxis( float rad );
 		void  transpose();

+ 54 - 18
src/Math/Mat3.inl.h

@@ -398,9 +398,9 @@ inline Vec3 Mat3::getRow( const uint i ) const
 // setColumn
 inline void Mat3::setColumn( const uint i, const Vec3& v )
 {
-	ME(0,i)=v.x;
-	ME(1,i)=v.y;
-	ME(2,i)=v.z;
+	ME(0,i) = v.x;
+	ME(1,i) = v.y;
+	ME(2,i) = v.z;
 }
 
 // getColumn
@@ -409,19 +409,55 @@ inline Vec3 Mat3::getColumn( const uint i ) const
 	return Vec3( ME(0,i), ME(1,i), ME(2,i) );
 }
 
+// getXAxis
+inline Vec3 Mat3::getXAxis() const
+{
+	return getColumn( 0 );
+}
+
+// getYAxis
+inline Vec3 Mat3::getYAxis() const
+{
+	return getColumn( 1 );
+}
+
+// getZAxis
+inline Vec3 Mat3::getZAxis() const
+{
+	return getColumn( 2 );
+}
+
+// setXAxis
+inline void Mat3::setXAxis( const Vec3& v3 )
+{
+	setColumn( 0, v3 );
+}
+
+// setYAxis
+inline void Mat3::setYAxis( const Vec3& v3 )
+{
+	setColumn( 1, v3 );
+}
+
+// setZAxis
+inline void Mat3::setZAxis( const Vec3& v3 )
+{
+	setColumn( 2, v3 );
+}
+
 // setRotationX
 inline void Mat3::setRotationX( float rad )
 {
 	float sintheta, costheta;
 	sinCos( rad, sintheta, costheta );
 
-	ME(0,0) = 1.0f;
-	ME(0,1) = 0.0f;
-	ME(0,2) = 0.0f;
-	ME(1,0) = 0.0f;
+	ME(0,0) = 1.0;
+	ME(0,1) = 0.0;
+	ME(0,2) = 0.0;
+	ME(1,0) = 0.0;
 	ME(1,1) = costheta;
 	ME(1,2) = -sintheta;
-	ME(2,0) = 0.0f;
+	ME(2,0) = 0.0;
 	ME(2,1) = sintheta;
 	ME(2,2) = costheta;
 }
@@ -433,13 +469,13 @@ inline void Mat3::setRotationY( float rad )
 	sinCos( rad, sintheta, costheta );
 
 	ME(0,0) = costheta;
-	ME(0,1) = 0.0f;
+	ME(0,1) = 0.0;
 	ME(0,2) = sintheta;
-	ME(1,0) = 0.0f;
-	ME(1,1) = 1.0f;
-	ME(1,2) = 0.0f;
+	ME(1,0) = 0.0;
+	ME(1,1) = 1.0;
+	ME(1,2) = 0.0;
 	ME(2,0) = -sintheta;
-	ME(2,1) = 0.0f;
+	ME(2,1) = 0.0;
 	ME(2,2) = costheta;
 }
 
@@ -451,13 +487,13 @@ inline void Mat3::setRotationZ( float rad )
 
 	ME(0,0) = costheta;
 	ME(0,1) = -sintheta;
-	ME(0,2) = 0.0f;
+	ME(0,2) = 0.0;
 	ME(1,0) = sintheta;
 	ME(1,1) = costheta;
-	ME(1,2) = 0.0f;
-	ME(2,0) = 0.0f;
-	ME(2,1) = 0.0f;
-	ME(2,2) = 1.0f;
+	ME(1,2) = 0.0;
+	ME(2,0) = 0.0;
+	ME(2,1) = 0.0;
+	ME(2,2) = 1.0;
 }
 
 // rotateXAxis

+ 56 - 0
src/Renderer/BufferObjects/BufferObject.h

@@ -0,0 +1,56 @@
+#ifndef _BUFFEROBJECT_H_
+#define _BUFFEROBJECT_H_
+
+#include "Common.h"
+#include <GL/glew.h>
+
+/**
+ * @brief A wrapper for OpenGL buffer objects ( vertex arrays, texture buffers etc ) to prevent us from making idiotic errors
+ */
+class BufferObject
+{
+	protected:
+		uint glId; ///< The OpenGL id of the BO
+		GLenum target; ///< Used in glBindBuffer( target, glId ) and for easy access
+
+	public:
+		BufferObject(): glId(0) {}
+		virtual ~BufferObject() { if(glId!=0) deleteBuff(); }
+
+		/**
+		 * Accessor
+		 * @return The OpenGL ID of the buffer
+		 */
+		uint getGlId() const
+		{
+			DEBUG_ERR( glId==0 );
+			return glId;
+		}
+
+		GLenum getBufferTarget() const
+		{
+			DEBUG_ERR( glId==0 );
+			return target;
+		}
+
+		void bind() const
+		{
+			DEBUG_ERR( glId==0 );
+			glBindBuffer( target, glId );
+		}
+
+		void unbind() const
+		{
+			DEBUG_ERR( glId==0 );
+			glBindBuffer( target, 0 );
+		}
+
+		void deleteBuff()
+		{
+			DEBUG_ERR( glId==0 );
+			glDeleteBuffers( 1, &glId );
+			glId = 0;
+		}
+};
+
+#endif

+ 0 - 0
src/Renderer/Fbo.h → src/Renderer/BufferObjects/Fbo.h


+ 6 - 42
src/Renderer/Vbo.h → src/Renderer/BufferObjects/Vbo.h

@@ -1,24 +1,18 @@
 #ifndef _VBO_H_
 #define _VBO_H_
 
-#include <GL/glew.h>
-#include <GL/gl.h>
 #include "Common.h"
+#include "BufferObject.h"
 
-/// This is a wrapper for Vertex Buffer Objects to prevent us from making idiotic errors
-class Vbo
+/**
+ * @brief This is a wrapper for Vertex Buffer Objects to prevent us from making idiotic errors
+ */
+class Vbo: public BufferObject
 {
 	protected:
-		uint glId; ///< The OpenGL id of the VBO
-		// the below vars can be extracted by quering OpenGL but I suppose keeping them here is faster
-		GLenum target;
-		GLenum usage;
+		GLenum usage; ///< GL_STREAM_DRAW or GL_STATIC_DRAW or GL_DYNAMIC_DRAW
 
 	public:
-		Vbo(): glId(0) {}
-		virtual ~Vbo() { deleteBuff(); }
-		uint   getGlId() const { DEBUG_ERR(glId==0); return glId; }
-		GLenum getBufferTarget() const { DEBUG_ERR(glId==0); return target; }
 		GLenum getBufferUsage() const { DEBUG_ERR(glId==0); return usage; }
 
 		/**
@@ -55,36 +49,6 @@ class Vbo
 			unbind();
 		}
 
-		/**
-		 * Deletes the VBO
-		 */
-		void deleteBuff()
-		{
-			DEBUG_ERR( glId==0 ); // VBO unitialized
-			glDeleteBuffers( 1, &glId );
-			glId = 0;
-		}
-
-		/**
-		 * Bind the VBO
-		 */
-		void bind() const
-		{
-			if( glId==0 )
-				PRINT( "-" );
-			DEBUG_ERR( glId==0 ); // VBO unitialized
-			glBindBuffer( target, glId );
-		}
-
-		/**
-		 * Unbinds only the targets that have the same target as this
-		 */
-		void unbind() const
-		{
-			DEBUG_ERR( glId==0 ); // VBO unitialized
-			glBindBuffer( target, 0 );
-		}
-
 		/**
 		 * Unbinds all VBOs, meaning both GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER targets
 		 */

+ 31 - 2
src/Renderer/Dbg.cpp

@@ -111,6 +111,26 @@ void init()
 }
 
 
+float projectRadius( float r, const Vec3& location, const Camera& cam )
+{
+	Vec3 axis = cam.rotationWspace.getXAxis();
+	float c = axis.dot( cam.translationWspace );
+	float dist = axis.dot( location ) - c;
+
+	/*if( dist > 0.0 )
+		return 0.0;*/
+
+	Vec3 p( 0.0, fabs(r), -dist );
+	Vec4 projected = cam.getProjectionMatrix() * Vec4( p, 1.0 );
+	float pr = projected.y / projected.w;
+
+	/*if ( pr > 1.0 )
+		pr = 1.0;*/
+
+	return pr;
+}
+
+
 //=====================================================================================================================================
 // runStage                                                                                                                           =
 //=====================================================================================================================================
@@ -133,7 +153,8 @@ void runStage( const Camera& cam )
 		if
 		(
 			(app->scene->nodes[i]->type == Node::NT_LIGHT && showLights) ||
-			(app->scene->nodes[i]->type == Node::NT_CAMERA && showCameras)
+			(app->scene->nodes[i]->type == Node::NT_CAMERA && showCameras) ||
+			app->scene->nodes[i]->type == Node::NT_PARTICLE_EMITTER
 		)
 		{
 			app->scene->nodes[i]->render();
@@ -157,6 +178,7 @@ void runStage( const Camera& cam )
 
 	glPushMatrix();
 	R::multMatrix( Mat4( Vec3(5.0, 2.0, 2.0), Mat3::getIdentity(), 1.0 ) );
+	R::color3( Vec3(1,0,0) );
 	R::Dbg::renderSphere( 1.2, 16 );
 	glPopMatrix();
 
@@ -185,7 +207,7 @@ void runStage( const Camera& cam )
 	glEnd();
 
 
-	Vec4 g = Vec4( Vec3(c) + Vec3(r,0,0), 1.0 );
+	/*Vec4 g = Vec4( Vec3(c) + Vec3(r,0,0), 1.0 );
 	g = app->activeCam->getProjectionMatrix() * (app->activeCam->getViewMatrix() * g);
 	g /= g.w;
 	float len = Vec2(p-g).getLength();
@@ -195,6 +217,13 @@ void runStage( const Camera& cam )
 	glBegin( GL_POINTS );
 		R::color3( Vec3(1.0,1.0,1.0) );
 		glVertex2fv( &(g)[0] );
+	glEnd();*/
+	float pr = projectRadius( r, c, cam );
+	//PRINT( pr );
+	glPointSize( 10 );
+	glBegin( GL_POINTS );
+		R::color3( Vec3(1.0,0.0,1.0) );
+		glVertex2fv( &( Vec2(p) + Vec2(pr,0.0) )[0] );
 	glEnd();
 
 	glPopMatrix();

+ 5 - 5
src/Renderer/Ms.cpp

@@ -105,11 +105,11 @@ void runStage( const Camera& cam )
 	// render the meshes
 	for( uint i=0; i<app->scene->meshNodes.size(); i++ )
 	{
-		MeshNode* mesh_node = app->scene->meshNodes[i];
-		DEBUG_ERR( mesh_node->material == NULL );
-		if( mesh_node->material->blends || mesh_node->material->refracts ) continue;
-		mesh_node->material->setup();
-		mesh_node->render();
+		MeshNode* meshNode = app->scene->meshNodes[i];
+		DEBUG_ERR( meshNode->material == NULL );
+		if( meshNode->material->blends || meshNode->material->refracts ) continue;
+		meshNode->material->setup();
+		meshNode->render();
 	}
 
 	glPolygonMode( GL_FRONT, GL_FILL ); // the rendering above fucks the polygon mode

+ 8 - 8
src/Renderer/PpsSsao.cpp

@@ -17,12 +17,12 @@ namespace Ssao {
 //=====================================================================================================================================
 // VARS                                                                                                                               =
 //=====================================================================================================================================
-bool enabled = false;
+bool enabled = true;
 
 static Fbo pass0Fbo, pass1Fbo, pass2Fbo;
 
-float renderingQuality = 0.9; // the renderingQuality of the SSAO fai. Chose low so it can blend
-float bluringQuality = 0.75;
+float renderingQuality = 0.75; // the renderingQuality of the SSAO fai. Chose low so it can blend
+float bluringQuality = 1.0;
 
 static uint w, h;
 static uint bw, bh;
@@ -31,7 +31,7 @@ Texture pass0Fai, pass1Fai, fai;
 
 static ShaderProg ssaoSProg, blurSProg, blurSProg2;
 
-static Texture* noise_map;
+static Texture* noiseMap;
 
 
 //=====================================================================================================================================
@@ -130,9 +130,9 @@ void init()
 	bool mipmaping = R::mipmaping;
 	R::textureCompression = false;
 	R::mipmaping = true;
-	noise_map = Rsrc::textures.load( "gfx/noise3.tga" );
-	noise_map->texParameter( GL_TEXTURE_WRAP_S, GL_REPEAT );
-	noise_map->texParameter( GL_TEXTURE_WRAP_T, GL_REPEAT );
+	noiseMap = Rsrc::textures.load( "gfx/noise3.tga" );
+	noiseMap->texParameter( GL_TEXTURE_WRAP_S, GL_REPEAT );
+	noiseMap->texParameter( GL_TEXTURE_WRAP_T, GL_REPEAT );
 	//noise_map->texParameter( GL_TEXTURE_MAG_FILTER, GL_NEAREST );
 	//noise_map->texParameter( GL_TEXTURE_MIN_FILTER, GL_NEAREST );
 	R::textureCompression = texCompr;
@@ -163,7 +163,7 @@ void runPass( const Camera& cam )
 	ssaoSProg.bind();
 	glUniform2fv( ssaoSProg.getUniVar("camerarange").getLoc(), 1, &(Vec2(cam.getZNear(), cam.getZFar()))[0] );
 	ssaoSProg.locTexUnit( ssaoSProg.getUniVar("msDepthFai").getLoc(), R::Ms::depthFai, 0 );
-	ssaoSProg.locTexUnit( ssaoSProg.getUniVar("noiseMap").getLoc(), *noise_map, 1 );
+	ssaoSProg.locTexUnit( ssaoSProg.getUniVar("noiseMap").getLoc(), *noiseMap, 1 );
 	ssaoSProg.locTexUnit( ssaoSProg.getUniVar("msNormalFai").getLoc(), R::Ms::normalFai, 2 );
 	R::DrawQuad( 0 ); // Draw quad
 

+ 20 - 0
src/Scene/GhostNode.h

@@ -0,0 +1,20 @@
+#ifndef _GHOSTNODE_H_
+#define _GHOSTNODE_H_
+
+#include "Common.h"
+#include "Node.h"
+
+/**
+ * This is a node that does nothing
+ */
+class GhostNode: public Node
+{
+	public:
+		GhostNode(): Node(NT_GHOST) { }
+		void init( const char* ) {}
+		void render() {}
+		void deinit() {}
+};
+
+
+#endif

+ 1 - 1
src/Scene/MeshNode.h

@@ -23,7 +23,7 @@ class MeshNode: public Node
 		// controllers
 		MeshSkelNodeCtrl* meshSkelCtrl;
 		// funcs
-		MeshNode(): Node(NT_MESH), meshSkelCtrl(NULL) {}
+		MeshNode(): Node(NT_MESH), material(NULL), dpMaterial(NULL), meshSkelCtrl(NULL) {}
 		virtual void render() { render(material); }
 		virtual void renderDepth() { render( material->dpMtl ); }
 		void init( const char* filename );

+ 1 - 0
src/Scene/Node.h

@@ -21,6 +21,7 @@ class Node
 	public:
 		enum Type
 		{
+			NT_GHOST,
 			NT_LIGHT,
 			NT_CAMERA,
 			NT_MESH,

+ 57 - 5
src/Scene/ParticleEmitter.cpp

@@ -31,10 +31,16 @@ void ParticleEmitter::init( const char* filename )
 	// dummy props init
 	maxParticleLife = 400;
 	minParticleLife = 100;
-	minAngle = Euler( 0.0, toRad(-30.0), toRad(10.0) );
-	maxAngle = Euler( 0.0, toRad(-30.0), toRad(10.0) );
+	minDirection = Vec3( -0.1, 1.0, 0.0 );
+	maxDirection = Vec3( 0.1, 1.0, 0.0 );
+	minForceMagnitude = 1.0;
+	maxForceMagnitude = 2.0;
 	minParticleMass = 1.0;
 	maxParticleMass = 2.0;
+	minGravity = Vec3( 0.0, 0.0, 0.0 );
+	minGravity = Vec3( 0.0, -1.0, 0.0 );
+	minInitialPos = Vec3( -1.0, -1.0, -1.0 );
+	maxInitialPos = Vec3( 1.0, 1.0, 1.0 );
 	maxNumOfParticles = 5;
 	emittionPeriod = 1000;
 
@@ -42,7 +48,7 @@ void ParticleEmitter::init( const char* filename )
 	btCollisionShape* colShape = new btSphereShape( 0.1 );
 
 	particles.resize( maxNumOfParticles );
-	for( int i=0; i<maxNumOfParticles; i++ )
+	for( uint i=0; i<maxNumOfParticles; i++ )
 	{
 		particles[i] = new Particle;
 
@@ -74,7 +80,7 @@ void ParticleEmitter::update()
 		part->lifeTillDeath -= crntTime-timeOfPrevUpdate;
 		if( part->lifeTillDeath < 1 )
 		{
-			part->body->setActivationState( ISLAND_SLEEPING );
+			// ToDo see how bullet can deactivate itself
 		}
 	}
 
@@ -89,8 +95,24 @@ void ParticleEmitter::update()
 			if( part->lifeTillDeath > 0 ) continue;
 
 			// reinit particle
-			//part->body->setActivationState(  );
+			part->lifeTillDeath = Util::randRange( minParticleLife, maxParticleLife );
 
+			Vec3 forceDir = Vec3( Util::randRange( minDirection.x , maxDirection.x ), Util::randRange( minDirection.y , maxDirection.y ),
+			                                       Util::randRange( minDirection.z , maxDirection.z ) );
+			forceDir.normalize();
+			part->body->applyCentralForce( toBt( forceDir * Util::randRange( minForceMagnitude, maxForceMagnitude ) ) );
+
+			minParticleMass = 1.0;
+			maxParticleMass = 2.0;
+
+			Vec3 grav = Vec3( Util::randRange(minGravity.x,maxGravity.x), Util::randRange(minGravity.y,maxGravity.y),
+			                  Util::randRange(minGravity.z,maxGravity.z) );
+			part->body->setGravity( toBt( grav ) );
+
+			//part->body->get
+
+
+			// do the rest
 			++partNum;
 			if( partNum >= particlesPerEmittion ) break;
 		}
@@ -100,3 +122,33 @@ void ParticleEmitter::update()
 
 	timeOfPrevUpdate = crntTime;
 }
+
+
+//=====================================================================================================================================
+// render                                                                                                                             =
+//=====================================================================================================================================
+void ParticleEmitter::render()
+{
+	float vertPositions[] = { maxInitialPos.x, maxInitialPos.y, maxInitialPos.z,   // right top front
+	                          minInitialPos.x, maxInitialPos.y, maxInitialPos.z,   // left top front
+	                          minInitialPos.x, minInitialPos.y, maxInitialPos.z,   // left bottom front
+	                          maxInitialPos.x, minInitialPos.y, maxInitialPos.z,   // right bottom front
+	                          maxInitialPos.x, maxInitialPos.y, minInitialPos.z,   // right top back
+	                          minInitialPos.x, maxInitialPos.y, minInitialPos.z,   // left top back
+	                          minInitialPos.x, minInitialPos.y, minInitialPos.z,   // left bottom back
+	                          maxInitialPos.x, minInitialPos.y, minInitialPos.z }; // right bottom back
+
+	uint vertIndices [] = { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 3, 7, 2, 6 };
+
+	glPushMatrix();
+	R::multMatrix( transformationWspace );
+
+	R::color3( Vec3(1.0) );
+
+	glEnableClientState( GL_VERTEX_ARRAY );
+	glVertexPointer( 3, GL_FLOAT, 0, vertPositions );
+	glDrawElements( GL_LINES, sizeof(vertIndices)/sizeof(uint), GL_UNSIGNED_INT, vertIndices );
+	glDisableClientState( GL_VERTEX_ARRAY );
+
+	glPopMatrix();
+}

+ 12 - 5
src/Scene/ParticleEmitter.h

@@ -4,6 +4,7 @@
 #include "Common.h"
 #include "Node.h"
 #include "MeshNode.h"
+#include "GhostNode.h"
 #include "PhyCommon.h"
 
 
@@ -14,7 +15,7 @@ class ParticleEmitter: public Node
 {
 	public:
 
-		class Particle: public MeshNode
+		class Particle: public GhostNode
 		{
 			public:
 				int lifeTillDeath; ///< Life till death. If 0 then dead. In ms
@@ -26,12 +27,18 @@ class ParticleEmitter: public Node
 		};
 
 		// the properties
-		uint maxParticleLife;
 		uint minParticleLife;
-		Euler maxAngle;
-		Euler minAngle;
+		uint maxParticleLife;
+		Vec3 minDirection;
+		Vec3 maxDirection;
+		float minForceMagnitude;
+		float maxForceMagnitude;
 		float minParticleMass;
 		float maxParticleMass;
+		Vec3 minGravity;
+		Vec3 maxGravity;
+		Vec3 minInitialPos;
+		Vec3 maxInitialPos;
 		uint maxNumOfParticles; ///< The size of the particles vector
 		uint emittionPeriod; ///< How often the emitter emits new particles. In ms
 		uint particlesPerEmittion; ///< How many particles are emitted every emittion
@@ -44,7 +51,7 @@ class ParticleEmitter: public Node
 
 		// funcs
 		ParticleEmitter(): Node( NT_PARTICLE_EMITTER ) {}
-		void render() {}
+		void render();
 		void renderDepth() {}
 		void init( const char* filename );
 		void deinit() {}

+ 4 - 3
src/Util/Common.h

@@ -146,7 +146,9 @@ template <typename Type> inline void MemZero( Type& t )
 //=====================================================================================================================================
 // Vec                                                                                                                              =
 //=====================================================================================================================================
-/// New vector class
+/**
+ * @brief This is a wrapper of std::vector that adds new functionality
+ */
 template<typename Type> class Vec: public vector<Type>
 {
 	public:
@@ -211,8 +213,7 @@ inline void printMallInfoDiff( const Mallinfo& prev, const Mallinfo& now )
 //=====================================================================================================================================
 //                                                                                                                                    =
 //=====================================================================================================================================
-class App;
-extern App* app;
+extern class App* app;
 
 
 #endif

+ 11 - 12
src/Util/Util.cpp

@@ -12,22 +12,21 @@ int randRange( int min, int max )
 	return (rand() % (max-min+1)) + min ;
 }
 
+uint randRange( uint min, uint max )
+{
+	return (rand() % (max-min+1)) + min ;
+}
 
 float randRange( float min, float max )
 {
-	double d = max - min; // difference
-	if( d==0.0 ) return min;
-	// diferrense = mant * e^exp
-	int exp;
-	double mant = frexp( d, &exp );
-
-	int precision = 1000; // more accurate
-
-	mant *= precision;
-	double newMant = rand() % (int)mant;
-	newMant /= precision;
+	float r = (float)rand() / (float)RAND_MAX;
+	return min + r * (max - min);
+}
 
-	return min + (float)ldexp( newMant, exp ); // return min + (new_mant * e^exp)
+double randRange( double min, double max )
+{
+	double r = (double)rand() / (double)RAND_MAX;
+	return min + r * (max - min);
 }
 
 

+ 4 - 2
src/Util/Util.h

@@ -5,8 +5,10 @@
 
 namespace Util {
 
-extern int   randRange( int min, int max );
-extern float randRange( float min, float max );
+extern int    randRange( int min, int max );
+extern uint   randRange( uint min, uint max );
+extern float  randRange( float min, float max );
+extern double randRange( double min, double max );
 
 extern string      readFile( const char* filename );
 extern Vec<string> getFileLines( const char* filename );

Деякі файли не було показано, через те що забагато файлів було змінено