At a loss

Ok then, here i am again… asking for help/advise (promice i will pay it back eventually!). Ok well here’s what i am trying to do:



I have an array of nodes (which are simply a box with a texture on it added as a child to another node, this other node is what i have an array of…). Anyway the other thing in my world is basically another large Box object which i am using as a “dance floor” each of the box’s are positioned arround the outer rim of the “dance floor” facing one another. This positioning is done by setLocalTranslation and setLocalRotation on each of the nodes in the array and depending where in the array they are they are positioned in there specific “start position”… It is unfortunatly at this point it all falls appart.



Basically each Node in array (from here i shall each a dancer) has an array associated with it which are that specific dancers movements (a move list) it is mearly an array of bytes which are paired together i.e. moveList[0] and movelist[1] … moveList[k] and movelist[k+1]. The first of the pair contains a byte which represents the type of movement the dancers is to do, the second contains the amount of time the dancer is to do this for.



My general plan was to, therefore, create a SpatialTransformer which contained the number of dancers on the dancefloor, and for each of the dancers add the list of moves to be performed. This however has ended in totaly spurious results. Firstly if the Transformer is setActive(false) so that the dancers dont start untill told to do so, after the moves have been added to the Transformer and the screen renders all of the dancers are out of rotation (however they are in the correct position). I cant quite see why this would occure as the Transformer is set inactive before any moves are added. Secondly if the Transform is setActive(true) the dancers all appear in the center of the dancefloor, not moving. Given that the current test array of moves contains only a single move (a rotation of 90 degrees to the left over 1 second) i dont see how this is occuring.



Any help on this issue would be gratfully recieved, also any “better ideas” as conserns how to animate the little blighters instead of using a SpatialTransformer are also appreciated!



