Wie fragt man Booleans auf true oder false ab?

Status
Nicht offen für weitere Antworten.
D

Developer_X

Gast
Hi, ich hab einen komplexeren Code, indem ich die Booleans b1,b2,b3 und b4 abfrage, aufdass sie falsch "false" oder richtig "true" sind.
Doch irgendwie scheint das ganze nicht zu klappen, wieso, wenn ihr mir helfen könnt, bitte helft mir, für euch ist das ein Klax, für mich harte Arbeit, die sich schon über viele, glaubt mir viele Wochen verläuft, ohne einen Hoffnungsschimmer, dann kam ich auf die Idee mein Problem mit Boolean zu lösen, welches eigentlich funktionieren sollte:
Ich habe 2 Klassen, "Keybehavior.java" und "WrapMaze3D.java".
In "Keybehavior" gibt es 4 Booleans, wenn ich nun auf eine Pfeil taste klicke, sollte ein boolean true gesetzt werden und alle anderen false, usw....
in "Keybehavior" gibt es auch folgendes:
public Keybehavior(Boolean b1, Boolean b2...)
bitte schaut euch dies genau an!
Dann in WrapMaze3D wird ein Keybehavior geaddet. Er sagt, dass wenn b1 true ist, eine gewisse TransformGroup (ein Ausdruck in der Java3D Programmier Sprache) etwas adden soll. Kann mir einer bitte, zum letzten mal, bitte sagen, was ich falsch mache?

KEYBEHAVIOR
Code:
import java.awt.AWTEvent;
import java.awt.event.*;
import java.util.Enumeration;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.vp.*;


public class KeyBehavior extends ViewPlatformBehavior
{
  private static final int FORWARD = 0;
  private static final int LEFT = 1;
  private static final int BACK = 2;
  private static final int RIGHT = 3;
  
  private Boolean bb1=false;
  private Boolean bb2=false;
  private Boolean bb3=false;
  private Boolean bb4=false;
  
  private final static double MOVE_AMT = 0.2;
  private final static double ROT_AMT = Math.PI / 40.0;  

  private static final Vector3d VFWD = new Vector3d(0,0,-MOVE_AMT);
  private static final Vector3d VBACK = new Vector3d(0,0,MOVE_AMT);
  private static final Vector3d VLEFT = new Vector3d(-MOVE_AMT,0,0);
  private static final Vector3d VRIGHT = new Vector3d(MOVE_AMT,0,0);
  private static final Vector3d VDOWN = new Vector3d(0, -MOVE_AMT ,0);
  private static final Vector3d VUP = new Vector3d(0, MOVE_AMT ,0);

  private int forwardKey = KeyEvent.VK_UP;
  private int backKey = KeyEvent.VK_DOWN;
  private int leftKey = KeyEvent.VK_LEFT;
  private int rightKey = KeyEvent.VK_RIGHT;

  private WakeupCondition keyPress;

  private MazeManager mm;    
  private BirdsEye be;       
  private int zOffset;      
  private TransformGroup camera2TG;   

  // for repeated calcs
  private Transform3D t3d = new Transform3D();
  private Transform3D toMove = new Transform3D();
  private Transform3D toRot = new Transform3D();
  private Vector3d trans = new Vector3d();



  public KeyBehavior(MazeManager mazeMan, BirdsEye bird, TransformGroup c2,Boolean b1, Boolean b2, Boolean b3, Boolean b4)
  {
    
	keyPress = new WakeupOnAWTEvent( KeyEvent.KEY_PRESSED );
    
    bb1 = b1;
    bb2 = b2;
    bb3 = b3;
    bb4 = b4;
    
	mm = mazeMan;
    be = bird;
    camera2TG = c2;
    zOffset = 0;
  } 


  public void initialize()
  { wakeupOn( keyPress ); }


  public void processStimulus( Enumeration criteria )
  {
    WakeupCriterion wakeup;
    AWTEvent[] event;

    while( criteria.hasMoreElements() ) {
      wakeup = (WakeupCriterion) criteria.nextElement();
      if( wakeup instanceof WakeupOnAWTEvent ) {
        event = ((WakeupOnAWTEvent)wakeup).getAWTEvent();
        for( int i = 0; i < event.length; i++ ) {
          if( event[i].getID() == KeyEvent.KEY_PRESSED )
            processKeyEvent((KeyEvent)event[i]);
        }
      }
    }
    wakeupOn( keyPress );
  } 

