Errors appear in my animation program

Errors in my program but can't seem to find what the problem is

Page 1 of 1

0 Replies - 668 Views - Last Post: 21 November 2009 - 07:51 AM Rate Topic: -----

#1 blueheroi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 15-February 08

Errors appear in my animation program

Post icon  Posted 21 November 2009 - 07:51 AM

Hello guys,

I have been trying to create a hand animation program with Java. The problem is a part of the code keeps giving me errors. I tried checking the spelling and indentation, but it sitll throws up errors.

I have not fully finished it as I wanted to take out the errors as it currently is, before moving on to the final part.So I am missing 2 movement angles for 1 fingers and 3 for 2 more fingers.
If possible could you have a quick look and see if you could find out what I am doing wrong?

The sections of the code where errors are :

public void processStimulus (Enumeration criteria)
	{
		double fl_stepAng1 = INITIAL_F1_ANG1 + NFrame * (FINAL_F1_ANG1 - INITIAL_F1_ANG1) / N_STEPS;
		double fl_stepAng1 = INITIAL_F1_ANG2 + NFrame * (FINAL_F1_ANG2 - INITIAL_F1_ANG2) / N_STEPS;
		double fl_stepAng1 = INITIAL_F1_ANG3 + NFrame * (FINAL_F1_ANG3 - INITIAL_F1_ANG3) / N_STEPS;

	 if (NFrame < N_STEPS)
	 {
		 resetFinger((TransformGroup)tgHand.getChild(0), f1_step Ang1, f1_step Ang2, f1_stepAng3 );
	 }
		NFrame++;
		wakeupOn (new WakeupOnElapsed Frames(1));
	}

	}
	}




	 public HandAnimation()
	 {
		setSize(700, 700);
	 	setLayout(new BorderLayout());

	 	GraphicsConfiguration graphicsConfig = 
			   SimpleUniverse.getPreferredConfiguration();
	Canvas3D c = new Canvas3D(graphicsConfig);

	 	add("Center", c);

	 	BranchGroup scene = createSceneGraph(c);
	 	SimpleUniverse u = new SimpleUniverse(c);
	 	u.getViewingPlatform().setNominalViewingTransform();
	 	u.addBranchGraph(scene);
	 }
	 



The full program code if anyone has time to run it:

package handanimation;



import java.awt.*;
import javax.swing.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.geometry.Box;

import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.util.Enumeration;

import javax.media.j3d.Material;

public class HandAnimation extends JFrame
{
	private static final int BONE_NV = 20;
	private static final int BONE_NH = 20;
	private static final int JOINT_NS = 30;

	private static final float BONE_L = (float)0.2;
	private static final float BONE_R = (float)0.02;
	private static final float JOINT_R = (float)0.05;

	private static final float PALM_W = 4 * (JOINT_R);
	private static final float PALM_L = (float)0.2;
	private static final float PALM_D = (float)0.02;

	// angles used to produce a static display of the first finger
	private static final double INITIAL_F1_ANG1 = -0;
	private static final double INITIAL_F1_ANG2 = -0;
	private static final double INITIAL_F1_ANG3 = -0.4;

	// angles used to produce a static display of the second finger
	private static final double INITIAL_F2_ANG1 = -0.3;
	private static final double INITIAL_F2_ANG2 = -0.4;
	private static final double INITIAL_F2_ANG3 = -0.5;

	// angles used to produce a static display of the third finger
	private static final double INITIAL_F3_ANG1 = 0.1;
	private static final double INITIAL_F3_ANG2 = -0.1;
	private static final double INITIAL_F3_ANG3 = -0.6;

	// angles used to produce a static display of the fourth finger
	private static final double INITIAL_F4_ANG1 = -0.1;
	private static final double INITIAL_F4_ANG2 = -0.5;
	private static final double INITIAL_F4_ANG3 = -0.8;

	// angles used to produce a static display of the fifth (i.e. thumb) finger
	private static final double INITIAL_F5_ANG1 = -1.9;
	private static final double INITIAL_F5_ANG2 = 0.2;
	private static final double INITIAL_F5_ANG3 = 0.8;




	static final int N_STEPS = 400;  // no of steps for linear interpolation

	Primitive joint1 = null;
	Primitive joint2 = null;
	Primitive joint3 = null;
	Primitive bone1 = null;
	Primitive bone2 = null;
	Primitive bone3 = null;


	public TransformGroup tgHand;

	public TransformGroup tgBall;

	public class  ObjectCollide extends behavior
	{
		WakeupOnCollisionEntry collideStart;
		WakeupOnCollisionExit collideEnd;

		
		 
