public void processNode(int nodeSubPart, int nodeTriangleIndex) {
      meshInterface.getLockedReadOnlyVertexIndexBase(data, nodeSubPart);

      // int* gfxbase = (int*)(indexbase+nodeTriangleIndex*indexstride);
      ByteBuffer gfxbase_ptr = data.indexbase;
      int gfxbase_index = (nodeTriangleIndex * data.indexstride);
      assert (data.indicestype == ScalarType.PHY_INTEGER
          || data.indicestype == ScalarType.PHY_SHORT);

      Vector3f meshScaling = meshInterface.getScaling();
      for (int j = 2; j >= 0; j--) {
        int graphicsindex;
        if (data.indicestype == ScalarType.PHY_SHORT) {
          graphicsindex = gfxbase_ptr.getShort(gfxbase_index + j * 2) & 0xFFFF;
        } else {
          graphicsindex = gfxbase_ptr.getInt(gfxbase_index + j * 4);
        }

        // float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
        ByteBuffer graphicsbase_ptr = data.vertexbase;
        int graphicsbase_index = graphicsindex * data.stride;

        triangle[j].set(
            graphicsbase_ptr.getFloat(graphicsbase_index + 4 * 0) * meshScaling.x,
            graphicsbase_ptr.getFloat(graphicsbase_index + 4 * 1) * meshScaling.y,
            graphicsbase_ptr.getFloat(graphicsbase_index + 4 * 2) * meshScaling.z);
      }

      /* Perform ray vs. triangle collision here */
      callback.processTriangle(triangle, nodeSubPart, nodeTriangleIndex);
      meshInterface.unLockReadOnlyVertexBase(nodeSubPart);

      data.unref();
    }
 /** Decode message with raw data */
 public void decode(ByteBuffer dis) throws IOException {
   time_boot_ms = (int) dis.getInt() & 0x00FFFFFFFF;
   roll_rate = (float) dis.getFloat();
   pitch_rate = (float) dis.getFloat();
   yaw_rate = (float) dis.getFloat();
   thrust = (float) dis.getFloat();
 }
Example #3
0
 private Quat4f readQuat() {
   float w = buf.getFloat();
   float x = buf.getFloat();
   float y = buf.getFloat();
   float z = buf.getFloat();
   return new Quat4f(x, y, z, w);
 }
Example #4
0
 public void read(ByteBuffer buffer) {
   size = buffer.getFloat();
   strength = buffer.getFloat();
   phase = buffer.getFloat();
   pad = buffer.getFloat();
   depth = buffer.getShort();
   modification = buffer.getShort();
 }
Example #5
0
 public Vector4f getVec4(ByteBuffer buffer, int index) {
   Vector4f v = new Vector4f();
   v.x = buffer.getFloat(index);
   v.y = buffer.getFloat(index + 4);
   v.z = buffer.getFloat(index + 8);
   v.w = buffer.getFloat(index + 12);
   return v;
 }
  /**
   * Constructor - Creates a new MulticastGroupMessage.
   *
   * @param header Representation of a Header in bytes.
   * @param data Representation of the data portion in bytes.
   */
  public ProjectileMessage(byte[] header, byte[] data) {
    // Create the Message superclass
    super(header, PlayerJoinLength);

    // Wrap the stream of bytes into a buffer
    ByteBuffer buffer = ByteBuffer.wrap(data);
    startPos = new Position(buffer.getFloat(), buffer.getFloat());
    direction = new Position(buffer.getFloat(), buffer.getFloat());
  }
 /** Decode message with raw data */
 public void decode(ByteBuffer dis) throws IOException {
   nav_roll = (float) dis.getFloat();
   nav_pitch = (float) dis.getFloat();
   alt_error = (float) dis.getFloat();
   aspd_error = (float) dis.getFloat();
   xtrack_error = (float) dis.getFloat();
   nav_bearing = (int) dis.getShort();
   target_bearing = (int) dis.getShort();
   wp_dist = (int) dis.getShort() & 0x00FFFF;
 }
Example #8
0
    public dplane_t(ByteBuffer bb) {
      bb.order(ByteOrder.LITTLE_ENDIAN);

      normal[0] = (bb.getFloat());
      normal[1] = (bb.getFloat());
      normal[2] = (bb.getFloat());

      dist = (bb.getFloat());
      type = (bb.getInt());
    }
Example #9
0
 public daliasframe_t(ByteBuffer b) {
   scale[0] = b.getFloat();
   scale[1] = b.getFloat();
   scale[2] = b.getFloat();
   translate[0] = b.getFloat();
   translate[1] = b.getFloat();
   translate[2] = b.getFloat();
   byte[] nameBuf = new byte[16];
   b.get(nameBuf);
   name = new String(nameBuf).trim();
 }
