Fixed. Next Q :)
[email protected] Fri, 23 Jul 2004 01:18:08 -0400
| Newsgroups | gmane.comp.graphics.fluidiom |
|---|---|
| Message-ID | <[email protected]> |
I seem to have "fixed" the problem of the plane not showing up by
moving the objects farther in the distance. It is visible then.
That said I am still having trouble turning on the physics manually. I
have set all the flags but I must have to fire an event somewhere. The
code seems to be very event driven and seems to be very coupled to a
GUI driven interface to control state and behaviour.
As well, it seems to "contort" stangely when it first starts before it
sets into its resting position. am pretty sure I positioned everything
correctly. I am wondering if there is some default values I forgot to
set on the intervals created in the MyFabricFactory.
Again I am submitting my "HelloWorld" example if anyone wants to look
over this and offer suggestions. I am trying to get some bare bones
code to understand the essential components, how to drive how to drive
behaviour, and understand the realtionships between the. Hopefully
this will touch on all the essentials without having to navigate
through the GUI portion.
As well, I am still interested in displaying spheres on each vertex.
My plan is to extend the engine Gerald has built and integrate it with
my own code which develops the morphology and neural networks of
virtual creatures. Each sphere then will represent an individual cell.
The idea is that the evolved neural networks will then take control of
certian elastics which will act like muscles. The others which are not
controled by actuator neurons will simply be there to stabalize the
shape and give it a defined, low energy morphology.
Again, two files below. I am avoiding anything fancy so you should be
able to just add them to a directory in the fluidiom package and
execute
//HelloWorld.java
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Set;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import nl.beautifulcode.fluidiom.fabric.Fabric;
import nl.beautifulcode.fluidiom.fabric.FabricEvent;
import nl.beautifulcode.fluidiom.fabric.FabricShell;
import nl.beautifulcode.fluidiom.fabric.Interval;
import nl.beautifulcode.fluidiom.fabric.IntervalList;
import nl.beautifulcode.fluidiom.fabric.Joint;
import nl.beautifulcode.fluidiom.fabric.JointList;
import nl.beautifulcode.fluidiom.fabric.MuscleActivator;
import nl.beautifulcode.fluidiom.factory.TriangleFactory;
import nl.beautifulcode.fluidiom.gui.PhysicsPanel;
import nl.beautifulcode.fluidiom.gui.Util;
import nl.beautifulcode.fluidiom.gui.ViewPanel;
import nl.beautifulcode.fluidiom.jogl.JoglFabric;
import nl.beautifulcode.fluidiom.jogl.JoglFabricView;
public class HelloWorld {
private static JFrame fabricFrame;
private static JoglFabricView joglFabricView;
private static void createDemoFrame() {
Dimension screen = Toolkit.getDefaultToolkit
().getScreenSize();
joglFabricView = new JoglFabricView();
joglFabricView.getFabric().setViewMode
(JoglFabric.VIEW_MODE_ELLIPSOID_CYLINDER);
fabricFrame = new JFrame();
fabricFrame.getContentPane().add
(joglFabricView,BorderLayout.CENTER);
FabricShell.get().addFabricListener(joglFabricView);
fabricFrame.setSize(screen.width,screen.height);
fabricFrame.addWindowListener(new WindowKiller());
}
private static void show() {
new MuscleActivator(FabricShell.get());
fabricFrame.setVisible(true);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
joglFabricView.start();
}
});
}
private static class WindowKiller extends WindowAdapter {
public void windowClosing(WindowEvent e) {
joglFabricView.stop();
System.exit(0);
}
}
public static void main(String[] args) {
FabricShell fs = FabricShell.get();
Fabric fabric = MyFabricFactory.newInstance();
fs.setFabric(fabric);
createDemoFrame();
joglFabricView.getFabric().refresh();
show();
}
}
//MyFabricFactory.java
import javax.vecmath.Vector3f;
import nl.beautifulcode.fluidiom.fabric.Fabric;
import nl.beautifulcode.fluidiom.fabric.FabricOccupant;
import nl.beautifulcode.fluidiom.fabric.Interval;
import nl.beautifulcode.fluidiom.fabric.IntervalList;
import nl.beautifulcode.fluidiom.fabric.Joint;
import nl.beautifulcode.fluidiom.fabric.JointList;
import nl.beautifulcode.fluidiom.fabric.Physics;
public class MyFabricFactory {
public static Fabric newInstance(){
Fabric fabric = new Fabric();
fabric.physics = new Physics();
fabric.physics.gravityOn = true;
fabric.jointList = new JointList();
fabric.intervalList = new IntervalList();
//four lower joints formig a square
Joint joint1 = createJoint(fabric,0,-1,1);
fabric.jointList.add(joint1);
Joint joint2 = createJoint(fabric,0,-2,1);
fabric.jointList.add(joint2);
Joint joint3 = createJoint(fabric,1,-2,1);
fabric.jointList.add(joint3);
Joint joint4 = createJoint(fabric,1,-1,1);
fabric.jointList.add(joint4);
//four upper joints completing the verticies ofthe cube
Joint joint5 = createJoint(fabric,0,-1,2);
fabric.jointList.add(joint1);
Joint joint6 = createJoint(fabric,0,-2,2);
fabric.jointList.add(joint2);
Joint joint7 = createJoint(fabric,1,-2,2);
fabric.jointList.add(joint3);
Joint joint8 = createJoint(fabric,1,-1,2);
fabric.jointList.add(joint4);
//bottom
Interval interval = createInterval(fabric, joint1,
joint2);
fabric.intervalList.add(interval);
interval = createInterval(fabric, joint2, joint3);
fabric.intervalList.add(interval);
interval = createInterval(fabric, joint3, joint4);
fabric.intervalList.add(interval);
interval = createInterval(fabric, joint1, joint4);
fabric.intervalList.add(interval);
// top
interval = createInterval(fabric, joint5, joint8);
fabric.intervalList.add(interval);
interval = createInterval(fabric, joint5, joint6);
fabric.intervalList.add(interval);
interval = createInterval(fabric, joint6, joint7);
fabric.intervalList.add(interval);
interval = createInterval(fabric, joint7, joint8);
fabric.intervalList.add(interval);
//sides
interval = createInterval(fabric, joint1, joint5);
fabric.intervalList.add(interval);
interval = createInterval(fabric, joint2, joint6);
fabric.intervalList.add(interval);
interval = createInterval(fabric, joint3, joint7);
fabric.intervalList.add(interval);
interval = createInterval(fabric, joint4, joint8);
fabric.intervalList.add(interval);
//diagonals
//front panel
interval = createInterval(fabric, joint1, joint8);
fabric.intervalList.add(interval);
interval = createInterval(fabric, joint4, joint5);
fabric.intervalList.add(interval);
// back panel
interval = createInterval(fabric, joint7, joint2);
fabric.intervalList.add(interval);
interval = createInterval(fabric, joint3, joint6);
fabric.intervalList.add(interval);
//left panel
interval = createInterval(fabric, joint4, joint7);
fabric.intervalList.add(interval);
interval = createInterval(fabric, joint8, joint3);
fabric.intervalList.add(interval);
// right panel
interval = createInterval(fabric, joint1, joint6);
fabric.intervalList.add(interval);
interval = createInterval(fabric, joint5, joint2);
fabric.intervalList.add(interval);
// bottom panel
interval = createInterval(fabric, joint1, joint3);
fabric.intervalList.add(interval);
interval = createInterval(fabric, joint2, joint4);
fabric.intervalList.add(interval);
// top panel
interval = createInterval(fabric, joint5, joint7);
fabric.intervalList.add(interval);
interval = createInterval(fabric, joint6, joint8);
fabric.intervalList.add(interval);
// interval = createInterval(fabric, joint3, joint7);
// fabric.intervalList.add(interval);
// interval = createInterval(fabric, joint4, joint8);
// fabric.intervalList.add(interval);
fabric.run();
return fabric;
}
private static Joint createJoint(Fabric theFabric, float
theX, float theY, float theZ) {
Joint joint = new Joint();
joint.run();
theFabric.put(joint.id,joint);
joint.locus.set(theX,theY,theZ);
joint.put(Joint.OCCUPANT_KEY,null);
return(joint);
}
private static Interval createInterval(Fabric theFabric,
Joint theAlpha, Joint theOmega) {
Interval interval = new Interval(theAlpha,theOmega);
Vector3f v = new Vector3f();
v.sub(theAlpha.locus, theOmega.locus);
interval.span = interval.actualSpan = v.length();
interval.run();
theFabric.put(interval.id,interval);
return(interval);
}
}
========================
Rob Leclerc
Yale University
email: [email protected]
email: [email protected]
webpage: www.cpsc.ucalgary.ca/~leclerc
========================
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click