# Rotationsblockierungs Problem



## Developer_X (16. Mai 2009)

Hi, ich habe im folgenden Code die "Enterprise" und mein Ziel ist es,
dass man sie mit der maus zwar drehen kann, aber nur bis zu einem bestimmtem Winkel, 
135 oder -135 Grad, was mache ich falsch?


```
package Enterprise_Astroids;

import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.Appearance;
import javax.media.j3d.Background;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.PointArray;
import javax.media.j3d.PointAttributes;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JProgressBar;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;

import com.sun.j3d.utils.universe.SimpleUniverse;

@SuppressWarnings("serial")
public class Game extends JFrame implements KeyListener {
	JProgressBar bar;

	SimpleUniverse u;

	boolean right = true;
	boolean left = true;

	TransformGroup Charakter;
	Transform3D charakter;
	Vector3f cvector;
	float cx = 0;
	float cz = -4;
	float ry = 180;

	TransformGroup View;
	Transform3D view;
	Vector3f vector;
	float x = 0;
	float z = 0;

	class WindowListener extends WindowAdapter {
		public void windowClosing(WindowEvent e) {
			System.exit(0);
		}
	}

	@SuppressWarnings("static-access")
	public Game() {
		super("Start Trek - Astroids");

		this.setUndecorated(true);
		Toolkit tk = null;
		Dimension d = tk.getDefaultToolkit().getScreenSize();
		this.setSize(d);
		this.addWindowListener(new WindowListener());
		JMenuBar b = new JMenuBar();
		bar = new JProgressBar();
		bar.setValue(50);
		b.add(bar);
		this.setJMenuBar(b);

		GraphicsConfiguration config = SimpleUniverse
				.getPreferredConfiguration();
		Canvas3D canvas = new Canvas3D(config);
		canvas.addKeyListener(this);
		canvas.setBounds(0, 0, d.width, d.height);
		this.add(canvas);
		u = new SimpleUniverse(canvas);
		BranchGroup scene = createSceneGraph();
		u.addBranchGraph(scene);

		this.setVisible(true);
		this.setLayout(null);
	}

	public BranchGroup createSceneGraph() {
		final BranchGroup objRoot = new BranchGroup();

		objRoot.addChild(new StarBoxes());
		createStarBackground(objRoot);
		// //////////////////// //////////////////////////
		charakter = new Transform3D();
		cvector = new Vector3f();
		cvector.setX(cx);
		cvector.setY(-0.8f);
		cvector.setZ(cz);
		charakter.rotY(Math.toRadians(ry));
		charakter.setTranslation(cvector);

		Charakter = new TransformGroup();
		Charakter.setTransform(charakter);
		Charakter.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		Charakter.addChild(new EnterPrise(0.5f));
		objRoot.addChild(Charakter);

		view = new Transform3D();
		vector = new Vector3f();
		vector.setX(x);
		vector.setY(0);
		vector.setZ(z);
		view.setTranslation(vector);
		View = new TransformGroup();
		View.setTransform(view);
		View.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		View = u.getViewingPlatform().getViewPlatformTransform();

		(new Thread() {
			@Override
			public void run() {
				while (!isInterrupted()) {
					// //////////////////////////////////////////////
					// das Bewegen
					// grundsätlich geradeaus
					z = z - 0.1f;
					cz = cz - 0.1f;

					vector.setX(x);
					vector.setZ(z);
					view.setTranslation(vector);
					View.setTransform(view);

					cvector.setX(cx);
					cvector.setZ(cz);
					charakter.rotY(Math.toRadians(ry));
					charakter.setTranslation(cvector);
					Charakter.setTransform(charakter);

					if (ry == 135) {
						right = false;
					} else if (ry == -135) {
						left = false;
					} else {
						right = true;
						left = true;
					}

					System.out.println(vector);
					// //////////////////////////////////////////////
					try {
						sleep(10);
					} catch (InterruptedException e) {
						interrupt();
					}
				}
			}
		}).start();
		Color3f lightColor = new Color3f(.5f, .6f, .6f);
		AmbientLight ambientLight = new AmbientLight(lightColor);
		ambientLight.setInfluencingBounds(new BoundingSphere(new Point3d(),
				100000000000000000000000000000000000000000000.0));
		objRoot.addChild(ambientLight);
		DirectionalLight directionalLight = new DirectionalLight();
		directionalLight.setColor(lightColor);
		directionalLight.setInfluencingBounds(new BoundingSphere(new Point3d(),
				100000000000000000000000000000000000000000000.0));
		objRoot.addChild(directionalLight);
		objRoot.compile();
		return objRoot;
	}

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

		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() + 1.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(),
				100000000000000000000000000000000000000000000.0));

		bg.addChild(BG);
	}

	public void keyPressed(KeyEvent arg0) {
		if (arg0.getKeyCode() == KeyEvent.VK_LEFT) {
			x = x - 1;
			cx = cx - 1;
			vector.setX(x);
			vector.setZ(z);
			view.setTranslation(vector);
			View.setTransform(view);

			cvector.setX(cx);
			cvector.setZ(cz);
			if (left == true) {
				ry = ry + 1;
			}
			charakter.rotY(Math.toRadians(ry));
			charakter.setTranslation(cvector);
			Charakter.setTransform(charakter);
		} else if (arg0.getKeyCode() == KeyEvent.VK_RIGHT) {
			x = x + 1;
			cx = cx + 1;
			vector.setX(x);
			vector.setZ(z);
			view.setTranslation(vector);
			View.setTransform(view);

			cvector.setX(cx);
			cvector.setZ(cz);
			if (right == true) {
				ry = ry - 1;
			}
			charakter.rotY(Math.toRadians(ry));
			charakter.setTranslation(cvector);
			Charakter.setTransform(charakter);
		}
	}

	public void keyReleased(KeyEvent arg0) {

	}

	public void keyTyped(KeyEvent arg0) {

	}

	public static void warte(long millis) {
		try {
			Thread.sleep(millis);
		} catch (InterruptedException e) {
		}
	}
}
```

