Search in sources :

Example 26 with Transform

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

the class CompoundCollisionShape method addChildShape.

/**
     * adds a child shape at the given local translation
     * @param shape the child shape to add
     * @param location the local location of the child shape
     */
public void addChildShape(CollisionShape shape, Vector3f location) {
    Transform transA = new Transform(Converter.convert(new Matrix3f()));
    Converter.convert(location, transA.origin);
    children.add(new ChildCollisionShape(location.clone(), new Matrix3f(), shape));
    ((CompoundShape) cShape).addChildShape(transA, shape.getCShape());
}
Also used : Matrix3f(com.jme3.math.Matrix3f) ChildCollisionShape(com.jme3.bullet.collision.shapes.infos.ChildCollisionShape) CompoundShape(com.bulletphysics.collision.shapes.CompoundShape) Transform(com.bulletphysics.linearmath.Transform)

Example 27 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 28 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 29 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 30 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)

Aggregations

Vector3f (com.jme3.math.Vector3f)29 Transform (com.jme3.math.Transform)26 TempVars (com.jme3.util.TempVars)24 Quaternion (com.jme3.math.Quaternion)11 Matrix4f (com.jme3.math.Matrix4f)10 Bone (com.jme3.animation.Bone)9 BoundingBox (com.jme3.bounding.BoundingBox)6 BoneContext (com.jme3.scene.plugins.blender.animations.BoneContext)5 PointLight (com.jme3.light.PointLight)4 Spatial (com.jme3.scene.Spatial)4 FloatBuffer (java.nio.FloatBuffer)4 Transform (com.bulletphysics.linearmath.Transform)3 ChildCollisionShape (com.jme3.bullet.collision.shapes.infos.ChildCollisionShape)3 DirectionalLight (com.jme3.light.DirectionalLight)3 Light (com.jme3.light.Light)3 SpotLight (com.jme3.light.SpotLight)3 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)2 BoneTrack (com.jme3.animation.BoneTrack)2 SpatialTrack (com.jme3.animation.SpatialTrack)2 BoundingVolume (com.jme3.bounding.BoundingVolume)2