Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [odejava] Help ! I don't understand joints  (Read 2979 times)
0 Members and 1 Guest are viewing this topic.
Offline arne

Senior Devvie




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


« Posted 2005-04-02 11:45:24 »

Hi
When I add joints (Joint.attach(body1,body2) ) the bodies dissapear. Why? When I don't use the joints they're shown. Actually they get positions of NaN,NaN,NaN.
What am I doing wrong?

:: JOODE :: Xith3d :: OdeJava ::
Offline harryk

Senior Newbie




Stone golems rock!


« Reply #1 - Posted 2005-04-03 08:11:42 »

What type of joint? Are you setting the anchor correctly? Code example? Smiley
Offline arne

Senior Devvie




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


« Reply #2 - Posted 2005-04-03 10:00:07 »

I just thought it might be a common problem Smiley

Here's the code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
  JointHinge j = new JointHinge(world);
  Vector3f v = getPos(split1[1]); // v = (-141.435, -103.317, 22.2769)
  Vector3f a = getPos(split1[2]); // a = (0.0, 0.0, 1.0)
                           
  j.setAnchor(v.x,v.y,v.z);
  j.setAxis1(a.x,a.y,a.z);
  Body b1 = (Body) joints.get(split0[0]); // b1.getPosition() = (-140.246, -122.405, 1.90785)  b1.getQuaternion() = (0.0, 0.0, 0.0, 1.0)
  Body b2 = (Body) joints.get(split0[1]); // b2.getPosition() = (0.0, 0.0, 60.0)  b2.getQuaternion() = (0.0, 0.0, 0.0, 1.0)
  j.attach(b1,b2);


Quote
Are you setting the anchor correctly?

Are there any rules how to set the anchor ?

Hope you can help me Smiley
Arne

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

Senior Newbie




Java games rock!


« Reply #3 - Posted 2005-04-03 13:57:38 »

have u tried to add the bodies before setting the anchor ?
Offline arne

Senior Devvie




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


« Reply #4 - Posted 2005-04-03 15:00:03 »

No changes there either. I also tried switching setAxis1 and setAnchor. Still get NaN's.

:: JOODE :: Xith3d :: OdeJava ::
Offline arne

Senior Devvie




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


« Reply #5 - Posted 2005-04-06 15:23:40 »

Hey
this can't be so hard, can it Huh
I also looked at the example code, but I don't get what I missed there. Do I have to add them maybe to some kind of space ? I really have no idea.
I really appreaciate it if someone experienced with joints could help me.

Thanks in advance
arne

:: JOODE :: Xith3d :: OdeJava ::
Offline ewills

Junior Devvie




Java skeletal animation systems rock!


« Reply #6 - Posted 2005-04-06 23:00:40 »

I have only used JointBalls and JointAMotors, but here is my approach:

1. Create World and Space.
2. Create Bodies and Geoms, add Geoms to Space.
3. Set the position and orientation of the Bodies.
4. Create the JointBall and attach it to the Bodies.
5. Create the JointAMotor and attach it to the Bodies.
6. Set the mode for the JointAMotor (Euler).
7. Set the pivot of the joint.

Note that the ODE user guide suggests setting the pivot BEFORE attaching the joint.  I adjust the pivot dynamically, which seems to work fine.

Hope this helps!

Edit:
Step 7 also involves setting the JointAMotor axes before setting the pivot.
Offline arne

Senior Devvie




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


« Reply #7 - Posted 2005-04-07 07:16:09 »

