Browse Source

Major release (wont compile)

* Moved common to utility
* Moned all resources to resources
* Moved all scene graph related to scene
* The object_t is now node_t
* The mesh_data_t and smodel do not exist
* New scene graph implementation
Panagiotis Christopoulos Charitos 16 years ago
parent
commit
5834b9363e
51 changed files with 1700 additions and 2376 deletions
  1. 7 5
      src/main.cpp
  2. 8 6
      src/math/mat3.inl.h
  3. 2 2
      src/math/mat4.inl.h
  4. 5 5
      src/math/vec4.inl.h
  5. 1 1
      src/renderer/r_bs.cpp
  6. 1 1
      src/renderer/r_dbg.cpp
  7. 1 1
      src/renderer/r_is_shadows.cpp
  8. 1 1
      src/renderer/r_ms.cpp
  9. 24 23
      src/resources/material.cpp
  10. 13 8
      src/resources/material.h
  11. 316 0
      src/resources/mesh.cpp
  12. 16 30
      src/resources/mesh.h
  13. 4 5
      src/resources/resource.cpp
  14. 28 28
      src/resources/resource.h
  15. 0 0
      src/resources/shader_parser.cpp
  16. 0 0
      src/resources/shader_parser.h
  17. 0 0
      src/resources/shader_prog.cpp
  18. 0 0
      src/resources/shader_prog.h
  19. 70 0
      src/resources/skel_anim.cpp
  20. 45 0
      src/resources/skel_anim.h
  21. 97 0
      src/resources/skeleton.cpp
  22. 48 0
      src/resources/skeleton.h
  23. 0 0
      src/resources/texture.cpp
  24. 0 0
      src/resources/texture.h
  25. 41 60
      src/scene/camera.cpp
  26. 14 17
      src/scene/camera.h
  27. 18 0
      src/scene/controller.h
  28. 36 0
      src/scene/light.cpp
  29. 72 0
      src/scene/light.h
  30. 168 0
      src/scene/mesh_node.cpp
  31. 43 0
      src/scene/mesh_node.h
  32. 137 0
      src/scene/node.cpp
  33. 65 0
      src/scene/node.h
  34. 140 0
      src/scene/scene.cpp
  35. 19 23
      src/scene/scene.h
  36. 197 0
      src/scene/skel_node.cpp
  37. 52 0
      src/scene/skel_node.h
  38. 0 77
      src/uncategorized/lights.cpp
  39. 0 85
      src/uncategorized/lights.h
  40. 5 5
      src/uncategorized/map.cpp
  41. 5 5
      src/uncategorized/map.h
  42. 0 612
      src/uncategorized/mesh.cpp
  43. 0 63
      src/uncategorized/model.cpp
  44. 0 18
      src/uncategorized/model.h
  45. 0 180
      src/uncategorized/scene.cpp
  46. 0 867
      src/uncategorized/smodel.cpp
  47. 0 190
      src/uncategorized/smodel.h
  48. 0 33
      src/uncategorized/spatial.cpp
  49. 0 24
      src/uncategorized/spatial.h
  50. 0 0
      src/utility/common.cpp
  51. 1 1
      src/utility/common.h

+ 7 - 5
src/main.cpp

@@ -26,21 +26,23 @@
 #include "map.h"
 #include "model.h"
 #include "renderer.hpp"
+#include "mesh_node.h"
+#include "skel_anim.h"
 
 camera_t main_cam;
 
-mesh_t imp, mcube, floor__, sarge;
+mesh_node_t imp, mcube, floor__, sarge;
 
 smodel_t mdl;
 
-skeleton_anim_t walk_anim;
+skel_anim_t walk_anim;
 
 point_light_t point_lights[10];
 spot_light_t projlights[2];
 
 map_t map;
 
-class sphere_t: public mesh_t
+class sphere_t: public mesh_node_t
 {
 	public:
 		sphere_t()
@@ -154,7 +156,7 @@ void Init()
 	sarge.RotateLocalX(ToRad(-90));
 	sarge.translation_lspace = vec3_t(0, -2.8, 1.0);
 
-	mdl.Init( rsrc::model_datas.Load( "models/imp/imp.smdl" ) );
+	mdl.Init( rsrc::model.Load( "models/imp/imp.smdl" ) );
 	mdl.translation_lspace = vec3_t( 0.0, 2.11, 0.0 );
 	mdl.scale_lspace = 0.7;
 	mdl.rotation_lspace.RotateXAxis( -PI/2 );
@@ -281,7 +283,7 @@ int main( int /*argc*/, char* /*argv*/[] )
 		// std stuff follow
 		SDL_GL_SwapBuffers();
 		r::PrintLastError();
-		if( 1 )
+		if( 0 )
 		{
 			if( r::frames_num == 10 ) r::TakeScreenshot("gfx/screenshot.tga");
 			hndl::WaitForNextFrame();

+ 8 - 6
src/math/mat3.inl.h

@@ -150,7 +150,7 @@ inline mat3_t mat3_t::operator +( const mat3_t& b ) const
 	return c;
 }
 
-// 3x3 + 3x3 (self)
+// 3x3 += 3x3
 inline mat3_t& mat3_t::operator +=( const mat3_t& b )
 {
 	for( int i=0; i<9; i++ )
@@ -167,7 +167,7 @@ inline mat3_t mat3_t::operator -( const mat3_t& b ) const
 	return c;
 }
 
-// 3x3 - 3x3 (self)
+// 3x3 -= 3x3
 inline mat3_t& mat3_t::operator -=( const mat3_t& b )
 {
 	for( int i=0; i<9; i++ )
@@ -191,7 +191,7 @@ inline mat3_t mat3_t::operator *( const mat3_t& b ) const
 	return c;
 }
 
-// 3x3 * 3x3 (self)
+// 3x3 *= 3x3
 inline mat3_t& mat3_t::operator *=( const mat3_t& b )
 {
 	ME = ME * b;
@@ -214,10 +214,11 @@ inline mat3_t operator +( float f, const mat3_t& m3 )
 }
 
 // 3x3 += float
-inline mat3_t mat3_t::operator +=( float f ) const
+inline mat3_t& mat3_t::operator +=( float f )
 {
 	for( uint i=0; i<9; i++ )
 		ME[i] += f;
+	return ME;
 }
 
 // 3x3 - float
@@ -239,10 +240,11 @@ inline mat3_t operator -( float f, const mat3_t& m3 )
 }
 
 // 3x3 -= float
-inline mat3_t mat3_t::operator -=( float f ) const
+inline mat3_t& mat3_t::operator -=( float f )
 {
 	for( uint i=0; i<9; i++ )
 		ME[i] -= f;
+	return ME;
 }
 
 // 3x3 * float
@@ -263,7 +265,7 @@ inline mat3_t operator *( float f, const mat3_t& m3 )
 	return out;
 }
 
-// 3x3 * float (self)
+// 3x3 *= float
 inline mat3_t& mat3_t::operator *=( float f )
 {
 	for( uint i=0; i<9; i++ )

+ 2 - 2
src/math/mat4.inl.h

@@ -278,7 +278,7 @@ inline mat4_t operator -( float f, const mat4_t& m4 )
 {
 	mat4_t out;
 	for( int i=0; i<16; i++ )
-		out[i] = f- m3[i];
+		out[i] = f- m4[i];
 	return out;
 }
 
@@ -327,7 +327,7 @@ inline mat4_t operator /( float f, const mat4_t& m4 )
 {
 	mat4_t out;
 	for( uint i=0; i<9; i++ )
-		out = f / m4[i];
+		out[i] = f / m4[i];
 	return out;
 }
 

+ 5 - 5
src/math/vec4.inl.h

@@ -142,7 +142,7 @@ inline vec4_t vec4_t::operator +( float f ) const
 }
 
 // float + vec4
-vec4_t operator +( float f, const vec4_t& v4 )
+inline vec4_t operator +( float f, const vec4_t& v4 )
 {
 	return v4+f;
 }
@@ -161,7 +161,7 @@ inline vec4_t vec4_t::operator -( float f ) const
 }
 
 // float - vec4
-vec4_t operator -( float f, const vec4_t& v4 )
+inline vec4_t operator -( float f, const vec4_t& v4 )
 {
 	return vec4_t( f-v4.x, f-v4.y, f-v4.z, f-v4.w );
 }
@@ -180,7 +180,7 @@ inline vec4_t vec4_t::operator *( float f ) const
 }
 
 // float * vec4
-vec4_t operator *( float f, const vec4_t& v4 )
+inline vec4_t operator *( float f, const vec4_t& v4 )
 {
 	return v4*f;
 }
@@ -199,9 +199,9 @@ inline vec4_t vec4_t::operator /( float f ) const
 }
 
 // float / vec4
-vec4_t operator /( float f, const vec4_t& v4 )
+inline vec4_t operator /( float f, const vec4_t& v4 )
 {
-	return vec4_t( f/vec4.x, f/vec4.y, f/vec4.z, f/vec4.w );
+	return vec4_t( f/v4.x, f/v4.y, f/v4.z, f/v4.w );
 }
 
 // vec4 /= float

+ 1 - 1
src/renderer/r_bs.cpp

@@ -113,7 +113,7 @@ void RunStage( const camera_t& cam )
 	// render the meshes
 	for( uint i=0; i<scene::meshes.size(); i++ )
 	{
-		mesh_t* mesh = scene::meshes[i];
+		mesh_node_t* mesh = scene::meshes[i];
 		if( mesh->material->blends )
 		{
 			b_fbo.Bind();

+ 1 - 1
src/renderer/r_dbg.cpp

@@ -90,7 +90,7 @@ void RunStage( const camera_t& cam )
 		}
 		else if( scene::objects[i]->type == object_t::MESH && show_vnormals )
 		{
-			mesh_t* mesh = static_cast<mesh_t*>( scene::objects[i] );
+			mesh_node_t* mesh = static_cast<mesh_node_t*>( scene::objects[i] );
 			mesh->RenderNormals();
 			mesh->RenderTangents();
 		}

+ 1 - 1
src/renderer/r_is_shadows.cpp

@@ -101,7 +101,7 @@ void RunPass( const camera_t& cam )
 
 	// render all meshes
 	for( uint i=0; i<scene::meshes.size(); i++ )
-		RenderDepth<mesh_t, true>( *scene::meshes[i] );
+		RenderDepth<mesh_node_t, true>( *scene::meshes[i] );
 
 	// render all smodels
 	for( uint i=0; i<scene::smodels.size(); i++ )

+ 1 - 1
src/renderer/r_ms.cpp

@@ -102,7 +102,7 @@ void RunStage( const camera_t& cam )
 
 	// render the meshes
 	for( uint i=0; i<scene::meshes.size(); i++ )
-		Render<mesh_t, false>( scene::meshes[i] );
+		Render<mesh_node_t, false>( scene::meshes[i] );
 
 	// render the smodels
 	for( uint i=0; i<scene::smodels.size(); i++ )

+ 24 - 23
src/uncategorized/material.cpp → src/resources/material.cpp

@@ -68,7 +68,7 @@ bool material_t::Load( const char* filename )
 		//** SHADER **
 		if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "SHADER" ) )
 		{
-			if( shader ) ERROR( "Shader allready loaded" );
+			if( shader_prog ) ERROR( "Shader allready loaded" );
 
 			token = &scanner.GetNextToken();
 			if( token->code != scanner_t::TC_STRING )
@@ -76,9 +76,9 @@ bool material_t::Load( const char* filename )
 				PARSE_ERR_EXPECTED( "string" );
 				return false;
 			}
-			shader = rsrc::shaders.Load( token->value.string );
+			shader_prog = rsrc::shaders.Load( token->value.string );
 		}
