Graphics2D setTransform (Rotation?)

I am having problems trying to get strings to rotate usin code taken from the Java Developers Almanac 2000. I am using the following code and the strange thing is no errors occur, but the text does not appear on screen.
      AffineTransform at = new AffineTransform();
      at.setToRotation(-Math.PI/2.0);
      g2d.setTransform(at);
      g2d.drawString(this.getText(), 0, g2d.getFontMetrics().getHeight());
Thankyou in advance...
Regards, Richard Lannan

Hi, Richard.
Your program works, at least on my machine.
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
public class RotateText extends JFrame {
  public RotateText()     {
          JPanel p = new JPanel() {
               public void paintComponent(Graphics g) {
                    Graphics2D g2d = (Graphics2D)g;
                    System.out.println("inside paintComponent()");
                    g2d.setColor(Color.black);
                    AffineTransform at = new AffineTransform();
                    at.setToRotation(-Math.PI/2.0);
                    g2d.setTransform(at);
                    g2d.drawString("Hello World", 0, g2d.getFontMetrics().getHeight());
                    // g2d.drawString("Hello World", 100, 100);
          getContentPane().add(p);
          p.repaint();
     public static void main(String args[])
          RotateText f = new RotateText();
          f.setSize(300,300);
          f.setVisible(true);
}BTW: You'd better use
g2d.transform(at);
instead of
g2d.setTransform(at);
because the 'setTransform()' can cause undesired effects.
Cheers, Tom

Similar Messages

  • Problems rotating shape with anchors

    Hey everyone,
    Just learning Java and I'm trying to rotate an oval around in a circle on a fixed point. The problem that comes up is that when the angle changes, the oval moves it's center. I can't get an anchor in place and rotate around it.
    I've looked everywhere for possible fixes and none seem to be working. I think at least I need an AffineTransform. My code (snippet) is below. Any help is greatly appreciated.
    public void paint(Graphics g)
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    AffineTransform rotator = new AffineTransform();
    rotator.rotate(Math.toRadians(45),37,45);
    g2.setPaint(Color.red);
    g2.setTransform(rotator);
    g2.fillOval(0,0,100,150);
    Any ideas why it's not anchoring?

    Blah, db beat me to the punch.{color:#000080}Yay! First time I ever did that, and today's a bad day... got 9.71 kbps (yes that's bits, not Bytes) average over the last 2 hrs or so...
    <aside>^happy I guessed right, too^</aside>
    db{color}

  • Application Won't Rotate To Landscape

    Here's the problem: I want my application to always appear in Landscape mode. So, I added the UIInterfaceOrientation UIInterfaceOrientationLandscapeRight to my info.plist. I built all of my interfaces in interface builder in the landscape mode. When I run my application in the simulator, the simulator rotates when the app opens, but, the interfaces are cut off and do not take up the whole screen. The same is true if I run it on an actual iPhone. I have no idea what I have done wrong. This is very frustrating. Please help!

    I have been able to rotate some of my views using this code: CGAffineTransform rotate = CGAffineTransformMakeRotation(degreesToRadian(90.0));
    rotate = CGAffineTransformTranslate(rotate, 80.0, 80.0);
    [self.view setTransform:rotate];
    But, I cannot get the tab bar to rotate.

  • OO Graphic Engine, how to add Rotation?

    I'm trying to program a simple GameEngine, so far I've created a gameloop (doing stuff, render stuff and wait)
    Now I want to add to the rendering process a way to rotate every single object with a different angle
    my object would looke like this:
    public class GameObject {
         double angle;
        public int x,y;
        public Image picture;
        public MOB(Image pic, int x, int y, double angle) {
                  this.picture=pic;
                  this.x = x;
                  this.y = y;
                  this.angle = angle;
    }and my graphic engine should now paint those objects (pictures) at x/y and rotated, and there lies my problem.
    how can i rotate the objects without rotating the whole panel? do i have to use a buffered image?
    and last but not least, is this method efficient?
    thx for helping
    Ghley

    Take a look at the AffineTransform class and the Graphics2D methods rotate, scale, translate etc. Worry about efficiency if you come up against a performance issue. Micro-optimization seldom helps, and can sometimes be deleterious.
    a way to rotate every single object with a different angleThe method create (inherited from Graphics) can be useful here.
    Remember that angles in Java are in radians, not degrees. The Math class has a static method that could be useful there.
    db

  • Rotated text on a JButton

    I'm trying to create a JButton which has text on it rotated through 90 degrees. Could anyone give me any pointers please?

    Thanks, That worked fine but I had problems when I tried to rotate the text by another 90 degrees. I tried playing around with the code but got very confused with rotations and translations.
    The code that is used to rotate it by 90 degrees is:
    else if (fRotation == ROTATE_RIGHT) {
         g.translate(x,y);
         ((Graphics2D)g).rotate(NINETY_DEGREES);
         g.drawString(fLabel, kBufferSpace, -fDescent);
         ((Graphics2D)g).rotate(-NINETY_DEGREES);
         g.translate(-x,-y);
    I tried adding in:
    else if (fRotation == ROTATE_180) {
         g.translate(x,y);
         ((Graphics2D)g).rotate(NINETY_DEGREES+NINETY_DEGREES);
         g.drawString(fLabel, kBufferSpace, -fDescent);
         ((Graphics2D)g).rotate(-(NINETY_DEGREES+NINETY_DEGREES));
         g.translate(-x,-y);
    but that didn't work so then I tried:
    else if (fRotation == ROTATE_180) {
         g.translate(x,y);
         ((Graphics2D)g).rotate(NINETY_DEGREES);
         g.translate(x,y);
         ((Graphics2D)g).rotate(NINETY_DEGREES);
         g.drawString(fLabel, kBufferSpace, -fDescent);
         ((Graphics2D)g).rotate(-NINETY_DEGREES);
         g.translate(-x,-y);
         ((Graphics2D)g).rotate(-NINETY_DEGREES);
         g.translate(-x,-y);
    but that didn't work either. They both compiled and ran OK but just didn't produce the output where i could see it. I had a play around with some other variations and one of them did show a small amount of the text but in completely the wrong place. Unfortunately I have managed to forget what this was and have since tried to find it again and failed :-( If anyone has got any suggestions I would be most grateful. Thanks, Tom

  • AffineTransform problem caused by JMenuBar + JTabbedPane

    Hello everyone.
    I am starting to think that there is a bug in Java, because otherwise what else could cause the problem I am experiencing? Namely: adding a panel with a vertical text (like a Y axis caption) using an AffineTransform (see SSCCE below) causes this text to be misplaced in some cases.
    Variant A
    Panel is added directly to the application frame. This causes no problems and everything is as it should be.
    Variant B
    Panel is placed on a tabbed pane and a menu bar is associated with the frame. The vertical text is now shifted away from the place where it should be by the height of the menu bar plus the height of tabs on the tabbed pane. Why is this happening? Am I doing something wrong?
    Moreover, when one switches to another tab and then back, the text is now shifted only by the height of the tabs. Once the application window is resized at least a bit, the text jumps right back to the position shifted by tab height plus menu bar height... Strange, strange, strange...
    SSCCE
    import java.awt.*;
    import java.awt.font.FontRenderContext;
    import java.awt.geom.*;
    import javax.swing.*;
    class MyPanel extends JPanel {
        MyPanel() {
            this.setPreferredSize(new Dimension(300, 200));
        @Override
        protected void paintComponent(Graphics g) {
            Graphics2D g2D = (Graphics2D)g;
            int g2DWidth = this.getWidth();
            int g2DHeight = this.getHeight();
            // Horizontal line in the middle of the panel (indicates the position
            // where the middle of the vertical label should be)
            g2D.drawLine(30, (int)(g2DHeight / 2), g2DWidth - 10,
                    (int)(g2DHeight / 2));
            // Vertical label
            AffineTransform origTransform = g2D.getTransform();
            AffineTransform rotate = AffineTransform.getRotateInstance(
                    -Math.PI / 2.0, 0, 0);
            g2D.setTransform(rotate);
            String text = "Centered?";
            FontRenderContext frc = g2D.getFontRenderContext();
            Font font = UIManager.getFont("Label.font");
            Rectangle2D bounds = font.getStringBounds(text, frc);
            g2D.drawString(text, -(int)((g2DHeight + bounds.getWidth()) / 2), 20);
            g2D.setTransform(origTransform);
    class Main {
        private static void createAndShowGUI() {
            // Menu bar
            JMenuBar menuBar = new JMenuBar();
            JMenu menu = new JMenu("Menu");
            JMenuItem menuItem = new JMenuItem("Menu Item");
            menu.add(menuItem);
            menuBar.add(menu);
            // Tabbed pane
            JTabbedPane tabbedPane = new JTabbedPane();
            JPanel panel = new MyPanel();
            tabbedPane.add(panel);
            JLabel label = new JLabel("Nothing interesting's going on here...");
            tabbedPane.add(label);
            // Frame
            JFrame frame = new JFrame();
            // TRICKY PART HERE =========================================
            // [(Un)comment lines as necessary]
            // Variant A: the panel only --------------------------------
            //frame.add(panel);
            // Variant B: menu bar + panel on a tabbed pane -------------
            frame.setJMenuBar(menuBar);
            frame.add(tabbedPane);
            // ==========================================================
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }Thanks for any help.
    Best regards,
    vt
    Edited by: -vt- on 23-Apr-2010 13:08

    You are ignoring the current transform on the Graphics, use the following instead of setTransform():
    g2D.rotate(-Math.PI / 2.0, 0, 0);

  • Creating a image

    Hi,
    I am new to the image section. i want to create a image of the data. how csn i create a image. iam using swing for the project. Do i have to download any api. A example can also do.
    Thanks in advance!!!

    hi Ashitosh,
    It is fairly easy to draw a Shape at any location on your image:
    you have two possibilities:
    - Choice 1:
    build your shape directly with the coordinates it should have in your image and draw it without setting any affine transform to your Graphics2D object. You can use all kind of classes like Ellipse, Rectangle, Polygon, ...
    - Choice 2:
    build a shape with generic size and coordinates, apply a transform to the Graphics2D (using the Graphics2D.setTransform() metthod and draw the shape.
    This second choice might be useful if for example you want to animate the shape (rotations, translation, resize, shearing, ...). You may then build the shape once and apply the corresponding transformation to draw it.
    This applies as well for images (Graphics2D.drawImage()) and strings (Graphics2D.drawString()) you want to composite with your image.
    iIt would be too long here to explain you how to do everything: you can find all you need in this tutorial:
    http://www.apl.jhu.edu/~hall/java/Java2D-Tutorial.html
    If you want me to send you some code doing a specific thing like drawing an Ellipse somewhere in an image, I can do it. Just let me know exactly what you want to do if you were not able to find it in the tutorial.
    Cheers.
    vince.

  • Weird problem with bounds in collsion

    the code
    import java.applet.Applet;
    import java.awt.BorderLayout;
    import java.awt.Font;
    import java.awt.Frame;
    import java.awt.Window;
    import java.awt.event.*;
    import java.awt.GraphicsConfiguration;
    import com.mnstarfire.loaders3d.Inspector3DS;
    import com.sun.j3d.utils.applet.MainFrame;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.geometry.*;
    import javax.imageio.ImageIO;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import java.awt.AWTEvent;
    import java.net.URL;
    import java.util.Enumeration;
    import com.sun.j3d.utils.behaviors.keyboard.*;
    public class Tlo3D extends Applet
         public Tlo3D()
           setLayout(new BorderLayout());
           GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
           Canvas3D canvas3D = new Canvas3D(config);
           add(canvas3D);
           SimpleUniverse simpleUniverse = new SimpleUniverse(canvas3D);
           BranchGroup scene = createSceneGraph(simpleUniverse);
           simpleUniverse.getViewingPlatform().setNominalViewingTransform();
           simpleUniverse.addBranchGraph(scene);
           canvas3D.getView().setBackClipDistance(50);
         public class Podloga extends Shape3D
              Geometry geometria;
             Appearance wyglad;
              public Podloga(float kolor, float przezroczystosc)
                float k = kolor;
                float p = przezroczystosc;
                geometria = createGeometry(k);
                wyglad = createAppearance(p);
                setGeometry(geometria);
                setAppearance(wyglad);
              public Geometry createGeometry(float kolor)
                float k = kolor;
                TriangleFanArray geometria_podlogi = new TriangleFanArray(44, GeometryArray.COORDINATES | GeometryArray.COLOR_3, new int[] {44});
                Point3f punkty[] = new Point3f[44];
                float l = -50.0f;
                for (int c = 0; c < 44; c += 4)
                 geometria_podlogi.setCoordinate(c + 0, new Point3f(-500.0f, 0.0f, l));
                 geometria_podlogi.setCoordinate(c + 1, new Point3f(500.0f, 0.0f, l));
                 geometria_podlogi.setCoordinate(c + 2, new Point3f(l, 0.0f, -500.0f));
                 geometria_podlogi.setCoordinate(c + 3, new Point3f(l, 0.0f, 500.0f));
                l += 10.0f;
               Color3f c = new Color3f(0.1f, k, k);
               for (int i = 0; i < 44; i++) geometria_podlogi.setColor(i, c);
              return geometria_podlogi;
              public Appearance createAppearance(float przezroczystosc)
                   float p = przezroczystosc;
                   Appearance wyglad = new Appearance();
                   PolygonAttributes atrybuty_poligowow ;
                   atrybuty_poligowow = new PolygonAttributes();
                  atrybuty_poligowow.setCullFace(PolygonAttributes.CULL_NONE);
                  atrybuty_poligowow.setPolygonMode(PolygonAttributes.POLYGON_FILL);
                  atrybuty_poligowow.setPolygonOffset(0.1f);
                  atrybuty_poligowow.setBackFaceNormalFlip(false);
                  TransparencyAttributes atrybuty_przezroczystosci = new TransparencyAttributes(1, p);
                  wyglad.setTransparencyAttributes(atrybuty_przezroczystosci);
                   wyglad.setPolygonAttributes(atrybuty_poligowow);
                  return wyglad;
         public BranchGroup createSceneGraph(SimpleUniverse simpleUniverse)
           SimpleUniverse su;
           su = simpleUniverse;
           BranchGroup korzen = new BranchGroup();     
           BoundingLeaf boundingLeaf = new BoundingLeaf(new BoundingBox());
           PlatformGeometry platformGeom = new PlatformGeometry();
           platformGeom.addChild(boundingLeaf);
           platformGeom.compile();
           su.getViewingPlatform().setPlatformGeometry(platformGeom);
           KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(su.getViewingPlatform().getViewPlatformTransform());
           keyNavBeh.setSchedulingBoundingLeaf(boundingLeaf);
           korzen.addChild(keyNavBeh);
           Background background = new Background(new Color3f(1.0f, 1.0f, 1.0f));
           background.setApplicationBounds(new BoundingSphere(new Point3d(), 100000.0));
           korzen.addChild(background);
           Transform3D t3D_podlogi = new Transform3D();
           t3D_podlogi.set(new Vector3d(0.0f, -1.0f, 0.0f));
           TransformGroup tr_podlogi = new TransformGroup(t3D_podlogi);
           korzen.addChild(tr_podlogi);
           Podloga podloga = new Podloga(0.5f, 0.9f);
           tr_podlogi.addChild(podloga);
           Transform3D t3D_kostki1 = new Transform3D();
           t3D_kostki1.set(new Vector3d(3.0f, 0f, 0f));
           TransformGroup tg_kostki1 = new TransformGroup(t3D_kostki1);
           tg_kostki1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
           Transform3D t3D_kostki2 = new Transform3D();
           t3D_kostki2.set(new Vector3d(-3.0f, 0f, 0f));
           TransformGroup tg_kostki2 = new TransformGroup(t3D_kostki2);
           tg_kostki2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
           tg_kostki2.setBoundsAutoCompute(true);
           /*Inspector3DS loader = new Inspector3DS("D:\\Documents and Settings\\szeryf\\Tlo3D\\xw-pilot.3ds");
           loader.setDetail(9);
           loader.setLogging(true);
          loader.setTextureLightingOn();
          loader.setTexturePath("D:\\Documents and Settings\\szeryf\\Tlo3D\\");
          loader.setCreaseAngle(1.0);
           loader.parseIt();
          TransformGroup theModel = loader.getModel();
          theModel.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);*/
           SimpleBehavior myRotationBehavior = new SimpleBehavior(tg_kostki1);
           myRotationBehavior.setSchedulingBounds(new BoundingSphere(new Point3d(0, 0, 0), 1000));
           korzen.addChild(myRotationBehavior);
          korzen.addChild(tg_kostki1);
          korzen.addChild(tg_kostki2);
          Font3D font3d1 = new Font3D(new Font("Helvetica", Font.ITALIC, 1), new FontExtrusion());
          Text3D textGeom1 = new Text3D(font3d1, new String("JEDEN"), new Point3f(-4.0f, 0.0f, 0.0f));
           Appearance ap1 = new Appearance();
           ColoringAttributes ca1 = new ColoringAttributes();
           ca1.setColor(1.0f, 0.0f, 0.0f);
           ap1.setColoringAttributes(ca1);
          Shape3D textShape1 = new Shape3D(textGeom1,ap1);
           tg_kostki1.addChild(textShape1);
           Font3D font3d2 = new Font3D(new Font("Helvetica", Font.ITALIC, 1), new FontExtrusion());
           Text3D textGeom2 = new Text3D(font3d2, new String("DWA"), new Point3f(-4.0f, 0.0f, 0.0f));
          Appearance ap2 = new Appearance();
           ColoringAttributes ca2 = new ColoringAttributes();
           ca2.setColor(0.0f, 1.0f, 0.0f);
           ap2.setColoringAttributes(ca2);
           Shape3D textShape2 = new Shape3D(textGeom2,ap2);
           tg_kostki2.addChild(textShape2);
           SimpleBehavior2 myRotationBehavior2 = new SimpleBehavior2(tg_kostki2);
           myRotationBehavior2.setSchedulingBounds(new BoundingSphere(new Point3d(0, 0, 0), 1000));
           korzen.addChild(myRotationBehavior2);
          korzen.compile();
           return korzen;
         public class SimpleBehavior extends Behavior
             private TransformGroup targetTG;
             private Transform3D rotation2 = new Transform3D();
             private WakeupCriterion wakeupNextFrame;
             private Transform3D rotation = new Transform3D();
             private double angle, x, angle2;
             SimpleBehavior(TransformGroup targetTG)
                this.targetTG = targetTG;
                wakeupNextFrame = new WakeupOnElapsedFrames(5);
             public void initialize()
                wakeupOn(new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED));     
                angle = -3.0f;
                angle2 = 10;
                x = 0.2;
             public void processStimulus(Enumeration criteria)
                if (angle < angle2)
                 x = x + 0.001;
                 angle += x;
                 rotation.setTranslation(new Vector3d(-angle, 0, 0));
                 targetTG.setTransform(rotation);
                 this.wakeupOn(wakeupNextFrame);
                else
                 angle2 = angle2 + 10;
                 x = -x;
                 wakeupOn(new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED));
         public class SimpleBehavior2 extends Behavior
              private TransformGroup TG;
              private WakeupOnCollisionEntry wEnter;
             private WakeupOnCollisionExit wExit;
             private WakeupOnCollisionMovement wMove;
             private Transform3D rotation = new Transform3D();
             private Transform3D rotation2 = new Transform3D();
             private WakeupCriterion wakeupNextFrame;
             private double angle, x, angle2;
             SimpleBehavior2(TransformGroup targetTG)
               TG = targetTG;
               wakeupNextFrame = new WakeupOnElapsedFrames(20);
               wMove = new WakeupOnCollisionMovement(TG);
             public void initialize()
               wakeupOn(wMove);
               x = 0;
             public void processStimulus(Enumeration criteria)
               rotation.rotX(x);
               x = x + 0.1;
               rotation2.setTranslation(new Vector3d(-3f, 0f, 0f));
               rotation.mul(rotation2);
               TG.setTransform(rotation);
               wakeupOn(wMove);
         public static void main(String[] args)
             new MainFrame(new Tlo3D(), 500, 500);
    }A simple grey floor with 2 texts objects on it, right mouse button moves "jeden" to the left, while "jeden" intersects "dwa", "dwa" rotates around its X axis, then, when "jeden" stops moving you can click again to force the movement in right direction, so that "jeden" is going to intersect "dwa" once again. The thing is, that while "jeden" moves left everyhing is allright, "dwa" rotates as long as both objects remain in collision, however, as "jeden" moves back (that is in the right direction) "dwa" keeps rotating even though they are not colliding anymore. The best way is just to copy /paste that code and try it out to observe what kind of problem i am facing.
    Another question : how can i rewrite that code, so that "dwa" object could do something on wakeupOnCollisionExit, for example move up.
    regards, Lukasz

    How did you solve this problem?
    I'm having the same issue.
    It would mean the word to me if you could share your solution.

  • Adding Canvas3D image to a JPanel or JFrame

    My team has developed a 3D game board and we want to add it to a JPanel. The test code below works fine but we want to add this to a JPanel. Can you put a Canvas3D in a JPanel?
    import java.applet.Applet;
    import java.awt.BorderLayout;
    import java.awt.Frame;
    import java.awt.event.*;
    import com.sun.j3d.utils.applet.MainFrame;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.geometry.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import java.awt.event.*;
    import java.util.Enumeration;
    import com.sun.j3d.utils.behaviors.mouse.*;
    import com.sun.j3d.utils.behaviors.keyboard.*;
    public class ProxyBoard extends Applet
         public class SimpleBehave extends Behavior
              private TransformGroup targetTG;
              private Transform3D rotation = new Transform3D();
              private double angle = 0.0;
              SimpleBehave(TransformGroup targetTG)
                   this.targetTG = targetTG;
              public void initialize()
                   this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
              public void processStimulus(Enumeration criteria)
                   angle +=0.05;
                   rotation.rotX(angle);
                   targetTG.setTransform(rotation);
                   this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
         public ProxyBoard()
              setLayout(new BorderLayout());
              Canvas3D canvas3D = new Canvas3D(null);
              add("Center", canvas3D);
              SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
              simpleU.getViewingPlatform().setNominalViewingTransform();
              BranchGroup scene = createSceneGraph(simpleU);
              scene.compile();
              simpleU.addBranchGraph(scene);
         public BranchGroup createSceneGraph(SimpleUniverse su)
              BranchGroup boardBG = new BranchGroup();
              TransformGroup vpTrans = null;
              BoundingSphere mouseBounds = null;
              vpTrans = su.getViewingPlatform().getViewPlatformTransform();
              mouseBounds = new BoundingSphere(new Point3d(), 1000.0);
              KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(vpTrans);
              keyNavBeh.setSchedulingBounds(mouseBounds);
              boardBG.addChild(keyNavBeh);
              MouseRotate myMouseRotate = new MouseRotate(MouseBehavior.INVERT_INPUT);
              myMouseRotate.setTransformGroup(vpTrans);
              myMouseRotate.setSchedulingBounds(mouseBounds);
              boardBG.addChild(myMouseRotate);
              MouseTranslate myMouseTranslate = new MouseTranslate(MouseBehavior.INVERT_INPUT);
              myMouseTranslate.setTransformGroup(vpTrans);
              myMouseTranslate.setSchedulingBounds(mouseBounds);
              boardBG.addChild(myMouseTranslate);
              MouseZoom myMouseZoom = new MouseZoom(MouseBehavior.INVERT_INPUT);
              myMouseZoom.setTransformGroup(vpTrans);
              myMouseZoom.setSchedulingBounds(mouseBounds);
              boardBG.addChild(myMouseZoom);
              Board board = new Board();
              Transform3D pegPositions[] = new Transform3D[8];
              TransformGroup pegPositionsTG[] = new TransformGroup[8];
              Pegs pegs[] = new Pegs[8];
              Transform3D translate = new Transform3D();
              translate.set(new Vector3f(0.0f, -1.0f, -5.0f));
              TransformGroup boardTGT1 = new TransformGroup(translate);
              TransformGroup boardTGR1 = new TransformGroup();
              boardTGR1.setCapability(boardTGR1.ALLOW_TRANSFORM_WRITE);
              for(int i = 0; i < 8; i++)
                   pegs[i] = new Pegs();
                   pegPositions[i] = new Transform3D();
                   pegPositions.set(new Vector3f(-2.5f, 0, (float)(-i/4.0)));
                   pegPositionsTG[i] = new TransformGroup(pegPositions[i]);
                   pegPositionsTG[i].addChild(pegs[i].getTransformGroup());
                   boardTGT1.addChild(pegPositionsTG[i]);               
              boardTGR1.addChild(board.getBoard());
              SimpleBehave myRotate = new SimpleBehave(boardTGR1);
              myRotate.setSchedulingBounds(new BoundingSphere());
              boardBG.addChild(myRotate);
              boardTGT1.addChild(boardTGR1);
              boardBG.addChild(boardTGT1);                    
              boardBG.compile();
              return boardBG;
         public static void main(String[] args)
              Frame frame = new MainFrame(new ProxyBoard(), 800, 600);
    /*-------------Main Source Container------------------*/
    public class Proxy extends JFrame
         implements MouseMotionListener
         private JDesktopPane myDesktop;
         private JPanel panel;
         private JLabel statusBar, position;
         private JSlider zSlide, zSlide1;
         private ImageIcon test;
         private int i;
         public Proxy()
              super("Proxy Board Prototype 1.2.2");
              i=0;
              statusBar = new JLabel();
              getContentPane();
              myDesktop = new JDesktopPane();
              getContentPane().add(myDesktop);
    public static void main(String args[])
              Proxy app = new Proxy();
              //new MainFrame( new Proxy(), 800, 600 );
    //          app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    /*-------------JPanel I want to hold to the 3D Graphics--------*/
    class Session extends JPanel
         implements MouseMotionListener
         private ImageIcon test;
         private JLabel position;
         private JSlider zSlide;
         private JPanel panel, gPanel;
         static int openFrameCount = 0;
         public Session()
              //super("", true, true, true, true);
              setLayout(new FlowLayout());
              openFrameCount++;
         //setTitle("Untitled Message " + openFrameCount);
    ProxyBoard pb = new ProxyBoard();//<-Graphic Class
    gPanel = new JPanel();
    gPanel.add(pb);//<-I want the 3D Graphic here
              test = new ImageIcon("Layout.jpg");
              JLabel pic = new JLabel(test);
              addMouseMotionListener( this );
              zSlide = new JSlider(SwingConstants.VERTICAL, 600, 10);
              zSlide.setMajorTickSpacing(25);
              zSlide.setPaintTicks(true);
              zSlide.setToolTipText("Zoom");
              panel.add(zSlide, BorderLayout.NORTH);
              panel.add(gPanel, BorderLayout.CENTER);//<-Graphic Here
              panel.add(position, BorderLayout.SOUTH);
              add(panel);
              //pack();
              setSize(200,200);
              setVisible (true);

    Yes you can. Just use the add method of JPanel. However note this
    http://www.j3d.org/faq/swing.html (specially read this: http://java.sun.com/products/jfc/tsc/articles/mixing/)
    when mixing Lightweight (JPanel) and Heavyweight (Canvas3D) components.

  • I want to create a border...

    but it is not working!!!!!!! I want to create a border around a box. What I have done is create 2 separate transform groups one with the filled boxes and another with lines. The border works fine if it is just around one box in any position but when it is placed around a group of boxes it doesn't work! Consider the board a boardgame board... there have to be borders around the boxes so that the users can know where a square ends and begins spent all day on this today... didn't think that something so simple would be so difficult!! Thank you in advance for helping! Below is the code
    //This is the code for creating the squares
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.geometry.*;
    import com.sun.j3d.utils.image.TextureLoader;
    public class Square
         public static final float LENGTH = (float)0.05;
         public static final float DEPTH = (float)0.0125;
         public int column;
         public int row;
         public float x;
         public float y;
         public float z;
         private TransformGroup trans;
         private TransformGroup blackLines;
         private Box square;
         private Box lineSquare;
         private Group subGroup;
         private Group lineGroup;
         public Square(Texture boardpic, int column, int row)
              this.column = column;
              this.row = row;
              subGroup = new BranchGroup();
              lineGroup = new BranchGroup();
              Color3f grey = new Color3f(0.5f,0.5f,0.5f);
              Color3f black = new Color3f(1.0f,1.0f,1.0f);
         Transform3D t = new Transform3D( );
              float distanceToEdge = ( LENGTH * (float)4.0 ) - ( LENGTH / (float)2.0 );
              //System.out.println(distanceToEdge);
              trans= new TransformGroup();
              blackLines = new TransformGroup();
              x = -distanceToEdge + ( column * LENGTH ) ;
         y = distanceToEdge - ( row * LENGTH ) ;
              z = -DEPTH;
    Vector3f v = new Vector3f(x, y, z);
              t.setTranslation(v);
              trans.setTransform(t);
              trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
              trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
              blackLines.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
              blackLines.setTransform(t);
              //sets a black line around a square                    
              Appearance blackLineApp = new Appearance();
              blackLineApp.setColoringAttributes(new ColoringAttributes(black,ColoringAttributes.NICEST));
              PolygonAttributes blPolyAt=new PolygonAttributes(PolygonAttributes.POLYGON_LINE,
                                            PolygonAttributes.CULL_FRONT,0f);
              //blPolyAt.setPolygonOffset(100.0f);
              //blPolyAt.setPolygonOffsetFactor(100.0f);
              blackLineApp.setPolygonAttributes(blPolyAt);
              lineSquare = new Box((LENGTH / 2.0f), (LENGTH / 2.0f), DEPTH, blackLineApp);
              subGroup.addChild(lineSquare);
              //Attributes for creating the filled box
              Appearance appearance = new Appearance();
              PolygonAttributes polyAt=new PolygonAttributes(PolygonAttributes.POLYGON_FILL,
                                            PolygonAttributes.CULL_NONE,0f);
              polyAt.setPolygonOffset(0.1f);
              polyAt.setPolygonOffsetFactor(0.1f);
              appearance.setPolygonAttributes(polyAt);
              appearance.setColoringAttributes(new ColoringAttributes(grey,ColoringAttributes.NICEST));
              appearance.setTexture(boardpic);
              TextureAttributes texAttr = new TextureAttributes();
              texAttr.setTextureMode(TextureAttributes.MODULATE);
              appearance.setTextureAttributes(texAttr);     
              Box square = new com.sun.j3d.utils.geometry.Box((LENGTH / 2.0f), (LENGTH / 2.0f), DEPTH, appearance);
              trans.addChild(square);
              subGroup.addChild(trans);
              subGroup.addChild(blackLines);
         public Group getGroup()
              return subGroup;
         public Group getLines()
              return lineGroup;
    //this the code for creating the board
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.GraphicsConfiguration;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.geometry.*;
    import com.sun.j3d.utils.image.TextureLoader;
    public class Board extends JFrame
         public Square[][] fullBoard = new Square[23][23];
         public Board()
              GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
              Canvas3D c = new Canvas3D(config);
              BranchGroup bg = new BranchGroup();
              TextureLoader picload = new TextureLoader("brown001.gif", this);
              Texture texture = picload.getTexture();
              texture.setMagFilter(Texture.BASE_LEVEL_LINEAR | Texture.NICEST);
              texture.setMinFilter(Texture.BASE_LEVEL_LINEAR | Texture.NICEST);
              for(int col = 1; col < 23; col++)
                   for (int row = 1; row < 23; row++)
                        fullBoard[col][row]=new Square(texture, (col-11), (row-11));
                        bg.addChild(fullBoard[col][row].getGroup());
                        //bg.addChild(fullBoard[col][row].getLines());
              TransformGroup tg = new TransformGroup();
              tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
              Transform3D rotation = new Transform3D();
              rotation.rotX(java.lang.Math.toRadians( -45 ));
              tg.setTransform(rotation);
              tg.addChild(bg);
              BranchGroup scene = new BranchGroup();
              scene.addChild(tg);
              scene.compile();
              SimpleUniverse u = new SimpleUniverse();
              u.getViewingPlatform().setNominalViewingTransform();
              u.addBranchGraph(scene);
              System.out.println("I am here now");
         public static void main (String [] args)
              Board b = new Board();
    Thanks again...
    -JET-

    Sorry the line:
    subGroup.addChild(lineSquare);
    should read:
    blackLines.addChild(lineSquare);

  • Java3D Picking Problem

    Hi, I have problem with picking. I have two shapes 3D (for example) and if there are separately (not hidden) picking is OK. But when I rotate them using myMouseRotate or rotation.rotY(angle) so one of them is hiden, it's always pick me only one of them, even it's hidden. I use pickClosest() method. What's wrong?
    Please help me
    pozdrawiam
    Wojtek

    It doesn't work because I need to pick one of this shape. I think that it's something with rotation... Check this simply full code below. Press any key to rotate. At the begining you pick ColorCube and it' ok. But if you rotate 180 degrees you will pick ColorCube again and it's wrong. Additionally if you change "angle = 3.14/2;" to "angle = 3*3.14/2;" you can pick Sphere but can't pick ColorCube.
    How can I solve it?? Maybe when I rotate something is change with direction of pick rays.
    Code - Pick_1.java:
    import com.sun.j3d.utils.picking.*;
    import com.sun.j3d.utils.universe.SimpleUniverse;
    import com.sun.j3d.utils.geometry.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import java.awt.event.*;
    import java.awt.*;
    import com.sun.j3d.utils.behaviors.mouse.*;
    import java.util.Enumeration;
    public class Pick_1 extends MouseAdapter {
         private PickCanvas pickCanvas;
         static double angle = 0.0;
         public class SimpleBehavior extends Behavior{
         private TransformGroup targetTG;
         private Transform3D rotation = new Transform3D();
         // private double angle = 0.0;
         // create SimpleBehavior
         SimpleBehavior(TransformGroup targetTG){
         this.targetTG = targetTG;
         // initialize the Behavior
         // set initial wakeup condition
         // called when behavior beacomes live
         public void initialize(){
         // set initial wakeup condition
         this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
         // behave
         // called by Java 3D when appropriate stimulus occures
         public void processStimulus(Enumeration criteria){
         // decode event
         // do what is necessary
         angle += 0.1;
         rotation.rotY(angle);
         targetTG.setTransform(rotation);
         //rotation.set(new Vector3f(-0.1f, 0.0f, 0.0f));
         //targetTG.setTransform(rotation);
         this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
         public Pick_1()
         Frame frame = new Frame("Box and Sphere");
         GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
         Canvas3D canvas = new Canvas3D(config);
         canvas.setSize(400, 400);
         SimpleUniverse universe = new SimpleUniverse(canvas);
         BranchGroup group = new BranchGroup();
              TransformGroup objTransform = new TransformGroup();     
         objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
         objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
         group.addChild(objTransform);     
         /*      MouseRotate myMouseRotate = new MouseRotate();
         myMouseRotate.setTransformGroup(objTransform);
         myMouseRotate.setSchedulingBounds(new BoundingSphere());
         group.addChild(myMouseRotate);
         MouseTranslate myMouseTranslate = new MouseTranslate();
         myMouseTranslate.setTransformGroup(objTransform);
         myMouseTranslate.setSchedulingBounds(new BoundingSphere());
         group.addChild(myMouseTranslate);
         MouseZoom myMouseZoom = new MouseZoom();
         myMouseZoom.setTransformGroup(objTransform);
         myMouseZoom.setSchedulingBounds(new BoundingSphere());
         group.addChild(myMouseZoom);
         SimpleBehavior myRotationBehavior = new SimpleBehavior(objTransform);
         myRotationBehavior.setSchedulingBounds(new BoundingSphere());
              group.addChild(myRotationBehavior);
         //create a sphere
         Vector3f vector2 = new Vector3f(0.6f, 0.0f, 0.0f);
         Transform3D transform2 = new Transform3D();
         transform2.setTranslation(vector2);
         TransformGroup transformGroup2 = new TransformGroup(transform2);
         Appearance appearance = new Appearance();
         appearance.setPolygonAttributes(
         new PolygonAttributes(PolygonAttributes.POLYGON_LINE,
         PolygonAttributes.CULL_BACK,0.0f));
         Sphere sphere = new Sphere(0.1f,appearance);
         transformGroup2.addChild(sphere);
         objTransform.addChild(transformGroup2);
         // create a color cube
         Vector3f vector = new Vector3f(0.3f, 0.0f, 0.0f);
         Transform3D transform = new Transform3D();
         transform.setTranslation(vector);
         TransformGroup transformGroup = new TransformGroup(transform);
         ColorCube cube = new ColorCube(0.1);
         transformGroup.addChild(cube);
         objTransform.addChild(transformGroup);
         //dodatkowo przesuniecie od razu o 90 stopni
              Transform3D obrot = new Transform3D();
                   angle = 3.14/2;
              obrot.rotY(angle);                                   //!!!!! takie przesuniecie dobrze dziala
         objTransform.setTransform(obrot);                //WIEC O CO CHODZI!!!!!!!!!!!!!!!
         universe.getViewingPlatform().setNominalViewingTransform();
         universe.addBranchGraph(group);
         frame.addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent winEvent) {
         System.exit(0);
         frame.add(canvas);
         pickCanvas = new PickCanvas(canvas, group);
         pickCanvas.setMode(PickCanvas.BOUNDS);
         canvas.addMouseListener(this);
         frame.pack();
         frame.show();
         public static void main( String[] args ) {
         new Pick_1();
         public void mouseClicked(MouseEvent e)
         pickCanvas.setShapeLocation(e);
         PickResult result = pickCanvas.pickClosest();
         if (result == null) {
         System.out.println("Nothing picked");
         } else {
         Primitive p = (Primitive)result.getNode(PickResult.PRIMITIVE);
         Shape3D s = (Shape3D)result.getNode(PickResult.SHAPE3D);
         if (p != null) {
         System.out.println(p.getClass().getName());
         } else if (s != null) {
         System.out.println(s.getClass().getName());
         } else{
         System.out.println("null");
         /*pickCanvas.setShapeLocation(e);
         PickResult result = pickCanvas.pickClosest();
         if (result == null) {
         System.out.println("Nothing picked");
         } else {
         // PickIntersection pi = result.getClosestIntersection(
         pickCanvas.getStartPosition();
         Shape3D s = (Shape3D)result.getNode(PickResult.SHAPE3D);
         System.out.println(s.getClass().getName());
    } // end of class Pick

  • Determining Whether Current Animation Has Been Completed

    For the iPhone, I want to combine two animations together but am crossing some problems. Basically, I want to hide and then show some outlets in one go. I can do this when they are separated into different events, but I when I combine them, the second round of animations (the show portion) takes precedence (when setAnimationBeginsFromCurrentState:FALSE). When it is setAnimationBeginsFromCurrentState:TRUE, nothing really happens at all.
    Is there some way that I can have it wait till all the hiding stuff and then do the show stuff? I suppose this defeats the purpose of core animation's implicit purpose, so I guess I'm trying to go for a keyframe type of approach (I'm not sure. I'm pretty new to objective-c).
    // The following chunk is set on awakeFromNib
    zero = CGPointMake(250.0f, 524.0f);
    bCenter01 = [button01 center];
    bCenter02 = [button02 center];
    //here are just the first two of my buttons that I wan't to animate, but imagine 14 more after this
    // END awakeFromNib chunk
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // assume this is a button press
    // HIDE portion
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:FALSE];
    float time = 1.7;
    CGAffineTransform rotate = CGAffineTransformMakeRotation(-M_PI);
    [UIView setAnimationDuration:time];
    [button01 setCenter:zero];
    [button01 setTransform:rotate];
    [button01 setAlpha:0.0];
    time -= .1;
    [UIView setAnimationDuration:time];
    [button02 setCenter:zero];
    [button02 setTransform:rotate];
    [button02 setAlpha:0.0];
    time -= .1;
    // again, assume this is repeated 14 more times for the other buttons
    // SHOW portion (this is basically where I want the animation to start after the HIDE has finished
    // currently, when the button is pressed, the animation currently just starts from here (as it has "instantly" moved everything from the hide portion)
    time = 0.2;
    [UIView setAnimationDuration:time];
    [button01 setTransform:rotate];
    [button01 setCenter:bCenter01];
    [button01 setAlpha:1.0];
    time += .1;
    [UIView setAnimationDuration:time];
    [button02 setTransform:rotate];
    [button02 setCenter:bCenter02];
    [button02 setAlpha:1.0];
    time += .1;
    // again, assume 14 more...
    [UIView commitAnimations];

    I figured out how to do this. If anyone wants to know how to perform an animation after another one, this is what I did...
    By the way, you don't have to declare the goPutThemBack in your header file.
    - (IBAction)clear:(id)sender {
    [UIView beginAnimations:nil context:NULL]
    [button01 setCenter:offWindow];
    // all your animations up here for the first part (let's assume this will hide something)
    // now the magic to starting the second part
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(goPutThemBack:finished:context:)];
    // end magic part
    [UIView commitAnimations];
    - (void)goPutThemBack:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    [UIView beginAnimations:nil context:NULL];
    [button01 setCenter:onWindow];
    // second set of animations
    [UIView commitAnimations];

  • Cannot resolve import statements

    I recently decided to start messing around with some Java3d. I tried to get an example program to try to dissect but I can't even get past compilation. The main problem is the fact that the import statements cannot be resolved. I thought maybe I was using an outdated example program but upon further inspection of Oracle's own Java3d tutorials I saw the same import statements. I downloaded java3d 1.5.1 because I thought perhaps it wasn't included in the java core classes. This did not help me at all. So maybe it is a problem with the IDE (eclipse) not recognizing them. However, I have had no such success with Google thus far. I realize that this is more than likely a horribly simple mistake that anyone over a novice understanding of Java would be able to spot. But if anyone could help me figure out why I can't compile it would be much appreciated.
    Regards,
    Corey
    Import statements that would not resolve
    import com.sun.j3d.utils.geometry.GeometryInfo;
    import com.sun.j3d.utils.geometry.NormalGenerator;
    import com.sun.j3d.utils.universe.SimpleUniverse;
    import javax.media.j3d.*;
    import javax.vecmath.*;Full program
    import java.awt.Color;
    import com.sun.j3d.utils.geometry.GeometryInfo;
    import com.sun.j3d.utils.geometry.NormalGenerator;
    import com.sun.j3d.utils.universe.SimpleUniverse;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    // An Egyptian pyramid
    // Base divided into two triangles
    public class PyramidExample {
         public static void main(String[] args) {
              SimpleUniverse universe = new SimpleUniverse();
              BranchGroup group = new BranchGroup();
              Point3f e = new Point3f(1.0f, 0.0f, 0.0f); // east
              Point3f s = new Point3f(0.0f, 0.0f, 1.0f); // south
              Point3f w = new Point3f(-1.0f, 0.0f, 0.0f); // west
              Point3f n = new Point3f(0.0f, 0.0f, -1.0f); // north
              Point3f t = new Point3f(0.0f, 0.721f, 0.0f); // top
              TriangleArray pyramidGeometry = new TriangleArray(18,
                        TriangleArray.COORDINATES);
              pyramidGeometry.setCoordinate(0, e);
              pyramidGeometry.setCoordinate(1, t);
              pyramidGeometry.setCoordinate(2, s);
              pyramidGeometry.setCoordinate(3, s);
              pyramidGeometry.setCoordinate(4, t);
              pyramidGeometry.setCoordinate(5, w);
              pyramidGeometry.setCoordinate(6, w);
              pyramidGeometry.setCoordinate(7, t);
              pyramidGeometry.setCoordinate(8, n);
              pyramidGeometry.setCoordinate(9, n);
              pyramidGeometry.setCoordinate(10, t);
              pyramidGeometry.setCoordinate(11, e);
              pyramidGeometry.setCoordinate(12, e);
              pyramidGeometry.setCoordinate(13, s);
              pyramidGeometry.setCoordinate(14, w);
              pyramidGeometry.setCoordinate(15, w);
              pyramidGeometry.setCoordinate(16, n);
              pyramidGeometry.setCoordinate(17, e);
              GeometryInfo geometryInfo = new GeometryInfo(pyramidGeometry);
              NormalGenerator ng = new NormalGenerator();
              ng.generateNormals(geometryInfo);
              GeometryArray result = geometryInfo.getGeometryArray();
              // yellow appearance
              Appearance appearance = new Appearance();
              Color3f color = new Color3f(Color.yellow);
              Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
              Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
              Texture texture = new Texture2D();
              TextureAttributes texAttr = new TextureAttributes();
              texAttr.setTextureMode(TextureAttributes.MODULATE);
              texture.setBoundaryModeS(Texture.WRAP);
              texture.setBoundaryModeT(Texture.WRAP);
              texture.setBoundaryColor(new Color4f(0.0f, 1.0f, 0.0f, 0.0f));
              Material mat = new Material(color, black, color, white, 70f);
              appearance.setTextureAttributes(texAttr);
              appearance.setMaterial(mat);
              appearance.setTexture(texture);
              Shape3D shape = new Shape3D(result, appearance);
              group.addChild(shape);
              // above pyramid
              Vector3f viewTranslation = new Vector3f();
              viewTranslation.z = 3;
              viewTranslation.x = 0f;
              viewTranslation.y = .3f;
              Transform3D viewTransform = new Transform3D();
              viewTransform.setTranslation(viewTranslation);
              Transform3D rotation = new Transform3D();
              rotation.rotX(-Math.PI / 12.0d);
              rotation.mul(viewTransform);
              universe.getViewingPlatform().getViewPlatformTransform().setTransform(
                        rotation);
              universe.getViewingPlatform().getViewPlatformTransform().getTransform(
                        viewTransform);
              // lights
              BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
                        1000.0);
              Color3f light1Color = new Color3f(.7f, .7f, .7f);
              Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
              DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
              light1.setInfluencingBounds(bounds);
              group.addChild(light1);
              Color3f ambientColor = new Color3f(.4f, .4f, .4f);
              AmbientLight ambientLightNode = new AmbientLight(ambientColor);
              ambientLightNode.setInfluencingBounds(bounds);
              group.addChild(ambientLightNode);
              universe.addBranchGraph(group);
    }

    Hi,
    - The latest Java 3D release is *1.5.2*. Uninstall older versions.
    - Java 3D home: http://java3d.java.net/
    - Java 3D project: http://java.net/projects/java3d
    - Java 3D downloads: http://java3d.java.net/binary-builds.html
    - Start with one of the Java 3D examples from "j3d-examples-1_5_2-src.zip"
    - Use eclipse *3.6.2*, it should recognize Java 3D's jars if they are installed in '..\jre\lib\ext\'. See also Java3D + Newer Eclipse Version -> Access Restriction (solution + question)
    August

  • OS 2.1 Bug with CGAffineTransform and Views?

    Anyone get any complaints about shifting images in OS2.1? I use
    [[rootViewController view] addSubview:[holdemController view]];
    CGAffineTransform rotate = CGAffineTransformMakeRotation(1.57079633);
    rotate = CGAffineTransformTranslate (rotate, 80.0, 80.0);
    [[rootViewController view] setTransform:rotate];
    And it works fine on the previous OS 2.0 release, but reports have been that's broken in 2.1
    Anyone else seeing these complaints?

    I fixed it by setting the view to the center of the window rather than shifting it 80x80.
    eg: controller view center = window center
    It was a bug they fixed I'm sure in 2.1, but bug fixes are sometimes just as bad if not worse than the bugs themselves.
    C'est la vie.
    Hopefully they accelerate the review of my bug fix though, considering it was their change that broke it. I'm not holding my breath, however..

  • Canvas and BufferedImage display different.

    I use the same method to paint the Canvas and the BufferedImage. But the Graphics2D drawString method
    shows up correctly on the Canvas but not on the BufferedImage (JPEG). Why is there a difference?
    I use the Graphics2D to rotate the text 90 degrees.
    I can't think of any reason why the display comes out different.
    Any suggestions???
    Thanks.

    Here is the code for putting the Canvas graphics onto the BufferedImage (JPEG).
    public void save(HCanvas comp) {
         int w = comp.getWidth();
         int h = comp.getHeight();
         Frame frame = new Frame();
         BufferedImage im = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
         Graphics2D g2 = im.createGraphics();
         g2.setPaint(Color.white);
         g2.fillRect(0,0,w,h);
         g2.setPaint(Color.black);          // back to default color
         comp.paint(g2);                              // Graphics argument
         g2.dispose();
         FileDialog fd = new FileDialog(frame,"Save As JPEG",FileDialog.SAVE);
         fd.show();
         try {
              String dum;
              dum = fd.getDirectory() + fd.getFile();
              OutputStream out = new FileOutputStream(dum);
              JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
              encoder.encode(im);
              out.flush();
              out.close();
              im.flush();
         } catch (Exception FileNotFoundException) {
              String errormsg = "File Not Assigned";
              JOptionPane.showMessageDialog(frame, errormsg);

Maybe you are looking for

  • Opinion: From SVHS-C to DVD

    I have old SVHS-C tapes but the camcorder that made them is long gone. I want to get them onto DVD's and I can think of a couple of ways to do it: Start with my QSVHS player (reads SVHS tapes but converts them the output to VHS) or buy an SVHS (under

  • I modified graphics colors and can't get back to a normal display

    It does not help to try and delete Foxfire and re-download it. If I start Foxfire and then start Internet Explore, the bad color scheme is applied to Internet Explorer so the problem has to do with Foxfire load parameters.

  • Extracting portions of a sequence

    New to Premiere Pro.  Using Lynda.com and classroom in a book to learn. I have a large single .AVI file (2 hours) I want to break it into multiple .AVI files as each portion is different subject so I can name the files ABC.avi DEF.avi for later use. 

  • Aperture will not open on my new MacBook Pro. I'm running version 10.8.3.

    The following message appears: "Check with the developer to make sure Aperture works with this version of OS X. You may need to reinstall the application. Be sure to install any available updates for the application and OS X." I've reinstalled Apertu

  • TS1702 How we can remove/un-install an app from iPad?

    Can someone tell that how to remove the installed app from iPad?