Example #10
0
    public dmodel_t(ByteBuffer bb) {
      bb.order(ByteOrder.LITTLE_ENDIAN);

      for (int j = 0; j < 3; j++) mins[j] = bb.getFloat();

      for (int j = 0; j < 3; j++) maxs[j] = bb.getFloat();

      for (int j = 0; j < 3; j++) origin[j] = bb.getFloat();

      headnode = bb.getInt();
      firstface = bb.getInt();
      numfaces = bb.getInt();
    }
Example #11
0
  private void loadWaveformResources(Context context, GL10 gl) throws IOException {
    m_waveformTexture = GLHelpers.loadTexture(gl, context, R.drawable.waveform);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);

    if (m_waveformVertices == null) {
      ByteBuffer vertices = GLHelpers.allocateFloatBuffer(WAVEFORM_POINTS * 3);
      vertices
          .putFloat(+WAVEFORM_HEAD_WIDTH / 2)
          .putFloat(0)
          .putFloat(0)
          .putFloat(-WAVEFORM_HEAD_WIDTH / 2)
          .putFloat(0)
          .putFloat(0)
          .putFloat(+0.5f)
          .putFloat(0)
          .putFloat(WAVEFORM_HEAD_HEIGHT)
          .putFloat(-0.5f)
          .putFloat(0)
          .putFloat(WAVEFORM_HEAD_HEIGHT)
          .putFloat(+0.5f)
          .putFloat(0)
          .putFloat(1 - WAVEFORM_TAIL_HEIGHT)
          .putFloat(-0.5f)
          .putFloat(0)
          .putFloat(1 - WAVEFORM_TAIL_HEIGHT)
          .putFloat(+WAVEFORM_TAIL_WIDTH / 2)
          .putFloat(0)
          .putFloat(1)
          .putFloat(-WAVEFORM_TAIL_WIDTH / 2)
          .putFloat(0)
          .putFloat(1);

      ByteBuffer texcoords = GLHelpers.allocateFloatBuffer(WAVEFORM_POINTS * 2);
      {
        vertices.position(0);
        for (int i = 0; i != WAVEFORM_POINTS; ++i) {
          float x = vertices.getFloat();
          /*float y=*/ vertices.getFloat();
          float z = vertices.getFloat();
          texcoords.putFloat(-x + 0.5f);
          texcoords.putFloat(z);
        }
      }
      m_waveformVertices = GLBufferObject.createVertices(3, GL10.GL_FLOAT, vertices);
      m_waveformTexcoords = GLBufferObject.createTexcoords(2, GL10.GL_FLOAT, texcoords);
    }
    m_waveformVertices.bind(gl);
    m_waveformTexcoords.bind(gl);
  }
Example #12
0
 public void read(ByteBuffer buffer) {
   next = DNATools.link(DNATools.ptr(buffer), BoidState.class); // get ptr
   prev = DNATools.link(DNATools.ptr(buffer), BoidState.class); // get ptr
   rules.read(buffer);
   conditions.read(buffer);
   actions.read(buffer);
   buffer.get(name);
   id = buffer.getInt();
   flag = buffer.getInt();
   ruleset_type = buffer.getInt();
   rule_fuzziness = buffer.getFloat();
   signal_id = buffer.getInt();
   channels = buffer.getInt();
   volume = buffer.getFloat();
   falloff = buffer.getFloat();
 }
 public float readFloat() throws IOException {
   try {
     return buf.getFloat();
   } catch (BufferUnderflowException e) {
     throw new EOFException();
   }
 }