Here’s the code that is used to add the animations to the dancers:




   private void startDance() {
      st.setActive(true);      //set the little buggers off..
   }

   public void setupAnimation() {
      
      int dancerNum = 0;
      
      for (int k=0; k < moveLists.length; k++) {   //create enough dancers for the movelists we have
         if (moveLists[k] == null)            //if a given movelist is empty we havent created a dancer for it!
            continue;
         
         Object[] moves = moveLists[k].getMoves();
         Node dancer = dancers[k].getDancer();
         
         System.out.println("Adding Animation For Dancer " + (k+1));
         
         st.setObject(dancer,dancerNum,-1);   //associate the transformer with this dancer
         
         int MoveType, MoveSize;
         Quaternion rot=new Quaternion();      //Quaternion we can use for rotations
         
         System.out.println("currentDegree: " + dancers[k].getCurrentDegree() + "totalTime" + dancers[k].getTotalTime());
         
         for (int i=0; i<moves.length; i+=2) {   //for each move on the movelist array for this dancer add it to the transformer
            
            MoveType = ((Integer)moves[i]).intValue();      //get the movetype from the user
            MoveSize = ((Integer)moves[i+1]).intValue();   //get the duration that move should be performed for (or number of degrees if its an angle)
            
            if (MoveType == FORWARDMOVE) {         //forward move
               
               System.out.println("Forward: " + MoveSize);
               dancers[k].setTotalTime(dancers[k].getTotalTime() + (MoveSize));
               System.out.println("End Add");

            } else if (MoveType == BACKWARDMOVE) {   //backward move
               
               System.out.println("Backward: " + MoveSize);
               dancers[k].setTotalTime(dancers[k].getTotalTime() + (MoveSize));
               System.out.println("End Add");

            } else if (MoveType == LEFTMOVE) {      //left turn move
               
//               we multiply by 5 as we devide the number by 5 when we create it (due to transmission limits with the actual robots)
               System.out.println("Left: " + MoveSize*5);

               for (int j=0; j<6; j++) {   //split the movement into 6 keyframes (to reduce the chances of odd rotationa)
                  rot.fromAngleAxis(FastMath.DEG_TO_RAD*(dancers[k].getCurrentDegree()+((MoveSize)*j)),new Vector3f(0,1,0));
                  st.setRotation(dancerNum,dancers[k].getTotalTime()+((barLength/5)*j),rot);
               }
               
               dancers[k].setCurrentDegree(dancers[k].getCurrentDegree() + MoveSize*5);
               dancers[k].setTotalTime(dancers[k].getTotalTime() + (barLength));
               System.out.println("End Add");
               System.out.println("currentDegree: " + dancers[k].getCurrentDegree() + "totalTime" + dancers[k].getTotalTime());
                           
            } else if (MoveType == RIGHTMOVE) {      //right turn move
               
//               we multiply by 5 as we devide the number by 5 when we create it (due to transmission limits with the actual robots)
               System.out.println("Right: " + MoveSize*5);
               
               for (int j=0; j<6; j++) { //split the movement into 6 keyframes (to reduce the chances of odd rotationa)
                  rot.fromAngleAxis(FastMath.DEG_TO_RAD*(dancers[k].getCurrentDegree()-((MoveSize)*j)),new Vector3f(0,1,0));
                  st.setRotation(dancerNum,dancers[k].getTotalTime()+((barLength/5)*j),rot);
               }
               dancers[k].setCurrentDegree(dancers[k].getCurrentDegree() + MoveSize*5);
               dancers[k].setTotalTime(dancers[k].getTotalTime() + (barLength));
               System.out.println("End Add");
               System.out.println("currentDegree: " + dancers[k].getCurrentDegree() + "totalTime" + dancers[k].getTotalTime());
               
            } else if (MoveType == WAITMOVE) {      //wait move
               
               System.out.println("Wait: " + MoveSize);
               rot.fromAngleAxis(FastMath.DEG_TO_RAD*dancers[k].getCurrentDegree(),new Vector3f(0,1,0));
               st.setRotation(dancerNum,(dancers[k].getTotalTime()+(barLength*MoveSize)),rot);
               dancers[k].setTotalTime(dancers[k].getTotalTime() + (barLength*MoveSize));
               System.out.println("End Add");
               
            }         
            
         }   
         
         dancer.addController(st);
         dancerNum++;
         System.out.println("Finnished Adding Animation For Dancer " + (k+1));
         
      }
      
      st.interpolateMissing();
      //st.setRepeatType(SpatialTransformer.RT_CLAMP);

   }



Here's a dancer:



package simulation;

import com.jme.bounding.BoundingSphere;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;

//import com.jme.animation.SpatialTransformer;

public class Dancer {
   

   private float currentDegree, totalTime = 0;
   private int danceNumber;
   private Node completeDancer;
   private Vector3f startPosition;
   
   public Dancer(int givenDanceNumber) {
      danceNumber = givenDanceNumber;
      completeDancer = new Node("Dancer " + danceNumber);
      BuildDancer();
   }
   
   private void BuildDancer() {
      Box body = new Box("Body Of Dancer " + danceNumber, new Vector3f(), 2,.5f,2);
      body.setModelBound(new BoundingSphere());
      body.updateModelBound();
      completeDancer.attachChild(body);
      completeDancer.updateWorldBound();
   }
   
   /**
    * @return Returns the completeDancer.
    */
   public Node getDancer() {
      return completeDancer;
   }

   /**
    * @return Returns the currentDegree.
    */
   public float getCurrentDegree() {
      return currentDegree;
   }
   /**
    * @param currentDegree The currentDegree to set.
    */
   public void setCurrentDegree(float currentDegree) {
      this.currentDegree = currentDegree;
   }
   
   /**
    * @return Returns the totalTime.
    */
   public float getTotalTime() {
      return totalTime;
   }
   /**
    * @param totalTime The totalTime to set.
    */
   public void setTotalTime(float totalTime) {
      this.totalTime = totalTime;
   }
}



This is without the animation:


When the animation is setup but the Transformer is set to inactive:


When the animation is setup then started:


Regards all again for putting up with my learning curve!

Roja

Sorted it… was multiplying an int and a float and it was going terrebly wrong :frowning:



Cheers,



Roja