Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  Move/Spin model  (Read 4470 times)
0 Members and 1 Guest are viewing this topic.
Offline Grand Poeba

Junior Devvie





« Posted 2005-09-16 16:30:18 »

Hey

I am currently makeing something for fun. I have a 3ds max model of a jeep which I load into my program with kevs loader
everything goes fine but i want to move it. I also want to make the wheels spin when the jeep is riding en make them turn
when i make a turn. To do so i have made severl tranformgroups to be able to animate each part seperatly
but the things wont move and when I rotate a wheel its rotating not around the center of itself but around an axis
how can i fix this. This is the code of the jeep class, which includes methods to drive and spin weels:


//standard xith3D imports
import com.xith3d.scenegraph.*;
import javax.vecmath.*;

/**
 *    Jeep 3ds max model
 **/
public class Jeep extends Model
{
   //wheels
   private TransformGroup rlw; private Transform3D rlw3D; private float angleRLW = 0;
   private TransformGroup rrw; private Transform3D frw3D; private float angleFRW = 0;
   private TransformGroup flw; private Transform3D flw3D; private float angleFLW = 0;
   private TransformGroup frw; private Transform3D rrw3D; private float angleRRW = 0;
   //steerings
   private TransformGroup ls;
   private TransformGroup rs;
   //main body
   private TransformGroup main;
   
   /**
    *  Constructor
    **/
   public Jeep ()
   {
      super ("./models/jeep/jeep.3ds", "./models/jeep/");
      loadComponents ();
   }
   
   //loads each component and add it to it's own tranform3d
   public void loadComponents ()
   {
      rlw = TDSmodel.getNamedTransformGroup("rlw");
      rlw.removeFromParentGroup();
      rrw = TDSmodel.getNamedTransformGroup("rrw");
      rrw.removeFromParentGroup();
      flw = TDSmodel.getNamedTransformGroup("flw");
      flw.removeFromParentGroup();
      frw = TDSmodel.getNamedTransformGroup("frw");
      frw.removeFromParentGroup();
   
      ls = TDSmodel.getNamedTransformGroup("lsteer");
      ls.removeFromParentGroup();
      rs = TDSmodel.getNamedTransformGroup("rsteer");
      rs.removeFromParentGroup();
      
      main = TDSmodel.getNamedTransformGroup("main");
      main.removeFromParentGroup();
   }

   //rotates the front right wheel
   public void rotateFRW ()
   {
      
      angleFRW += 0.1f;
      frw3D = new Transform3D();
      frw3D.setTranslation(new Vector3f(2.0f, -5.0f, 0.0f));
      frw.getTransform(frw3D);            
      
      frw3D.rotX(angleFRW);
      frw.setTransform(frw3D);
      //rlw.getTransform().setTranslation(new Vector3f(2.0f, -5.0f, 0.0f));
   }
   
   //rotates the rear rightt wheel
   public void rotateRRW ()
   {
      
      angleRRW += 0.1f;
      
      rrw3D = new Transform3D();
      rrw.getTransform(rrw3D);            
      rrw3D.rotX(angleRRW);
      rrw.setTransform(rrw3D);
      //rlw.getTransform().setTranslation(new Vector3f(2.0f, -5.0f, 0.0f));
   }
   
   //rotates the front left wheel
   public void rotateFLW ()
   {
      
      angleFLW += 0.1f;
      
      flw3D = new Transform3D();
      flw.getTransform(flw3D);            
      flw3D.rotX(angleFLW);
      flw.setTransform(flw3D);
      //rlw.getTransform().setTranslation(new Vector3f(2.0f, -5.0f, 0.0f));
   }
   
   //rotates the rear left wheel
   public void rotateRLW ()
   {
      
      angleRLW += 0.1f;
      
      rlw3D = new Transform3D();
      rlw.getTransform(rlw3D);            
      rlw3D.rotX(angleRLW);
      rlw.setTransform(rlw3D);
      //rlw.getTransform().setTranslation(new Vector3f(2.0f, -5.0f, 0.0f));
   }
   
   public void drive ()
   {
      rlw.getTransform().setTranslation(new Vector3f(2.0f, -5.0f, 5.0f));
      rrw.getTransform().setTranslation(new Vector3f(2.0f, -5.0f, 5.0f));
      flw.getTransform().setTranslation(new Vector3f(2.0f, -5.0f, 10.0f));
      frw.getTransform().setTranslation(new Vector3f(2.0f, -5.0f, 10.0f));
   }
   
   /**
    * Getters
    **/
   
