Search in sources :

Example 1 with Transform

use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.

the class CollisionShapeFactory method createSingleMeshShape.

/**
     * This type of collision shape is mesh-accurate and meant for immovable "world objects".
     * Examples include terrain, houses or whole shooter levels.<br>
     * Objects with "mesh" type collision shape will not collide with each other.
     */
private static MeshCollisionShape createSingleMeshShape(Geometry geom, Spatial parent) {
    Mesh mesh = geom.getMesh();
    Transform trans = getTransform(geom, parent);
    if (mesh != null && mesh.getMode() == Mesh.Mode.Triangles) {
        MeshCollisionShape mColl = new MeshCollisionShape(mesh);
        mColl.setScale(trans.getScale());
        return mColl;
    } else {
        return null;
    }
}
Also used : Transform(com.jme3.math.Transform)

Example 2 with Transform

use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.

the class CollisionShapeFactory method createSingleDynamicMeshShape.

/**
     * This method creates a hull collision shape for the given mesh.<br>
     */
private static HullCollisionShape createSingleDynamicMeshShape(Geometry geom, Spatial parent) {
    Mesh mesh = geom.getMesh();
    Transform trans = getTransform(geom, parent);
    if (mesh != null) {
        HullCollisionShape dynamicShape = new HullCollisionShape(mesh);
        dynamicShape.setScale(trans.getScale());
        return dynamicShape;
    } else {
        return null;
    }
}
Also used : Transform(com.jme3.math.Transform)

Example 3 with Transform

use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.

the class TestTexture3D method simpleInitApp.

@Override
public void simpleInitApp() {
    //mouseInput.setCursorVisible(true);
    flyCam.setMoveSpeed(10);
    //creating a sphere
    Sphere sphere = new Sphere(32, 32, 1);
    //getting the boundingbox
    sphere.updateBound();
    BoundingBox bb = (BoundingBox) sphere.getBound();
    Vector3f min = bb.getMin(null);
    float[] ext = new float[] { bb.getXExtent() * 2, bb.getYExtent() * 2, bb.getZExtent() * 2 };
    //we need to change the UV coordinates (the sphere is assumet to be inside the 3D image box)
    sphere.clearBuffer(Type.TexCoord);
    VertexBuffer vb = sphere.getBuffer(Type.Position);
    FloatBuffer fb = (FloatBuffer) vb.getData();
    float[] uvCoordinates = BufferUtils.getFloatArray(fb);
    //now transform the coordinates so that they are in the range of <0; 1>
    for (int i = 0; i < uvCoordinates.length; i += 3) {
        uvCoordinates[i] = (uvCoordinates[i] - min.x) / ext[0];
        uvCoordinates[i + 1] = (uvCoordinates[i + 1] - min.y) / ext[1];
        uvCoordinates[i + 2] = (uvCoordinates[i + 2] - min.z) / ext[2];
    }
    //apply new texture coordinates
    VertexBuffer uvCoordsBuffer = new VertexBuffer(Type.TexCoord);
    uvCoordsBuffer.setupData(Usage.Static, 3, com.jme3.scene.VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(uvCoordinates));
    sphere.setBuffer(uvCoordsBuffer);
    //create geometry, and apply material and our 3D texture
    Geometry g = new Geometry("sphere", sphere);
    Material material = new Material(assetManager, "jme3test/texture/tex3D.j3md");
    try {
        Texture texture = this.getTexture();
        material.setTexture("Texture", texture);
    } catch (IOException e) {
        e.printStackTrace();
    }
    g.setMaterial(material);
    rootNode.attachChild(g);
    //add some light so that it is visible
    PointLight light = new PointLight();
    light.setColor(ColorRGBA.White);
    light.setPosition(new Vector3f(5, 5, 5));
    light.setRadius(20);
    rootNode.addLight(light);
    light = new PointLight();
    light.setColor(ColorRGBA.White);
    light.setPosition(new Vector3f(-5, -5, -5));
    light.setRadius(20);
    rootNode.addLight(light);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) VertexBuffer(com.jme3.scene.VertexBuffer) BoundingBox(com.jme3.bounding.BoundingBox) Vector3f(com.jme3.math.Vector3f) FloatBuffer(java.nio.FloatBuffer) Material(com.jme3.material.Material) IOException(java.io.IOException) PointLight(com.jme3.light.PointLight) Texture(com.jme3.texture.Texture)

Example 4 with Transform

use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.

the class EnvMapUtils method getVectorFromCubemapFaceTexCoord.

/**
     *
     * Computes the 3 component vector coordinates for the given face and coords
     *
     * @param x the x texture coordinate
     * @param y the y texture coordinate
     * @param mapSize the size of a face of the cube map
     * @param face the face to consider
     * @param store a vector3f where the resulting vector will be stored
     * @param fixSeamsMethod the method to fix the seams
     * @return
     */
