Преглед изворни кода

Bug fixing the scenegraph and the renderer

Panagiotis Christopoulos Charitos пре 16 година
родитељ
комит
8c44de1b96

+ 21 - 18
src/main.cpp

@@ -14,20 +14,23 @@
 #include "primitives.h"
 #include "texture.h"
 #include "mesh.h"
-#include "lights.h"
+#include "light.h"
 #include "collision.h"
-#include "smodel.h"
-#include "spatial.h"
 #include "material.h"
 #include "resource.h"
 #include "scene.h"
 #include "scanner.h"
 #include "skybox.h"
 #include "map.h"
-#include "model.h"
-#include "renderer.hpp"
+#include "mesh_node.h"
+#include "skel_model_node.h"
 #include "mesh_node.h"
 #include "skel_anim.h"
+#include "skel_controller.h"
+#include "skel_anim_controller.h"
+#include "skel_node.h"
+#include "light_mtl.h"
+
 
 // map (hard coded)
 camera_t* main_cam;
@@ -58,20 +61,20 @@ void Init()
 
 	// camera
 	main_cam = new camera_t( r::aspect_ratio*ToRad(60.0), ToRad(60.0), 0.5, 100.0 );
-	main_cam.MoveLocalY( 3.0 );
-	main_cam.MoveLocalZ( 5.7 );
-	main_cam.MoveLocalX( -0.3 );
+	main_cam->MoveLocalY( 3.0 );
+	main_cam->MoveLocalZ( 5.7 );
+	main_cam->MoveLocalX( -0.3 );
 
 	// lights
 	point_lights[0] = new point_light_t();
 	point_lights[0]->light_mtl = rsrc::light_mtls.Load( "maps/temple/light0.lmtl" );
-	point_lights[0]->SetLocatTransformation( vec3_t( -1.0, 2.4, 1.0 ), mat3_t::GetIdentity(), 1.0 );
+	point_lights[0]->SetLocalTransformation( vec3_t( -1.0, 2.4, 1.0 ), mat3_t::GetIdentity(), 1.0 );
 	point_lights[0]->radius = 2.0;
 
 	// horse
 	horse = new mesh_node_t();
 	horse->Init( "meshes/horse/horse.mesh" );
-	horst->SetLocalTransformation( vec3_t( -2, 0, 1 ), mat3_t( euler_t(-m::PI/2, 0.0, 0.0) ), 0.5 );
+	horse->SetLocalTransformation( vec3_t( -2, 0, 1 ), mat3_t( euler_t(-m::PI/2, 0.0, 0.0) ), 0.5 );
 	
 	// sarge
 	sarge = new mesh_node_t();
@@ -120,13 +123,13 @@ int main( int /*argc*/, char* /*argv*/[] )
 		float scale = 0.01;
 
 		// move the camera
-		static node_t* mover = &main_cam;
+		static node_t* mover = main_cam;
 
-		if( i::keys[ SDLK_1 ] ) mover = &main_cam;
-		if( i::keys[ SDLK_2 ] ) mover = &point_lights[0];
-		if( i::keys[ SDLK_3 ] ) mover = &projlights[0];
-		if( i::keys[ SDLK_4 ] ) mover = &point_lights[1];
-		if( i::keys[ SDLK_5 ] ) mover = &projlights[1];
+		if( i::keys[ SDLK_1 ] ) mover = main_cam;
+		if( i::keys[ SDLK_2 ] ) mover = point_lights[0];
+		if( i::keys[ SDLK_3 ] ) mover = projlights[0];
+		if( i::keys[ SDLK_4 ] ) mover = point_lights[1];
+		if( i::keys[ SDLK_5 ] ) mover = projlights[1];
 		if( i::keys[ SDLK_m ] == 1 ) i::warp_mouse = !i::warp_mouse;
 
 		if( i::keys[SDLK_a] ) mover->MoveLocalX( -dist );
@@ -153,7 +156,7 @@ int main( int /*argc*/, char* /*argv*/[] )
 		if( i::keys[SDLK_PAGEUP] ) mover->scale_lspace += scale ;
 		if( i::keys[SDLK_PAGEDOWN] ) mover->scale_lspace -= scale ;
 
