Cheers. I'm still having difficulties though. When I go up it works fine, but left, right and back it just stalls the program?
 
Here's the methods in question as it is (all other methods are similar to the original):
I've not used stepper because he tends to shoot off in the distance if there's a bit of lag
 
////////////////////////////// START moveStep()
 
private void moveStep()   
        {
   float sidestep = 0;
   float upstep = 0;
   
           
            if (rightDown || leftDown || fwDown || downDown)
            {
 
                upSum=0;              
                double stepper = getStep();
                Transform3D tempTrans = new Transform3D();
                Transform3D ourTrans = new Transform3D();
                ourTG.getTransform(ourTrans);
               
                if (rightDown || leftDown)
                {
                    if (rightDown)
                    {   
                        //tempTrans.rotY(0-0.2d);
                        sidestep-=0.2;
                        upSum++;
 
                    }   
                    else
                    {
        //tempTrans.rotY(0.2d);
                       sidestep+=0.2;
                       upSum++;
                      
                    }
                }
                 if (fwDown)
                {
        upstep+=0.2;
                      upSum++;
 
                      Point3d pickStart=new Point3d();
                      Vector3d down = new Vector3d(0.0, -1.0, 0.0);
                      Transform3D newT3d = new Transform3D();
                      newT3d.setTranslation(new Vector3d(0.0, 1.0, 0.2d));
                      newT3d.mul(ourTrans);
                      newT3d.transform(pickStart);
                     
                      picker.setShapeRay(pickStart, down);
 
                     
                      PickResult picked = null;
                      PickIntersection intersect = null;
                      Point3d nextpoint = null;
                      double pickY = 0;
                     
                      try{
                      picked = picker.pickClosest();
 
                      intersect = picked.getIntersection(0);
                      nextpoint = intersect.getPointCoordinates();
                      pickY = (pickStart.y);
                     }catch(Exception fd){return;}
                     
                      pickY = pickY-1.0;
 
                        if (nextpoint != null)
                        {
                            if (nextpoint.y != pickY)
                            {
                                Vector3d translate = new Vector3d();
                                ourTrans.get(translate);
                                translate.y=nextpoint.y;
                                ourTrans.setTranslation(translate);
                                //ourTrans.setTranslation(new Vector3d(pickStart.x, nextpoint.y, pickStart.z));
                            }   
                        }
                     
                     
                }
                if (downDown)
                {
        upstep-=0.2;
                      upSum++;
 
                      Point3d pickStart=new Point3d();
                      Vector3d down = new Vector3d(0.0, -1.0, 0.0);
                      Transform3D newT3d = new Transform3D();
                      newT3d.setTranslation(new Vector3d(0.0, 1.0, 0.2d));
                      newT3d.mul(ourTrans);
                      newT3d.transform(pickStart);
                     
                      picker.setShapeRay(pickStart, down);
 
                     
                      PickResult picked = null;
                      PickIntersection intersect = null;
                      Point3d nextpoint = null;
                      double pickY = 0;
                     
                      try{
                      picked = picker.pickClosest();
 
                      intersect = picked.getIntersection(0);
                      nextpoint = intersect.getPointCoordinates();
                      pickY = (pickStart.y);
                     }catch(Exception fd){return;}
                     
                      pickY = pickY-1.0;
 
                        if (nextpoint != null)
                        {
                            if (nextpoint.y != pickY)
                            {
                                Vector3d translate = new Vector3d();
                                ourTrans.get(translate);
                                translate.y=nextpoint.y;
                                ourTrans.setTranslation(translate);
                                //ourTrans.setTranslation(new Vector3d(pickStart.x, nextpoint.y, pickStart.z));
                            }   
                        }
                     
                     
                }
              
               tempTrans.setTranslation(new Vector3d(0.0d, sidestep, upstep));
               System.err.println("      Stepper is "+stepper);
               ourTrans.mul(tempTrans);
               ourTG.setTransform(ourTrans);
               translateCamera(ourTrans);
               wakeupOn(keepUpCondition);
            }
    }
 
 
////////////////////////////// END moveStep()
 
////////////////////////////// START processAWTEvent
 