  private void processKeyEvent(KeyEvent eventKey)
  {
    int keyCode = eventKey.getKeyCode();
    if( eventKey.isAltDown() )   
      altMove(keyCode);
    else
      standardMove(keyCode);
  } 


  private void standardMove(int keycode)
  {
    if(keycode == forwardKey)
    {
      moveBy(VFWD, FORWARD, VBACK); 
      bb1=true;
      bb2=false;
      bb3=false;
      bb4=false;
    }
    else if(keycode == backKey)
    {
      moveBy(VBACK, BACK, VFWD);
      bb1=false;
      bb2=false;
      bb3=false;
      bb4=true;
    }
      else if(keycode == leftKey)
      {
      doRotateY(ROT_AMT, LEFT);
      bb1=false;
      bb2=false;
      bb3=true;
      bb4=false;
      }
      else if(keycode == rightKey)
      {
    	  doRotateY(-ROT_AMT, RIGHT);
          bb1=false;
          bb2=true;
          bb3=false;
          bb4=false;
      }
  } 

  private void altMove(int keycode)
  {
    if(keycode == backKey) {  
      if (zOffset > 0) {
        doMove(VDOWN);  
        doMoveC2(VDOWN);
        bb1=false;
        bb2=false;
        bb3=false;
        bb4=true;
        zOffset--;
      }
    }
    else if(keycode == forwardKey) {  
      doMove(VUP);  
      doMoveC2(VUP);
      bb1=true;
      bb2=false;
      bb3=false;
      bb4=false;
      zOffset++;
    }
    else if(keycode == leftKey)
    {
      moveBy(VLEFT, LEFT, VRIGHT);
    bb1=false;
    bb2=false;
    bb3=true;
    bb4=false; 
    }
    else if(keycode == rightKey)
    {
      moveBy(VRIGHT, RIGHT, VLEFT);
      bb1=false;
      bb2=true;
      bb3=false;
      bb4=false;
    }
  } 

  private void moveBy(Vector3d theMove, int dir, Vector3d theMoveC2)
  {
    Point3d nextLoc = possibleMove(theMove);
    if (mm.canMoveTo(nextLoc.x, nextLoc.z)) {   
      targetTG.setTransform(t3d);   

      doMoveC2(theMoveC2);
      be.setMove(dir);
    }
    else  
    {
      be.bangAlert();
    }
  }  

  private Point3d possibleMove(Vector3d theMove)
  { 
    targetTG.getTransform(t3d);  
    toMove.setTranslation(theMove);
    t3d.mul(toMove);
    t3d.get(trans);
    return new Point3d( trans.x, trans.y, trans.z);
  }

  private void doMove(Vector3d theMove)
  {
    targetTG.getTransform(t3d);
    toMove.setTranslation(theMove);
    t3d.mul(toMove);
    targetTG.setTransform(t3d);
  } 


  private void doMoveC2(Vector3d theMoveC2)
  {
    camera2TG.getTransform(t3d);
    toMove.setTranslation(theMoveC2);
    t3d.mul(toMove);
    camera2TG.setTransform(t3d);
  } 

