Sophie

Sophie

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

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0088)http://homepages.ihug.co.nz/~evilnic/Tutorials/Ogre/LightsCameraAction/CameraMotion.html -->
  <title>Creating OGRE Project Files</title>
  <meta http-equiv="Content-Type"
 content="text/html; charset=windows-1252">
  <style type="text/css">.MainHeader {
	FONT-WEIGHT: bold; FONT-SIZE: 10pt; COLOR: #ffffff; BACKGROUND-COLOR: #003300
}
BODY {
	FONT-SIZE: 10pt; COLOR: #003300; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: #ffffff
}
.BorderHeader {
	FONT-WEIGHT: bold; FONT-SIZE: 8pt; COLOR: #333300; BACKGROUND-COLOR: #999900; TEXT-ALIGN: center
}
.MainContent {
	FONT-SIZE: 10pt; COLOR: #003300; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
}
.BorderContent {
	BORDER-RIGHT: #666600 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: black 0px solid; PADDING-LEFT: 2px; FONT-SIZE: 8pt; MARGIN-BOTTOM: 2px; PADDING-BOTTOM: 10px; BORDER-LEFT: #666600 1px solid; COLOR: #000000; PADDING-TOP: 2px; BORDER-BOTTOM: #666600 1px solid
}
A:link {
	COLOR: #000066; TEXT-DECORATION: underline
}
A:hover {
	COLOR: #0000ff; TEXT-DECORATION: underline
}
A:visited {
	COLOR: #660066; TEXT-DECORATION: underline
}
LI {
	LEFT: -15px; COLOR: #000000; LIST-STYLE-TYPE: circle; POSITION: relative
}
.NewsDate {
	FONT-WEIGHT: bold; COLOR: #000000
}
TD {
	FONT-SIZE: 10pt
}
TH {
	FONT-SIZE: 10pt
}
.Annotation {
	FONT-SIZE: 10px
}
.header {
	FONT-SIZE: 16pt; COLOR: #000000
}
.SectionHeader {
	FONT-WEIGHT: bold; FONT-SIZE: 14px; COLOR: #000000
}
PRE {
	FONT-SIZE: 12px; COLOR: #000066
}
  </style>
  <meta content="MSHTML 6.00.2600.0" name="GENERATOR">
  <meta content="" name="keywords">
  <meta content="" name="description">
  <meta content="Nicholas" name="author">
  <meta http-equiv="reply-to" content="vastrim@hotmail.com">
  <meta content="Sat, 13 Jul, 2002 12:32:59 p GMT" name="creation_date">
</head>
<body text="#000000" bgcolor="#ffffff">
<p class="header" align="center">OGRE (Object-Oriented Graphics
Rendering Engine)</p>
<p class="header" align="center">Spining the Camera </p>
<p class="MainHeader" align="left">&nbsp;</p>
<p class="SectionHeader" align="left">Camera Spins</p>
<p align="left">Lets do some camera motion. The first thing we are
going to do it spin the camera. Not around itself but around the ship
and keep it facing the ship. Ogre gives us a very easy way to do this
using SceneNodes. </p>
<p></p>
<pre>class SpaceCameraRotator : public ExampleFrameListener<br></pre>
Yep thats right, another class derived from ExampleFrameListener. One
of the good things about Ogre is that we can have more than one piece
of code monitoring the keyboard, and that is exactly what we are going
to do here. Our first FrameListener, SpaceFrameListener will remain
and move the ship based on the arrow keys and this new class will move
the camera based on some other keys.
<pre>{<br>protected:<br>	Camera* mCamera;<br>	SceneNode* mCentralNode;<br>	SceneNode* mRotatingNode;<br>	Vector3 mRotationAxis;<br>	Real mRotationSpeed;<br></pre>
Nothing special there, just some member variables.
<pre>public:<br>	SpaceCameraRotator(RenderWindow* win, Camera* cam, SceneNode* centralNode, Vector3 initialPosition) : ExampleFrameListener(win, cam)<br>	{<br>		mCamera = cam;<br>		mCentralNode = centralNode;<br>		mRotationAxis = Vector3::UNIT_Y;<br>		mRotationSpeed = 60.0;<br><br>		// Create a node to act as the central rotation point<br>		mRotatingNode = static_cast&lt;SceneNode*&gt;(mCentralNode-&gt;createChild());<br><br>		mRotatingNode-&gt;attachCamera(mCamera);<br>		mCamera-&gt;moveRelative(initialPosition);<br>		mCamera-&gt;lookAt(0, 0, 0);<br>	}<br></pre>
As you can see what we have done is created a new SceneNode called
mRotatingNode that is attached to SceneNode supplied to the constructor,
which by the way will be the node that ship is attached to. This node
will be the anchor for our rotations. Then we attach the camera to the
new node, set its position to be off centre, and tell it to look at
the 0,0,0 which just so happens to be the ship.
<pre>	~SpaceCameraRotator()<br>	{<br>		delete mRotatingNode;<br>	}<br></pre>
Since we created a SceneNode in the constructor we really should
destroy it in the destructor.
<pre>    bool frameStarted(const FrameEvent&amp; evt)<br>    {<br>		// Copy the current state of the input devices<br>		mInputDevice-&gt;capture();<br><br>		if(mInputDevice-&gt;isKeyDown(Ogre::KC_SPACE))<br>		  mRotatingNode-&gt;rotate(mRotationAxis, mRotationSpeed * evt.timeSinceLastFrame);		<br><br>		return true;<br>	}<br><br>};<br></pre>
This is pretty simple, rotate the new SceneNode around the axis if the
space bar is pressed. All that is left now is creating an instance of
SpaceCameraRotator. Insert the following code into createFrameListener
<pre>	SpaceCameraRotator* cameraRotator = new SpaceCameraRotator(mWindow, mCamera, mShipNode, Vector3(0, 0, 100));<br>	mRoot-&gt;addFrameListener(cameraRotator);<br></pre>
Compile and run the program. When you hold down the space bar you
should see the camera is rotating around the ship. You can tell that
the camera is spinning and not the ship because the background is
moving. If you press the arrow keys the ship will still move as it did
before BUT the camera will move with it. The net effect is that the
background will look like it is moving and the ship isn't.
<p></p>
<p>I had planned to do some more camera work (like bumping) but another
scene would demonstrate them better. So that will have to wait until
another day. </p>
<table cellspacing="2" cellpadding="0" width="100%" border="0">
  <tbody>
    <tr>
      <td width="14%"><a
 href="Index.html">Back
to Index</a></td>
      <td width="39%">&nbsp;</td>
      <td width="22%"><a
 href="WaveformController.html">&lt;&lt;
Previous section</a></td>
      <td width="25%">Next section &gt;&gt;</td>
    </tr>
  </tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p class="SectionHeader">&nbsp;</p>
</body>
</html>