private void processAWTEvent(AWTEvent[] events)
    {
             
       
        for (int n=0;n<events.length;n++)
        {
            if (events[n] instanceof KeyEvent)
            {
                KeyEvent ek = (KeyEvent) events[n];               
 
                if (ek.getID() == KeyEvent.KEY_PRESSED)
                {
                    System.err.println("key event "+ek.getKeyChar());
                    if (ek.getKeyChar() == 'w')
                    {
                        alpha.setStartTime(System.currentTimeMillis());
                        walking=true;
                        fwDown= true;
                        getStep();
                        upSum++;
                    }
                    else if (ek.getKeyChar() == 'a')
                    {
                     alpha.setStartTime(System.currentTimeMillis());
                     walking=true;
                        getStep();
                        leftDown=true;
                        upSum++;
                    }
                    else if (ek.getKeyChar() == 'd')
                    {
                     alpha.setStartTime(System.currentTimeMillis());
                     walking=true;
                        getStep();
                        rightDown=true;
                        upSum++;
                    }
                    else if (ek.getKeyChar() == 's')
                    {
                     alpha.setStartTime(System.currentTimeMillis());
                     walking=true;
                        getStep();
                        downDown=true;
                        upSum++;
                    }
                }
                else if (ek.getID() == KeyEvent.KEY_RELEASED)
                {
                    if (ek.getKeyChar() == 'w')
                    {
                        walking=false;
                        fwDown=false;
                        upSum--;
 
                    }
                    else if (ek.getKeyChar() == 'a')
                    {
                        walking=false;
                        leftDown=false;
                        upSum--;
                    }
                    else if (ek.getKeyChar() == 'd')
                    {
                        walking=false;
                        rightDown=false;
                        upSum--;
                    }
                    else if (ek.getKeyChar() == 'e')
                    {
                        walking=false;
                        downDown=false;
                        upSum--;
                    }                
                }
               
            }
            else {
           
             System.out.println("event error");
           
            }
 
           
           
        }
////////////////////////////// START processAWTEvent
----- Original Message -----
From: Ben Moxon
Sent: Tuesday, September 07, 2004 3:07 PM
Subject: Re: [JAVA3D] Newbie Question

As I'm sure you can tell, what I'm doing there is rotating the transformgroup in the Y direction - what you want to do is change the translation to step you left or right in the same way that it currently steps you forward.
 
Once you've compensated for the fact that I don't think you can pile transformations on top of each other, that probably translates as something like this:
 
float yStepper=0;
float zStepper=0;
 
if (rightDown || leftDown)
{
    if (rightDown)
    { 
        yStepper+=stepper;
        upSum++;
    } 
    else
    {
        yStepper-=stepper);
        upSum++;
    }
}
 
if (fwDown)
{
    upSum++;
    zStepper=stepper;
}
 
tempTrans.setTranslation(new Vector3d(0.0d, yStepper, zStepper));
 
 
I haven't really worked with this for a while, so I can't guarantee that you need to translate in Y rather than X - but that is worth a shot for managing the sidesteps. You could also add a backwards key very easily from there.
 
Hope that helps,
 
-ben
-----Original Message-----
From: Discussion list for Java 3D API [mailto:[EMAIL PROTECTED]On Behalf Of FantasyFooty.org
Sent: 07 September 2004 14:51
To: [EMAIL PROTECTED]
Subject: Re: [JAVA3D] Newbie Question

Ben, quality tutorial. I wonder if you could help me modify it slightly?
 
I've attached this to the BranchGroup and it happily lets me look around with the mouse.
 
        oMouseRotate_1 = new MouseRotate(MouseBehavior.INVERT_INPUT);
        oMouseRotate_1.setTransformGroup(ourView.getViewPlatformTransform());
        oMouseRotate_1.setSchedulingBounds(bounds);
        objRoot.addChild(oMouseRotate_1);
 
What I would ideally like to do is intstead of 'a' and 'd' spinning him round I would like the mouse to do it.
 
The problem is I would like 'a' to sidestep left and 'd' right. At the moment it does:
 
tempTrans.rotY(0-0.2d);
 
How can I change that so that the purple dude pans across and the mouse direction determining where he looks? (like you get with 1st person shooters). And is orbitbehaviour the same as mouserotate?
----- Original Message -----
From: Ben Moxon
Sent: Tuesday, September 07, 2004 2:16 PM
Subject: Re: [JAVA3D] Newbie Question

I don't know about sample files - I haven't seen any, or maybe I did, but not for a long time and I don't recall where- but if you follow through that tutorial you should be able to sort out a roaming camera approach from it with a bit of extension of the existing behaviour, perhaps looking at combining it with the orbitbehaviour?
 
-ben
-----Original Message-----
From: Discussion list for Java 3D API [mailto:[EMAIL PROTECTED]On Behalf Of FantasyFooty.org
Sent: 07 September 2004 14:02
To: [EMAIL PROTECTED]
Subject: [JAVA3D] Newbie Question

Hi,
 
I'm just getting into Java3D and was wondering whether there are any sample java files on the internet which produce a very basic first person perspective on a bumpy terrain. I've looked and ran the purple dude program from newview and would like something like this only with the camera not being locked in one direction but to follow where he is looking.
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to