本文整理匯總了Java中java.nio.FloatBuffer.capacity方法的典型用法代碼示例。如果您正苦於以下問題:Java FloatBuffer.capacity方法的具體用法?Java FloatBuffer.capacity怎麽用?Java FloatBuffer.capacity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.FloatBuffer
的用法示例。
在下文中一共展示了FloatBuffer.capacity方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setupJoystick
import java.nio.FloatBuffer; //導入方法依賴的package包/類
/** Setup a specific joystick that is connected
*
* @param joy the joystick id to setup
*/
public static void setupJoystick(int joy){
//make sure the joystick is connected
if(!GLFW.glfwJoystickPresent(joy))
return;
//get the name of the joystick and normalize the casing
String name = GLFW.glfwGetJoystickName(joy).toLowerCase();
JoystickType type = JoystickType.OTHER;
//check the name for the type
if(name.contains("xbox"))
type = JoystickType.XBOX360;
else if(name.contains("playstation"))
type = JoystickType.PLAYSTATION;
//setup the axis size for the controller
FloatBuffer buf = GLFW.glfwGetJoystickAxes(joy);
int axisCount = buf.capacity();
//setup the button size for the controller
ByteBuffer bbuf = GLFW.glfwGetJoystickButtons(joy);
int buttonCount = bbuf.capacity();
//add the controller to the static array for usage
connected.add(new Joystick(joy, type, axisCount, buttonCount));
}
示例2: compile
import java.nio.FloatBuffer; //導入方法依賴的package包/類
/**
* Compiles a FloatBuffer and binds it to OpenGL for rendering.
*
* @param buffer a FloatBuffer populated with VBO vertices
* @return The original VBO
*/
public VBO compile(FloatBuffer buffer) {
this.size = buffer.capacity();
FEATHER.bindBuffer(this.id);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
FEATHER.bindBuffer(0);
return this;
}
示例3: getFloat
import java.nio.FloatBuffer; //導入方法依賴的package包/類
public float[] getFloat(Attribute attrib) {
int pname = getAttrib(attrib);
FloatBuffer buf = ByteBuffer.allocateDirect(16).order(ByteOrder.nativeOrder()).asFloatBuffer();
gl.glGetFloatv(pname, buf);
float[] result = new float[buf.capacity()];
for(int i = 0; i < result.length; i++)
result[i] = buf.get();
return result;
}
示例4: store
import java.nio.FloatBuffer; //導入方法依賴的package包/類
/**
* Stores the specified data into the VAO with a VBO
* @param data
* @param dimensions
*/
private void store(FloatBuffer data, int[] dimensions) {
bind();
// Generate a VBO to hold the data
int vboid = GL15.glGenBuffers();
// Bind the VBO
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboid);
// Store the data in the VBO
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, data, GL15.GL_STATIC_DRAW);
// Get the stride of the data in bytes
int stride = 0;
if(dimensions.length > 1)
for(int i = 0; i < dimensions.length; i++) {
stride += dimensions[i] * 4;
}
// Determine the number of vertices assuming attribute 0 is position
vertexCount = data.capacity() / dimensions[0];
// Setup data in VBO
int offset = 0;
for(int i = 0; i < dimensions.length; i++) {
GL20.glVertexAttribPointer(i, dimensions[i], GL11.GL_FLOAT, false, stride, offset);
offset += dimensions[i] * 4;
}
// Add the vbo to the list of buffer objects for memory management
addBufferObject(vboid);
unbind();
}
示例5: bufferToFloatArray
import java.nio.FloatBuffer; //導入方法依賴的package包/類
private static float[] bufferToFloatArray(ByteBuffer buffer) {
buffer.order(ByteOrder.nativeOrder());
FloatBuffer floats = buffer.asFloatBuffer();
if (floats.hasArray()) {
return floats.array();
} else {
float[] resultArray = new float[floats.capacity()];
floats.get(resultArray);
return resultArray;
}
}
示例6: 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;
}
示例7: update
import java.nio.FloatBuffer; //導入方法依賴的package包/類
/**
* Update the values of the joystick
*/
public void update(){
this.buttonsLastFrame = this.buttons.clone();
this.axesLastFrame = this.axes.clone();
FloatBuffer abuf = GLFW.glfwGetJoystickAxes(this.id);
ByteBuffer bbuf = GLFW.glfwGetJoystickButtons(this.id);
for(int i=0;i<abuf.capacity();i++)
this.axes[i] = abuf.get(i);
for(int i=0;i<bbuf.capacity();i++)
this.buttons[i] = bbuf.get(i);
}
示例8: update
import java.nio.FloatBuffer; //導入方法依賴的package包/類
public void update(){
float mouseX = Input.getMousePosition().x;
float mouseY = Input.getMousePosition().y;
float dMouseX = Input.getDMouse().x;
float dMouseY = Input.getDMouse().y;
if(mouseX >= this.x && mouseX <= this.x + this.width && mouseY >= this.y && mouseY <= this.y + this.height){
for(int i = 0;i < Input.NBRE_BUTTON;i++){
if(Input.isButton(i)){
action.clicked(mouseX,mouseY,i,Input.getButtonState(i));
}
}
if(mouseInGUI == 0){
mouseInGUI = 1;
action.enter(mouseX,mouseY);
}else if(mouseInGUI == 1 || mouseInGUI == 2){
mouseInGUI = 2;
action.hover(mouseX,mouseY);
if(dMouseX != 0 || dMouseY != 0)action.move(mouseX,mouseY);
}
}else{
if(mouseInGUI == 1 || mouseInGUI == 2){
mouseInGUI = 0;
action.leave(mouseX,mouseY);
}
}
for(int id : Input.getJoysticks()){
try{
FloatBuffer axis = Input.getJoysticksAxis(id);
for(int i = 0;i < axis.capacity();i++){
action.joystickAxisState(id, i, axis.get(i));
}
ByteBuffer buttons = Input.getJoysticksButton(id);
for(int i = 0;i < buttons.capacity();i++){
action.joystickButtonState(id, i, buttons.get(i));
}
}catch(Exception e){}
}
}
示例9: RangeFloatDicManager
import java.nio.FloatBuffer; //導入方法依賴的package包/類
public RangeFloatDicManager( final FloatBuffer dicBuffer ){
this.dicBuffer = dicBuffer;
dicLength = dicBuffer.capacity();
}