Search in sources :

Example 76 with Quaternion

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

the class VehicleWheel method applyWheelTransform.

public void applyWheelTransform() {
    if (wheelSpatial == null) {
        return;
    }
    Quaternion localRotationQuat = wheelSpatial.getLocalRotation();
    Vector3f localLocation = wheelSpatial.getLocalTranslation();
    if (!applyLocal && wheelSpatial.getParent() != null) {
        localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation());
        localLocation.divideLocal(wheelSpatial.getParent().getWorldScale());
        tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
        localRotationQuat.set(wheelWorldRotation);
        tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);
        wheelSpatial.setLocalTranslation(localLocation);
        wheelSpatial.setLocalRotation(localRotationQuat);
    } else {
        wheelSpatial.setLocalTranslation(wheelWorldLocation);
        wheelSpatial.setLocalRotation(wheelWorldRotation);
    }
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f)

Example 77 with Quaternion

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

the class AbstractPhysicsControl method applyPhysicsTransform.

/**
     * Applies a physics transform to the spatial
     *
     * @param worldLocation
     * @param worldRotation
     */
protected void applyPhysicsTransform(Vector3f worldLocation, Quaternion worldRotation) {
    if (enabled && spatial != null) {
        Vector3f localLocation = spatial.getLocalTranslation();
        Quaternion localRotationQuat = spatial.getLocalRotation();
        if (!applyLocal && spatial.getParent() != null) {
            localLocation.set(worldLocation).subtractLocal(spatial.getParent().getWorldTranslation());
            localLocation.divideLocal(spatial.getParent().getWorldScale());
            tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);
            localRotationQuat.set(worldRotation);
            tmp_inverseWorldRotation.set(spatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);
            spatial.setLocalTranslation(localLocation);
            spatial.setLocalRotation(localRotationQuat);
        } else {
            spatial.setLocalTranslation(worldLocation);
            spatial.setLocalRotation(worldRotation);
        }
    }
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f)

Example 78 with Quaternion

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

the class EnvMapUtils method getCubeMapCrossDebugViewWithMipMaps.

public static Node getCubeMapCrossDebugViewWithMipMaps(TextureCubeMap cubeMap, AssetManager assetManager) {
    Node n = new Node("CubeMapDebug" + cubeMap.getName());
    int size = cubeMap.getImage().getWidth();
    int nbMips = cubeMap.getImage().getMipMapSizes().length;
    Picture[] pics = new Picture[6 * nbMips];
    // 128f / (float) size;
    float ratio = 1f;
    int offset = 0;
    int guiOffset = 0;
    for (int mipLevel = 0; mipLevel < nbMips; mipLevel++) {
        size = Math.max(1, cubeMap.getImage().getWidth() >> mipLevel);
        int dataSize = cubeMap.getImage().getMipMapSizes()[mipLevel];
        byte[] dataArray = new byte[dataSize];
        for (int i = 0; i < 6; i++) {
            ByteBuffer bb = cubeMap.getImage().getData(i);
            bb.rewind();
            bb.position(offset);
            bb.get(dataArray, 0, dataSize);
            ByteBuffer data = BufferUtils.createByteBuffer(dataArray);
            pics[i] = new Picture("bla");
            Texture2D tex = new Texture2D(new Image(cubeMap.getImage().getFormat(), size, size, data, cubeMap.getImage().getColorSpace()));
            pics[i].setTexture(assetManager, tex, true);
            pics[i].setWidth(size);
            pics[i].setHeight(size);
            n.attachChild(pics[i]);
        }
        pics[0].setLocalTranslation(guiOffset + size, guiOffset + size * 2, 1);
        pics[0].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        pics[1].setLocalTranslation(guiOffset + size * 3, guiOffset + size * 2, 1);
        pics[1].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        pics[2].setLocalTranslation(guiOffset + size * 2, guiOffset + size * 3, 1);
        pics[2].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        pics[3].setLocalTranslation(guiOffset + size * 2, guiOffset + size, 1);
        pics[3].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        pics[4].setLocalTranslation(guiOffset + size * 2, guiOffset + size * 2, 1);
        pics[4].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        pics[5].setLocalTranslation(guiOffset + size * 4, guiOffset + size * 2, 1);
        pics[5].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        guiOffset += size * 2 + 1;
        offset += dataSize;
    }
    Quad q = new Quad(cubeMap.getImage().getWidth() * 4 + nbMips, guiOffset + size);
    Geometry g = new Geometry("bg", q);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Black);
    g.setMaterial(mat);
    g.setLocalTranslation(0, 0, 0);
    n.attachChild(g);
    n.setLocalScale(ratio);
    return n;
}
Also used : Quad(com.jme3.scene.shape.Quad) Texture2D(com.jme3.texture.Texture2D) Quaternion(com.jme3.math.Quaternion) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) Image(com.jme3.texture.Image) ByteBuffer(java.nio.ByteBuffer) Geometry(com.jme3.scene.Geometry) Picture(com.jme3.ui.Picture)