   //return each wheel
   public TransformGroup getRearLeftWheel () { return rlw; }
   public TransformGroup getRearRightWheel () { return rrw; }
   public TransformGroup getFrontLeftWheel () { return flw; }
   public TransformGroup getFrontRightWheel () { return frw; }
   //return eacht steer
   public TransformGroup getLeftSteer() { return ls; }
   public TransformGroup getRightSteer() { return rs; }
   //return main body
   public TransformGroup getMainBody() { return main; }
   //return the whole model
   public BranchGroup getModel ()
   {
      BranchGroup bg = new BranchGroup();
      bg.addChild(rlw); bg.addChild(flw);   bg.addChild(rrw); bg.addChild(frw);
      bg.addChild(ls); bg.addChild(rs);
      bg.addChild(main);
      return bg;
   }
}

In mijn main class I have created a branchgroup and have added echt part serperatly to it
and then added it to the scene but it doesnt work. Here is my mainclass code:

//standard xith3D imports
import com.xith3d.scenegraph.*;
import javax.vecmath.*;
// use Jogl
import com.xith3d.render.*;
import com.xith3d.render.jogl.*;
// Texture stuff
import com.xith3d.loaders.texture.*;
// Model loader
import com.kinostudios.loader3ds.*;
//keylistener
import java.awt.event.*;

/**
 *    Class which animates the wheels bij turning and spinning them
 **/
public class WheelAnimation
{
   private final int DIST = 20;
   
    private float rotX = 0;
    private float rotY = 0;
    private float rotZ = 0;

    private TransformGroup objRotate;
    private Transform3D rotate;

    private boolean isRotationScheduled = false;
       
   private View view;
   private BranchGroup scene;
   
   private Jeep jeep;

   public WheelAnimation()
   {
      VirtualUniverse vu = new VirtualUniverse();
      
      view = new View();
      vu.addView(view);
      
      Locale locale = new Locale();
      vu.addLocale(locale);

        rotate = new Transform3D();
        rotate.rotXYZ(rotX, rotY, rotZ);
        objRotate = new TransformGroup(rotate);
        objRotate.addChild(createScene());       
      
      scene =  new BranchGroup();
      // let objects along this path rotate
        scene.addChild(objRotate);
      locale.addBranchGraph(scene);

      drawGrid ();

      RenderPeer    rp      = new RenderPeerImpl();
      CanvasPeer    cp      = rp.makeCanvas(null, 1280, 1024, 32, true);
      Canvas3D      canvas  = new Canvas3D();
      //set the render options
      RenderOptions options = new RenderOptions();
      options.setOption(Option.USE_SHADOWS, true);
      options.setOption(Option.USE_LIGHTING, true);
      options.setOption(Option.USE_TEXTURES, true);
      cp.setRenderOptions(options);
      //close app with ESC key
      cp.getComponent().addKeyListener(new KeyAdapter() {
         public void keyPressed(KeyEvent e) {
              switch(e.getKeyCode()) {
                  case KeyEvent.VK_LEFT : rotY+=0.05;
                                    isRotationScheduled = true;
                                    break;
                  case KeyEvent.VK_RIGHT: rotY-=0.05;
                                    isRotationScheduled = true;
                                    break;
              }
          }
         public void keyTyped(KeyEvent e) {   
            switch(e.getKeyChar()) { case 27: System.exit(0); break; }
         }
      });
      
      Color3f ambientColor = new Color3f(1f, 1f, 1f);
      AmbientLight ambientLightNode = new AmbientLight(true, ambientColor);
      scene.addChild(ambientLightNode);

      DirectionalLight light = new DirectionalLight(true,
                                            new Color3f(1f, 1f, 1f),
                                            new Vector3f(0f, -2f, -3f));
      scene.addChild(light);

      canvas.set3DPeer(cp);

      view.addCanvas3D(canvas);
      view.getTransform().lookAt(new Vector3f(DIST, DIST, DIST), // location of eye
                           new Vector3f(0, -10, 0), // center of view
                           new Vector3f(0, 1, 0));// which axis is "up"
   
      scene.compile();
      //keep on rendering
      run();
   }

   //draws a grid on the scene
   public void drawGrid ()
   {      
      for (int i = -20; i <= 20; i+=2)
      {   //draw lines // with X-axis
         objRotate.addChild( new Shape3D(
                      drawLine ( new Point3f[] {
                                 new Point3f (i, 0, -20),
                                 new Point3f (i, 0, 20) }),
                               new Appearance()));
         //draw lines // with Z-axis
         objRotate.addChild( new Shape3D(
                      drawLine ( new Point3f[] {
                                 new Point3f (-20, 0, i),
                                 new Point3f (20, 0, i) }),
                               new Appearance()));
      }
   }
      
