Project

General

Profile

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

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

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
 * Reset the value of the floats to (vx,vy,vz,vw).
54
 * 
55
 * @param vx new value of the first float
56
 * @param vy new value of the second float
57
 * @param vz new value of the third float
58
 * @param vw new value of the fourth float
59
 */
60
  public void set(float vx, float vy, float vz, float vw)
61
    {
62
    x = vx;
63
    y = vy;
64
    z = vz;
65
    w = vw;
66
    }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69
/**
70
 * Copy a Static4D.
71
 */
72
  public void set(Static4D s)
73
    {
74
    x = s.x;
75
    y = s.y;
76
    z = s.z;
77
    w = s.w;
78
    }
79

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81
/**
82
 * Resets the value of the first float.
83
 *
84
 * @param ox new value of the first float.
85
 */
86
  public void set0(float ox)
87
    {
88
    x = ox;
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92
/**
93
 * Resets the value of the second float.
94
 *
95
 * @param oy new value of the second float.
96
 */
97
  public void set1(float oy)
98
    {
99
    y = oy;
100
    }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
/**
104
 * Resets the value of the third float.
105
 *
106
 * @param oz new value of the third float.
107
 */
108
  public void set2(float oz)
109
    {
110
    z = oz;
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114
/**
115
 * Resets the value of the fourth float.
116
 *
117
 * @param ow new value of the fourth float.
118
 */
119
  public void set3(float ow)
120
    {
121
    w = ow;
122
    }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125
/**
126
 * Return the value of the first float contained.
127
 *
128
 * @return The first float.
129
 */
130
  public float get0()
131
    {
132
    return x;
133
    }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136
/**
137
 * Return the value of the second float contained.
138
 *
139
 * @return The second float.
140
 */
141
  public float get1()
142
    {
143
    return y;
144
    }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147
/**
148
 * Return the value of the third float contained.
149
 *
150
 * @return The third float.
151
 */
152
  public float get2()
153
    {
154
    return z;
155
    }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
/**
159
 * Return the value of the fourth float contained.
160
 *
161
 * @return The fourth float.
162
 */
163
  public float get3()
164
    {
165
    return w;
166
    }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169
/**
170
 * 'Interpolation' between the single Point (i.e. always this very value) returned to the buffer.
171
 *
172
 * @param buffer Float buffer we will write the results to.
173
 * @param offset Offset in the buffer where to write the result.
174
 * @param time not used
175
 * @param step not used
176
 * @return <code>false</code>
177
 */
178
  public boolean get(float[] buffer, int offset, long time, long step)
179
    {
180
    buffer[offset  ] = x;
181
    buffer[offset+1] = y;
182
    buffer[offset+2] = z;
183
    buffer[offset+3] = w;
184
    return false;
185
    }
186
  }
(17-17/18)