当前位置: 首页>>代码示例>>Java>>正文


Java BufferUtils.createVector2Buffer方法代码示例

本文整理汇总了Java中com.jme3.util.BufferUtils.createVector2Buffer方法的典型用法代码示例。如果您正苦于以下问题:Java BufferUtils.createVector2Buffer方法的具体用法?Java BufferUtils.createVector2Buffer怎么用?Java BufferUtils.createVector2Buffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jme3.util.BufferUtils的用法示例。


在下文中一共展示了BufferUtils.createVector2Buffer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setGeometryData

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
private void setGeometryData() {
    setMode(Mode.Lines);

    FloatBuffer posBuf = BufferUtils.createVector3Buffer(3);
    FloatBuffer texBuf = BufferUtils.createVector2Buffer(3);

    setBuffer(VertexBuffer.Type.Position, 3, posBuf);
    setBuffer(VertexBuffer.Type.TexCoord, 2, texBuf);

    posBuf.put(-width).put(0).put(0);
    posBuf.put(0).put(height).put(0);
    posBuf.put(width).put(0).put(0);
    
    texBuf.put(-width).put(0);
    texBuf.put(0).put(height);
    texBuf.put(width).put(0);
}
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:18,代码来源:Triangle.java

示例2: setGeometryData

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
private void setGeometryData() {
    // allocate vertices
    int vertCount = (circleSamples + 1) * (radialSamples + 1);
    FloatBuffer fpb = BufferUtils.createVector3Buffer(vertCount);
    setBuffer(Type.Position, 3, fpb);

    // allocate normals if requested
    FloatBuffer fnb = BufferUtils.createVector3Buffer(vertCount);
    setBuffer(Type.Normal, 3, fnb);

    // allocate texture coordinates
    FloatBuffer ftb = BufferUtils.createVector2Buffer(vertCount);
    setBuffer(Type.TexCoord, 2, 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 = FastMath.TWO_PI * circleFraction;
        float cosTheta = FastMath.cos(theta);
        float sinTheta = FastMath.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 = FastMath.TWO_PI * radialFraction;
            float cosPhi = FastMath.cos(phi);
            float sinPhi = FastMath.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);
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:67,代码来源:Torus.java

示例3: initParticleData

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
@Override
public void initParticleData(ParticleEmitter emitter, int numParticles) {
    setMode(Mode.Triangles);

    this.emitter = emitter;

    particlesCopy = new Particle[numParticles];

    // set positions
    FloatBuffer pb = BufferUtils.createVector3Buffer(numParticles * 4);
    VertexBuffer pvb = new VertexBuffer(VertexBuffer.Type.Position);
    pvb.setupData(Usage.Stream, 3, Format.Float, pb);
    setBuffer(pvb);

    // set colors
    ByteBuffer cb = BufferUtils.createByteBuffer(numParticles * 4 * 4);
    VertexBuffer cvb = new VertexBuffer(VertexBuffer.Type.Color);
    cvb.setupData(Usage.Stream, 4, Format.UnsignedByte, cb);
    cvb.setNormalized(true);
    setBuffer(cvb);

    // set texcoords
    VertexBuffer tvb = new VertexBuffer(VertexBuffer.Type.TexCoord);
    FloatBuffer tb = BufferUtils.createVector2Buffer(numParticles * 4);
    
    uniqueTexCoords = false;
    for (int i = 0; i < numParticles; i++){
        tb.put(0f).put(1f);
        tb.put(1f).put(1f);
        tb.put(0f).put(0f);
        tb.put(1f).put(0f);
    }
    tb.flip();
    tvb.setupData(Usage.Static, 2, Format.Float, tb);
    
    setBuffer(tvb);

    // set indices
    ShortBuffer ib = BufferUtils.createShortBuffer(numParticles * 6);
    for (int i = 0; i < numParticles; i++){
        int startIdx = (i * 4);

        // triangle 1
        ib.put((short)(startIdx + 1))
          .put((short)(startIdx + 0))
          .put((short)(startIdx + 2));

        // triangle 2
        ib.put((short)(startIdx + 1))
          .put((short)(startIdx + 2))
          .put((short)(startIdx + 3));
    }
    ib.flip();
    
    VertexBuffer ivb = new VertexBuffer(VertexBuffer.Type.Index);
    ivb.setupData(Usage.Static, 3, Format.UnsignedShort, ib);
    setBuffer(ivb);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:59,代码来源:ParticleTriMesh.java

示例4: setGeometryData

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
/**
 * builds the vertices based on the radius
 */
private void setGeometryData() {
    setMode(Mode.Lines);

    FloatBuffer posBuf = BufferUtils.createVector3Buffer((radialSamples + 1));
    FloatBuffer colBuf = BufferUtils.createFloatBuffer((radialSamples + 1) * 4);
    FloatBuffer texBuf = BufferUtils.createVector2Buffer(radialSamples + 1);
    

    setBuffer(Type.Position, 3, posBuf);
    setBuffer(Type.Color, 4, colBuf);
    setBuffer(Type.TexCoord, 2, texBuf);

    // generate geometry
    float fInvRS = 1.0f / radialSamples;

    // Generate points on the unit circle to be used in computing the mesh
    // points on a sphere slice.
    float[] afSin = new float[(radialSamples + 1)];
    float[] afCos = new float[(radialSamples + 1)];
    for (int iR = 0; iR < radialSamples; iR++) {
        float fAngle = FastMath.TWO_PI * fInvRS * iR;
        afCos[iR] = FastMath.cos(fAngle);
        afSin[iR] = FastMath.sin(fAngle);
    }
    afSin[radialSamples] = afSin[0];
    afCos[radialSamples] = afCos[0];

    for (int iR = 0; iR <= radialSamples; iR++) {
        posBuf.put(afCos[iR])
                .put(afSin[iR])
                .put(0);
        colBuf.put(ColorRGBA.Orange.r)
                .put(ColorRGBA.Orange.g)
                .put(ColorRGBA.Orange.b)
                .put(ColorRGBA.Orange.a);
        texBuf.put(iR % 2f)
                .put(iR % 2f);

    }

    updateBound();
    setStatic();
}
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:47,代码来源:ProbeRadiusShape.java

示例5: setGeometryData

import com.jme3.util.BufferUtils; //导入方法依赖的package包/类
/**
 * builds the vertices based on the radius
 */
private void setGeometryData() {
    setMode(Mode.Lines);

    FloatBuffer posBuf = BufferUtils.createVector3Buffer((radialSamples + 1));
    FloatBuffer colBuf = BufferUtils.createFloatBuffer((radialSamples + 1) * 4);
    FloatBuffer texBuf = BufferUtils.createVector2Buffer(radialSamples + 1);

    setBuffer(Type.Position, 3, posBuf);
    setBuffer(Type.Color, 4, colBuf);
    setBuffer(Type.TexCoord, 2, texBuf);

    // generate geometry
    float fInvRS = 1.0f / radialSamples;

    // Generate points on the unit circle to be used in computing the mesh
    // points on a sphere slice.
    float[] afSin = new float[(radialSamples + 1)];
    float[] afCos = new float[(radialSamples + 1)];
    for (int iR = 0; iR < radialSamples; iR++) {
        float fAngle = FastMath.TWO_PI * fInvRS * iR;
        afCos[iR] = FastMath.cos(fAngle);
        afSin[iR] = FastMath.sin(fAngle);
    }
    afSin[radialSamples] = afSin[0];
    afCos[radialSamples] = afCos[0];

    for (int iR = 0; iR <= radialSamples; iR++) {
        posBuf.put(afCos[iR])
                .put(afSin[iR])
                .put(0);
        colBuf.put(ColorRGBA.Orange.r)
                .put(ColorRGBA.Orange.g)
                .put(ColorRGBA.Orange.b)
                .put(ColorRGBA.Orange.a);
        texBuf.put(iR % 2f)
                .put(iR % 2f);

    }

    updateBound();
    setStatic();
}
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:46,代码来源:RadiusShape.java


注:本文中的com.jme3.util.BufferUtils.createVector2Buffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。