   public Geometry drawLine (Point3f[] coords)
   {
      LineArray g = new LineArray(coords.length, GeometryArray.COORDINATES);
      g.setCoordinates(0,coords);
      return g;
   }
   
   public void run()
   {
      while (true)
      {
         /*jeep.rotateRLW();
         jeep.rotateFLW();
         jeep.rotateRRW();
         jeep.rotateFRW();
         */
         jeep.drive();
         view.renderOnce();
         if(isRotationScheduled)
            {
               performRotation();
                isRotationScheduled = false;
            }
            try { Thread.sleep(50); } catch (Exception e) {e.printStackTrace();}
        }
    }

   public BranchGroup createScene()
   {
      BranchGroup root = new BranchGroup();
      //change backgroundcolor
      Background bg = new Background(new Color3f(0.5f,0.5f,0.5f));
      root.addChild(bg);
      //load the axis model
      Axis assen = new Axis ();
      root.addChild(assen.getModel());
      
      //load jeep model
      jeep = new Jeep ();
                  
      BranchGroup bg1 = new BranchGroup();
      bg1.addChild(jeep.getRearLeftWheel());
      bg1.addChild(jeep.getFrontLeftWheel());
      bg1.addChild(jeep.getRearRightWheel());
      bg1.addChild(jeep.getFrontRightWheel());
      root.addChild(bg1);
      
      return root;
   }

    /**
     * This method performs the rotation of the canvas
     */
    private void performRotation()
    {
        rotate.rotXYZ(rotX, rotY, rotZ);
        objRotate.setTransform(rotate);
    }

   public static void main(String[] args) { new WheelAnimation(); }
}

Can anyone help? plz thx a lot Smiley
Offline Grand Poeba

Junior Devvie





« Reply #1 - Posted 2005-09-16 21:48:11 »

i have been able to track the coordinates of the center of each wheel
cant i rotate a wheel around a custom axis? (formed with that coordinate)
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #2 - Posted 2005-09-17 05:34:04 »

I do not know if the 3ds loader can create individual transform groups relitive to the object's center (or pivot point).

I do know that the ASE Loader can do this because I added this feature, use it regularly and wrote a tutorial about the topic.

Cheers,

Will.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Grand Poeba

Junior Devvie





« Reply #3 - Posted 2005-09-17 09:59:56 »

i first used the ase loader but my 3ds files get soooo large and it doenst support the 3ds materials
thats why i used an external 3ds loader for xith (kevs) to be able to do all this
aint their a way i can move the (0,0,0) around so point (1,2,5) for example becomes the new center?
Offline arne

Senior Devvie




money is the worst drug- we should not let it rule


« Reply #4 - Posted 2005-09-17 10:47:31 »

If you have a point p you can rotate it with a rotation-matrix M around a point q by doing this:
1  
new_p = q.add(M.translate(p.sub(q)));


Is that what you want to do?

:: JOODE :: Xith3d :: OdeJava ::
Offline Grand Poeba

Junior Devvie





« Reply #5 - Posted 2005-09-17 10:47:42 »

is it possible to get the names of the nodes bcz when i use
TDSmodel.getNamedTransformGroup(name);
I have to allready know the name so i cant make a gerenal class which lodes each node seperatly
Offline arne

Senior Devvie




money is the worst drug- we should not let it rule


« Reply #6 - Posted 2005-09-17 10:50:43 »

i have been able to track the coordinates of the center of each wheel
cant i rotate a wheel around a custom axis? (formed with that coordinate)

Quote
is it possible to get the names of the nodes bcz when i use
TDSmodel.getNamedTransformGroup(name);
I have to allready know the name so i cant make a gerenal class which lodes each node seperatly

How did you do the tracking I wonder, without getting the names of the nodes?

:: JOODE :: Xith3d :: OdeJava ::
Offline Grand Poeba

Junior Devvie





« Reply #7 - Posted 2005-09-17 10:51:35 »

If you have a point p you can rotate it with a rotation-matrix M around a point q by doing this:
1  
new_p = q.add(M.translate(p.sub(q)));


Is that what you want to do?
i have a wheel and i want to rotate around its own X-aixs (to make it spin, to let you feel the car is riding)
and around its Y-axis when you make a turn te make the wheels turn

