Project

General

Profile

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

library / src / main / java / org / distorted / library / type / Static4D.java @ 9a3607b3

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
 * Resets the value of the first float.
71
 *
72
 * @param ox new value of the first float.
73
 */
74
  public void set1(float ox)
75
    {
76
    x = ox;
77
    }
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80
/**
81
 * Resets the value of the second float.
82
 *
83
 * @param oy new value of the second float.
84
 */
85
  public void set2(float oy)
86
    {
87
    y = oy;
88
    }
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91
/**
92
 * Resets the value of the third float.
93
 *
94
 * @param oz new value of the third float.
95
 */
96
  public void set3(float oz)
97
    {
98
    z = oz;
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102
/**
103
 * Resets the value of the fourth float.
104
 *
105
 * @param ow new value of the fourth float.
106
 */
107
  public void set4(float ow)
108
    {
109
    w = ow;
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113
/**
114
 * Return the value of the first float contained.
115
 *
116
 * @return The first float.
117
 */
118
  public float get1()
119
    {
120
    return x;
121
    }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
/**
125
 * Return the value of the second float contained.
126
 *
127
 * @return The second float.
128
 */
129
  public float get2()
130
    {
131
    return y;
132
    }
133

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135
/**
136
 * Return the value of the third float contained.
137
 *
138
 * @return The third float.
139
 */
140
  public float get3()
141
    {
142
    return z;
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
/**
147
 * Return the value of the fourth float contained.
148
 *
149
 * @return The fourth float.
150
 */
151
  public float get4()
152
    {
153
    return w;
154
    }
155

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157
/**
158
 * 'Interpolation' between the single Point (i.e. always this very value) returned to the buffer.
159
 *
160
 * @param buffer Float buffer we will write the results to.
161
 * @param offset Offset in the buffer where to write the result.
162
 * @param time not used
163
 * @param step not used
164
 * @return <code>false</code>
165
 */
166
  public boolean get(float[] buffer, int offset, long time, long step)
167
    {
168
    buffer[offset  ] = x;
169
    buffer[offset+1] = y;
170
    buffer[offset+2] = z;
171
    buffer[offset+3] = w;
172
    return false;
173
    }
174
  }
(17-17/18)