Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3508 Members - Latest Member: NevilleKemp

26. May 2012, 04:37:31 pm
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)Tips
Pages: [1]
Print
Author Topic: Tips  (Read 579 times)
jpl
Just dropped in

Offline Offline

Posts: 7


View Profile Email
« on: 27. January 2011, 03:40:27 am »

Hey all!

I've been attempting to write a Rubik's Cube like scenery for practice: 27 cubes total. Such a scene may be divided into 9 planes, with some overlapping: plane x1, x2, x3, y1, y2, y3, z1, z2, z3. Logically, I attempted to create groups for these planes, and have some of the cubes as childs of more than one plane, only to find that this is not possible. It got messy:

http://pastebin.com/h7VSpmJu
http://pastebin.com/rmiGgpHB
http://pastebin.com/nHLJqnFY

The idea was that each plane could get rotated independently. After reading through a few of the XIN examples, I got stumped when trying to make a group rotate 90 degrees and then stop: any pointers on this?

Also, would it be possible to allow a user to pick a cube, and then make a decision as to how to rotate the plane the cube is located on by sampling the movement of the mouse (i.e. up, down, left, right)?

Another question: it seems that many of the examples in xith-tk, even the more complicated ones, do not make use of more than one class to create the scene. Is this standard practice?

Any suggestions are welcome Smiley

J.P.
« Last Edit: 27. January 2011, 03:47:01 am by jpl » Logged
jpl
Just dropped in

Offline Offline

Posts: 7


View Profile Email
« Reply #1 on: 27. January 2011, 04:31:56 pm »

I've made some major changes to the code:

http://pastebin.com/gmrKXeCE

I'm getting over the aforementioned plane issue by detaching objects and re-setting their parent. Is this an effective method to go about solving the problem?

Also, I've been trying to change the appearance of a cube which has been picked, but am facing a slight challenge as the object returned is of type Node, on which I cannot call setAppearance(). Any ideas? Smiley

J.P.
Logged
ChrisE
Becoming dependent
**
Offline Offline

Posts: 104


View Profile
« Reply #2 on: 27. January 2011, 08:03:10 pm »

J.P., welcome to the community!

I'll try to help where I can.

Quote
Also, I've been trying to change the appearance of a cube which has been picked, but am facing a slight challenge as the object returned is of type Node, on which I cannot call setAppearance().

Try using the getGeometry() method instead; it should return the appropriate geometry for your pick.

Also, you can cast the returned node into a needed type if you know what to expect. A snippet of my code for this from my PickListener subclass was:

Code:
Node n = nearest.getNode();
TransformGroup tg = n.getTransformGroup();
System.err.printf("PICKED: %s", tg.getName());

The trick here is that at the lowest level of my graph I have some number of Shape3Ds (representing the faces of an object I might want to manipulate) attached to a TransformGroup (representing the object). So, once I pick some geometry, I then get its parent. I then iterate from the parent all of its children nodes (my pick's siblings, which I know to be Shape3Ds) and call setAppearance() on each.

For the plane issue, you might want to consider keeping all of the cubes as children of the root scene object/branch group. For animation purposes, once the user has selected a plane of rotation for the cube add it and the coplanar cubes to a new plane object belonging to the root. I'm not completely sure, but I don't think you'll be able to do this cleanly without using another data structure better suited to handling the Rubix motion.

Quote
The idea was that each plane could get rotated independently. After reading through a few of the XIN examples, I got stumped when trying to make a group rotate 90 degrees and then stop: any pointers on this?

So, what I would do is use a persistent ScheduledOperation or Interval to update the cubes being animated and manipulate that other data structure I mentioned, and also to set some sort of lock on further picking until the animation is complete (and the data handled).

I can give you more information on this, but I don't want to spoil the puzzle for you if you don't want me to.

Quote
Also, would it be possible to allow a user to pick a cube, and then make a decision as to how to rotate the plane the cube is located on by sampling the movement of the mouse (i.e. up, down, left, right)?

This is certainly possible! Just have the pick, on success, register a new InputListener subclassed to do interesting things on the mouse movements you care about.

Quote
Another question: it seems that many of the examples in xith-tk, even the more complicated ones, do not make use of more than one class to create the scene. Is this standard practice?

I'm not entirely sure what you mean here by "more than one class", but I'd be happy to pass on my findings. Xith is easily embedded inside some other class, and you are free to interact with it without extending or subclassing any of the helpful stuff Marvin and co. have provided. I can provide some example code of this if you'd be interested.

Hope that helps!
Logged
jpl
Just dropped in

Offline Offline

Posts: 7


View Profile Email
« Reply #3 on: 28. January 2011, 02:19:20 pm »

Thanks for the reply Chris, it certainly was helpful!

I believe I have most issues sorted now, I'll post an update sometime between today and tomorrow (and hopefully get some additional pointers on my code)!

I have a few more questions to ask:

1) I am not using Shape3D, but rather Cube (possibly Cube extends Shape3D?). Is this good practice?
2) I keep my cubes in a RotatableGroup, and set whatever rotations I need by calling setTransformationDirectives(). Is this fine?
3) The above method works fine for rotations, but any translations I attempt to make occur over one frame. What is the best way of dealing with this? (i.e. getting cubes to move away from the origin, uniformly, over a number of frames?)