Das Problem, keine Excception, wenn man die rechte Taste drückt, funktionierts auch wie gewünscht, aber mit der linken maustaste kann man sich unendlich oft im Kreis drehen


----------



## diggaa1984 (16. Mai 2009)

du könntest sicherheitshalber mal ein >= / <= in den if-Abfragen verwenden im Thread, statt dem ==  .. nur mal ins blaue geraten 

und kann es sein das du left und right rein logisch gesehen vertauscht hast - wenn VK_LEFT dann ry++ .. if (ry == 135) dann right = false!?

Hat nix mit dem Problem zu tun, aber ist verwirrend ^^


----------



## Developer_X (16. Mai 2009)

diggaa1984 hat gesagt.:


> du könntest sicherheitshalber mal ein >= / <= in den if-Abfragen verwenden im Thread, statt dem ==  .. nur mal ins blaue geraten
> 
> und kann es sein das du left und right rein logisch gesehen vertauscht hast - wenn VK_LEFT dann ry++ .. if (ry == 135) dann right = false!?
> 
> Hat nix mit dem Problem zu tun, aber ist verwirrend ^^



KA, der Fakt ist immer noch, dass das ganze nicht richtig funktioniert:

```
package Enterprise_Astroids;

import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.Appearance;
import javax.media.j3d.Background;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.PointArray;
import javax.media.j3d.PointAttributes;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JProgressBar;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;

import TransoForm.TransoFormGroup;

import com.indie.genesis.j3d.Rock;
import com.sun.j3d.utils.universe.SimpleUniverse;

@SuppressWarnings("serial")
public class Game extends JFrame implements KeyListener {
	JProgressBar bar;

	SimpleUniverse u;

	boolean right = true;
	boolean left = true;

	TransformGroup Charakter;
	Transform3D charakter;
	Vector3f cvector;
	float cx = 0;
	float cz = -4;
	float ry = 180;

	TransformGroup View;
	Transform3D view;
	Vector3f vector;
	float x = 0;
	float z = 0;

	class WindowListener extends WindowAdapter {
		public void windowClosing(WindowEvent e) {
			System.exit(0);
		}
	}

	@SuppressWarnings("static-access")
	public Game() {
		super("Start Trek - Astroids");

		this.setUndecorated(true);
		Toolkit tk = null;
		Dimension d = tk.getDefaultToolkit().getScreenSize();
		this.setSize(d);
		this.addWindowListener(new WindowListener());
		JMenuBar b = new JMenuBar();
		bar = new JProgressBar();
		bar.setValue(50);
		b.add(bar);
		this.setJMenuBar(b);

		GraphicsConfiguration config = SimpleUniverse
				.getPreferredConfiguration();
		Canvas3D canvas = new Canvas3D(config);
		canvas.addKeyListener(this);
		canvas.setBounds(0, 0, d.width, d.height);
		this.add(canvas);
		u = new SimpleUniverse(canvas);
		BranchGroup scene = createSceneGraph();
		u.addBranchGraph(scene);

		this.setVisible(true);
		this.setLayout(null);
	}

	public BranchGroup createSceneGraph() {
		final BranchGroup objRoot = new BranchGroup();

		objRoot.addChild(new StarBoxes());
		createStarBackground(objRoot);

		TransoFormGroup f1 = new TransoFormGroup(new Vector3f(0, 0, -50), 20,
				20, 0, 0.1f);
		f1.addChild(new Rock());
		objRoot.addChild(f1);

		TransoFormGroup f2 = new TransoFormGroup(new Vector3f(0, 0, -70), 0,
				20, 20, 0.1f);
		f2.addChild(new Rock());
		objRoot.addChild(f2);
		// //////////////////// //////////////////////////
		charakter = new Transform3D();
		cvector = new Vector3f();
		cvector.setX(cx);
		cvector.setY(-0.8f);
		cvector.setZ(cz);
		charakter.rotY(Math.toRadians(ry));
		charakter.setTranslation(cvector);

		Charakter = new TransformGroup();
		Charakter.setTransform(charakter);
		Charakter.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		Charakter.addChild(new EnterPrise(0.5f));
		objRoot.addChild(Charakter);

		view = new Transform3D();
		vector = new Vector3f();
		vector.setX(x);
		vector.setY(0);
		vector.setZ(z);
		view.setTranslation(vector);
		View = new TransformGroup();
		View.setTransform(view);
		View.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		View = u.getViewingPlatform().getViewPlatformTransform();

		(new Thread() {
			@Override
			public void run() {
				while (!isInterrupted()) {
					// //////////////////////////////////////////////
					// das Bewegen
					// grundsätlich geradeaus
					z = z - 0.1f;
					cz = cz - 0.1f;

					vector.setX(x);
					vector.setZ(z);
					view.setTranslation(vector);
					View.setTransform(view);

					cvector.setX(cx);
					cvector.setZ(cz);
					charakter.rotY(Math.toRadians(ry));
					charakter.setTranslation(cvector);
					Charakter.setTransform(charakter);

					if (ry <= 135) {
						right = false;
					} else if (ry <= -135) {
						left = false;
					} else {
						right = true;
						left = true;
					}

					System.out.println(cvector);
					// //////////////////////////////////////////////
					try {
						sleep(10);
					} catch (InterruptedException e) {
						interrupt();
					}
				}
			}
		}).start();

		Color3f lightColor = new Color3f(.5f, .6f, .6f);
		AmbientLight ambientLight = new AmbientLight(lightColor);
		ambientLight.setInfluencingBounds(new BoundingSphere(new Point3d(),
				100000000000000000000000000000000000000000000.0));
		objRoot.addChild(ambientLight);
		DirectionalLight directionalLight = new DirectionalLight();
		directionalLight.setColor(lightColor);
		directionalLight.setInfluencingBounds(new BoundingSphere(new Point3d(),
				100000000000000000000000000000000000000000000.0));
		objRoot.addChild(directionalLight);
		objRoot.compile();
		return objRoot;
	}

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

		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() + 1.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(),
				100000000000000000000000000000000000000000000.0));

		bg.addChild(BG);
	}

	public void keyPressed(KeyEvent arg0) {
		if (arg0.getKeyCode() == KeyEvent.VK_LEFT) {
			x = x - 0.1f;
			cx = cx - 0.1f;
			vector.setX(x);
			vector.setZ(z);
			view.setTranslation(vector);
			View.setTransform(view);

			cvector.setX(cx);
			cvector.setZ(cz);
			if (left == true) {
				ry = ry + 1;
			}
			charakter.rotY(Math.toRadians(ry));
			charakter.setTranslation(cvector);
			Charakter.setTransform(charakter);
		} else if (arg0.getKeyCode() == KeyEvent.VK_RIGHT) {
			x = x + 0.1f;
			cx = cx + 0.1f;
			vector.setX(x);
			vector.setZ(z);
			view.setTranslation(vector);
			View.setTransform(view);

			cvector.setX(cx);
			cvector.setZ(cz);
			if (right == true) {
				ry = ry - 1;
			}
			charakter.rotY(Math.toRadians(ry));
			charakter.setTranslation(cvector);
			Charakter.setTransform(charakter);
		}
	}

	public void keyReleased(KeyEvent arg0) {

		ry = 180;
		charakter.rotY(Math.toRadians(ry));
		charakter.setTranslation(cvector);
		Charakter.setTransform(charakter);
	}

	public void keyTyped(KeyEvent arg0) {

	}

	public static void warte(long millis) {
		try {
			Thread.sleep(millis);
		} catch (InterruptedException e) {
		}
	}
}
```


