Using GeneralizedForce

55 views
Skip to first unread message

jfelrod1960

unread,
Jul 6, 2011, 9:08:08 PM7/6/11
to jinngine
I'm trying to add 4 hover thrusters to my hovercraft. Could you
explain or give an example of how GeneralizedForce is used when
applied to a rigid body?

Here is some code I have. I may be way off base:

// Initialize hover engines points of thrusts. I'm using a Box
geometry.
leftFrontHoverPt = new Vector3(xMin - ((xMax - xMin)/4.0), yMin, zMin
- ((zMax - zMin)/4.0));
rightFrontHoverPt = new Vector3(xMax - ((xMax - xMin)/4.0), yMin, zMin
- ((zMax - zMin)/4.0));
leftRearHoverPt = new Vector3(xMin - ((xMax - xMin)/4.0), yMin, zMax -
((zMax - zMin)/4.0));
rightRearHoverPt = new Vector3(xMax - ((xMax - xMin)/4.0), yMin, zMax
- ((zMax - zMin)/4.0));

leftFrontThruster = new GeneralizedForce(geomList.get(0).getBody(),
new Body("leftFrontThruster"));
rightFrontThruster = new GeneralizedForce(geomList.get(0).getBody(),
new Body("rightFrontThruster"));
leftRearThruster = new GeneralizedForce(geomList.get(0).getBody(), new
Body("leftRearThruster"));
rightRearThruster = new GeneralizedForce(geomList.get(0).getBody(),
new Body("rightRearThruster"));

physicsWorld.getWorldScene().addBody(leftFrontThruster.getBody2());
physicsWorld.getWorldScene().addBody(rightFrontThruster.getBody2());
physicsWorld.getWorldScene().addBody(leftRearThruster.getBody2());
physicsWorld.getWorldScene().addBody(rightRearThruster.getBody2());

// Attach thrusters to hovercraft body.
physicsWorld.getWorldScene().addConstraint(leftFrontThruster);
physicsWorld.getWorldScene().addConstraint(rightFrontThruster);
physicsWorld.getWorldScene().addConstraint(leftRearThruster);
physicsWorld.getWorldScene().addConstraint(rightRearThruster);

// No angular forces being applied.
public void applyForces(double leftFrontForce, double rightFrontForce,
double leftRearForce, double rightRearForce) {
leftFrontThruster.setForce(leftFrontForce, multiply(getRotation(),
leftFrontHoverPt), 0.0, new Vector3());
rightFrontThruster.setForce(rightFrontForce, multiply(getRotation(),
rightFrontHoverPt), 0.0, new Vector3());
leftRearThruster.setForce(leftRearForce,multiply(getRotation(),
leftRearHoverPt), 0.0, new Vector3());
rightRearThruster.setForce(rightRearForce, multiply(getRotation(),
rightRearHoverPt), 0.0, new Vector3());
}

I appreciate any help
Jeff

mo

unread,
Jul 10, 2011, 5:54:47 AM7/10/11
to jinn...@googlegroups.com
Hi jeff

Look fine, only thing is that you only need single body for connecting the generalized force. Like with gravity, and that body needs to be fixed, so it wont move around. Do you have some demo/link for this project? 

Morten

jfelrod1960

unread,
Jul 10, 2011, 10:53:36 PM7/10/11
to jinngine
No demo/link yet. But rest assured I will post a link to this group
soon. So I just create one body, (e.g. HoverThrusters) and create
four GeneralizedForce objects?

Thanks!
Jeff

Morten Silcowitz

unread,
Jul 11, 2011, 3:03:45 AM7/11/11
to jinn...@googlegroups.com
Yes that would work. And fix that body before you add it to the scene.
Looking forward to see your project!

morten

Morten Silcowitz

unread,
Jul 21, 2011, 4:34:22 AM7/21/11
to jinn...@googlegroups.com
Hi jeff,
Did the generalized force work out for you?

morten

Jeffrey Elrod

unread,
Jul 21, 2011, 7:31:31 PM7/21/11
to jinn...@googlegroups.com
Hi Morten,

This is the error I'm getting.
Throwable caught in MainThread - exiting
java.lang.IllegalStateException: DefaultScene: external delta
velocities containes NaN
at jinngine.physics.DefaultScene.step(DefaultScene.java:323)
at jinngine.physics.DefaultScene.tick(DefaultScene.java:370)
at com.complexsive.hovercraft.test.TransformationTestExample.updateExample(TransformationTestExample.java:67)
at com.ardor3d.example.ExampleBase.update(ExampleBase.java:242)
at com.ardor3d.framework.FrameHandler.updateFrame(FrameHandler.java:68)
at com.ardor3d.example.ExampleBase.run(ExampleBase.java:145)
at java.lang.Thread.run(Unknown Source)

Any advice is greatly appreciated.
Jeff

Morten Silcowitz

unread,
Jul 22, 2011, 5:01:07 AM7/22/11
to jinn...@googlegroups.com
---------- Forwarded message ----------
From: Morten Silcowitz <mor...@silcowitz.dk>
Date: Fri, Jul 22, 2011 at 9:26 AM
Subject: Re: [jinngine] Re: Using GeneralizedForce
To: jinn...@googlegroups.com


Does that happen even if you apply a constant force?

To start with, put some asserts around the places in you code where
you compute the force to be applied. Make sure its never NaN or Inf.
Do you manually set the inertia of the space craft body?

Jeffrey Elrod

