If you think the Android project min3d listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.min3d.lib.core;
/*fromwww.java2s.com*/import com.min3d.lib.vos.Uv;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
publicclass UvBufferList
{
publicstaticfinalint PROPERTIES_PER_ELEMENT = 2;
publicstaticfinalint BYTES_PER_PROPERTY = 4;
private FloatBuffer _b;
privateint _numElements = 0;
public UvBufferList(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 UvBufferList(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.
*/publicint 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)
*/publicint capacity()
{
return _b.capacity() / PROPERTIES_PER_ELEMENT;
}
/**
* Clear object in preparation for garbage collection
*/publicvoid clear()
{
_b.clear();
}
public Uv getAsUv(int $index)
{
_b.position($index * PROPERTIES_PER_ELEMENT);
returnnew Uv( _b.get(), _b.get() );
}
publicvoid putInUv(int $index, Uv $uv)
{
_b.position($index * PROPERTIES_PER_ELEMENT);
$uv.u = _b.get();
$uv.v = _b.get();
}
publicfloat getPropertyU(int $index)
{
_b.position($index * PROPERTIES_PER_ELEMENT);
return _b.get();
}
publicfloat getPropertyV(int $index)
{
_b.position($index * PROPERTIES_PER_ELEMENT + 1);
return _b.get();
}
//
publicvoid add(Uv $uv)
{
set( _numElements, $uv );
_numElements++;
}
publicvoid add(float $u, float $v)
{
set(_numElements, $u, $v);
_numElements++;
}
publicvoid set(int $index, Uv $uv)
{
_b.position($index * PROPERTIES_PER_ELEMENT);
_b.put($uv.u);
_b.put($uv.v);
}
publicvoid set(int $index, float $u, float $v)
{
_b.position($index * PROPERTIES_PER_ELEMENT);
_b.put($u);
_b.put($v);
}
publicvoid setPropertyU(int $index, float $u)
{
_b.position($index * PROPERTIES_PER_ELEMENT);
_b.put($u);
}
publicvoid setPropertyV(int $index, float $v)
{
_b.position($index * PROPERTIES_PER_ELEMENT + 1);
_b.put($v);
}
//
public FloatBuffer buffer()
{
return _b;
}
public UvBufferList clone()
{
_b.position(0);
UvBufferList c = new UvBufferList(_b, size());
return c;
}
}