Example 79 with Quaternion

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

the class MotionEvent method read.

@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule in = im.getCapsule(this);
    lookAt = (Vector3f) in.readSavable("lookAt", null);
    upVector = (Vector3f) in.readSavable("upVector", Vector3f.UNIT_Y);
    rotation = (Quaternion) in.readSavable("rotation", null);
    directionType = in.readEnum("directionType", Direction.class, Direction.None);
    path = (MotionPath) in.readSavable("path", null);
    spatial = (Spatial) in.readSavable("spatial", null);
}
Also used : InputCapsule(com.jme3.export.InputCapsule)

Example 80 with Quaternion

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

the class TestBatchNodeCluster method simpleInitApp.

//protected
//    protected Geometry player;
@Override
public void simpleInitApp() {
    timer = new NanoTimer();
    batchNode = new SimpleBatchNode("BatchNode");
    xPosition.add(0);
    yPosition.add(0);
    zPosition.add(0);
    mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setColor("Color", ColorRGBA.White);
    mat1.setColor("GlowColor", ColorRGBA.Blue.mult(10));
    mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.setColor("Color", ColorRGBA.White);
    mat2.setColor("GlowColor", ColorRGBA.Red.mult(10));
    mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat3.setColor("Color", ColorRGBA.White);
    mat3.setColor("GlowColor", ColorRGBA.Yellow.mult(10));
    mat4 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat4.setColor("Color", ColorRGBA.White);
    mat4.setColor("GlowColor", ColorRGBA.Orange.mult(10));
    randomGenerator();
    //rootNode.attachChild(SkyFactory.createSky(
    //  assetManager, "Textures/SKY02.zip", false));
    inputManager.addMapping("Start Game", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addListener(al, new String[] { "Start Game" });
    cam.setLocation(new Vector3f(-34.403286f, 126.65158f, 434.791f));
    cam.setRotation(new Quaternion(0.022630932f, 0.9749435f, -0.18736298f, 0.11776358f));
    batchNode.batch();
    terrain = new Node("terrain");
    terrain.setLocalTranslation(50, 0, 50);
    terrain.attachChild(batchNode);
    flyCam.setMoveSpeed(100);
    rootNode.attachChild(terrain);
    Vector3f pos = new Vector3f(-40, 0, -40);
    batchNode.setLocalTranslation(pos);
    Arrow a = new Arrow(new Vector3f(0, 50, 0));
    Geometry g = new Geometry("a", a);
    g.setLocalTranslation(terrain.getLocalTranslation());
    Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    m.setColor("Color", ColorRGBA.Blue);
    g.setMaterial(m);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(new BloomFilter(BloomFilter.GlowMode.Objects));
    //        SSAOFilter ssao = new SSAOFilter(8.630104f,22.970434f,2.9299977f,0.2999997f);    
    //        fpp.addFilter(ssao);
    viewPort.addProcessor(fpp);
//   viewPort.setBackgroundColor(ColorRGBA.DarkGray);
}
Also used : Arrow(com.jme3.scene.debug.Arrow) NanoTimer(com.jme3.system.NanoTimer) Quaternion(com.jme3.math.Quaternion) KeyTrigger(com.jme3.input.controls.KeyTrigger) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) FilterPostProcessor(com.jme3.post.FilterPostProcessor) BloomFilter(com.jme3.post.filters.BloomFilter)

Aggregations

Quaternion (com.jme3.math.Quaternion)115 Vector3f (com.jme3.math.Vector3f)100 Geometry (com.jme3.scene.Geometry)42 DirectionalLight (com.jme3.light.DirectionalLight)37 Material (com.jme3.material.Material)36 Node (com.jme3.scene.Node)30 FilterPostProcessor (com.jme3.post.FilterPostProcessor)26 Spatial (com.jme3.scene.Spatial)26 KeyTrigger (com.jme3.input.controls.KeyTrigger)22 Box (com.jme3.scene.shape.Box)21 TempVars (com.jme3.util.TempVars)16 ActionListener (com.jme3.input.controls.ActionListener)15 ColorRGBA (com.jme3.math.ColorRGBA)15 Quad (com.jme3.scene.shape.Quad)15 AmbientLight (com.jme3.light.AmbientLight)14 Sphere (com.jme3.scene.shape.Sphere)11 Bone (com.jme3.animation.Bone)9 PointLight (com.jme3.light.PointLight)8 AnimControl (com.jme3.animation.AnimControl)7 SpotLight (com.jme3.light.SpotLight)7