Thanks for the reply, but  I still don't get it to work. Sad I followed your instruction step by step. Here's all the code:
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  
public class Tester implements Demonstration{
    Vector geoms = new Vector();
    Body b;
    World world;
    /** Creates a new instance of Tester */
    public Tester() {
        Odejava.getInstance();
        world = new World();
        world.setStepInteractions(10);
        world.setStepSize(0.05f);
        Space s = new HashSpace();
        GeomBox boxG = new GeomBox(280, 60,240);
        GeomSphere sphereG = new GeomSphere(100);
        Body boxB = new Body(world);
        b = boxB;
        boxB.addGeom(boxG);
        Body sphereB = new Body(world);
        sphereB.addGeom(sphereG);
        s.add(boxG);
        s.add(sphereG);
        boxB.setPosition(0,0,0);
        sphereB.setPosition(0,100, 50);
        boxB.setQuaternion(new Quat4f(0,0,0,1));
        sphereB.setQuaternion(new Quat4f(0,0, 0,1));
        geoms.add(boxG);
        geoms.add(sphereG);
        JointBall jh = new JointBall(world);
        jh.attach(boxB,sphereB);
        JointAMotor m = new JointAMotor(world);
        m.attach(boxB, sphereB);
        m.setMode(1);  // What do I have to do here? I've no idea !!
        jh.setAnchor(0,0,0);
        jh.setAxis1(0,0,1);
        jh.setAxis1(1,0,0);
    }
   
    public java.util.List getGeoms() {
        return(geoms);
    }
   
    public void step() {
        world.step();
        System.out.println(b.getPosition());
    }
   