		 Color3f newCol = new Color3f(1.0f, 0.0f, 0.5f);
		 Material newmaterial = new Material();
		 
		 
	
		boolean inCollision;

	


		Shape3D shape;
		Appearance sapp;
		Material setMaterial;
		double x, y, z;
		

	   public ObjectCollide( Shape3D myshape, double xt, double yt, double zt) /* TO DO - Task c: pass in the arguments
						   for Shape3D object and the x, y and z coordinate values
							 */
	   {
	   	
	   	shape = myshape;
		x = xt;
		y = yt;
		z = zt;
	
		   
			
			newmaterial.setDiffuseColor(newCol);

	

		   sapp = myshape.getAppearance();
		   setMaterial = sapp.getMaterial();
		   inCollision = false;
	   }

	   public void initialize()
	   {
		 
		   collideStart = new WakeupOnCollisionEntry(shape);
		   collideEnd = new WakeupOnCollisionExit(shape);
		   wakeupOn(collideStart);
		   
	   }

	   public void processStimulus(Enumeration criteria)
	   {
		 inCollision = !inCollision;
		   if (inCollision)
		   {
	 
			   
			   sapp.setMaterial(newmaterial);
			   
			   Transform3D tnew = new Transform3D();
			   tnew.setTranslation(new Vector3d(x, y, z));
			   tgBall.setTransform(tnew);
			   wakeupOn(collideEnd);
			} else
			{
				 sapp.setMaterial(newmaterial);

			   wakeupOn(collideStart);
			}
		}
	



	public class X extends behavior
	{
		private int NFrame = 0;

		public X()
		{
		}
	

	public void initialise ()

	{
		wakeupOn(new WakeupOnElapsed Time(2000));

	}

	public void processStimulus (Enumeration criteria)
	{
		double fl_stepAng1 = INITIAL_F1_ANG1 + NFrame * (FINAL_F1_ANG1 - INITIAL_F1_ANG1) / N_STEPS;
		double fl_stepAng1 = INITIAL_F1_ANG2 + NFrame * (FINAL_F1_ANG2 - INITIAL_F1_ANG2) / N_STEPS;
		double fl_stepAng1 = INITIAL_F1_ANG3 + NFrame * (FINAL_F1_ANG3 - INITIAL_F1_ANG3) / N_STEPS;

	 if (NFrame < N_STEPS)
	 {
		 resetFinger((TransformGroup)tgHand.getChild(0), f1_step Ang1, f1_step Ang2, f1_stepAng3 );
	 }
		NFrame++;
		wakeupOn (new WakeupOnElapsed Frames(1));
	}

	}
	}

	public BranchGroup createSceneGraph(Canvas3D c)
	{
		Appearance app = new Appearance();

		BranchGroup sceneRoot = new BranchGroup();

		BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

		Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
		Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
		Color3f emitColor = new Color3f(0.0f, 0.0f, 0.3f);
		Color3f gold = new Color3f(1.0f, 0.6f, 0.0f);
		Color3f grey = new Color3f(0.2f, 0.2f, 0.2f);
		Color3f redish = new Color3f(1.0f, 0.05f, 0.2f);

		Vector3f dir = new Vector3f(-1.0f, -1.0f, -1.0f);

		float shiny = 100.0f;

		Background bg = new Background(white);

		bg.setApplicationBounds(bounds);

		Transform3D rx = new Transform3D();
		rx.rotX(0.8);
		Transform3D ry = new Transform3D();
		ry.rotY(-0.8);

		Transform3D tHand = new Transform3D();
		tHand.mul(rx, ry);

		tgHand = new TransformGroup(tHand);
		tgHand.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
		tgHand.setCapability( TransformGroup.ALLOW_CHILDREN_WRITE );

	  sceneRoot.addChild(bg);

	  AmbientLight ambLgt = new AmbientLight(grey);
	  ambLgt.setInfluencingBounds(bounds);

	  DirectionalLight dirLgt = new DirectionalLight(white, dir);
	  dirLgt.setInfluencingBounds(bounds);

	  sceneRoot.addChild(ambLgt);
	  sceneRoot.addChild(dirLgt);

	  app.setMaterial( new Material( gold, black , gold, white , shiny ) );
	  app.setCapability( Appearance.ALLOW_MATERIAL_READ );
	  app.setCapability( Appearance.ALLOW_MATERIAL_WRITE );

	  tgHand.addChild(createFinger(app, 0.0, 0.0, 0.0,
						INITIAL_F1_ANG1,
						INITIAL_F1_ANG2,
						INITIAL_F1_ANG3));

	  tgHand.addChild(createFinger(app, 0.0, 0.0, 0.1,
						INITIAL_F2_ANG1,
						INITIAL_F2_ANG2,
						INITIAL_F2_ANG3));
						
	  tgHand.addChild(createFinger(app, 0.0, 0.0, 0.2,
						INITIAL_F3_ANG1,
						INITIAL_F3_ANG2,
						INITIAL_F3_ANG3));
						
	  tgHand.addChild(createFinger(app, 0.0, 0.0, 0.3,
	  INITIAL_F4_ANG1,
	  INITIAL_F4_ANG2,
	  INITIAL_F4_ANG3));

	  tgHand.addChild(createFinger(app, 0.0, 0.0, 0.4,
						INITIAL_F5_ANG1,
						INITIAL_F5_ANG2,
						INITIAL_F5_ANG3));

	  Transform3D tPalm = new Transform3D();
	  tPalm.setTranslation(new Vector3d(0, 0, PALM_W - JOINT_R));

	  TransformGroup tgPalm = new TransformGroup(tPalm);
	  tgPalm.addChild(createPalm(app));

	  tgHand.addChild(tgPalm);
	  sceneRoot.addChild(tgHand);
	   
	   Primitive object = null;

		Shape3D shape = (Shape3D) object.getShape(Sphere.BODY);
		ObjectCollide objcollide = new ObjectCollide(shape, x, y, z);
		objcollide.setSchedulingBounds(bounds);
		sceneroot.addChild(ObjectCollide);
		

		sceneRoot.compile();

		return sceneRoot;
	}





