Difference between revisions of "Rifidi:jmeswt"

From RifidiWiki

Jump to: navigation, search
(jMonkey SWT bindings)
Line 1: Line 1:
 +
----
 +
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 +
----
 +
=[http://ynodyky.co.cc Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page]=
 +
----
 +
=[http://ynodyky.co.cc CLICK HERE]=
 +
----
 +
</div>
 
=jMonkey SWT bindings=
 
=jMonkey SWT bindings=
[[Image:Screen1.jpg]]<br/>
+
[[Image:Screen1.jpg]]&lt;br/&gt;
 
This screenshot is taken from the image converter we built using jmeswt.
 
This screenshot is taken from the image converter we built using jmeswt.
 
==Overview==
 
==Overview==
Within this entry we will introduce you to the jmeswt plugin that allows developers to get the jMonkey engine into there app.<br/>
+
Within this entry we will introduce you to the jmeswt plugin that allows developers to get the jMonkey engine into there app.&lt;br/&gt;
All our code is release under the LGPL. The contained libraries are compatible with this license (if we overlooked something please inform us).<br/>
+
All our code is release under the LGPL. The contained libraries are compatible with this license (if we overlooked something please inform us).&lt;br/&gt;
Included libraries are:<br/>
+
Included libraries are:&lt;br/&gt;
 
* [http://lwjgl.org/ lwjgl]
 
* [http://lwjgl.org/ lwjgl]
 
* [https://jmephysics.dev.java.net/ jmephysics]
 
* [https://jmephysics.dev.java.net/ jmephysics]
 
* [http://jmonkeyengine.com/ jmonkey]
 
* [http://jmonkeyengine.com/ jmonkey]
This whole library has come from tons of forum posts and a lot of hard work.<br/>
+
This whole library has come from tons of forum posts and a lot of hard work.&lt;br/&gt;
Most notably we included the OffscreenRenderer from Olivier Sambourg and Joshua Slack.<br/>
+
Most notably we included the OffscreenRenderer from Olivier Sambourg and Joshua Slack.&lt;br/&gt;
 
==Installation==
 
==Installation==
We have our own update site right now to make it as convenient as possible to use the plugin: <br/>
+
We have our own update site right now to make it as convenient as possible to use the plugin: &lt;br/&gt;
[http://rifidi.org/update http://rifidi.org/update Rifidi update site]<br/>
+
[http://rifidi.org/update http://rifidi.org/update Rifidi update site]&lt;br/&gt;
Just add this site in Help->Software Updates->find and install ...<br/>
+
Just add this site in Help-&gt;Software Updates-&gt;find and install ...&lt;br/&gt;
After adding it just select org.rifidi.jmeswt:<br/><br/>
+
After adding it just select org.rifidi.jmeswt:&lt;br/&gt;&lt;br/&gt;
[[Image:Screenshot-Updates.png]]<br/>
+
[[Image:Screenshot-Updates.png]]&lt;br/&gt;
Yoiu can also add the second plugin in the list, it's a (alpha!!!!) editor for .dae (collada) files.<br/>
+
Yoiu can also add the second plugin in the list, it's a (alpha!!!!) editor for .dae (collada) files.&lt;br/&gt;
After adding the editor a doubleclick on a file ending with .dae will bring up a 3d view that displays the contents of the file. It's just a little demo app that will be enhanced as we progress on our ide for RifidiDesigner.<br/>
+
After adding the editor a doubleclick on a file ending with .dae will bring up a 3d view that displays the contents of the file. It's just a little demo app that will be enhanced as we progress on our ide for RifidiDesigner.&lt;br/&gt;
The sourccde to this plugin is availabel from our puplic repository.<br/>
+
The sourccde to this plugin is availabel from our puplic repository.&lt;br/&gt;
 
==What's in it==
 
==What's in it==
The plug-in contain two things:<nr/>
+
The plug-in contain two things:&lt;nr/&gt;
 
* A jar with the system provider: This is required as jmonkey uses the old service stuff from sun that requires some MANIFEST magic that apparently doesn't go well with the OSGi classloaders.
 
* A jar with the system provider: This is required as jmonkey uses the old service stuff from sun that requires some MANIFEST magic that apparently doesn't go well with the OSGi classloaders.
 
* The classes that actually form the layer between SWT and jMonkey.
 
* The classes that actually form the layer between SWT and jMonkey.
Line 29: Line 37:
 
** org.rifidi.jmeswt.SWTBaseGame: This is the starting point for SWT based jmonkey games (See next chapter).
 
** org.rifidi.jmeswt.SWTBaseGame: This is the starting point for SWT based jmonkey games (See next chapter).
 
==How to use it==
 
==How to use it==
I assume that you are an Eclipse RCP developer so I will just skip the details for creating an RCP projhect.<br/>
+
I assume that you are an Eclipse RCP developer so I will just skip the details for creating an RCP projhect.&lt;br/&gt;
After creating the project add org.rifidi.jmeswt to your dependencies.<br/>
+
After creating the project add org.rifidi.jmeswt to your dependencies.&lt;br/&gt;
Now create your custom game:<br/>
+
Now create your custom game:&lt;br/&gt;
 
  package test;
 
  package test;
 
   
 
   
Line 71: Line 79:
 
  @Override
 
  @Override
 
  protected void simpleInitGame() {
 
  protected void simpleInitGame() {
  Box myBox=new Box("boxxy", Vector3f.ZERO.clone(), 2f, 2f, 2f);
+
  Box myBox=new Box(&quot;boxxy&quot;, Vector3f.ZERO.clone(), 2f, 2f, 2f);
 
  myBox.setRandomColors();
 
  myBox.setRandomColors();
 
  getRootNode().attachChild(myBox);
 
  getRootNode().attachChild(myBox);
Line 77: Line 85:
 
  }
 
  }
 
  }
 
  }
<br/>
+
&lt;br/&gt;
After creating this game instantiated it in your createPartControl method and hit the start() method after creating it.<br/>
+
After creating this game instantiated it in your createPartControl method and hit the start() method after creating it.&lt;br/&gt;
  MyGame my=new MyGame("gamy",10,20,640,480,parent,true);
+
  MyGame my=new MyGame(&quot;gamy&quot;,10,20,640,480,parent,true);
 
  my.start();
 
  my.start();
 
* The first parameter is a name for the game.
 
* The first parameter is a name for the game.
Line 87: Line 95:
 
* number six is the parent composite for the glCanas.
 
* number six is the parent composite for the glCanas.
 
* the seventh and last one states if this is the only SWTGame running.
 
* the seventh and last one states if this is the only SWTGame running.
The game is now running.<br/>
+
The game is now running.&lt;br/&gt;
 
==Controlling the scene==
 
==Controlling the scene==
Now we want to add a FirstPersonController.<br/>
+
Now we want to add a FirstPersonController.&lt;br/&gt;
To do this add this code to your simpleInitGame() method:<br/>
+
To do this add this code to your simpleInitGame() method:&lt;br/&gt;
 
  getGlCanvas().addKeyListener((KeyListener) KeyInput.get());
 
  getGlCanvas().addKeyListener((KeyListener) KeyInput.get());
 
  getGlCanvas()
 
  getGlCanvas()
Line 112: Line 120:
 
  input.update(interpolation);
 
  input.update(interpolation);
 
  }
 
  }
Start your RCP-app again, click in the 3d window and move around your fancy box.<br/>
+
Start your RCP-app again, click in the 3d window and move around your fancy box.&lt;br/&gt;
As you can see from this example SWTKeyInput and SWTMouseInput are already registered for handling events<br/>
+
As you can see from this example SWTKeyInput and SWTMouseInput are already registered for handling events&lt;br/&gt;
The RenderThread works good but I will add some timing related tweaks soon.<br/>
+
The RenderThread works good but I will add some timing related tweaks soon.&lt;br/&gt;
 
Have Fun :)
 
Have Fun :)
==What does the "simple" parameter in the constructor mean?==
+
==What does the &quot;simple&quot; parameter in the constructor mean?==
Ok, we are in eclipse RCP so mostly you will deal with  multiwindow thing.<br/>
+
Ok, we are in eclipse RCP so mostly you will deal with  multiwindow thing.&lt;br/&gt;
First of all:<br/>
+
First of all:&lt;br/&gt;
If you don't intend to use more than one game/window inside eclipse stop reading here. Everything will work like you are used to it from jmonkey.<br/> You will have your GameTaskQueues as you are used to them and can live happily on without bothering ybout the rest.<br/>
+
If you don't intend to use more than one game/window inside eclipse stop reading here. Everything will work like you are used to it from jmonkey.&lt;br/&gt; You will have your GameTaskQueues as you are used to them and can live happily on without bothering ybout the rest.&lt;br/&gt;
If you, like us, need support for multiple games in one app continue readiung.<br/>
+
If you, like us, need support for multiple games in one app continue readiung.&lt;br/&gt;
When you create let's say two games you will have to set single to false.<br/>
+
When you create let's say two games you will have to set single to false.&lt;br/&gt;
That tells SWTBaseGame to create individual rendering and update queues for each game so that we don't have collisions there.<br/>
+
That tells SWTBaseGame to create individual rendering and update queues for each game so that we don't have collisions there.&lt;br/&gt;
The queues are name "<gamename>.render" and "<gamename>.update". This is important to remember as your callables will have to be sent to the right queues.<br/>
+
The queues are name &quot;&lt;gamename&gt;.render&quot; and &quot;&lt;gamename&gt;.update&quot;. This is important to remember as your callables will have to be sent to the right queues.&lt;br/&gt;
You can also access the queues directly in SWTBaseGame with getUpdateQueue() or getRenderQueue().<br/>
+
You can also access the queues directly in SWTBaseGame with getUpdateQueue() or getRenderQueue().&lt;br/&gt;
 
Right now you can't render to two games at the same time (NOTE: the next release should include functionality for that, but our current app doesn't need that) so call stopRendering() when your game loses the focus and resumeRendering() when it acquires focus. The important thing is that the games don't stop updating!
 
Right now you can't render to two games at the same time (NOTE: the next release should include functionality for that, but our current app doesn't need that) so call stopRendering() when your game loses the focus and resumeRendering() when it acquires focus. The important thing is that the games don't stop updating!

Revision as of 23:21, 23 November 2010


jMonkey SWT bindings

Screen1.jpg<br/> This screenshot is taken from the image converter we built using jmeswt.

Overview

Within this entry we will introduce you to the jmeswt plugin that allows developers to get the jMonkey engine into there app.<br/> All our code is release under the LGPL. The contained libraries are compatible with this license (if we overlooked something please inform us).<br/> Included libraries are:<br/>

This whole library has come from tons of forum posts and a lot of hard work.<br/> Most notably we included the OffscreenRenderer from Olivier Sambourg and Joshua Slack.<br/>

Installation

We have our own update site right now to make it as convenient as possible to use the plugin: <br/> http://rifidi.org/update Rifidi update site<br/> Just add this site in Help->Software Updates->find and install ...<br/> After adding it just select org.rifidi.jmeswt:<br/><br/> Screenshot-Updates.png<br/> Yoiu can also add the second plugin in the list, it's a (alpha!!!!) editor for .dae (collada) files.<br/> After adding the editor a doubleclick on a file ending with .dae will bring up a 3d view that displays the contents of the file. It's just a little demo app that will be enhanced as we progress on our ide for RifidiDesigner.<br/> The sourccde to this plugin is availabel from our puplic repository.<br/>

What's in it

The plug-in contain two things:<nr/>

  • A jar with the system provider: This is required as jmonkey uses the old service stuff from sun that requires some MANIFEST magic that apparently doesn't go well with the OSGi classloaders.
  • The classes that actually form the layer between SWT and jMonkey.
    • org.rifidi.jmeswt.input.SWTKeyInput: This is the KeyInput provider to be used with the different handlers of jmonkey.
    • org.rifidi.jmeswt.input.SWTMouseInput: This is the KeyInput provider to be used with the different handlers of jmonkey.
    • org.rifidi.jmeswt.input.Mapping: This is a static class to provide a fast and extensible way of mapping the different SWT events to LWJGL events. It's about 90% complete with only some minor things missing.
    • org.rifidi.jmeswt.SWTBaseGame: This is the starting point for SWT based jmonkey games (See next chapter).

How to use it

I assume that you are an Eclipse RCP developer so I will just skip the details for creating an RCP projhect.<br/> After creating the project add org.rifidi.jmeswt to your dependencies.<br/> Now create your custom game:<br/>

package test;

import org.eclipse.swt.widgets.Composite;
import org.rifidi.jmeswt.SWTBaseGame;

import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;

/**
 * 
 * 
 * @author Jochen Mader - jochen@pramari.com - Jun 2, 2008
 * 
 */
public class MyGame extends SWTBaseGame {

	/**
	 * @param name
	 * @param updateResolution
	 * @param renderResolution
	 * @param width
	 * @param height
	 * @param parent
	 * @param single
	 */
	public MyGame(String name, int updateResolution, int renderResolution,
			int width, int height, Composite parent, boolean single) {
		super(name, updateResolution, renderResolution, width, height, parent,
				single);
		// TODO Auto-generated constructor stub
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.rifidi.jmeswt.SWTBaseGame#simpleInitGame()
	 */
	@Override
	protected void simpleInitGame() {
		Box myBox=new Box("boxxy", Vector3f.ZERO.clone(), 2f, 2f, 2f);
		myBox.setRandomColors();
		getRootNode().attachChild(myBox);
		getRootNode().updateRenderState();
	}
}

<br/> After creating this game instantiated it in your createPartControl method and hit the start() method after creating it.<br/>

MyGame my=new MyGame("gamy",10,20,640,480,parent,true);
my.start();
  • The first parameter is a name for the game.
  • The second one is the amount of msecs between two updates.
  • The third one is the amount of msecs between two render runs.
  • four and five are start width and height.
  • number six is the parent composite for the glCanas.
  • the seventh and last one states if this is the only SWTGame running.

The game is now running.<br/>

Controlling the scene

Now we want to add a FirstPersonController.<br/> To do this add this code to your simpleInitGame() method:<br/>

		getGlCanvas().addKeyListener((KeyListener) KeyInput.get());
		getGlCanvas()
				.addMouseMoveListener((MouseMoveListener) MouseInput.get());
		getGlCanvas().addMouseListener((MouseListener) MouseInput.get());
		FirstPersonHandler firstPersonHandler = new FirstPersonHandler(display
				.getRenderer().getCamera(), 50, 1);
		input = firstPersonHandler;

And add a global var:

	/**
	 * Handles our mouse/keyboard input.
	 */
	protected InputHandler input;

Now overwrite the update() method:

	/* (non-Javadoc)
	 * @see org.rifidi.jmeswt.SWTBaseGame#update(float)
	 */
	@Override
	protected void update(float interpolation) {
		super.update(interpolation);
		input.update(interpolation);
	}

Start your RCP-app again, click in the 3d window and move around your fancy box.<br/> As you can see from this example SWTKeyInput and SWTMouseInput are already registered for handling events<br/> The RenderThread works good but I will add some timing related tweaks soon.<br/> Have Fun :)

What does the "simple" parameter in the constructor mean?

Ok, we are in eclipse RCP so mostly you will deal with multiwindow thing.<br/> First of all:<br/> If you don't intend to use more than one game/window inside eclipse stop reading here. Everything will work like you are used to it from jmonkey.<br/> You will have your GameTaskQueues as you are used to them and can live happily on without bothering ybout the rest.<br/> If you, like us, need support for multiple games in one app continue readiung.<br/> When you create let's say two games you will have to set single to false.<br/> That tells SWTBaseGame to create individual rendering and update queues for each game so that we don't have collisions there.<br/> The queues are name "<gamename>.render" and "<gamename>.update". This is important to remember as your callables will have to be sent to the right queues.<br/> You can also access the queues directly in SWTBaseGame with getUpdateQueue() or getRenderQueue().<br/> Right now you can't render to two games at the same time (NOTE: the next release should include functionality for that, but our current app doesn't need that) so call stopRendering() when your game loses the focus and resumeRendering() when it acquires focus. The important thing is that the games don't stop updating!