-		//** DIFFUSE_COL **
+		/*//** DIFFUSE_COL **
 		else if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "DIFFUSE_COL" ) )
 		{
 			ParseArrOfNumbers<float>( scanner, true, true, 4, &diffuse_color[0] );
@@ -101,7 +101,7 @@ bool material_t::Load( const char* filename )
 				shininess = token->value.float_;
 			else
 				shininess = (float)token->value.int_;
-		}
+		}*/
 		//** BLENDS **
 		else if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "BLENDS" ) )
 		{
@@ -278,6 +278,7 @@ bool material_t::Load( const char* filename )
 						break;
 					// float
 					case user_defined_var_t::FLOAT:
+						token = &scanner.GetNextToken();
 						if( token->code == scanner_t::TC_NUMBER && token->type == scanner_t::DT_FLOAT )
 							var.value.float_ = token->value.float_;
 						else
@@ -323,41 +324,41 @@ bool material_t::Load( const char* filename )
 bool material_t::InitTheOther()
 {
 	// sanity check
-	if( !shader )
+	if( !shader_prog )
 	{
 		ERROR( "Material file (\"" << GetPath() << GetName() << "\") without shader is like cake without sugar" );
 		return false;
 	}
 
 	// for all user defined vars get their location
-	shader->Bind();
+	shader_prog->Bind();
 	for( uint i=0; i<user_defined_vars.size(); i++ )
 	{
-		int loc = shader->GetUniformLocation( user_defined_vars[i].name.c_str() );
+		int loc = shader_prog->GetUniformLocation( user_defined_vars[i].name.c_str() );
 		if( loc == -1 )
 		{
-			ERROR( "Material \"" << GetPath() << GetName() << "\", shader \"" << shader->GetName() << "\" and user defined var \"" << user_defined_vars[i].name <<
-			       "\" do not combine. Incorect location" );
+			ERROR( "Material \"" << GetPath() << GetName() << "\", shader \"" << shader_prog->GetName() << "\" and user defined var \"" <<
+			       user_defined_vars[i].name << "\" do not combine. Incorect location" );
 			return false;
 		}
 		user_defined_vars[i].uniform_location = loc;
 	}
-	shader->Unbind();
+	shader_prog->Unbind();
 
 	// init the attribute locations
-	attribute_locs.tanget = shader->GetAttributeLocationSilently( "tangent" );
-	attribute_locs.position = shader->GetAttributeLocationSilently( "position" );
-	attribute_locs.normal = shader->GetAttributeLocationSilently( "normal" );
-	attribute_locs.tex_coords = shader->GetAttributeLocationSilently( "tex_coords" );
+	attribute_locs.tanget = shader_prog->GetAttributeLocationSilently( "tangent" );
+	attribute_locs.position = shader_prog->GetAttributeLocationSilently( "position" );
+	attribute_locs.normal = shader_prog->GetAttributeLocationSilently( "normal" );
+	attribute_locs.tex_coords = shader_prog->GetAttributeLocationSilently( "tex_coords" );
 
 	// vertex weights
-	attribute_locs.vert_weight_bones_num = shader->GetAttributeLocationSilently( "vert_weight_bones_num" );
+	attribute_locs.vert_weight_bones_num = shader_prog->GetAttributeLocationSilently( "vert_weight_bones_num" );
 	if( attribute_locs.vert_weight_bones_num != -1 )
 	{
-		attribute_locs.vert_weight_bone_ids = shader->GetAttributeLocation( "vert_weight_bone_ids" );
-		attribute_locs.vert_weight_weights = shader->GetAttributeLocation( "vert_weight_weights" );
-		uniform_locs.skinning_rotations = shader->GetUniformLocation( "skinning_rotations" );
-		uniform_locs.skinning_translations = shader->GetUniformLocation( "skinning_translations" );
+		attribute_locs.vert_weight_bone_ids = shader_prog->GetAttributeLocation( "vert_weight_bone_ids" );
+		attribute_locs.vert_weight_weights = shader_prog->GetAttributeLocation( "vert_weight_weights" );
+		uniform_locs.skinning_rotations = shader_prog->GetUniformLocation( "skinning_rotations" );
+		uniform_locs.skinning_translations = shader_prog->GetUniformLocation( "skinning_translations" );
 	}
 
 	return true;
@@ -371,7 +372,7 @@ Unload
 */
 void material_t::Unload()
 {
-	rsrc::shaders.Unload( shader );
+	rsrc::shaders.Unload( shader_prog );
 
 	// loop all user defined vars and unload the textures
 	for( uint i=0; i<user_defined_vars.size(); i++ )
@@ -392,7 +393,7 @@ SetToDefault
 */
 void material_t::SetToDefault()
 {
-	shader = NULL;
+	shader_prog = NULL;
 	blends = false;
 	blending_sfactor = GL_ONE;
 	blending_dfactor = GL_ZERO;
@@ -414,7 +415,7 @@ Setup
 */
 void material_t::Setup()
 {
-	shader->Bind();
+	shader_prog->Bind();
 
 	// first set the standard vars
 	glMaterialfv( GL_FRONT, GL_DIFFUSE, &diffuse_color[0] );
@@ -447,7 +448,7 @@ void material_t::Setup()
 		{
 			// texture
 			case user_defined_var_t::TEXTURE:
-				shader->LocTexUnit( udv->uniform_location, *udv->value.texture, texture_unit++ );
+				shader_prog->LocTexUnit( udv->uniform_location, *udv->value.texture, texture_unit++ );
 				break;
 			// float
 			case user_defined_var_t::FLOAT:

+ 13 - 8
src/uncategorized/material.h → src/resources/material.h

@@ -8,14 +8,10 @@
 /// The material class
 class material_t: public resource_t
 {
-	protected:
-		void SetToDefault();
-		bool InitTheOther(); ///< The func is for not poluting Load with extra code
-
+	//===================================================================================================================================
+	// User defined variables                                                                                                           =
+	//===================================================================================================================================
 	public:
-		//=================================================================================================================================
-		// user_defined_var_t nested class                                                                                                =
-		//=================================================================================================================================
 		/// class for user defined material variables that will be passes in to the shader
 		class user_defined_var_t
 		{
@@ -45,7 +41,16 @@ class material_t: public resource_t
 
 		vec_t< user_defined_var_t > user_defined_vars;
 
-		shader_prog_t* shader;
+
+	//===================================================================================================================================
+	// Misc                                                                                                                             =
+	//===================================================================================================================================
+	protected:
+		void SetToDefault();
+		bool InitTheOther(); ///< The func is for not poluting Load with extra code
+
+	public:
+		shader_prog_t* shader_prog;
 
 		vec4_t diffuse_color;
 		vec4_t specular_color;

+ 316 - 0
src/resources/mesh.cpp

@@ -0,0 +1,316 @@
+#include "mesh.h"
+#include "renderer.h"
+#include "resource.h"
+#include "scanner.h"
+#include "parser.h"
+
+
+//=====================================================================================================================================
+// Load                                                                                                                               =
+//=====================================================================================================================================
+bool mesh_t::Load( const char* filename )
+{
+	scanner_t scanner;
+	if( !scanner.LoadFile( filename ) ) return false;
+
+	const scanner_t::token_t* token;
+
+
+	//** MATERIAL **
+	token = &scanner.GetNextToken();
+	if( token->code != scanner_t::TC_STRING )
+	{
+		PARSE_ERR_EXPECTED( "string" );
+		return false;
+	}
+	material_name = token->value.string;
+
+	//** VERTS **
+	// verts num
+	token = &scanner.GetNextToken();
+	if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
+	{
+		PARSE_ERR_EXPECTED( "integer" );
+		return false;
+	}
+	vert_coords.resize( token->value.int_ );
+
+	// read the verts
+	for( uint i=0; i<vert_coords.size(); i++ )
+	{
+		if( !ParseArrOfNumbers<float>( scanner, false, true, 3, &vert_coords[i][0] ) ) return false;
+	}
+
+	//** FACES **
+	// faces num
+	token = &scanner.GetNextToken();
+	if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
+	{
+		PARSE_ERR_EXPECTED( "integer" );
+		return false;
+	}
+	tris.resize( token->value.int_ );
+	// read the faces
+	for( uint i=0; i<tris.size(); i++ )
+	{
+		if( !ParseArrOfNumbers<uint>( scanner, false, true, 3, tris[i].vert_ids ) ) return false;
+	}
+
+	//** UVS **
+	// UVs num
+	token = &scanner.GetNextToken();
+	if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
+	{
+		PARSE_ERR_EXPECTED( "integer" );
+		return false;
+	}
+	tex_coords.resize( token->value.int_ );
+	// read the tex_coords
+	for( uint i=0; i<tex_coords.size(); i++ )
+	{
+		if( !ParseArrOfNumbers( scanner, false, true, 2, &tex_coords[i][0] ) ) return false;
+	}
+
+	//** VERTEX WEIGHTS **
+	token = &scanner.GetNextToken();
+	if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
+	{
+		PARSE_ERR_EXPECTED( "integer" );
+		return false;
+	}
+	vert_weights.resize( token->value.int_ );
+	for( uint i=0; i<vert_weights.size(); i++ )
+	{
+		// get the bone connections num
+		token = &scanner.GetNextToken();
+		if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
+		{
+			PARSE_ERR_EXPECTED( "integer" );
+			return false;
+		}
+
+		// we treat as error if one vert doesnt have a bone
+		if( token->value.int_ < 1 )
+		{
+			ERROR( "Vert \"" << i << "\" doesnt have at least one bone" );
+			return false;
+		}
+
+		// and here is another possible error
+		if( token->value.int_ > vertex_weight_t::MAX_BONES_PER_VERT )
+		{
+			ERROR( "Cannot have more than " << vertex_weight_t::MAX_BONES_PER_VERT << " bones per vertex" );
+			return false;
+		}
+		vert_weights[i].bones_num = token->value.int_;
+
+		// for all the weights of the current vertes
+		for( uint j=0; j<vert_weights[i].bones_num; j++ )
+		{
+			// read bone id
+			token = &scanner.GetNextToken();
+			if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
+			{
+				PARSE_ERR_EXPECTED( "integer" );
+				return false;
+			}
+			vert_weights[i].bone_ids[j] = token->value.int_;
+
+			// read the weight of that bone
+			token = &scanner.GetNextToken();
+			if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_FLOAT )
+			{
+				PARSE_ERR_EXPECTED( "float" );
+				return false;
+			}
+			vert_weights[i].weights[j] = token->value.float_;
+		}
+	}
+
+	// Sanity checks
+	if( vert_coords.size()<1 || tris.size()<1 )
+	{
+		ERROR( "Vert coords and tris must be filled \"" << filename << "\"" );
+		return false;
+	}
+	if( tex_coords.size()!=0 && tex_coords.size()!=vert_coords.size() )
+	{
+		ERROR( "Tex coords num must be zero or equal to vertex coords num \"" << filename << "\"" );
+		return false;
+	}
+	if( vert_weights.size()!=0 && vert_weights.size()!=vert_coords.size() )
+	{
+		ERROR( "Vert weights num must be zero or equal to vertex coords num \"" << filename << "\"" );
+		return false;
+	}
+
+	CreateAllNormals();
+	CreateVertTangents();
+	CreateVertIndeces();
+	CreateVBOs();
+	CalcBSphere();
+
+	return true;
+}
+
+
+//=====================================================================================================================================
+// Unload                                                                                                                             =
+//=====================================================================================================================================
+void mesh_t::Unload()
+{
+	// ToDo: add when finalized
+}
+
+
+//=====================================================================================================================================
+// CreateFaceNormals                                                                                                                  =
+//=====================================================================================================================================
+void mesh_t::CreateVertIndeces()
+{
+	DEBUG_ERR( vert_indeces.size() > 0 );
+
+	vert_indeces.resize( tris.size() * 3 );
+	for( uint i=0; i<tris.size(); i++ )
+	{
+		vert_indeces[i*3+0] = tris[i].vert_ids[0];
+		vert_indeces[i*3+1] = tris[i].vert_ids[1];
+		vert_indeces[i*3+2] = tris[i].vert_ids[2];
+	}
+}
+
+
+//=====================================================================================================================================
+// CreateFaceNormals                                                                                                                  =
+//=====================================================================================================================================
+void mesh_t::CreateFaceNormals()
+{
+	for( uint i=0; i<tris.size(); i++ )
+	{
+		triangle_t& tri = tris[i];
+		const vec3_t& v0 = vert_coords[ tri.vert_ids[0] ];
+		const vec3_t& v1 = vert_coords[ tri.vert_ids[1] ];
+		const vec3_t& v2 = vert_coords[ tri.vert_ids[2] ];
+
+		tri.normal = ( v1 - v0 ).Cross( v2 - v0 );
+
+		tri.normal.Normalize();
+	}
+}
+
+
+//=====================================================================================================================================
+// CreateVertNormals                                                                                                                  =
+//=====================================================================================================================================
+void mesh_t::CreateVertNormals()
+{
+	vert_normals.resize( vert_coords.size() ); // alloc
+
+	for( uint i=0; i<vert_coords.size(); i++ )
+		vert_normals[i] = vec3_t( 0.0, 0.0, 0.0 );
+
+	for( uint i=0; i<tris.size(); i++ )
+	{
+		const triangle_t& tri = tris[i];
+		vert_normals[ tri.vert_ids[0] ] += tri.normal;
+		vert_normals[ tri.vert_ids[1] ] += tri.normal;
+		vert_normals[ tri.vert_ids[2] ] += tri.normal;
+	}
+
+	for( uint i=0; i<vert_normals.size(); i++ )
+		vert_normals[i].Normalize();
+}
+
+
+//=====================================================================================================================================
+// CreateVertTangents                                                                                                                 =
+//=====================================================================================================================================
+void mesh_t::CreateVertTangents()
+{
+	vert_tangents.resize( vert_coords.size() ); // alloc
+
+	vec_t<vec3_t> bitagents( vert_coords.size() );
+
+	for( uint i=0; i<vert_tangents.size(); i++ )
+	{
+		vert_tangents[i] = vec4_t( 0.0 );
+		bitagents[i] = vec3_t( 0.0 );
+	}
+
+	for( uint i=0; i<tris.size(); i++ )
+	{
+		const triangle_t& tri = tris[i];
+		const int i0 = tri.vert_ids[0];
+		const int i1 = tri.vert_ids[1];
+		const int i2 = tri.vert_ids[2];
+		const vec3_t& v0 = vert_coords[ i0 ];
+		const vec3_t& v1 = vert_coords[ i1 ];
+		const vec3_t& v2 = vert_coords[ i2 ];
+		vec3_t edge01 = v1 - v0;
+		vec3_t edge02 = v2 - v0;
+		vec2_t uvedge01 = tex_coords[i1] - tex_coords[i0];
+		vec2_t uvedge02 = tex_coords[i2] - tex_coords[i0];
+
+
+		float det = (uvedge01.y * uvedge02.x) - (uvedge01.x * uvedge02.y);
+		DEBUG_ERR( IsZero(det) );
+		det = 1.0f / det;
+
+		vec3_t t = ( edge02 * uvedge01.y - edge01 * uvedge02.y ) * det;
+		vec3_t b = ( edge02 * uvedge01.x - edge01 * uvedge02.x ) * det;
+		t.Normalize();
+		b.Normalize();
+
+		vert_tangents[i0] += vec4_t(t, 1.0);
+		vert_tangents[i1] += vec4_t(t, 1.0);
+		vert_tangents[i2] += vec4_t(t, 1.0);
+
+		bitagents[i0] += b;
+		bitagents[i1] += b;
+		bitagents[i2] += b;
+	}
+
+	for( uint i=0; i<vert_tangents.size(); i++ )
+	{
+		vec3_t t = vec3_t(vert_tangents[i]);
+		const vec3_t& n = vert_normals[i];
+		vec3_t& b = bitagents[i];
+
+		//t = t - n * n.Dot(t);
+		t.Normalize();
+
+		b.Normalize();
+
+		float w = ( (n.Cross(t)).Dot( b ) < 0.0) ? 1.0 : -1.0;
+
+		vert_tangents[i] = vec4_t( t, w );
+	}
+
+	bitagents.clear();
+}
+
+
+//=====================================================================================================================================
+// CreateVBOs                                                                                                                         =
+//=====================================================================================================================================
+void mesh_t::CreateVBOs()
+{
+	vbos.vert_indeces.Create( GL_ELEMENT_ARRAY_BUFFER, vert_indeces.GetSizeInBytes(), &vert_indeces[0], GL_STATIC_DRAW );
+	vbos.vert_coords.Create( GL_ARRAY_BUFFER, vert_coords.GetSizeInBytes(), &vert_coords[0], GL_STATIC_DRAW );
+	vbos.vert_normals.Create( GL_ARRAY_BUFFER, vert_normals.GetSizeInBytes(), &vert_normals[0], GL_STATIC_DRAW );
+	vbos.vert_tangents.Create( GL_ARRAY_BUFFER, vert_tangents.GetSizeInBytes(), &vert_tangents[0], GL_STATIC_DRAW );
+	if( tex_coords.size() > 1 )
+		vbos.tex_coords.Create( GL_ARRAY_BUFFER, tex_coords.GetSizeInBytes(), &tex_coords[0], GL_STATIC_DRAW );
+	if( vert_weights.size() > 1 )
+		vbos.vert_weights.Create( GL_ARRAY_BUFFER, vert_weights.GetSizeInBytes(), &vert_weights[0], GL_STATIC_DRAW );
+
+}
+
+
+//=====================================================================================================================================
+// CalcBSphere                                                                                                                        =
+//=====================================================================================================================================
+void mesh_t::CalcBSphere()
+{
+	bsphere.Set( &vert_coords[0], 0, vert_coords.size() );
+}

+ 16 - 30
src/uncategorized/mesh.h → src/resources/mesh.h

@@ -2,16 +2,17 @@
 #define _MESH_H_
 
 #include "common.h"
-#include "material.h"
 #include "gmath.h"
 #include "primitives.h"
-#include "engine_class.h"
-#include "object.h"
 #include "vbo.h"
+#include "resource.h"
+#include "collision.h"
 
-// mesh data
-class mesh_data_t: public resource_t
+
+/// Mesh resource
+class mesh_t: public resource_t
 {
+	// data
 	public:
 		class vertex_weight_t
 		{
@@ -29,9 +30,8 @@ class mesh_data_t: public resource_t
 		vec_t<vec4_t>          vert_tangents;
 		vec_t<vec2_t>          tex_coords;    ///< One for every vert so we can use vertex arrays
 		vec_t<vertex_weight_t> vert_weights;
-
-		vec_t<triangle_t> tris;
-		vec_t<ushort>     vert_indeces; ///< Used for vertex arrays
+		vec_t<triangle_t>      tris;
+		vec_t<ushort>          vert_indeces; ///< Used for vertex arrays
 
 		struct
 		{
@@ -43,40 +43,26 @@ class mesh_data_t: public resource_t
 			vbo_t vert_weights;
 		} vbos;
 
-		char* material_name;
+		string material_name;
 
-		mesh_data_t(): material_name(NULL) {}
-		virtual ~mesh_data_t() { /*ToDo*/ }
+		bsphere_t bsphere;
 
-		// funcs
-		bool Load( const char* filename );
-		void Unload();
+	// funcs
+	protected:
 		void CreateFaceNormals();
 		void CreateVertNormals();
 		void CreateAllNormals() { CreateFaceNormals(); CreateVertNormals(); }
 		void CreateVertTangents();
 		void CreateVertIndeces();
 		void CreateVBOs();
-};
-
+		void CalcBSphere();
 
-// mesh
-class mesh_data_user_class_t: public data_user_class_t {}; // for ambiguity reasons
-
-class mesh_t: public object_t, public mesh_data_user_class_t
-{
 	public:
-		mesh_data_t* mesh_data;
-		material_t* material;
-
-		mesh_t(): object_t(MESH), mesh_data(NULL), material(NULL) {}
-
+		mesh_t() {}
+		virtual ~mesh_t() { /*ToDo*/ }
 		bool Load( const char* filename );
 		void Unload();
-		void Render();
-		void RenderDepth();
-		void RenderNormals();
-		void RenderTangents();
+
 };
 
 

+ 4 - 5
src/uncategorized/resource.cpp → src/resources/resource.cpp

@@ -3,8 +3,7 @@
 #include "material.h"
 #include "shader_prog.h"
 #include "mesh.h"
-#include "smodel.h"
-#include "model.h"
+#include "skel_anim.h"
 
 
 namespace rsrc {
@@ -18,9 +17,9 @@ DATA OBJECTS
 container_t<texture_t>     textures;
 container_t<shader_prog_t> shaders;
 container_t<material_t>    materials;
-container_t<mesh_data_t>   mesh_datas;
-container_t<model_data_t>  model_datas;
-container_t<model_t>       models;
+container_t<mesh_t>        meshes;
+container_t<skeleton_t>    skeletons;
+container_t<skel_anim_t>   skel_anims;
 
 
 } // end namespace

+ 28 - 28
src/uncategorized/resource.h → src/resources/resource.h

@@ -8,9 +8,9 @@
 class texture_t;
 class material_t;
 class shader_prog_t;
-class mesh_data_t;
-class model_data_t;
-class model_t;
+class mesh_t;
+class skeleton_t;
+class skel_anim_t;
 
 
 // forward decl
@@ -35,9 +35,9 @@ class resource_t
 	friend class rsrc::container_t<texture_t>;
 	friend class rsrc::container_t<material_t>;
 	friend class rsrc::container_t<shader_prog_t>;
-	friend class rsrc::container_t<mesh_data_t>;
-	friend class rsrc::container_t<model_data_t>;
-	friend class rsrc::container_t<model_t>;
+	friend class rsrc::container_t<skeleton_t>;
+	friend class rsrc::container_t<mesh_t>;
+	friend class rsrc::container_t<skel_anim_t>;
 	friend class shader_prog_t;
 
 	public:
@@ -56,9 +56,9 @@ namespace rsrc { // begin namesapce
 extern container_t<texture_t>     textures;
 extern container_t<shader_prog_t> shaders;
 extern container_t<material_t>    materials;
-extern container_t<mesh_data_t>   mesh_datas;
-extern container_t<model_data_t>  model_datas;
-extern container_t<model_t>       models;
+extern container_t<mesh_t>        meshes;
+extern container_t<skeleton_t>    skeletons;
+extern container_t<skel_anim_t>   skel_anims;
 
 
 /// resource container class
@@ -69,10 +69,10 @@ template<typename type_t> class container_t: public vec_t<type_t*>
 		typedef vec_t<type_t*> base_class_t;
 
 		/**
-		* Search inside the container by name
-		* @param name The name of the resource
-		* @return The iterator of the content end of vector if not found
-		*/
+		 * Search inside the container by name
+		 * @param name The name of the resource
+		 * @return The iterator of the content end of vector if not found
+		 */
 		iterator_t FindByName( const char* name )
 		{
 			iterator_t it = base_class_t::begin();
@@ -88,11 +88,11 @@ template<typename type_t> class container_t: public vec_t<type_t*>
 
 
 		/**
-		* Search inside the container by name and path
-		* @param name The name of the resource
-		* @param path The path of the resource
-		* @return The iterator of the content end of vector if not found
-		*/
+		 * Search inside the container by name and path
+		 * @param name The name of the resource
+		 * @param path The path of the resource
+		 * @return The iterator of the content end of vector if not found
+		 */
 		iterator_t FindByNameAndPath( const char* name, const char* path )
 		{
 			iterator_t it = base_class_t::begin();
@@ -108,10 +108,10 @@ template<typename type_t> class container_t: public vec_t<type_t*>
 
 
 		/**
-		* Search inside the container by pointer
-		* @param name The name of the resource object
-		* @return The iterator of the content end of vector if not found
-		*/
+	   * Search inside the container by pointer
+		 * @param name The name of the resource object
+		 * @return The iterator of the content end of vector if not found
+		 */
 		iterator_t FindByPtr( type_t* ptr )
 		{
 			iterator_t it = base_class_t::begin();
@@ -127,9 +127,9 @@ template<typename type_t> class container_t: public vec_t<type_t*>
 
 		public:
 		/**
-		* Load an object and register it. If its allready loaded return its pointer
-		* @param fname The filename that initializes the object
-		*/
+		 * Load an object and register it. If its allready loaded return its pointer
+		 * @param fname The filename that initializes the object
+		 */
 		type_t* Load( const char* fname )
 		{
 			char* name = util::CutPath( fname );
@@ -162,9 +162,9 @@ template<typename type_t> class container_t: public vec_t<type_t*>
 
 
 		/**
-		* Unload item. If nobody else uses it then delete it completely
-		* @param x Pointer to the instance we want to unload
-		*/
+		 * Unload item. If nobody else uses it then delete it completely
+		 * @param x Pointer to the instance we want to unload
+		 */
 		void Unload( type_t* x )
 		{
 			iterator_t it = FindByPtr( x );

+ 0 - 0
src/uncategorized/shader_parser.cpp → src/resources/shader_parser.cpp


+ 0 - 0
src/uncategorized/shader_parser.h → src/resources/shader_parser.h


+ 0 - 0
src/uncategorized/shader_prog.cpp → src/resources/shader_prog.cpp


+ 0 - 0
src/uncategorized/shader_prog.h → src/resources/shader_prog.h


+ 70 - 0
src/resources/skel_anim.cpp

@@ -0,0 +1,70 @@
+#include "skel_anim.h"
+#include "scanner.h"
+#include "parser.h"
+
+
+//=====================================================================================================================================
+// Load                                                                                                                               =
+//=====================================================================================================================================
+bool skel_anim_t::Load( const char* filename )
+{
+	scanner_t scanner;
+	if( !scanner.LoadFile( filename ) ) return false;
+
+	const scanner_t::token_t* token;
+
+
+	// keyframes
+	token = &scanner.GetNextToken();
+	if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT  )
+	{
+		PARSE_ERR_EXPECTED( "integer" );
+		return false;
+	}
+	keyframes.resize( token->value.int_ );
+
+	if( !ParseArrOfNumbers( scanner, false, false, keyframes.size(), &keyframes[0] ) ) return false;
+
+	// bones num
+	token = &scanner.GetNextToken();
+	if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT  )
+	{
+		PARSE_ERR_EXPECTED( "integer" );
+		return false;
+	}
+	bones.resize( token->value.int_ );
+
+	// poses
+	for( uint i=0; i<bones.size(); i++ )
+	{
+		// has anim?
+		token = &scanner.GetNextToken();
+		if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT  )
+		{
+			PARSE_ERR_EXPECTED( "integer" );
+			return false;
+		}
+
+		// it has
+		if( token->value.int_ == 1 )
+		{
+			bones[i].keyframes.resize( keyframes.size() );
+
+			for( uint j=0; j<keyframes.size(); ++j )
+			{
+				// parse the quat
+				float tmp[4];
+				if( !ParseArrOfNumbers( scanner, false, true, 4, &tmp[0] ) ) return false;
+				bones[i].keyframes[j].rotation = quat_t( tmp[1], tmp[2], tmp[3], tmp[0] );
+
+				// parse the vec3
+				if( !ParseArrOfNumbers( scanner, false, true, 3, &bones[i].keyframes[j].translation[0] ) ) return false;
+			}
+		}
+	} // end for all bones
+
+
+	frames_num = keyframes[ keyframes.size()-1 ] + 1;
+
+	return true;
+}

+ 45 - 0
src/resources/skel_anim.h

@@ -0,0 +1,45 @@
+#ifndef _SKEL_ANIM_H_
+#define _SKEL_ANIM_H_
+
+#include "common.h"
+#include "resource.h"
+#include "gmath.h"
+
+
+/// Skeleton animation
+class skel_anim_t: public resource_t
+{
+	public:
+		/// bone_pose_t
+		class bone_pose_t
+		{
+			public:
+				quat_t rotation;
+				vec3_t translation;
+		};
+
+
+		/// bone_anim_t
+		class bone_anim_t
+		{
+			public:
+				vec_t<bone_pose_t> keyframes; ///< The poses for every keyframe. Its empty if the bone doesnt have any animation
+
+				bone_anim_t() {}
+				~bone_anim_t() { if(keyframes.size()) keyframes.clear();}
+		};
+		
+		vec_t<uint> keyframes;
+		uint frames_num;
+
+		vec_t<bone_anim_t> bones;
+
+		skel_anim_t() {}
+		~skel_anim_t() {}
+		bool Load( const char* filename );
+		void Unload() { keyframes.clear(); bones.clear(); frames_num=0; }
+};
+
+
+
+#endif

+ 97 - 0
src/resources/skeleton.cpp

@@ -0,0 +1,97 @@
+#include "skeleton.h"
+#include "scanner.h"
+#include "parser.h"
+
+
+//=====================================================================================================================================
+// Load                                                                                                                               =
+//=====================================================================================================================================
+bool skeleton_t::Load( const char* filename )
+{
+	scanner_t scanner;
+	if( !scanner.LoadFile( filename ) ) return false;
+
+	const scanner_t::token_t* token;
+
+
+	//** BONES NUM **
+	token = &scanner.GetNextToken();
+	if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
+	{
+		PARSE_ERR_EXPECTED( "integer" );
+		return false;
+	}
+	bones.resize( token->value.int_, bone_t() );
+
+	for( uint i=0; i<bones.size(); i++ )
+	{
+		bone_t& bone = bones[i];
+		bone.id = i;
+
+		// NAME
+		token = &scanner.GetNextToken();
+		if( token->code != scanner_t::TC_STRING )
+		{
+			PARSE_ERR_EXPECTED( "string" );
+			return false;
+		}
+		bone.SetName( token->value.string );
+
+		// head
+		if( !ParseArrOfNumbers<float>( scanner, false, true, 3, &bone.head[0] ) ) return false;
+
+		// tail
+		if( !ParseArrOfNumbers<float>( scanner, false, true, 3, &bone.tail[0] ) ) return false;
+
+		// matrix
+		mat4_t m4;
+		if( !ParseArrOfNumbers<float>( scanner, false, true, 16, &m4[0] ) ) return false;
+
+		// matrix for real
+		bone.rot_skel_space = m4.GetRotationPart();
+		bone.tsl_skel_space = m4.GetTranslationPart();
+		mat4_t MAi( m4.GetInverse() );
+		bone.rot_skel_space_inv = MAi.GetRotationPart();
+		bone.tsl_skel_space_inv = MAi.GetTranslationPart();
+
+		// parent
+		token = &scanner.GetNextToken();
+		if( (token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT) &&
+		    (token->code != scanner_t::TC_IDENTIFIER || strcmp( token->value.string, "NULL" )!=0) )
+		{
+			PARSE_ERR_EXPECTED( "integer or NULL" );
+			return false;
+		}
+
+		if( token->code == scanner_t::TC_IDENTIFIER )
+			bone.parent = NULL;
+		else
+			bone.parent = &bones[ token->value.int_ ];
+
+		// childs
+		token = &scanner.GetNextToken();
+		if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
+		{
+			PARSE_ERR_EXPECTED( "integer" );
+			return false;
+		}
+		if( token->value.int_ > bone_t::MAX_CHILDS_PER_BONE )
+		{
+			ERROR( "Childs for bone \"" << bone.GetName() << "\" exceed the max" );
+			return false;
+		}
+		bone.childs_num = token->value.int_;
+		for( int j=0; j<bone.childs_num; j++ )
+		{
+			token = &scanner.GetNextToken();
+			if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
+			{
+				PARSE_ERR_EXPECTED( "integer" );
+				return false;
+			}
+			bone.childs[j] = &bones[ token->value.int_ ];
+		}
+	} // for all bones
+
+	return true;
+}

+ 48 - 0
src/resources/skeleton.h

@@ -0,0 +1,48 @@
+#ifndef _SKELETON_H_
+#define _SKELETON_H_
+
+#include "common.h"
+#include "gmath.h"
+#include "resource.h"
+#include "engine_class.h"
+
+
+/// skeleton_t
+class skeleton_t: public resource_t
+{
+	public:
+		/// bone_t
+		class bone_t: public nc_t
+		{
+			public:
+				static const uint MAX_CHILDS_PER_BONE = 4; ///< Please dont change this
+				ushort  id; ///< pos inside the skeleton_t::bones vector
+				bone_t* parent;
+				bone_t* childs[ MAX_CHILDS_PER_BONE ];
+				ushort  childs_num;
+				vec3_t  head;
+				vec3_t  tail;
+
+				/* The rotation and translation that transform the bone from bone space to armature space. Meaning that if
+				MA = TRS(rot_skel_space, tsl_skel_space) then head = MA * vec3_t(0.0, length, 0.0) and tail = MA * vec3_t( 0.0, 0.0, 0.0 )
+				We also keep the inverted ones for fast calculations. rot_skel_space_inv = MA.Inverted().GetRotationPart() and NOT
+				rot_skel_space_inv = rot_skel_space.GetInverted() */
+				mat3_t rot_skel_space;
+				vec3_t tsl_skel_space;
+				mat3_t rot_skel_space_inv;
+				vec3_t tsl_skel_space_inv;
+
+				 bone_t() {}
+				~bone_t() {}
+		};	
+	
+		vec_t<bone_t> bones;
+
+		 skeleton_t() {}
+		~skeleton_t() {}
+		bool Load( const char* filename );
+		void Unload() { bones.clear(); }
+};
+
+
+#endif

+ 0 - 0
src/uncategorized/texture.cpp → src/resources/texture.cpp


+ 0 - 0
src/uncategorized/texture.h → src/resources/texture.h


+ 41 - 60
src/uncategorized/camera.cpp → src/scene/camera.cpp

@@ -2,11 +2,9 @@
 #include "renderer.h"
 
 
-/*
-=======================================================================================================================================
-SetAll                                                                                                                                =
-=======================================================================================================================================
-*/
+//=====================================================================================================================================
+// SetAll                                                                                                                             =
+//=====================================================================================================================================
 void camera_t::SetAll( float fovx_, float fovy_, float znear_, float zfar_ )
 {
 	fovx = fovx_;
@@ -17,11 +15,10 @@ void camera_t::SetAll( float fovx_, float fovy_, float znear_, float zfar_ )
 	CalcLSpaceFrustumPlanes();
 }
 
-/*
-=======================================================================================================================================
-Render                                                                                                                                =
-=======================================================================================================================================
-*/
+
+//=====================================================================================================================================
+// Render                                                                                                                             =
+//=====================================================================================================================================
 void camera_t::Render()
 {
 	glPushMatrix();
@@ -70,11 +67,9 @@ void camera_t::Render()
 }
 
 
-/*
-=======================================================================================================================================
-LookAtPoint                                                                                                                           =
-=======================================================================================================================================
-*/
+//=====================================================================================================================================
+// LookAtPoint                                                                                                                        =
+//=====================================================================================================================================
 void camera_t::LookAtPoint( const vec3_t& point )
 {
 	const vec3_t& j = vec3_t( 0.0, 1.0, 0.0 );
@@ -85,39 +80,35 @@ void camera_t::LookAtPoint( const vec3_t& point )
 }
 
 
-/*
-=======================================================================================================================================
-CalcLSpaceFrustumPlanes                                                                                                               =
-=======================================================================================================================================
-*/
+//=====================================================================================================================================
+// CalcLSpaceFrustumPlanes                                                                                                            =
+//=====================================================================================================================================
 void camera_t::CalcLSpaceFrustumPlanes()
 {
 	float c, s; // cos & sine
 
 	SinCos( PI+fovx/2, s, c );
 	// right
-	lspace_frustum_planes[RIGHT_PL] = plane_t( vec3_t(c, 0.0f, s), 0.0f );
+	lspace_frustum_planes[FP_RIGHT] = plane_t( vec3_t(c, 0.0, s), 0.0 );
 	// left
-	lspace_frustum_planes[LEFT_PL] = plane_t( vec3_t(-c, 0.0f, s), 0.0f );
+	lspace_frustum_planes[FP_LEFT] = plane_t( vec3_t(-c, 0.0, s), 0.0 );
 
 	SinCos( (3*PI-fovy)*0.5, s, c );
 	// top
-	lspace_frustum_planes[TOP_PL] = plane_t( vec3_t(0.0f, s, c), 0.0f );
+	lspace_frustum_planes[FP_TOP] = plane_t( vec3_t(0.0, s, c), 0.0 );
 	// bottom
-	lspace_frustum_planes[BOTTOM_PL] = plane_t( vec3_t(0.0f, -s, c), 0.0f );
+	lspace_frustum_planes[FP_BOTTOM] = plane_t( vec3_t(0.0, -s, c), 0.0 );
 
 	// near
-	lspace_frustum_planes[NEAR_PL] = plane_t( vec3_t( 0.0f, 0.0f, -1.0f ), znear );
+	lspace_frustum_planes[FP_NEAR] = plane_t( vec3_t( 0.0, 0.0, -1.0 ), znear );
 	// far
-	lspace_frustum_planes[FAR_PL] = plane_t( vec3_t( 0.0f, 0.0f, 1.0f ), -zfar );
+	lspace_frustum_planes[FP_FAR] = plane_t( vec3_t( 0.0, 0.0, 1.0 ), -zfar );
 }
 
 
-/*
-=======================================================================================================================================
-UpdateWSpaceFrustumPlanes                                                                                                             =
-=======================================================================================================================================
-*/
+//=====================================================================================================================================
+// UpdateWSpaceFrustumPlanes                                                                                                          =
+//=====================================================================================================================================
 void camera_t::UpdateWSpaceFrustumPlanes()
 {
 	for( uint i=0; i<6; i++ )
@@ -125,12 +116,10 @@ void camera_t::UpdateWSpaceFrustumPlanes()
 }
 
 
-/*
-=======================================================================================================================================
-InsideFrustum                                                                                                                         =
-check if the volume is inside the frustum cliping planes                                                                              =
-=======================================================================================================================================
-*/
+//=====================================================================================================================================
+// InsideFrustum                                                                                                                      =
+//=====================================================================================================================================
+/// Check if the volume is inside the frustum cliping planes
 bool camera_t::InsideFrustum( const bvolume_t& bvol ) const
 {
 	for( uint i=0; i<6; i++ )
@@ -141,12 +130,10 @@ bool camera_t::InsideFrustum( const bvolume_t& bvol ) const
 }
 
 
-/*
-=======================================================================================================================================
-InsideFrustum                                                                                                                         =
-check if the given camera is inside the frustum cliping planes. This is used mainly to test if the projected lights are visible       =
-=======================================================================================================================================
-*/
+//=====================================================================================================================================
+// InsideFrustum                                                                                                                      =
+//=====================================================================================================================================
+/// Check if the given camera is inside the frustum cliping planes. This is used mainly to test if the projected lights are visible
 bool camera_t::InsideFrustum( const camera_t& cam ) const
 {
 	//** get five points. These points are the tips of the given camera **
@@ -186,14 +173,12 @@ bool camera_t::InsideFrustum( const camera_t& cam ) const
 }
 
 
-/*
-=======================================================================================================================================
-CalcProjectionMatrix                                                                                                                  =
-=======================================================================================================================================
-*/
+//=====================================================================================================================================
+// CalcProjectionMatrix                                                                                                               =
+//=====================================================================================================================================
 void camera_t::CalcProjectionMatrix()
 {
-	float f = 1.0f/tan( fovy*0.5f ); // f = cot(fovy/2)
+	float f = 1.0/tan( fovy*0.5f ); // f = cot(fovy/2)
 
 	projection_mat(0,0) = f*fovy/fovx; // = f/aspect_ratio;
 	projection_mat(0,1) = 0.0;
@@ -209,18 +194,16 @@ void camera_t::CalcProjectionMatrix()
 	projection_mat(2,3) = (2.0f*zfar*znear) / (znear-zfar);
 	projection_mat(3,0) = 0.0;
 	projection_mat(3,1) = 0.0;
-	projection_mat(3,2) = -1.0f;
+	projection_mat(3,2) = -1.0;
 	projection_mat(3,3) = 0.0;
 
 	inv_projection_mat = projection_mat.GetInverse();
 }
 
 
-/*
-=======================================================================================================================================
-UpdateViewMatrix                                                                                                                      =
-=======================================================================================================================================
-*/
+//=====================================================================================================================================
+// UpdateViewMatrix                                                                                                                   =
+//=====================================================================================================================================
 void camera_t::UpdateViewMatrix()
 {
 	/* The point at which the camera looks:
@@ -237,11 +220,9 @@ void camera_t::UpdateViewMatrix()
 }
 
 
-/*
-=======================================================================================================================================
-UpdateWorldStuff                                                                                                                      =
-=======================================================================================================================================
-*/
+//=====================================================================================================================================
+// UpdateWorldStuff                                                                                                                   =
+//=====================================================================================================================================
 void camera_t::UpdateWorldStuff()
 {
 	UpdateWorldTransform();

+ 14 - 17
src/uncategorized/camera.h → src/scene/camera.h

@@ -1,25 +1,22 @@
 #ifndef _CAMERA_H_
 #define _CAMERA_H_
 
-#include <cstring>
 #include "common.h"
-#include "primitives.h"
 #include "collision.h"
-#include "object.h"
+#include "node.h"
 
-class camera_data_user_class_t: public data_user_class_t {}; // for ambiguity reasons
 
-class camera_t: public object_t, public camera_data_user_class_t
+class camera_t: public node_t
 {
 	public:
-		enum planes_e
+		enum frustrum_planes_e
 		{
-			LEFT_PL = 0,
-			RIGHT_PL,
-			NEAR_PL,
-			TOP_PL,
-			BOTTOM_PL,
-			FAR_PL
+			FP_LEFT = 0,
+			FP_RIGHT,
+			FP_NEAR,
+			FP_TOP,
+			FP_BOTTOM,
+			FP_FAR
 		};
 
 		// Fovx is the angle in the y axis (imagine the cam positioned in the default OGL pos)
@@ -51,14 +48,14 @@ class camera_t: public object_t, public camera_data_user_class_t
 
 	public:
 		// constructors and destuctors
-		camera_t( float fovx_, float fovy_, float znear_, float zfar_ ): object_t(CAMERA), fovx(fovx_), fovy(fovy_), znear(znear_), zfar(zfar_)
+		camera_t( float fovx_, float fovy_, float znear_, float zfar_ ): node_t(NT_CAMERA), fovx(fovx_), fovy(fovy_), znear(znear_), zfar(zfar_)
 		{
 			CalcLSpaceFrustumPlanes();
 			UpdateWSpaceFrustumPlanes();
 			CalcProjectionMatrix();
 		}
-		camera_t( const camera_t& c ): object_t(CAMERA) { memcpy( this, &c, sizeof( camera_t ) ); }
-		camera_t(): object_t(CAMERA) {}
+		camera_t( const camera_t& c ): node_t(NT_CAMERA) { memcpy( this, &c, sizeof( camera_t ) ); }
+		camera_t(): node_t(NT_CAMERA) {}
 		~camera_t() {}
 
 		// Sets & Gets
@@ -78,9 +75,9 @@ class camera_t: public object_t, public camera_data_user_class_t
 		// misc
 		void LookAtPoint( const vec3_t& point );
 		void UpdateWorldStuff();
-		void RenderDebug();
 		void Render();
-		void RenderDepth() { ERROR("You may want to reconsider rendering a camera for depth passes") };
+		void Init( const char* ) {}
+		void Deinit() {}
 
 		// frustum stuff
 		bool InsideFrustum( const bvolume_t& vol ) const;

+ 18 - 0
src/scene/controller.h

@@ -0,0 +1,18 @@
+#ifndef _CONTROLLER_H_
+#define _CONTROLLER_H_
+
+#include "common.h"
+
+
+template<typename type_t> class controller_t
+{
+	public:
+		enum type_e { CT_SKEL_ANIM, CT_SKEL };
+
+		controller_t() {}
+		virtual ~controller_t() {}
+		virtual void Update() = 0;
+};
+
+
+#endif

+ 36 - 0
src/scene/light.cpp

@@ -0,0 +1,36 @@
+#include "light.h"
+#include "collision.h"
+#include "renderer.h"
+
+
+//=====================================================================================================================================
+// RenderSphere                                                                                                                       =
+//=====================================================================================================================================
+static void RenderSphere( const mat4_t& tsl, const vec3_t& col )
+{
+	glPushMatrix();
+	r::MultMatrix( tsl );
+
+	r::Color3( col );
+	r::dbg::RenderSphere( 1.0/8.0, 8 );
+
+	glPopMatrix();
+}
+
+
+//=====================================================================================================================================
+// Render                                                                                                                             =
+//=====================================================================================================================================
+void point_light_t::Render()
+{
+	RenderSphere( transformation_wspace, diffuse_color );
+}
+
+
+//=====================================================================================================================================
+// Render                                                                                                                             =
+//=====================================================================================================================================
+void spot_light_t::Render()
+{
+	RenderSphere( transformation_wspace, diffuse_color );
+}

+ 72 - 0
src/scene/light.h

@@ -0,0 +1,72 @@
+#ifndef _LIGHT_H_
+#define _LIGHT_H_
+
+#include "common.h"
+#include "texture.h"
+#include "node.h"
+#include "camera.h"
+
+/*
+LIGHTING MODEL
+
+Final intensity:                If = Ia + Id + Is
+Ambient intensity:              Ia = Al * Am
+Ambient intensity of light:     Al
+Ambient intensity of material:  Am
+Defuse intensity:               Id = Dl * Dm * LambertTerm
+Defuse intensity of light:      Dl
+Defuse intensity of material:   Dm
+LambertTerm:                    max( Normal dot Light, 0.0 )
+Specular intensity:             Is = Sm x Sl x pow( max(R dot E, 0.0), f )
+Specular intensity of light:    Sl
+Specular intensity of material: Sm
+*/
+
+
+/// light_t (A)
+class light_t: public node_t
+{
+	public:
+		enum types_e { LT_POINT, LT_SPOT };
+
+	PROPERTY_RW( vec3_t, diffuse_color, GetDiffuseColor, SetDiffuseColor );
+	PROPERTY_RW( vec3_t, specular_color, GetSpecularColor, SetSpecularColor );
+	PROPERTY_R( types_e, type, GetType );
+
+	friend class point_light_t;
+	friend class spot_light_t;
+
+
+
+	public:
+		light_t( types_e type_ ): node_t(NT_LIGHT), type(type_) {}
+};
+
+
+/// point_light_t
+class point_light_t: public light_t
+{
+	public:
+		float radius;
+
+		point_light_t(): light_t(LT_POINT) {}
+		void Render();
+};
+
+
+/// spot_light_t
+class spot_light_t: public light_t
+{
+	public:
+		camera_t camera;
+		texture_t* texture;
+		bool casts_shadow;
+
+		spot_light_t(): light_t(LT_SPOT), texture(NULL), casts_shadow(false) { AddChild( &camera ); }
+		float GetDistance() const { return camera.GetZFar(); }
+		void  SetDistance( float d ) { camera.SetZFar(d); }
+		void Render();
+};
+
+
+#endif

+ 168 - 0
src/scene/mesh_node.cpp

@@ -0,0 +1,168 @@
+#include "mesh_node.h"
+#include "resource.h"
+#include "mesh.h"
+#include "renderer.h"
+#include "material.h"
+#include "skel_node.h"
+#include "skeleton.h"
+
+
+//=====================================================================================================================================
+// Init                                                                                                                               =
+//=====================================================================================================================================
+void mesh_node_t::Init( const char* filename )
+{
+	mesh = rsrc::meshes.Load( filename );
+	material = rsrc::materials.Load( mesh->material_name.c_str() );
+}
+
+
+//=====================================================================================================================================
+// Deinit                                                                                                                             =
+//=====================================================================================================================================
+void mesh_node_t::Deinit()
+{
+	rsrc::meshes.Unload( mesh );
+	rsrc::materials.Unload( material );
+}
+
+
+//=====================================================================================================================================
+// Render                                                                                                                             =
+//=====================================================================================================================================
+void mesh_node_t::Render()
+{
+	glPushMatrix();
+	r::MultMatrix( transformation_wspace );
+
+	// if we have skeleton controller
+	if( skel_controller )
+	{
+		// first the uniforms
+		glUniformMatrix3fv( material->uniform_locs.skinning_rotations, skel_controller->skel_node->skeleton->bones.size(), 1,
+		                    &(skel_controller->skel_node->skel_anim_controller->bone_rotations[0])[0] );
+		glUniform3fv( material->uniform_locs.skinning_translations, skel_controller->skel_node->skeleton->bones.size(),
+		              &(skel_controller->skel_node->skel_anim_controller->bone_translations[0])[0] );
+
+		// then the attributes
+		DEBUG_ERR( material->attribute_locs.vert_weight_bones_num == -1 );
+
+		mesh->vbos.vert_weights.Bind();
+		glEnableVertexAttribArray( material->attribute_locs.vert_weight_bones_num );
+		glVertexAttribPointer( material->attribute_locs.vert_weight_bones_num, 1, GL_FLOAT, GL_FALSE, sizeof(mesh_t::vertex_weight_t), BUFFER_OFFSET(0) );
+		glEnableVertexAttribArray( material->attribute_locs.vert_weight_bone_ids );
+		glVertexAttribPointer( material->attribute_locs.vert_weight_bone_ids, 4, GL_FLOAT, GL_FALSE, sizeof(mesh_t::vertex_weight_t), BUFFER_OFFSET(4) );
+		glEnableVertexAttribArray( material->attribute_locs.vert_weight_weights );
+		glVertexAttribPointer( material->attribute_locs.vert_weight_weights, 4, GL_FLOAT, GL_FALSE, sizeof(mesh_t::vertex_weight_t), BUFFER_OFFSET(20) );
+	}
+
+	if( material->attribute_locs.position != -1 )
+	{
+		mesh->vbos.vert_coords.Bind();
+		glVertexAttribPointer( material->attribute_locs.position, 3, GL_FLOAT, false, 0, NULL );
+		glEnableVertexAttribArray( material->attribute_locs.position );
+	}
+
+	if( material->attribute_locs.normal != -1 )
+	{
+		mesh->vbos.vert_normals.Bind();
+		glVertexAttribPointer( material->attribute_locs.normal, 3, GL_FLOAT, false, 0, NULL );
+		glEnableVertexAttribArray( material->attribute_locs.normal );
+	}
+
+	if( material->attribute_locs.tex_coords != -1 )
+	{
+		mesh->vbos.tex_coords.Bind();
+		glVertexAttribPointer( material->attribute_locs.tex_coords, 2, GL_FLOAT, false, 0, NULL );
+		glEnableVertexAttribArray( material->attribute_locs.tex_coords );
+	}
+
+	if( material->attribute_locs.tanget != -1 )
+	{
+		mesh->vbos.vert_tangents.Bind();
+		glVertexAttribPointer( material->attribute_locs.tanget, 4, GL_FLOAT, false, 0, NULL );
+		glEnableVertexAttribArray( material->attribute_locs.tanget );
+	}
+
+	mesh->vbos.vert_indeces.Bind();
+
+	glDrawElements( GL_TRIANGLES, mesh->vert_indeces.size(), GL_UNSIGNED_SHORT, 0 );
+
+	// disable
+	if( material->attribute_locs.position != -1 ) glDisableVertexAttribArray( material->attribute_locs.position );
+	if( material->attribute_locs.normal != -1 ) glDisableVertexAttribArray( material->attribute_locs.normal );
+	if( material->attribute_locs.tex_coords != -1 ) glDisableVertexAttribArray( material->attribute_locs.tex_coords );
+	if( material->attribute_locs.tanget != -1 ) glDisableVertexAttribArray( material->attribute_locs.tanget );
+
+	if( skel_controller )
+	{
+		glDisableVertexAttribArray( material->attribute_locs.vert_weight_bones_num );
+		glDisableVertexAttribArray( material->attribute_locs.vert_weight_bone_ids );
+		glDisableVertexAttribArray( material->attribute_locs.vert_weight_weights );
+	}
+
+	vbo_t::UnbindAllTargets();
+	glPopMatrix();
+}
+
+
+//=====================================================================================================================================
+// RenderDepth                                                                                                                        =
+//=====================================================================================================================================
+void mesh_node_t::RenderDepth()
+{
+	glPushMatrix();
+	r::MultMatrix( transformation_wspace );
+
+	mesh->vbos.vert_coords.Bind();
+	glVertexPointer( 3, GL_FLOAT, 0, NULL );
+
+	if( material->grass_map )
+	{
+		mesh->vbos.tex_coords.Bind();
+		glTexCoordPointer( 2, GL_FLOAT, 0, NULL );
+		glEnableClientState( GL_TEXTURE_COORD_ARRAY );
+	}
+
+	// if we have skeleton controller
+	if( skel_controller )
+	{
+		// first the uniforms
+		glUniformMatrix3fv( material->uniform_locs.skinning_rotations, skel_controller->skel_node->skeleton->bones.size(), 1,
+		                    &(skel_controller->skel_node->skel_anim_controller->bone_rotations[0])[0] );
+		glUniform3fv( material->uniform_locs.skinning_translations, skel_controller->skel_node->skeleton->bones.size(),
+		              &(skel_controller->skel_node->skel_anim_controller->bone_translations[0])[0] );
+
+		// then the attributes
+		DEBUG_ERR( material->attribute_locs.vert_weight_bones_num == -1 );
+
+		mesh->vbos.vert_weights.Bind();
+		glEnableVertexAttribArray( r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(0) );
+		glVertexAttribPointer( r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(0), 1, GL_FLOAT, GL_FALSE, sizeof(mesh_t::vertex_weight_t), BUFFER_OFFSET(0) );
+		glEnableVertexAttribArray(r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(1) );
+		glVertexAttribPointer( r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(1), 4, GL_FLOAT, GL_FALSE, sizeof(mesh_t::vertex_weight_t), BUFFER_OFFSET(4) );
+		glEnableVertexAttribArray( r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(2) );
+		glVertexAttribPointer( r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(2), 4, GL_FLOAT, GL_FALSE, sizeof(mesh_t::vertex_weight_t), BUFFER_OFFSET(20) );
+	}
+
+	mesh->vbos.vert_indeces.Bind();
+
+	glEnableClientState( GL_VERTEX_ARRAY );
+
+	glDrawElements( GL_TRIANGLES, mesh->vert_indeces.size(), GL_UNSIGNED_SHORT, 0 );
+
+	// disable
+	glDisableClientState( GL_VERTEX_ARRAY );
+	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
+
+	if( skel_controller )
+	{
+		glDisableVertexAttribArray( material->attribute_locs.vert_weight_bones_num );
+		glDisableVertexAttribArray( material->attribute_locs.vert_weight_bone_ids );
+		glDisableVertexAttribArray( material->attribute_locs.vert_weight_weights );
+	}
+
+	vbo_t::UnbindAllTargets();
+
+	glPopMatrix();
+}

+ 43 - 0
src/scene/mesh_node.h

@@ -0,0 +1,43 @@
+#ifndef _MESH_NODE_H_
+#define _MESH_NODE_H_
+
+#include "common.h"
+#include "node.h"
+#include "controller.h"
+
+
+class mesh_node_t;
+class skel_node_t;
+class mesh_t;
+
+
+/// Skeleton controller
+class skel_controller_t: public controller_t<mesh_node_t>
+{
+	public:
+		skel_node_t* skel_node;
+		mesh_node_t* mesh_node;
+
+		skel_controller_t( mesh_node_t* mesh_node_ ): mesh_node(mesh_node_) {}
+		void Update() {}
+};
+
+
+/// Mesh node
+class mesh_node_t: public node_t
+{
+	public:
+		mesh_t* mesh;
+		material_t* material;
+		skel_controller_t* skel_controller;
+
+		mesh_node_t(): node_t(NT_MESH) {}
+
+		void Render();
+		void RenderDepth();
+		void Init( const char* filename );
+		void Deinit();
+};
+
+
+#endif

+ 137 - 0
src/scene/node.cpp

@@ -0,0 +1,137 @@
+#include <algorithm>
+#include "node.h"
+#include "renderer.h"
+#include "collision.h"
+
+
+//=====================================================================================================================================
+// Constructor                                                                                                                        =
+//=====================================================================================================================================
+node_t::node_t( type_e type_ )
+{
+	type = type_;
+	parent = NULL;
+	translation_lspace = vec3_t( 0.0, 0.0, 0.0 );
+	scale_lspace = 1.0;
+	rotation_lspace = mat3_t::GetIdentity();
+	translation_wspace = vec3_t( 0.0, 0.0, 0.0 );
+	scale_wspace = 1.0;
+	rotation_wspace = mat3_t::GetIdentity();
+	bvolume_lspace = NULL;
+}
+
+
+//=====================================================================================================================================
+// UpdateWorldTransform                                                                                                               =
+//=====================================================================================================================================
+void node_t::UpdateWorldTransform()
+{
+	if( parent )
+	{
+		/* the original code:
+		scale_wspace = parent->scale_wspace * scale_lspace;
+		rotation_wspace = parent->rotation_wspace * rotation_lspace;
+		translation_wspace = translation_lspace.Transformed( parent->translation_wspace, parent->rotation_wspace, parent->scale_wspace ); */
+		CombineTransformations( parent->translation_wspace, parent->rotation_wspace, parent->scale_wspace,
+		                        translation_lspace, rotation_lspace, scale_lspace,
+		                        translation_wspace, rotation_wspace, scale_wspace );
+	}
+	else // else copy
+	{
+		scale_wspace = scale_lspace;
+		rotation_wspace = rotation_lspace;
+		translation_wspace = translation_lspace;
+	}
+
+	transformation_wspace = mat4_t( translation_wspace, rotation_wspace, scale_wspace );
+
+
+	// transform the bvolume
+	/*if( bvolume_lspace != NULL )
+	{
+		DEBUG_ERR( bvolume_lspace->type!=bvolume_t::BSPHERE && bvolume_lspace->type!=bvolume_t::AABB && bvolume_lspace->type!=bvolume_t::OBB );
+
+		switch( bvolume_lspace->type )
+		{
+			case bvolume_t::BSPHERE:
+			{
+				bsphere_t sphere = static_cast<bsphere_t*>(bvolume_lspace)->Transformed( translation_wspace, rotation_wspace, scale_wspace );
+				*static_cast<bsphere_t*>(bvolume_wspace) = sphere;
+				break;
+			}
+
+			case bvolume_t::AABB:
+			{
+				aabb_t aabb = static_cast<aabb_t*>(bvolume_lspace)->Transformed( translation_wspace, rotation_wspace, scale_wspace );
+				*static_cast<aabb_t*>(bvolume_wspace) = aabb;
+				break;
+			}
+
+			case bvolume_t::OBB:
+			{
+				obb_t obb = static_cast<obb_t*>(bvolume_lspace)->Transformed( translation_wspace, rotation_wspace, scale_wspace );
+				*static_cast<obb_t*>(bvolume_wspace) = obb;
+				break;
+			}
+
+			default:
+				FATAL( "What the fuck" );
+		}
+	}*/
+}
+
+
+//=====================================================================================================================================
+// Move(s)                                                                                                                            =
+// Move the object according to it's local axis                                                                                       =
+//=====================================================================================================================================
+void node_t::MoveLocalX( float distance )
+{
+	vec3_t x_axis = rotation_lspace.GetColumn(0);
+	translation_lspace += x_axis * distance;
+}
+
+void node_t::MoveLocalY( float distance )
+{
+	vec3_t y_axis = rotation_lspace.GetColumn(1);
+	translation_lspace += y_axis * distance;
+}
+
+void node_t::MoveLocalZ( float distance )
+{
+	vec3_t z_axis = rotation_lspace.GetColumn(2);
+	translation_lspace += z_axis * distance;
+}
+
+
+//=====================================================================================================================================
+// AddChild                                                                                                                           =
+//=====================================================================================================================================
+void node_t::AddChild( node_t* node )
+{
+	if( node->parent != NULL )
+	{
+		ERROR( "Node allready have parent" );
+		return;
+	}
+
+	node->parent = this;
+	childs.push_back( node );
+}
+
+
+//=====================================================================================================================================
+// RemoveChild                                                                                                                        =
+//=====================================================================================================================================
+void node_t::RemoveChild( node_t* node )
+{
+	vec_t<node_t*>::iterator it = find( childs.begin(), childs.end(), node );
+	if( it == childs.end() )
+	{
+		ERROR( "Child not found" );
+		return;
+	}
+
+	node->parent = NULL;
+	childs.erase( it );
+}

+ 65 - 0
src/scene/node.h

@@ -0,0 +1,65 @@
+#ifndef _NODE_H_
+#define _NODE_H_
+
+#include "common.h"
+
+#include "common.h"
+#include "gmath.h"
+
+
+class bvolume_t;
+class material_t;
+
+
+/// Scene Node
+class node_t
+{
+	public:
+		enum type_e
+		{
+			NT_LIGHT,
+			NT_CAMERA,
+			NT_MESH,
+			NT_SKELETON
+		};
+
+		vec3_t translation_lspace;
+		float  scale_lspace;
+		mat3_t rotation_lspace;
+
+		vec3_t translation_wspace;
+		float  scale_wspace;
+		mat3_t rotation_wspace;
+
+		mat4_t transformation_wspace;
+
+		node_t* parent;
+		vec_t<node_t*> childs;
+
+		type_e type;
+
+		bvolume_t* bvolume_lspace;
+		bvolume_t* bvolume_wspace;
+
+		bool is_group_node;
+
+		// funcs
+		 node_t( type_e type_ );
+		~node_t() {};
+		virtual void Render() = 0;
+		virtual void Init( const char* filename ) = 0;
+		virtual void Deinit() = 0;
+		virtual void UpdateWorldStuff() { UpdateWorldTransform(); } ///< This update happens only when the object gets moved. Override it if you want more
+		void UpdateWorldTransform();
+		void RotateLocalX( float ang_degrees ) { rotation_lspace.RotateXAxis( ang_degrees ); }
+		void RotateLocalY( float ang_degrees ) { rotation_lspace.RotateYAxis( ang_degrees ); }
+		void RotateLocalZ( float ang_degrees ) { rotation_lspace.RotateZAxis( ang_degrees ); }
+		void MoveLocalX( float distance );
+		void MoveLocalY( float distance );
+		void MoveLocalZ( float distance );
+		void AddChild( node_t* node );
+		void RemoveChild( node_t* node );
+};
+
+
+#endif

+ 140 - 0
src/scene/scene.cpp

@@ -0,0 +1,140 @@
+#include "scene.h"
+#include "skel_node.h"
+
+namespace scene {
+
+/*
+=======================================================================================================================================
+DATA                                                                                                                                  =
+=======================================================================================================================================
+*/
+skybox_t skybox;
+
+extern container_node_t       nodes;
+extern container_light_t      lights;
+extern container_camera_t     cameras;
+extern container_mesh_node_t  mesh_nodes;
+extern container_skel_node_t  skel_nodes;
+
+
+/*
+=======================================================================================================================================
+UpdateAllWorldStuff                                                                                                                   =
+=======================================================================================================================================
+*/
+void UpdateAllWorldStuff()
+{
+	DEBUG_ERR( nodes.size() > 1024 );
+	node_t* queue [1024];
+	uint head = 0, tail = 0;
+	uint num = 0;
+
+
+	// put the roots
+	for( uint i=0; i<nodes.size(); i++ )
+		if( nodes[i]->parent == NULL )
+			queue[tail++] = nodes[i]; // queue push
+
+	// loop
+	while( head != tail ) // while queue not empty
+	{
+		node_t* obj = queue[head++]; // queue pop
+
+		obj->UpdateWorldStuff();
+		++num;
+
+		for( uint i=0; i<obj->childs.size(); i++ )
+			queue[tail++] = obj->childs[i];
+	}
+
+	DEBUG_ERR( num != nodes.size() );
+}
+
+
+//=====================================================================================================================================
+// UpdateAllSkeletonNodes                                                                                                             =
+//=====================================================================================================================================
+void UpdateAllSkeletonNodes()
+{
+	for( uint i=0; i<skel_nodes.size(); i++ )
+	{
+		skel_nodes[i]->skel_anim_controller->Update();
+	}
+}
+
+
+//=====================================================================================================================================
+// Nodet                                                                                                                              =
+//=====================================================================================================================================
+void container_node_t::Register( node_t* x )
+{
+	RegisterMe( x );
+}
+
+void container_node_t::Unregister( node_t* x )
+{
+	UnregisterMe( x );
+}
+
+
+//=====================================================================================================================================
+// Camera                                                                                                                             =
+//=====================================================================================================================================
+void container_camera_t::Register( camera_t* x )
+{
+	RegisterMe( x );
+	nodes.Register( x );
+}
+
+void container_camera_t::Unregister( camera_t* x )
+{
+	UnregisterMe( x );
+	nodes.Unregister( x );
+}
+
+
+//=====================================================================================================================================
+// Light                                                                                                                              =
+//=====================================================================================================================================
+void container_light_t::Register( light_t* x )
+{
+	RegisterMe( x );
+	nodes.Register( x );
+
+	if( x->GetType() == light_t::LT_SPOT )
+	{
+		spot_light_t* spot = static_cast<spot_light_t*>(x);
+		cameras.Register( &spot->camera );
+	}
+}
+
+void container_light_t::Unregister( light_t* x )
+{
+	UnregisterMe( x );
+	nodes.Unregister( x );
+
+	if( x->GetType() == light_t::LT_SPOT )
+	{
+		spot_light_t* spot = static_cast<spot_light_t*>(x);
+		cameras.Unregister( &spot->camera );
+	}
+}
+
+
+//=====================================================================================================================================
+// Mesh node                                                                                                                          =
+//=====================================================================================================================================
+void container_mesh_node_t::Register( mesh_node_t* x )
+{
+	RegisterMe( x );
+	nodes.Register( x );
+}
+
+void container_mesh_node_t::Unregister( mesh_node_t* x )
+{
+	UnregisterMe( x );
+	nodes.Unregister( x );
+}
+
+
+} // end namespace

+ 19 - 23
src/uncategorized/scene.h → src/scene/scene.h

@@ -2,11 +2,8 @@
 #define _SCENE_H_
 
 #include "common.h"
-#include "primitives.h"
-#include "spatial.h"
-#include "lights.h"
-#include "mesh.h"
-#include "smodel.h"
+#include "light.h"
+#include "mesh_node.h"
 #include "skybox.h"
 
 
@@ -17,8 +14,7 @@ extern skybox_t skybox;
 inline vec3_t GetAmbientColor() { return vec3_t( 0.1, 0.05, 0.05 )*1; }
 
 extern void UpdateAllWorldStuff();
-extern void RenderAllObjs();
-extern void InterpolateAllModels();
+extern void UpdateAllSkeletonNodes();
 
 
 // container_t
@@ -29,12 +25,12 @@ template<typename type_t> class container_t: public vec_t<type_t*>
 		typedef typename vector<type_t*>::iterator iterator_t; ///< Just to save me time from typing
 
 		/**
-		 * Register x in this container only. Throw error if its allready registered
+		 * Register x in this container only. Throw error if its already registered
 		 * @param x pointer to the object we want to register
 		 */
 		void RegisterMe( type_t* x )
 		{
-			DEBUG_ERR( Search( x ) ); // the obj must not be allready loaded
+			DEBUG_ERR( Search( x ) ); // the obj must not be already loaded
 
 			vec_t<type_t*>::push_back( x );
 		}
@@ -112,11 +108,11 @@ template<typename type_t> class container_t: public vec_t<type_t*>
 
 
 // conaiteners
-class container_object_t: public container_t<object_t>
+class container_node_t: public container_t<node_t>
 {
 	public:
-		void Register( object_t* x );
-		void Unregister( object_t* x );
+		void Register( node_t* x );
+		void Unregister( node_t* x );
 };
 
 class container_light_t: public container_t<light_t>
@@ -133,26 +129,26 @@ class container_camera_t: public container_t<camera_t>
 		void Unregister( camera_t* x );
 };
 
-class container_mesh_t: public container_t<mesh_t>
+class container_mesh_node_t: public container_t<mesh_node_t>
 {
 	public:
-		void Register( mesh_t* x );
-		void Unregister( mesh_t* x );
+		void Register( mesh_node_t* x );
+		void Unregister( mesh_node_t* x );
 };
 
-class container_smodel_t: public container_t<smodel_t>
+class container_skel_node_t: public container_t<skel_node_t>
 {
 	public:
-		void Register( smodel_t* x );
-		void Unregister( smodel_t* x );
+		void Register( skel_node_t* x );
+		void Unregister( skel_node_t* x );
 };
 
 
-extern container_object_t objects;
-extern container_light_t  lights;
-extern container_camera_t cameras;
-extern container_mesh_t   meshes;
-extern container_smodel_t smodels;
+extern container_node_t       nodes;
+extern container_light_t      lights;
+extern container_camera_t     cameras;
+extern container_mesh_node_t  mesh_nodes;
+extern container_skel_node_t  skel_nodes;
 
 
 } // end namespace

+ 197 - 0
src/scene/skel_node.cpp

@@ -0,0 +1,197 @@
+#include "skel_node.h"
+#include "renderer.h"
+#include "skel_anim.h"
+#include "skeleton.h"
+
+
+//=====================================================================================================================================
+// Interpolate                                                                                                                        =
+//=====================================================================================================================================
+void skel_anim_controller_t::Interpolate( skel_anim_t* animation, float frame )
+{
+	DEBUG_ERR( frame >= skel_anim->frames_num );
+
+	// calculate the t (used in slerp and lerp) and
+	// calc the l_pose and r_pose witch indicate the pose ids in witch the frame lies between
+	const vec_t<uint>& keyframes = skel_anim->keyframes;
+	float t = 0.0;
+	uint l_pose = 0, r_pose = 0;
+	for( uint j=0; j<keyframes.size(); j++ )
+	{
+		if( (float)keyframes[j] == frame )
+		{
+			l_pose = r_pose = j;
+			t = 0.0;
+			break;
+		}
+		else if( (float)keyframes[j] > frame )
+		{
+			l_pose = j-1;
+			r_pose = j;
+			t = ( frame - (float)keyframes[l_pose] ) / float( keyframes[r_pose] - keyframes[l_pose] );
+			break;
+		}
+	}
+
+
+	// now for all bones update bone's poses
+	for( uint i=0; i<bone_rotations.size(); i++ )
+	{
+		const skel_anim_t::bone_anim_t& banim = skel_anim->bones[i];
+
+		mat3_t& local_rot = bone_rotations[i];
+		vec3_t& local_transl = bone_translations[i];
+
+		// if the bone has animations then slerp and lerp to find the rotation and translation
+		if( banim.keyframes.size() != 0 )
+		{
+			const skel_anim_t::bone_pose_t& l_bpose = banim.keyframes[l_pose];
+			const skel_anim_t::bone_pose_t& r_bpose = banim.keyframes[r_pose];
+
+			// rotation
+			const quat_t& q0 = l_bpose.rotation;
+			const quat_t& q1 = r_bpose.rotation;
+			local_rot = mat3_t( q0.Slerp(q1, t) );
+
+			// translation
+			const vec3_t& v0 = l_bpose.translation;
+			const vec3_t& v1 = r_bpose.translation;
+			local_transl = v0.Lerp( v1, t );
+		}
+		// else put the idents
+		else
+		{
+			local_rot = mat3_t::GetIdentity();
+			local_transl = vec3_t( 0.0, 0.0, 0.0 );
+		}
+	}
+}
+
+
+//=====================================================================================================================================
+// UpdateBoneTransforms                                                                                                               =
+//=====================================================================================================================================
+void skel_anim_controller_t::UpdateBoneTransforms()
+{
+	uint queue[ 128 ];
+	uint head = 0, tail = 0;
+
+	// put the roots
+	for( uint i=0; i<skel_node->skeleton->bones.size(); i++ )
+		if( skel_node->skeleton->bones[i].parent == NULL )
+			queue[tail++] = i; // queue push
+
+	// loop
+	while( head != tail ) // while queue not empty
+	{
+		uint bone_id = queue[head++]; // queue pop
+		const skeleton_t::bone_t& boned = skel_node->skeleton->bones[bone_id];
+
+		// bone.final_transform = MA * ANIM * MAi
+		// where MA is bone matrix at armature space and ANIM the interpolated transformation.
+		CombineTransformations( bone_translations[bone_id], bone_rotations[bone_id],
+		                        boned.tsl_skel_space_inv, boned.rot_skel_space_inv,
+		                        bone_translations[bone_id], bone_rotations[bone_id] );
+
+		CombineTransformations( boned.tsl_skel_space, boned.rot_skel_space,
+		                        bone_translations[bone_id], bone_rotations[bone_id],
+		                        bone_translations[bone_id], bone_rotations[bone_id] );
+
+		// and finaly add the parent's transform
+		if( boned.parent )
+		{
+			// bone.final_final_transform = parent.transf * bone.final_transform
+			CombineTransformations( bone_translations[boned.parent->id], bone_rotations[boned.parent->id],
+		                          bone_translations[bone_id], bone_rotations[bone_id],
+		                          bone_translations[bone_id], bone_rotations[bone_id] );
+		}
+
+		// now add the bone's childes
+		for( uint i=0; i<boned.childs_num; i++ )
+			queue[tail++] = boned.childs[i]->id;
+	}
+}
+
+
+//=====================================================================================================================================
+// Deform                                                                                                                             =
+//=====================================================================================================================================
+void skel_anim_controller_t::Deform()
+{
+	skeleton_t* skeleton = skel_node->skeleton;
+
+	for( uint i=0; i<skeleton->bones.size(); i++ )
+	{
+		const mat3_t& rot = bone_rotations[ i ];
+		const vec3_t& transl = bone_translations[ i ];
+
+		heads[i] = skeleton->bones[i].head.GetTransformed( transl, rot );
+		tails[i] = skeleton->bones[i].tail.GetTransformed( transl, rot );
+	}
+}
+
+
+//=====================================================================================================================================
+// Update                                                                                                                             =
+//=====================================================================================================================================
+void skel_anim_controller_t::Update()
+{
+	frame += step;
+	if( frame > skel_anim->frames_num ) // if the crnt is finished then play the next or loop the crnt
+	{
+		frame = 0.0;
+	}
+
+	Interpolate( skel_anim, frame );
+	UpdateBoneTransforms();
+	if( r::dbg::show_skeletons )
+	{
+		Deform();
+	}
+}
+
+
+//=====================================================================================================================================
+// Init                                                                                                                               =
+//=====================================================================================================================================
+void skel_node_t::Init( const char* filename )
+{
+	skeleton = rsrc::skeletons.Load( filename );
+}
+
+//=====================================================================================================================================
+// Deinit                                                                                                                             =
+//=====================================================================================================================================
+void skel_node_t::Deinit()
+{
+	rsrc::skeletons.Unload( skeleton );
+}
+
+
+//=====================================================================================================================================
+// Render                                                                                                                             =
+//=====================================================================================================================================
+void skel_node_t::Render()
+{
+	glPushMatrix();
+	r::MultMatrix( transformation_wspace );
+
+	//glPointSize( 4.0f );
+	//glLineWidth( 2.0f );
+
+	for( uint i=0; i<skeleton->bones.size(); i++ )
+	{
+		glColor3fv( &vec3_t( 1.0, 1.0, 1.0 )[0] );
+		glBegin( GL_POINTS );
+			glVertex3fv( &skel_anim_controller->heads[0][0] );
+		glEnd();
+
+		glBegin( GL_LINES );
+			glVertex3fv( &skel_anim_controller->heads[0][0] );
+			glColor3fv( &vec3_t( 1.0, 0.0, 0.0 )[0] );
+			glVertex3fv( &skel_anim_controller->tails[0][0] );
+		glEnd();
+	}
+
+	glPopMatrix();
+}

+ 52 - 0
src/scene/skel_node.h

@@ -0,0 +1,52 @@
+#ifndef _SKEL_NODE_H_
+#define _SKEL_NODE_H_
+
+#include "common.h"
+#include "node.h"
+#include "controller.h"
+#include "gmath.h"
+
+
+class skeleton_t;
+class skel_anim_t;
+class skel_node_t;
+
+
+/// Skeleton animation controller
+class skel_anim_controller_t: public controller_t<skel_node_t>
+{
+	private:
+		void Interpolate( skel_anim_t* animation, float frame );
+		void UpdateBoneTransforms();
+		void Deform();
+
+	public:
+		skel_anim_t*  skel_anim; ///< Skeleton animation resource
+		skel_node_t*  skel_node;
+		vec_t<vec3_t> heads;
+		vec_t<vec3_t> tails;
+		vec_t<mat3_t> bone_rotations;
+		vec_t<vec3_t> bone_translations;
+		float step;
+		float frame;
+
+		skel_anim_controller_t( skel_node_t* skel_node_ ): skel_node( skel_node_ ) {}
+		void Update();
+};
+
+
+/// Skeleton node
+class skel_node_t: public node_t
+{
+	public:
+		skeleton_t* skeleton;
+		skel_anim_controller_t* skel_anim_controller;
+
+		skel_node_t(): node_t( NT_SKELETON ) {}
+		void Render();
+		void Init( const char* filename );
+		void Deinit();
+};
+
+
+#endif

+ 0 - 77
src/uncategorized/lights.cpp

@@ -1,77 +0,0 @@
-#include "lights.h"
-#include "collision.h"
-#include "renderer.h"
-
-
-/*
-=======================================================================================================================================
-RenderDebug                                                                                                                           =
-=======================================================================================================================================
-*/
-void light_t::RenderDebug()
-{
-	glPushMatrix();
-	r::MultMatrix( transformation_wspace );
-
-	r::Color3( diffuse_color );
-	r::dbg::RenderSphere( 1.0f/8.0f, 8 );
-
-	glPopMatrix();
-}
-
-/*
-=======================================================================================================================================
-Render                                                                                                                                =
-=======================================================================================================================================
-*/
-void point_light_t::Render()
-{
-	RenderDebug();
-
-	//bsphere_t sphere( translation_wspace, radius );
-	//sphere.Render();
-}
-
-
-/*
-=======================================================================================================================================
-Render                                                                                                                                =
-=======================================================================================================================================
-*/
-void spot_light_t::Render()
-{
-	RenderDebug();
-
-//	vec3_t center( 0.0, 0.0, -camera.GetZFar()/2.0 );
-//	obb_t box( center, mat3_t::ident, vec3_t(1.0, 1.0, 1.0) );
-//	box = box.Transformed( translation_wspace, rotation_wspace, scale_wspace );
-//	box.Render();
-
-
-//	float x = camera.GetZFar() / tan( (PI-camera.GetFovX())/2 );
-//	float y = tan( camera.GetFovY()/2 ) * camera.GetZFar();
-//	float z = -camera.GetZFar();
-//
-//	vec3_t right_top( x, y, z );
-//	vec3_t left_top( -x, y, z );
-//	vec3_t left_bottom( -x, -y, z );
-//	vec3_t right_bottom( x, -y, z );
-//
-//	right_top.Transform( translation_wspace, rotation_wspace, scale_wspace );
-//	left_top.Transform( translation_wspace, rotation_wspace, scale_wspace );
-//	left_bottom.Transform( translation_wspace, rotation_wspace, scale_wspace );
-//	right_bottom.Transform( translation_wspace, rotation_wspace, scale_wspace );
-//
-//	glPointSize( 10.0 );
-//	r::Color3( vec3_t( 0.0, 1.0, 0.0 ) );
-//	glBegin( GL_LINES );
-//		glVertex3fv( &translation_wspace[0] );
-//		glVertex3fv( &right_top[0] );
-//		glVertex3fv( &translation_wspace[0] );
-//		glVertex3fv( &left_top[0] );
-//		glVertex3fv( &translation_wspace[0] );
-//		glVertex3fv( &left_bottom[0] );
-//		glVertex3fv( &translation_wspace[0] );
-//		glVertex3fv( &right_bottom[0] );
-//	glEnd();
-}

+ 0 - 85
src/uncategorized/lights.h

@@ -1,85 +0,0 @@
-#ifndef _LIGHTS_H_
-#define _LIGHTS_H_
-
-#include "common.h"
-#include "primitives.h"
-#include "texture.h"
-#include "object.h"
-#include "camera.h"
-
-/*
-LIGHTING MODEL
-
-Final intensity:                If = Ia + Id + Is
-Ambient intensity:              Ia = Al * Am
-Ambient intensity of light:     Al
-Ambient intensity of material:  Am
-Defuse intensity:               Id = Dl * Dm * LambertTerm
-Defuse intensity of light:      Dl
-Defuse intensity of material:   Dm
-LambertTerm:                    max( Normal dot Light, 0.0 )
-Specular intensity:             Is = Sm x Sl x pow( max(R dot E, 0.0), f )
-Specular intensity of light:    Sl
-Specular intensity of material: Sm
-*/
-
-class light_data_user_class_t: public data_user_class_t {}; // for ambiguity reasons
-
-// light_t (A)
-class light_t: public object_t, public light_data_user_class_t
-{
-	public:
-		enum types_e
-		{
-			POINT,
-			SPOT
-		};
-
-	protected:
-		vec3_t diffuse_color;
-		vec3_t specular_color;
-		types_e type;
-		void RenderDebug();
-
-	public:
-		light_t( types_e type_ ): object_t(LIGHT), type(type_) {}
-
-
-		// Gets & Sets
-		const vec3_t GetDiffuseColor() const { return diffuse_color; }
-		const vec3_t GetSpecularColor() const { return specular_color; }
-		types_e GetType() const { return type; }
-		void SetDiffuseColor( const vec3_t col ) { diffuse_color = col; }
-		void SetSpecularColor( const vec3_t col ) { specular_color = col; }
-};
-
-
-// point_light_t
-class point_light_t: public light_t
-{
-	public:
-		float radius;
-
-		point_light_t(): light_t(POINT) {}
-		void Render();
-		void RenderDepth() {}
-};
-
-
-// spot_light_t
-class spot_light_t: public light_t
-{
-	public:
-		camera_t camera;
-		texture_t* texture;
-		bool casts_shadow;
-
-		spot_light_t(): light_t(SPOT), texture(NULL), casts_shadow(false) { MakeParent(&camera); }
-		float GetDistance() const { return camera.GetZFar(); }
-		void  SetDistance( float d ) { camera.SetZFar(d); }
-		void Render();
-		void RenderDepth() {};
-};
-
-
-#endif

+ 5 - 5
src/uncategorized/map.cpp

@@ -12,7 +12,7 @@
 CreateRoot                                                                                                                            =
 =======================================================================================================================================
 */
-void octree_t::CreateRoot( const vec_t<mesh_data_t*>& meshes )
+void octree_t::CreateRoot( const vec_t<mesh_t*>& meshes )
 {
 	DEBUG_ERR( root ); // root should be NULL
 
@@ -21,7 +21,7 @@ void octree_t::CreateRoot( const vec_t<mesh_data_t*>& meshes )
 
 	for( uint m=0; m<meshes.size(); m++ )
 	{
-		mesh_data_t* cmesh = meshes[m];
+		mesh_t* cmesh = meshes[m];
 		for( uint v=0; v<cmesh->vert_coords.size(); v++ )
 		{
 			const vec3_t& vert_coords = cmesh->vert_coords[v];
@@ -51,7 +51,7 @@ void octree_t::CreateRoot( const vec_t<mesh_data_t*>& meshes )
 
 	for( uint m=0; m<meshes.size(); m++ )
 	{
-		mesh_data_t* cmesh = meshes[m];
+		mesh_t* cmesh = meshes[m];
 
 		// first set the mesh
 		node->meshes[m] = cmesh;
@@ -127,7 +127,7 @@ void octree_t::SubdivideNode( node_t* node )
 CreateTree                                                                                                                            =
 =======================================================================================================================================
 */
-void octree_t::CreateTree( const vec_t<mesh_data_t*>& meshes )
+void octree_t::CreateTree( const vec_t<mesh_t*>& meshes )
 {
 	CreateRoot( meshes );
 	SubdivideNode( root );
@@ -196,7 +196,7 @@ bool map_t::Load( const char* filename )
 		// strings is what we want in this case... please let it be G-Strings
 		if( token->code == scanner_t::TC_STRING )
 		{
-			mesh_data_t* mesh = rsrc::mesh_datas.Load( token->value.string );
+			mesh_t* mesh = rsrc::meshes.Load( token->value.string );
 			if( !mesh ) return false;
 
 			meshes.push_back( mesh );

+ 5 - 5
src/uncategorized/map.h

@@ -4,7 +4,7 @@
 #include "common.h"
 #include "collision.h"
 
-class mesh_data_t;
+class mesh_t;
 class camera_t;
 
 
@@ -24,7 +24,7 @@ class octree_t
 				node_t* childs[8];
 				aabb_t  bounding_box;
 
-				vec_t<mesh_data_t*>   meshes;
+				vec_t<mesh_t*>   meshes;
 				vec_t< vec_t<uint> > vert_ids;
 				vec_t< vec_t<uint> > face_ids;
 
@@ -40,7 +40,7 @@ class octree_t
 		// funcs for the tree creation
 		bool IsSubdivHeuristicMet( node_t* node ) const;
 		void SubdivideNode( node_t* node );
-		void CreateRoot( const vec_t<mesh_data_t*>& meshes );
+		void CreateRoot( const vec_t<mesh_t*>& meshes );
 
 		// frustum funcs
 		uint CheckNodeAgainstFrustum( node_t* node, const camera_t& cam ) const;
@@ -48,7 +48,7 @@ class octree_t
 	public:
 		node_t* root;
 
-		void CreateTree( const vec_t<mesh_data_t*>& meshes );
+		void CreateTree( const vec_t<mesh_t*>& meshes );
 };
 
 
@@ -60,7 +60,7 @@ map_t
 class map_t
 {
 	public:
-		vec_t<mesh_data_t*> meshes;
+		vec_t<mesh_t*> meshes;
 		octree_t             octree;
 
 		bool Load( const char* filename );

+ 0 - 612
src/uncategorized/mesh.cpp

@@ -1,612 +0,0 @@
-#include <iostream>
-#include <fstream>
-#include <string.h>
-#include "mesh.h"
-#include "renderer.h"
-#include "resource.h"
-#include "scanner.h"
-#include "parser.h"
-
-
-/*
-=================================================================================================================================================================
-Load                                                                                                                                                            =
-=================================================================================================================================================================
-*/
-bool mesh_data_t::Load( const char* filename )
-{
-	scanner_t scanner;
-	if( !scanner.LoadFile( filename ) ) return false;
-
-	const scanner_t::token_t* token;
-
-
-	//** MATERIAL **
-	token = &scanner.GetNextToken();
-	if( token->code != scanner_t::TC_STRING )
-	{
-		PARSE_ERR_EXPECTED( "string" );
-		return false;
-	}
-	material_name = new char [strlen(token->value.string)+1];
-	strcpy( material_name, token->value.string );
-
-	//** VERTS **
-	// verts num
-	token = &scanner.GetNextToken();
-	if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
-	{
-		PARSE_ERR_EXPECTED( "integer" );
-		return false;
-	}
-	vert_coords.resize( token->value.int_ );
-
-	// read the verts
-	for( uint i=0; i<vert_coords.size(); i++ )
-	{
-		if( !ParseArrOfNumbers<float>( scanner, false, true, 3, &vert_coords[i][0] ) ) return false;
-	}
-
-	//** FACES **
-	// faces num
-	token = &scanner.GetNextToken();
-	if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
-	{
-		PARSE_ERR_EXPECTED( "integer" );
-		return false;
-	}
-	tris.resize( token->value.int_ );
-	// read the faces
-	for( uint i=0; i<tris.size(); i++ )
-	{
-		if( !ParseArrOfNumbers<uint>( scanner, false, true, 3, tris[i].vert_ids ) ) return false;
-	}
-
-	//** UVS **
-	// UVs num
-	token = &scanner.GetNextToken();
-	if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
-	{
-		PARSE_ERR_EXPECTED( "integer" );
-		return false;
-	}
-	tex_coords.resize( token->value.int_ );
-	// read the tex_coords
-	for( uint i=0; i<tex_coords.size(); i++ )
-	{
-		if( !ParseArrOfNumbers( scanner, false, true, 2, &tex_coords[i][0] ) ) return false;
-	}
-
-	//** VERTEX WEIGHTS **
-	token = &scanner.GetNextToken();
-	if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
-	{
-		PARSE_ERR_EXPECTED( "integer" );
-		return false;
-	}
-	vert_weights.resize( token->value.int_ );
-	for( uint i=0; i<vert_weights.size(); i++ )
-	{
-		// get the bone connections num
-		token = &scanner.GetNextToken();
-		if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
-		{
-			PARSE_ERR_EXPECTED( "integer" );
-			return false;
-		}
-
-		// we treat as error if one vert doesnt have a bone
-		if( token->value.int_ < 1 )
-		{
-			ERROR( "Vert \"" << i << "\" doesnt have at least one bone" );
-			return false;
-		}
-
-		// and here is another possible error
-		if( token->value.int_ > vertex_weight_t::MAX_BONES_PER_VERT )
-		{
-			ERROR( "Cannot have more than " << vertex_weight_t::MAX_BONES_PER_VERT << " bones per vertex" );
-			return false;
-		}
-		vert_weights[i].bones_num = token->value.int_;
-
-		// for all the weights of the current vertes
-		for( uint j=0; j<vert_weights[i].bones_num; j++ )
-		{
-			// read bone id
-			token = &scanner.GetNextToken();
-			if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
-			{
-				PARSE_ERR_EXPECTED( "integer" );
-				return false;
-			}
-			vert_weights[i].bone_ids[j] = token->value.int_;
-
-			// read the weight of that bone
-			token = &scanner.GetNextToken();
-			if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_FLOAT )
-			{
-				PARSE_ERR_EXPECTED( "float" );
-				return false;
-			}
-			vert_weights[i].weights[j] = token->value.float_;
-		}
-	}
-
-	// Sanity checks
-	if( vert_coords.size()<1 || tris.size()<1 )
-	{
-		ERROR( "Vert coords and tris must be filled \"" << filename << "\"" );
-		return false;
-	}
-	if( tex_coords.size()!=0 && tex_coords.size()!=vert_coords.size() )
-	{
-		ERROR( "Tex coords num must be zero or equal to vertex coords num \"" << filename << "\"" );
-		return false;
-	}
-	if( vert_weights.size()!=0 && vert_weights.size()!=vert_coords.size() )
-	{
-		ERROR( "Vert weights num must be zero or equal to vertex coords num \"" << filename << "\"" );
-		return false;
-	}
-
-	CreateAllNormals();
-	CreateVertTangents();
-	CreateVertIndeces();
-	CreateVBOs();
-
-	return true;
-}
-
-
-/*
-=================================================================================================================================================================
-Unload                                                                                                                                                            =
-=================================================================================================================================================================
-*/
-void mesh_data_t::Unload()
-{
-	vert_coords.clear();
-	vert_normals.clear();
-	tris.clear();
-	tex_coords.clear();
-	vert_tangents.clear();
-	vert_indeces.clear();
-	if( material_name ) delete [] material_name;
-}
-
-
-/*
-=======================================================================================================================================
-CreateFaceNormals                                                                                                                     =
-=======================================================================================================================================
-*/
-void mesh_data_t::CreateVertIndeces()
-{
-	DEBUG_ERR( vert_indeces.size() > 0 );
-
-	vert_indeces.resize( tris.size() * 3 );
-	for( uint i=0; i<tris.size(); i++ )
-	{
-		vert_indeces[i*3+0] = tris[i].vert_ids[0];
-		vert_indeces[i*3+1] = tris[i].vert_ids[1];
-		vert_indeces[i*3+2] = tris[i].vert_ids[2];
-	}
-}
-
-
-/*
-=======================================================================================================================================
-CreateFaceNormals                                                                                                                     =
-=======================================================================================================================================
-*/
-void mesh_data_t::CreateFaceNormals()
-{
-	for( uint i=0; i<tris.size(); i++ )
-	{
-		triangle_t& tri = tris[i];
-		const vec3_t& v0 = vert_coords[ tri.vert_ids[0] ];
-		const vec3_t& v1 = vert_coords[ tri.vert_ids[1] ];
-		const vec3_t& v2 = vert_coords[ tri.vert_ids[2] ];
-
-		tri.normal = ( v1 - v0 ).Cross( v2 - v0 );
-
-		tri.normal.Normalize();
-	}
-}
-
-
-/*
-=======================================================================================================================================
-CreateVertNormals                                                                                                                     =
-=======================================================================================================================================
-*/
-void mesh_data_t::CreateVertNormals()
-{
-	vert_normals.resize( vert_coords.size() ); // alloc
-
-	for( uint i=0; i<vert_coords.size(); i++ )
-		vert_normals[i] = vec3_t( 0.0, 0.0, 0.0 );
-
-	for( uint i=0; i<tris.size(); i++ )
-	{
-		const triangle_t& tri = tris[i];
-		vert_normals[ tri.vert_ids[0] ] += tri.normal;
-		vert_normals[ tri.vert_ids[1] ] += tri.normal;
-		vert_normals[ tri.vert_ids[2] ] += tri.normal;
-	}
-
-	for( uint i=0; i<vert_normals.size(); i++ )
-		vert_normals[i].Normalize();
-}
-
-
-/*
-=======================================================================================================================================
-CreateVertTangents                                                                                                                      =
-=======================================================================================================================================
-*/
-void mesh_data_t::CreateVertTangents()
-{
-	vert_tangents.resize( vert_coords.size() ); // alloc
-
-	vec_t<vec3_t> bitagents( vert_coords.size() );
-
-	for( uint i=0; i<vert_tangents.size(); i++ )
-	{
-		vert_tangents[i] = vec4_t( 0.0 );
-		bitagents[i] = vec3_t( 0.0 );
-	}
-
-	for( uint i=0; i<tris.size(); i++ )
-	{
-		const triangle_t& tri = tris[i];
-		const int i0 = tri.vert_ids[0];
-		const int i1 = tri.vert_ids[1];
-		const int i2 = tri.vert_ids[2];
-		const vec3_t& v0 = vert_coords[ i0 ];
-		const vec3_t& v1 = vert_coords[ i1 ];
-		const vec3_t& v2 = vert_coords[ i2 ];
-		vec3_t edge01 = v1 - v0;
-		vec3_t edge02 = v2 - v0;
-		vec2_t uvedge01 = tex_coords[i1] - tex_coords[i0];
-		vec2_t uvedge02 = tex_coords[i2] - tex_coords[i0];
-
-
-		float det = (uvedge01.y * uvedge02.x) - (uvedge01.x * uvedge02.y);
-		DEBUG_ERR( IsZero(det) );
-		det = 1.0f / det;
-
-		vec3_t t = ( edge02 * uvedge01.y - edge01 * uvedge02.y ) * det;
-		vec3_t b = ( edge02 * uvedge01.x - edge01 * uvedge02.x ) * det;
-		t.Normalize();
-		b.Normalize();
-
-		vert_tangents[i0] += vec4_t(t, 1.0);
-		vert_tangents[i1] += vec4_t(t, 1.0);
-		vert_tangents[i2] += vec4_t(t, 1.0);
-
-		bitagents[i0] += b;
-		bitagents[i1] += b;
-		bitagents[i2] += b;
-	}
-
-	for( uint i=0; i<vert_tangents.size(); i++ )
-	{
-		vec3_t t = vec3_t(vert_tangents[i]);
-		const vec3_t& n = vert_normals[i];
-		vec3_t& b = bitagents[i];
-
-		//t = t - n * n.Dot(t);
-		t.Normalize();
-
-		b.Normalize();
-
-		float w = ( (n.Cross(t)).Dot( b ) < 0.0) ? 1.0 : -1.0;
-
-		vert_tangents[i] = vec4_t( t, w );
-	}
-
-	bitagents.clear();
-
-//	for( uint i=0; i<tris.size(); i++ )
-//	{
-//		const triangle_t& tri = tris[i];
-//		const int vi1 = tri.vert_ids[0];
-//		const int vi2 = tri.vert_ids[1];
-//		const int vi3 = tri.vert_ids[2];
-//		vec3_t v1 = verts[ vi3 ].coords - verts[ vi1 ].coords;
-//		vec3_t v2 = verts[ vi2 ].coords - verts[ vi1 ].coords;
-//
-//		vec2_t st1 = uvs[vi3] - uvs[vi1];
-//		vec2_t st2 = uvs[vi2] - uvs[vi1];
-//
-//
-//		float coef = 1 / (st1.x * st2.y - st2.x * st1.y);
-//		vec3_t tangent;
-//
-//		tangent.x = coef * ((v1.x * st2.y)  + (v2.x * -st1.y));
-//		tangent.y = coef * ((v1.y * st2.y)  + (v2.y * -st1.y));
-//		tangent.z = coef * ((v1.z * st2.y)  + (v2.z * -st1.y));
-//
-//
-//		face_tangents[i] = tangent;
-//	}
-
-//    vec3_t* tan1 = new vec3_t[verts.size() * 2];
-//    vec3_t* tan2 = tan1 + verts.size();
-//    memset( tan1, 0, verts.size() * 2 * sizeof(vec3_t) );
-//
-//    for (long a = 0; a < tris.size(); a++)
-//    {
-//			triangle_t* triangle = &tris[a];
-//			long i1 = triangle->vert_ids[0];
-//			long i2 = triangle->vert_ids[1];
-//			long i3 = triangle->vert_ids[2];
-//
-//			const vec3_t& v1 = verts[i1].coords;
-//			const vec3_t& v2 = verts[i2].coords;
-//			const vec3_t& v3 = verts[i3].coords;
-//
-//			const vec2_t& w1 = uvs[i1];
-//			const vec2_t& w2 = uvs[i2];
-//			const vec2_t& w3 = uvs[i3];
-//
-//			float x1 = v2.x - v1.x;
-//			float x2 = v3.x - v1.x;
-//			float y1 = v2.y - v1.y;
-//			float y2 = v3.y - v1.y;
-//			float z1 = v2.z - v1.z;
-//			float z2 = v3.z - v1.z;
-//
-//			float s1 = w2.x - w1.x;
-//			float s2 = w3.x - w1.x;
-//			float t1 = w2.y - w1.y;
-//			float t2 = w3.y - w1.y;
-//
-//			float r = 1.0F / (s1 * t2 - s2 * t1);
-//			vec3_t sdir( (t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r,
-//							(t2 * z1 - t1 * z2) * r);
-//			vec3_t tdir((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r,
-//							(s1 * z2 - s2 * z1) * r);
-//
-//			tan1[i1] += sdir;
-//			tan1[i2] += sdir;
-//			tan1[i3] += sdir;
-//
-//			tan2[i1] += tdir;
-//			tan2[i2] += tdir;
-//			tan2[i3] += tdir;
-//
-//    }
-//
-//    for (long a = 0; a < verts.size(); a++)
-//    {
-//        const vec3_t& n = verts[a].normal;
-//        const vec3_t& t = tan1[a];
-//
-//        // Gram-Schmidt orthogonalize
-//        vert_tangents[a] = vec4_t(
-//					( (t - n) * n.Dot(t)).Normalized(),
-//					( (n*t).Dot( tan2[a] ) < 0.0F) ? -1.0F : 1.0F // handedness
-//				);
-//    }
-//
-//    delete[] tan1;
-}
-
-
-/*
-=======================================================================================================================================
-CreateVBOs                                                                                                                            =
-=======================================================================================================================================
-*/
-void mesh_data_t::CreateVBOs()
-{
-	vbos.vert_indeces.Create( GL_ELEMENT_ARRAY_BUFFER, vert_indeces.GetSizeInBytes(), &vert_indeces[0], GL_STATIC_DRAW );
-	vbos.vert_coords.Create( GL_ARRAY_BUFFER, vert_coords.GetSizeInBytes(), &vert_coords[0], GL_STATIC_DRAW );
-	vbos.vert_normals.Create( GL_ARRAY_BUFFER, vert_normals.GetSizeInBytes(), &vert_normals[0], GL_STATIC_DRAW );
-	vbos.vert_tangents.Create( GL_ARRAY_BUFFER, vert_tangents.GetSizeInBytes(), &vert_tangents[0], GL_STATIC_DRAW );
-	if( tex_coords.size() > 1 )
-		vbos.tex_coords.Create( GL_ARRAY_BUFFER, tex_coords.GetSizeInBytes(), &tex_coords[0], GL_STATIC_DRAW );
-	if( vert_weights.size() > 1 )
-		vbos.vert_weights.Create( GL_ARRAY_BUFFER, vert_weights.GetSizeInBytes(), &vert_weights[0], GL_STATIC_DRAW );
-
-}
-
-
-/*
-=======================================================================================================================================
-Load                                                                                                                                  =
-=======================================================================================================================================
-*/
-bool mesh_t::Load( const char* filename )
-{
-	mesh_data = rsrc::mesh_datas.Load( filename );
-	if( !mesh_data ) return false;
-
-	material = rsrc::materials.Load( mesh_data->material_name );
-	if( !material ) return false;
-
-	return true;
-}
-
-
-/*
-=======================================================================================================================================
-Unload                                                                                                                                =
-=======================================================================================================================================
-*/
-void mesh_t::Unload()
-{
-	rsrc::mesh_datas.Unload( mesh_data );
-	rsrc::materials.Unload( material );
-}
-
-
-/*
-=======================================================================================================================================
-Render                                                                                                                                =
-=======================================================================================================================================
-*/
-void mesh_t::Render()
-{
-	glPushMatrix();
-	r::MultMatrix( transformation_wspace );
-
-
-	if( material->attribute_locs.position != -1 )
-	{
-		mesh_data->vbos.vert_coords.Bind();
-		glVertexAttribPointer( material->attribute_locs.position, 3, GL_FLOAT, false, 0, NULL );
-		glEnableVertexAttribArray( material->attribute_locs.position );
-	}
-
-	if( material->attribute_locs.normal != -1 )
-	{
-		mesh_data->vbos.vert_normals.Bind();
-		glVertexAttribPointer( material->attribute_locs.normal, 3, GL_FLOAT, false, 0, NULL );
-		glEnableVertexAttribArray( material->attribute_locs.normal );
-	}
-
-	if( material->attribute_locs.tex_coords != -1 )
-	{
-		mesh_data->vbos.tex_coords.Bind();
-		glVertexAttribPointer( material->attribute_locs.tex_coords, 2, GL_FLOAT, false, 0, NULL );
-		glEnableVertexAttribArray( material->attribute_locs.tex_coords );
-	}
-
-	if( material->attribute_locs.tanget != -1 )
-	{
-		mesh_data->vbos.vert_tangents.Bind();
-		glVertexAttribPointer( material->attribute_locs.tanget, 4, GL_FLOAT, false, 0, NULL );
-		glEnableVertexAttribArray( material->attribute_locs.tanget );
-	}
-
-	mesh_data->vbos.vert_indeces.Bind();
-
-	glDrawElements( GL_TRIANGLES, mesh_data->vert_indeces.size(), GL_UNSIGNED_SHORT, 0 );
-
-
-	if( material->attribute_locs.position != -1 ) glDisableVertexAttribArray( material->attribute_locs.position );
-	if( material->attribute_locs.normal != -1 ) glDisableVertexAttribArray( material->attribute_locs.normal );
-	if( material->attribute_locs.tex_coords != -1 ) glDisableVertexAttribArray( material->attribute_locs.tex_coords );
-	if( material->attribute_locs.tanget != -1 ) glDisableVertexAttribArray( material->attribute_locs.tanget );
-
-
-	vbo_t::UnbindAllTargets();
-	glPopMatrix();
-}
-
-
-/*
-=======================================================================================================================================
-RenderNormals                                                                                                                         =
-=======================================================================================================================================
-*/
-void mesh_t::RenderNormals()
-{
-	glPushMatrix();
-	r::MultMatrix( transformation_wspace );
-
-	//glLineWidth( 1.0 );
-	glColor3f( 0.0, 0.0, 1.0 );
-
-	glBegin( GL_LINES );
-		for( uint i=0; i<mesh_data->tris.size(); i++ )
-		{
-			triangle_t* tri = &mesh_data->tris[i];
-			for( int j=0; j<3; j++ )
-			{
-				const vec3_t& normal = mesh_data->vert_normals[ tri->vert_ids[j] ];
-				const vec3_t& coord = mesh_data->vert_coords[ tri->vert_ids[j] ];
-
-				vec3_t vec0;
-				vec0 = (normal * 0.1f) + coord;
-
-				glVertex3fv( &(const_cast<vec3_t&>(coord))[0] );
-				glVertex3fv( &vec0[0] );
-			}
-		}
-	glEnd();
-
-	glPopMatrix();
-}
-
-
-/*
-=======================================================================================================================================
-RenderTangents                                                                                                                        =
-=======================================================================================================================================
-*/
-void mesh_t::RenderTangents()
-{
-	glPushMatrix();
-	r::MultMatrix( transformation_wspace );
-
-	//glLineWidth( 1.0 );
-	glColor3f( 1.0, 0.0, 0.0 );
-
-	glBegin( GL_LINES );
-		for( uint i=0; i<mesh_data->vert_coords.size(); i++ )
-		{
-				vec3_t vec0 = (vec3_t(mesh_data->vert_tangents[i]) * 0.1f) + mesh_data->vert_coords[i];
-
-				glVertex3fv( &mesh_data->vert_coords[i][0] );
-				glVertex3fv( &vec0[0] );
-		}
-	glEnd();
-
-	glPopMatrix();
-}
-
-
-
-/*
-=======================================================================================================================================
-RenderDepth                                                                                                                           =
-=======================================================================================================================================
-*/
-void mesh_t::RenderDepth()
-{
-	glPushMatrix();
-	r::MultMatrix( transformation_wspace );
-
-	/*glEnableClientState( GL_VERTEX_ARRAY );
-	glVertexPointer( 3, GL_FLOAT, 0, &mesh_data->vert_coords[0][0] );
-
-	if( material->grass_map )
-	{
-		glEnableClientState( GL_TEXTURE_COORD_ARRAY );
-		glTexCoordPointer( 2, GL_FLOAT, 0, &mesh_data->uvs[0] );
-	}
-
-	glDrawElements( GL_TRIANGLES, mesh_data->vert_indeces.size(), GL_UNSIGNED_SHORT, &mesh_data->vert_indeces[0] );
-
-	glDisableClientState( GL_VERTEX_ARRAY );
-	if( material->grass_map )
-		glDisableClientState( GL_TEXTURE_COORD_ARRAY );*/
-
-	mesh_data->vbos.vert_coords.Bind();
-	glVertexPointer( 3, GL_FLOAT, 0, NULL );
-
-	if( material->grass_map )
-	{
-		mesh_data->vbos.tex_coords.Bind();
-		glTexCoordPointer( 2, GL_FLOAT, 0, NULL );
-		glEnableClientState( GL_TEXTURE_COORD_ARRAY );
-	}
-
-	mesh_data->vbos.vert_indeces.Bind();
-
-	glEnableClientState( GL_VERTEX_ARRAY );
-
-	glDrawElements( GL_TRIANGLES, mesh_data->vert_indeces.size(), GL_UNSIGNED_SHORT, 0 );
-
-	glDisableClientState( GL_VERTEX_ARRAY );
-	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
-
-	vbo_t::UnbindAllTargets();
-
-	glPopMatrix();
-}

+ 0 - 63
src/uncategorized/model.cpp

@@ -1,63 +0,0 @@
-#include "model.h"
-#include "scanner.h"
-#include "parser.h"
-#include "mesh.h"
-
-
-/*
-=======================================================================================================================================
-Load                                                                                                                                  =
-=======================================================================================================================================
-*/
-bool model_t::Load( const char* filename )
-{
-	scanner_t scanner;
-	if( !scanner.LoadFile( filename ) ) return false;
-	const scanner_t::token_t* token;
-
-
-	do
-	{
-		token = &scanner.GetNextToken();
-
-		// I want only strings and yes I prefere G-Strings
-		if( token->code == scanner_t::TC_STRING )
-		{
-			mesh_data_t* mesh = rsrc::mesh_datas.Load( token->value.string );
-			if( mesh == NULL )
-			{
-				ERROR( "Model \"" << filename << "\": Cannot load mesh \"" << token->value.string << "\"" );
-				return false;
-			}
-			meshes.push_back( mesh );
-		}
-		// end of file
-		else if( token->code == scanner_t::TC_EOF )
-		{
-			break;
-		}
-		// other crap
-		else
-		{
-			PARSE_ERR_UNEXPECTED();
-			return false;
-		}
-
-	}while( true );
-
-	return true;
-}
-
-
-/*
-=======================================================================================================================================
-Unload                                                                                                                                =
-=======================================================================================================================================
-*/
-void model_t::Unload()
-{
-	for( uint i=0; i<meshes.size(); i++ )
-	{
-		rsrc::mesh_datas.Unload( meshes[i] );
-	}
-}

+ 0 - 18
src/uncategorized/model.h

@@ -1,18 +0,0 @@
-#ifndef _MODEL_H_
-#define _MODEL_H_
-
-#include "common.h"
-#include "resource.h"
-
-class mesh_data_t;
-
-class model_t: public resource_t
-{
-	public:
-		vector<mesh_data_t*> meshes;
-
-		bool Load( const char* filename );
-		void Unload();
-};
-
-#endif

+ 0 - 180
src/uncategorized/scene.cpp

@@ -1,180 +0,0 @@
-#include "scene.h"
-
-namespace scene {
-
-/*
-=======================================================================================================================================
-DATA                                                                                                                                  =
-=======================================================================================================================================
-*/
-skybox_t skybox;
-
-container_object_t objects;
-container_light_t lights;
-container_camera_t cameras;
-container_mesh_t meshes;
-container_smodel_t smodels;
-
-
-/*
-=======================================================================================================================================
-UpdateAllWorldStuff                                                                                                                   =
-=======================================================================================================================================
-*/
-void UpdateAllWorldStuff()
-{
-	DEBUG_ERR( objects.size() > 1024 );
-	object_t* queue [1024];
-	uint head = 0, tail = 0;
-	uint num = 0;
-
-
-	// put the roots
-	for( uint i=0; i<objects.size(); i++ )
-		if( objects[i]->parent == NULL )
-			queue[tail++] = objects[i]; // queue push
-
-	// loop
-	while( head != tail ) // while queue not empty
-	{
-		object_t* obj = queue[head++]; // queue pop
-
-		obj->UpdateWorldStuff();
-		++num;
-
-		for( uint i=0; i<obj->childs.size(); i++ )
-			queue[tail++] = obj->childs[i];
-	}
-
-	DEBUG_ERR( num != objects.size() );
-}
-
-
-/*
-=======================================================================================================================================
-RenderAll                                                                                                                             =
-=======================================================================================================================================
-*/
-void RenderAllObjs()
-{
-	for( uint i=0; i<objects.size(); i++ )
-		objects[i]->Render();
-}
-
-
-/*
-=======================================================================================================================================
-InterpolateAllModels                                                                                                                  =
-=======================================================================================================================================
-*/
-void InterpolateAllModels()
-{
-	for( uint i=0; i<smodels.size(); i++ )
-	{
-		smodels[i]->Interpolate();
-		smodels[i]->Deform();
-	}
-}
-
-
-/*
-=======================================================================================================================================
-object_t                                                                                                                              =
-=======================================================================================================================================
-*/
-void container_object_t::Register( object_t* x )
-{
-	RegisterMe( x );
-}
-
-void container_object_t::Unregister( object_t* x )
-{
-	UnregisterMe( x );
-}
-
-
-/*
-=======================================================================================================================================
-camera_t                                                                                                                              =
-=======================================================================================================================================
-*/
-void container_camera_t::Register( camera_t* x )
-{
-	RegisterMe( x );
-	objects.Register( x );
-}
-
-void container_camera_t::Unregister( camera_t* x )
-{
-	UnregisterMe( x );
-	objects.Unregister( x );
-}
-
-
-/*
-=======================================================================================================================================
-light_t                                                                                                                               =
-=======================================================================================================================================
-*/
-void container_light_t::Register( light_t* x )
-{
-	RegisterMe( x );
-	objects.Register( x );
-
-	if( x->GetType() == light_t::SPOT )
-	{
-		spot_light_t* projl = static_cast<spot_light_t*>(x);
-		cameras.Register( &projl->camera );
-	}
-}
-
-void container_light_t::Unregister( light_t* x )
-{
-	UnregisterMe( x );
-	objects.Unregister( x );
-
-	if( x->GetType() == light_t::SPOT )
-	{
-		spot_light_t* projl = static_cast<spot_light_t*>(x);
-		cameras.Unregister( &projl->camera );
-	}
-}
-
-
-/*
-=======================================================================================================================================
-smodel_t                                                                                                                               =
-=======================================================================================================================================
-*/
-void container_smodel_t::Register( smodel_t* x )
-{
-	RegisterMe( x );
-	objects.Register( x );
-}
-
-void container_smodel_t::Unregister( smodel_t* x )
-{
-	UnregisterMe( x );
-	objects.Unregister( x );
-}
-
-
-/*
-=======================================================================================================================================
-mesh_t                                                                                                                                =
-=======================================================================================================================================
-*/
-void container_mesh_t::Register( mesh_t* x )
-{
-	RegisterMe( x );
-	objects.Register( x );
-}
-
-void container_mesh_t::Unregister( mesh_t* x )
-{
-	UnregisterMe( x );
-	objects.Unregister( x );
-}
-
-
-} // end namespace

+ 0 - 867
src/uncategorized/smodel.cpp

@@ -1,867 +0,0 @@
-#include <fstream>
-#include "smodel.h"
-#include "resource.h"
-#include "material.h"
-#include "renderer.h"
-#include "scanner.h"
-#include "parser.h"
-
-
-/*
-=======================================================================================================================================
-model's data                                                                                                                          =
-=======================================================================================================================================
-*/
-
-
-/*
-=======================================================================================================================================
-skeleton_data_t::Load                                                                                                                 =
-=======================================================================================================================================
-*/
-bool skeleton_data_t::Load( const char* filename )
-{
-	scanner_t scanner;
-	if( !scanner.LoadFile( filename ) ) return false;
-
-	const scanner_t::token_t* token;
-
-
-	//** BONES NUM **
-	token = &scanner.GetNextToken();
-	if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
-	{
-		PARSE_ERR_EXPECTED( "integer" );
-		return false;
-	}
-	bones.resize( token->value.int_, bone_data_t() );
-
-	for( uint i=0; i<bones.size(); i++ )
-	{
-		bone_data_t& bone = bones[i];
-		bone.id = i;
-
-		// NAME
-		token = &scanner.GetNextToken();
-		if( token->code != scanner_t::TC_STRING )
-		{
-			PARSE_ERR_EXPECTED( "string" );
-			return false;
-		}
-		bone.SetName( token->value.string );
-
-		// head
-		if( !ParseArrOfNumbers<float>( scanner, false, true, 3, &bone.head[0] ) ) return false;
-
-		// tail
-		if( !ParseArrOfNumbers<float>( scanner, false, true, 3, &bone.tail[0] ) ) return false;
-
-		// matrix
-		mat4_t m4;
-		if( !ParseArrOfNumbers<float>( scanner, false, true, 16, &m4[0] ) ) return false;
-
-		// matrix for real
-		bone.rot_skel_space = m4.GetRotationPart();
-		bone.tsl_skel_space = m4.GetTranslationPart();
-		mat4_t MAi( m4.GetInverse() );
-		bone.rot_skel_space_inv = MAi.GetRotationPart();
-		bone.tsl_skel_space_inv = MAi.GetTranslationPart();
-
-		// parent
-		token = &scanner.GetNextToken();
-		if( (token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT) &&
-		    (token->code != scanner_t::TC_IDENTIFIER || !strcmp( token->value.string, "REPEAT_TXTR_MAP_T" )) )
-		{
-			PARSE_ERR_EXPECTED( "integer or NULL" );
-			return false;
-		}
-
-		if( token->code == scanner_t::TC_IDENTIFIER )
-			bone.parent = NULL;
-		else
-			bone.parent = &bones[ token->value.int_ ];
-
-		// childs
-		token = &scanner.GetNextToken();
-		if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
-		{
-			PARSE_ERR_EXPECTED( "integer" );
-			return false;
-		}
-		if( token->value.int_ > bone_data_t::MAX_CHILDS_PER_BONE )
-		{
-			ERROR( "Childs for bone \"" << bone.GetName() << "\" exceed the max" );
-			return false;
-		}
-		bone.childs_num = token->value.int_;
-		for( int j=0; j<bone.childs_num; j++ )
-		{
-			token = &scanner.GetNextToken();
-			if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
-			{
-				PARSE_ERR_EXPECTED( "integer" );
-				return false;
-			}
-			bone.childs[j] = &bones[ token->value.int_ ];
-		}
-	}
-
-	return true;
-}
-
-
-/*
-=======================================================================================================================================
-model_data_t::LoadVWeights                                                                                                            =
-=======================================================================================================================================
-*/
-/*bool model_data_t::LoadVWeights( const char* filename )
-{
-	scanner_t scanner;
-	if( !scanner.LoadFile( filename ) ) return false;
-
-	const scanner_t::token_t* token;
-
-
-	// get the verts num
-	token = &scanner.GetNextToken();
-	if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
-	{
-		PARSE_ERR_EXPECTED( "integer" );
-		return false;
-	}
-	// do a check
-	if( token->value.int_ != mesh_data->vert_coords.size() )
-	{
-		ERROR( "The verts weight num is not equal to the verts num" );
-		return false;
-	}
-	vert_weights.resize( token->value.int_ );
-
-	// for all vert weights
-	for( uint i=0; i<vert_weights.size(); i++ )
-	{
-		// get the bone connections num
-		token = &scanner.GetNextToken();
-		if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
-		{
-			PARSE_ERR_EXPECTED( "integer" );
-			return false;
-		}
-
-		// we treat as error if one vert doesnt have a bone
-		if( token->value.int_ < 1 )
-		{
-			ERROR( "Vert \"" << i << "\" doesnt have at least one bone" );
-			return false;
-		}
-
-		// and here is another possible error
-		if( token->value.int_ > vertex_weight_t::MAX_BONES_PER_VERT )
-		{
-			ERROR( "Cannot have more than " << vertex_weight_t::MAX_BONES_PER_VERT << " bones per vertex" );
-			return false;
-		}
-
-		vert_weights[i].bones_num = token->value.int_;
-
-		for( uint j=0; j<vert_weights[i].bones_num; j++ )
-		{
-			// read bone id
-			token = &scanner.GetNextToken();
-			if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT )
-			{
-				PARSE_ERR_EXPECTED( "integer" );
-				return false;
-			}
-			if( token->value.int_ >= skeleton_data->bones.size() )
-			{
-				ERROR( "Incorrect bone id" );
-				return false;
-			}
-			vert_weights[i].bone_ids[j] = token->value.int_;
-
-			// read the weight of that bone
-			token = &scanner.GetNextToken();
-			if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_FLOAT )
-			{
-				PARSE_ERR_EXPECTED( "float" );
-				return false;
-			}
-			vert_weights[i].weights[j] = token->value.float_;
-		}
-	}
-
-	return true;
-}*/
-
-
-/*
-=======================================================================================================================================
-model_data_t::Load                                                                                                                    =
-=======================================================================================================================================
-*/
-bool model_data_t::Load( const char* filename )
-{
-	scanner_t scanner;
-	if( !scanner.LoadFile( filename ) ) return false;
-
-	const scanner_t::token_t* token;
-
-	do
-	{
-		token = &scanner.GetNextToken();
-
-		//** MESH **
-		if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "MESH" ) )
-		{
-			if( mesh_data )
-			{
-				PARSE_ERR( "mesh_data allready set" );
-				return false;
-			}
-
-			token = &scanner.GetNextToken();
-			if( token->code != scanner_t::TC_STRING )
-			{
-				PARSE_ERR_EXPECTED( "string" );
-				return false;
-			}
-			if( (mesh_data = rsrc::mesh_datas.Load( token->value.string )) == NULL ) return false;
-		}
-
-		//** SKELETON **
-		else if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "SKELETON" ) )
-		{
-			if( skeleton_data )
-			{
-				PARSE_ERR( "skeleton_data allready set" );
-				return false;
-			}
-
-			token = &scanner.GetNextToken();
-			if( token->code != scanner_t::TC_STRING )
-			{
-				PARSE_ERR_EXPECTED( "string" );
-				return false;
-			}
-			skeleton_data = new skeleton_data_t;
-			if( !skeleton_data->Load( token->value.string ) ) return false;
-		}
-
-		//** VERTEX_WEIGHTS **
-		/*else if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "VERTEX_WEIGHTS" ) )
-		{
-			if( vert_weights.size() > 0 )
-			{
-				PARSE_ERR( "vert_weights not empty" );
-				return false;
-			}
-
-			token = &scanner.GetNextToken();
-			if( token->code != scanner_t::TC_STRING )
-			{
-				PARSE_ERR_EXPECTED( "string" );
-				return false;
-			}
-			if( !LoadVWeights( token->value.string ) ) return false;
-		}*/
-
-		//** EOF **
-		else if( token->code == scanner_t::TC_EOF )
-		{
-			break;
-		}
-
-		//** other crap **
-		else
-		{
-			PARSE_ERR_UNEXPECTED();
-			return false;
-		}
-	}while( true ); // end do
-
-	return true;
-}
-
-
-
-/*
-=======================================================================================================================================
-skeleton animation                                                                                                                    =
-=======================================================================================================================================
-*/
-
-
-/*
-=======================================================================================================================================
-Load                                                                                                                                  =
-=======================================================================================================================================
-*/
-bool skeleton_anim_t::Load( const char* filename )
-{
-	/*fstream file( filename, ios::in );
-	char str[200];
-	int tmpi;
-
-	if( !file.is_open() )
-	{
-		ERROR( "Cannot open \"" << filename << "\"" );
-		return false;
-	}
-
-	// read the keyframes
-	file >> str >> tmpi >> str; // the keyframes num
-	keyframes.resize( tmpi );
-
-	for( uint i=0; i<keyframes.size(); i++ )
-	{
-		file >> tmpi;
-		keyframes[i] = tmpi;
-	}
-
-	// frames_num
-	frames_num = keyframes[ keyframes.size()-1 ] + 1;
-
-	// bones
-	file >> str >> tmpi;
-	bones.resize( tmpi );
-
-	for( uint i=0; i<bones.size(); i++ )
-	{
-		file >> str >> str >> str >> str >> str >> tmpi;
-		if( tmpi ) // if has animation
-		{
-			bones[i].keyframes.resize( keyframes.size() );
-
-			for( uint j=0; j<keyframes.size(); j++ )
-			{
-				file >> str >> str >> str;
-
-				file >> bones[i].keyframes[j].rotation.w >> bones[i].keyframes[j].rotation.x >> bones[i].keyframes[j].rotation.y >>
-				        bones[i].keyframes[j].rotation.z;
-
-				file >> str;
-				for( int k=0; k<3; k++ )
-					file >> bones[i].keyframes[j].translation[k];
-			}
-		}
-	}
-
-	file.close();
-	return true;*/
-
-	scanner_t scanner;
-	if( !scanner.LoadFile( filename ) ) return false;
-
-	const scanner_t::token_t* token;
-
-
-	// keyframes
-	token = &scanner.GetNextToken();
-	if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT  )
-	{
-		PARSE_ERR_EXPECTED( "integer" );
-		return false;
-	}
-	keyframes.resize( token->value.int_ );
-
-	if( !ParseArrOfNumbers( scanner, false, false, keyframes.size(), &keyframes[0] ) ) return false;
-
-	// bones num
-	token = &scanner.GetNextToken();
-	if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT  )
-	{
-		PARSE_ERR_EXPECTED( "integer" );
-		return false;
-	}
-	bones.resize( token->value.int_ );
-
-	// poses
-	for( uint i=0; i<bones.size(); i++ )
-	{
-		// has anim?
-		token = &scanner.GetNextToken();
-		if( token->code != scanner_t::TC_NUMBER || token->type != scanner_t::DT_INT  )
-		{
-			PARSE_ERR_EXPECTED( "integer" );
-			return false;
-		}
-
-		// it has
-		if( token->value.int_ == 1 )
-		{
-			bones[i].keyframes.resize( keyframes.size() );
-
-			for( uint j=0; j<keyframes.size(); ++j )
-			{
-				// parse the quat
-				float tmp[4];
-				if( !ParseArrOfNumbers( scanner, false, true, 4, &tmp[0] ) ) return false;
-				bones[i].keyframes[j].rotation = quat_t( tmp[1], tmp[2], tmp[3], tmp[0] );
-
-				// parse the vec3
-				if( !ParseArrOfNumbers( scanner, false, true, 3, &bones[i].keyframes[j].translation[0] ) ) return false;
-			}
-		}
-	} // end for all bones
-
-
-	frames_num = keyframes[ keyframes.size()-1 ] + 1;
-
-	return true;
-}
-
-
-/*
-=======================================================================================================================================
-model                                                                                                                                 =
-=======================================================================================================================================
-*/
-
-
-/*
-=======================================================================================================================================
-model_t::Init                                                                                                                         =
-=======================================================================================================================================
-*/
-void smodel_t::Init( model_data_t* model_data_ )
-{
-	model_data = model_data_;
-
-	// init the bones
-	bones.resize( model_data->skeleton_data->bones.size() );
-	bone_rotations.resize( model_data->skeleton_data->bones.size() );
-	bone_translations.resize( model_data->skeleton_data->bones.size() );
-
-	// init the verts and vert tangents
-	vert_coords.resize( model_data->mesh_data->vert_coords.size() );
-	vert_normals.resize( model_data->mesh_data->vert_coords.size() );
-	vert_tangents.resize( model_data->mesh_data->vert_coords.size() );
-
-	// the material
-	material = rsrc::materials.Load( model_data->mesh_data->material_name );
-}
-
-
-/*
-=======================================================================================================================================
-model_t::Interpolate                                                                                                                  =
-=======================================================================================================================================
-*/
-void smodel_t::Interpolate( skeleton_anim_t* anim, float frame )
-{
-	DEBUG_ERR( frame >= anim->frames_num );
-
-	// calculate the t (used in slerp and lerp) and
-	// calc the l_pose and r_pose witch indicate the pose ids in witch the frame lies between
-	const vec_t<uint>& keyframes = anim->keyframes;
-	float t = 0.0;
-	uint l_pose = 0, r_pose = 0;
-	for( uint j=0; j<keyframes.size(); j++ )
-	{
-		if( (float)keyframes[j] == frame )
-		{
-			l_pose = r_pose = j;
-			t = 0.0;
-			break;
-		}
-		else if( (float)keyframes[j] > frame )
-		{
-			l_pose = j-1;
-			r_pose = j;
-			t = ( frame - (float)keyframes[l_pose] ) / float( keyframes[r_pose] - keyframes[l_pose] );
-			break;
-		}
-	}
-
-
-	uint i;
-	// now for all bones update bone's poses
-	for( i=0; i<bones.size(); i++ )
-	{
-		const bone_anim_t& banim = anim->bones[i];
-
-		mat3_t& local_rot = bone_rotations[i];
-		vec3_t& local_transl = bone_translations[i];
-
-		// if the bone has animations then slerp and lerp to find the rotation and translation
-		if( banim.keyframes.size() != 0 )
-		{
-			const bone_pose_t& l_bpose = banim.keyframes[l_pose];
-			const bone_pose_t& r_bpose = banim.keyframes[r_pose];
-
-			// rotation
-			const quat_t& q0 = l_bpose.rotation;
-			const quat_t& q1 = r_bpose.rotation;
-			local_rot = mat3_t( q0.Slerp(q1, t) );
-
-			// translation
-			const vec3_t& v0 = l_bpose.translation;
-			const vec3_t& v1 = r_bpose.translation;
-			local_transl = v0.Lerp( v1, t );
-		}
-		// else put the idents
-		else
-		{
-			local_rot = mat3_t::GetIdentity();
-			local_transl = vec3_t( 0.0, 0.0, 0.0 );
-		}
-	}
-
-}
-
-
-/*
-=======================================================================================================================================
-model_t::Interpolate                                                                                                                  =
-=======================================================================================================================================
-*/
-void smodel_t::Interpolate()
-{
-	DEBUG_ERR( !model_data );
-
-	for( ushort i=0; i<MAX_SIMULTANEOUS_ANIMS; i++ )
-	{
-		action_t* crnt = &crnt_actions[i];
-		action_t* next = &next_actions[i];
-
-		if( crnt->anim == NULL ) continue; // if the slot doesnt have anim dont bother
-
-		if( crnt->frame + crnt->step > crnt->anim->frames_num ) // if the crnt is finished then play the next or loop the crnt
-		{
-			if( next->anim == NULL ) // if there is no next anim then loop the crnt
-				crnt->frame = 0.0;
-			else // else play the next
-			{
-				crnt->anim = next->anim;
-				crnt->step = next->step;
-				crnt->frame = 0.0;
-				next->anim = NULL;
-			}
-		}
-
-		Interpolate( crnt->anim, crnt->frame );
-
-		crnt->frame += crnt->step; // inc the frame
-	}
-
-	UpdateBoneTransforms();
-}
-
-
-/*
-=======================================================================================================================================
-model_t::UpdateBoneTransforms                                                                                                         =
-=======================================================================================================================================
-*/
-void smodel_t::UpdateBoneTransforms()
-{
-	uint queue[ 128 ];
-	uint head = 0, tail = 0;
-
-
-	// put the roots
-	for( uint i=0; i<bones.size(); i++ )
-		if( model_data->skeleton_data->bones[i].parent == NULL )
-			queue[tail++] = i; // queue push
-
-	// loop
-	while( head != tail ) // while queue not empty
-	{
-		uint bone_id = queue[head++]; // queue pop
-		const bone_data_t& boned = model_data->skeleton_data->bones[bone_id];
-
-		// bone.final_transform = MA * ANIM * MAi
-		// where MA is bone matrix at armature space and ANIM the interpolated transformation.
-		CombineTransformations( bone_translations[bone_id], bone_rotations[bone_id],
-		                        boned.tsl_skel_space_inv, boned.rot_skel_space_inv,
-		                        bone_translations[bone_id], bone_rotations[bone_id] );
-
-		CombineTransformations( boned.tsl_skel_space, boned.rot_skel_space,
-		                        bone_translations[bone_id], bone_rotations[bone_id],
-		                        bone_translations[bone_id], bone_rotations[bone_id] );
-
-		// and finaly add the parent's transform
-		if( boned.parent )
-		{
-			// bone.final_final_transform = parent.transf * bone.final_transform
-			CombineTransformations( bone_translations[boned.parent->id], bone_rotations[boned.parent->id],
-		                          bone_translations[bone_id], bone_rotations[bone_id],
-		                          bone_translations[bone_id], bone_rotations[bone_id] );
-		}
-
-		// now add the bone's childes
-		for( uint i=0; i<boned.childs_num; i++ )
-			queue[tail++] = boned.childs[i]->id;
-	}
-}
-
-
-/*
-=======================================================================================================================================
-model_t::Play                                                                                                                         =
-=======================================================================================================================================
-*/
-void smodel_t::Play( skeleton_anim_t* anim, ushort slot, float step, ushort play_type, float /*smooth_transition_frames*/ )
-{
-	DEBUG_ERR( !model_data );
-	DEBUG_ERR( anim->bones.size() != model_data->skeleton_data->bones.size() ); // the anim is not for this skeleton
-	DEBUG_ERR( slot >= MAX_SIMULTANEOUS_ANIMS ); // wrong slot
-
-	switch( play_type )
-	{
-		case START_IMMEDIATELY:
-			crnt_actions[slot].anim = anim;
-			crnt_actions[slot].step = step;
-			crnt_actions[slot].frame = 0.0;
-			break;
-
-		case WAIT_CRNT_TO_FINISH:
-			next_actions[slot].anim = anim;
-			next_actions[slot].step = step;
-			next_actions[slot].frame = 0.0;
-			break;
-
-		case SMOOTH_TRANSITION:
-			DEBUG_ERR( true ); // unimplemented
-			break;
-
-		default:
-			DEBUG_ERR( true );
-	}
-}
-
-
-/*
-=======================================================================================================================================
-model_t::Deform                                                                                                                       =
-=======================================================================================================================================
-*/
-void smodel_t::Deform()
-{
-	/*DEBUG_ERR( !model_data );
-
-	// deform the verts
-	for( uint i=0; i<model_data->mesh_data->vert_coords.size(); i++ ) // for all verts
-	{
-		const mesh_data_t::vertex_weight_t& vw = model_data->mesh_data->vert_weights[i];
-
-		// a small optimazation detour in case the vert has only one bone
-		if( vw.bones_num == 1 )
-		{
-			const uint& bid = vw.bone_ids[0];
-			const mat3_t& rot = bone_rotations[ bid ];
-			const vec3_t& transl = bone_translations[ bid ];
-
-			vert_coords[i] = model_data->mesh_data->vert_coords[i].Transformed( transl, rot );
-			vert_normals[i] = rot * model_data->mesh_data->vert_normals[i];
-			vert_tangents[i] = vec4_t( rot * vec3_t(model_data->mesh_data->vert_tangents[i]), model_data->mesh_data->vert_tangents[i].w );
-			continue;
-		}
-
-		// calc the matrix according the weights
-		mat3_t m3( 0.0 );
-		vec3_t v3( 0.0 );
-		// for all bones of this vert
-		for( int j=0; j< vw.bones_num; j++ )
-		{
-			uint bid = vw.bone_ids[j];
-
-			m3 += bone_rotations[ bid ] * vw.weights[j];
-			v3 += bone_translations[ bid ] * vw.weights[j];
-		}
-
-		// apply the matrix to the verts
-		vert_coords[i] = model_data->mesh_data->vert_coords[i].Transformed( v3, m3 );
-		vert_normals[i] = m3 * model_data->mesh_data->vert_normals[i];
-		vert_tangents[i] = vec4_t( m3 * vec3_t(model_data->mesh_data->vert_tangents[i]), model_data->mesh_data->vert_tangents[i].w );
-	}*/
-
-
-	// deform the heads and tails
-	if( r::dbg::show_skeletons )
-	{
-		for( uint i=0; i<model_data->skeleton_data->bones.size(); i++ )
-		{
-			const mat3_t& rot = bone_rotations[ i ];
-			const vec3_t& transl = bone_translations[ i ];
-
-			bones[i].head = model_data->skeleton_data->bones[i].head.GetTransformed( transl, rot );
-			bones[i].tail = model_data->skeleton_data->bones[i].tail.GetTransformed( transl, rot );
-		}
-	}
-}
-
-
-/*
-=======================================================================================================================================
-model_t::RenderSkeleton                                                                                                               =
-=======================================================================================================================================
-*/
-void smodel_t::RenderSkeleton()
-{
-	glPushMatrix();
-	r::MultMatrix( transformation_wspace );
-
-	//glPointSize( 4.0f );
-	//glLineWidth( 2.0f );
-
-	for( uint i=0; i<model_data->skeleton_data->bones.size(); i++ )
-	{
-		glColor3fv( &vec3_t( 1.0, 1.0, 1.0 )[0] );
-		glBegin( GL_POINTS );
-			glVertex3fv( &bones[i].head[0] );
-		glEnd();
-
-		glBegin( GL_LINES );
-			glVertex3fv( &bones[i].head[0] );
-			glColor3fv( &vec3_t( 1.0, 0.0, 0.0 )[0] );
-			glVertex3fv( &bones[i].tail[0] );
-		glEnd();
-	}
-
-	glPopMatrix();
-}
-
-
-/*
-=======================================================================================================================================
-model_t::Render                                                                                                                       =
-=======================================================================================================================================
-*/
-void smodel_t::Render()
-{
-	glPushMatrix();
-	r::MultMatrix( transformation_wspace );
-
-
-	// first the uniforms
-	glUniformMatrix3fv( material->uniform_locs.skinning_rotations, model_data->skeleton_data->bones.size(), 1, &(bone_rotations[0])[0] );
-	glUniform3fv( material->uniform_locs.skinning_translations, model_data->skeleton_data->bones.size(), &(bone_translations[0])[0] );
-
-
-	if( material->attribute_locs.position != -1 )
-	{
-		model_data->mesh_data->vbos.vert_coords.Bind();
-		glVertexAttribPointer( material->attribute_locs.position, 3, GL_FLOAT, false, 0, NULL );
-		glEnableVertexAttribArray( material->attribute_locs.position );
-	}
-
-	if( material->attribute_locs.normal != -1 )
-	{
-		model_data->mesh_data->vbos.vert_normals.Bind();
-		glVertexAttribPointer( material->attribute_locs.normal, 3, GL_FLOAT, false, 0, NULL );
-		glEnableVertexAttribArray( material->attribute_locs.normal );
-	}
-
-	if( material->attribute_locs.tex_coords != -1 )
-	{
-		model_data->mesh_data->vbos.tex_coords.Bind();
-		glVertexAttribPointer( material->attribute_locs.tex_coords, 2, GL_FLOAT, false, 0, NULL );
-		glEnableVertexAttribArray( material->attribute_locs.tex_coords );
-	}
-
-	if( material->attribute_locs.tanget != -1 )
-	{
-		model_data->mesh_data->vbos.vert_tangents.Bind();
-		glVertexAttribPointer( material->attribute_locs.tanget, 4, GL_FLOAT, false, 0, NULL );
-		glEnableVertexAttribArray( material->attribute_locs.tanget );
-	}
-
-	if( material->attribute_locs.vert_weight_bones_num != -1 )
-	{
-		model_data->mesh_data->vbos.vert_weights.Bind();
-		glEnableVertexAttribArray( material->attribute_locs.vert_weight_bones_num );
-		glVertexAttribPointer( material->attribute_locs.vert_weight_bones_num, 1, GL_FLOAT, GL_FALSE, sizeof(mesh_data_t::vertex_weight_t), BUFFER_OFFSET(0) );
-		glEnableVertexAttribArray( material->attribute_locs.vert_weight_bone_ids );
-		glVertexAttribPointer( material->attribute_locs.vert_weight_bone_ids, 4, GL_FLOAT, GL_FALSE, sizeof(mesh_data_t::vertex_weight_t), BUFFER_OFFSET(4) );
-		glEnableVertexAttribArray( material->attribute_locs.vert_weight_weights );
-		glVertexAttribPointer( material->attribute_locs.vert_weight_weights, 4, GL_FLOAT, GL_FALSE, sizeof(mesh_data_t::vertex_weight_t), BUFFER_OFFSET(20) );
-	}
-
-	model_data->mesh_data->vbos.vert_indeces.Bind();
-
-	glDrawElements( GL_TRIANGLES, model_data->mesh_data->vert_indeces.size(), GL_UNSIGNED_SHORT, 0 );
-
-
-	if( material->attribute_locs.position != -1 ) glDisableVertexAttribArray( material->attribute_locs.position );
-	if( material->attribute_locs.normal != -1 ) glDisableVertexAttribArray( material->attribute_locs.normal );
-	if( material->attribute_locs.tex_coords != -1 ) glDisableVertexAttribArray( material->attribute_locs.tex_coords );
-	if( material->attribute_locs.tanget != -1 ) glDisableVertexAttribArray( material->attribute_locs.tanget );
-	if( material->attribute_locs.vert_weight_bones_num != -1 )
-	{
-		glDisableVertexAttribArray( material->attribute_locs.vert_weight_bones_num );
-		glDisableVertexAttribArray( material->attribute_locs.vert_weight_bone_ids );
-		glDisableVertexAttribArray( material->attribute_locs.vert_weight_weights );
-	}
-
-	vbo_t::UnbindAllTargets();
-	glPopMatrix();
-}
-
-
-/*
-=======================================================================================================================================
-model_t::RenderDepth                                                                                                                  =
-=======================================================================================================================================
-*/
-void smodel_t::RenderDepth()
-{
-	glPushMatrix();
-	r::MultMatrix( transformation_wspace );
-
-
-	glUniformMatrix3fv( r::is::shadows::shdr_depth_hw_skinning->GetUniformLocation(0), model_data->skeleton_data->bones.size(), 1, &(bone_rotations[0])[0] );
-	glUniform3fv( r::is::shadows::shdr_depth_hw_skinning->GetUniformLocation(1), model_data->skeleton_data->bones.size(), &(bone_translations[0])[0] );
-
-
-	model_data->mesh_data->vbos.vert_coords.Bind();
-	glVertexPointer( 3, GL_FLOAT, 0, NULL );
-	glEnableClientState( GL_VERTEX_ARRAY );
-
-	model_data->mesh_data->vbos.vert_weights.Bind();
-	glEnableVertexAttribArray( r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(0) );
-	glVertexAttribPointer( r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(0), 1, GL_FLOAT, GL_FALSE, sizeof(mesh_data_t::vertex_weight_t), BUFFER_OFFSET(0) );
-	glEnableVertexAttribArray(r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(1) );
-	glVertexAttribPointer( r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(1), 4, GL_FLOAT, GL_FALSE, sizeof(mesh_data_t::vertex_weight_t), BUFFER_OFFSET(4) );
-	glEnableVertexAttribArray( r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(2) );
-	glVertexAttribPointer( r::is::shadows::shdr_depth_hw_skinning->GetAttributeLocation(2), 4, GL_FLOAT, GL_FALSE, sizeof(mesh_data_t::vertex_weight_t), BUFFER_OFFSET(20) );
-
-	model_data->mesh_data->vbos.vert_indeces.Bind();
-
-
-	glDrawElements( GL_TRIANGLES, model_data->mesh_data->vert_indeces.size(), GL_UNSIGNED_SHORT, 0 );
-
-	glDisableClientState( GL_VERTEX_ARRAY );
-
-	vbo_t::UnbindAllTargets();
-
-	glPopMatrix();
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

+ 0 - 190
src/uncategorized/smodel.h

@@ -1,190 +0,0 @@
-/**
-How tha animation works:
-
-First we interpolate using animation data. This produces a few poses that they are the transformations of a bone in bone space.
-Secondly we update the bones transformations by using the poses from the above step and add their father's transformations also. This
-produces transformations (rots and translations in manner of 1 mat3 and 1 vec3) of a bone in armature space. Thirdly we use the
-transformations to deform the mesh and the skeleton (if nessesary). This produces a set of vertices and a set of heads and tails. The
-last step is to use the verts, heads and tails to render the model. END
-
-Interpolate -> poses[] -> UpdateTransformations -> rots[] & transls[] -> Deform -> verts[] -> Render
-*/
-
-#ifndef _SMODEL_H_
-#define _SMODEL_H_
-
-#include "common.h"
-#include "primitives.h"
-#include "mesh.h"
-#include "gmath.h"
-
-
-/*
-=======================================================================================================================================
-model's data                                                                                                                          =
-=======================================================================================================================================
-*/
-
-/// bone_data_t
-class bone_data_t: public nc_t
-{
-	public:
-		ushort id; ///< pos inside the skeleton_t::bones vector
-		bone_data_t* parent;
-		static const uint MAX_CHILDS_PER_BONE = 4;
-		bone_data_t* childs[MAX_CHILDS_PER_BONE];
-		ushort childs_num;
-
-		vec3_t head, tail;
-
-		/* the rotation and translation that transform the bone from bone space to armature space. Meaning that if
-		MA = TRS(rot_skel_space, tsl_skel_space) then head = MA * vec3_t(0.0, length, 0.0) and tail = MA * vec3_t( 0.0, 0.0, 0.0 )
-		We also keep the inverted ones for fast calculations. rot_skel_space_inv = MA.Inverted().GetRotationPart() and NOT
-		rot_skel_space_inv = rot_skel_space.Inverted()*/
-		mat3_t rot_skel_space;
-		vec3_t tsl_skel_space;
-		mat3_t rot_skel_space_inv;
-		vec3_t tsl_skel_space_inv;
-
-		 bone_data_t() {}
-		~bone_data_t() {}
-};
-
-
-/// skeleton_data_t
-class skeleton_data_t
-{
-	public:
-		vec_t<bone_data_t> bones;
-
-		 skeleton_data_t() {}
-		~skeleton_data_t() { Unload(); }
-		bool Load( const char* filename );
-		void Unload(){ bones.clear(); };
-};
-
-
-/// model_data_t
-class model_data_t: public resource_t
-{
-	public:
-		mesh_data_t* mesh_data;
-		skeleton_data_t* skeleton_data; ///< Its a pointer in case I want to make skeleton_data_t an resource_t class
-
-		model_data_t(): mesh_data(NULL), skeleton_data(NULL) {}
-		~model_data_t() {}
-		bool Load( const char* filename );
-		void Unload() { /* ToDo: add code */ }
-};
-
-
-/*
-=======================================================================================================================================
-model animation                                                                                                                       =
-=======================================================================================================================================
-*/
-
-/// bone_pose_t
-class bone_pose_t
-{
-	public:
-		quat_t rotation;
-		vec3_t translation;
-};
-
-
-/// bone_anim_t
-class bone_anim_t
-{
-	public:
-		vec_t<bone_pose_t> keyframes; ///< The poses for every keyframe. Its empty if the bone doesnt have any animation
-
-		bone_anim_t() {}
-		~bone_anim_t() { if(keyframes.size()) keyframes.clear();}
-};
-
-
-/// skeleton_anim_t
-class skeleton_anim_t: public resource_t
-{
-	public:
-		vec_t<uint> keyframes;
-		uint frames_num;
-
-		vec_t<bone_anim_t> bones;
-
-		skeleton_anim_t() {};
-		~skeleton_anim_t() { Unload(); }
-		bool Load( const char* filename );
-		void Unload() { keyframes.clear(); bones.clear(); }
-};
-
-
-/*
-=======================================================================================================================================
-model                                                                                                                                 =
-=======================================================================================================================================
-*/
-
-class smodel_data_user_class_t: public data_user_class_t {}; // for ambiguity reasons
-
-// model_t
-/// The model_t class contains runtime data and the control functions for the model
-class smodel_t: public object_t, public smodel_data_user_class_t
-{
-	protected:
-		void Interpolate( skeleton_anim_t* animation, float frame );
-		void UpdateBoneTransforms();
-
-	public:
-		class bone_t
-		{
-			public:
-				vec3_t head, tail;
-		};
-
-		vec_t<mat3_t> bone_rotations;
-		vec_t<vec3_t> bone_translations;
-
-		model_data_t* model_data;
-		material_t* material;
-		vec_t<bone_t> bones;
-		vec_t<vec3_t> vert_coords;
-		vec_t<vec3_t> vert_normals;
-		vec_t<vec4_t> vert_tangents;
-
-		// for actions
-		class action_t
-		{
-			public:
-				skeleton_anim_t* anim;
-				float step;
-				float frame;
-		};
-		static const ushort MAX_SIMULTANEOUS_ANIMS = 2;
-		action_t crnt_actions[MAX_SIMULTANEOUS_ANIMS];
-		action_t next_actions[MAX_SIMULTANEOUS_ANIMS];
-
-		enum play_type_e
-		{
-			START_IMMEDIATELY,
-			WAIT_CRNT_TO_FINISH,
-			SMOOTH_TRANSITION
-		};
-
-		// funcs
-		 smodel_t(): object_t(MODEL), model_data(NULL) {}
-		~smodel_t() { bones.clear(); vert_coords.clear(); vert_normals.clear(); }
-
-		void Init( model_data_t* model_data_ ); ///< Initializes the model with runtime data @param model_data_ is the pointer to a model_data_t asset
-		bone_t* GetBone( const string& name );
-
-		void Play( skeleton_anim_t* animation, ushort slot, float step, ushort play_type, float smooth_transition_frames=0.0 );
-		void Interpolate();
-		void Deform();
-		void Render();
-		void RenderDepth();
-		void RenderSkeleton();
-};
-
-#endif

+ 0 - 33
src/uncategorized/spatial.cpp

@@ -1,33 +0,0 @@
-#include "spatial.h"
-
-
-
-/*
-=======================================================================================================================================
-UpdateBVolums                                                                                                                         =
-=======================================================================================================================================
-*/
-void spatial_t::UpdateBVolums()
-{
-	if( local_bvolume == NULL ) return;
-
-	DEBUG_ERR( local_bvolume->type!=bvolume_t::BSPHERE || local_bvolume->type!=bvolume_t::AABB || local_bvolume->type!=bvolume_t::OBB );
-
-	switch( local_bvolume->type )
-	{
-		case bvolume_t::BSPHERE:
-			(*(bsphere_t*)world_bvolume) = (*(bsphere_t*)local_bvolume).Transformed( translation_wspace, rotation_wspace, scale_wspace );
-			break;
-
-		case bvolume_t::AABB:
-			(*(aabb_t*)world_bvolume) = (*(aabb_t*)local_bvolume).Transformed( translation_wspace, rotation_wspace, scale_wspace );
-			break;
-
-		case bvolume_t::OBB:
-			(*(obb_t*)world_bvolume) = (*(obb_t*)local_bvolume).Transformed( translation_wspace, rotation_wspace, scale_wspace );
-			break;
-
-		default:
-			FATAL( "What the fuck" );
-	}
-}

+ 0 - 24
src/uncategorized/spatial.h

@@ -1,24 +0,0 @@
-#ifndef _SPATIAL_H_
-#define _SPATIAL_H_
-
-#include "common.h"
-#include "collision.h"
-#include "engine_class.h"
-#include "object.h"
-
-class spatial_data_user_class_t: public data_user_class_t {}; // for ambiguity reasons
-
-class spatial_t: public object_t, public spatial_data_user_class_t
-{
-	public:
-
-		bvolume_t* local_bvolume;
-		bvolume_t* world_bvolume;
-
-		spatial_t(): object_t(LIGHT) {}; // ToDo: correct this
-		~spatial_t() {};
-		void UpdateBVolums();
-};
-
-
-#endif

+ 0 - 0
src/uncategorized/common.cpp → src/utility/common.cpp


+ 1 - 1
src/uncategorized/common.h → src/utility/common.h

@@ -74,7 +74,7 @@ extern string GetFunctionFromPrettyFunction( const char* pretty_function );
 #endif
 
 #define GENERAL_ERR( x, y, col ) \
-	cerr << col << "**" << x << "** " << __FILENAME__ << "(" << __LINE__ << ") " << __G_FUNCTION__ << ": " << y << COL_DEFAULT << endl;
+	cerr << col << "**" << x << "** (" << __FILENAME__ << ":" << __LINE__ << " " << __G_FUNCTION__ << "): " << y << COL_DEFAULT << endl;
 
 /// in ERROR you can write something like this: ERROR( "tralala" << 10 << ' ' )
 #define ERROR( x ) GENERAL_ERR( "ERROR", x, COL_ERROR )