    public static void main(String[] args) {
        try {
            new RunDemo(new Tester());
        } catch(Exception ex) {
            ex.printStackTrace();
        }
}


When I don't call world.step the geoms are shown. But thats no use Sad . I don't exactly know how to configure the joints espacially the JointAMotor -  how do I have to do this Huh - the javadoc doesn't say there very much and  the Ode doc is only for this lowlevel stuff.

:: JOODE :: Xith3d :: OdeJava ::
Offline ewills

Junior Devvie




Java skeletal animation systems rock!


« Reply #8 - Posted 2005-04-07 15:09:53 »

Try calling Body.adjustMass(float f) on each Body after the Geom is added but before the joint and motor are attached.  Also call these on the motor after attaching it:
jointAMotor.setMode(Ode.dAMotorEuler);
jointAMotor.setAxis(0, 1, 1.0f, 0.0f, 0.0f);
jointAMotor.setAxis(2, 2, 0.0f, 1.0f, 0.0f);
Offline arne

Senior Devvie




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


« Reply #9 - Posted 2005-04-07 16:55:02 »

Thanks a lot !!! Cheesy it works now - it was the Body.adjustMass() I forgot.  Ok - this was only for my tester program - in my real program (the one for which I really wanted to have it) I set the mass and the bodies show when I don't add the Joint - when I add it, they don't - hmm this is strange... I'll try to work it out myself with now having some workable code Cheesy

Arne

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

Senior Devvie




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


« Reply #10 - Posted 2005-04-07 17:33:53 »

Ohh holy crap - my biggest nightmares came true !!! I got now to the error-source of that thingi - When I put My Geoms in GeomTransforms - then it starts sucking.
It doesn't matter if I use my extended GeomTransforms or the normal ones - I get the same result Sad

Is this now a bug Huh - it's probably clear, that the Joint is not able to work with that GeomTransform thingi.

Anybody any ideas ?
Arne

:: JOODE :: Xith3d :: OdeJava ::
Offline ewills

Junior Devvie




Java skeletal animation systems rock!


« Reply #11 - Posted 2005-04-07 18:58:53 »

I use both Joints and GeomTransforms.  I have had some trouble with Body.adjustMass() and GeomTransforms.  Make sure you are using the latest CVS and try using Body.setMassParameters() instead of Body.adjustMass().
Offline arne

Senior Devvie




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


« Reply #12 - Posted 2005-04-08 06:46:05 »

Ok. I downloaded the latest cvs, but I can't get it to compile - it says it can't find package org.apache.xml.serialize and org.apache.xml.parsers ...
Anyways I tried it with the old one, but with using setMassParameters instaed of adjustMass - and guess what ? - It works Grin  Thanks a lot !!!
One question only: I say there setMassParameters(mass, 0,0,0,1,1,1,0,0,0)  - is this correct if I want to set the mass at the center of the body and the mass  to be spread from there in every direction the same amount?

Arne

:: JOODE :: Xith3d :: OdeJava ::
Offline ewills

Junior Devvie




Java skeletal animation systems rock!


« Reply #13 - Posted 2005-04-08 22:08:28 »

You're probably better off using setMassParemeters(mass, 0.0f, 0.0f, 0.0f, mass, mass, mass, 0.0f, 0.0f, 0.0f).  This isn't correct, but works pretty well.
Offline arne

Senior Devvie




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


« Reply #14 - Posted 2005-04-09 05:40:09 »

Thanx

:: JOODE :: Xith3d :: OdeJava ::
Offline darkprophet

Senior Devvie




Go Go Gadget Arms


« Reply #15 - Posted 2005-04-11 12:10:02 »

ewills, why are you setting mass, mass, mass instead of 1, 1,1? Is there any advantage to doing that?

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline ewills

Junior Devvie




Java skeletal animation systems rock!


« Reply #16 - Posted 2005-04-11 14:27:51 »

Setting the moment of inertia to (1, 1, 1) for all objects will allow all objects to rotate at the same rate.  Scaling the MOI by mass is not quite correct, but at least causes more massive objects to rotate slower than less massive objects.
Offline arne

Senior Devvie




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


« Reply #17 - Posted 2005-04-11 14:40:54 »

Quote

Scaling the MOI by mass is not quite correct, but at least causes more massive objects to rotate slower than less massive objects.

Saying you need more force to accelerate it's rotation speed?
Quote

Scaling the MOI by mass is not quite correct,

What actually would be correct? - just interested. This is probably not easy to answer, because it depends of what you want to have. Does the MOI also specify, how the mass is distributed in the bodies, for example?

Arne

:: JOODE :: Xith3d :: OdeJava ::
Offline ewills

Junior Devvie




Java skeletal animation systems rock!


« Reply #18 - Posted 2005-04-11 18:18:40 »

In general, the mass and center of mass (COM) determine how easily an object can be moved around.  Forces applied to a Body at its COM simply move the Body.  Forces applied at locations other than the center of mass both move the Body and create torques.  Torques rotate the Body according the Body's inertial tensor.

The inertial tensor is usually represented by a symmetrical 3x3 matrix.  The matrix is symmetrical, so you can represent the inertial tensor using 6 floats.  The diagonals of the matrix are the moment of inertial (MOI).  The MOI is the most important component of the inertial tensor  Think of any torque applied to the Body being multiplied by the MOI.  The MOI is a triple because the Body may rotate more easily about some axes due to the Body's geometry.  Note that mass can be a scalar because forces from any direction affect the Body similarly.  The other components of the inertial tensor ensure that a free-floating Body eventually rotates about it's principal axis of rotation.  Think of these non-diagonal components of the inertial tensor matrix as constantly performing slight rotations.

So that was just a quick brain dump Smiley  For more information on COM and inertial tensor calculation, see:
http://scienceworld.wolfram.com/physics/MomentofInertia.html

Edit:
Oops!  Torques is actually divided by the MOI to get angular acceleration.  Similarly, Forces are divided by mass to get linear accelerations.
Offline arne

Senior Devvie




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


« Reply #19 - Posted 2005-04-13 16:48:29 »

Quote

So that was just a quick brain dump   For more information on COM and inertial tensor calculation, see:
http://scienceworld.wolfram.com/physics/MomentofInertia.html


Ohh - this is to high for me -  but the other stuff you said was more understandable Smiley Now I've got at least some kind of idea what it is meant for.

:: JOODE :: Xith3d :: OdeJava ::
Pages: [1]
  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 (38 views)
2014-12-15 09:26:44

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

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

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

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

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

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

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

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

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!