Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  OrbitBehavior and Text3D strange thing happens  (Read 1506 times)
0 Members and 1 Guest are viewing this topic.
Offline Mario Sol

Junior Newbie





« Posted 2012-01-30 21:25:48 »

Hi all,

putting it briefly:
a) i have put some Text3D objects along the z axis
b) when going past the origin Text3D objects disappear, Cylinders in front of Text3D go on being rendered
this is the code,
the red cylinder is at the origin

quite confused...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.image.*;
import com.sun.j3d.utils.behaviors.vp.*;
import java.awt.*;
import java.awt.Font;
import javax.swing.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class Text3DTest
{
public Text3DTest()
{
    BranchGroup group = new BranchGroup();
    Color3f green     = new Color3f(0.0f, 1.0f, 0.0f);
    Color3f white     = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f red       = new Color3f(0.7f, .15f, .15f);
    Color3f black     = new Color3f(0.0f, 0.0f, 0.0f);
   
    Vector3f direction    = new Vector3f(4.0f,-7.0f, -12.0f);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),300.0);


    AmbientLight ambientLightNode = new AmbientLight(white);
    ambientLightNode.setInfluencingBounds(bounds);
    group.addChild(ambientLightNode);

    Transform3D rot = new Transform3D();
    rot.setIdentity();
    rot.rotZ(Math.toRadians(90));
    TransformGroup tg = new TransformGroup(rot);
    Appearance ap     = new Appearance();
    ap.setMaterial(new Material(red, black, red, white, 1.0f));
    Cylinder RedAxis = new Cylinder(0.01f, 1000.0f, ap);
    tg.addChild(RedAxis);
    group.addChild(tg);



    BranchGroup text1 = Text3DTest.text("alpha", new Point3f(-5.0f, 0.0f, 15.0f));
    BranchGroup text2 = Text3DTest.text("bravo", new Point3f(-5.0f, 0.0f, 0.0f));
    BranchGroup text3 = Text3DTest.text("charlie", new Point3f(-5.0f, 0.0f, -15.0f));
    group.addChild(text1);
    group.addChild(text2);
    group.addChild(text3);

    BranchGroup text10 = Text3DTest.text("alpha", new Point3f(-5.0f, 5.0f, 15.0f));
    BranchGroup text20 = Text3DTest.text("bravo", new Point3f(-5.0f, 5.0f, 0.0f));
    BranchGroup text30 = Text3DTest.text("charlie", new Point3f(-5.0f, 5.0f, -15.0f));
    group.addChild(text10);
    group.addChild(text20);
    group.addChild(text30);

    BranchGroup text101 = Text3DTest.text("alpha", new Point3f(-5.0f, -5.0f, 15.0f));
    BranchGroup text201 = Text3DTest.text("bravo", new Point3f(-5.0f, -5.0f, 0.0f));
    BranchGroup text301 = Text3DTest.text("charlie", new Point3f(-5.0f, -5.0f, -15.0f));
    group.addChild(text101);
    group.addChild(text201);
    group.addChild(text301);

    BranchGroup cylinder1 = Text3DTest.cylinder(green, 0.0f, 0.0f, 10.0f);
    BranchGroup cylinder2 = Text3DTest.cylinder(red, 0.0f, 0.0f, 0.0f);
    BranchGroup cylinder3 = Text3DTest.cylinder(white, 0.0f, 0.0f, -10.0f);
    group.addChild(cylinder1);    
    group.addChild(cylinder2);
    group.addChild(cylinder3);

    JFrame f = new JFrame();
    GraphicsConfiguration gc = SimpleUniverse.getPreferredConfiguration();
    Canvas3D canvas = new Canvas3D(gc);
    f.add(new JPanel().add("Center",canvas));

    SimpleUniverse universe = new SimpleUniverse(canvas);
    OrbitBehavior orbit =  new OrbitBehavior(canvas, OrbitBehavior.REVERSE_ALL);
    orbit.setSchedulingBounds(bounds);
    ViewingPlatform vp = universe.getViewingPlatform();
    vp.setViewPlatformBehavior(orbit);
    vp = universe.getViewingPlatform();
    vp.getViewPlatform().setActivationRadius(1000.0f);
    TransformGroup steerTG = vp.getViewPlatformTransform();
    Transform3D t3d = new Transform3D( );
    steerTG.getTransform( t3d );
    Point3d viewerInitPos = new Point3d(0, 0, -20);
    Point3d viewerLooksAt = new Point3d(0, 0, 0);
    Vector3d upDirection  = new Vector3d(0,1,0);
    t3d.lookAt( viewerInitPos, viewerLooksAt, upDirection);
    t3d.invert();
    steerTG.setTransform(t3d);


    universe.addBranchGraph(group);

    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.setPreferredSize(new Dimension(600,600));
    f.pack();
    f.setVisible(true);
}
private static BranchGroup text(String text, Point3f pos)
{
    BranchGroup textBG = new BranchGroup();
    Font3D font3d = new Font3D(new Font("Helvetica", Font.PLAIN, 2), new FontExtrusion());
    Text3D textGeom = new Text3D(font3d, text, pos);
    Shape3D textShape = new Shape3D(textGeom);

    Color3f red       = new Color3f(0.7f, .15f, .15f);
    Color3f black     = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white     = new Color3f(1.0f, 1.0f, 1.0f);
    Appearance redAp = new Appearance();
    redAp.setMaterial(new Material(red, black, red, white, 1.0f));
    textShape.setAppearance(redAp);
    textBG.addChild(textShape);
    return textBG;
}
private static BranchGroup cylinder(Color3f color, float x, float y, float z)
{
    Color3f blue      = new Color3f(0.0f, 0.0f, 1.0f);
    Color3f white     = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f red       = new Color3f(0.7f, .15f, .15f);
    Color3f black     = new Color3f(0.0f, 0.0f, 0.0f);

    BranchGroup bg = new BranchGroup();
    Appearance ap2 = new Appearance();
    ap2.setMaterial(new Material(color, black, color, white, 1.0f));

    Cylinder cylinder = new Cylinder(0.5f, 1.0f, ap2);
    Transform3D transform = new Transform3D();
    Vector3f vector = new Vector3f(x, y, z);
    transform.set(vector);
    TransformGroup tg = new TransformGroup(transform);
    tg.addChild(cylinder);
    bg.addChild(tg);
    return bg;
}
public static void main(String[] args )
{
    new Text3DTest();
}
}
Offline tom
« Reply #1 - Posted 2012-01-30 22:00:29 »

Not sure if I understand what the problem is. I tried to run the code, and did not see any code. My only suggestion is to use an infinite bounds. Make the radius Double.POSITIVE_INFINITY. That will sort out any scoping issues. What you are seeing can also be the objects being ciipped by the back clip plane. You could try increasing it.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (49 views)
2014-10-17 03:59:02

Norakomi (38 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (34 views)
2014-10-15 16:18:58

TehJavaDev (65 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (54 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!