-		if( i::keys[SDLK_k] ) main_cam.LookAtPoint( point_lights[0].translation_wspace );
+		if( i::keys[SDLK_k] ) main_cam->LookAtPoint( point_lights[0]->translation_wspace );
 
 		mover->rotation_lspace.Reorthogonalize();
 
@@ -161,7 +164,7 @@ int main( int /*argc*/, char* /*argv*/[] )
 		scene::UpdateAllControllers();
 		scene::UpdateAllWorldStuff();
 
-		r::Render( main_cam );
+		r::Render( *main_cam );
 
 		//map.octree.root->bounding_box.Render();
 

+ 4 - 1
src/renderer/r_bs.cpp

@@ -10,6 +10,9 @@
 #include "r_private.h"
 #include "resource.h"
 #include "fbo.h"
+#include "mesh_node.h"
+#include "material.h"
+
 
 namespace r {
 namespace bs {
@@ -120,7 +123,7 @@ void RunStage( const camera_t& cam )
 			mesh_node->material->Setup();
 			mesh_node->Render();
 		}
-		else if( mesh->material->refracts )
+		else if( mesh_node->material->refracts )
 		{
 			// write to the rFbo
 			r_fbo.Bind();

+ 9 - 13
src/renderer/r_dbg.cpp

@@ -4,6 +4,8 @@
 #include "scene.h"
 #include "texture.h"
 #include "fbo.h"
+#include "node.h"
+#include "skel_node.h"
 
 
 namespace r {
@@ -78,27 +80,21 @@ void RunStage( const camera_t& cam )
 	glDisable( GL_BLEND );
 
 	//r::RenderGrid();
-	for( uint i=0; i<scene::objects.size(); i++ )
+	for( uint i=0; i<scene::nodes.size(); i++ )
 	{
 		if
 		(
-			(scene::objects[i]->type == object_t::LIGHT && show_lights) ||
-			(scene::objects[i]->type == object_t::CAMERA && show_cameras)
+			(scene::nodes[i]->type == node_t::NT_LIGHT && show_lights) ||
+			(scene::nodes[i]->type == node_t::NT_CAMERA && show_cameras)
 		)
 		{
-			scene::objects[i]->Render();
+			scene::nodes[i]->Render();
 		}
-		else if( scene::objects[i]->type == object_t::MESH && show_vnormals )
+		else if( scene::nodes[i]->type == node_t::NT_SKELETON && show_skeletons )
 		{
-			mesh_node_t* mesh = static_cast<mesh_node_t*>( scene::objects[i] );
-			mesh->RenderNormals();
-			mesh->RenderTangents();
-		}
-		else if( scene::objects[i]->type == object_t::MODEL && show_skeletons )
-		{
-			smodel_t* model = static_cast<smodel_t*>( scene::objects[i] );
+			skel_node_t* skel_node = static_cast<skel_node_t*>( scene::nodes[i] );
 			glDisable( GL_DEPTH_TEST );
-			model->RenderSkeleton();
+			skel_node->Render();
 			glEnable( GL_DEPTH_TEST );
 		}
 	}

+ 2 - 2
src/renderer/r_is.cpp

@@ -6,7 +6,7 @@ The file contains functions and vars used for the deferred shading illumination
 #include "camera.h"
 #include "scene.h"
 #include "mesh.h"
-#include "lights.h"
+#include "light.h"
 #include "resource.h"
 #include "scene.h"
 #include "r_private.h"
@@ -497,7 +497,7 @@ void RunStage( const camera_t& cam )
 	for( uint i=0; i<scene::lights.size(); i++ )
 	{
 		const light_t& light = *scene::lights[i];
-		switch( light.GetType() )
+		switch( light.type )
 		{
 			case light_t::LT_POINT:
 			{

+ 1 - 0
src/renderer/r_is_shadows.cpp

@@ -5,6 +5,7 @@
 #include "r_private.h"
 #include "fbo.h"
 #include "material.h"
+#include "mesh_node.h"
 
 namespace r {
 namespace is {

+ 2 - 0
src/renderer/r_ms.cpp

@@ -8,6 +8,8 @@
 #include "mesh.h"
 #include "r_private.h"
 #include "fbo.h"
+#include "material.h"
+#include "mesh_node.h"
 
 
 namespace r {

+ 1 - 0
src/renderer/r_pps_ssao.cpp

@@ -8,6 +8,7 @@ The file contains functions and vars used for the deferred shading/post-processi
 #include "scene.h"
 #include "r_private.h"
 #include "fbo.h"
+#include "camera.h"
 
 namespace r {
 namespace pps {

+ 1 - 0
src/renderer/renderer.cpp

@@ -5,6 +5,7 @@
 #include "texture.h"
 #include "scene.h"
 #include "r_private.h"
+#include "camera.h"
 
 namespace r {
 

+ 1 - 0
src/renderer/renderer.h

@@ -7,6 +7,7 @@
 #include <GL/glu.h>
 #include "gmath.h"
 #include "shader_prog.h"
+#include "camera.h"
 
 
 

Разлика између датотеке није приказан због своје велике величине
+ 2 - 1
src/renderer2/r_is.cpp


+ 4 - 2
src/renderer2/r_ms.cpp

@@ -1,3 +1,4 @@
+/*
 #include "renderer.hpp"
 #include "scene.h"
 
@@ -59,15 +60,16 @@ void renderer_t::material_stage_t::Run() const
 
 
 	// render the meshes
-	/*for( uint i=0; i<scene::meshes.size(); i++ )
+	for( uint i=0; i<scene::meshes.size(); i++ )
 		Render<mesh_t, false>( scene::meshes[i] );
 
 	// render the smodels
 	for( uint i=0; i<scene::smodels.size(); i++ )
-		Render<smodel_t, false>( scene::smodels[i] );*/
+		Render<smodel_t, false>( scene::smodels[i] );
 
 	glPolygonMode( GL_FRONT, GL_FILL ); // the rendering above fucks the polygon mode
 
 
 	fbo.Unbind();
 }
+*/

+ 2 - 0
src/renderer2/renderer.cpp

@@ -1,3 +1,4 @@
+/*
 #include "renderer.hpp"
 
 
@@ -48,3 +49,4 @@ void renderer_t::DrawQuad()
 	glDrawArrays( GL_QUADS, 0, 4 );
 	glDisableClientState( GL_VERTEX_ARRAY );
 }
+*/

+ 2 - 0
src/renderer2/renderer.hpp

@@ -1,3 +1,4 @@
+/*
 #ifndef _RENDERER_HPP_
 #define _RENDERER_HPP_
 
@@ -255,3 +256,4 @@ struct renderer_t
 };
 
 #endif
+*/

+ 2 - 2
src/resources/light_mtl.cpp

@@ -18,12 +18,12 @@ scanner_t scanner;
 		token = &scanner.GetNextToken();
 
 		//** DIFFUSE_COL **
-		if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "DIFFUSE_COL" ) )
+		if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "DIFFUSE_COLOR" ) )
 		{
 			ParseArrOfNumbers<float>( scanner, true, true, 3, &diffuse_col[0] );
 		}
 		//** SPECULAR_COL **
-		else if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "SPECULAR_COL" ) )
+		else if( token->code == scanner_t::TC_IDENTIFIER && !strcmp( token->value.string, "SPECULAR_COLOR" ) )
 		{
 			ParseArrOfNumbers<float>( scanner, true, true, 3, &specular_col[0] );
 		}

+ 2 - 2
src/scene/scene.cpp

@@ -147,9 +147,9 @@ void UpdateAllWorldStuff()
 
 
 //=====================================================================================================================================
-// UpdateAllCotrollers                                                                                                                =
+// UpdateAllControllers                                                                                                               =
 //=====================================================================================================================================
-void UpdateAllCotrollers()
+void UpdateAllControllers()
 {
 	/*for( container_node_t::iterator it=nodes.begin(); it!=nodes.end(); it++ )
 	{

+ 1 - 1
src/scene/scene.h

@@ -26,7 +26,7 @@ extern void RegisterController( controller_t* controller );
 extern void UnregisterController( controller_t* controller );
 
 extern void UpdateAllWorldStuff();
-extern void UpdateAllCotrollers();
+extern void UpdateAllControllers();
 
 
 // container_t

Неке датотеке нису приказане због велике количине промена