Example #14
0
 private Object getSingleValue(ByteBuffer buffer) {
   Object v;
   if (type.equals("float")) {
     v = buffer.getFloat();
   } else if (type.equals("double")) {
     v = buffer.getDouble();
   } else if (type.equals("int8_t") || type.equals("bool")) {
     v = (int) buffer.get();
   } else if (type.equals("uint8_t")) {
     v = buffer.get() & 0xFF;
   } else if (type.equals("int16_t")) {
     v = (int) buffer.getShort();
   } else if (type.equals("uint16_t")) {
     v = buffer.getShort() & 0xFFFF;
   } else if (type.equals("int32_t")) {
     v = buffer.getInt();
   } else if (type.equals("uint32_t")) {
     v = buffer.getInt() & 0xFFFFFFFFl;
   } else if (type.equals("int64_t")) {
     v = buffer.getLong();
   } else if (type.equals("uint64_t")) {
     v = buffer.getLong();
   } else if (type.equals("char")) {
     v = buffer.get();
   } else {
     throw new RuntimeException("Unsupported type: " + type);
   }
   return v;
 }
 public static void main(String[] args) {
   ByteBuffer bb = ByteBuffer.allocate(BSIZE);
   // Allocation automatically zeroes the ByteBuffer:
   int i = 0;
   while (i++ < bb.limit()) if (bb.get() != 0) print("nonzero");
   print("i = " + i);
   bb.rewind();
   // Store and read a char array:
   bb.asCharBuffer().put("Howdy!");
   char c;
   while ((c = bb.getChar()) != 0) printnb(c + " ");
   print();
   bb.rewind();
   // Store and read a short:
   bb.asShortBuffer().put((short) 471142);
   print(bb.getShort());
   bb.rewind();
   // Store and read an int:
   bb.asIntBuffer().put(99471142);
   print(bb.getInt());
   bb.rewind();
   // Store and read a long:
   bb.asLongBuffer().put(99471142);
   print(bb.getLong());
   bb.rewind();
   // Store and read a float:
   bb.asFloatBuffer().put(99471142);
   print(bb.getFloat());
   bb.rewind();
   // Store and read a double:
   bb.asDoubleBuffer().put(99471142);
   print(bb.getDouble());
   bb.rewind();
 }
Example #16
0
 private Object getValue(MAVLinkDataType type, int offset) {
   switch (type) {
     case CHAR:
       return payloadBB.get(offset);
     case UINT8:
       return payloadBB.get(offset) & 0xFF;
     case INT8:
       return (int) payloadBB.get(offset);
     case UINT16:
       return payloadBB.getShort(offset) & 0xFFFF;
     case INT16:
       return (int) payloadBB.getShort(offset);
     case UINT32:
       return payloadBB.getInt(offset) & 0xFFFFFFFFl;
     case INT32:
       return payloadBB.getInt(offset);
     case UINT64:
       return payloadBB.getLong(offset);
     case INT64:
       return payloadBB.getLong(offset);
     case FLOAT:
       return payloadBB.getFloat(offset);
     case DOUBLE:
       return payloadBB.getDouble(offset);
     default:
       throw new RuntimeException("Unknown type: " + type);
   }
 }
  protected Float[] readFloatArray(InputStream in) {
    byte[] data = null;

    try {
      int len = (int) readUnsignedVarint(in);

      data = new byte[len * 4];
      if (in.read(data, 0, len * 4) != len * 4) {
        debug("readFloatArray: could not read array");
        return null;
      }

      ByteBuffer bb = ByteBuffer.allocate(4 * len);
      bb.put(data);
      bb.flip();
      Float[] res = new Float[len];
      for (int i = 0; i < len; i++) {

        res[i] = bb.getFloat();
      }
      return res;
    } catch (IOException e) {
      debug("readFloatArray: could not read array");
      e.printStackTrace();
    }
    return null;
  }
Example #18
0
 /**
  * Reads the an object of the given Class from the untagged value contained in the ByteBuffer.
  *
  * @param bb contains the Object
  * @param tag TAG of the Value to be read
  * @return the object
  * @throws JdwpException
  * @throws IOException
  */
 public static Object getUntaggedObj(ByteBuffer bb, byte tag) throws JdwpException, IOException {
   switch (tag) {
     case JdwpConstants.Tag.BYTE:
       return new Byte(bb.get());
     case JdwpConstants.Tag.CHAR:
       return new Character(bb.getChar());
     case JdwpConstants.Tag.FLOAT:
       return new Float(bb.getFloat());
     case JdwpConstants.Tag.DOUBLE:
       return new Double(bb.getDouble());
     case JdwpConstants.Tag.INT:
       return new Integer(bb.getInt());
     case JdwpConstants.Tag.LONG:
       return new Long(bb.getLong());
     case JdwpConstants.Tag.SHORT:
       return new Short(bb.getShort());
     case JdwpConstants.Tag.VOID:
       return new byte[0];
     case JdwpConstants.Tag.BOOLEAN:
       return (bb.get() == 0) ? new Boolean(false) : new Boolean(true);
     case JdwpConstants.Tag.STRING:
       return JdwpString.readString(bb);
     case JdwpConstants.Tag.ARRAY:
     case JdwpConstants.Tag.THREAD:
     case JdwpConstants.Tag.OBJECT:
     case JdwpConstants.Tag.THREAD_GROUP:
     case JdwpConstants.Tag.CLASS_LOADER:
     case JdwpConstants.Tag.CLASS_OBJECT:
       // All these cases are ObjectIds
       ObjectId oid = VMIdManager.getDefault().readObjectId(bb);
       return oid.getObject();
     default:
       throw new NotImplementedException("Tag " + tag + " is not implemented.");
   }
 }
