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?
What type of joint? Are you setting the anchor correctly? Code example?
I just thought it might be a common problem
Here’s the code:
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?
[/quote]
Are there any rules how to set the anchor ?
Hope you can help me
Arne
have u tried to add the bodies before setting the anchor ?
No changes there either. I also tried switching setAxis1 and setAnchor. Still get NaN’s.
Hey
this can’t be so hard, can it ???
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
I have only used JointBalls and JointAMotors, but here is my approach:
- Create World and Space.
- Create Bodies and Geoms, add Geoms to Space.
- Set the position and orientation of the Bodies.
- Create the JointBall and attach it to the Bodies.
- Create the JointAMotor and attach it to the Bodies.
- Set the mode for the JointAMotor (Euler).
- 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.
Thanks for the reply, but I still don’t get it to work. I followed your instruction step by step. Here’s all the code:
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 . I don’t exactly know how to configure the joints espacially the JointAMotor - how do I have to do this ??? - the javadoc doesn’t say there very much and the Ode doc is only for this lowlevel stuff.
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);
Thanks a lot !!! 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
Arne
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
Is this now a bug ??? - it’s probably clear, that the Joint is not able to work with that GeomTransform thingi.
Anybody any ideas ?
Arne
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().
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 ;D 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
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.
Thanx
ewills, why are you setting mass, mass, mass instead of 1, 1,1? Is there any advantage to doing that?
DP
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.
Saying you need more force to accelerate it’s rotation speed?
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
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 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.
Ohh - this is to high for me - but the other stuff you said was more understandable Now I’ve got at least some kind of idea what it is meant for.