www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: san14 on May 22, 2007, 07:15:22 am

Title: Mouse Mapper
Post by: san14 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
Title: Re: Mouse Mapper
Post by: EgonOlsen 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.
Title: Re: Mouse Mapper
Post by: san14 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


Title: Re: Mouse Mapper
Post by: EgonOlsen 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.
Title: Re: Mouse Mapper
Post by: san14 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
Title: Re: Mouse Mapper
Post by: EgonOlsen on May 29, 2007, 11:34:23 am
Then increase the heap space (java -Xmx256m ....) like the batch-file does it.
Title: Re: Mouse Mapper
Post by: san14 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
Title: Re: Mouse Mapper
Post by: san14 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
Title: Re: Mouse Mapper
Post by: EgonOlsen 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.
Title: Re: Mouse Mapper
Post by: san14 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
 
Title: Re: Mouse Mapper
Post by: EgonOlsen 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.
Title: Re: Mouse Mapper
Post by: san14 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
Title: Re: Mouse Mapper
Post by: EgonOlsen 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;
      }
   }
Title: Re: Mouse Mapper
Post by: EgonOlsen 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.
Title: Re: Mouse Mapper
Post by: san14 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
Title: Re: Mouse Mapper
Post by: EgonOlsen on June 04, 2007, 01:48:40 pm
Init the MouseMapper, call mouse.hide() on it. Do both things ONE time, not multiple times in the loop.
Call move() in the loop. Should work.
Title: Re: Mouse Mapper
Post by: san14 on June 05, 2007, 08:17:50 am
Hi EgonOlsen
     
        Is it what I need to do As
       private void initMouseMapper(){
                            mouse.hide();
     
              }
              private void gameLoop() throws Exception {
                            move();
             }
       
       



         Is some thing else to be done in initMouseMapper(). As i tried with this and could not do.


With Regards
San14


Title: Re: Mouse Mapper
Post by: EgonOlsen on June 05, 2007, 08:33:49 am
Looks fine so far. Maybe you application does something else with the camera that makes the call to move() useless. Look at move() and adept what it does to your case. I don't know what you are doing exactly, so this example is for manipulating the camera as if no other code would do it. If it does, you have to adjust that behaviour.
Title: Re: Mouse Mapper
Post by: san14 on June 13, 2007, 11:27:40 am
HI EgonOlsen

     The mouse code is working fine. I have tried to put forward movement as
                 
            float speedForMouse=3;

             if (mouse.buttonDown(0)) {
                      SimpleVector s=camera.getDirection();
                theWorld.checkCameraCollisionEllipsoid(s, UP_MOVEMENT, 2, 2);              
              }

             
            And is Working fine
           How do I do same for Right Click of Mouse


With Regards
san14
Title: Re: Mouse Mapper
Post by: EgonOlsen on June 13, 2007, 12:14:15 pm
mouse.buttonDown(1) ?
Title: Re: Mouse Mapper
Post by: san14 on June 13, 2007, 12:39:31 pm
Thanks EgonOlsen
     
        It worked.  :D

With Regards
San14
Title: Re: Mouse Mapper
Post by: san14 on July 11, 2007, 12:22:47 pm
HI
    I am able to move in environment using mouse. I want to move in front and back , even if i am seeing at roof..etc.

   Means Player should not leave the floor while seeing roof and walking ahead.
   This is the code for normal movement. Can some one help me out with it.


 if (mouse.buttonDown(0)) {              
         SimpleVector s=camera.getDirection(); 
         theWorld.checkCameraCollisionEllipsoid(s, UP_MOVEMENT, 2, 2);
     }

 if (mouse.buttonDown(1)) {              
           SimpleVector s=camera.getDirection();
         theWorld.checkCameraCollisionEllipsoid(s, UP_MOVEMENT, -2, 2);
    }



With Regards
San14
Title: Re: Mouse Mapper
Post by: EgonOlsen on July 11, 2007, 02:35:17 pm
The fps-example as well as the advanced example are doing this. The basic idea is, to keep track of the rotations in the X-Z-plane (i.e. around the y-axis) in the seperate matrix instead of only turning the camera. You have to modify the rotations for x-mouse-movement (dx<0; dx>0) in a way that you add a <your-tracking-matrix>.rotateY(angle);. Then you can use this matrix instead of the camera's so that SimpleVector s=camera.getDirection(); becomes something like SimpleVector s=<your-tracking-matrix>.getZAxis();
As said: Both examples contain similar code. In fact, this thread contains similar code (taken from the advanced example) in the earlier posts.
Title: Re: Mouse Mapper
Post by: san14 on August 08, 2007, 12:46:09 pm
Hi EgonOlsen

      I looked for movements in Advance example but could not make out. But I am able to achive the movements using this code. But the problem is that When I take turn the user. The user forgets the direction and moves in other direction.


  if (mouse.buttonDown(0)) { 
             SimpleVector s=camera.getDirection();
           SimpleVector ss=new Matrix().getZAxis();
                   theWorld.checkCameraCollisionEllipsoid(ss, UP_MOVEMENT, 2, 2);

       
     }
    if (mouse.buttonDown(1)) {              
           SimpleVector s=camera.getDirection();
           SimpleVector ss=new Matrix().getZAxis();
                   theWorld.checkCameraCollisionEllipsoid(ss, UP_MOVEMENT, -2, 2);
     }



Can suggest how to go about this


With Regards
San14
Title: Re: Mouse Mapper
Post by: EgonOlsen on August 08, 2007, 07:04:54 pm
That code makes no sense. It's a very complicated of saying: Just move along the z-axis. Instead of instantiating the Matrix for ss everytime, do it once and apply the rotations of the user to it, i.e. you are now doing a cam.rotateAxis(com.getYAxis(), ang) or something similar. You simply add (not replace) a <your_matrix>.rotateY(ang); and use that <your_matrix> to derive your ss from it.
Title: Re: Mouse Mapper
Post by: san14 on August 09, 2007, 03:15:39 pm
Hi EgonOlsen
   
       Please can you tell me, which portion or file implements this kind of mouse movement in Advance Example.


With Regards
San14
Title: Re: Mouse Mapper
Post by: EgonOlsen on August 09, 2007, 03:57:53 pm
Sure. That's feud.testgame.model.LocalPlayerObject