Move/Spin model

Admittedly, this is a crappy fix, but it works! I added a mouse listener to the check box to listen for it being clicked. I also added a window listener so that the application doesn’t keep running when the user tried to exit by clicking the “X”.


//awt and swingcomponents
import javax.swing.*;

import java.awt.event.*;

class TestFrame extends JFrame
{
   public TestFrame()
   {
      setTitle("TestFrame");
      //add menubar to frame
      setJMenuBar(createMenuBar());
      //add panel with jcheckbox
      addPanel();
      addWindowListener(new WindowListener(){
		public void windowOpened(WindowEvent arg0)
		{}
		public void windowClosing(WindowEvent arg0)
		{
			close();
		}
		public void windowClosed(WindowEvent arg0)
		{}
		public void windowIconified(WindowEvent arg0)
		{}
		public void windowDeiconified(WindowEvent arg0)
		{}
		public void windowActivated(WindowEvent arg0)
		{}
		public void windowDeactivated(WindowEvent arg0)
		{}    	  
      });
      //start frame maximized
      setExtendedState(JFrame.MAXIMIZED_BOTH);
      setVisible(true);      
   }
   
   public void addPanel ()
   {
      JPanel test = new JPanel ();
      JCheckBox click = new JCheckBox ("click me");
      test.add(click);
      add(test);
   }
   
   //creates the menubar
   public JMenuBar createMenuBar ()
   {
      JMenuBar mb = new JMenuBar ();

      //create the menu file
      JMenu file = new JMenu ("File");
      
      JMenuItem quit = new JMenuItem ("Quit");
      quit.addActionListener(new ActionListener(){
         public void actionPerformed (ActionEvent ae){ close(); }
      });
      //add menuitems to menu file
      file.add(quit);

      //create the menu options
      JMenu options = new JMenu ("Options");
      //menuitems of het menu
      final JCheckBox wire = new JCheckBox ("Wireframe Models");
      wire.addMouseListener(new MouseListener(){
		public void mouseClicked(MouseEvent arg0)
		{
			wire.setSelected(!wire.isSelected());
			/* ActionEvent Code Here */
		}
		public void mousePressed(MouseEvent arg0)
		{}
		public void mouseReleased(MouseEvent arg0)
		{}
		public void mouseEntered(MouseEvent arg0)
		{}
		public void mouseExited(MouseEvent arg0)
		{}    	  
      });
      final JCheckBox shadows = new JCheckBox ("Shadows");
      shadows.setSelected(true);
      shadows.addMouseListener(new MouseListener(){
		public void mouseClicked(MouseEvent arg0)
		{
			shadows.setSelected(!shadow.isSelected());
			/* ActionEvent Code Here */
		}
		public void mousePressed(MouseEvent arg0)
		{}
		public void mouseReleased(MouseEvent arg0)
		{}
		public void mouseEntered(MouseEvent arg0)
		{}
		public void mouseExited(MouseEvent arg0)
		{}    	  
      });
      //add menuitems to menu file
      options.add(wire);
      options.add(shadows);

      //add menus to menubar
      mb.add(file);
      mb.add(options);
      
      return mb;
   }
   
   //displays dialog which ask to close
   public void close ()
   {
      if (JOptionPane.showConfirmDialog(null, "Do you really want to close",
                                 "Close ModelLoader",
                                 JOptionPane.YES_NO_OPTION)
            == JOptionPane.YES_OPTION)
         System.exit(0);
   }
         
   //main method
   public static void main(String[] args) { new TestFrame(); }   
}

thx for the reply, didnt think of that
btw why do u use new Listener()?
i just use Adapters so i dont need to implement all the methods and just the ones i need but thx anyway

i have drawn my probleem with my wheel
i want to be able to rotate around the yellow axis and around the black axis (doesnt need to be at the same time)
both axis go trhough the center point of the model (which i have been able to track)

I guess i would have to be able to translate the current x-axis to that location so i am able to spin it around that new axis?
or am i seeing thins wrong


http://img262.imageshack.us/img262/9169/rotatingproblem8gb.th.jpg

Do this:


Transform3D trans; // the Transform3D of your TransformGroup
Vector3f pos; // the position of the wheel

public void rotate(Matrix3f m) {
  Vector3f v = new Vector3f(pos);
  v.negate();
  trans.setTranslation(v);
  trans.mul(m);
  trans.setTranslation(new Vector3f());
}


This code only works, if you don’t modify the TransformGroup in a other way, too.

how do i determine Matrix3f m?

i have been able to spin my wheels and rotate them but not at teh same time :frowning:
i exectue follwing code:
Transform3D t3d = components[0].getTransform();
t3d.setTranslation(new Vector3f(direction));
t3d.setRotation(new AxisAngle4f(1.0f,0.0f,0.0f, rotX)); //spin the wheel
t3d.setRotation(new AxisAngle4f(0.0f,1.0f,0.0f, rotY)); ///turn the wheel
components[0].setTransform(t3d);

if i do this only the second setRotation has effect, if i comment that one he does perform the first setRotation
bu he doenst perform them both after each othter.

t3d.setRotation sets the rotation matrix to represent this rotation. So you just overwrite the older rotation. You first have to extract the old rotation and then mul it with the new one, so:

Matrix3f temp1, temp2;
AxisAngle4f a;

t3d.get(temp1); // get the rotation
temp2.set(a);
temp1.mul(temp2);
t3d.setRotation(temp1);

why use AWT to begin with?

It’s asynchronous nature is not well suited to Xith3D. I recommend HIAL.

Will.

it works well with my key class i wrote as awt componenten ( ican press multiple keys at once)
but i just dont seem to understand this camera

does any one has a good tut on how this camera(movement/rotation) works and it in general

My tutorial is not ready for prime time yet. But here is my recomendation

Get the source for the maze3d demo from xith.org

key strokes map to methods of the MovementForce class in the maze demo, turnLeft, turnRight, forward, etc. This class is passed a reference to your View and manipulates this view accordingly ala Camera

understand the code, then use HIAL lib to call the correct methds of MovementForce class instead of AWTKeyboard

The Maze code uses Eulars for rotations, examining the code which rotated around Y, should allow you to extand and rotate around any axis

thx will try this :slight_smile:
maybe an odd question but does anyone know where i can get some 3ds max models for free (with textures included) of some buidlings, citys?
i would like to craete a world or someting like that

You can try http://www.planit3d.com

i want to attach the camera to my jeep so when it moves it moves along with
as long as the jeep rotates at starting poitns, camera rotates alogn
ik i drive for or backward, the camera does the same thing
but when i first rotate and then drive forward camera screws up
same if i want to rotate when i have driven forward/backward

i know i had to add someting to the coordinates but i cant seem to figure out what

i can import com.xith3d… pakcages but not the org.xith ones?
any idea?

the org-packages are from the xith-tk. You’ll have to download also the cvs from the xith-tk (that’s a different project).

easy rule:
org.xith3d : xith-tk
com.xith3d: xith (core)

Arne

sometimes when i try to load a 3ds model I get an array out of bounds exception
this isdue to a part of the model
when i delete the part in 3ds max and then export new model and load it in my program
everything goes fine
maybe the dimensions are to big?

this sounds very much like a bug in your importing/exporting process. Could you print the stack trace of the exception?

i have attached 2 pics of errors with the arrayoutofbounds

aehm
you can also get the text by pressing enter on your keyboard, then you don’t have to post screenshots.

I’ll take a look anyways…

EDIT: Yep, it really seems that this is a loader3ds problem. To fix this you could do several things:

  1. Wait until somebody fixes this.
  2. Download the source and fix it yourself.
  3. If you’re not able to fix it, make a new post adressing this problem.
  4. If nothing else works, simply check what the differences between your working and not working model are. E.g. has that part you delete to make it work any specialities? And then simply don’t export scenes that contain such.