Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (430)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (468)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / Xith3D Forums / Re: Problems with picking (need help) on: 2005-09-05 13:11:56
Hi arne,

I really thank you. Your picking code

http://192.18.37.44/forums/index.php?topic=5549.msg75762#msg75762

really helped me solving my problems.

I added some lines so the code can now handle IndexedTriangleArrays too (that was what I needed).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
if (geomArr instanceof IndexedTriangleArray) {
    //System.out.println("indexedTriangleArray");
    IndexedTriangleArray geomArr1 = (IndexedTriangleArray) geomArr;
    int[] indizes = geomArr1.getIndex();
    for (int j = 0; j < indizes.length; j += 3) {
        geomArr.getVertex(indizes[j], pos1);
        geomArr.getVertex(indizes[j + 1], pos2);
        geomArr.getVertex(indizes[j + 2], pos3);
        t.set(pos1, pos2, pos3);
        float f = t.test(transOrigin, transDirection,closestIntersect);
        if (f != -1) { // there is a collision
             f = f / transDirection.length();
             if (f < closestIntersect) {
                   closestIntersect = f;
                   r.setDistance(f);
                   nearest = r;
              }//if
         }//if
    }//for
}//if
2  Java Game APIs & Engines / Xith3D Forums / Problems with picking (need help) on: 2005-08-31 15:42:34
Hello everyone,

I have a scene and want to highlight some objects when the mouse is over them. So I took the simple "picking demo" from the xith.org page and modified it in that way, that I changed the mousePressed() method to a mouseMoved() method. But running that demo and moving the mouse over the window made the complete application hang after a short time. There is no exeption or anything else that could help me to determine where the failure comes from.

So I need some help. Please try my code and to tell me weather the application hangs too on your machine or not. I am thankful for any suggestions that could help me to solve that problem.

Thanks a lot

Marc

-----------------------------------

import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.util.BitSet;

import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;

import com.xith3d.picking.PickRenderResult;
import com.xith3d.render.CanvasPeer;
import com.xith3d.render.RenderPeer;
import com.xith3d.render.jogl.RenderPeerImpl;
import com.xith3d.scenegraph.Appearance;
import com.xith3d.scenegraph.BranchGroup;
import com.xith3d.scenegraph.Canvas3D;
import com.xith3d.scenegraph.Geometry;
import com.xith3d.scenegraph.GeometryArray;
import com.xith3d.scenegraph.Locale;
import com.xith3d.scenegraph.Node;
import com.xith3d.scenegraph.QuadArray;
import com.xith3d.scenegraph.Shape3D;
import com.xith3d.scenegraph.Switch;
import com.xith3d.scenegraph.View;
import com.xith3d.scenegraph.VirtualUniverse;

public class Picking
{
    private boolean mouseClicked;
    private int xPos;
    private int yPos;
   
    private int counter = 0;

    private Switch sw;
    private BitSet displayedPlanes = new BitSet(3);

    public Integer pickParamsMutex = new Integer(0);


    public static void main(String[] args)
    {
        new Picking();
    }

