To detect a collision, I added an inner class, in the following code CollisionDetectorGroup, to the Mykeynavbeh class.
The CollisionDetectorGroup class extends the Behavior class, so it has the processStimulus method, which can be executed when the wakeup condition is satisfied.
Within the method, you can write code for making the object bounce back, making a sound, or whatever you like.
A colliding object's local coordinate system and a CollisionDetectorGroup object (cdGroup) must be connected to the same local coordinate system.
If you are interested in why the part shown in yellow is executed each time a collision is detected, please check the above video 5:33~
Explosion can be used in combination with collision detection.
Mini-games can be created using the above classes, but to make cool programs, you need something more.
Related videos:
You can use the RotationInterpolator class and the SharedGroup Class together.
Within the processStimulus method of the CollisionDetectorGroup class, you can write code for reading a .wav file to play a sound.
Also, after a .mid file is read, you can toggle music on and off by pressing a key.
If you change a crash sound file to a voice file, you can create a program where a character can speak when you type a string from the keyboard.
Using the Switch and BitSet classes, you can make a 3D version of a flip book. The bits in a BitSet are indexed like this: By default, all bits are set to false.
When you set a certain bit to true, only the corresponding child connected under a Switch becomes visible. For example, if you set bit 0 in a BitSet to true, the first child under a Switch becomes visible.
By using this, you can create a walking 3D model, or suddenly change the scene to another world.
I have no idea how to calculate shadow shapes in real time in Java 3D, so I created fake shadows. I created a Shape3D to which a shadow texture was applied. When an object is moving up, the shadow is also moving up, so the shadow must be moving down by the same amount. When the object is moving down, the shadow is also moving down, so the shadow must be moving up by the same amount. Therefore, the shadow always stays at the same level.
If the light comes from the side, multiple shadow textures are needed. Also when an object is rotating, the textures must be rotating in the opposite direction to the object (in this case, only one texture is visible by a Switch).
Related videos:
The light comes from directly above:
A shadow is created using a Shape3D (car) or an OrientedShape3D (tree) with a shadow image.
The light comes from the side:
A shadow is created using OrientedShape3Ds with shadow images. When a model is rotated, the images are switched.
Using the code like this:
speed += 0.01f;
speed -= 0.01f;
accelerates or decelerates a moving object.
If an object, for example a car, is positioned like this:
the code like this:
speed -= 0.01f;
accelerates the car.
If acceleration and deceleration are applied to the y-axis direction, an object flies through the air and follows a parabolic path.
I could fly if I had wings. If you are always thinking about that, try the followings:
To make an object move on the surface of a sphere,
the followings are needed: