FreeWRL/FreeX3D  3.0.0
VSFRotation.java
1 // copyright (c) 1997,1998 stephen f. white
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2, or (at your option)
6 // any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; see the file COPYING. If not, write to
15 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16 
17 package sai.eai;
18 import java.io.*;
19 
20 public class VSFRotation extends VField
21 {
22  private float[] values = new float[4];
23 
24  public VSFRotation(float axisX, float axisY, float axisZ, float angle)
25  {
26  values[0] = axisX;
27  values[1] = axisY;
28  values[2] = axisZ;
29  values[3] = angle;
30  }
31 
32  public VSFRotation(float[] values)
33  {
34  if (values.length != 4) {
35  this.values[0] = values[0];
36  this.values[1] = values[1];
37  this.values[2] = values[2];
38  this.values[3] = values[3];
39  } else {
40  this.values = values;
41  }
42  }
43 
44  public VSFRotation(DataInputStream in) throws IOException
45  {
46  values[0] = in.readFloat();
47  values[1] = in.readFloat();
48  values[2] = in.readFloat();
49  values[3] = in.readFloat();
50  }
51 
52  public void write(DataOutputStream out) throws IOException
53  {
54  out.writeFloat(values[0]);
55  out.writeFloat(values[1]);
56  out.writeFloat(values[2]);
57  out.writeFloat(values[3]);
58  }
59 
60  public String toString()
61  {
62  return "(" + values[0] + ", " + values[1] + ", " + values[2] + ", " + values[3] + ")";
63  }
64 
65  public byte getType() { return SFROTATION; }
66 
67  public float[] getValue() {
68  return values;
69  }
70 
71  /* Isabelle June 25 1999 for RAT 3D */
72 
73  public double getAngle() {
74  /* a 90 degree correcting factor is required to map VNet initial orientation to */
75  /* standard convention. VNet defines 0 degree as where the avatar is facing */
76  /* whereas normally, 0 degree is on the x axis of a circle */
77 
78  double angle;
79 
80  angle = (double)values[3] + (Math.PI/2);
81  if (angle > Math.PI) /* value can only be between +/- PI */
82  {
83  angle = angle - (2*Math.PI);
84  }
85  return angle;
86  }
87 
88 }