<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Benny's Blog &#187; real time updates</title>
	<atom:link href="http://blog.projectnibble.org/tag/real-time-updates/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.projectnibble.org</link>
	<description>House Of Code</description>
	<lastBuildDate>Fri, 13 Aug 2010 15:06:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Papervision3D DisplayObject3D helper baseclass for realtime updates</title>
		<link>http://blog.projectnibble.org/2009/06/15/papervision3d-displayobject3d-helper-baseclass-for-realtime-updates/</link>
		<comments>http://blog.projectnibble.org/2009/06/15/papervision3d-displayobject3d-helper-baseclass-for-realtime-updates/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 14:36:34 +0000</pubDate>
		<dc:creator>Benny Bottema</dc:creator>
				<category><![CDATA[Papervision3D]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[real time updates]]></category>

		<guid isPermaLink="false">http://blog.projectnibble.org/?p=281</guid>
		<description><![CDATA[Here's a small class I made for adding realtime updates to DisplayObject3D objects. This class allows for easy time-based updates instead of the traditional frame-based updates.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a small class I made for adding realtime updates to DisplayObject3D objects. This class allows for easy time-based updates instead of the traditional frame-based updates.</p>
<ul>
<li><a href="http://projectnibble.org/dump/blog/papervision3d_realtime/RealtimeDisplayObject3D.as">RealtimeDisplayObject3D.as</a></li>
</ul>
<p>I use the convention of adding update methods to all (my own) DisplayObject3D objects, which then update themselves according to preconfigured settings (eg. passed in the constructor). I pass in a Camera3D and that&#8217;s it, let the objects do their own thing. I&#8217;m making use of this convention by extracting this update method to a baseclass which then can do time-based updates instead.</p>
<p><span id="more-281"></span></p>
<p>It only works for new classes you create that normally would extend DisplayObject3D, such as a composite parent DisplayObject3D. For example, if you were to create an <a href="http://blog.projectnibble.org/2009/06/19/papervision3d-clouded-planet-earth-tutorial-and-source/">Earth object in PV3D</a>, you could create a new DisplayObject3D container class which adds a planet, clouds and a glow to itself as child objects. This Earth object could then extend our special class, RealtimeDisplayObject3D, for controlling time-based updates.</p>
<pre  name="code" class="java">
public class Planet extends RealtimeDisplayObject3D {

	private var earth:DisplayObject3D;

	// define: 1 update every 200ms (5 updates per second) and process 1 value per second
	public function Planet() {
		super(200, 1);
		// add planet, clouds and glow etc.
	}

	// rotates Earth 5 times per second, with a stepsize of 0.2 (1 second / updates per second)
	protected override function realtimeUpdate(camera:Camera3D, stepsize:Number):void {
		earth.rotate(stepsize);
	}
}
</pre>
<p>With the planet now extending our RealtimeDisplayObject3D class instead of DisplayObject3D, you can provide realistic rotation speed that is not influenced by the FPS the movie is pulling. Instead, it works by applying a set value-per-second (phase speed) and a required update frequency per second; the phase speed is spread out over the number of updates per second.</p>
<p>There is one requirement though: <strong>the fps the movie is pulling cannot go below the updates per second specified</strong>, or the updates per second is capped by the frames per second. If you specify 200ms for each update, this means 5 updates per second (1000 / 200). This won&#8217;t be a problem. If however you define 50ms for each update, this means 20 updates per second (1000 / 50). You must ensure that your movie is running on 20 frames per second or more.</p>
<h2>Combining time-based updates with frame-based updates</h2>
<p>You can still update normally on frame-based timetable by overriding the <i>update(camera)</i> method of the baseclass. Or, you can combine both type of updates by overriding <i>update(camera)</i>, do a frame-based update, call <i>super.update(camera)</i> and override the <i>realtimeUpdate(camera)</i> method as we did before. Here&#8217;s an example of that:</p>
<pre  name="code" class="java">
public class Planet extends RealtimeDisplayObject3D {

	private var earth:DisplayObject3D;

	// define: 1 update every 200ms (5 updates per second) and process 1 value per second
	public function Planet() {
		super(200, 1);
		// add planet, clouds and glow etc.
	}

	// makes the planet face the camera each and every frame
	protected override function update(camera:Camera3D, stepsize:Number):void {
		earth.lookAt(camera);
		super.update(camera);
	}

	// rotates Earth 5 times per second, with a stepsize of 0.2 (1 second / updates per second)
	protected override function realtimeUpdate(camera:Camera3D, stepsize:Number):void {
		earth.rotate(stepsize);
	}
}
</pre>
<p><a href="http://blog.projectnibble.org/2009/06/15/papervision3d-displayobject3d-helper-baseclass-for-realtime-updates/trackback/">trackback</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.projectnibble.org/2009/06/15/papervision3d-displayobject3d-helper-baseclass-for-realtime-updates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
