示例#1
0
文件: app.cpp 项目: dreamsxin/nawia
void Application::mainLoop( float timeSinceLastFrame )
{
	keyHandler( timeSinceLastFrame );

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

	_lightTimer += timeSinceLastFrame;

	// Has it gone a second since the light changed color?
	if( _lightTimer >= 1.0f )
	{
		// Set a random light color
		switch( rand() % 6 )
		{
		case 0:
			// Red
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 1.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 0.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 0.0f );
			break;
		case 1:
			// Green
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 0.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 1.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 0.0f );
			break;
		case 2:
			// Blue
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 0.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 0.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 1.0f );
			break;
		case 3:
			// Yellow
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 1.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 1.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 0.0f );
			break;
		case 4:
			// Purple
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 1.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 0.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 1.0f );
			break;
		case 5:
			// Cyan
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 0.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 1.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 1.0f );
			break;
		}

		// Reset the timer
		_lightTimer = 0.0f;
	}

	// Show stats
	h3dutShowFrameStats( _fontMatRes, _panelMatRes, _statMode );
	if( _statMode > 0 )
	{	
		displaySoundInfo();
	}

	// Show logo
	const float ww = (float)h3dGetNodeParamI( _cam, H3DCamera::ViewportWidthI ) /
	                 (float)h3dGetNodeParamI( _cam, H3DCamera::ViewportHeightI );
	const float ovLogo[] = { ww-0.4f, 0.8f, 0, 1,  ww-0.4f, 1, 0, 0,  ww, 1, 1, 0,  ww, 0.8f, 1, 1 };
	h3dShowOverlays( ovLogo, 4, 1.f, 1.f, 1.f, 1.f, _logoMatRes, 0 );

	// Render scene
	h3dRender( _cam );

	// Finish rendering of frame
	h3dFinalizeFrame();

	// Remove all overlays
	h3dClearOverlays();

	// Write all mesages to log file
	h3dutDumpMessages();
}
示例#2
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();
}