本文整理汇总了Java中java.nio.FloatBuffer.put方法的典型用法代码示例。如果您正苦于以下问题:Java FloatBuffer.put方法的具体用法?Java FloatBuffer.put怎么用?Java FloatBuffer.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.FloatBuffer
的用法示例。
在下文中一共展示了FloatBuffer.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fillFloatBuffer
import java.nio.FloatBuffer; //导入方法依赖的package包/类
/**
* <code>fillFloatBuffer</code> fills a FloatBuffer object with the matrix
* data.
*
* @param fb
* the buffer to fill, starting at current position. Must have
* room for 16 more floats.
* @param columnMajor
* if true, this buffer should be filled with column major data,
* otherwise it will be filled row major.
* @return matrix data as a FloatBuffer. (position is advanced by 16 and any
* limit set is not changed).
*/
public FloatBuffer fillFloatBuffer(FloatBuffer fb, boolean columnMajor) {
// if (columnMajor) {
// fb.put(m00).put(m10).put(m20).put(m30);
// fb.put(m01).put(m11).put(m21).put(m31);
// fb.put(m02).put(m12).put(m22).put(m32);
// fb.put(m03).put(m13).put(m23).put(m33);
// } else {
// fb.put(m00).put(m01).put(m02).put(m03);
// fb.put(m10).put(m11).put(m12).put(m13);
// fb.put(m20).put(m21).put(m22).put(m23);
// fb.put(m30).put(m31).put(m32).put(m33);
// }
TempVars vars = TempVars.get();
fillFloatArray(vars.matrixWrite, columnMajor);
fb.put(vars.matrixWrite, 0, 16);
vars.release();
fb.rewind();
return fb;
}
示例2: clone
import java.nio.FloatBuffer; //导入方法依赖的package包/类
/**
* Creates a new FloatBuffer with the same contents as the given
* FloatBuffer. The new FloatBuffer is seperate from the old one and changes
* are not reflected across. If you want to reflect changes, consider using
* Buffer.duplicate().
*
* @param buf
* the FloatBuffer to copy
* @return the copy
*/
public static FloatBuffer clone(FloatBuffer buf) {
if (buf == null) {
return null;
}
buf.rewind();
FloatBuffer copy;
if (isDirect(buf)) {
copy = createFloatBuffer(buf.limit());
} else {
copy = FloatBuffer.allocate(buf.limit());
}
copy.put(buf);
return copy;
}
示例3: CreateFlippedBuffer
import java.nio.FloatBuffer; //导入方法依赖的package包/类
public static FloatBuffer CreateFlippedBuffer(Vertex[] vertices)
{
FloatBuffer buffer = CreateFloatBuffer(vertices.length * Vertex.SIZE);
for(int i = 0; i < vertices.length; i++)
{
buffer.put(vertices[i].GetPos().GetX());
buffer.put(vertices[i].GetPos().GetY());
buffer.put(vertices[i].GetPos().GetZ());
buffer.put(vertices[i].GetTexCoord().GetX());
buffer.put(vertices[i].GetTexCoord().GetY());
buffer.put(vertices[i].GetNormal().GetX());
buffer.put(vertices[i].GetNormal().GetY());
buffer.put(vertices[i].GetNormal().GetZ());
buffer.put(vertices[i].GetTangent().GetX());
buffer.put(vertices[i].GetTangent().GetY());
buffer.put(vertices[i].GetTangent().GetZ());
}
buffer.flip();
return buffer;
}
示例4: floatBufferUtil
import java.nio.FloatBuffer; //导入方法依赖的package包/类
public FloatBuffer floatBufferUtil(float[] arr) {
// 初始化ByteBuffer,长度为arr数组的长度*4,因为一个int占4个字节
ByteBuffer qbb = ByteBuffer.allocateDirect(arr.length * 4);
// 数组排列用nativeOrder
qbb.order(ByteOrder.nativeOrder());
FloatBuffer mBuffer = qbb.asFloatBuffer();
mBuffer.put(arr);
mBuffer.position(0);
return mBuffer;
}
示例5: createFloatBuffer
import java.nio.FloatBuffer; //导入方法依赖的package包/类
/**
* Allocates a direct float buffer, and populates it with the float array data.
*/
public static FloatBuffer createFloatBuffer(float[] coords) {
// Allocate a direct ByteBuffer, using 4 bytes per float, and copy coords into it.
ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * SIZEOF_FLOAT);
bb.order(ByteOrder.nativeOrder());
FloatBuffer fb = bb.asFloatBuffer();
fb.put(coords);
fb.position(0);
return fb;
}
示例6: testGetFloatInt
import java.nio.FloatBuffer; //导入方法依赖的package包/类
@Test
public void testGetFloatInt() {
ByteBuffer bb = ByteBuffer.allocate(20);
FloatBuffer fb = bb.asFloatBuffer();
fb.put(1.1f);
fb.put(2.2f);
fb.put(3.3f);
fb.put(4.4f);
fb.put(5.5f);
byte[] bytes = bb.array();
ByteSource bs = createByteSource(bytes);
bs.position(3);
float f = bs.getFloat(0);
assertEquals(1.1f, f, 0.0001);
assertEquals(3, bs.position());
f = bs.getFloat(4);
assertEquals(2.2f, f, 0.0001);
assertEquals(3, bs.position());
f = bs.getFloat(4 * 4);
assertEquals(5.5f, f, 0.0001);
assertEquals(3, bs.position());
try {
bs.getFloat((4 * 4) + 1);
fail("expected IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException expected) {
}
}
示例7: createSquareVtx
import java.nio.FloatBuffer; //导入方法依赖的package包/类
public static FloatBuffer createSquareVtx() {
final float vtx[] = {
// XYZ, UV
-1f, 1f, 0f, 0f, 1f,
-1f, -1f, 0f, 0f, 0f,
1f, 1f, 0f, 1f, 1f,
1f, -1f, 0f, 1f, 0f,
};
ByteBuffer bb = ByteBuffer.allocateDirect(4 * vtx.length);
bb.order(ByteOrder.nativeOrder());
FloatBuffer fb = bb.asFloatBuffer();
fb.put(vtx);
fb.position(0);
return fb;
}
示例8: quatToGlMatrix
import java.nio.FloatBuffer; //导入方法依赖的package包/类
public static FloatBuffer quatToGlMatrix(FloatBuffer p_187418_0_, Quaternion p_187418_1_)
{
p_187418_0_.clear();
float f = p_187418_1_.x * p_187418_1_.x;
float f1 = p_187418_1_.x * p_187418_1_.y;
float f2 = p_187418_1_.x * p_187418_1_.z;
float f3 = p_187418_1_.x * p_187418_1_.w;
float f4 = p_187418_1_.y * p_187418_1_.y;
float f5 = p_187418_1_.y * p_187418_1_.z;
float f6 = p_187418_1_.y * p_187418_1_.w;
float f7 = p_187418_1_.z * p_187418_1_.z;
float f8 = p_187418_1_.z * p_187418_1_.w;
p_187418_0_.put(1.0F - 2.0F * (f4 + f7));
p_187418_0_.put(2.0F * (f1 + f8));
p_187418_0_.put(2.0F * (f2 - f6));
p_187418_0_.put(0.0F);
p_187418_0_.put(2.0F * (f1 - f8));
p_187418_0_.put(1.0F - 2.0F * (f + f7));
p_187418_0_.put(2.0F * (f5 + f3));
p_187418_0_.put(0.0F);
p_187418_0_.put(2.0F * (f2 + f6));
p_187418_0_.put(2.0F * (f5 - f3));
p_187418_0_.put(1.0F - 2.0F * (f + f4));
p_187418_0_.put(0.0F);
p_187418_0_.put(0.0F);
p_187418_0_.put(0.0F);
p_187418_0_.put(0.0F);
p_187418_0_.put(1.0F);
p_187418_0_.rewind();
return p_187418_0_;
}
示例9: renderTexture
import java.nio.FloatBuffer; //导入方法依赖的package包/类
public int renderTexture(int textureId){
if(mGpuImageFilter == null){
mGpuImageFilter = new GPUImageFilter(null);
mGpuImageFilter.init();
}
int vertexNum = 6;
float[] vertexCoordinate = {1.0f, -1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, 0.0f,
-1.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f};
ByteBuffer bbVertices = ByteBuffer.allocateDirect(vertexNum * 3 * 4);
bbVertices.order(ByteOrder.nativeOrder());
FloatBuffer vertexBuf = bbVertices.asFloatBuffer();
vertexBuf.put(vertexCoordinate);
vertexBuf.position(0);
float[] textureCoordinate1 = {1.0f, 1.0f,
1.0f, 0.0f,
0.0f, 0.0f,
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f};
ByteBuffer bbColors1 = ByteBuffer.allocateDirect(vertexNum * 2 * 4);
bbColors1.order(ByteOrder.nativeOrder());
FloatBuffer textureCoordinateBuf = bbColors1.asFloatBuffer();
textureCoordinateBuf.put(textureCoordinate1);
textureCoordinateBuf.position(0);
mGpuImageFilter.draw(textureId,vertexBuf,textureCoordinateBuf);
return 1;
}
示例10: createFloatBuffer
import java.nio.FloatBuffer; //导入方法依赖的package包/类
public static FloatBuffer createFloatBuffer(float[] coords) {
// Allocate a direct ByteBuffer, using 4 bytes per float, and copy coords into it.
ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * 4);
bb.order(ByteOrder.nativeOrder());
FloatBuffer fb = bb.asFloatBuffer();
fb.put(coords);
fb.position(0);
return fb;
}
示例11: createFloatBuffer
import java.nio.FloatBuffer; //导入方法依赖的package包/类
public static FloatBuffer createFloatBuffer(float[] coords) {
// Allocate a direct ByteBuffer, using 4 bytes per float, and copy coords into it.
ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * 4);
bb.order(ByteOrder.nativeOrder());
FloatBuffer fb = bb.asFloatBuffer();
fb.put(coords);
fb.position(0);
return fb;
}
示例12: getTexCoordArray
import java.nio.FloatBuffer; //导入方法依赖的package包/类
/**
* Returns the array of texture coordinates. The first time this is called, we generate
* a modified version of the array from the parent class.
* <p>
* To avoid allocations, this returns internal state. The caller must not modify it.
*/
@Override
public FloatBuffer getTexCoordArray() {
if (mRecalculate) {
//Log.v(TAG, "Scaling to " + mScale);
FloatBuffer parentBuf = super.getTexCoordArray();
int count = parentBuf.capacity();
if (mTweakedTexCoordArray == null) {
ByteBuffer bb = ByteBuffer.allocateDirect(count * SIZEOF_FLOAT);
bb.order(ByteOrder.nativeOrder());
mTweakedTexCoordArray = bb.asFloatBuffer();
}
// Texture coordinates range from 0.0 to 1.0, inclusive. We do a simple scale
// here, but we could get much fancier if we wanted to (say) zoom in and pan
// around.
FloatBuffer fb = mTweakedTexCoordArray;
float scale = mScale;
for (int i = 0; i < count; i++) {
float fl = parentBuf.get(i);
fl = ((fl - 0.5f) * scale) + 0.5f;
fb.put(i, fl);
}
mRecalculate = false;
}
return mTweakedTexCoordArray;
}
示例13: getAsFloatBuffer
import java.nio.FloatBuffer; //导入方法依赖的package包/类
public FloatBuffer getAsFloatBuffer() {
FloatBuffer buffer = BufferUtils.createFloatBuffer(4);
buffer.put(new float[] { col.x, col.y, col.z, a });
buffer.flip();
return buffer;
}
示例14: storeDataInBuffer
import java.nio.FloatBuffer; //导入方法依赖的package包/类
public static void storeDataInBuffer(FloatBuffer buffer, int vertexCount, float[]... data) {
float[] interleavedData = interleaveFloatData(vertexCount, data);
buffer.clear();
buffer.put(interleavedData);
buffer.flip();
}
示例15: setGeometryData
import java.nio.FloatBuffer; //导入方法依赖的package包/类
private void setGeometryData() {
// allocate vertices
int vertCount = (circleSamples + 1) * (radialSamples + 1);
//position
FloatBuffer fpb = BufferUtils.createVector3Buffer(vertCount);
setPosition(fpb);
// allocate normals if requested
FloatBuffer fnb = BufferUtils.createVector3Buffer(vertCount);
setNormal(fnb);
// allocate texture coordinates
FloatBuffer ftb = BufferUtils.createVector2Buffer(vertCount);
setTexture(ftb);
// generate geometry
float inverseCircleSamples = 1.0f / circleSamples;
float inverseRadialSamples = 1.0f / radialSamples;
int i = 0;
// generate the cylinder itself
Vector3f radialAxis = new Vector3f(), torusMiddle = new Vector3f(), tempNormal = new Vector3f();
for (int circleCount = 0; circleCount < circleSamples; circleCount++) {
// compute center point on torus circle at specified angle
float circleFraction = circleCount * inverseCircleSamples;
float theta = M.TWO_PI * circleFraction;
float cosTheta = M.cos(theta);
float sinTheta = M.sin(theta);
radialAxis.set(cosTheta, sinTheta, 0);
radialAxis.mult(outerRadius, torusMiddle);
// compute slice vertices with duplication at end point
int iSave = i;
for (int radialCount = 0; radialCount < radialSamples; radialCount++) {
float radialFraction = radialCount * inverseRadialSamples;
// in [0,1)
float phi = M.TWO_PI * radialFraction;
float cosPhi = M.cos(phi);
float sinPhi = M.sin(phi);
tempNormal.set(radialAxis).multLocal(cosPhi);
tempNormal.z += sinPhi;
fnb.put(tempNormal.x).put(tempNormal.y).put(
tempNormal.z);
tempNormal.multLocal(innerRadius).addLocal(torusMiddle);
fpb.put(tempNormal.x).put(tempNormal.y).put(
tempNormal.z);
ftb.put(radialFraction).put(circleFraction);
i++;
}
BufferUtils.copyInternalVector3(fpb, iSave, i);
BufferUtils.copyInternalVector3(fnb, iSave, i);
ftb.put(1.0f).put(circleFraction);
i++;
}
// duplicate the cylinder ends to form a torus
for (int iR = 0; iR <= radialSamples; iR++, i++) {
BufferUtils.copyInternalVector3(fpb, iR, i);
BufferUtils.copyInternalVector3(fnb, iR, i);
BufferUtils.copyInternalVector2(ftb, iR, i);
ftb.put(i * 2 + 1, 1.0f);
}
}