Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate a rectangle continously in a specific angle in Java 3D

I used the following code to rotate a rectangle along x-axis. But the problem is, I want to change the rotation angle continuously by loop, or by taking the values from user input. As I am new in java 3D, I have no idea how to do that. Any kind of help is great for me, THANKS IN ADVANCE!

  SimpleUniverse universe = new SimpleUniverse();
  BranchGroup group = new BranchGroup();
  ColorCube c = new ColorCube(0.3);

  Transform3D t1 = new Transform3D();
  t1.rotX(Math.PI/2.0d);    

  TransformGroup tg1 = new TransformGroup(t1);

  tg1.addChild(c);
  group.addChild(tg1);
  group.compile();

  universe.getViewingPlatform().setNominalViewingTransform();
  universe.addBranchGraph(group);
like image 763
Sefat Noor Orni Avatar asked Apr 21 '26 03:04

Sefat Noor Orni


1 Answers

You must call TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE) to allow your transform to be modified at runtime. Then, you must call TransformGroup.setTransform() later to modify its transform. It's up to you to pass it with a different transform to make it rotate, move, ... You can use the following example: http://www.java3d.org/animationinteraction.html

You can use a timer to execute a task regularly. This task can modify the transform (by computing a new transform from the previous one) and you don't need to write a loop to do so.

like image 73
gouessej Avatar answered Apr 22 '26 15:04

gouessej



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!