Exemple #1
0
SCENEGRAPHPLUGINEXP void dllLoadScene( const char* sceneFile )
{
    GameLog::logMessage("Setting Horde3D Paths");

    XMLResults results;
    XMLNode scene = XMLNode::parseFile( sceneFile, "Configuration", &results);
    XMLNode& engineSettings(scene.getChildNode("EngineConfig"));
    if ( !engineSettings.isEmpty() )
    {
        bool loadTextures =
            _stricmp(engineSettings.getAttribute("loadTextures", "true"), "true") == 0 ||
            _stricmp(engineSettings.getAttribute("loadTextures", "1"), "1") == 0;
        GameLog::logMessage("LoadTextures: %s", loadTextures ? "enabled" : "disabled");
        h3dSetOption( H3DOptions::LoadTextures, loadTextures ? 1.0f : 0.0f );
        int shadowMapSize = atoi(engineSettings.getAttribute("shadowMapSize", "1024"));
        GameLog::logMessage("ShadowMapSize: %d", shadowMapSize);
        h3dSetOption( H3DOptions::ShadowMapSize, float( shadowMapSize) );
        int anisotropyFactor = atoi(engineSettings.getAttribute("anisotropyFactor", "1"));
        GameLog::logMessage("Anisotropy: %d", anisotropyFactor);
        h3dSetOption( H3DOptions::MaxAnisotropy, float( anisotropyFactor ) );
        bool texCompression =
            _stricmp(engineSettings.getAttribute("texCompression", "true"), "true") == 0 ||
            _stricmp(engineSettings.getAttribute("texCompression", "1"), "1") == 0;
        GameLog::logMessage("TexCompression: %s", texCompression ? "enabled" : "disabled");
        h3dSetOption( H3DOptions::TexCompression, texCompression );
        int maxNumMessages = atoi(engineSettings.getAttribute("maxNumMessages", "1024"));
        h3dSetOption( H3DOptions::MaxNumMessages, float( maxNumMessages ) );
    }

    // Loading scene graph
    XMLNode& sceneGraph(scene.getChildNode("SceneGraph"));
    if ( sceneGraph.isEmpty() ) GameLog::errorMessage("No Scene Graph Node found!");
    else
    {
        GameLog::logMessage("Loading SceneGraph %s", sceneGraph.getAttribute("path"));
        // Environment
        H3DRes sceneGraphID = h3dAddResource( H3DResTypes::SceneGraph, sceneGraph.getAttribute("path"), 0 );
        GameLog::logMessage("Loading Resources...");
        // Load resources
        h3dutLoadResourcesFromDisk( "." );
        GameLog::logMessage("Adding scene graph to root node");
        // Add scene nodes
        H3DNode newSceneID = h3dAddNodes( H3DRootNode, sceneGraphID);
        SceneGraphManager::instance()->addNewHordeNode( newSceneID );
    }
    // Use the specified render cam
    if (scene.getChildNode("ActiveCamera").getAttribute("name") && h3dFindNodes( H3DRootNode, scene.getChildNode("ActiveCamera").getAttribute("name"), H3DNodeTypes::Camera ) > 0)
        SceneGraphManager::instance()->setActiveCam( h3dGetNodeFindResult(0) );

}
Exemple #2
0
void DemoApp::keyHandler()
{		
	unsigned int ball = GameEngine::entityWorldID("Ball");
	if( m_keys[118] )  // F7
	{
		h3dSetOption( H3DOptions::DebugViewMode, h3dGetOption(H3DOptions::DebugViewMode) != 0 ? 0 : 1 );	
		m_keys[118] = 0;
	}
	if( m_keys['W'] ) 
		GameEngine::translateEntityLocal(m_camID, 0, 0, -1);
	if( m_keys['S'] ) 
		GameEngine::translateEntityLocal(m_camID, 0, 0, 1);
	if( m_keys['A'] )
		GameEngine::translateEntityLocal(m_camID, -1, 0, 0);
	if( m_keys['D'] )
		GameEngine::translateEntityLocal(m_camID, 1, 0, 0);
	if( m_keys['I'] )
		GameEngine::translateEntityLocal( ball, 0, 0, 1 );
	if( m_keys['K'] )
		GameEngine::translateEntityLocal( ball, 0, 0, -1 );
	if( m_keys['J'] )
		GameEngine::translateEntityLocal( ball, -1, 0, 0 );
	if( m_keys['L'] )
		GameEngine::translateEntityLocal( ball, 1, 0, 0 );

	m_running = m_keys[27] == 0;
}
Exemple #3
0
void DemoApp::keyHandler()
{
	unsigned int ball = GameEngine::entityWorldID("Ball");
	float fps = GameEngine::FPS();

	if( m_keys[GLFW_KEY_F7] )
	{
		h3dSetOption( H3DOptions::DebugViewMode, h3dGetOption(H3DOptions::DebugViewMode) != 0 ? 0 : 1.0f );
		m_keys[GLFW_KEY_F7] = 0; // reset key state so we only change it once
	}
	if( m_keys[GLFW_KEY_F6] )
	{
		GameEngine::setPhysicsShapeRenderingEnabled(!GameEngine::physicsShapeRenderingEnabled());
		m_keys[GLFW_KEY_F6] = 0; // reset key state so we only change it once
	}
	if( m_keys['R'])
	{
		GameEngine::resetPhysics();
		m_keys['R'] = 0; // reset key state so we only change it once
	}

	if( m_keys['W'] )
		GameEngine::translateEntityLocal(m_camID, 0, 0, -10 / fps);
	if( m_keys['S'] )
		GameEngine::translateEntityLocal(m_camID, 0, 0, 10 / fps);
	if( m_keys['A'] )
		GameEngine::translateEntityLocal(m_camID, -10 / fps, 0, 0);
	if( m_keys['D'] )
		GameEngine::translateEntityLocal(m_camID, 10 / fps, 0, 0);

	if( m_keys['I'] )
		GameEngine::translateEntityGlobal( ball, 0, 0, -10 / fps );
	if( m_keys['K'] )
		GameEngine::translateEntityGlobal( ball, 0, 0, 10 / fps );
	if( m_keys['J'] )
		GameEngine::translateEntityGlobal( ball, -10 / fps, 0, 0 );
	if( m_keys['L'] )
		GameEngine::translateEntityGlobal( ball, 10 / fps, 0, 0 );
	if( m_keys['U'] )
		GameEngine::translateEntityGlobal( ball, 0, 10 / fps, 0 );
	if( m_keys['O'] )
		GameEngine::translateEntityGlobal( ball, 0, -10 / fps, 0 );

	m_running = m_keys[27] == 0;
}
Exemple #4
0
ANIMATIONSPLUGINEXP void dllLoadScene( const char* sceneFile )
{
	XMLResults results;
	XMLNode scene = XMLNode::parseFile( sceneFile, "Configuration", &results);

	XMLNode& pathes(scene.getChildNode("EnginePath"));
	if (!pathes.isEmpty())
	{
		GameLog::logMessage("-  AnimationPath = %s", pathes.getAttribute("AnimationPath", "models"));
		h3dutSetResourcePath(H3DResTypes::Animation, pathes.getAttribute("animationpath", "animations"));
	}

	XMLNode& engineSettings(scene.getChildNode("EngineConfig"));
	if ( !engineSettings.isEmpty() )
	{				
		bool fastAnim = 
			_stricmp(engineSettings.getAttribute("fastAnimation", "false"), "true") == 0 ||
			_stricmp(engineSettings.getAttribute("fastAnimation", "0"), "1") == 0;
		GameLog::logMessage("FastAnimation: %s", fastAnim ? "enabled" : "disabled");
		h3dSetOption( H3DOptions::FastAnimation, fastAnim ? 1.0f : 0.0f );
	}

}
Exemple #5
0
int main( int argc, char** argv )
{
	// Initialize GLFW
	glfwInit();
	if( !setupWindow( appWidth, appHeight, fullScreen ) ) return -1;
	
	// Initalize application and engine
	app = new TentacleApplication( generatePath( argv[0], "../../../Data/HordeContent" ) );
	if ( !app->init() )
	{
		// Fake message box
		glfwCloseWindow();
		glfwOpenWindow( 800, 16, 8, 8, 8, 8, 24, 8, GLFW_WINDOW );
		glfwSetWindowTitle( "Unable to initalize engine - Make sure you have an OpenGL 2.0 compatible graphics card" );
		glfwSleep( 5 );
		
		std::cout << "Unable to initalize engine" << std::endl;
		std::cout << "Make sure you have an OpenGL 2.0 compatible graphics card";
		glfwTerminate();
		h3dSetOption(H3DOptions::MaxLogLevel, 0.0);
		return -1;

	}
	app->resize( appWidth, appHeight );

	glfwDisable( GLFW_MOUSE_CURSOR );

	

	int frames = 0;
	float fps = 30.0f;
	t0 = glfwGetTime();
	running = true;

	// Game loop
	while( running )
	{
		// Calc FPS
		++frames;
		if( frames >= 3 )
		{
			double t = glfwGetTime();
			fps = frames / (float)(t - t0);
			frames = 0;
			t0 = t;
		}

		// Render
		app->mainLoop( fps );
		glfwSwapBuffers();
	}

	glfwEnable( GLFW_MOUSE_CURSOR );

	// Quit
	app->release();
	delete app;
	glfwTerminate();

	return 0;
}
Exemple #6
0
bool Application::init()
{	
	// Initialize engine and open default sound device
	if( !h3dInit() || !h3dOpenDevice( 0x0 ) )
	{	
		h3dutDumpMessages();
		return false;
	}

	// Set options
	h3dSetOption( H3DOptions::LoadTextures, 1 );
	h3dSetOption( H3DOptions::TexCompression, 0 );
	h3dSetOption( H3DOptions::FastAnimation, 0 );
	h3dSetOption( H3DOptions::MaxAnisotropy, 4 );
	h3dSetOption( H3DOptions::ShadowMapSize, 2048 );

	// Add resources
	// Pipelines
	_hdrPipeRes = h3dAddResource( H3DResTypes::Pipeline, "pipelines/hdr.pipeline.xml", 0 );
	_forwardPipeRes = h3dAddResource( H3DResTypes::Pipeline, "pipelines/forward.pipeline.xml", 0 );
	// Overlays
	_fontMatRes = h3dAddResource( H3DResTypes::Material, "overlays/font.material.xml", 0 );
	_panelMatRes = h3dAddResource( H3DResTypes::Material, "overlays/panel.material.xml", 0 );
	_logoMatRes = h3dAddResource( H3DResTypes::Material, "overlays/logo.material.xml", 0 );
	// Environment
	H3DRes floorRes = h3dAddResource( H3DResTypes::SceneGraph, "models/tiles/tiles.scene.xml", 0 );
	// Knight
	H3DRes speakerRes = h3dAddResource( H3DResTypes::SceneGraph, "models/speaker/speaker.scene.xml", 0 );
	// Music
	_soundRes = h3dAddResource( RST_SoundResource, "sounds/stringed_disco.ogg", 0 );

	// Load resources
	h3dutLoadResourcesFromDisk( _contentDir.c_str() );

	// Add scene nodes
	// Add camera
	_cam = h3dAddCameraNode( H3DRootNode, "Camera", _hdrPipeRes );
	//h3dSetNodeParamI( _cam, CameraNodeParams::OcclusionCulling, 1 );
	// Add listener to the camera
	H3DNode listener = h3dAddListenerNode( _cam, "Listener" );
	h3dSetActiveListener( listener );
	// Add floor
	H3DNode floor = h3dAddNodes( H3DRootNode, floorRes );
	h3dSetNodeTransform( floor, 0, -0.125, 0, 0, 0, 0, 1, 1, 1 );
	// Add the speakers
	H3DNode speaker1 = h3dAddNodes( H3DRootNode, speakerRes );
	h3dSetNodeTransform( speaker1, -2, 0, -2, 0, 215.0f, 0, 1, 1, 1 );
	H3DNode speaker2 = h3dAddNodes( H3DRootNode, speakerRes );
	h3dSetNodeTransform( speaker2, 2, 0, -2, 0, 145.0f, 0, 1, 1, 1 );
	// Add music to the speakers
	_sound1 = h3dAddSoundNode( speaker1, "Sound1", _soundRes );
	_sound2 = h3dAddSoundNode( speaker2, "Sound2", _soundRes );
	// Add light source
	_light = h3dAddLightNode( H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP" );
	h3dSetNodeTransform( _light, 0, 7, 0, -90, 0, 0, 1, 1, 1 );
	h3dSetNodeParamF( _light, H3DLight::RadiusF, 0, 30 );
	h3dSetNodeParamF( _light, H3DLight::FovF, 0, 90 );
	h3dSetNodeParamI( _light, H3DLight::ShadowMapCountI, 1 );
	h3dSetNodeParamF( _light, H3DLight::ShadowMapBiasF, 0, 0.01f );

	// Set the distance model
	h3dSetDistanceModel( _distanceModel );
	// Set the timer so the light immediately gets a random color
	_lightTimer = 1.0f;

	// Customize post processing effects
	H3DRes matRes = h3dFindResource( H3DResTypes::Material, "pipelines/postHDR.material.xml" );
	// hdrParams: exposure, brightpass threshold, brightpass offset (see shader for description)
	h3dSetMaterialUniform( matRes, "hdrParams", 2.0f, 0.6f, 0.08f, 0 );

	// Play the music
	h3dPlaySound( _sound1 );
	h3dPlaySound( _sound2 );

	return true;
}
Exemple #7
0
void Application::keyPressEvent( int key )
{
	switch( key )
	{
	case '1':
		if( h3dIsSoundPlaying( _sound1 ) )
		{
			h3dPauseSound( _sound1 );
			h3dPauseSound( _sound2 );
		}
		else
		{
			h3dPlaySound( _sound1 );
			h3dPlaySound( _sound2 );
		}

		break;
	case '2':
		h3dRewindSound( _sound1 );
		h3dRewindSound( _sound2 );

		break;
	case '7':
		_soundLoop = !_soundLoop;

		h3dSetNodeParamI( _sound1, H3DSoundNodeParams::Loop, _soundLoop ? 1 : 0 );
		h3dSetNodeParamI( _sound2, H3DSoundNodeParams::Loop, _soundLoop ? 1 : 0 );
		break;
	case '8':
		// Rotate between the distance models
		switch( _distanceModel )
		{
		case H3DDistanceModels::None:
			_distanceModel = H3DDistanceModels::InverseDistance;
			break;
		case H3DDistanceModels::InverseDistance:
			_distanceModel = H3DDistanceModels::InverseDistanceClamped;
			break;
		case H3DDistanceModels::InverseDistanceClamped:
			_distanceModel = H3DDistanceModels::LinearDistance;
			break;
		case H3DDistanceModels::LinearDistance:
			_distanceModel = H3DDistanceModels::LinearDistanceClamped;
			break;
		case H3DDistanceModels::LinearDistanceClamped:
			_distanceModel = H3DDistanceModels::ExponentDistance;
			break;
		case H3DDistanceModels::ExponentDistance:
			_distanceModel = H3DDistanceModels::ExponentDistanceClamped;
			break;
		case H3DDistanceModels::ExponentDistanceClamped:
			_distanceModel = H3DDistanceModels::None;
			break;
		}

		h3dSetDistanceModel( _distanceModel );
		break;
	case GLFW_KEY_F3:
		if( h3dGetNodeParamI( _cam, H3DCamera::PipeResI ) == _hdrPipeRes )
			h3dSetNodeParamI( _cam, H3DCamera::PipeResI, _forwardPipeRes );
		else
			h3dSetNodeParamI( _cam, H3DCamera::PipeResI, _hdrPipeRes );

		break;
	case GLFW_KEY_F7:
		_debugViewMode = !_debugViewMode;
		h3dSetOption( H3DOptions::DebugViewMode, _debugViewMode ? 1.0f : 0.0f );
		break;
	case GLFW_KEY_F8:
		_wireframeMode = !_wireframeMode;
		h3dSetOption( H3DOptions::WireframeMode, _wireframeMode ? 1.0f : 0.0f );
		break;
	case GLFW_KEY_F6:
		_statMode += 1;

		if( _statMode > H3DUTMaxStatMode )
			_statMode = 0;

		break;
	}
}
SCENEGRAPHPLUGINEXP void dllLoadScene( const char* sceneFile )
{
	GameLog::logMessage("Setting Horde3D Configuration");
	
	XMLResults results;
	XMLNode scene = XMLNode::parseFile( sceneFile, "Configuration", &results);
	const XMLNode& engineSettings(scene.getChildNode("EngineConfig"));
	if ( !engineSettings.isEmpty() )
	{
		int maxLogLevel = atoi(engineSettings.getAttribute("maxLogLevel", "4"));
		GameLog::logMessage("MaxLogLevel: %d", maxLogLevel);
		h3dSetOption( H3DOptions::MaxLogLevel, float( maxLogLevel ) );

		int maxNumMessages = atoi(engineSettings.getAttribute("maxNumMessages", "1024"));
		GameLog::logMessage("MaxNumMessages: %d", maxNumMessages);
		h3dSetOption( H3DOptions::MaxNumMessages, float( maxNumMessages ) );

		int trilinearFiltering = atoi(engineSettings.getAttribute("trilinearFiltering", "1"));
		GameLog::logMessage("TrilinearFiltering: %d", trilinearFiltering);
		h3dSetOption( H3DOptions::TrilinearFiltering, float( trilinearFiltering ) );

		int maxAnisotropy = atoi(engineSettings.getAttribute("maxAnisotropy", "1"));
		GameLog::logMessage("MaxAnisotropy: %d", maxAnisotropy);
		h3dSetOption( H3DOptions::MaxAnisotropy, float( maxAnisotropy ) );

		bool sRGBLinearization = 
			_stricmp(engineSettings.getAttribute("sRGBLinearization", "0"), "true") == 0 ||
			_stricmp(engineSettings.getAttribute("sRGBLinearization", "0"), "1") == 0;
		GameLog::logMessage("SRGBLinearization: %s", sRGBLinearization ? "enabled" : "disabled");
		h3dSetOption( H3DOptions::SRGBLinearization, sRGBLinearization );

		bool texCompression = 
			_stricmp(engineSettings.getAttribute("texCompression", "0"), "true") == 0 ||
			_stricmp(engineSettings.getAttribute("texCompression", "0"), "1") == 0;
		GameLog::logMessage("TexCompression: %s", texCompression ? "enabled" : "disabled");
		h3dSetOption( H3DOptions::TexCompression, texCompression );

		bool loadTextures = 
			_stricmp(engineSettings.getAttribute("loadTextures", "1"), "1") == 0
			|| _stricmp(engineSettings.getAttribute("loadTextures", "1"), "true") == 0;
		GameLog::logMessage("LoadTextures: %s", loadTextures ? "enabled" : "disabled");
		h3dSetOption( H3DOptions::LoadTextures, loadTextures ? 1.0f : 0.0f );

		const XMLNode& pathes(scene.getChildNode("EnginePath"));
		if (!pathes.isEmpty())
		{
			GameLog::logMessage("AnimationPath: %s", pathes.getAttribute("animationpath", "animations"));
			h3dutSetResourcePath(H3DResTypes::Animation, pathes.getAttribute("animationpath", "animations"));
		}
		const XMLNode& engineSettings(scene.getChildNode("EngineConfig"));
		if ( !engineSettings.isEmpty() )
		{				
			bool fastAnim = 
				_stricmp(engineSettings.getAttribute("fastAnimation", "false"), "true") == 0 ||
				_stricmp(engineSettings.getAttribute("fastAnimation", "0"), "1") == 0;
			GameLog::logMessage("FastAnimation: %s", fastAnim ? "enabled" : "disabled");
			h3dSetOption( H3DOptions::FastAnimation, fastAnim ? 1.0f : 0.0f );
		}

		int shadowMapSize = atoi(engineSettings.getAttribute("shadowMapSize", "1024"));					
		GameLog::logMessage("ShadowMapSize: %d", shadowMapSize);
		h3dSetOption( H3DOptions::ShadowMapSize, float( shadowMapSize) );

		int sampleCount = atoi(engineSettings.getAttribute("sampleCount", "0"));					
		GameLog::logMessage("SampleCount: %d", sampleCount);
		h3dSetOption( H3DOptions::SampleCount, float( sampleCount) );

		bool wireframeMode = 
			_stricmp(engineSettings.getAttribute("wireframeMode", "0"), "1") == 0 ||
			_stricmp(engineSettings.getAttribute("wireframeMode", "0"), "true") == 0;
		GameLog::logMessage("WireframeMode: %s", wireframeMode ? "enabled" : "disabled");
		h3dSetOption( H3DOptions::WireframeMode, wireframeMode );

		bool debugViewMode = 
			_stricmp(engineSettings.getAttribute("debugViewMode", "0"), "1") == 0 ||
			_stricmp(engineSettings.getAttribute("debugViewMode", "0"), "true") == 0;
		GameLog::logMessage("DebugViewMode: %s", debugViewMode ? "enabled" : "disabled");
		h3dSetOption( H3DOptions::DebugViewMode, debugViewMode );

		bool dumpFailedShaders = 
			_stricmp(engineSettings.getAttribute("dumpFailedShaders", "0"), "1") == 0 ||
			_stricmp(engineSettings.getAttribute("dumpFailedShaders", "0"), "true") == 0;
		GameLog::logMessage("DumpFailedShaders: %s", dumpFailedShaders ? "enabled" : "disabled");
		h3dSetOption( H3DOptions::DumpFailedShaders, dumpFailedShaders );

		bool gatherTimeStats = 
			_stricmp(engineSettings.getAttribute("gatherTimeStats", "1"), "1") == 0 ||
			_stricmp(engineSettings.getAttribute("gatherTimeStats", "1"), "true") == 0;
		GameLog::logMessage("GatherTimeStats: %s", gatherTimeStats ? "enabled" : "disabled");
		h3dSetOption( H3DOptions::GatherTimeStats, gatherTimeStats );

	}

	const XMLNode& stereoSettings(scene.getChildNode("StereoscopyConfig"));
	if ( !stereoSettings.isEmpty() )
	{
		const char* modeC = stereoSettings.getAttribute("mode", "0");
		unsigned int mode = 0;
		if (_stricmp(modeC, "0") == 0 || _stricmp(modeC, "disabled") == 0)
			mode = 0;
		else if (_stricmp(modeC, "1") == 0 || _stricmp(modeC, "sideBySide") == 0)
			mode = 1;
		else if (_stricmp(modeC, "2") == 0 || _stricmp(modeC, "quadBuffering") == 0)
			mode = 2;
		SceneGraphManager::instance()->setStereoscopyMode(mode);

		const char* methodC = stereoSettings.getAttribute("method", "0");
		unsigned int method = 0;
		if (_stricmp(methodC, "0") == 0 || _stricmp(methodC, "toedIn") == 0)
			method = 0;
		else if (_stricmp(methodC, "1") == 0 || _stricmp(methodC, "asymmetricFrustum") == 0)
			method = 1;
		SceneGraphManager::instance()->setStereoscopyMethod(method);

		SceneGraphManager::instance()->setStereoscopyParams((float)atof(stereoSettings.getAttribute("eyeOffset", "0.05")),
			(float)atof(stereoSettings.getAttribute("strabismus", "2.5")), (float)atof(stereoSettings.getAttribute("focalLength", "1")));

		const char* stereoPipeline = stereoSettings.getAttribute("renderPipeline");
		if (stereoPipeline)
		{
			int resID = h3dAddResource( H3DResTypes::Pipeline, stereoPipeline, 0 );
			h3dutLoadResourcesFromDisk( "." );
			if (resID > 0)
				SceneGraphManager::instance()->setStereoPipelineResource(resID);
		}
		const char* stereoOverlayMaterial = stereoSettings.getAttribute("overlayMaterial");
		if (stereoOverlayMaterial)
		{
			int materialId = h3dAddResource( H3DResTypes::Material, stereoOverlayMaterial, 0 );
			h3dutLoadResourcesFromDisk( "." );
			if (materialId > 0)
				SceneGraphManager::instance()->setStereoOverlayMaterial(materialId);
		}
	}

	// Loading scene graph
	const XMLNode& sceneGraph(scene.getChildNode("SceneGraph"));
	if ( sceneGraph.isEmpty() )
		GameLog::errorMessage("No Scene Graph Node found!");
	else
	{
		GameLog::logMessage("Loading SceneGraph %s", sceneGraph.getAttribute("path"));
		// Environment
		H3DRes sceneGraphID = h3dAddResource( H3DResTypes::SceneGraph, sceneGraph.getAttribute("path"), 0 );
		GameLog::logMessage("Loading Resources...");
		// Load resources
		h3dutLoadResourcesFromDisk( "." );
		GameLog::logMessage("Adding scene graph to root node");
		// Add scene nodes	
		H3DNode newSceneID = h3dAddNodes( H3DRootNode, sceneGraphID);
		SceneGraphManager::instance()->addNewHordeNode( newSceneID );
	}
	// Use the specified render cam
	if (scene.getChildNode("ActiveCamera").getAttribute("name") && h3dFindNodes( H3DRootNode, scene.getChildNode("ActiveCamera").getAttribute("name"), H3DNodeTypes::Camera ) > 0)
		SceneGraphManager::instance()->setActiveCam( h3dGetNodeFindResult(0) );

}
Exemple #9
0
void TentacleApplication::mainLoop( float fps )
{
  _curFPS = fps;
  _timer += 1 / fps;
  keyHandler();

  h3dSetOption( H3DOptions::DebugViewMode, _debugViewMode ? 1.0f : 0.0f );
  h3dSetOption( H3DOptions::WireframeMode, _wireframeMode ? 1.0f : 0.0f );

  if( !_freeze )
  {
    float tx,ty,tz,foo;
    h3dGetNodeTransform(_fly,&tx,&ty,&tz,&foo,&foo,&foo,&foo,&foo,&foo);
    if (!_freezeFly)
    {
      // routhly simulates the random fly of a fly
      if((rand() % 100)>95)
      {
        _dx = ((ranf()))/50.0f;
        _dy = ((ranf()))/50.0f;
        _dz = ((ranf()))/50.0f;
      }
      // change fly position
      h3dSetNodeTransform( _fly, tx+_dx, ty+_dy, tz+_dz, 0, 0, 0, 0.2f, 0.2f, 0.2f );
      if (tx < -4.0) _dx =  0.05f;
      if (tx >  4.0) _dx = -0.05f;
      if (ty <  0.0) _dy =  0.05f;
      if (ty >  6.0) _dy = -0.05f;
      if (tz < -4.0) _dz =  0.05f;
      if (tz >  4.0) _dz = -0.05f;
      h3dGetNodeTransform(_fly,&tx,&ty,&tz,&foo,&foo,&foo,&foo,&foo,&foo);


      //update constraint position according to fly position
      _ikConstraint->setPosition(SMRVector3(tx, ty, tz));
    }

    if (!_freezeIK || _ikStep)
    {
      //Compute inverse kinematics
      _currentSolver->process();

      // update tentacle's joint (IK)
      updateTentacle();
      _ikStep = false;
    }
  }

  // Set camera parameters
  h3dSetNodeTransform( _cam, _x, _y, _z, _rx ,_ry, 0, 1, 1, 1 );

  if( _showFPS )
  {
    // Avoid updating FPS text every frame to make it readable
    if( _timer > 0.3f )
    {
      _fpsText.str( "" );
      _fpsText << "FPS: " << fixed << setprecision( 2 ) << _curFPS;
      _timer = 0;
    }

    // Show text
    //h3dutShowText( _fpsText.str().c_str(), 0, 0.95f, 0.03f, 0, _fontMatRes );
  }

  // Show title
  //h3dutShowText( "Comparing Standard IK algorithms.", 0.0f, 0.90f, 0.03f, 0, _fontMatRes );

  // Show IK method
  //h3dutShowText( _ikMethodString, 0.6f, 0.80f, 0.03f, 0, _fontMatRes );


  // Show logo
  //h3dShowOverlay( 0.7f, 0.2, 0, 0,
  //					    1, 0.2, 1, 0,
  //                        1, 0.6f, 1, 1, 
  //						0.7f, 0.6f, 0, 1,
  //                      7, _invJacMatRes );

  // Render scene
  h3dRender( _cam );

  // Remove all overlays
  h3dClearOverlays();

  // Write all mesages to log file
  h3dutDumpMessages();
}
Exemple #10
0
bool TentacleApplication::init()
{
  // Initialize engine
  if( !h3dInit() )
  {
    h3dutDumpMessages();
    return false;
  }

	// Set options
	h3dSetOption( H3DOptions::LoadTextures, 1 );
	h3dSetOption( H3DOptions::TexCompression, 0 );
	h3dSetOption( H3DOptions::MaxAnisotropy, 4 );
	h3dSetOption( H3DOptions::ShadowMapSize, 2048 );
	h3dSetOption( H3DOptions::FastAnimation, 1 );

  // Add resources
  // Pipelines
  _hdrPipeRes = h3dAddResource( H3DResTypes::Pipeline, "pipelines/hdr.pipeline.xml", 0 );
  _forwardPipeRes = h3dAddResource( H3DResTypes::Pipeline, "pipelines/forward.pipeline.xml", 0 );
  // Font
  _fontMatRes = h3dAddResource( H3DResTypes::Material, "overlays/font.material.xml", 0 );
  // Logo
  _logoMatRes = h3dAddResource( H3DResTypes::Material, "overlays/logo.material.xml", 0 );
  // invJacXpl
  //_invJacMatRes = h3dAddResource( H3DResTypes::Material, "materials/invJac.material.xml", 0 );
  // Environment
  H3DRes envRes = h3dAddResource( H3DResTypes::SceneGraph, "models/sphere/sphere.scene.xml", 0 );
  // Tentacle
  H3DRes tentacleRes = h3dAddResource( H3DResTypes::SceneGraph, "models/tentacle.scene.xml", 0 );
  // Fly
  H3DRes flyRes = h3dAddResource( H3DResTypes::SceneGraph, "models/fly.scene.xml", 0 );

  _dx = _dy = _dz = 0;

  // Load resources
  h3dutLoadResourcesFromDisk( _contentDir.c_str() );

  // Add scene nodes
  // Add camera
  _cam = h3dAddCameraNode( H3DRootNode, "Camera", _forwardPipeRes );
  // Add environment
  H3DNode env = h3dAddNodes( H3DRootNode, envRes );
  h3dSetNodeTransform( env, 0, -20, 0, 0, 0, 0, 20, 20, 20 );

  // Add tentacle node
  _tentacle = h3dAddNodes( H3DRootNode, tentacleRes );
  h3dSetNodeTransform( _tentacle, 0, 0, 0, 0, 0, 0.0, 1.0f, 1.0f, 1.0f );

  // Create tentacle kinematic chain
  _tentacleIK = setUpKinematikChain(_tentacle);
  //cout << _tentacleIK->getEndPosition(_tentacleIK->getNumJoints()-1);
  //_ikCCDSolver = new SmrCCDSolver(_tentacleIK);
  //_ikCCDSolver->addConstraintPtr(_ikConstraint);

  _ikGSMMSolver = new SMRGSMMSolver(_tentacleIK);
  _ikGSMMSolver->addConstraintPtr(_ikConstraint);

  _ikInvJacSolver = new SMRInvJacSolver(_tentacleIK);
  _ikInvJacSolver->addConstraintPtr(_ikConstraint);

  //delete(_tentacleIK);

  _currentSolver = _ikInvJacSolver;
  _ikMethodString = "J pseudo-inverse";

  // Add fly node
  _fly = h3dAddNodes( H3DRootNode, flyRes );
  h3dSetNodeTransform( _fly, 0, 4, 0, 0, 0, 0, 0.2f, 0.2f, 0.2f );

  // Add light source
  H3DNode light = h3dAddLightNode( H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP" );
  h3dSetNodeTransform( light, 0, 15, 10, -60, 0, 0, 1, 1, 1 );
  h3dSetNodeParamF( light, H3DLight::RadiusF,0, 30 );
  h3dSetNodeParamF( light, H3DLight::FovF,0, 90 );
  h3dSetNodeParamI( light, H3DLight::ShadowMapCountI, 0 );
  h3dSetNodeParamF( light, H3DLight::ShadowMapBiasF,0, 0.01f );
  h3dSetNodeParamF( light, H3DLight::ColorF3,0, 1.0f );
  h3dSetNodeParamF( light, H3DLight::ColorF3,1, 0.8f );
  h3dSetNodeParamF( light, H3DLight::ColorF3,2, 0.7f );

  // Customize post processing effects
	H3DNode matRes = h3dFindResource( H3DResTypes::Material, "pipelines/postHDR.material.xml" );

  //hdrParams: exposure, brightpass threshold, brightpass offset (see shader for description)
	h3dSetMaterialUniform( matRes, "hdrParams", 2.5f, 0.5f, 0.08f, 0 );

  return true;
}
	H3DView(int winWidth, int winHeight) :
			BulletEngineTest(),
			//model(0),
			cam(0),
			frameNum(0),
			text(NULL), textLen(32),
			_rx(15), _ry(-50),
			//_rx(0), _ry(0),
			_prev_x(0), _prev_y(0),
			_mouseEnteredThisFrame(false)
	{
		assert(view == NULL);
		view = this;

		text = new char[textLen];
		memset(text, 0, textLen);

		LOG("Initializing Horde3D...");
		h3dInit();

		h3dSetOption(H3DOptions::MaxAnisotropy, 8);
		h3dSetOption(H3DOptions::SampleCount, 16);

		//h3dSetOption(H3DOptions::WireframeMode, 1);
		//h3dSetOption(H3DOptions::DebugViewMode, 1);
		h3dSetOption(H3DOptions::GatherTimeStats, 1);

		LOG("Declaring resources...");

		pipeRes = h3dAddResource(H3DResTypes::Pipeline, "pipelines/forward.pipeline.xml", 0);

		H3DRes skyBoxRes = h3dAddResource(H3DResTypes::SceneGraph, "models/skybox/skybox.scene.xml", 0);

		//modelRes = h3dAddResource(H3DResTypes::SceneGraph, "models/AssJacket/AssJacket.scene.xml", 0);
		//modelRes = h3dAddResource(H3DResTypes::SceneGraph, "models/ares/ares.scene.xml", 0);
		modelRes = h3dAddResource(H3DResTypes::SceneGraph, "models/man/man.scene.xml", 0);

		fontMatRes = h3dAddResource(H3DResTypes::Material, "overlays/font.material.xml", 0);
		panelMatRes = h3dAddResource(H3DResTypes::Material, "overlays/panel.material.xml", 0);

		LOG("Loading resources from disk...");
		h3dutLoadResourcesFromDisk("/home/whitelynx/devel/other/Horde3D/build-make/Binaries/Content"
				"|/home/whitelynx/devel/skewedaspect/precursors-client/resources/content");

		LOG("Building scene...");
		/*
		// Add model to scene
		model = h3dAddNodes(H3DRootNode, modelRes);
		h3dSetNodeTransform(model,
				0, 0, -500,  // Translation
				0, 0, 0,     // Rotation
				1, 1, 1      // Scale
				);
		*/

		// Add light source
		H3DNode light = h3dAddLightNode(H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP");
		// Set light position and radius
		h3dSetNodeTransform(light,
				0, 20, 0,
				0, 0, 0,
				10, 10, 10
				);
		h3dSetNodeParamF(light, H3DLight::RadiusF, 0, 50.0f);

		LOG("Setting up camera...");
		cam = h3dAddCameraNode(H3DRootNode, "Camera", pipeRes);

		resizeViewport(winWidth, winHeight);

#if 1
		H3DNode sky = h3dAddNodes(H3DRootNode, skyBoxRes);
		h3dSetNodeTransform(sky,
				0, 0, 0,      // Translation
				0, 0, 0,      // Rotation
				210, 50, 210  // Scale
				);
		h3dSetNodeFlags(sky, H3DNodeFlags::NoCastShadow, true);
#endif

		LOG("Setting BulletEngine callbacks...");
		setMakeModelCallback(&makeModelCB);
		setUpdateModelCallback(&updateModelCB);

		LOG("Initializing physics...");
		initPhysics();

		LOG("Ready.");
	} // end H3DView
Exemple #12
0
AGENTPLUGINEXP void dllLoadScene( const char* sceneFile )
{
	XMLResults results;
	XMLNode scene = XMLNode::parseFile( sceneFile, "Configuration", &results);

	/*
	 * Paths
	 */
	XMLNode& pathes(scene.getChildNode("EnginePath"));
	if (!pathes.isEmpty())
	{
		GameLog::logMessage("-  AnimationPath = %s", pathes.getAttribute("AnimationPath", "models"));
		h3dutSetResourcePath(H3DResTypes::Animation, pathes.getAttribute("animationpath", "animations"));
	}

	/*
	 * Horde3D configurations
	 */
	XMLNode& engineSettings(scene.getChildNode("EngineConfig"));
	if ( !engineSettings.isEmpty() )
	{				
		bool fastAnim = 
			_stricmp(engineSettings.getAttribute("fastAnimation", "false"), "true") == 0 ||
			_stricmp(engineSettings.getAttribute("fastAnimation", "0"), "1") == 0;
		GameLog::logMessage("FastAnimation: %s", fastAnim ? "enabled" : "disabled");
		h3dSetOption( H3DOptions::FastAnimation, fastAnim ? 1.0f : 0.0f );
	}

	/*
	 * Agent component configurations
	 */
	// First set default config
	Config::useDefault();

	XMLNode& extras(scene.getChildNode("Extras"));
	if (!extras.isEmpty())
	{
		const XMLNode& agentSettings(extras.getChildNode("AgentConfig"));
		if (!agentSettings.isEmpty())
		{
			char* xmlString = agentSettings.createXMLString();
			GameLog::logMessage("- Setting Agent settings from xml = %s", xmlString);
			delete xmlString;

			Config::loadFromXml(agentSettings);
		}
	}

	/*
	 * Animation lexicon
	 */
	if (!extras.isEmpty())
	{
		const XMLNode& animLexicon(extras.getChildNode("AnimationLexicon"));
		if (!animLexicon.isEmpty() && animLexicon.getAttribute("path") != 0)
		{			
			GameLog::logMessage("- Parsing Animation Lexicon from %s", animLexicon.getAttribute("path"));
			AnimationData::loadLexiconData( &XMLNode::openFileHelper( animLexicon.getAttribute("path"), "AnimationLexicon" ));
		}
		else
			GameLog::errorMessage( "AgentComponent: error parsing animation lexicon (file not found?). Animation loading will only be available by filename or resource" );
	}

	/*
	 * Socket entity
	 */
	if (!extras.isEmpty())
	{
		const XMLNode& socket(extras.getChildNode("SocketServer"));
		if (!socket.isEmpty() && socket.getAttribute("entity") != 0)
		{			
			GameLog::logMessage("- SocketServer entity set to %s", socket.getAttribute("entity"));
			Config::setParamS(Agent_Param::SocketEntityName_S, socket.getAttribute("entity"));
		}
		else
			GameLog::logMessage("- SocketServer entity set to default value (%s)", Config::getParamS(Agent_Param::SocketEntityName_S));
	}
}