use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.
the class StripBox method duUpdateGeometryVertices.
protected void duUpdateGeometryVertices() {
FloatBuffer fpb = BufferUtils.createVector3Buffer(8 * 3);
Vector3f[] v = computeVertices();
fpb.put(new float[] { v[0].x, v[0].y, v[0].z, v[1].x, v[1].y, v[1].z, v[2].x, v[2].y, v[2].z, v[3].x, v[3].y, v[3].z, v[4].x, v[4].y, v[4].z, v[5].x, v[5].y, v[5].z, v[6].x, v[6].y, v[6].z, v[7].x, v[7].y, v[7].z });
setBuffer(Type.Position, 3, fpb);
setMode(Mode.TriangleStrip);
updateBound();
}
use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.
the class Arrow method setArrowExtent.
/**
* Sets the arrow's extent.
* This will modify the buffers on the mesh.
*
* @param extent the arrow's extent.
*/
public void setArrowExtent(Vector3f extent) {
float len = extent.length();
// Vector3f dir = extent.normalize();
tempQuat.lookAt(extent, Vector3f.UNIT_Y);
tempQuat.normalizeLocal();
VertexBuffer pvb = getBuffer(Type.Position);
FloatBuffer buffer = (FloatBuffer) pvb.getData();
buffer.rewind();
for (int i = 0; i < positions.length; i += 3) {
Vector3f vec = tempVec.set(positions[i], positions[i + 1], positions[i + 2]);
vec.multLocal(len);
tempQuat.mult(vec, vec);
buffer.put(vec.x);
buffer.put(vec.y);
buffer.put(vec.z);
}
pvb.updateData(buffer);
updateBound();
updateCounts();
}
use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.
the class WireFrustum method update.
public void update(Vector3f[] points) {
VertexBuffer vb = getBuffer(Type.Position);
if (vb == null) {
setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(points));
return;
}
FloatBuffer b = BufferUtils.createFloatBuffer(points);
FloatBuffer a = (FloatBuffer) vb.getData();
b.rewind();
a.rewind();
a.put(b);
a.rewind();
vb.updateData(a);
updateBound();
}
use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.
the class WireSphere method updatePositions.
public void updatePositions(float radius) {
VertexBuffer pvb = getBuffer(Type.Position);
FloatBuffer pb;
if (pvb == null) {
pvb = new VertexBuffer(Type.Position);
pb = BufferUtils.createVector3Buffer(samples * 2 + samples * zSamples);
pvb.setupData(Usage.Dynamic, 3, Format.Float, pb);
setBuffer(pvb);
} else {
pb = (FloatBuffer) pvb.getData();
}
pb.rewind();
// X axis
// pb.put(radius).put(0).put(0);
// pb.put(-radius).put(0).put(0);
//
// // Y axis
// pb.put(0).put(radius).put(0);
// pb.put(0).put(-radius).put(0);
//
// // Z axis
// pb.put(0).put(0).put(radius);
// pb.put(0).put(0).put(-radius);
float rate = FastMath.TWO_PI / (float) samples;
float angle = 0;
for (int i = 0; i < samples; i++) {
float x = radius * FastMath.cos(angle);
float y = radius * FastMath.sin(angle);
pb.put(x).put(y).put(0);
angle += rate;
}
angle = 0;
for (int i = 0; i < samples; i++) {
float x = radius * FastMath.cos(angle);
float y = radius * FastMath.sin(angle);
pb.put(0).put(x).put(y);
angle += rate;
}
float zRate = (radius * 2) / (float) (zSamples);
float zHeight = -radius + (zRate / 2f);
float rb = 1f / zSamples;
float b = rb / 2f;
for (int k = 0; k < zSamples; k++) {
angle = 0;
float scale = FastMath.sin(b * FastMath.PI);
for (int i = 0; i < samples; i++) {
float x = radius * FastMath.cos(angle);
float y = radius * FastMath.sin(angle);
pb.put(x * scale).put(zHeight).put(y * scale);
angle += rate;
}
zHeight += zRate;
b += rb;
}
}
use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.
the class InstancedGeometry method updateInstances.
public void updateInstances() {
FloatBuffer fb = (FloatBuffer) transformInstanceData.getData();
fb.limit(fb.capacity());
fb.position(0);
TempVars vars = TempVars.get();
{
float[] temp = vars.matrixWrite;
for (int i = 0; i < firstUnusedIndex; i++) {
Geometry geom = geometries[i];
if (geom == null) {
geom = geometries[firstUnusedIndex - 1];
if (geom == null) {
throw new AssertionError();
}
swap(i, firstUnusedIndex - 1);
while (geometries[firstUnusedIndex - 1] == null) {
firstUnusedIndex--;
}
}
Matrix4f worldMatrix = geom.getWorldMatrix();
updateInstance(worldMatrix, temp, 0, vars.tempMat3, vars.quat1);
fb.put(temp);
}
}
vars.release();
fb.flip();
if (fb.limit() / INSTANCE_SIZE != firstUnusedIndex) {
throw new AssertionError();
}
transformInstanceData.updateData(fb);
}
Aggregations