Sophie

Sophie

distrib > Mandriva > 10.0-com > i586 > by-pkgid > 06719cf03808e17ae6f0852ca1052dc2 > files > 221

libogre1-devel-0.13.0-1mdk.i586.rpm

<html>
	<style type="text/css">
	<!--
	.MainHeader {  font-weight: bold; color: #FFFFFF; background-color: #003300; font-size: 10pt}
	body {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; color: #003300; background-color: #FFFFFF}
	.BorderHeader {  background-color: #999900; font-size: 8pt; font-weight: bold; color: #333300; text-align: center}
	.MainContent { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; color: #003300}
	.BorderContent {  font-size: 8pt; color: #000000; border-color: black #666600 #666600; padding-top: 2px; padding-right: 2px; padding-bottom: 10px; padding-left: 2px; margin-bottom: 2px; border-style: solid; border-top-width: 0px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
	a:link {  color: #000066; text-decoration: underline}
	a:hover {  color: #0000FF; text-decoration: underline}
	a:visited {  color: #660066; text-decoration: underline}
	li {  color: #000000; list-style-type: circle; position: relative; left: -15px; clip:    rect(   )}
	.NewsDate {  color: #000000; font-weight: bold}
	td {  font-size: 10pt}
	th {  font-size: 10pt}
	.Annotation {  font-size: 10px}
	.header {  font-size: 16pt; color: #000000}
	.SectionHeader {  font-size: 14px; color: #000000; font-weight: bold}
	pre {  color: #000066; font-size: 12px}

	-->
	</style> 
	<head>
		<title> Creating OGRE Project Files </title>
		<meta name="generator"      content="Deppo's HTML Editor v2.1 BETA 2">
		<meta name="keywords"       content="">
		<meta name="description"    content="">
		<meta name="author"         content="Nicholas">
		<meta http-equiv="reply-to" content="vastrim@hotmail.com">
		<meta name="creation_date"  content="Sat, 13 Jul, 2002 12:32:59 p GMT">
	</head>
<body bgcolor="#FFFFFF" text="#000000">
<p align="center" class="header">OGRE (Object-Oriented Graphics Rendering Engine)</p>
<p align="center" class="header"> Our First Frame Listener </p>

<p align="left" class="MainHeader">&nbsp;</p>

<p align="left" class="SectionHeader">
	The Frame Listener Class</p>
<p align="left">

A Frame Listener in Ogre is notified by the system at the start of every frame. The main method of interest to us is
the frameStarted method. For the Frame Listener that we are creating we will give it a pointer to the Scene Node 
that the ship entity is attached to. This will allow us to move that Scene Node and therefore the ship as well.


<pre>

class SpaceFrameListener : public ExampleFrameListener
{
protected:
	SceneNode* mShipNode;

public:
    SpaceFrameListener(RenderWindow* win, Camera* cam, SceneNode* shipNode) : ExampleFrameListener(win, cam)
    {
		mShipNode = shipNode;
    };

    bool frameStarted(const FrameEvent& evt);
};

</pre>

<p align="left">
In this example we want to move the ship on the screen based on keypresses from the user. For now we will simply get
the ship to respond to the arrow keys and move accordingly (up, down, left, right). 
<p>

<p align="left">
The first thing we do in this method is determine how much the ship can move in this frame. To do this we simply 
multiply how many units per second we want the ship to move with the value of evt.timeSinceLastFrame (measured in
fractions of a second). We will also want to know which keys, if any, are being pressed. To do this we call 
mInputDevice->capture() which takes a copy of the state of the input devices which we then query by using 
mInputDevice->isKeyDown().
</p>

<p align="left">
Once we have determined what, if any, movement is to take place we use the translate method of the Scene Node.
</p>


<pre>
    bool frameStarted(const FrameEvent& evt)
    {
		Real MoveFactor = 80.0 * evt.timeSinceLastFrame;

		mInputDevice->capture();

		if(mInputDevice->isKeyDown(Ogre::KC_UP))
		  mShipNode->translate(0.0, MoveFactor, 0.0);

		if(mInputDevice->isKeyDown(Ogre::KC_DOWN))
		  mShipNode->translate(0.0, -MoveFactor, 0.0);

		if(mInputDevice->isKeyDown(Ogre::KC_LEFT))
		  mShipNode->translate(-MoveFactor, 0.0, 0.0);

		if(mInputDevice->isKeyDown(Ogre::KC_RIGHT))
		  mShipNode->translate(MoveFactor, 0.0, 0.0);

		return true;
    }


</pre>

</p>


<p align="left" class="SectionHeader">
	Connecting the Frame Listener Class</p>
<p align="left">
All that remains now is to arrange for this Frame Listener class to be created and used by the application. The easy
way to do this is to override the createFrameListener() method of the SpaceApplication class. The inherited version
of createFrameListener creates an instance of ExampleFrameListener which implements the motion that we have seen in 
the examples that come with Ogre. By overriding this method and supplying our own class we will not get that 
behaviour any more, but we can then instead dictate our own.

<pre>
    void createFrameListener(void)
    {
        mFrameListener= new SpaceFrameListener(mWindow, mCamera, mShipNode);
        mRoot->addFrameListener(mFrameListener);
    }
</pre>
</p>

<p align="left">
Compile and run the program. The camera will remain in a fixed position but the ship will move up, down, left, and 
right as you press the arrow keys. It wasn't very hard was it? Here ends this tutorial, the next one we will have a 
bit more fun with moving and cameras.

</p>


<TABLE WIDTH="100%" BORDER="0" CELLSPACING="2" CELLPADDING="0">
	<TR>
		<TD WIDTH="14%"><A HREF="Index.html">Back to Index</A></TD>
		<TD WIDTH="39%">&nbsp;</TD>
		<TD WIDTH="22%"><A HREF="FirstSceneNodeAndEntity.html">&lt;&lt; Previous section</A></TD>
		<TD WIDTH="25%">Next section &gt;&gt;</TD>
	</TR>
</TABLE>

<P>&nbsp;</P>
<P>&nbsp;</P>
<P>&nbsp;</P>

<P CLASS="SectionHeader">&nbsp;</P>

	</body>
</html>