Can't handle Keyboard-Input

Have jReality programming problems or questions? Post them here.
Post Reply
goetz
Posts: 12
Joined: Sun 7. Jun 2009, 09:48

Can't handle Keyboard-Input

Post by goetz » Sun 7. Jun 2009, 09:58

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.

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: Can't handle Keyboard-Input

Post by gunn » Mon 8. Jun 2009, 10:44

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.
jReality core developer

User avatar
steffen
Posts: 186
Joined: Fri 16. Jun 2006, 13:30
Location: TU Berlin
Contact:

Re: Can't handle Keyboard-Input

Post by steffen » Mon 8. Jun 2009, 22:00

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...

goetz
Posts: 12
Joined: Sun 7. Jun 2009, 09:48

Re: Can't handle Keyboard-Input

Post by goetz » Tue 9. Jun 2009, 10:31

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

goetz
Posts: 12
Joined: Sun 7. Jun 2009, 09:48

Re: Can't handle Keyboard-Input

Post by goetz » Tue 9. Jun 2009, 15:37

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.

User avatar
steffen
Posts: 186
Joined: Fri 16. Jun 2006, 13:30
Location: TU Berlin
Contact:

Re: Can't handle Keyboard-Input

Post by steffen » Tue 9. Jun 2009, 15:56

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.

goetz
Posts: 12
Joined: Sun 7. Jun 2009, 09:48

Re: Can't handle Keyboard-Input

Post by goetz » Mon 22. Jun 2009, 16:44

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.

Post Reply