  private void doRotateY(double radians, int dir)
  {
    targetTG.getTransform(t3d);   
    toRot.rotY(radians);
    t3d.mul(toRot);
    targetTG.setTransform(t3d);

    camera2TG.getTransform(t3d);  
    t3d.mul(toRot);  
    camera2TG.setTransform(t3d);

    be.setRotation(dir);  
  } 
}
WrapMaze3D
Code:
import javax.swing.*;
import java.awt.*;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class WrapMaze3D extends JPanel
{
  private static final int PWIDTH = 1450;   // size of panel
  private static final int PHEIGHT = 600; 

  private Boolean b1=false;
  private Boolean b2=false;
  private Boolean b3=false;
  private Boolean b4=false;
  
  private static final int BOUNDSIZE = 10000;  // larger than world
  private SimpleUniverse su;
  private BranchGroup sceneBG;
  private BoundingSphere bounds;   // for environment nodes

  private MazeManager mazeMan;      // maze manager
  private TransformGroup camera2TG; // back-facing camera

  void createStarBackground(BranchGroup bg)
  {
  java.util.Random rand = new java.util.Random();
  float            mag;
  BranchGroup      BGBranch=new BranchGroup();
  Background       BG=new Background();
  Sphere           BGSphere;
 

  PointArray starfield = new PointArray(15000, PointArray.COORDINATES|PointArray.COLOR_3);
  float[] point = new float[3];
  float[] brightness = new float[3];
  for (int i = 0; i < 15000; i++)
     {
     point[0] = (rand.nextInt(2) == 0) ? rand.nextFloat() * -1.0f :rand.nextFloat();
     point[1] = (rand.nextInt(2) == 0) ? rand.nextFloat() * -1.0f :rand.nextFloat();
     point[2] = (rand.nextInt(2) == 0) ? rand.nextFloat() * -1.0f :rand.nextFloat();
     starfield.setCoordinate(i, point);
     mag=(rand.nextFloat()+0.5f)/1.5f;
     brightness[0]=mag;
     brightness[1]=mag;
     brightness[2]=mag;
     starfield.setColor(i, brightness);
     }
  Shape3D StarShape=new Shape3D(starfield);
  StarShape.setAppearance(new Appearance());
  StarShape.getAppearance().setPointAttributes(new PointAttributes(1f,true));
  BGBranch.addChild(StarShape);
  BG.setGeometry(BGBranch);
  BG.setApplicationBounds(new BoundingSphere(new Point3d(),100.0));

  Appearance SphereApp = new Appearance();
  SphereApp.setTexture((new TextureLoader("F:/Rayman/BonusGame_1/Sky.jpg",null)).getTexture());
  SphereApp.setTextureAttributes(new TextureAttributes(TextureAttributes.MODULATE,new Transform3D(),new Color4f(),TextureAttributes.FASTEST));
 
  BGSphere=new Sphere(1.0f,Sphere.GENERATE_NORMALS_INWARD|Sphere.GENERATE_TEXTURE_COORDS,50,SphereApp);
  BGBranch.addChild(BGSphere);

  bg.addChild(BG);
  }

  public WrapMaze3D(MazeManager mm, BirdsEye be, TransformGroup c2TG)
  // construct the scene and the main camera
  {
    mazeMan = mm;       // ref to maze manager
    camera2TG = c2TG;   // ref to second back-facong camera

    setLayout( new BorderLayout() );
    setOpaque( false );
    setPreferredSize( new Dimension(PWIDTH, PHEIGHT));

    GraphicsConfiguration config =
					SimpleUniverse.getPreferredConfiguration();
    Canvas3D canvas3D = new Canvas3D(config);
    add("Center", canvas3D);
    canvas3D.setFocusable(true); 
    canvas3D.requestFocus();
    su = new SimpleUniverse(canvas3D);

    createSceneGraph();
    prepareViewPoint(be);

    su.addBranchGraph( sceneBG );
  } // end of WrapMaze3D()


  void createSceneGraph()
  // initilise the scene 
  { 
    sceneBG = new BranchGroup();
    bounds = new BoundingSphere(new Point3d(0,0,0), BOUNDSIZE); 

    lightScene();     // add the lights  
    TexturedFloor floor = new TexturedFloor();
    sceneBG.addChild( floor.getBG() );
    
    sceneBG.addChild( mazeMan.getMaze() );  // add maze, using MazeManager
    sceneBG.addChild( camera2TG );          // add second camera
    createStarBackground(sceneBG);
    sceneBG.compile();   // fix the scene
  } // end of createSceneGraph()



  private void lightScene()
  // *No* ambient light, 2 directional lights
  {
    Color3f white = new Color3f(0.3f, 0.3f, 0.3f);

    // Set up the ambient light
    AmbientLight ambientLightNode = new AmbientLight(white);
    ambientLightNode.setInfluencingBounds(bounds);
    // sceneBG.addChild(ambientLightNode);   // ambient commented out

    // Set up the directional lights
    Vector3f light1Direction  = new Vector3f(-1.0f, -1.0f, -1.0f);
       // left, down, backwards 
    Vector3f light2Direction  = new Vector3f(1.0f, -1.0f, 1.0f);
       // right, down, forwards

    DirectionalLight light1 = 
            new DirectionalLight(white, light1Direction);
    light1.setInfluencingBounds(bounds);
    sceneBG.addChild(light1);

    DirectionalLight light2 = 
        new DirectionalLight(white, light2Direction);
    light2.setInfluencingBounds(bounds);
    sceneBG.addChild(light2);
  }  // end of lightScene()

  private void prepareViewPoint(BirdsEye be)
  {
    // adjust viewpoint parameters
    View userView = su.getViewer().getView();
    userView.setFieldOfView( Math.toRadians(90.0));  // wider FOV
    // 10 and 0.1; keep ratio between 100-1000
    userView.setBackClipDistance(60);      // can see a long way
    userView.setFrontClipDistance(0.05);   // can see close things

    ViewingPlatform vp = su.getViewingPlatform();

    // add a spotlight and avatar to viewpoint
    KeyBehavior keybeh = new KeyBehavior(mazeMan, be, camera2TG,b1,b2,b3,b4);
    keybeh.setSchedulingBounds(bounds);
    vp.setViewPlatformBehavior(keybeh);
    
    PlatformGeometry pg = new PlatformGeometry();
    pg.addChild( makeSpot() );
    if(b1==true)
    {
     pg.addChild(makeAvatar());    // avatar not used here
    }
     vp.setPlatformGeometry( pg );

    // fix starting position and orientation of viewpoint
    TransformGroup steerTG = vp.getViewPlatformTransform();
    initViewPosition(steerTG);

    // set up keyboard controls
   
   
  } // end of prepareViewPoint()


  private void initViewPosition(TransformGroup steerTG)
  // rotate and move the viewpoint
  {
    Transform3D t3d = new Transform3D();
    steerTG.getTransform(t3d);
    Transform3D toRot = new Transform3D();
    toRot.rotY(-Math.PI);   
    // rotate 180 degrees around Y-axis, so facing along positive z-axis

    t3d.mul(toRot);
	t3d.setTranslation( mazeMan.getMazeStartPosn() );  // place at maze start
    steerTG.setTransform(t3d); 
  }  // end of initViewPosition()


  private SpotLight makeSpot()
  // a spotlight to help the user see in the (relative) darkness
  {
    SpotLight spot = new SpotLight();
    spot.setPosition(0.0f, 0.5f, 0.0f);      // a bit above the user
    spot.setAttenuation(0.0f, 1.2f, 0.0f);   // linear attentuation
    spot.setSpreadAngle( (float)Math.toRadians(30.0));  // smaller angle
    spot.setConcentration(5.0f);            // reduce strength quicker
    spot.setInfluencingBounds(bounds);
    return spot;
  }  // end of makeSpot()


  private TransformGroup makeAvatar() 
  { 
   TransformGroup U = new TransformGroup(); 
Appearance SphereApp = new Appearance(); 
SphereApp.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_LINE,PolygonAttributes.CULL_NONE,0));
    	U.addChild(new Sphere(1,Sphere.GENERATE_NORMALS_INWARD,80,SphereApp));  
    return U; 
  } 
}
 
