Project

General

Profile

Download (6.2 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / type / Static4D.java @ 8c57d77b

1
////////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski  leszek@koltunski.pl                                          //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// This library is free software; you can redistribute it and/or                                 //
7
// modify it under the terms of the GNU Lesser General Public                                    //
8
// License as published by the Free Software Foundation; either                                  //
9
// version 2.1 of the License, or (at your option) any later version.                            //
10
//                                                                                               //
11
// This library is distributed in the hope that it will be useful,                               //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                             //
14
// Lesser General Public License for more details.                                               //
15
//                                                                                               //
16
// You should have received a copy of the GNU Lesser General Public                              //
17
// License along with this library; if not, write to the Free Software                           //
18
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20

    
21
package org.distorted.library.type;
22

    
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24
/**
25
 * A 4-dimensional data structure containing four floats. The floats have no particular meaning; 
26
 * when this data structure is used in Dynamics, we can think of it as a 4-dimensional Point
27
 * a few of which the Dynamic interpolates between.
28
 */
29

    
30
public class Static4D extends Static implements Data4D
31
  {
32
  float x,y,z,w;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35
/**
36
 * Constructor that initialises the value of the four floats to (vx,vy,vz,vw).   
37
 *   
38
 * @param vx value of the first float.
39
 * @param vy value of the second float.
40
 * @param vz value of the third float.
41
 * @param vw value of the fourth float.
42
 */ 
43
  public Static4D(float vx, float vy, float vz, float vw)
44
    {
45
    super(4);
46
    x = vx;
47
    y = vy;
48
    z = vz;
49
    w = vw;
50
    }
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53
/**
54
 * Copy constructor.
55
 */
56
  public Static4D(Static4D sta)
57
    {
58
    super(4);
59
    x = sta.x;
60
    y = sta.y;
61
    z = sta.z;
62
    w = sta.w;
63
    }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
/**
67
 * Reset the value of the floats to (vx,vy,vz,vw).
68
 * 
69
 * @param vx new value of the first float
70
 * @param vy new value of the second float
71
 * @param vz new value of the third float
72
 * @param vw new value of the fourth float
73
 */
74
  public void set(float vx, float vy, float vz, float vw)
75
    {
76
    x = vx;
77
    y = vy;
78
    z = vz;
79
    w = vw;
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83
/**
84
 * Copy a Static4D.
85
 */
86
  public void set(Static4D s)
87
    {
88
    x = s.x;
89
    y = s.y;
90
    z = s.z;
91
    w = s.w;
92
    }
93

    
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95
/**
96
 * Resets the value of the first float.
97
 *
98
 * @param ox new value of the first float.
99
 */
100
  public void set0(float ox)
101
    {
102
    x = ox;
103
    }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106
/**
107
 * Resets the value of the second float.
108
 *
109
 * @param oy new value of the second float.
110
 */
111
  public void set1(float oy)
112
    {
113
    y = oy;
114
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117
/**
118
 * Resets the value of the third float.
119
 *
120
 * @param oz new value of the third float.
121
 */
122
  public void set2(float oz)
123
    {
124
    z = oz;
125
    }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
/**
129
 * Resets the value of the fourth float.
130
 *
131
 * @param ow new value of the fourth float.
132
 */
133
  public void set3(float ow)
134
    {
135
    w = ow;
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139
/**
140
 * Return the value of the first float contained.
141
 *
142
 * @return The first float.
143
 */
144
  public float get0()
145
    {
146
    return x;
147
    }
148

    
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150
/**
151
 * Return the value of the second float contained.
152
 *
153
 * @return The second float.
154
 */
155
  public float get1()
156
    {
157
    return y;
158
    }
159

    
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161
/**
162
 * Return the value of the third float contained.
163
 *
164
 * @return The third float.
165
 */
166
  public float get2()
167
    {
168
    return z;
169
    }
170

    
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172
/**
173
 * Return the value of the fourth float contained.
174
 *
175
 * @return The fourth float.
176
 */
177
  public float get3()
178
    {
179
    return w;
180
    }
181

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183
/**
184
 * 'Interpolation' between the single Point (i.e. always this very value) returned to the buffer.
185
 *
186
 * @param buffer Float buffer we will write the results to.
187
 * @param offset Offset in the buffer where to write the result.
188
 * @param time not used
189
 * @param step not used
190
 * @return <code>false</code>
191
 */
192
  public boolean get(float[] buffer, int offset, long time, long step)
193
    {
194
    buffer[offset  ] = x;
195
    buffer[offset+1] = y;
196
    buffer[offset+2] = z;
197
    buffer[offset+3] = w;
198
    return false;
199
    }
200
  }
(17-17/18)