Example #19
0
 public void writeTori(GL4 gl, int toriArrayBuffer, int count) throws IOException {
   try (BufferedWriter writer =
       new BufferedWriter(new FileWriter(new File(debugDir, "tori.txt")))) {
     // write tori
     gl.glBindBuffer(GL_SHADER_STORAGE_BUFFER, toriArrayBuffer);
     ByteBuffer toriArray = gl.glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY);
     for (int i = 0; i < count; i++) {
       Vector4f position = getVec4(toriArray, i * Scene.SIZEOF_TORUS);
       float operation = toriArray.getFloat(i * Scene.SIZEOF_TORUS + 28);
       String op = (operation > 0f) ? "AND" : (operation < 0f) ? "OR " : "ISOLATED";
       Vector4f plane1 = getVec4(toriArray, i * Scene.SIZEOF_TORUS + 48);
       Vector4f plane2 = getVec4(toriArray, i * Scene.SIZEOF_TORUS + 64);
       writer.append(String.format("%4d: ", i));
       writer.append(
           String.format(
               "center: [%f %f %f], R: %f, ", position.x, position.y, position.z, position.w));
       writer.append(String.format("op: %s, ", op));
       writer.append(
           String.format("plane1: [%f %f %f %f], ", plane1.x, plane1.y, plane1.z, plane1.w));
       writer.append(
           String.format("plane2: [%f %f %f %f]", plane2.x, plane2.y, plane2.z, plane2.w));
       writer.newLine();
     }
     gl.glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
   }
 }
Example #20
0
 private List<Texture> texs() throws IOException {
   chunk("TEXS");
   List<Texture> ret = new ArrayList<Texture>();
   while (buf.hasRemaining()) {
     String path = readString();
     int flags = buf.getInt();
     int blend = buf.getInt();
     Vector2f pos = new Vector2f(buf.getFloat(), buf.getFloat());
     Vector2f scale = new Vector2f(buf.getFloat(), buf.getFloat());
     float rot = buf.getFloat();
     ret.add(new Texture(path, flags, blend, pos, scale, rot));
   }
   dump("TEXS([" + Joiner.on(", ").join(ret) + "])");
   popLimit();
   this.textures.addAll(ret);
   return ret;
 }
Example #21
0
 /**
  * Read double from this packet buffer.
  *
  * @return double
  */
 protected final float readF() {
   try {
     return buf.getFloat();
   } catch (Exception e) {
     log.error("Missing F for: " + this);
   }
   return 0;
 }
  @Theory
  public void shouldPutFloatToNativeBuffer(final AtomicBuffer buffer) {
    final ByteBuffer duplicateBuffer = byteBuffer(buffer);

    buffer.putFloat(INDEX, FLOAT_VALUE);

    assertThat(duplicateBuffer.getFloat(INDEX), is(FLOAT_VALUE));
  }
Example #23
0
 // Separa o buffer (variavel byte[] buffer) em 2 buffers, colocando em um buffer os vertices
 // (vertexBuffer) e em outro buffer as cores (colorBuffer).
 private void separateBuffers() {
   if (problemBufferInterleaved) {
     System.gc();
     vertexBuffer = ByteBuffer.allocate(totalPoints * 3 * 4).order(ByteOrder.LITTLE_ENDIAN);
     colorBuffer = ByteBuffer.allocate(totalPoints * 3).order(ByteOrder.LITTLE_ENDIAN);
     vertexBuffer.position(0);
     colorBuffer.position(0);
     for (int i = 0; i < (totalPoints - 1); i++) {
       vertexBuffer.putFloat(buffer.getFloat(i * 15));
       vertexBuffer.putFloat(buffer.getFloat((i * 15) + 4));
       vertexBuffer.putFloat(buffer.getFloat((i * 15) + 8));
       colorBuffer.put(buffer.get((i * 15) + 12));
       colorBuffer.put(buffer.get((i * 15) + 13));
       colorBuffer.put(buffer.get((i * 15) + 14));
     }
   }
 }