D

Developer_X

Gast
L-ectron-x gibts da unterschiede?
Tatsächlich, danke das war ein guter rat,
und Gast, könntest du mir da ein beispiel zeigen:
Geht das ungefähr so:
Code:
if(b1.booleanValue()==true)
{
}
oder so?
Code:
if(b1 == booleanValue(true)
{
}

Dieser Beitrag wurde von L-ectron-X am 31.01.2009 um 18:11 Uhr editiert.
-Code-Tags repariert
 
D

Developer_X

Gast
Aber dafür muss das Boolean ein:
Boolean b1;
sein
und nicht
boolean b1;
außerdem funktioniert das immer noch nicht wenn ich das einbaue:
 
D

Developer_X

Gast
Code:
import java.awt.AWTEvent;
import java.awt.event.*;
import java.util.Enumeration;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.vp.*;


public class KeyBehavior extends ViewPlatformBehavior
{
  private static final int FORWARD = 0;
  private static final int LEFT = 1;
  private static final int BACK = 2;
  private static final int RIGHT = 3;
  
  private Boolean bb1=false;
  private boolean bb2=false;
  private boolean bb3=false;
  private boolean bb4=false;
  
  private final static double MOVE_AMT = 0.2;
  private final static double ROT_AMT = Math.PI / 40.0;  

  private static final Vector3d VFWD = new Vector3d(0,0,-MOVE_AMT);
  private static final Vector3d VBACK = new Vector3d(0,0,MOVE_AMT);
  private static final Vector3d VLEFT = new Vector3d(-MOVE_AMT,0,0);
  private static final Vector3d VRIGHT = new Vector3d(MOVE_AMT,0,0);
  private static final Vector3d VDOWN = new Vector3d(0, -MOVE_AMT ,0);
  private static final Vector3d VUP = new Vector3d(0, MOVE_AMT ,0);

  private int forwardKey = KeyEvent.VK_UP;
  private int backKey = KeyEvent.VK_DOWN;
  private int leftKey = KeyEvent.VK_LEFT;
  private int rightKey = KeyEvent.VK_RIGHT;

  private WakeupCondition keyPress;

  private MazeManager mm;    
  private BirdsEye be;       
  private int zOffset;      
  private TransformGroup camera2TG;   

  // for repeated calcs
  private Transform3D t3d = new Transform3D();
  private Transform3D toMove = new Transform3D();
  private Transform3D toRot = new Transform3D();
  private Vector3d trans = new Vector3d();



  public KeyBehavior(MazeManager mazeMan, BirdsEye bird, TransformGroup c2,boolean b1, boolean b2, boolean b3, boolean b4)
  {
    
	keyPress = new WakeupOnAWTEvent( KeyEvent.KEY_PRESSED );
    
    bb1 = b1;
    bb2 = b2;
    bb3 = b3;
    bb4 = b4;
    
	mm = mazeMan;
    be = bird;
    camera2TG = c2;
    zOffset = 0;
  } 


  public void initialize()
  { wakeupOn( keyPress ); }


  public void processStimulus( Enumeration criteria )
  {
    WakeupCriterion wakeup;
    AWTEvent[] event;

    while( criteria.hasMoreElements() ) {
      wakeup = (WakeupCriterion) criteria.nextElement();
      if( wakeup instanceof WakeupOnAWTEvent ) {
        event = ((WakeupOnAWTEvent)wakeup).getAWTEvent();
        for( int i = 0; i < event.length; i++ ) {
          if( event[i].getID() == KeyEvent.KEY_PRESSED )
            processKeyEvent((KeyEvent)event[i]);
        }
      }
    }
    wakeupOn( keyPress );
  } 

  private void processKeyEvent(KeyEvent eventKey)
  {
    int keyCode = eventKey.getKeyCode();
    if( eventKey.isAltDown() )   
      altMove(keyCode);
    else
      standardMove(keyCode);
  } 


  private void standardMove(int keycode)
  {
    if(keycode == forwardKey)
    {
      moveBy(VFWD, FORWARD, VBACK); 
      bb1=true;
      bb2=false;
      bb3=false;
      bb4=false;
    }
    else if(keycode == backKey)
    {
      moveBy(VBACK, BACK, VFWD);
      bb1=false;
      bb2=false;
      bb3=false;
      bb4=true;
    }
      else if(keycode == leftKey)
      {
      doRotateY(ROT_AMT, LEFT);
      bb1=false;
      bb2=false;
      bb3=true;
      bb4=false;
      }
      else if(keycode == rightKey)
      {
    	  doRotateY(-ROT_AMT, RIGHT);
          bb1=false;
          bb2=true;
          bb3=false;
          bb4=false;
      }
  } 

  private void altMove(int keycode)
  {
    if(keycode == backKey) {  
      if (zOffset > 0) {
        doMove(VDOWN);  
        doMoveC2(VDOWN);
        bb1=false;
        bb2=false;
        bb3=false;
        bb4=true;
        zOffset--;
      }
    }
    else if(keycode == forwardKey) {  
      doMove(VUP);  
      doMoveC2(VUP);
      bb1=true;
      bb2=false;
      bb3=false;
      bb4=false;
      zOffset++;
    }
    else if(keycode == leftKey)
    {
      moveBy(VLEFT, LEFT, VRIGHT);
    bb1=false;
    bb2=false;
    bb3=true;
    bb4=false; 
    }
    else if(keycode == rightKey)
    {
      moveBy(VRIGHT, RIGHT, VLEFT);
      bb1=false;
      bb2=true;
      bb3=false;
      bb4=false;
    }
  } 

  private void moveBy(Vector3d theMove, int dir, Vector3d theMoveC2)
  {
    Point3d nextLoc = possibleMove(theMove);
    if (mm.canMoveTo(nextLoc.x, nextLoc.z)) {   
      targetTG.setTransform(t3d);   

      doMoveC2(theMoveC2);
      be.setMove(dir);
    }
    else  
    {
      be.bangAlert();
    }
  }  

  private Point3d possibleMove(Vector3d theMove)
  { 
    targetTG.getTransform(t3d);  
    toMove.setTranslation(theMove);
    t3d.mul(toMove);
    t3d.get(trans);
    return new Point3d( trans.x, trans.y, trans.z);
  }

  private void doMove(Vector3d theMove)
  {
    targetTG.getTransform(t3d);
    toMove.setTranslation(theMove);
    t3d.mul(toMove);
    targetTG.setTransform(t3d);
  } 


  private void doMoveC2(Vector3d theMoveC2)
  {
    camera2TG.getTransform(t3d);
    toMove.setTranslation(theMoveC2);
    t3d.mul(toMove);
    camera2TG.setTransform(t3d);
  } 

  private void doRotateY(double radians, int dir)
  {
    targetTG.getTransform(t3d);   
    toRot.rotY(radians);
    t3d.mul(toRot);
    targetTG.setTransform(t3d);

    camera2TG.getTransform(t3d);  
    t3d.mul(toRot);  
    camera2TG.setTransform(t3d);

    be.setRotation(dir);  
  } 
}
 
D

Developer_X

Gast
Code:
import javax.swing.*;
import java.awt.*;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class WrapMaze3D extends JPanel
{
  private static final int PWIDTH = 1450;   // size of panel
  private static final int PHEIGHT = 600; 

  private Boolean b1=false;
  private boolean b2=false;
  private boolean b3=false;
  private boolean b4=false;
  
  private static final int BOUNDSIZE = 10000;  // larger than world
  private SimpleUniverse su;
  private BranchGroup sceneBG;
  private BoundingSphere bounds;   // for environment nodes

  private MazeManager mazeMan;      // maze manager
  private TransformGroup camera2TG; // back-facing camera

  void createStarBackground(BranchGroup bg)
  {
  java.util.Random rand = new java.util.Random();
  float            mag;
  BranchGroup      BGBranch=new BranchGroup();
  Background       BG=new Background();
  Sphere           BGSphere;
 

  PointArray starfield = new PointArray(15000, PointArray.COORDINATES|PointArray.COLOR_3);
  float[] point = new float[3];
  float[] brightness = new float[3];
  for (int i = 0; i < 15000; i++)
     {
     point[0] = (rand.nextInt(2) == 0) ? rand.nextFloat() * -1.0f :rand.nextFloat();
     point[1] = (rand.nextInt(2) == 0) ? rand.nextFloat() * -1.0f :rand.nextFloat();
     point[2] = (rand.nextInt(2) == 0) ? rand.nextFloat() * -1.0f :rand.nextFloat();
     starfield.setCoordinate(i, point);
     mag=(rand.nextFloat()+0.5f)/1.5f;
     brightness[0]=mag;
     brightness[1]=mag;
     brightness[2]=mag;
     starfield.setColor(i, brightness);
     }
  Shape3D StarShape=new Shape3D(starfield);
  StarShape.setAppearance(new Appearance());
  StarShape.getAppearance().setPointAttributes(new PointAttributes(1f,true));
  BGBranch.addChild(StarShape);
  BG.setGeometry(BGBranch);
  BG.setApplicationBounds(new BoundingSphere(new Point3d(),100.0));

  Appearance SphereApp = new Appearance();
  SphereApp.setTexture((new TextureLoader("F:/Rayman/BonusGame_1/Sky.jpg",null)).getTexture());
  SphereApp.setTextureAttributes(new TextureAttributes(TextureAttributes.MODULATE,new Transform3D(),new Color4f(),TextureAttributes.FASTEST));
 
  BGSphere=new Sphere(1.0f,Sphere.GENERATE_NORMALS_INWARD|Sphere.GENERATE_TEXTURE_COORDS,50,SphereApp);
  BGBranch.addChild(BGSphere);

  bg.addChild(BG);
  }

  public WrapMaze3D(MazeManager mm, BirdsEye be, TransformGroup c2TG)
  // construct the scene and the main camera
  {
    mazeMan = mm;       // ref to maze manager
    camera2TG = c2TG;   // ref to second back-facong camera

    setLayout( new BorderLayout() );
    setOpaque( false );
    setPreferredSize( new Dimension(PWIDTH, PHEIGHT));

    GraphicsConfiguration config =
					SimpleUniverse.getPreferredConfiguration();
    Canvas3D canvas3D = new Canvas3D(config);
    add("Center", canvas3D);
    canvas3D.setFocusable(true); 
    canvas3D.requestFocus();
    su = new SimpleUniverse(canvas3D);

    createSceneGraph();
    prepareViewPoint(be);

    su.addBranchGraph( sceneBG );
  } // end of WrapMaze3D()


  void createSceneGraph()
  // initilise the scene 
  { 
    sceneBG = new BranchGroup();
    bounds = new BoundingSphere(new Point3d(0,0,0), BOUNDSIZE); 

    lightScene();     // add the lights  
    TexturedFloor floor = new TexturedFloor();
    sceneBG.addChild( floor.getBG() );
    
    sceneBG.addChild( mazeMan.getMaze() );  // add maze, using MazeManager
    sceneBG.addChild( camera2TG );          // add second camera
    createStarBackground(sceneBG);
    sceneBG.compile();   // fix the scene
  } // end of createSceneGraph()



  private void lightScene()
  // *No* ambient light, 2 directional lights
  {
    Color3f white = new Color3f(0.3f, 0.3f, 0.3f);

    // Set up the ambient light
    AmbientLight ambientLightNode = new AmbientLight(white);
    ambientLightNode.setInfluencingBounds(bounds);
    // sceneBG.addChild(ambientLightNode);   // ambient commented out

    // Set up the directional lights
    Vector3f light1Direction  = new Vector3f(-1.0f, -1.0f, -1.0f);
       // left, down, backwards 
    Vector3f light2Direction  = new Vector3f(1.0f, -1.0f, 1.0f);
       // right, down, forwards

    DirectionalLight light1 = 
            new DirectionalLight(white, light1Direction);
    light1.setInfluencingBounds(bounds);
    sceneBG.addChild(light1);

    DirectionalLight light2 = 
        new DirectionalLight(white, light2Direction);
    light2.setInfluencingBounds(bounds);
    sceneBG.addChild(light2);
  }  // end of lightScene()

  private void prepareViewPoint(BirdsEye be)
  {
    // adjust viewpoint parameters
    View userView = su.getViewer().getView();
    userView.setFieldOfView( Math.toRadians(90.0));  // wider FOV
    // 10 and 0.1; keep ratio between 100-1000
    userView.setBackClipDistance(60);      // can see a long way
    userView.setFrontClipDistance(0.05);   // can see close things

    ViewingPlatform vp = su.getViewingPlatform();

    // add a spotlight and avatar to viewpoint
    KeyBehavior keybeh = new KeyBehavior(mazeMan, be, camera2TG,b1,b2,b3,b4);
    keybeh.setSchedulingBounds(bounds);
    vp.setViewPlatformBehavior(keybeh);
    
    PlatformGeometry pg = new PlatformGeometry();
    pg.addChild( makeSpot() );
    if(b1.booleanValue()==true)     
    {
     pg.addChild(makeAvatar());    // avatar not used here
    }
     vp.setPlatformGeometry( pg );

    // fix starting position and orientation of viewpoint
    TransformGroup steerTG = vp.getViewPlatformTransform();
    initViewPosition(steerTG);

    // set up keyboard controls
   
   
  } // end of prepareViewPoint()


  private void initViewPosition(TransformGroup steerTG)
  // rotate and move the viewpoint
  {
    Transform3D t3d = new Transform3D();
    steerTG.getTransform(t3d);
    Transform3D toRot = new Transform3D();
    toRot.rotY(-Math.PI);   
    // rotate 180 degrees around Y-axis, so facing along positive z-axis

    t3d.mul(toRot);
	t3d.setTranslation( mazeMan.getMazeStartPosn() );  // place at maze start
    steerTG.setTransform(t3d); 
  }  // end of initViewPosition()


  private SpotLight makeSpot()
  // a spotlight to help the user see in the (relative) darkness
  {
    SpotLight spot = new SpotLight();
    spot.setPosition(0.0f, 0.5f, 0.0f);      // a bit above the user
    spot.setAttenuation(0.0f, 1.2f, 0.0f);   // linear attentuation
    spot.setSpreadAngle( (float)Math.toRadians(30.0));  // smaller angle
    spot.setConcentration(5.0f);            // reduce strength quicker
    spot.setInfluencingBounds(bounds);
    return spot;
  }  // end of makeSpot()


  private TransformGroup makeAvatar() 
  { 
   TransformGroup U = new TransformGroup(); 
Appearance SphereApp = new Appearance(); 
SphereApp.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_LINE,PolygonAttributes.CULL_NONE,0));
    	U.addChild(new Sphere(1,Sphere.GENERATE_NORMALS_INWARD,80,SphereApp));  
    return U; 
  } 
}
 