Thanks for the help so far!

J.P.
« Last Edit: 28. January 2011, 02:20:55 pm by jpl » Logged
ChrisE
Becoming dependent
**
Offline Offline

Posts: 104


View Profile
« Reply #4 on: 28. January 2011, 04:23:00 pm »

No problem! Always glad to help.

Quote
1) I am not using Shape3D, but rather Cube (possibly Cube extends Shape3D?). Is this good practice?

Consulting the documentation (http://xith.org/javadoc/xith3d/) we see that Cube extends Box extends Shape3D. It seems to be just a convenience class, so go nuts. Shape3Ds contain a Geometry object, which in my case is a pile of triangles of some variety. I'd say that what you're doing, if it works for you, is the Right Thing(tm). If you need more advanced geometry not offered by one of the other classes, try using a basic Shape3D constructed with a Geometry object (TriangleArray, LineArray, etc.) containing what you want.

Quote
2) I keep my cubes in a RotatableGroup, and set whatever rotations I need by calling setTransformationDirectives(). Is this fine?

In my own code, I use a TransformGroup and handle transformations manually (read: painfully) with ScheduledOperations. I suspect that what you're using might do something similar down in its depths. Again, if what you are doing works for now, stick with it until you need a better solution.

Quote
3) The above method works fine for rotations, but any translations I attempt to make occur over one frame. What is the best way of dealing with this? (i.e. getting cubes to move away from the origin, uniformly, over a number of frames?)

I think that there is a TranslatableGroup or something similar in the API. That might be what you want. I'm not sure that you want one of those, though, depending on how your scene graph is laid out; could you show us how you have your scene set up now?
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #5 on: 28. January 2011, 06:30:04 pm »

There is no other way of adding geometries to the scenegraph then by encapsulating them in Shape3Ds. So any object, that keeps a geometry, that is not directly a Shape3D must be a subclass of it.

You can always find out the class hierarchy in Eclipse by pressing F4 with the caret on a class name.

If you want to create a cube with your own Shape3D, you can use Cube.createGeometryTA() to construct the geometry.

RotatableGroup and TranslatableGroup both extend AnimatableGroup, which you can use to implement your own transformation other than a simple rotation or translation.

Marvin
Logged
jpl
Just dropped in

Offline Offline

Posts: 7


View Profile Email
« Reply #6 on: 28. January 2011, 09:25:37 pm »

Thanks for the reply, Marvin.

Here's an updated version of the code: http://pastebin.com/vdAByUWa

I now have the cubes changing colour when picked, independent plane rotations based on mouse input, and cube translations working.

I'd like to get some input on my prepareNextFrame method, as I get a horrible amount of lag after I translate the cube a few times (press SPACE for this).

Also, I call nearest.getGeometry().setColor(0, colour) to set the colour of a cube once it has been picked. This screws up the transparency of all the cubes, and the picked cube only gets a triangle of the assigned colour... Any tips? Smiley

J.P.
« Last Edit: 28. January 2011, 09:41:52 pm by jpl » Logged
ChrisE
Becoming dependent
**
Offline Offline

Posts: 104


View Profile
« Reply #7 on: 28. January 2011, 09:47:24 pm »

I'm at work, so I can't run and compile that at the moment.

However, I do notice a couple of things:

1. Line 184 you call System.gc()

2. Line 255-258: Minor, but it looks like you could just write an else clause "lineExpanded = !lineExpanded".

Does that help?
Logged
jpl
Just dropped in

Offline Offline

Posts: 7


View Profile Email
« Reply #8 on: 28. January 2011, 09:52:47 pm »

1) I'm calling System.gc() as I *thought* the lag might be due to gc given the amount of Transform objects I'm disposing of on every expansion / contraction.

2) That one was useful, no impact on performance (obviously), but adds readability!

Thanks once again.

BTW: is there an IRC channel for xith?

J.P.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic