Mouse Mapper

Started by san14, May 22, 2007, 07:15:22 AM

Previous topic - Next topic

san14

Hi
 
   I am trying to implement mouse in JPCTDemo.java type example. I want to move into environment like We do by keyboard.

  Any one could help me out with suggesion or code to implement mouse in such type of example..


With Regards
San14
San14

EgonOlsen

The advanced example in the News-section contains a simple MouseMapper für OpenGL-rendering. If you still have the Paradriodz-sources somewhere (i don't distribute them any longer): They contain a more advanced MouseMapper that supports software- and AWTGL-mode, too.

san14

Hi EgonOlsen

    I am trying to implement MouseMapper (One from News-section) in JPCTDemo.java type example. I have called
       
   
        private MouseMapper mouse = null;

        mouse = new MouseMapper(buffer);
   


     and called mouse = new MouseMapper(buffer); in gameLoop(); in JPCTDemo.java  Is this, is the way to do it. Could you suggest me for the same. I am not geting it.


With Regards
San14


San14

EgonOlsen

Quote from: san14 on May 24, 2007, 03:04:57 PM
     and called mouse = new MouseMapper(buffer); in gameLoop(); i....
Not a good idea...just poll the mouse-instance for the mouse coordinates. As mentioned, there's the "advanced example". It does the fps-like mouse movement you are looking for. Just have a look on how it's done there.

san14

#4
Hi EgonOlsen


     I tried web start and is working fine But when I downloaded code for it and compiled, It comes to a  black screen and then comes out with error message as


Loading textures...
Loading level...
Loading Texture...from InputStream
Loading Texture...from InputStream
Loading Texture...from InputStream
Loading Texture...from InputStream
Loading file from InputStream
File from InputStream loaded...23908 bytes
Processing new material Cielo!
Processing object from 3DS-file: Sphere02
Object 'Sphere02_jPCT-1' created using 1024 polygons and 514 vertices.
Java version is: 1.5.0_06
-> support for BufferedImage
Version helper for 1.2+ initialized!
-> using BufferedImage
Software renderer (OpenGL mode) initialized
Software renderer disposed
Current mode:800 x 600 x 32 @70Hz
Driver is: ialmrnt5/6.14.10.3847
OpenGL renderer initialized (using 4 texture stages)
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space


With Regards
san14
San14

EgonOlsen

Then increase the heap space (java -Xmx256m ....) like the batch-file does it.

san14

#6
Thanks EgonOlsen

    I increased the heap space (java -Xmx256m ....)  to (java -Xmx456m ....) and Its working fine now(Using bat file ) .
  In Code what do i need to chage to increase the heap space.  To make the code working on my system.


With Regards
San14
San14

san14

Hi
    Mouse Movement in advanced example in the News-section is quit good and that is what i am looking for. But is much dependent on client server base. I find quit difficult to change it for my Stand alone code (fps example ) Could you plz give some simple example for similar type. That would be of great help to beginners like me.


With Regards
San14
San14

EgonOlsen

It doesn't really matter if this example uses a client/server-based approach or not. The code for using the mouse to move the player is exactly the same and doesn't touch the server-side. There's a game loop which calls player.move(....); which does the mouse movement. In this example, it does it on a simple data object containing just the position and the rotation of the player. If you don't want/need that, do it directly on the camera instead. What you basically have to do, is to get the delta-values in x/y direction from the mouse (the mapper does this for you) and rotate accordingly. It's really quite simple.

san14

#9
Hi EgonOlsen

I tried for your  this  suggesion 
Quote
  If you don't want/need that, do it directly on the camera instead. What you basically have to do, is to get the delta-values in x/y direction from the mouse (the mapper does this for you) and rotate accordingly. It's really quite simple.


  I don't know I am dong right or wrong This is something I tried But could not get result Could give some more hints to me



         
class JPCTDemo  implements Runnable{

    private MouseMapper mouse = null;


  JPCTDemo(String[] args) {
           mouse = new MouseMapper();
   }

   private void gameLoop() {
         while (!exit) {

               if (!isIdle) {
           
                      long difTicks=(timerTicks-ticks);
                      ticks=timerTicks;

                for (int i=0; i<difTicks; i++) {
                    mouse.getDeltaX();
                       mouse.getDeltaY();           
   
                     doMovement();
                }
      if (openGL) {
                            
                     pollLWJGLKeys();
                }

     }
   }


}
         


   Do I need to change at or some other place to
   
private void keyAffected(int code, boolean event) {
      switch (code) {
         case (KeyEvent.VK_ESCAPE): {
            exit=event;
            break;
         }


With Regards
San14
 
San14

EgonOlsen

Do something with the deltas! You are just calling the methods. There's no magic that makes the rotations...it's up to you. Look at the example (LocalPlayerObject) on how to use them to do the rotations.

san14

#11
Hi EgonOlse
         
       I have tried to understand with my limited gaming knowledge. I have made changes to this method and tried to call in fps game loop as  move(theWorld,mouse);
But did not work. could you plz help me out with this. Am i near to the solution

                                           
         public void move(World world,  MouseMapper mouse) {
           SimpleVector pos = getPosition();
           if (pos != null) {
              
               pos.add(new SimpleVector(0, ellipsoid.y, 0));
               SimpleVector dir = world.checkCollisionEllipsoid(pos, null, ellipsoid, 1);
               pos.add(new SimpleVector(0, -ellipsoid.y, 0));
               dir.x = 0;
               dir.z = 0;
               pos.add(dir);
               setSpeed(dir);

               pos.add(new SimpleVector(0, ellipsoid.y, 0));

            
               Matrix rot = getRotation();

               int dx = mouse.getDeltaX();
               int dy = mouse.getDeltaY();

               float ts = turnSpeed ;
               float tsy = ts;

               if (dx != 0) {
                   ts = Math.abs(dx) / -500f;
               }
               if (dy != 0) {
                   tsy = Math.abs(dy) / 500f;
               }

               if (dx < 0) {
                   viewRot.rotateAxis(viewRot.getYAxis(), ts);
                   rot.rotateY(ts);
               }

               if (dx > 0) {
                   viewRot.rotateAxis(viewRot.getYAxis(), -ts);
                   rot.rotateY( -ts);
               }

              
               pos.add(new SimpleVector(0, -ellipsoid.y, 0));
              camera.setPosition(pos);
           }
          
       }
                                           


With Regards
San14
San14

EgonOlsen

Something like this should work:


private void move() {
      Matrix rot=world.getCamera().getBack();
      int dx=mouse.getDeltaX();
      int dy=mouse.getDeltaY();

      float ts=0.2f;
      float tsy=ts;

      if (dx!=0) {
         ts=Math.abs(dx)/-500f;
      }
      if (dy!=0) {
         tsy=Math.abs(dy)/500f;
      }

      if (dx<0) {
         rot.rotateAxis(rot.getYAxis(), ts);
      }

      if (dx>0) {
         rot.rotateAxis(rot.getYAxis(), -ts);
      }

      if (dy>0&&xAngle<Math.PI/4.2) {
         rot.rotateX(tsy);
         xAngle+=tsy;
      }
      if (dy<0&&xAngle>-Math.PI/4.2) {
         rot.rotateX(-tsy);
         xAngle-=tsy;
      }
   }

EgonOlsen

I forgot that you have to make a call to mouse.hide(); to make the getDelta???()-methods work.

san14

#14
Hi EgonOlsen

    Thanks for the code. But I could not make it work. I called mouse.hide(); in gameLoop()  (fps example),  Is it just to call method or some thing else to be done.

    With Regards
    San14
San14