unread,
Jul 22, 2011, 1:15:16 PM7/22/11
to jinn...@googlegroups.com
It happens on the very first call to Scene.tick(). I will create a
PDF document and send it to you. It will explain how I'm doing
things. I'm sure I'm doing something wrong.

Pierre LABATUT

unread,
Jul 23, 2011, 3:28:08 AM7/23/11
to jinn...@googlegroups.com
Hi Jeffrey,

I'm also interested by your the thread for my spaceship. I found a way to make it work.
I wonder what does morten think about my current implementation, I'm not sure that's a best practice.

For now I use Body.applyGeneralizedForce() in a custom Trigger implementation.
I also implemented a special DeactivationPolicy to be sure the my ship is always active.

Here is the code:

public class InteractiveDesactivationPolicy extends DefaultDeactivationPolicy {
    final private Set<Body> allwaysActive = new HashSet<Body>();
    public void setAllwaysActive(Body b) {
        allwaysActive.add(b);
    }
    @Override
    public boolean shouldBeActivated(Body b, double dt) {
        if (allwaysActive.contains(b)) {return true;}
        return super.shouldBeActivated(b, dt);
    }
    @Override
    public boolean shouldBeDeactivated(Body b, double dt) {
        if (allwaysActive.contains(b)) {
            return false;
        }
        return super.shouldBeDeactivated(b, dt);
    }
}

public void main(){
    final InteractiveDesactivationPolicy deactivationPolicy = new InteractiveDesactivationPolicy();
    final Scene scene = new DefaultScene(new SAP2(), new NonsmoothNonlinearConjugateGradient(45), deactivationPolicy);
    Body body = new Body("moveyourbody");
    scene.addBody(body);

    final Vector3 force = new Vector3();
    final Vector3 torque = new Vector3();
    scene.addTrigger(body, new Trigger() {
        public void start(Body body) {}
        public boolean update(Body body, double dt) {
            body.applyGeneralizedForce(force, torque, dt);
            return true;
        }
        public void stop(Body body) {}
        public void bodyAttached(Body body) {}
        public void bodyDetached(Body body) {}
        public void constraintAttached(Body body, Constraint c) {}
        public void constraintDetached(Body body, Constraint c) {}
    });

force.assign(10.,0.,0.);
scene.tick();
}

--
https://code.google.com/p/space-chronicles/
Pierre LABATUT

Jeffrey Elrod

unread,
Jul 24, 2011, 7:56:32 PM7/24/11
to jinn...@googlegroups.com
Hi Pierre,

You project is interesting. I will following it's progress. After
looking at your code I decided to use Body.applyForce(point, f, dt)
instead.

This is what I do. In the constructor of the hovercraft, I calculate
the points where I want the force to be applied to the hovercraft.
The hovercraft model was not designed with physics in mind so I use
Box geometry for the body.

Then before each time step, I multiply those force points with the
rotation calculated from the the Geometry.getWorldTransform() and add
it to the position calculated from Geometry.getWorldTransform() to get
the new point to apply the force. Then I apply the force at that new
point. When the hovercraft is at its initial position, the force
vector would be going in the Vector3.j() direction.

Instead of hovering the hovercraft collides into the ground.

Should I multiply the force by the rotation as well?
Jeff

Pierre LABATUT

unread,
Jul 25, 2011, 4:30:31 AM7/25/11
to jinn...@googlegroups.com
Hi,
The force and torque have to be expressed in world coordinate.
The engine moves with the ship, so you can easily express the vector in ship's coordinate.
That's why, you have to multiply the vectors by Body.getOrientation().

--
Pierre LABATUT

Morten Silcowitz

unread,
Jul 25, 2011, 9:52:18 AM7/25/11
to jinn...@googlegroups.com
Hi guys

cool you have something working. However, the right way to do this
would be using the generalized force constraint. It might have a bug
in it somewhere. I'll look into that soon. Until then just use the way
you have found to work :)

morten

Jeffrey Elrod

unread,
Jul 25, 2011, 10:22:53 AM7/25/11
to jinn...@googlegroups.com
Hi Morten,

Is it possible that you can create an example using GeneralizedForce
in the geometry_rework branch? That would help me understand things a
lot. In the meantime I can look into using Pierre's approach to get
me further along.

Thanks to both of you,
Jeff

Morten Silcowitz

unread,
Jul 25, 2011, 11:51:59 AM7/25/11
to jinn...@googlegroups.com
Yes i'll add an example as soon as I figure out what the bug is

morten

Jeffrey Elrod

unread,
Aug 18, 2011, 12:56:35 AM8/18/11
to jinn...@googlegroups.com
Hi Morten,

Just seeing if you had a chance to work on this. Hope all is well with you.

Jeff

mo

unread,
Aug 18, 2011, 5:23:15 PM8/18/11
to jinn...@googlegroups.com
Hi 

I updated GeneralizedForce and added a small example for it, to the geometry_rework branch. Let me know how it works out. In the example, only angular force is applied. If you want the force direction to follow the object, you just have to apply the rotation of the dynamic body to the angular direction vector. 

mo

Jeffrey Elrod

unread,
Aug 18, 2011, 5:29:29 PM8/18/11
to jinn...@googlegroups.com
Great! Thanks!

Jeffrey Elrod

unread,
Aug 31, 2011, 12:32:59 AM8/31/11
to jinn...@googlegroups.com
Hi Morten,

Thanks again for the help. I should have something to show you very
soon. I saw another model on turbo squid that I want to use in the
demo.

Jeff

Reply all
Reply to author
Forward
0 new messages