	private Group createPalm(Appearance app)
	{
		Primitive palm = null;
		palm = (Primitive) new Box(PALM_D, PALM_L, PALM_W, app);

		Transform3D tP = new Transform3D();
		tP.setTranslation(new Vector3d(0, -PALM_L, 0));

		TransformGroup tgP = new TransformGroup(tP);
		tgP.addChild(palm);
		return tgP;
	}


	private Group createFinger(Appearance app,
							   double xPos, double yPos, double zPos,
							   double ang1, double ang2, double ang3)
	{
		Transform3D tF = new Transform3D();
		tF.setTranslation(new Vector3d(xPos, yPos, zPos));

		TransformGroup tgF = new TransformGroup(tF);
		tgF.setCapability(TransformGroup.ALLOW_CHILDREN_READ);


		joint1 = (Primitive) new Sphere(JOINT_R,
										Sphere.GENERATE_NORMALS, JOINT_NS, app);

		joint2 = (Primitive) new Sphere(JOINT_R,
										Sphere.GENERATE_NORMALS, JOINT_NS, app);

		joint3 = (Primitive) new Sphere(JOINT_R,
										Sphere.GENERATE_NORMALS, JOINT_NS, app);


		bone1 = (Primitive) new Cylinder(BONE_R, BONE_L,
										Cylinder.GENERATE_NORMALS, BONE_NV, BONE_NH,app);

		bone2 = (Primitive) new Cylinder(BONE_R, BONE_L,
										Cylinder.GENERATE_NORMALS, BONE_NV, BONE_NH, app);

		bone3 = (Primitive) new Cylinder(BONE_R, BONE_L,
										Cylinder.GENERATE_NORMALS, BONE_NV, BONE_NH, app);
		
		
		

		Transform3D tb1Align = new Transform3D();
		tb1Align.setTranslation(new Vector3d(0, 0.5*BONE_L, 0.0));

		TransformGroup tgb1Align = new TransformGroup(tb1Align);
		tgb1Align.addChild(bone1);

		Transform3D tb1T = new Transform3D();
		TransformGroup tgb1T = new TransformGroup(tb1T);
		tgb1T.setCapability(TransformGroup.ALLOW_CHILDREN_READ);

		Transform3D tb1R = new Transform3D();
		tb1R.rotZ(ang1);
		TransformGroup tgb1R = new TransformGroup(tb1R);
		tgb1R.setCapability(TransformGroup.ALLOW_CHILDREN_READ);

		tgb1R.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		tgb1R.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

		tgb1T.addChild(tgb1R);

		Transform3D tj2T = new Transform3D();
		tj2T.setTranslation(new Vector3d(0, BONE_L, 0));

		TransformGroup tgj2T = new TransformGroup(tj2T);

		Transform3D tb2Align = new Transform3D();
		tb2Align.setTranslation(new Vector3d(0.0, 0.5*BONE_L, 0.0));
		TransformGroup tgb2Align = new TransformGroup(tb2Align);
		tgb2Align.addChild(bone2);

		Transform3D tb2R = new Transform3D();
		tb2R.rotZ(ang2);

		Transform3D tb2T = new Transform3D();
		tb2T.setTranslation(new Vector3d(0.0, BONE_L, 0.0));

		TransformGroup tgb2T = new TransformGroup(tb2T);
		TransformGroup tgb2R = new TransformGroup(tb2R);

		tgb2T.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
		tgb2R.setCapability(TransformGroup.ALLOW_CHILDREN_READ);

		tgb2R.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		tgb2R.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

		tgb2T.addChild(tgb2R); // bone 2 Transform Group
		tgj2T.addChild(joint2); // joint 2 Transform Group

		Transform3D tj3T = new Transform3D();
		tj3T.setTranslation(new Vector3d(0, BONE_L, 0));

		Transform3D tj3R = new Transform3D();
		tj3R.set(tb2R);

		TransformGroup tgj3T = new TransformGroup(tj3T);

		Transform3D tb3Align = new Transform3D();
		tb3Align.setTranslation(new Vector3d(0.0, 0.5*BONE_L, 0.0));
		TransformGroup tgb3Align = new TransformGroup(tb3Align);
		tgb3Align.addChild(bone3);

		Transform3D tb3R = new Transform3D();
		tb3R.rotZ(ang3);

		Transform3D tb3T = new Transform3D();
		tb3T.setTranslation(new Vector3d(0.0, BONE_L, 0.0));

		TransformGroup tgb3T = new TransformGroup(tb3T);
		TransformGroup tgb3R = new TransformGroup(tb3R);

		tgb3T.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
		tgb3R.setCapability(TransformGroup.ALLOW_CHILDREN_READ);

		tgb3R.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		tgb3R.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

		tgb3T.addChild(tgb3R);
		tgj3T.addChild(joint3);

		tgb3R.addChild(tgb3Align);

		tgF.addChild(tgb1T);
		tgb1R.addChild(tgb2T);

		tgb1R.addChild(tgb1Align);

		tgb1R.addChild(tgj2T);
		tgb2R.addChild(tgb3T);

		tgb2R.addChild(tgb2Align);

		tgb2R.addChild(tgj3T);
		tgF.addChild(joint1);

		return tgF;
	 }