Example #24
0
 public float getFloat() {
   float v;
   if (this.awxEndian == EndianByteBuffer.LITTLE_ENDIAN) {
     v = byteBuffer.order(ByteOrder.LITTLE_ENDIAN).getFloat();
   } else {
     v = byteBuffer.getFloat();
   }
   return v;
 }
 @Override
 public Object read(ByteBuffer buff, int tag) {
   if (tag != TYPE_ARRAY) {
     byte[] data;
     int len = tag - TAG_BYTE_ARRAY_0_15;
     data = DataUtils.newBytes(len);
     buff.get(data);
     return data;
   }
   int ct = buff.get();
   Class<?> clazz;
   Object obj;
   if (ct == -1) {
     String componentType = StringDataType.INSTANCE.read(buff);
     try {
       clazz = Class.forName(componentType);
     } catch (Exception e) {
       throw DataUtils.newIllegalStateException("Could not get class {0}", componentType, e);
     }
   } else {
     clazz = COMMON_CLASSES[ct];
   }
   int len = DataUtils.readVarInt(buff);
   try {
     obj = Array.newInstance(clazz, len);
   } catch (Exception e) {
     throw DataUtils.newIllegalStateException(
         "Could not create array of type {0} length {1}", clazz, len, e);
   }
   if (clazz.isPrimitive()) {
     for (int i = 0; i < len; i++) {
       if (clazz == boolean.class) {
         ((boolean[]) obj)[i] = buff.get() == 1;
       } else if (clazz == byte.class) {
         ((byte[]) obj)[i] = buff.get();
       } else if (clazz == char.class) {
         ((char[]) obj)[i] = buff.getChar();
       } else if (clazz == short.class) {
         ((short[]) obj)[i] = buff.getShort();
       } else if (clazz == int.class) {
         ((int[]) obj)[i] = buff.getInt();
       } else if (clazz == float.class) {
         ((float[]) obj)[i] = buff.getFloat();
       } else if (clazz == double.class) {
         ((double[]) obj)[i] = buff.getDouble();
       } else {
         ((long[]) obj)[i] = buff.getLong();
       }
     }
   } else {
     Object[] array = (Object[]) obj;
     for (int i = 0; i < len; i++) {
       array[i] = elementType.read(buff);
     }
   }
   return obj;
 }
Example #26
0
 private Triple<Integer, Integer, Float> anim() throws IOException {
   chunk("ANIM");
   int flags = buf.getInt();
   int frames = buf.getInt();
   float fps = buf.getFloat();
   dump("ANIM(" + flags + ", " + frames + ", " + fps + ")");
   popLimit();
   return Triple.of(flags, frames, fps);
 }
Example #27
0
 private Number fractional() {
   switch (size) {
     case 4:
       return byteBuffer.getFloat();
     case 8:
       return byteBuffer.getDouble();
     default:
       throw new UnsupportedOperationException("invalid bytes size for fractional number");
   }
 }
Example #28
0
  public static FidBlockHeader readBlockHeader(FileChannel channel) throws IOException {
    FidBlockHeader blockHeader = new FidBlockHeader();
    ByteBuffer buffer = ByteBuffer.allocateDirect(FidFileHeader.BLOCK_HEADER_LENGTH);
    channel.read(buffer);
    buffer.rewind();

    blockHeader.scale = buffer.getShort();
    blockHeader.status = buffer.getShort();
    blockHeader.index = buffer.getShort();
    blockHeader.mode = buffer.getShort();
    blockHeader.ctcount = buffer.getInt();
    blockHeader.lpval = buffer.getFloat();
    blockHeader.rpval = buffer.getFloat();
    blockHeader.lvl = buffer.getFloat();
    blockHeader.tlt = buffer.getFloat();
    blockHeader.readStatus(blockHeader.status);

    return blockHeader;
  }
Example #29
0
 private List<Pair<Vertex, Float>> bone() throws IOException {
   chunk("BONE");
   List<Pair<Vertex, Float>> ret = new ArrayList<Pair<Vertex, Float>>();
   while (buf.hasRemaining()) {
     ret.add(Pair.of(getVertex(buf.getInt()), buf.getFloat()));
   }
   dump("BONE(...)");
   popLimit();
   return ret;
 }
 /**
  * Receive as many items as possible from the given byte buffer to this buffer.
  *
  * <p>The <TT>receiveItems()</TT> method must not block the calling thread; if it does, all
  * message I/O in MP will be blocked.
  *
  * @param i Index of first item to receive, in the range 0 .. <TT>length</TT>-1.
  * @param num Maximum number of items to receive.
  * @param buffer Byte buffer.
  * @return Number of items received.
  */
 protected int receiveItems(int i, int num, ByteBuffer buffer) {
   int index = i;
   int off = myArrayOffset + i * myStride;
   int max = Math.min(i + num, myLength);
   while (index < max && buffer.remaining() >= 4) {
     myArray.reduce(off, buffer.getFloat(), myOp);
     ++index;
     off += myStride;
   }
   return index - i;
 }