Tuesday, April 08, 2008

Simple class from jbullet modified just for a quick and dirty feasibility test.

Code following has been decompiled from the JBullet basic demo class, changed to have one cube, and trace of linear velocity as well as x, y ,z coordinates of the box. Numbers are from a stupid System.out.println(), then this GUI wil lbe integrated in swarm-i to send these numbers to Lab connected dummy devices. In a correct way.

// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: Basic2Demo.java

package javabullet.demos.basic;

import java.util.ArrayList;
import java.util.List;
import javabullet.collision.broadphase.BroadphaseInterface;
import javabullet.collision.broadphase.SimpleBroadphase;
import javabullet.collision.dispatch.CollisionDispatcher;
import javabullet.collision.dispatch.DefaultCollisionConfiguration;
import javabullet.collision.shapes.*;
import javabullet.demos.opengl.*;
import javabullet.dynamics.*;
import javabullet.dynamics.constraintsolver.ConstraintSolver;
import javabullet.dynamics.constraintsolver.SequentialImpulseConstraintSolver;
import javabullet.linearmath.*;

import javax.vecmath.Vector3f;
import org.lwjgl.LWJGLException;

public class Basic2Demo extends DemoApplication
{

RigidBody body2 = null;

private static final int MAX_SHAPE_SIZE = 1;

public Basic2Demo(IGL gl)
{
super(gl);
collisionShapes = new ArrayList();
}

public void clientMoveAndDisplay()
{

gl.glClear(16640);

if(body2 != null){
System.out.println("# box: x=" + body2.getCenterOfMassPosition().x + " y=" + body2.getCenterOfMassPosition().y + " z=" + body2.getCenterOfMassPosition().z + " linear velocity=" + body2.getLinearVelocity());
}


float ms = clock.getTimeMicroseconds();
clock.reset();
if(dynamicsWorld != null)
{
dynamicsWorld.stepSimulation(ms / 1000000F);
dynamicsWorld.debugDrawWorld();
}

renderme();

}

public void displayCallback()
{
gl.glClear(16640);
renderme();
if(dynamicsWorld != null)
dynamicsWorld.debugDrawWorld();
}

public void initPhysics()
{
setCameraDistance(30F);
collisionConfiguration = new DefaultCollisionConfiguration();
dispatcher = new CollisionDispatcher(collisionConfiguration);
//Vector3f worldAabbMin = new Vector3f(-10000F, -10000F, -10000F);
//Vector3f worldAabbMax = new Vector3f(10000F, 10000F, 10000F);
overlappingPairCache = new SimpleBroadphase(1149);
SequentialImpulseConstraintSolver sol = new SequentialImpulseConstraintSolver();
solver = sol;
dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicsWorld.setGravity(new Vector3f(0.0F, -10F, 0.0F));
CollisionShape groundShape = new StaticPlaneShape(new Vector3f(0.0F, 1.0F, 0.0F), 50F);
collisionShapes.add(0,groundShape);
Transform groundTransform = new Transform();
groundTransform.setIdentity();
groundTransform.origin.set(0.0F, -56F, 0.0F);
float mass = 0.0F;
boolean isDynamic = mass != 0.0F;
Vector3f localInertia = new Vector3f(0.0F, 0.0F, 0.0F);
if(isDynamic)
groundShape.calculateLocalInertia(mass, localInertia);
DefaultMotionState myMotionState = new DefaultMotionState(groundTransform);
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, groundShape, localInertia);
RigidBody body = new RigidBody(rbInfo);
dynamicsWorld.addRigidBody(body);
CollisionShape colShape = new BoxShape(new Vector3f(1.0F, 1.0F, 1.0F));
//CollisionShape colShape = new SphereShape(30F);
//CollisionShape colShape = new CylinderShape(new Vector3f(1.0F, 1.0F, 1.0F));
collisionShapes.add(1,colShape);
Transform startTransform = new Transform();
startTransform.setIdentity();
float mass2 = 1.0F;
boolean isDynamic2 = mass2 != 0.0F;
Vector3f localInertia2 = new Vector3f(0.0F, 0.0F, 0.0F);
if(isDynamic)
colShape.calculateLocalInertia(mass2, localInertia2);
float start_x = -7F;
float start_y = -5F;
float start_z = -5F;
for(int k = 0; k <>
{
for(int i = 0; i <>
{
for(int j = 0; j <>
{
startTransform.origin.set(2.0F * (float)i + start_x, 2.0F * (float)k + start_y, 2.0F * (float)j + start_z);
DefaultMotionState myMotionState2 = new DefaultMotionState(startTransform);
RigidBodyConstructionInfo rbInf2 = new RigidBodyConstructionInfo(mass2, myMotionState2, colShape, localInertia2);
body2 = new RigidBody(rbInf2);
dynamicsWorld.addRigidBody(body2);
}

}

}

clientResetScene();
}

public static void main(String args[])
throws LWJGLException
{
Basic2Demo ccdDemo = new Basic2Demo(LWJGL.getGL());
ccdDemo.initPhysics();
ccdDemo.getDynamicsWorld().setDebugDrawer(new GLDebugDrawer(LWJGL.getGL()));
LWJGL.main(args, 800, 600, "Bullet Physics Demo. http://bullet.sf.net", ccdDemo);

}

private static final int ARRAY_SIZE_X = 5;
private static final int ARRAY_SIZE_Y = 5;
private static final int ARRAY_SIZE_Z = 5;
private static final int MAX_PROXIES = 1149;
private static final int START_POS_X = -5;
private static final int START_POS_Y = -5;
private static final int START_POS_Z = -3;
private List collisionShapes;
private BroadphaseInterface overlappingPairCache;
private CollisionDispatcher dispatcher;
private ConstraintSolver solver;
private DefaultCollisionConfiguration collisionConfiguration;
}


OK HORRIBLE NIGHTLY BUILT FIX but doing so, Doc Mud has his numbers in the meanwhile:

numbers are like these:

# box: x=-5.2613173 y=-5.000006 z=-5.6992044 linear velocity=(7.113341, 2.5081635E-4, -1.8705462)

# box: x=-5.1365914 y=-5.0000033 z=-5.7320027 linear velocity=(7.483558, 1.6021729E-4, -1.9678993)

# box: x=-5.0183263 y=-5.0000024 z=-5.7619495 linear velocity=(7.095896, 6.771088E-5, -1.7968078)

# box: x=-4.905269 y=-5.0000014 z=-5.78896 linear velocity=(6.783436, 6.9618225E-5, -1.6206144)

# box: x=-4.726717 y=-5.211472 z=-5.7739735 linear velocity=(10.713142, -12.6882305, 0.8991995)

# box: x=-4.6235833 y=-5.126884 z=-5.765317 linear velocity=(6.1880307, 5.0752907, 0.5193877)

# box: x=-4.511769 y=-5.0761304 z=-5.755932 linear velocity=(6.7088833, 3.04521, 0.5631053)

# box: x=-4.3964 y=-5.045679 z=-5.7462482 linear velocity=(6.9221334, 1.8270884, 0.5810045)

# box: x=-4.3964 y=-5.045679 z=-5.7462482 linear velocity=(6.9221334, 1.8270884, 0.5810045)

This is an easy, funny fast way to produce numbers to infer with a new intelligent prototype for the swarm-i hig level logic.

Sunday, April 06, 2008

Graphical generation of test data for the system

Doc Mud (thanks for the link to the great jbullet toy: http://jbullet.advel.cz/),

to gnerate test numbers to let you play with high level (this.)system intelligence design, can we use povray ? No, he suggested blender3d and jbullet. This to allow us to use a physic simulation library, to go through a software design of the sample. The sample will run producing the numbers for the tests. Result should be: we will design the cube and add its physic features, for example a cube falling down, then capture the numbers we need. Ah ? :)

I dunno yet if it is feasibile (too night to test it now and tomorrow it is another bloody monday), but doing so, while you move your cube here running in the same jvm of the "system", postion of the cube is sent to the dummy devices (in real) time, these will post back to the virtual world values read, and transform what you do here on the guy, into composable information units !! Then it will be possible to apply different algorithm to collate composable information unit and have some experiment scenarios. Good lab to play.

PS: on http://jbullet.advel.cz/ try to run the demos. They are very interesting.