Skip to main content

Alpha animation and collision

8 replies [Last post]
ktulu
Offline
Joined: 2006-07-18
Points: 0

We're doing a project in Java3D where a bowling ball is supposed to hit a pin. The ball moves with an Alpha and so does the pin. The problem is that both Alphas is synchronized (they start at the same time). We obviously want the pin animation to start only when it's hit by the ball, not before, but now it starts when the ball starts to move since they're synchronized.
Any idea how to solve this problem? Trigger Time and Phase Delay does not do the job here since we don't know at what time the collision takes place. We want to use collision detection to start the pin animation.
I hope you understand my bad english. I'm swedish =)
Any help is very appreciated.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ktulu
Offline
Joined: 2006-07-18
Points: 0

Great, we'll start working on the project again in the beginning of next year. Then we'll try to implement Pick Tool.
Thanks for your help and merry christmas!

/Olof

ktulu
Offline
Joined: 2006-07-18
Points: 0

Thanks again for your help. The alpha interpolators works fine now but we have some more problems.

1. The first one is probably difficult for you to answer but I'll try to explain. We have made the pin object in 3D Studio Max and implemented it in Java3D. We used a loader written by a norwegian guy (ASE Loader 4.51). The problem is that our collision detection doesn't work with this object although it works fine with objects made in Java3D. The WakeUpOnCollisionEntry doesn't work on the loaded object. Here's a link to the ASE Loader:
http://home.no.net/tabusd/main.php
Since you probably haven't used this loader it may be difficult to answer, but do you have any idea how to solve this problem?

2. Another thing we've thought about is how to know where on the pin the ball hits on the collision. In the pin alpha interpolator we need an angle to know in which direction it will move. I guess we need to know which vertex coordinates or polygons that are hit. Any suggestions how to get this information in Java3D?

/Olof

Gilson Laurent

Hello

> 1. (collision does not work with Loader XY)

Collision-detection is only done between nodes with getCollidable() = true.
The loader may set that flag to false. (see
javax.media.j3d.Node.setCollidable(boolean b) and set it in all model-nodes
before adding the loaded model to the universe)

But there is a second point: If the loader sets "strange" bounds and you use
bounds-based collision-detection anything may happen. Use geometry-based
detection. It's slower but very effectiv.

> 2. I guess we need to know which
> vertex coordinates or polygons that are hit.

You have a sphere colliding with a model, right ? You can't get the
information out form the collision-system, you will have to use picking:

(you will have to set some capabilities, see class-doc of
com.sun.j3d.utils.picking.PickTool.)

create a pickshape PS using:
PS = new PickBounds (new BoundingSphere(Point3d center, double radius))

Create a picktool PT, using:
PT new PickTool(BranchGroup b)" (b containing the pin-model)

call:
PT.setMode(PT.GEOMETRY_INTERSECT_INFO); //more information/slower
or
PT.setMode(PT.GEOMETRY); //less information/faster

call:
PT.setShape(PS, center);

Now PT can try to find any intersections between PS and pickable (check your
capabilities !) nodes inside b. To get the intersections call any of:

PickResult[] PT.pickAll()
PickResult[] PT.pickAllSorted()
PickResult PT.pickAny()
PickResult PT.pickClosest()

You get the interections (PickIntersection) by calling:
PickResult.getIntersection(int index)

PickIntersection.getClosestVertexCoordinates() and/or
PickIntersection.getPointCoordinates() should give you the collision-point

good luck.

cu
[att1.dat]

ktulu
Offline
Joined: 2006-07-18
Points: 0

We tried to use a picker but we don't really get how it works and what it does. We're pretty new to Java and especially Java3D. Could you explain how a picker works? What exactly is a pickshape and a picktool and how do we implement it on our problem with the ball-pin collision?

/Olof

Gilson Laurent

Hello

> We tried to use a picker but we don't really get how it works and what it
> does.

Picking searchs for intersections between a Pickshape and other stuff (shapes)
in the scenegraph and reports them. The picktools make it easier to use
picking.

Example: The user clicks somewhere on the canvas. The programm knows the
mouse-coordinates on the canvas. But you don't know directly that is shown at
that moment in these coordinates. So you create a pickshape (pickray) that
travels from the canvas-mouse-coordinates to the infinite. Them you make a
pick with that shape and get everything intersecting that pickshape.

(PickCanvas does that for you)

> Could you explain how a picker works?

A picker does the real work: you give it a pickshape and a Branchgroup. It
tries to find intersections between the pickshape and stuff in the
branchgroup.

So if you want to know where your shapes intersect you will have to use a
picktool:

You have a ball which is "sphere"-shaped. So you create a picksphere the same
size and position as the ball. Then you search for intersections with the pin
using a picktool.

But there are some problems: Picking only works if the right capabilities are
set. The easiest was to set them all is:
Picktool.setCapabilities(BranchGroup_to_be_picked, Picktool.INTERSECT_FULL)

(If you want to do something special with Shapes/Elements in java3d, you
always have to set capabilities. Always set them just before adding the
branchgroup to the universe)

cu
[att1.dat]

ktulu
Offline
Joined: 2006-07-18
Points: 0

Thanks alot for your help! We will try this and if we still can't make it work, I'll be back.

Gilson Laurent

Hello

> Any idea how to solve this problem?

Well, use a Behavior and WakeupOnCollisionEntry as wakeupcondition. Pause the
pin-alpha and let it resume at the first collision.

If you don't know how to write behaviors: post again.

cu
[att1.dat]

cs

Gilson Laurent,您好!

and I suggest you see the demo about collision detector offered by java3d itself.
if your OS is windows, that is in C:\j2sdk1.4.2_03\demo\java3d\TickTockCollision      
======= 2004-12-08 11:49:00 您在来信中写道:=======

>Hello
>
>> Any idea how to solve this problem?
>
>Well, use a Behavior and WakeupOnCollisionEntry as wakeupcondition. Pause the
>pin-alpha and let it resume at the first collision.
>
>If you don't know how to write behaviors: post again.
>
>cu

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net