Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package min3d.core;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import min3d.vos.Number3d;

public class Number3dBufferList
{
	public static final int PROPERTIES_PER_ELEMENT = 3;
	public static final int BYTES_PER_PROPERTY = 4;

	private FloatBuffer _b;
	private int _numElements = 0;
	
	public Number3dBufferList(FloatBuffer $b, int $size)
	{
		ByteBuffer bb = ByteBuffer.allocateDirect($b.limit() * BYTES_PER_PROPERTY); 
		bb.order(ByteOrder.nativeOrder());
		_b = bb.asFloatBuffer();
		_b.put($b);
		_numElements = $size;
	}
	
	public Number3dBufferList(int $maxElements)
	{
		int numBytes = $maxElements * PROPERTIES_PER_ELEMENT * BYTES_PER_PROPERTY;
		ByteBuffer bb = ByteBuffer.allocateDirect(numBytes); 
		bb.order(ByteOrder.nativeOrder());
		
		_b  = bb.asFloatBuffer();
	}
	
	/**
	 * The number of items in the list. 
	 */
	public int size()
	{
		return _numElements;
	}
	
	/**
	 * The _maximum_ number of items that the list can hold, as defined on instantiation.
	 * (Not to be confused with the Buffer's capacity)
	 */
	public int capacity()
	{
		return _b.capacity() / PROPERTIES_PER_ELEMENT;
	}
	
	/**
	 * Clear object in preparation for garbage collection
	 */
	public void clear()
	{
		_b.clear();
	}
	
	//
	
	public Number3d getAsNumber3d(int $index)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		return new Number3d( _b.get(), _b.get(), _b.get() );
	}
	
	public void putInNumber3d(int $index, Number3d $number3d)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		$number3d.x = _b.get();
		$number3d.y = _b.get();
		$number3d.z = _b.get();
	}
	
	public float getPropertyX(int $index)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		return _b.get();
	}
	public float getPropertyY(int $index)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT + 1);
		return _b.get();
	}
	public float getPropertyZ(int $index)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT + 2);
		return _b.get();
	}
	
	//
	
	public void add(Number3d $n)
	{
		set( _numElements, $n );
		_numElements++;
	}
	
	public void add(float $x, float $y, float $z)
	{
		set( _numElements, $x,$y,$z );
		_numElements++;
	}
	
	public void set(int $index, Number3d $n)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		_b.put($n.x);
		_b.put($n.y);
		_b.put($n.z);
	}

	public void set(int $index, float $x, float $y, float $z)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		_b.put($x);
		_b.put($y);
		_b.put($z);
	}
	
	public void setPropertyX(int $index, float $x)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT);
		_b.put($x);
	}
	public void setPropertyY(int $index, float $y)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT + 1);
		_b.put($y);
	}
	public void setPropertyZ(int $index, float $z)
	{
		_b.position($index * PROPERTIES_PER_ELEMENT + 2);
		_b.put($z);
	}
	
	//
	
	public FloatBuffer buffer()
	{
		return _b;
	}
	
	public void overwrite(float[] $newVals)
	{
		_b.position(0);
		_b.put($newVals);
	}
	
	public Number3dBufferList clone()
	{
		_b.position(0);
		Number3dBufferList c = new Number3dBufferList(_b, size());
		return c;
	}
}

Commits for Nextrek/Android/LibrerieNextrek/src/min3d/core/Number3dBufferList.java

Diff revisions: vs.
Revision Author Commited Message
4 FMMortaroli picture FMMortaroli Fri 19 Apr, 2013 16:54:38 +0000