The below sample is adapted by regress from samplesGraphicsDemo originally from psyclonist. Add comments and questions where necessary.

//****************************************************************************
//**
//**    Basic Sample Adapted from samplesGraphicsDemo
//**
//****************************************************************************

//============================================================================
//    IMPLEMENTATION HEADERS
//============================================================================

//If you want to use pre-compiled headers for faster compiling time, include this line. Non-crucial.
#include <yake/samples/graphics/pch.h>

//Don't warn us about these warnings
#pragma warning( disable: 4305 ) // truncation from 'double' to 'float'

using namespace yake;
using namespace yake::base::templates;
using namespace yake::math;
using namespace yake::graphics;
using namespace yake::data;

// todo template approach for subsystems
class TheApp : public yake::exapp::ExampleApplication
{
private:
	//Group a viewport and camera together for (not so) easy access, and create the 
	//graphical world while we're at it.
	Vector<std::pair<IViewport*,ICamera*> >	mVPs;
	SharedPtr< IWorld >					mGWorld;

	//Declare and optionally intialize your scenenodes, entities, and other variables here.

	//Let's define a simple structure for easy access to a SceneNode and the associated
	//Entity.
	struct SimpleOne {
		graphics::ISceneNode*			pSN;
		graphics::IEntity*		        pE;
	};

public:
	TheApp() : ExampleApplication( true /*graphics*/,
					false /*physics*/,
					false /*scripting*/,
					true /*input*/,
					false /*script bindings*/,
					false /*audio*/)//,
				//mLightOneNode(0),
				//mCurrentTechnique(0)
	{
          //Set all of your scenenodes = 0 here
	}

	void onKey(const yake::input::KeyboardEvent & e)
	{
         //What to do when the keyboard is pressed
         //e.keycode is the key that was just pressed (ie. KC_UP, KC_W, etc)
	}

	void onMB(uint8 btn)
	{
		//What to do whenever the mouse buttons are pressed
	}

	void onMMove(Vector3 mMouseVector)
	{
		//What to do whenever the mouse moves
	}

	int createCameraViewportPair( real sx, real sy, real w, real h, int z )
	{
		ICamera* pC = mGWorld->createCamera();
		YAKE_ASSERT( pC );
		pC->setNearClipDistance( 1. );
        // incase infinite far distance is not supported
        pC->setFarClipDistance(100000);

		mVPs.push_back( std::pair<IViewport*,ICamera*>(mGWorld->createViewport( pC ), pC) );
		size_t idx = mVPs.size()-1;
		YAKE_ASSERT( mVPs[idx].first );
		mVPs[idx].first->setDimensions( sx, sy, w, h );
		mVPs[idx].first->setZ( z );
		return static_cast<int>(idx);
	}

	virtual void run()
	{
		// setup event input generators
		mKeyboardEventGenerator.subscribeToKeyDown( Bind1( &TheApp::onKey, this ) );    //Bind keyboard event to the above onKey() function
		mMouseEventGenerator.subscribeToMouseButtonDown( Bind1( &TheApp::onMB, this ) );//Bind the mouse button events to the above onMB() function
		mMouseEventGenerator.subscribeToMouseMoved( Bind1( &TheApp::onMMove, this ) );  //Bind the mouse movement event to the above onMMove() function

		// graphics
		mGWorld = getGraphicsSystem().createWorld();
		YAKE_ASSERT( mGWorld );

		//NOTE: Make sure you create a camera before calling mGWorld->setShadowsEnabled(true)
		// when using "ogre3d" and the terrain scene manager with modulated texture shadows.
		// The first camera created will be used as the primary camera by the scene manager
		// and it crashes wildly if it's a texture shadow camera!

		createCameraViewportPair( 0.0, 0.0, 1, 1, 10 );

		if (mVPs[0].second)
		{
			mVPs[0].second->translate( Vector3(0,100,700) );
			mVPs[0].second->pitch(-10);
		}

		//Camera Stuff
                //Set this if you want to use FPS-style movement, working with euler stuff without worrying about affecting roll through yaw and pitch
		mVPs[0].second->setFixedYawAxis( Vector3::kUnitY );

		// objects
		//Call some functions to setup your objects

		//Uncomment if you want shadows
                //mGWorld->setShadowsEnabled( true );

		// main loop
		real lastTime = base::native::getTime();
		while (!shutdownRequested())
		{
			// timing
			real time = base::native::getTime();
			real timeElapsed = time-lastTime;//timer->getSeconds();
			lastTime = time;

			// handle input
			getInputSystem().update();
			mMouseEventGenerator.update();
			mKeyboardEventGenerator.update();

			//
			YAKE_ASSERT( getKeyboard() );
			if (getKeyboard())
			{
				static  unsigned iCam = 0;
				real distance = -200. * timeElapsed;
			}

			// render the scene
			if (!shutdownRequested())
				mGWorld->render( timeElapsed );
		}

                //Get rid of our above variables - including SceneNodes, entities, lights, etc.
		//YAKE_SAFE_DELETE( mMyObject.pSN );

		mGWorld.reset();
	}
};

//============================================================================
//    IMPLEMENTATION FUNCTIONS
//============================================================================

int main()
{
	try
	{
		std::cout << std::endl << "YAKE Framework, adapted from samplesGraphicsDemo" << std::endl;
		TheApp theApp;
		theApp.initialise();
		theApp.run();
	}
	catch (const yake::Exception & e)
	{
		std::cout << std::endl << e.what() << std::endl;
	}
	catch (...)
	{
		std::cout << std::endl << "-----------------" << std::endl << "UNHANDLED EXCEPTION" << std::endl;
	}
#if defined( YAKE_DEBUG_BUILD )
	std::cout << std::endl << "Waiting for you...";
	std::cin.get();
#endif

	return 0;
}
 
tutorials/basics/non-raf_sample.txt · Last modified: 2008/02/21 21:59 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki