Hello !
Alessandro, you solved my problem, thanks!

Best regards
Fredrik

Below is the result:

        PlatformGeometry platformGeometry = new PlatformGeometry();
        Aim aim = new Aim(new Color3f(1f, 0f, 0f), new Vector3d(0.0,
0.0, -0.8), 0.005f, 0.005f);
        platformGeometry.addChild(aim);

                ViewingPlatform viewingPlatform = simpleUniverse.getViewingPlatform();
                viewingPlatform.setPlatformGeometry(platformGeometry);

public class Aim extends TransformGroup
{
        Color3f color;
        Vector3d position;
        float radius;
        float height;

        public Aim(Color3f c, Vector3d p, float r, float h)
        {
                color = c;
                position = p;
                radius = r;
                height = h;

                setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
                Transform3D transform3D = new Transform3D();
                transform3D.rotX(Math.PI/2.0);
                transform3D.setTranslation(position);
                setTransform(transform3D);
                Appearance appearance = new Appearance();
                ColoringAttributes coloringAttributes = new ColoringAttributes(color,
ColoringAttributes.FASTEST);
                appearance.setColoringAttributes(coloringAttributes);
                TransparencyAttributes transparencyAttributes = new
TransparencyAttributes(TransparencyAttributes.FASTEST, 1.0f);
                appearance.setTransparencyAttributes(transparencyAttributes);
                Cylinder cylinder = new Cylinder(radius, height, appearance);
                addChild(cylinder);

                Point3f[] verts = { new Point3f (-0.01f, 0.0f, 0.0f),new Point3f(0.01f,
0.0f, 0.0f)};
                Point3f[] verts2 = { new Point3f (-0.01f, 0.0f, 0.0f),new 
Point3f(0.01f,
0.0f, 0.0f)};
                Color3f black = new Color3f (1.0f, 1.0f, 1.0f);
                Color3f[] colors = {black, black};
                LineArray la = new LineArray (4, LineArray.COORDINATES |
LineArray.COLOR_3);
                la.setCoordinates (0, verts);
                la.setCoordinates (1, verts2);
                la.setColors (0, colors);
                la.setColors (1, colors);
                Shape3D shape = new Shape3D();
                shape.setGeometry (la);
                addChild(shape);

        }

}

-----Ursprungligt meddelande-----
Från: Discussion list for Java 3D API
[mailto:[EMAIL PROTECTED] Alessandro Borges
Skickat: den 10 februari 2004 16:29
Till: [EMAIL PROTECTED]
Ämne: Re: [JAVA3D] How to paint a aim on the GlassPane


Hi,
This will not work.
try to use a texture with transparency mask in a
platformGeometry.
See Java3D's PlatformGeometry demo

Alessandro

 --- Fredrik Andersson
<[EMAIL PROTECTED]> escreveu: > Hello!
>
> I try to paint a filled oval on the glasspane, but
> it doesn't seems to work.
>
> This works on a regular JFrame but doesn't seems to
> work on a JMainFrame
> even do it extends from JFrame.
>
> My code to test my attemtp is below.
>
> So if any one could give me a hint or solution for
> this it would be great.
>
> The reason for this is to paint a aim like a
> haircross in a 3D-world. So
> perhaps someone got a better strategy for this.
>
> Best regards
> Fredrik
>
> //The glasscomponent
>
> import java.awt.*;
>
> public class AimPane extends JComponent
> {
>     int x;
>     int y;
>
>     public AimPane(int x, int y)
>     {
>         this.x = x;
>         this.y = y;
>         setVisible(true);
>         repaint();
>     }
>
>     protected void paintComponent(Graphics g)
>     {
>         g.setColor(Color.blue);
>         g.fillOval(x, y, 20, 20);
>     }
> }
>
> //The class to run this
> import java.applet.*;
> import java.awt.*;
> 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 com.sun.j3d.utils.behaviors.keyboard.*;
> import javax.media.j3d.*;
> import javax.vecmath.*;
> import javax.swing.*;
>
> import java.util.*;
>
> import com.sun.j3d.utils.applet.*;
>
>
>
>
> public class TestAimPane extends Applet
> {
>         Canvas3D canvas3D;
>         SimpleUniverse simpleUniverse;
>
>         public void init()
>         {
>                 long start =
> System.currentTimeMillis();
>                 setLayout(new BorderLayout());
>                 GraphicsConfiguration config =
> SimpleUniverse.getPreferredConfiguration();
>                 canvas3D = new Canvas3D(config);
>                 add("Center", canvas3D);
>                 simpleUniverse = new
> SimpleUniverse(canvas3D);
>
>                 TransformGroup transformGroup = new
> TransformGroup();
>                 Transform3D transform3D = new
> Transform3D();
>                 transform3D.setTranslation( new
> Vector3d( 0.0, 0.0, -8.0 ) );
>
> transformGroup.setTransform(transform3D);
>                 transformGroup.addChild(new
> ColorCube());
>
>                 BranchGroup branchGroup = new
> BranchGroup();
>
> branchGroup.addChild(transformGroup);
>
>                 simpleUniverse.addBranchGraph(
> branchGroup );
>
>                 long end =
> System.currentTimeMillis();
>
> System.out.println((end-start)/1000);
>         }
>
>
>         public static void main(String[] args)
>         {
>                 JMainFrame jMainFrame = new
> JMainFrame(new TestAimPane(), 700, 300);
>                 Dimension dimension =
> jMainFrame.getToolkit().getScreenSize();
>                 Rectangle bounds =
> jMainFrame.getBounds();
>                 jMainFrame.setBounds(
> (dimension.width - bounds.width) / 2,
> (dimension.height - bounds.height) / 2, 700, 300);
>                 AimPane aimPane = new
> AimPane(bounds.width/2, bounds.height/2);
>                 jMainFrame.setGlassPane(aimPane);
>                 aimPane.setVisible(true);
>
>                 try
>                 {
>                         java.awt.Robot robot = new
> java.awt.Robot();
>
>
robot.mouseMove(dimension.width/2,dimension.height/2);
>                 }
>                 catch(Exception e)
>                 {
>                 }
>
>     }
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED]
> and include in the body
> of the message "signoff JAVA3D-INTEREST".  For
> general help, send email to
> [EMAIL PROTECTED] and include in the body of the
> message "help".

______________________________________________________________________

Yahoo! GeoCities: 15MB de espaço grátis para criar seu web site!
http://br.geocities.yahoo.com/

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to