    public Picking()
    {
        VirtualUniverse universe = new VirtualUniverse();

        View view = new View();
        universe.addView(view);

        Locale locale = new Locale();
        universe.addLocale(locale);

        BranchGroup scene = new BranchGroup();
        locale.addBranchGraph(scene);
        scene.setPickable(true);

        displayedPlanes.set(0, 3);
        sw = new Switch(Switch.CHILD_MASK, displayedPlanes);       
        sw.setPickable(true);
        scene.addChild(sw);

        Geometry geo1 = createColouredPlane(-.5f, 0, .2f, .5f, .5f, 0, 1, 0);
        Shape3D sh1 = new Shape3D(geo1, new Appearance());
        sh1.setPickable(true);
        sh1.setName("left plane");
        sw.addChild(sh1);

        Geometry geo2 = createColouredPlane(0, 0, 0, 1, 1, 1, 0, 0);
        Shape3D sh2 = new Shape3D(geo2, new Appearance());
        sh2.setPickable(true);
        sh2.setName("middle plane");
        sw.addChild(sh2);

        Geometry geo3 = createColouredPlane(.5f, 0, .2f, .5f, .5f, 0, 0, 1);
        Shape3D sh3 = new Shape3D(geo3, new Appearance());
        sh3.setPickable(true);
        sh3.setName("right plane");
        sw.addChild(sh3);

        RenderPeer rp = new RenderPeerImpl();
        CanvasPeer cp = rp.makeCanvas(null, 640, 480, 32, false);
        Canvas3D canvas = new Canvas3D();
        canvas.set3DPeer(cp);

        cp.getComponent().addMouseMotionListener(new MouseMotionAdapter()
        {
            public void mouseMoved(MouseEvent e)
            {
                synchronized (pickParamsMutex)
                {
                    xPos = e.getX();
                    yPos = e.getY();
                    mouseClicked = true;
                    counter++;
                    System.out.println(counter);
                }
            }
        });

        view.addCanvas3D(canvas);
        view.getTransform().lookAt(new Vector3f( 0, 0, 1.5f),   // location of eye
                                   new Vector3f( 0, 0, 0),   // center of view
                                   new Vector3f( 0, 1, 0));  // vector pointing up

        while(true)
        {
            view.renderOnce();
            synchronized (pickParamsMutex)
            {
                if(mouseClicked)
                {
                    PickRenderResult[] results = view.pick(canvas, xPos, yPos, 1, 1);
                    if(results != null)
                    {
                        displayedPlanes.set(0, 3);
                        for(int i=0; i<results.length; i++)
                        {
                            Node node = results.getNodes()[0];
                            String nodeName = node.getName();

                            if(nodeName.equals("left plane"))
                                displayedPlanes.clear(0);
                            else if(nodeName.equals("middle plane"))
                                displayedPlanes.clear(1);
                            else if(nodeName.equals("right plane"))
                                displayedPlanes.clear(2);
                        }
                    }
                    mouseClicked = false;
                }
            }
        }
    }
    private Geometry createColouredPlane(float xPos,
                                         float yPos,
                                         float zPos,
                                         float xSize,
                                         float ySize,
                                         float redValue,
                                         float greenValue,
                                         float blueValue)
    {
        float xHalf = xSize/2f;
        float yHalf = ySize/2f;

        Point3f[] coords = new Point3f[]
        {
            new Point3f(xPos+xHalf, yPos-yHalf, zPos),
            new Point3f(xPos+xHalf, yPos+yHalf, zPos),
            new Point3f(xPos-xHalf, yPos+yHalf, zPos),
            new Point3f(xPos-xHalf, yPos-yHalf, zPos),
        };

        Color3f[] colors = new Color3f[]
        {
            new Color3f(redValue, greenValue, blueValue),
            new Color3f(redValue, greenValue, blueValue),
            new Color3f(redValue, greenValue, blueValue),
            new Color3f(redValue, greenValue, blueValue)
        };

        QuadArray g = new QuadArray(coords.length, GeometryArray.COORDINATES
                                                 | GeometryArray.COLOR_3);
        g.setCoordinates(0,coords);
        g.setColors(0,colors);

        return g;
    }

}
3  Java Game APIs & Engines / Xith3D Forums / Re: 3DS Loader transport object names ? on: 2005-08-31 15:22:34
Hi,
thank you for coming back to my problem ..... in the meantime i solved it by myself.

It is not enough to insert the line

  context.shape.setName(context.objectName);

because the Shape3D will be copied later with

<com.xith3d.scenegraph.Node>.sharedCopy(<Shape3D>)

and the made copy will be attached to the scenegraph. This method does NOT copy the name of the given node and that was the problem. So I changed the method a bit and it worked.

anyway .... thanks for your help :-)
4  Java Game APIs & Engines / Xith3D Forums / Re: 3DS Loader transport object names ? on: 2005-08-27 13:32:00
it's me again ....

Remeber me and my problem ?  Sad

In the meantime I found out, there is this class "ModelContext" where all information found out by the "ChunkProcessor"s is stored. But i cant find the place where the real  "Shape3D"s (that can be found later in the TDSModel) are created.

greetz Marc
5  Java Game APIs & Engines / Xith3D Forums / switching 3D-window between two Windows? on: 2005-08-27 12:19:46
Hello everyone,

I hope that someone can help me. I'm writing an application where I need the same 3D-Window in two different JPanels. When the 3D-stuff is visible in the first Panel it is not in the other. But it does not work, I always get an Error caused by "ialmgicd.dll".


#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0354331d, pid=228, tid=188
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0-b64 mixed mode, sharing)
# Problematic frame:
# C  [ialmgicd.dll+0x4331d]
#
# An error report file with more information is saved as hs_err_pid228.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#



I have written a short example to demonstrate the problem.


