   [java] JOGL good Camera (A S D W and Mouse)
  Does anyone knows a good Camera class for java that works wit A S D W buttons and mouse moviments?att.Marcelo Luiz Onhate   
  here you go, that'S the first person cam I use with Jogl:public class FirstPersonCam implements Camera, KeyListener, MouseMotionListener, GLEventListener{    private static final int forward = KeyEvent.VK_W;    private static final int backward = KeyEvent.VK_S;    private static final int leftward = KeyEvent.VK_A;    private static final int rightward = KeyEvent.VK_D;    private static final int space = KeyEvent.VK_SPACE;    private static final int shift = KeyEvent.VK_SHIFT;    private static final int mouseSpeed = 1;    private static final int keySpeed = 3;    private static final int rotVMax = 1;    private static final int rotVMin = -1;    private final Map<Integer, Boolean> keys = new ConcurrentHashMap<Integer, Boolean>();    private final float[] modelview = new float[16];    private final GLCanvas canvas;    private final Robot robot;    private float rotX, rotY, rotZ, rotV;    private float posX, posY, posZ;    private int centerX, centerY;    private long lastTime = -1;    // a very simple first person shooter style camera    public FirstPersonCam(final GLCanvas canvas)    {   // we need the robot to get full control over the mouse   Robot r = null;   try {  r = new Robot();   } catch (final AWTException e) {  e.printStackTrace();   }   // setup the modelview matrix   for (int i = 0; i < 4; i++)  modelview = <span class="cpp-number">1</span>.0f;<br><br>   <span class="cpp-keyword">this</span>.canvas = canvas;<br>   <span class="cpp-keyword">this</span>.robot = r;<br><br>   canvas.addKeyListener(<span class="cpp-keyword">this</span>);<br>   canvas.addMouseMotionListener(<span class="cpp-keyword">this</span>);<br>   canvas.addGLEventListener(<span class="cpp-keyword">this</span>);<br><br>    }<br><br>    <span class="cpp-comment">/**<br>* Berrechnet die aktuelle View Matrix aus der aktuellen Kamera Position<br>*/</span><br>    <span class="cpp-keyword">public</span> ViewMatrix getViewMatrix() {<br>   calculatePosition();<br>   calculateModelview();<br>   <span class="cpp-keyword">return</span> <span class="cpp-keyword">new</span> ViewMatrix(modelview);<br>    }<br><br>    <span class="cpp-keyword">private</span> <span class="cpp-keyword">void</span> calculatePosition()<br>    {<br><br>   <span class="cpp-keyword">if</span> (lastTime == -<span class="cpp-number">1</span>)<br>  lastTime = System.nanoTime();<br><br>   <span class="cpp-keyword">double</span> mul = <span class="cpp-number">1</span>.<span class="cpp-number">0</span>;<br><br>   Boolean value = null;<br>   <span class="cpp-keyword">if</span> ((value = keys.get(shift)) != null &amp;&amp; value == <span class="cpp-keyword">true</span>)<br>  mul = <span class="cpp-number">0</span>.<span class="cpp-number">1</span>;<br><br>   final <span class="cpp-keyword">double</span> speed = keySpeed * -((lastTime - (lastTime = System.nanoTime())) / 10E7) * mul;<br><br><br>   <span class="cpp-keyword">if</span> ((value = keys.get(forward)) != null &amp;&amp; value == <span class="cpp-keyword">true</span>) {<br><br>  posX -= Math.sin(rotY) * speed;<br>  posZ += Math.cos(rotY) * speed;<br>  posY += rotV * speed;<br>   }<br><br>   <span class="cpp-keyword">if</span> ((value = keys.get(backward)) != null &amp;&amp; value == <span class="cpp-keyword">true</span>) {<br><br>  posX += Math.sin(rotY) * speed;<br>  posZ -= Math.cos(rotY) * speed;<br>  posY -= rotV * speed;<br>   }<br><br>   <span class="cpp-keyword">if</span> ((value = keys.get(leftward)) != null &amp;&amp; value == <span class="cpp-keyword">true</span>) {<br><br>  posX += Math.cos(rotY) * speed;<br>  posZ += Math.sin(rotY) * speed;<br><br>   }<br><br>   <span class="cpp-keyword">if</span> ((value = keys.get(rightward)) != null &amp;&amp; value == <span class="cpp-keyword">true</span>) {<br><br>  posX -= Math.cos(rotY) * speed;<br>  posZ -= Math.sin(rotY) * speed;<br><br>   }<br><br>    }<br><br>    <span class="cpp-keyword">private</span> <span class="cpp-keyword">void</span> calculateModelview()<br>    {<br><br>   final <span class="cpp-keyword">float</span> sinX = (<span class="cpp-keyword">float</span>) Math.sin(rotX);<br>   final <span class="cpp-keyword">float</span> sinY = (<span class="cpp-keyword">float</span>) Math.sin(rotY);<br>   final <span class="cpp-keyword">float</span> sinZ = (<span class="cpp-keyword">float</span>) Math.sin(rotZ);<br><br>   final <span class="cpp-keyword">float</span> cosX = (<span class="cpp-keyword">float</span>) Math.cos(rotX);<br>   final <span class="cpp-keyword">float</span> cosY = (<span class="cpp-keyword">float</span>) Math.cos(rotY);<br>   final <span class="cpp-keyword">float</span> cosZ = (<span class="cpp-keyword">float</span>) Math.cos(rotZ);<br><br>   modelview[<span class="cpp-number">0</span>] = cosY * cosZ + sinY * sinX * sinZ;<br>   modelview[<span class="cpp-number">1</span>] = cosX * sinZ;<br>   modelview[<span class="cpp-number">2</span>] = -sinY * cosZ + cosY * sinX * sinZ;<br>   modelview[<span class="cpp-number">4</span>] = -cosY * sinZ + sinY * sinX * cosZ;<br>   modelview[<span class="cpp-number">5</span>] = cosX * cosZ;<br>   modelview[<span class="cpp-number">6</span>] = sinY * sinZ + cosY * sinX * cosZ;<br>   modelview[<span class="cpp-number">8</span>] = sinY * cosX;<br>   modelview[<span class="cpp-number">9</span>] = -sinX;<br>   modelview[<span class="cpp-number">10</span>] = cosY * cosX;<br><br>   modelview[<span class="cpp-number">12</span>] = modelview[<span class="cpp-number">0</span>] * posX + modelview[<span class="cpp-number">4</span>] * posY + modelview[<span class="cpp-number">8</span>] * posZ;<br>   modelview[<span class="cpp-number">13</span>] = modelview[<span class="cpp-number">1</span>] * posX + modelview[<span class="cpp-number">5</span>] * posY + modelview[<span class="cpp-number">9</span>] * posZ;<br>   modelview[<span class="cpp-number">14</span>] = modelview[<span class="cpp-number">2</span>] * posX + modelview[<span class="cpp-number">6</span>] * posY + modelview[<span class="cpp-number">10</span>] * posZ;<br><br>    }<br>    <br>    <span class="cpp-keyword">public</span> <span class="cpp-keyword">void</span> setPosition(<span class="cpp-keyword">float</span> x, <span class="cpp-keyword">float</span> y, <span class="cpp-keyword">float</span> z){<br>   posX = x;<br>   posY = y;<br>   posZ = z;<br>    }<br><br>    @Override<br>    <span class="cpp-keyword">public</span> <span class="cpp-keyword">void</span> init(final GLAutoDrawable drawable)<br>    {}<br><br>    <br>    @Override<br>    <span class="cpp-keyword">public</span> <span class="cpp-keyword">void</span> reshape(final GLAutoDrawable drawable, final <span class="cpp-keyword">int</span> x, final <span class="cpp-keyword">int</span> y, final <span class="cpp-keyword">int</span> width, final <span class="cpp-keyword">int</span> height)<br>    {<br>   rotV = <span class="cpp-number">0</span>;<br>   final Rectangle r = canvas.getParent().getBounds();<br>   final Point p = canvas.getParent().getLocationOnScreen();<br><br>   centerX = r.x + p.x + width / <span class="cpp-number">2</span>;<br>   centerY = r.y + p.y + height / <span class="cpp-number">2</span>;<br>   Boolean value = null;<br>   <span class="cpp-keyword">if</span> ((value = keys.get(space)) != null &amp;&amp; value == <span class="cpp-keyword">true</span>)<br>  <span class="cpp-keyword">if</span> (robot != null)<br> robot.mouseMove(centerX, centerY);<br>    }<br><br>    <br>    @Override<br>    <span class="cpp-keyword">public</span> <span class="cpp-keyword">void</span> mouseMoved(final MouseEvent e)<br>    {<br><br>   Boolean value = null;<br>   <span class="cpp-keyword">if</span> ((value = keys.get(space)) != null &amp;&amp; value == <span class="cpp-keyword">true</span>) {<br>  rotY -= (centerX - e.getXOnScreen()) / <span class="cpp-number">1000</span>.<span class="cpp-number">0</span> * mouseSpeed;<br>  rotV -= (centerY - e.getYOnScreen()) / <span class="cpp-number">1000</span>.<span class="cpp-number">0</span> * mouseSpeed;<br><br>  <span class="cpp-keyword">if</span> (rotV &gt; rotVMax)<br> rotV = rotVMax;<br><br>  <span class="cpp-keyword">if</span> (rotV &lt; rotVMin)<br> rotV = rotVMin;<br><br>  rotX = (<span class="cpp-keyword">float</span>) Math.cos(rotY) * rotV;<br>  rotZ = (<span class="cpp-keyword">float</span>) Math.sin(rotY) * rotV;<br><br>  <span class="cpp-keyword">if</span> (robot != null)<br> robot.mouseMove(centerX, centerY);<br>   }<br><br>    }<br><br>    @Override<br>    <span class="cpp-keyword">public</span> <span class="cpp-keyword">void</span> mouseDragged(final MouseEvent e)<br>    {<br><br>   mouseMoved(e);<br><br>    }<br><br>    @Override<br>    <span class="cpp-keyword">public</span> <span class="cpp-keyword">void</span> keyPressed(final KeyEvent e)<br>    {<br><br>   keys.put(e.getKeyCode(), <span class="cpp-keyword">true</span>);<br><br>    }<br><br>    @Override<br>    <span class="cpp-keyword">public</span> <span class="cpp-keyword">void</span> keyReleased(final KeyEvent e)<br>    {<br><br>   keys.put(e.getKeyCode(), <span class="cpp-keyword">false</span>);<br><br>    }<br><br>    @Override <span class="cpp-keyword">public</span> <span class="cpp-keyword">void</span> keyTyped(final KeyEvent e)<br>    {<br>    }<br><br>    @Override <span class="cpp-keyword">public</span> <span class="cpp-keyword">void</span> display(final GLAutoDrawable drawable)<br>    {<br>    }<br><br>    <span class="cpp-keyword">public</span> <span class="cpp-keyword">void</span> dispose(GLAutoDrawable drawable)<br>    {<br>    }<br>}<br><br></pre></div><!–ENDSCRIPT–> ;  Thank You! Very helpfull!   