the spinning round X en Y isnt at the same time though
Offline Grand Poeba

Junior Devvie





« Reply #8 - Posted 2005-09-17 10:52:59 »

i have been able to track the coordinates of the center of each wheel
cant i rotate a wheel around a custom axis? (formed with that coordinate)

Quote
is it possible to get the names of the nodes bcz when i use
TDSmodel.getNamedTransformGroup(name);
I have to allready know the name so i cant make a gerenal class which lodes each node seperatly

How did you do the tracking I wonder, without getting the names of the nodes?

i know the names because its just a testing model.
But i would want to make a general class for each model, from which i dont know the names
Offline arne

Senior Devvie




money is the worst drug- we should not let it rule


« Reply #9 - Posted 2005-09-17 11:33:13 »

If you have a point p you can rotate it with a rotation-matrix M around a point q by doing this:
1  
new_p = q.add(M.translate(p.sub(q)));


Is that what you want to do?
i have a wheel and i want to rotate around its own X-aixs (to make it spin, to let you feel the car is riding)
and around its Y-axis when you make a turn te make the wheels turn

the spinning round X en Y isnt at the same time though

yep you have to have the appropriate Matrix for that. e.g. you can set rotations around an Axis with AxisAngle and the setting the AxisAngle to the Matrix. Look at javax.vecmath.Matrix3f.

:: JOODE :: Xith3d :: OdeJava ::
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Grand Poeba

Junior Devvie





« Reply #10 - Posted 2005-09-17 12:56:41 »

If you have a point p you can rotate it with a rotation-matrix M around a point q by doing this:
1  
new_p = q.add(M.translate(p.sub(q)));


Is that what you want to do?
i have a wheel and i want to rotate around its own X-aixs (to make it spin, to let you feel the car is riding)
and around its Y-axis when you make a turn te make the wheels turn

the spinning round X en Y isnt at the same time though

yep you have to have the appropriate Matrix for that. e.g. you can set rotations around an Axis with AxisAngle and the setting the AxisAngle to the Matrix. Look at javax.vecmath.Matrix3f.

do you have an example? much easier to understand than
Offline arne

Senior Devvie




money is the worst drug- we should not let it rule


« Reply #11 - Posted 2005-09-17 16:58:49 »

Matrix3f m = new Matrix3f();
AxisAngle4f a = new AxisAngle4f(1,0,0,2); // rotate 2 radians around the x-Axis
m.set(a);

:: JOODE :: Xith3d :: OdeJava ::
Offline Grand Poeba

Junior Devvie





« Reply #12 - Posted 2005-09-17 17:55:39 »

Matrix3f m = new Matrix3f();
AxisAngle4f a = new AxisAngle4f(1,0,0,2); // rotate 2 radians around the x-Axis
m.set(a);

but i have for example a wheel at (5,3,2)
if I use that axisAngle wont it rotate around an axis trought that point and (0,0,0)?
I don't quite understand sorry
Offline arne

Senior Devvie




money is the worst drug- we should not let it rule


« Reply #13 - Posted 2005-09-17 18:27:04 »

Matrix3f.transform(Point) rotates Point around (0|0|0) and with the AxisAngle you specify the direction and the amount (e.g. x-Axis and 2 radians).

to rotate Point around another Point you first have to translate it, so that the other Point is at (0|0|0) then you can transform it with the matrix, and then you can translate it back.

:: JOODE :: Xith3d :: OdeJava ::
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #14 - Posted 2005-09-18 03:28:36 »

In my experiance what makes it hard is that the actual geometry coordinates are at say 10,10,10 which makes it hard to transform it based on the object's own pivot point (instead of the object turning by itself, it is transformed relitive to the origin which is not what you want), hence the reason for my work on the ASE loader.

I'm not sure if I am misreading your problem though, it just sounded similar to one I had (and solved).

Will.

Offline Grand Poeba

Junior Devvie





« Reply #15 - Posted 2005-09-19 14:34:23 »

i have been able to track the coordinates of the center of each wheel
cant i rotate a wheel around a custom axis? (formed with that coordinate)

Quote
is it possible to get the names of the nodes bcz when i use
TDSmodel.getNamedTransformGroup(name);
I have to allready know the name so i cant make a gerenal class which lodes each node seperatly

How did you do the tracking I wonder, without getting the names of the nodes?

i have now made a generic class which loads any model by loading its groups seperatly
i have made a little loader in which u can select which groups u want to see
but i have an other question, i have upgraded to java 1.5 and something in my menu doenst work anymore
i have added some jcheckbox in a option JMenu but i cant click them
they appear when i click the jmenu so it unfolds but when i click the jcheckbox nothing happens bcz the program doesnt call the actionlistener
this was going fine with java 1.4.2, the shadow jcheckbox is autoselected but both cant be clicked and I need to be albe those jcheckboxes
bcz I have added another menu with all names of nodes/parts so i can select which ones i want to view


Offline Grand Poeba

Junior Devvie





« Reply #16 - Posted 2005-09-19 17:35:43 »

the only why i can use the jcheckboxes is by first clicking on them so they are selected and then by pressing space their state changes
and so the actionlistener is called
Offline arne

Senior Devvie




money is the worst drug- we should not let it rule


« Reply #17 - Posted 2005-09-19 17:41:37 »

strange
have you tested, if this also happens in normal application, without the Xith-Canvas below? (maybe this is a heavyweight/lightwight problem)

:: JOODE :: Xith3d :: OdeJava ::
Offline Grand Poeba

Junior Devvie





« Reply #18 - Posted 2005-09-19 19:58:29 »

strange
have you tested, if this also happens in normal application, without the Xith-Canvas below? (maybe this is a heavyweight/lightwight problem)

will try btw i still dont get my wheel to spin dont quite understand, can I add u at icq or maybe send me my code for some help?
Offline Grand Poeba

Junior Devvie





« Reply #19 - Posted 2005-09-19 20:41:56 »

wrote a test class with just a jframe
i have adde 2 jcheckboxes (1 selected) to a jmenubar  but stille the same problem
i also adde a jpanel with a jcheckbox on and i can click that one no problem :s
anyone has an idea?


//awt and swingcomponents
import java.awt.*;
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();
      //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
      JCheckBox wire = new JCheckBox ("Wireframe Models");
      wire.addActionListener(new ActionListener(){
         public void actionPerformed (ActionEvent ae){

         }
      });
      JCheckBox shadows = new JCheckBox ("Shadows");
      shadows.setSelected(true);
      shadows.addActionListener(new ActionListener(){
         public void actionPerformed (ActionEvent ae){

         }
      });
      //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(); }   
}
Offline cborders

Junior Devvie





« Reply #20 - Posted 2005-09-19 21:10:15 »

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".

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
//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(); }  
}
Offline Grand Poeba

Junior Devvie





« Reply #21 - Posted 2005-09-19 22:06:43 »

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
Offline Grand Poeba

Junior Devvie





« Reply #22 - Posted 2005-09-20 00:41:22 »

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



Offline arne

Senior Devvie




money is the worst drug- we should not let it rule


« Reply #23 - Posted 2005-09-20 18:20:03 »

Do this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
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.

:: JOODE :: Xith3d :: OdeJava ::
Offline Grand Poeba

Junior Devvie





« Reply #24 - Posted 2005-09-20 18:41:53 »

Do this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
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?
Offline Grand Poeba

Junior Devvie





« Reply #25 - Posted 2005-09-20 23:10:06 »

i have been able to spin my wheels and rotate them but not at teh same time Sad
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.
Offline arne

Senior Devvie




money is the worst drug- we should not let it rule


« Reply #26 - Posted 2005-09-21 09:33:28 »

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:

1  
2  
3  
4  
5  
6  
7  
Matrix3f temp1, temp2;
AxisAngle4f a;

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

:: JOODE :: Xith3d :: OdeJava ::
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #27 - Posted 2005-09-22 05:53:28 »

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

why use AWT to begin with?

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

Will.

Offline Grand Poeba

Junior Devvie





« Reply #28 - Posted 2005-09-22 14:38:40 »

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

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
Offline Grand Poeba

Junior Devvie





« Reply #29 - Posted 2005-09-22 21:06:21 »

does any one has a good tut on how this camera(movement/rotation) works and it in general
Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (28 views)
2014-12-15 09:26:44

Mr.CodeIt (19 views)
2014-12-14 19:50:38

BurntPizza (37 views)
2014-12-09 22:41:13

BurntPizza (73 views)
2014-12-08 04:46:31

JscottyBieshaar (34 views)
2014-12-05 12:39:02

SHC (47 views)
2014-12-03 16:27:13

CopyableCougar4 (42 views)
2014-11-29 21:32:03

toopeicgaming1999 (110 views)
2014-11-26 15:22:04

toopeicgaming1999 (96 views)
2014-11-26 15:20:36

toopeicgaming1999 (29 views)
2014-11-26 15:20:08
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!