Java Code Examples for com.jme3.math.FastMath#TWO_PI

The following examples show how to use com.jme3.math.FastMath#TWO_PI . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSimpleBumps.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf){
    angle += tpf * 0.25f;
    angle %= FastMath.TWO_PI;

    pl.setPosition(new Vector3f(FastMath.cos(angle) * 4f, 0.5f, FastMath.sin(angle) * 4f));
    lightMdl.setLocalTranslation(pl.getPosition());
}
 
Example 2
Source File: TestSpotLight.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf) {
    super.simpleUpdate(tpf);
    angle += tpf;
    angle %= FastMath.TWO_PI;

    spot.setPosition(new Vector3f(FastMath.cos(angle) * 30f, 34.013165f, FastMath.sin(angle) * 30f));
    lightMdl.setLocalTranslation(spot.getPosition());
    spot.setDirection(lightTarget.subtract(spot.getPosition()));     
}
 
Example 3
Source File: ParticleEmitter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Particle emitParticle(Vector3f min, Vector3f max) {
    int idx = lastUsed + 1;
    if (idx >= particles.length) {
        return null;
    }

    Particle p = particles[idx];
    if (selectRandomImage) {
        p.imageIndex = FastMath.nextRandomInt(0, imagesY - 1) * imagesX + FastMath.nextRandomInt(0, imagesX - 1);
    }

    p.startlife = lowLife + FastMath.nextRandomFloat() * (highLife - lowLife);
    p.life = p.startlife;
    p.color.set(startColor);
    p.size = startSize;
    //shape.getRandomPoint(p.position);
    particleInfluencer.influenceParticle(p, shape);
    if (worldSpace) {
        worldTransform.transformVector(p.position, p.position);
        worldTransform.getRotation().mult(p.velocity, p.velocity);
        // TODO: Make scale relevant somehow??
    }
    if (randomAngle) {
        p.angle = FastMath.nextRandomFloat() * FastMath.TWO_PI;
    }
    if (rotateSpeed != 0) {
        p.rotateSpeed = rotateSpeed * (0.2f + (FastMath.nextRandomFloat() * 2f - 1f) * .8f);
    }

    temp.set(p.position).addLocal(p.size, p.size, p.size);
    max.maxLocal(temp);
    temp.set(p.position).subtractLocal(p.size, p.size, p.size);
    min.minLocal(temp);

    ++lastUsed;
    firstUnUsed = idx + 1;
    return p;
}
 
Example 4
Source File: TestOgreLoading.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf) {
    angle1 += tpf * 0.25f;
    angle1 %= FastMath.TWO_PI;

    angle2 += tpf * 0.50f;
    angle2 %= FastMath.TWO_PI;

    pl.setPosition(new Vector3f(FastMath.cos(angle1) * 4f, 0.5f, FastMath.sin(angle1) * 4f));
    p2.setPosition(new Vector3f(FastMath.cos(angle2) * 4f, 0.5f, FastMath.sin(angle2) * 4f));
    lightMdl.setLocalTranslation(pl.getPosition());
    lightMd2.setLocalTranslation(p2.getPosition());
}
 
Example 5
Source File: TestNormalMapping.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf){
    angle += tpf * 0.25f;
    angle %= FastMath.TWO_PI;

    pl.setPosition(new Vector3f(FastMath.cos(angle) * 4f, 0.5f, FastMath.sin(angle) * 4f));
    lightMdl.setLocalTranslation(pl.getPosition());
}
 
Example 6
Source File: TextureGeneratorWood.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public float execute(float x) {
    int n = (int) (x * FastMath.INV_TWO_PI);
    x -= n * FastMath.TWO_PI;
    if (x < 0.0f) {
        x += FastMath.TWO_PI;
    }
    return x * FastMath.INV_TWO_PI;
}
 
Example 7
Source File: TestMovingParticle.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf) {
    angle += tpf;
    angle %= FastMath.TWO_PI;
    float x = FastMath.cos(angle) * 2;
    float y = FastMath.sin(angle) * 2;
    emit.setLocalTranslation(x, 0, y);
}
 
Example 8
Source File: TestNormalMapping.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf){
    angle += tpf * 0.25f;
    angle %= FastMath.TWO_PI;

    pl.setPosition(new Vector3f(FastMath.cos(angle) * 4f, 0.5f, FastMath.sin(angle) * 4f));
    lightMdl.setLocalTranslation(pl.getPosition());
}
 
Example 9
Source File: TestMonkeyHead.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf){
    angle += tpf * 0.25f;
    angle %= FastMath.TWO_PI;

    pl.setPosition(new Vector3f(FastMath.cos(angle) * 6f, 3f, FastMath.sin(angle) * 6f));
    lightMdl.setLocalTranslation(pl.getPosition());
}
 
Example 10
Source File: TestBumpModel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf){
    angle += tpf * 0.25f;
    angle %= FastMath.TWO_PI;

    pl.setPosition(new Vector3f(FastMath.cos(angle) * 6f, 3f, FastMath.sin(angle) * 6f));
    lightMdl.setLocalTranslation(pl.getPosition());
}
 
Example 11
Source File: TestOgreLoading.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf) {
    angle1 += tpf * 0.25f;
    angle1 %= FastMath.TWO_PI;

    angle2 += tpf * 0.50f;
    angle2 %= FastMath.TWO_PI;

    pl.setPosition(new Vector3f(FastMath.cos(angle1) * 4f, 0.5f, FastMath.sin(angle1) * 4f));
    p2.setPosition(new Vector3f(FastMath.cos(angle2) * 4f, 0.5f, FastMath.sin(angle2) * 4f));
    lightMdl.setLocalTranslation(pl.getPosition());
    lightMd2.setLocalTranslation(p2.getPosition());
}
 
Example 12
Source File: TestMonkeyHead.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf){
    angle += tpf * 0.25f;
    angle %= FastMath.TWO_PI;

    pl.setPosition(new Vector3f(FastMath.cos(angle) * 6f, 3f, FastMath.sin(angle) * 6f));
    lightMdl.setLocalTranslation(pl.getPosition());
}
 
Example 13
Source File: TestSimpleBumps.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf){
    angle += tpf * 0.25f;
    angle %= FastMath.TWO_PI;

    pl.setPosition(new Vector3f(FastMath.cos(angle) * 4f, 0.5f, FastMath.sin(angle) * 4f));
    lightMdl.setLocalTranslation(pl.getPosition());
}
 
Example 14
Source File: TestDoppler.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf){
    //float x  = (float) (Math.cos(angle) * xDist);
    float dx = (float)  Math.sin(angle) * xDist; 
    
    //float z  = (float) (Math.sin(angle) * zDist);
    float dz = (float)(-Math.cos(angle) * zDist);
    
    x += dx * tpf * 0.05f;
    z += dz * tpf * 0.05f;
    
    angle += tpf * rate;
    
    if (angle > FastMath.TWO_PI){
        angle = FastMath.TWO_PI;
        rate = -rate;
    }else if (angle < -0){
        angle = -0;
        rate = -rate;
    }
    
    ufo.setVelocity(new Vector3f(dx, 0, dz));
    ufo.setLocalTranslation(x, 0, z);
    ufo.updateGeometricState();
    
    System.out.println("LOC: " + (int)x +", " + (int)z + 
            ", VEL: " + (int)dx + ", " + (int)dz);
}
 
Example 15
Source File: TestTwoSideLighting.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf){
    angle += tpf;
    angle %= FastMath.TWO_PI;
    
    pl.setPosition(new Vector3f(FastMath.cos(angle) * 3f, 0.5f, FastMath.sin(angle) * 3f));
    lightMdl.setLocalTranslation(pl.getPosition());
}
 
Example 16
Source File: TestTangentGenBadUV.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf){
    angle += tpf;
    angle %= FastMath.TWO_PI;
    
    pl.setPosition(new Vector3f(FastMath.cos(angle) * 2f, 0.5f, FastMath.sin(angle) * 2f));
    lightMdl.setLocalTranslation(pl.getPosition());
}
 
Example 17
Source File: TestRenderToCubemap.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf){
    Quaternion q = new Quaternion();
 
    angle += tpf;
    angle %= FastMath.TWO_PI;
    q.fromAngles(angle, 0, angle);

    offBox.setLocalRotation(q);
    offBox.updateLogicalState(tpf);
    offBox.updateGeometricState();
}
 
Example 18
Source File: TestMovingParticle.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf) {
    angle += tpf;
    angle %= FastMath.TWO_PI;
    float x = FastMath.cos(angle) * 2;
    float y = FastMath.sin(angle) * 2;
    emit.setLocalTranslation(x, 0, y);
}
 
Example 19
Source File: UVProjectionGenerator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Sphere projection for 2D textures.
 * 
 * @param positions
 *            points to be projected
 * @param bb
 *            the bounding box for projecting
 * @return UV coordinates after the projection
 */
public static float[] sphereProjection(float[] positions, BoundingSphere bs) {// TODO: rotate it to be vertical
    float[] uvCoordinates = new float[positions.length / 3 * 2];
    Vector3f v = new Vector3f();
    float cx = bs.getCenter().x, cy = bs.getCenter().y, cz = bs.getCenter().z;
    Vector3f uBase = new Vector3f(0, -1, 0);
    Vector3f vBase = new Vector3f(0, 0, -1);

    for (int i = 0, j = 0; i < positions.length; i += 3, j += 2) {
        // calculating U
        v.set(positions[i] - cx, positions[i + 1] - cy, 0);
        v.normalizeLocal();
        float angle = v.angleBetween(uBase);// result between [0; PI]
        if (v.x < 0) {// the angle should be greater than PI, we're on the other part of the image then
            angle = FastMath.TWO_PI - angle;
        }
        uvCoordinates[j] = angle / FastMath.TWO_PI;

        // calculating V
        v.set(positions[i] - cx, positions[i + 1] - cy, positions[i + 2] - cz);
        v.normalizeLocal();
        angle = v.angleBetween(vBase);// result between [0; PI]
        uvCoordinates[j + 1] = angle / FastMath.PI;
    }

    // looking for splitted triangles
    Triangle triangle = new Triangle();
    for (int i = 0; i < positions.length; i += 9) {
        triangle.set(0, positions[i], positions[i + 1], positions[i + 2]);
        triangle.set(1, positions[i + 3], positions[i + 4], positions[i + 5]);
        triangle.set(2, positions[i + 6], positions[i + 7], positions[i + 8]);
        float sgn1 = Math.signum(triangle.get1().x - cx);
        float sgn2 = Math.signum(triangle.get2().x - cx);
        float sgn3 = Math.signum(triangle.get3().x - cx);
        float xSideFactor = sgn1 + sgn2 + sgn3;
        float ySideFactor = Math.signum(triangle.get1().y - cy) + Math.signum(triangle.get2().y - cy) + Math.signum(triangle.get3().y - cy);
        if ((xSideFactor > -3 || xSideFactor < 3) && ySideFactor < 0) {// the triangle is on the splitting plane
            if (sgn1 == 1.0f) {
                uvCoordinates[i / 3 * 2] += 1.0f;
            }
            if (sgn2 == 1.0f) {
                uvCoordinates[(i / 3 + 1) * 2] += 1.0f;
            }
            if (sgn3 == 1.0f) {
                uvCoordinates[(i / 3 + 2) * 2] += 1.0f;
            }
        }
    }
    return uvCoordinates;
}
 
Example 20
Source File: BoundingSphereDebug.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * builds the vertices based on the radius
 */
private void setGeometryData() {
    setMode(Mode.Lines);

    FloatBuffer posBuf = BufferUtils.createVector3Buffer((radialSamples + 1) * 3);
    FloatBuffer colBuf = BufferUtils.createVector3Buffer((radialSamples + 1) * 4);

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

    // 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.Blue.r)
                .put(ColorRGBA.Blue.g)
                .put(ColorRGBA.Blue.b)
                .put(ColorRGBA.Blue.a);

    }
    for (int iR = 0; iR <= radialSamples; iR++) {
        posBuf.put(afCos[iR])
                .put(0)
                .put(afSin[iR]);
        colBuf.put(ColorRGBA.Green.r)
                .put(ColorRGBA.Green.g)
                .put(ColorRGBA.Green.b)
                .put(ColorRGBA.Green.a);
    }
    for (int iR = 0; iR <= radialSamples; iR++) {
        posBuf.put(0)
                .put(afCos[iR])
                .put(afSin[iR]);
        colBuf.put(ColorRGBA.Yellow.r)
                .put(ColorRGBA.Yellow.g)
                .put(ColorRGBA.Yellow.b)
                .put(ColorRGBA.Yellow.a);
    }

    updateBound();
    setStatic();
}