public static Vector3f getVectorFromCubemapFaceTexCoord(int x, int y, int mapSize, int face, Vector3f store, FixSeamsMethod fixSeamsMethod) {
    if (store == null) {
        store = new Vector3f();
    }
    float u;
    float v;
    if (fixSeamsMethod == FixSeamsMethod.Stretch) {
        /* Code from Nvtt : http://code.google.com/p/nvidia-texture-tools/source/browse/trunk/src/nvtt/CubeSurface.cpp		
             * transform from [0..res - 1] to [-1 .. 1], match up edges exactly. */
        u = (2.0f * (float) x / ((float) mapSize - 1.0f)) - 1.0f;
        v = (2.0f * (float) y / ((float) mapSize - 1.0f)) - 1.0f;
    } else {
        //Done if any other fix method or no fix method is set
        /* transform from [0..res - 1] to [- (1 - 1 / res) .. (1 - 1 / res)]
             * (+ 0.5f is for texel center addressing) */
        u = (2.0f * ((float) x + 0.5f) / (float) (mapSize)) - 1.0f;
        v = (2.0f * ((float) y + 0.5f) / (float) (mapSize)) - 1.0f;
    }
    if (fixSeamsMethod == FixSeamsMethod.Wrap) {
        // Warp texel centers in the proximity of the edges.
        float a = pow((float) mapSize, 2.0f) / pow(((float) mapSize - 1f), 3.0f);
        u = a * pow(u, 3f) + u;
        v = a * pow(v, 3f) + v;
    }
    // Code from Nvtt : http://code.google.com/p/nvidia-texture-tools/source/browse/trunk/src/nvtt/CubeSurface.cpp	
    switch(face) {
        case 0:
            store.set(1f, -v, -u);
            break;
        case 1:
            store.set(-1f, -v, u);
            break;
        case 2:
            store.set(u, 1f, v);
            break;
        case 3:
            store.set(u, -1f, -v);
            break;
        case 4:
            store.set(u, -v, 1f);
            break;
        case 5:
            store.set(-u, -v, -1.0f);
            break;
    }
    return store.normalizeLocal();
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 5 with Transform

use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.

the class ParticleEmitter method updateParticleState.

private void updateParticleState(float tpf) {
    // Force world transform to update
    this.getWorldTransform();
    TempVars vars = TempVars.get();
    Vector3f min = vars.vect1.set(Vector3f.POSITIVE_INFINITY);
    Vector3f max = vars.vect2.set(Vector3f.NEGATIVE_INFINITY);
    for (int i = 0; i < particles.length; ++i) {
        Particle p = particles[i];
        if (p.life == 0) {
            //                assert i <= firstUnUsed;
            continue;
        }
        p.life -= tpf;
        if (p.life <= 0) {
            this.freeParticle(i);
            continue;
        }
        updateParticle(p, tpf, min, max);
        if (firstUnUsed < i) {
            this.swap(firstUnUsed, i);
            if (i == lastUsed) {
                lastUsed = firstUnUsed;
            }
            firstUnUsed++;
        }
    }
    // Spawns particles within the tpf timeslot with proper age
    float interval = 1f / particlesPerSec;
    float originalTpf = tpf;
    tpf += timeDifference;
    while (tpf > interval) {
        tpf -= interval;
        Particle p = emitParticle(min, max);
        if (p != null) {
            p.life -= tpf;
            if (lastPos != null && isInWorldSpace()) {
                p.position.interpolateLocal(lastPos, 1 - tpf / originalTpf);
            }
            if (p.life <= 0) {
                freeParticle(lastUsed);
            } else {
                updateParticle(p, tpf, min, max);
            }
        }
    }
    timeDifference = tpf;
    if (lastPos == null) {
        lastPos = new Vector3f();
    }
    lastPos.set(getWorldTranslation());
    //This check avoids a NaN bounds when all the particles are dead during the first update.
    if (!min.equals(Vector3f.POSITIVE_INFINITY) && !max.equals(Vector3f.NEGATIVE_INFINITY)) {
        BoundingBox bbox = (BoundingBox) this.getMesh().getBound();
        bbox.setMinMax(min, max);
        this.setBoundRefresh();
    }
    vars.release();
}
Also used : Vector3f(com.jme3.math.Vector3f) BoundingBox(com.jme3.bounding.BoundingBox) TempVars(com.jme3.util.TempVars)

Aggregations

Vector3f (com.jme3.math.Vector3f)34 Transform (com.jme3.math.Transform)33 TempVars (com.jme3.util.TempVars)24 Quaternion (com.jme3.math.Quaternion)13 Matrix4f (com.jme3.math.Matrix4f)11 Bone (com.jme3.animation.Bone)9 BoundingBox (com.jme3.bounding.BoundingBox)9 Spatial (com.jme3.scene.Spatial)9 Geometry (com.jme3.scene.Geometry)8 ColorRGBA (com.jme3.math.ColorRGBA)7 Material (com.jme3.material.Material)6 Node (com.jme3.scene.Node)5 PointLight (com.jme3.light.PointLight)4 Mode (com.jme3.scene.Mesh.Mode)4 BoneContext (com.jme3.scene.plugins.blender.animations.BoneContext)4 FloatBuffer (java.nio.FloatBuffer)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Matrix4d (javax.vecmath.Matrix4d)4 Transform (com.bulletphysics.linearmath.Transform)3