import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.vecmath.Vector3f;
import com.xith3d.render.CanvasPeer;
import com.xith3d.render.RenderPeer;
import com.xith3d.render.jogl.RenderPeerImpl;
import com.xith3d.scenegraph.Appearance;
import com.xith3d.scenegraph.BranchGroup;
import com.xith3d.scenegraph.Canvas3D;
import com.xith3d.scenegraph.Locale;
import com.xith3d.scenegraph.Shape3D;
import com.xith3d.scenegraph.View;
import com.xith3d.scenegraph.VirtualUniverse;
import com.xith3d.test.Cube;

public class Test implements Runnable {

    JFrame frame1;
    JFrame frame2;
    JPanel content;
    View view;
    boolean flip = true;

    public Test() {
        frame1 = new JFrame() {
            {
                setSize(320, 200);
                setVisible(true);
                getContentPane().setLayout(new BorderLayout());
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }
        };
        frame2 = new JFrame() {
            {
                setSize(640, 480);
                setLocation(320, 200);
                setVisible(true);
                getContentPane().setLayout(new BorderLayout());
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }
        };
        content = new JPanel() {
            {
                setLayout(new GridLayout(1, 1));
            }
        };
        VirtualUniverse universe = new VirtualUniverse();
        view = new View();
        universe.addView(view);
        Locale locale = new Locale(5.0f, 0.0f, 10.0f);
        universe.addLocale(locale);
        BranchGroup root = new BranchGroup();
        locale.addBranchGraph(root);
        root.addChild(new Shape3D(Cube.createCubeViaTriangles(0, 0, 0, 1,
                        true), new Appearance()));
        root.compile();
        view.getTransform().lookAt(new Vector3f(0, 0, 2f),
                new Vector3f(0, 0, 0f), new Vector3f(0, 1, 0));
        RenderPeer rp = new RenderPeerImpl();
        CanvasPeer cp = rp.makeCanvas(content, 640, 480, 32, false);
        Canvas3D canvas = new Canvas3D();
        canvas.set3DPeer(cp);
        view.addCanvas3D(canvas);
        new Thread(this).start();
    }

    public static void main(String[] args) {
        new Test();
    }

    public void run() {
        while (true) {
            flip = !flip;
            if (flip) {
                frame1.getContentPane().removeAll();
                frame2.getContentPane().add(content);
            } else {
                frame2.getContentPane().removeAll();
                frame1.getContentPane().add(content);
            }
            view.renderOnce();
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
            }
        }

    }
}



anyone can help me out  Huh
6  Java Game APIs & Engines / Xith3D Forums / Re: 3DWindow in JPanel resizeable?? on: 2005-08-27 10:12:37
Thanx a lot, that thing with the GridLayout helped me out.
7  Java Game APIs & Engines / Xith3D Forums / 3DS Loader transport object names ? on: 2005-08-22 15:41:37
Hello everybody,

I have a geometry in a 3DS file that I want to load with the 3DS-Loaders from "www.newdawnsoftware.com".
I want to import this scene and later
adjust the positions of some of the 3d-objects. But I found out, that the names
of the Shape3Ds that represent the objects, are empty Strings
( <Shape3D>.getName() ). I really need this names to determine wich Shape3D
represents which 3D-object.

Has anyone any suggestions ??

best regards

Marc
8  Java Game APIs & Engines / Xith3D Forums / 3DWindow in JPanel resizeable?? on: 2005-08-22 15:30:46
Hello everybody,

I tried to set a JPanel as a parent Container of a canvasPeer.


JPanel p = new JPanel();
CanvasPeer cp = rp.makeCanvas(p,100, 100, 32, false);


The JPanel is embedded in a complex containment-hierarchy and will get resized often. The Size of the JPanel is dependent to the size of its parent component. The Problem is, that the 3D-Window does not change its size. The same 3D-window embedded into a JFrame works perfectly when resized. So anybody knows how to connect the size of the parent component to the size of the CanvasPeer?

best regards

Marc
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

theagentd (6 views)
2014-04-24 23:00:44

xsi3rr4x (83 views)
2014-04-15 18:08:23

BurntPizza (75 views)
2014-04-15 03:46:01

UprightPath (86 views)
2014-04-14 17:39:50

UprightPath (69 views)
2014-04-14 17:35:47

Porlus (86 views)
2014-04-14 15:48:38

tom_mai78101 (109 views)
2014-04-10 04:04:31

BurntPizza (169 views)
2014-04-08 23:06:04

tom_mai78101 (265 views)
2014-04-05 13:34:39

trollwarrior1 (217 views)
2014-04-04 12:06:45
Escape Analysis
by Roquen
2014-04-25 11:37:01

Escape Analysis
by Roquen
2014-04-25 10:38:58

Escape Analysis
by Roquen
2014-04-25 10:22:13

List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37
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!