Page 1 of 1

Can't handle Keyboard-Input

Posted: Sun 7. Jun 2009, 09:58
by goetz
Hello,

I wrote a small application which uses a stand-alone-viewer, just like in your tutorial ViewerFromScratch, but is there any way to use keyboard-input for the avatar-navigation (like WASD-keys for navigation with fixed y-axis)? I'm not able to find any hint on this topic but it works fine in the applications, that uses the vr-viewer...

thx for your help!

edit:
I was able to add a keylistener in my viewer-class, like this:

Code: Select all

Component comp = ((Component) this.getViewingComponent());
		comp.addKeyListener(new KeyAdapter() {
 				public void keyPressed(KeyEvent input)	{
					switch(input.getKeyCode())	{

					case KeyEvent.VK_W:
But, how do I edit the transformation-matrix of the transformation, that is bound to the camera, to move for example on x-axis?

edit:

I was able to handle translation about all 3 directions with this:

Code: Select all

m = camNode.getTransformation().getMatrix();
                       m[3]-=0.1;
                        camNode.getTransformation().setMatrix(m);
But, how can I handle rotation around z-axis? When I try like in the code above, it screws my perspective.

Re: Can't handle Keyboard-Input

Posted: Mon 8. Jun 2009, 10:44
by gunn
Since I don't know exactly what code you used in trying to rotate around the z-axis, I can't for sure say where the problem lies. But a good class to use for generating isometries of all kinds is de.jreality.math.MatrixBuilder. There is unfortunately no tutorial directly addressing how to use this class but the JavaDoc isn't bad: http://www3.math.tu-berlin.de/jreality/api/ (and then select package and class).

In particular, I'd recommend using something like this:

Code: Select all

Matrix m =camNode.getTransformation().getMatrix();
MatrixBuilder.euclidean(m).rotateZ(.1).assignTo(camNode); 
This will concatenate a rotation around the z-axis of .1 radians (about 6 degrees) to the transformation of the camera node.

Re: Can't handle Keyboard-Input

Posted: Mon 8. Jun 2009, 22:00
by steffen
is there any way to use keyboard-input for the avatar-navigation (like WASD-keys for navigation with fixed y-axis)?
You can just add a ShipNavigationTool to your avatar node (this is intended to be the node below the camera, the idea is that we navigate the feet of the avatar instead of its head...) But if you dont want to do something very special, I suggest you use a JRViewer and say .addVRSupport(). Unfortunately, this code is really fresh and so tutorials are not completely up-to-date. Or stick with the ViewerVR for now...
Edit: I hope you have jreality checked out from svn, our download section is out-dated at the moment. It will be updated this week...

Re: Can't handle Keyboard-Input

Posted: Tue 9. Jun 2009, 10:31
by goetz
Hello,

I tried ShipNavigationTool and added it to the camNode, it worked fine. Thanks for your suggestions.

At this moment I just downloaded the JARs from the download-section, but I will try the SVN this afternoon.

Greetings from the University of Wuppertal,

Goetz

Re: Can't handle Keyboard-Input

Posted: Tue 9. Jun 2009, 15:37
by goetz
SVN-Checkout didn't work with NetBeans 6.5 on Ubuntu 9.04...

==[IDE]== 09.06.2009 14:50:14 Connecting to Subversion Repository...
Autorisierung schlug fehl
svn: OPTIONS von »http://fs.math.tu-berlin.de:8000/svn/jreality«: Autorisierung schlug fehl (http://fs.math.tu-berlin.de:8000)

I guess it's my fault, because test-login via webbrowser worked fine.

Re: Can't handle Keyboard-Input

Posted: Tue 9. Jun 2009, 15:56
by steffen
Yes, login: guest with empty password will work...

BTW: the svn contains an Eclipse project, so setting it all up with Eclipse is much easier - and there is a tutorial for that in the wiki. For netbeans, you need to use all the src-* folders as src-folders, and add most of the jars from the lib folder.

Re: Can't handle Keyboard-Input

Posted: Mon 22. Jun 2009, 16:44
by goetz
For danny.lesnik:

The trick with Keyboard-Input is to not add the ShipNavigationTool to the camera itself, but to add it to the avatar. I first made the mistake to add it to the cam-node, but this is not necessary (btw it's not what it is made for).

I'd recommend you to stick with the JRViewer and add an avatar to it. In my oppinion, the JRViewer is the best viewer for quick results and very good custom-handling with tools and plugins.
I did it like this:

Code: Select all

SceneGraphComponent mainSGC = new SceneGraphComponent("test");

    	JRViewer viewer = new JRViewer();
    	viewer.setContent(mainSGC);
    	viewer.setShowMenuBar(false);
    	//Adding avatar-plugin for user navigation
    	Avatar avatar = new Avatar();
    	
    	viewer.registerPlugin(avatar);
    	
    	viewer.startup();
    	avatar.setNavigationSpeed(50);
The important thing is to check out the svn, because the newest classes (like JRViewer) are unfortunality not for download yet.

Please, take this as an answer to your IM, because I thought, this might be interesting for other people too.

Thanks to the jReality-ppl for this ingenious piece of software.