Project

General

Profile

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

library / src / main / java / org / distorted / library / type / Static4D.java @ bff329fb

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted 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                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.library.type;
21

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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