----------



## diggaa1984 (16. Mai 2009)

du musst natürlich schon >= 135 und <=-135 testen.

wenns dann immer noch net geht, immer dazu sagen ob das selbe problem besteht, oder was sich nun im verhalten geändert hat


----------



## Developer_X (16. Mai 2009)

danke, ich hab die lösung aber schon längst herausgefunden, danke trotzdem nochmal, bye DX


----------



## diggaa1984 (16. Mai 2009)

woran lags denn?


----------



## Developer_X (16. Mai 2009)

ich kann nur sagen, dass dies die Lösung ist:

```
package Enterprise_Astroids;

import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;

import javax.media.Manager;
import javax.media.Player;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.Appearance;
import javax.media.j3d.Background;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Material;
import javax.media.j3d.PointArray;
import javax.media.j3d.PointAttributes;
import javax.media.j3d.PolygonAttributes;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JProgressBar;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;

import TransoForm.TransoFormGroup;

import com.indie.genesis.j3d.Rock;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.Cylinder;
import com.sun.j3d.utils.universe.SimpleUniverse;

@SuppressWarnings("serial")
public class Game extends JFrame implements KeyListener {
	JProgressBar bar;

	SimpleUniverse u;

	boolean right = true;
	boolean left = true;

	TransformGroup Charakter;
	Transform3D charakter;
	Vector3f cvector;
	float cx = 0;
	float cy = -0.8f;
	float cz = -4;
	float ry = 180;

	TransformGroup View;
	Transform3D view;
	Vector3f vector;
	float x = 0;
	float y = 0;
	float z = 0;

	class WindowListener extends WindowAdapter {
		public void windowClosing(WindowEvent e) {
			System.exit(0);
		}
	}

	@SuppressWarnings( { "static-access", "deprecation" })
	public Game() {
		super("Start Trek - Astroids");

		try {
			Player m_Player = Manager.createPlayer(new File(
					"F:/JExcercises/StarTrek/StarWars.mp3").toURL());
			m_Player.start();
		} catch (Exception e) {
			e.printStackTrace();
		}

		this.setUndecorated(true);
		Toolkit tk = null;
		Dimension d = tk.getDefaultToolkit().getScreenSize();
		this.setSize(d);
		this.addWindowListener(new WindowListener());
		JMenuBar b = new JMenuBar();
		bar = new JProgressBar();
		bar.setValue(50);
		b.add(bar);
		this.setJMenuBar(b);

		GraphicsConfiguration config = SimpleUniverse
				.getPreferredConfiguration();
		Canvas3D canvas = new Canvas3D(config);
		canvas.addKeyListener(this);
		canvas.setBounds(0, 0, d.width, d.height);
		this.add(canvas);
		u = new SimpleUniverse(canvas);
		BranchGroup scene = createSceneGraph();
		u.addBranchGraph(scene);

		this.setVisible(true);
		this.setLayout(null);
	}

	public BranchGroup createSceneGraph() {
		final BranchGroup objRoot = new BranchGroup();

		objRoot.addChild(new StarBoxes());
		createStarBackground(objRoot);

		TransoFormGroup f1 = new TransoFormGroup(new Vector3f(0, 0, -50), 20,
				20, 0, 0.1f);
		f1.addChild(new Rock());
		objRoot.addChild(f1);

		TransoFormGroup f2 = new TransoFormGroup(new Vector3f(0, 0, -70), 0,
				20, 20, 0.1f);
		f2.addChild(new Rock());
		objRoot.addChild(f2);
		// //////////////////// //////////////////////////
		charakter = new Transform3D();
		cvector = new Vector3f();
		cvector.setX(cx);
		cvector.setY(cy);
		cvector.setZ(cz);
		charakter.rotY(Math.toRadians(ry));
		charakter.setTranslation(cvector);

		Charakter = new TransformGroup();
		Charakter.setTransform(charakter);
		Charakter.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		Charakter.addChild(new EnterPrise(0.5f));
		objRoot.addChild(Charakter);

		view = new Transform3D();
		vector = new Vector3f();
		vector.setX(x);
		vector.setY(y);
		vector.setZ(z);
		view.setTranslation(vector);
		View = new TransformGroup();
		View.setTransform(view);
		View.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		View = u.getViewingPlatform().getViewPlatformTransform();

		
		(new Thread() {
			@SuppressWarnings("deprecation")
			@Override
			public void run() {
				while (!isInterrupted()) {
					// //////////////////////////////////////////////
					// das Bewegen
					// grundsätlich geradeaus
					z = z - 0.1f;
					cz = cz - 0.1f;

					vector.setX(x);
					vector.setY(y);
					vector.setZ(z);
					view.setTranslation(vector);
					View.setTransform(view);

					cvector.setX(cx);
					cvector.setY(cy);
					cvector.setZ(cz);
					charakter.rotY(Math.toRadians(ry));
					charakter.setTranslation(cvector);
					Charakter.setTransform(charakter);

					if (ry <= 170) {
						right = false;
					} else if (ry >= 190) {
						left = false;
					} else {
						right = true;
						left = true;
					}
					if (cz >= 800) {
						System.exit(0);
					}
					System.out.println(cvector);
					// //////////////////////////////////////////////
					try {
						sleep(10);
					} catch (InterruptedException e) {
						interrupt();
					}
				}
			}
		}).start();

		Color3f lightColor = new Color3f(.5f, .6f, .6f);
		AmbientLight ambientLight = new AmbientLight(lightColor);
		ambientLight.setInfluencingBounds(new BoundingSphere(new Point3d(),
				100000000000000000000000000000000000000000000.0));
		objRoot.addChild(ambientLight);
		DirectionalLight directionalLight = new DirectionalLight();
		directionalLight.setColor(lightColor);
		directionalLight.setInfluencingBounds(new BoundingSphere(new Point3d(),
				100000000000000000000000000000000000000000000.0));
		objRoot.addChild(directionalLight);
		objRoot.compile();
		return objRoot;
	}

	void createStarBackground(BranchGroup bg) {
		java.util.Random rand = new java.util.Random();
		float mag;
		BranchGroup BGBranch = new BranchGroup();
		Background BG = new Background();
		BG.setColor(new Color3f(0, 0, 0.4f));
		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() + 1.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(),
				100000000000000000000000000000000000000000000.0));

		bg.addChild(BG);
	}

	public void keyPressed(KeyEvent arg0) {
		if (arg0.getKeyCode() == KeyEvent.VK_LEFT) {
			if (cx <= -5) {
				;
			} else {
				x = x - 0.1f;
				cx = cx - 0.1f;
				vector.setX(x);
				vector.setZ(z);
				view.setTranslation(vector);
				View.setTransform(view);

				cvector.setX(cx);
				cvector.setZ(cz);
				if (left == true) {
					ry = ry + 1;
				}
				charakter.rotY(Math.toRadians(ry));
				charakter.setTranslation(cvector);
				Charakter.setTransform(charakter);
			}
		} else if (arg0.getKeyCode() == KeyEvent.VK_UP) {
			if (cy >= 5) {
				;
			} else {
				y = y + 0.1f;
				vector.setX(x);
				vector.setY(y);
				vector.setZ(z);
				view.setTranslation(vector);
				View.setTransform(view);

				cy = cy + 0.1f;
				cvector.setX(cx);
				cvector.setY(cy);
				cvector.setZ(cz);
				charakter.rotY(Math.toRadians(ry));
				charakter.setTranslation(cvector);
				Charakter.setTransform(charakter);
			}
		} else if (arg0.getKeyCode() == KeyEvent.VK_DOWN) {
			if (cy <= -5) {
				;
			} else {
				y = y - 0.1f;
				vector.setX(x);
				vector.setY(y);
				vector.setZ(z);
				view.setTranslation(vector);
				View.setTransform(view);

				cy = cy - 0.1f;
				cvector.setX(cx);
				cvector.setY(cy);
				cvector.setZ(cz);
				charakter.rotY(Math.toRadians(ry));
				charakter.setTranslation(cvector);
				Charakter.setTransform(charakter);
			}
		} else if (arg0.getKeyCode() == KeyEvent.VK_RIGHT) {
			if (cx >= 5) {
				;
			} else {
				x = x + 0.1f;
				cx = cx + 0.1f;
				vector.setX(x);
				vector.setZ(z);
				view.setTranslation(vector);
				View.setTransform(view);

				cvector.setX(cx);
				cvector.setZ(cz);
				if (right == true) {
					ry = ry - 1;
				}
				charakter.rotY(Math.toRadians(ry));
				charakter.setTranslation(cvector);
				Charakter.setTransform(charakter);
			}
		}
	}

	public void keyReleased(KeyEvent arg0) {
		if (ry >= 180) {
			int faktor = 1;
			while (faktor <= 1000) {
				if (ry >= 180) {
					ry = ry - 0.01f;
					charakter.rotY(Math.toRadians(ry));
					charakter.setTranslation(cvector);
					Charakter.setTransform(charakter);

					faktor++;
					warte(1);
				} else {
					faktor++;
				}
			}
		}

		else if (ry <= 180) {
			int faktor = 1;
			while (faktor <= 1000) {
				if (ry <= 180) {
					ry = ry + 0.01f;
					charakter.rotY(Math.toRadians(ry));
					charakter.setTranslation(cvector);
					Charakter.setTransform(charakter);

					faktor++;
					warte(1);
				} else {
					faktor++;
				}
			}
		}
	}

	public void keyTyped(KeyEvent arg0) {
		;
	}

	public static void warte(long millis) {
		try {
			Thread.sleep(millis);
		} catch (InterruptedException e) {
		}
	}
}
```

digga, damit ich keinen ´neuen Thread mehr aufmachen muss, kannst du mir bei diesem Problem vielleicht helfeN:
Wenn cz = 800 oder größer ist soll da System.exit(0); passieren, das tut es aber nicht wieso?


----------



## diggaa1984 (16. Mai 2009)

aeh ja was auch immer die Lösung ist, wird mir ja grad nicht ersichtlich, genauso wenig wie bei oben beschriebenem Problem das Folgende Teil der Lösung sein soll (ich mein was hat das mit 135 und -135 zu tun) ???:L:bahnhof:


```
if (ry <= 170) {
    right = false;
} else if (ry >= 190) {
    left = false;
} else {
    right = true;
    left = true;
}
```

aeh warum cz nie 800 wird... hm ich seh bisher nur ein


```
float cz = -4;

//und später nur ein
cz = cz - 0.1f;

//laut AdamRiese kann das nich positiv werden, ausser die float-darstellung
//kippt um es wird positiv und geht wieder gegen 0 *g*
```


----------



## Developer_X (17. Mai 2009)

digga, wenn das Programm fertig ist, dann wirst du alles verstehen, ich werds veröffentlichen. Es soll 
"StarTrek "EnterPrise Asteroids"" heißen.


----------



## tuxedo (18. Mai 2009)




