Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (552)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Changing angles with Alpha..  (Read 817 times)
0 Members and 1 Guest are viewing this topic.
Offline ArchangelMorph

Senior Newbie




Java games rock!


« Posted 2005-03-28 09:28:29 »

Ok in my Java3D program I have a 3D model with which I'd like to animate..

I wanna use the alpha class to specify the time frame for the animation (i.e. the number of frames in the animation loop)

And I want to specify the angles for every frame of animation in the loop, for every joint on the model I want to move..

I was looking at the rotationInterpolator class but the problem with this is it calls the processStimulus method every frame to calculate the angle from the alpha rather than retrieve these angles from an array (which is what I want to do in my program)..

(hope i'm making sense thus far..)

So I'm keen to find out if I should just create a new class which extends the RotationInterpolator class but overrides the processStimulus method, or do something else entirely to achieve my goals?

I hope someone can help me resolve this issue since my program is very near to completion and I don't have too long left until the deadline..

Thankyou for your time


- ArchangelMorph -
Offline MatthewJones

Senior Newbie




Little Fat Blob!


« Reply #1 - Posted 2005-03-28 10:41:56 »

Write your own interpolater. We had to write a Matrix4f interpolater for keyframes (30kf per second) in an animation. Its really not that big of deal. We didn't have to write that much and you'll have to write less if all you want is rotation.

Matt
Offline ArchangelMorph

Senior Newbie




Java games rock!


« Reply #2 - Posted 2005-03-28 13:03:25 »

Could you give me a little info on to how to do this?

Since this is the first time i've written any kind of program with Java3D I'm not entirely sure on how java3D uses the Interpolator class for interpolating frames..

Any help would be extremely appreciated!

Thankyou so much

- ArchangelMorph -
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline MatthewJones

Senior Newbie




Little Fat Blob!


« Reply #3 - Posted 2005-03-28 14:15:14 »

Well I didn't write it for starters So I will have a hard time explaining all of it you can reveiw the Code. But its not well documented.  Hopefully it will help. If not my partner (my Father) will be back Friday we could give you some more details then.

Also rememember some of this will be specific to what we are building.

Prinarly though I think you will be interested in the Rotation parts.
" public static void getQuat "

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
249  
250  
251  
252  
253  
254  
255  
256  
257  
258  
259  
260  
261  
262  
263  
264  
265  
266  
267  
268  
269  
270  
271  
272  
273  
274  
package behaviors;
 

/*
 * Created on Jan 8, 2005
 *
 * MatrixRPSInterpolator class
 */

 
/**
 * @author Jim Jones
 *
 * Sharp Productions
 */

import java.util.Enumeration;
 
import javax.media.j3d.Alpha;
import javax.media.j3d.Interpolator;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.WakeupCriterion;
import javax.media.j3d.WakeupOnElapsedFrames;
import javax.vecmath.Quat4f;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;
 
public class MatrixRPSInterpolator extends Interpolator {
 Alpha alpha;
 Transform3D[] keys;
 Transform3D[] keyFrames;
 int keyLength;
 int currentFrame;
 float[] knots;
 int openClosed;
 TransformGroup target = null;
 WakeupCriterion wakeup;
 protected float prevAlpha = Float.NaN;
 protected float currentAlpha = Float.NaN;
 protected float currentU;
 protected float lowerKnot;
 protected Transform3D lowerT = new Transform3D();
 protected float upperKnot;
 protected Transform3D upperT = new Transform3D();
 private Transform3D currentTransform = new Transform3D();
 private float totalAlpha = 0f;
 private int indexAlpha = 0;
 private Vector3f oneT = new Vector3f();
 private Vector3f twoT = new Vector3f();
 private Vector3f finalT = new Vector3f();
 private Quat4f oneQ = new Quat4f();
 private Quat4f twoQ = new Quat4f();
 private Quat4f finalQ = new Quat4f();
 private Vector3d oneS = new Vector3d();
 private Vector3d twoS = new Vector3d();
 private Vector3d finalS = new Vector3d();
 
 
 // non-public, default constructor used by cloneNode
MatrixRPSInterpolator() {
 }
 
 /**
  *
  */

 public MatrixRPSInterpolator(int openClosed, Alpha alpha, Transform3D[] keys,
         float[] knots, TransformGroup target) {
  super(alpha);
  this.openClosed = openClosed;
  setKeys(keys);
  setTarget(target);
  this.currentFrame = 0;
  this.wakeup = (WakeupCriterion) new WakeupOnElapsedFrames(0, true);
  this.alpha = alpha;
  setKnots(knots);
  target.getTransform(currentTransform);
 }
 
 /**
  *
  */

 public void setKeys(Transform3D[] keys) {
        if (keys.length < 2) {
        throw new IllegalArgumentException("Key number of "+keys.length+" is too few");
        }
        this.keys = keys;
        this.keyLength = keys.length;
        keyFrames = new Transform3D[keyLength + 2];
        keyFrames[0] = new Transform3D();
        keyFrames[0] = keys[0];
        for (int i = 1; i < keyLength+1; i++) {
         keyFrames[i] = keys[i-1];
        }
        keyFrames[keyLength+1] = new Transform3D();
        keyFrames[keyLength+1] = keys[keyLength-1];
 
      
 
    
 }
 
 /**
  *
  */

 public void setTarget(TransformGroup target) {
        if (target == null) {
         throw new IllegalArgumentException("Requires a non-null TransformGroup");
        }
        this.target = target;
 }
 
 /**
  *
  */

 public void setKnots(float[] knots) {
  int len = knots.length;
  if(keyLength != len) {
   throw new IllegalArgumentException("# knots must equal # keys");
  }
  if((knots[0] != 0)|| (knots[knots.length-1] != 1)) {
   throw new IllegalArgumentException("knots must start w/ 0 and end w/ 1");
  }
  for(int i=2; i<len; i++) {
   float one = knots[i-1];
   float two = knots[i];
   if(one < two) {
    continue;
   } else {
    throw new IllegalArgumentException("knots must be in sequence up or down");
   }
  }
  this.knots = knots;
 }
 
 /**
  *
  */

 protected void computePathInterpolation() {
  float value = (this.getAlpha()).value();
  computePathInterpolation(value);
 }
 
 /**
  *
  */

 protected void computePathInterpolation(float aValue) {
  // Bubble Gum
 if(aValue < .0025f) {
   aValue = .0025f;
  }
  int i = 0;
  while((aValue > knots[i]) && (i < keyLength-2)) {
   i++;
  }
  if(i == 1) {
   currentU = 0f;
   lowerT = keys[1];
   upperT = keys[2];
  } else {
//System.out.println("alpha "+aValue);
//System.out.println(" knot index "+i);
//System.out.println(" knot[i] "+knots[i]);
//System.out.println("currentU "+currentU);
//System.out.println(" knots[i-1} "+knots[i-1]);
  currentU = (aValue - knots[i-1])/(knots[i] - knots[i-1]);
   lowerT = keys[i-1];
   upperT = keys[i];
  }
 }
 
 
 
 public void computeTransform(float alphaValue, Transform3D currentTransform) {
  computePathInterpolation(alphaValue);
  // Get the rotation and translation components
 getQuat(lowerT, oneQ);
  getTrans(lowerT, oneT);
  getScale(lowerT, oneS);
  oneQ.normalize();
  getQuat(upperT, twoQ);
  getTrans(upperT, twoT);
  getScale(upperT, twoS);
  oneQ.normalize();
  // Interpolate the translations
 finalT.sub(twoT, oneT);
  finalT.scaleAdd(1.0f, oneT);
  // Interpolater the rotations
 finalQ.sub(twoQ, oneQ);
  finalQ.scaleAdd(1.0f, oneQ);
  finalQ.normalize();
  // Interpolate Scale
 finalS.sub(twoS, oneS);
  finalS.scaleAdd(1.0f, oneS);
  // Set interpolations
 currentTransform.setTranslation(finalT);
  currentTransform.setRotation(finalQ);
  currentTransform.setScale(finalS);
  //currentTransform.normalize();
System.out.println("Type "+currentTransform.getBestType());
System.out.println("Sign "+currentTransform.getDeterminantSign());
 }
 
 /* (non-Javadoc)
  * @see javax.media.j3d.Behavior#processStimulus(java.util.Enumeration)
  */

/**/
 public void processStimulus(Enumeration criteria) {
  if(alpha != null) {
   currentAlpha = alpha.value();
   if(currentAlpha != prevAlpha) {
//System.out.println("currentAlpha "+currentAlpha+" "+prevAlpha);
    prevAlpha = currentAlpha;
    target.getTransform(currentTransform);
    computeTransform(currentAlpha, currentTransform);
    target.setTransform(currentTransform);
   }
      if (!alpha.finished() && !alpha.isPaused()) {
    wakeup = defaultWakeupCriterion;
   }
 
  }
  wakeupOn(wakeup);
 }

 
 public static void getQuat(Transform3D t, Quat4f q) {
  float[] mat = new float[16];
  t.get(mat);
  float trace = mat[0] + mat[5] + mat[10] + 1;
  if(trace > 0) {
   float s = 0.5f/(float)Math.sqrt(trace);
   q.w = 0.25f/s;
   q.x = (mat[9] - mat[6]) * s;
   q.y = (mat[2] - mat[8]) * s;
   q.w = (mat[4] - mat[1]) * s;
  } else {
   if((mat[0] > mat[5]) && (mat[0] > mat[10])) {
    float s = (float)Math.sqrt(1.0f + mat[0] - mat[5] - mat[10]) * 2;
    q.x = 0.5f/s;
    q.y = (mat[1] + mat[4])/s;
    q.z = (mat[2] + mat[8])/s;
    q.w = (mat[6] + mat[9])/s;
   } else if ((mat[5] > mat[0]) && (mat[5] > mat[10])) {
    float s = (float)Math.sqrt(1.0f + mat[5] - mat[0] - mat[10]) * 2;
    q.x = (mat[1] + mat[4])/s;
    q.y = 0.5f/s;
    q.z = (mat[6] + mat[9])/s;
    q.w = (mat[2] + mat[8])/s;
   } else if ((mat[10] > mat[0]) && (mat[10] > mat[5])) {
    float s = (float)Math.sqrt(1.0f + mat[10] - mat[0] - mat[5]) * 2;
    q.x = (mat[2] + mat[8])/s;
    q.y = (mat[6] + mat[9])/s;
    q.z = 0.5f/s;
    q.w = (mat[1] + mat[4])/s;
   }
  }
 }
 
 public static void getTrans(Transform3D t, Vector3f v) {
  float[] mat = new float[16];
  t.get(mat);
  v.x = mat[3];
  v.y = mat[7];
  v.z = mat[11];
 }
 
 public static void getScale(Transform3D t, Vector3d v) {
  float[] mat = new float[16];
  t.get(mat);
  v.x = mat[0];
  v.y = mat[5];
  v.z = mat[10];
 }
 
}

Offline ArchangelMorph

Senior Newbie




Java games rock!


« Reply #4 - Posted 2005-03-28 18:10:47 »

May god bless you as he has me through you!!

Seriously thankyou sooooooo much!!

There are tooo many good people around here and I just don't think you all get enough of the praise that you all deserve!!

I'll be graduating this yr thanx to the help of such fine members of society!!

Thanks again!!

- ArchangelMorph -
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (22 views)
2014-08-22 19:31:30

atombrot (34 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (28 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (26 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (41 views)
2014-08-06 19:49:38
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!