Getting Started With Java3D

Getting Started: Rotating Cube


In this tutorial we will be implementing a rotating cube using the Java3D API. You will need to have completed the previous tutorial The JFrame in order to complete this tutorial.

What You Will Need to Start

In the previous tutorial we set up a JFrame for the Java3D canvas. We will be continuing on with that exact same code. I recommend taking a copy of the code rather than overwriting it as the blank JFrame code will be used again in the future.

Create a new project (call it whatever you want), import all of the necessary libraries as we did in the very first tutorial and create a class in the default package called “Main”You can then copy the code from the previous tutorial into this new class.


Now to start, for this tutorial all of the code will be written within the main constructor method. “public Main()”. Starting under the line “BranchGroup group = new BranchGroup();” 

Let’s start by adding in the required imports for this project, all of the imports you need are seen below.


Creating the TransformGroup

Now, we can start programming. First of all we need to create a TransformGroup and set the capabilities of that TransformGroup. The TransformGroup can then be added into the BranchGroup which has already been created. So, here is how we do that.


Great, we’ve now created a TransformGroup which we can manipulate. This allows us to Translate/Rotate and do a whole bunch of things to the objects within this TransformGroup.

Creating the Cube

We need an object to be able to rotate, so we will create a standard ColorCube and add it to the TransformGroup.


Implementing the Rotation

Now we need to set the rotation for the cube, to do that we will be using a RotationInterpolator which takes in an Alpha value and the TransformGroup to manipulate. We also need to set the SchedulingBounds which sets the Behavior’s scheduling region to the specified bounds.


That is all! When you run the project you will see a rotating 3D cube with a black background.


You can find all of the source code in the Code Examples section of our website.
Click here to view the entire project code


One thought on “Getting Started: Rotating Cube

  1. You really make it seem really easy together with your presentation but I to find this topic to be really one thing that I believe I might never understand. It sort of feels too complicated and extremely vast for me. I am having a look forward on your next publish, I will attempt to get the dangle of it!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s