<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2F3D%2F3D_Switch</id>
		<title>Java/3D/3D Switch - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2F3D%2F3D_Switch"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/3D/3D_Switch&amp;action=history"/>
		<updated>2026-04-21T20:16:14Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/3D/3D_Switch&amp;diff=6453&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/3D/3D_Switch&amp;diff=6453&amp;oldid=prev"/>
				<updated>2010-06-01T06:13:58Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:13, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/3D/3D_Switch&amp;diff=6452&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/3D/3D_Switch&amp;diff=6452&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:43Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== A switch node to swap between two shapes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Essential Java 3D Fast&lt;br /&gt;
Ian Palmer&lt;br /&gt;
Publisher: Springer-Verlag&lt;br /&gt;
ISBN: 1-85233-394-4&lt;br /&gt;
*/&lt;br /&gt;
import java.awt.BorderLayout;&lt;br /&gt;
import java.awt.Button;&lt;br /&gt;
import java.awt.Frame;&lt;br /&gt;
import java.awt.Panel;&lt;br /&gt;
import java.awt.event.ActionEvent;&lt;br /&gt;
import java.awt.event.ActionListener;&lt;br /&gt;
import javax.media.j3d.Appearance;&lt;br /&gt;
import javax.media.j3d.BoundingSphere;&lt;br /&gt;
import javax.media.j3d.BranchGroup;&lt;br /&gt;
import javax.media.j3d.Canvas3D;&lt;br /&gt;
import javax.media.j3d.DirectionalLight;&lt;br /&gt;
import javax.media.j3d.Locale;&lt;br /&gt;
import javax.media.j3d.Material;&lt;br /&gt;
import javax.media.j3d.Node;&lt;br /&gt;
import javax.media.j3d.PhysicalBody;&lt;br /&gt;
import javax.media.j3d.PhysicalEnvironment;&lt;br /&gt;
import javax.media.j3d.Switch;&lt;br /&gt;
import javax.media.j3d.Transform3D;&lt;br /&gt;
import javax.media.j3d.TransformGroup;&lt;br /&gt;
import javax.media.j3d.View;&lt;br /&gt;
import javax.media.j3d.ViewPlatform;&lt;br /&gt;
import javax.media.j3d.VirtualUniverse;&lt;br /&gt;
import javax.vecmath.AxisAngle4d;&lt;br /&gt;
import javax.vecmath.Color3f;&lt;br /&gt;
import javax.vecmath.Point3d;&lt;br /&gt;
import javax.vecmath.Vector3f;&lt;br /&gt;
import com.sun.j3d.utils.geometry.Box;&lt;br /&gt;
import com.sun.j3d.utils.geometry.Cone;&lt;br /&gt;
/**&lt;br /&gt;
 * This application uses a switch node to swap between two shapes. The switch is&lt;br /&gt;
 * driven by two AWT buttons.&lt;br /&gt;
 * &lt;br /&gt;
 * @author I.J.Palmer&lt;br /&gt;
 * @version 1.0&lt;br /&gt;
 */&lt;br /&gt;
public class SimpleSwitch extends Frame implements ActionListener {&lt;br /&gt;
  protected Canvas3D myCanvas3D = new Canvas3D(null);&lt;br /&gt;
  /** The exit button */&lt;br /&gt;
  protected Button exitButton = new Button(&amp;quot;Exit&amp;quot;);&lt;br /&gt;
  /** Set the shape to a box */&lt;br /&gt;
  protected Button boxButton = new Button(&amp;quot;Box&amp;quot;);&lt;br /&gt;
  /** Set the shape to a cone */&lt;br /&gt;
  protected Button coneButton = new Button(&amp;quot;Cone&amp;quot;);&lt;br /&gt;
  /** The switch that is used to swap between the shapes */&lt;br /&gt;
  protected Switch firstSwitch = new Switch(0);&lt;br /&gt;
  /**&lt;br /&gt;
   * This function builds the view branch of the scene graph. It creates a&lt;br /&gt;
   * branch group and then creates the necessary view elements to give a&lt;br /&gt;
   * useful view of our content.&lt;br /&gt;
   * &lt;br /&gt;
   * @param c&lt;br /&gt;
   *            Canvas3D that will display the view&lt;br /&gt;
   * @return BranchGroup that is the root of the view elements&lt;br /&gt;
   */&lt;br /&gt;
  protected BranchGroup buildViewBranch(Canvas3D c) {&lt;br /&gt;
    BranchGroup viewBranch = new BranchGroup();&lt;br /&gt;
    Transform3D viewXfm = new Transform3D();&lt;br /&gt;
    viewXfm.set(new Vector3f(0.0f, 0.0f, 10.0f));&lt;br /&gt;
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);&lt;br /&gt;
    ViewPlatform myViewPlatform = new ViewPlatform();&lt;br /&gt;
    PhysicalBody myBody = new PhysicalBody();&lt;br /&gt;
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();&lt;br /&gt;
    viewXfmGroup.addChild(myViewPlatform);&lt;br /&gt;
    viewBranch.addChild(viewXfmGroup);&lt;br /&gt;
    View myView = new View();&lt;br /&gt;
    myView.addCanvas3D(c);&lt;br /&gt;
    myView.attachViewPlatform(myViewPlatform);&lt;br /&gt;
    myView.setPhysicalBody(myBody);&lt;br /&gt;
    myView.setPhysicalEnvironment(myEnvironment);&lt;br /&gt;
    return viewBranch;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Add some lights so that we can illuminate the scene. This adds one&lt;br /&gt;
   * ambient light to bring up the overall lighting level and one directional&lt;br /&gt;
   * shape to show the shape of the objects in the scene.&lt;br /&gt;
   * &lt;br /&gt;
   * @param b&lt;br /&gt;
   *            BranchGroup that the lights are to be added to.&lt;br /&gt;
   */&lt;br /&gt;
  protected void addLights(BranchGroup b) {&lt;br /&gt;
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),&lt;br /&gt;
        100.0);&lt;br /&gt;
    Color3f lightColour1 = new Color3f(1.0f, 1.0f, 1.0f);&lt;br /&gt;
    Vector3f lightDir1 = new Vector3f(0.0f, -1.0f, 0.0f);&lt;br /&gt;
    Color3f lightColour2 = new Color3f(1.0f, 1.0f, 1.0f);&lt;br /&gt;
    Vector3f lightDir2 = new Vector3f(0.0f, 1.0f, 0.0f);&lt;br /&gt;
    DirectionalLight light1 = new DirectionalLight(lightColour1, lightDir1);&lt;br /&gt;
    light1.setInfluencingBounds(bounds);&lt;br /&gt;
    DirectionalLight light2 = new DirectionalLight(lightColour2, lightDir2);&lt;br /&gt;
    light2.setInfluencingBounds(bounds);&lt;br /&gt;
    b.addChild(light1);&lt;br /&gt;
    b.addChild(light2);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * This builds the content branch of our scene graph. The root of the shapes&lt;br /&gt;
   * supplied as a parameter is slightly tilted to reveal its 3D shape. It&lt;br /&gt;
   * also uses the addLights function to add some lights to the scene.&lt;br /&gt;
   * &lt;br /&gt;
   * @param shape&lt;br /&gt;
   *            Node that represents the geometry for the content&lt;br /&gt;
   * @return BranchGroup that is the root of the content branch&lt;br /&gt;
   */&lt;br /&gt;
  protected BranchGroup buildContentBranch(Node shape) {&lt;br /&gt;
    BranchGroup contentBranch = new BranchGroup();&lt;br /&gt;
    Transform3D rotateCube = new Transform3D();&lt;br /&gt;
    rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0));&lt;br /&gt;
    TransformGroup rotationGroup = new TransformGroup(rotateCube);&lt;br /&gt;
    contentBranch.addChild(rotationGroup);&lt;br /&gt;
    rotationGroup.addChild(shape);&lt;br /&gt;
    addLights(contentBranch);&lt;br /&gt;
    return contentBranch;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * This creates the shapes used in the program. A switch node is created&lt;br /&gt;
   * that has its write capability set so that we can swap the rendered shape.&lt;br /&gt;
   * Then a box and a cone are created and added to the switch.&lt;br /&gt;
   * &lt;br /&gt;
   * @return Node that is the switch node&lt;br /&gt;
   */&lt;br /&gt;
  protected Node buildShape() {&lt;br /&gt;
    Appearance app = new Appearance();&lt;br /&gt;
    Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f);&lt;br /&gt;
    Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f);&lt;br /&gt;
    Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f);&lt;br /&gt;
    Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f);&lt;br /&gt;
    float shininess = 20.0f;&lt;br /&gt;
    app.setMaterial(new Material(ambientColour, emissiveColour,&lt;br /&gt;
        diffuseColour, specularColour, shininess));&lt;br /&gt;
    //Set the capability so that we can change the switch value&lt;br /&gt;
    firstSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);&lt;br /&gt;
    //Add the two shapes to the switch&lt;br /&gt;
    firstSwitch.addChild(new Box(2.0f, 2.0f, 2.0f, Box.GENERATE_NORMALS,&lt;br /&gt;
        app));&lt;br /&gt;
    firstSwitch.addChild(new Cone(2.0f, 4.0f, Cone.GENERATE_NORMALS, app));&lt;br /&gt;
    return firstSwitch;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Process the AWT events and perform the appropriate actions. If the exit&lt;br /&gt;
   * button has been pressed, quit the application, if the box button has been&lt;br /&gt;
   * pressed, select the box child of the switch and if its the cone button&lt;br /&gt;
   * select the cone child.&lt;br /&gt;
   * &lt;br /&gt;
   * @param e&lt;br /&gt;
   *            ActionEvent that is to be processed.&lt;br /&gt;
   */&lt;br /&gt;
  public void actionPerformed(ActionEvent e) {&lt;br /&gt;
    if (e.getSource() == exitButton) {&lt;br /&gt;
      dispose();&lt;br /&gt;
      System.exit(0);&lt;br /&gt;
    } else if (e.getSource() == boxButton) {&lt;br /&gt;
      firstSwitch.setWhichChild(0);&lt;br /&gt;
    } else if (e.getSource() == coneButton) {&lt;br /&gt;
      firstSwitch.setWhichChild(1);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public SimpleSwitch() {&lt;br /&gt;
    VirtualUniverse myUniverse = new VirtualUniverse();&lt;br /&gt;
    Locale myLocale = new Locale(myUniverse);&lt;br /&gt;
    myLocale.addBranchGraph(buildViewBranch(myCanvas3D));&lt;br /&gt;
    myLocale.addBranchGraph(buildContentBranch(buildShape()));&lt;br /&gt;
    setTitle(&amp;quot;SimpleWorld&amp;quot;);&lt;br /&gt;
    setSize(400, 400);&lt;br /&gt;
    setLayout(new BorderLayout());&lt;br /&gt;
    Panel bottom = new Panel();&lt;br /&gt;
    bottom.add(boxButton);&lt;br /&gt;
    bottom.add(coneButton);&lt;br /&gt;
    bottom.add(exitButton);&lt;br /&gt;
    add(BorderLayout.CENTER, myCanvas3D);&lt;br /&gt;
    add(BorderLayout.SOUTH, bottom);&lt;br /&gt;
    exitButton.addActionListener(this);&lt;br /&gt;
    boxButton.addActionListener(this);&lt;br /&gt;
    coneButton.addActionListener(this);&lt;br /&gt;
    setVisible(true);&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    SimpleSwitch ss = new SimpleSwitch();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>