	public void resetFinger(TransformGroup tg,
							 double ang1, double ang2, double ang3)
	{


		TransformGroup tgNext1 = (TransformGroup)tg.getChild(0);
	TransformGroup tgCurrent1 = (TransformGroup)tgNext1.getChild(0);

	Transform3D tCurrent1 = new Transform3D();
	tgCurrent1.getTransform(tCurrent1);
	tCurrent1.rotZ(ang1);
	tgCurrent1.setTransform(tCurrent1);

	  TransformGroup tgNext2 = (TransformGroup)tgCurrent1.getChild(0);
	TransformGroup tgCurrent2 = (TransformGroup)tgNext2.getChild(0);

	Transform3D tCurrent2 = new Transform3D();
	tgCurrent2.getTransform(tCurrent2);
	tCurrent2.rotZ(ang2);
	tgCurrent2.setTransform(tCurrent2);

	TransformGroup tgNext3 = (TransformGroup)tgCurrent2.getChild(0);
	TransformGroup tgCurrent3 = (TransformGroup)tgNext3.getChild(0);

	Transform3D tCurrent3 = new Transform3D();
	tgCurrent3.getTransform(tCurrent3);
	tCurrent3.rotZ(ang3);
	tgCurrent3.setTransform(tCurrent3);

	}

	 public HandAnimation()
	 {
		setSize(700, 700);
	 	setLayout(new BorderLayout());

	 	GraphicsConfiguration graphicsConfig = 
			   SimpleUniverse.getPreferredConfiguration();
	Canvas3D c = new Canvas3D(graphicsConfig);

	 	add("Center", c);

	 	BranchGroup scene = createSceneGraph(c);
	 	SimpleUniverse u = new SimpleUniverse(c);
	 	u.getViewingPlatform().setNominalViewingTransform();
	 	u.addBranchGraph(scene);
	 }
	 

	 public static void main(String[] args)
	 {
	 	 HandAnimation handTouchesBall = new HandAnimation();
	   handTouchesBall.setVisible(true);
	 }
 }




Thank you for any advice on what my errors could be as I am having a hard time figuring it out.

This post has been edited by blueheroi: 21 November 2009 - 07:55 AM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1