D

Developer_X

Gast
Vielleicht verwende ich den If-Satz auch an falscher stelle, kann mir einer sagen was ich falsch mache,?
bitte
 
D

Developer_X

Gast
*@ change
post KEYBEHAVIOR
public KeyBehavior(MazeManager mazeMan, BirdsEye bird, TransformGroup c2,Boolean b1, boolean b2, boolean b3, boolean b4)
{
 

srea

Bekanntes Mitglied
Vorhin hattest du doch nur Boolean Objekte und nie den primitiven Typ boolean.

Bei Boolean -> b1.booleanValue() == true
Bei boolean -> b1 == true
 
G

Gast

Gast
Was soll der ganze Müllcode? Sieht doch jeder Depp, dass du den nicht selbst geschrieben hast. Du kannst nicht einfach von irgendner Website dir nen Java3D Code kopieren und dann hier reinkommen und fragen wie "man booleans abfragt". Lern erstmal Java, so kann dir hier niemand weiterhelfen.
 

0x7F800000

Top Contributor
Gast hat gesagt.:
Was soll der ganze Müllcode? Sieht doch jeder Depp, dass du den nicht selbst geschrieben hast. Du kannst nicht einfach von irgendner Website dir nen Java3D Code kopieren und dann hier reinkommen und fragen wie "man booleans abfragt". Lern erstmal Java, so kann dir hier niemand weiterhelfen.
@Gast: das ist jetzt zwar ein etwas trolliges Vorgehen, aber diesmal scheint's mir berechtigt :) hart aber gerecht^^ :toll:
 

hdi

Top Contributor
@Developer-X

Ich will dich ja nicht nerven, aber du nervst mich ein wenig :bae: Ich habe dir nun schon über 3 mal
ganz ganz lieb und mit allerbesten Absichten geraten, erstmal die Basics zu lernen.

Du stürzt dich permanent in irgendwelche komplexen Java3D Programme und komplizierteste Algorithmen
mit deinem Rayman Projekt, und hast null Ahnung vom Programmieren!

Ganz ehrlich, willst du das nicht verstehen? Ich will dich nicht blöd anmachen, ich will dir helfen, aber
immer wieder kommt da so ein Thread von dir mit einem Riesen-Programm, und deine Frage hat mit
dem Programm nix zu tun und zeigt, dass du nicht mal die ersten 2 Kapitel der Java-Insel gelesen hast.

Ich geb dir jetzt - wieder mit besten Absichten - zum x-ten mal diesen Link:

http://openbook.galileocomputing.de/javainsel7/

BITTE tue uns und vorallem DIR den Gefallen, und L E S E das! Nicht nur bookmarkren.
Nicht nur dran denken. LESEN. JETZT.
Dort wird alles geklärt, was du im Moment so fragst, und wenn es dort nicht erklärt wird, dann
ist es noch nicht für dich bestimmt!

... mein Gott echt wenn du ein Modellflugzeug zusammenbauen willst, klebst du dann auch erstmal ewig
rum und baust es tausend mal auseinander, und liest DANN die Anleitung? So machst du das nämlich grad
mit dem Java lernen... Nich so gut ;)
 

0x7F800000

Top Contributor
hdi hat gesagt.:
Ich bin Ausländer ich muss sowas nicht können :wink:
Ooh man, mir ist der Fehler in deinem Beitrag erst beim drittmaligen durchlesen aufgefallen :? Scheiße ey, statt Ruby und Scala sollte ich in den nächsten Ferien vielleicht auch mal Deutsch lernen, nur so zur Abwechslung :(
 

hdi

Top Contributor
achso ne bin davon ausgegangen dass der 1. link bei google die neueste version ist, sry
 
Status
Nicht offen für weitere Antworten.

Ähnliche Java Themen

Neue Themen


Oben