----------



## Vayu (18. Mai 2009)

wolltest du nicht erst noch einen Taschenrechner entwickeln und dein JavaPad weiter verbessern?


----------



## ARadauer (18. Mai 2009)

```
directionalLight.setInfluencingBounds(new BoundingSphere(new Point3d(),
                100000000000000000000000000000000000000000000.0));
```
was wird das?


----------



## diggaa1984 (18. Mai 2009)

du wirst es verstehen wenn das programm fertig ist


----------



## Noctarius (18. Mai 2009)

ARadauer hat gesagt.:


> ```
> directionalLight.setInfluencingBounds(new BoundingSphere(new Point3d(),
> 100000000000000000000000000000000000000000000.0));
> ```
> was wird das?



digga wart's einfach ab xD


----------



## diggaa1984 (18. Mai 2009)

Noctarius hat gesagt.:


> digga wart's einfach ab xD



das war von ARadauer, nich von mir  .. und ich warte hier auf nix, weil hab noch ganz andere Sorgen als mir dann Code solchen anzusehen, wobei dann noch hinzukommt, dass ich nix mit 3d und java am hut hab.

da optimier ich lieber matrizen und parser und weiss der geier was


----------



## Noctarius (18. Mai 2009)

diggaa1984 hat gesagt.:


> das war von ARadauer, nich von mir  .. und ich warte hier auf nix, weil hab noch ganz andere Sorgen als mir dann Code solchen anzusehen, wobei dann noch hinzukommt, dass ich nix mit 3d und java am hut hab.
> 
> da optimier ich lieber matrizen und parser und weiss der geier was



Das digga war auch mehr als Fun-Wort gedacht  Das klang vorhin so nach Gangsterslang, da wollte ich mich nur anschließen ALTAH! ^^


----------



## diggaa1984 (18. Mai 2009)

Noctarius hat gesagt.:


> Das digga war auch mehr als Fun-Wort gedacht



war mein 2. gedanke  .. war ich mit meiner nick-wahl ein wenig unglücklich ^^ .. ich werd mich immer angesprochen fühlen, auch wenn ich mich explizit mit 2 a's registriert hab


----------

