Author Topic: Mouse Mapper  (Read 10191 times)

Offline san14

  • int
  • **
  • Posts: 60
    • View Profile
Mouse Mapper
« on: May 22, 2007, 07:15:22 am »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Mouse Mapper
« Reply #1 on: May 22, 2007, 02:24:58 pm »
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.

Offline san14

  • int
  • **
  • Posts: 60
    • View Profile
Re: Mouse Mapper
« Reply #2 on: May 24, 2007, 03:04:57 pm »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Mouse Mapper
« Reply #3 on: May 24, 2007, 05:50:54 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.

Offline san14

  • int
  • **
  • Posts: 60
    • View Profile
Re: Mouse Mapper
« Reply #4 on: May 29, 2007, 11:28:49 am »
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
« Last Edit: May 29, 2007, 11:34:01 am by san14 »
San14

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Mouse Mapper
« Reply #5 on: May 29, 2007, 11:34:23 am »
Then increase the heap space (java -Xmx256m ....) like the batch-file does it.

Offline san14

  • int
  • **
  • Posts: 60
    • View Profile
Re: Mouse Mapper
« Reply #6 on: May 29, 2007, 12:11:51 pm »
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
« Last Edit: May 31, 2007, 08:58:04 am by san14 »
San14

Offline san14

  • int
  • **
  • Posts: 60
    • View Profile
Re: Mouse Mapper
« Reply #7 on: May 31, 2007, 09:52:15 am »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Mouse Mapper
« Reply #8 on: May 31, 2007, 10:10:21 am »
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.

Offline san14

  • int
  • **
  • Posts: 60
    • View Profile
Re: Mouse Mapper
« Reply #9 on: May 31, 2007, 12:20:51 pm »
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
 
« Last Edit: May 31, 2007, 12:25:40 pm by san14 »
San14

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Mouse Mapper
« Reply #10 on: May 31, 2007, 12:49:39 pm »
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.

Offline san14

  • int
  • **
  • Posts: 60
    • View Profile
Re: Mouse Mapper
« Reply #11 on: June 02, 2007, 09:42:04 am »
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
« Last Edit: June 02, 2007, 10:34:14 am by san14 »
San14

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Mouse Mapper
« Reply #12 on: June 02, 2007, 11:26:57 am »
Something like this should work:

Code: [Select]
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;
      }
   }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Mouse Mapper
« Reply #13 on: June 03, 2007, 02:27:24 pm »
I forgot that you have to make a call to mouse.hide(); to make the getDelta???()-methods work.

Offline san14

  • int
  • **
  • Posts: 60
    • View Profile
Re: Mouse Mapper
« Reply #14 on: June 04, 2007, 01:31:16 pm »
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
« Last Edit: June 04, 2007, 01:44:36 pm by san14 »
San14