Search in sources :

Example 71 with Quaternion

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

the class EnvMapUtils method getCubeMapCrossDebugView.

/**
     * Creates a debug Node of the given cube map to attach to the gui node
     *
     * the cube map is layered this way :
     * <pre>
     *         _____
     *        |     |
     *        | +Y  |
     *   _____|_____|_____ _____
     *  |     |     |     |     |
     *  | -X  | +Z  | +X  | -Z  |
     *  |_____|_____|_____|_____|
     *        |     |
     *        | -Y  |
     *        |_____|
     *
     *</pre>
     *
     * @param cubeMap the cube map
     * @param assetManager the asset Manager
     * @return
     */
public static Node getCubeMapCrossDebugView(TextureCubeMap cubeMap, AssetManager assetManager) {
    Node n = new Node("CubeMapDebug" + cubeMap.getName());
    int size = cubeMap.getImage().getWidth();
    Picture[] pics = new Picture[6];
    float ratio = 128f / (float) size;
    for (int i = 0; i < 6; i++) {
        pics[i] = new Picture("bla");
        Texture2D tex = new Texture2D(new Image(cubeMap.getImage().getFormat(), size, size, cubeMap.getImage().getData(i), cubeMap.getImage().getColorSpace()));
        pics[i].setTexture(assetManager, tex, true);
        pics[i].setWidth(size);
        pics[i].setHeight(size);
        n.attachChild(pics[i]);
    }
    pics[0].setLocalTranslation(size, size * 2, 1);
    pics[0].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    pics[1].setLocalTranslation(size * 3, size * 2, 1);
    pics[1].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    pics[2].setLocalTranslation(size * 2, size * 3, 1);
    pics[2].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    pics[3].setLocalTranslation(size * 2, size, 1);
    pics[3].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    pics[4].setLocalTranslation(size * 2, size * 2, 1);
    pics[4].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    pics[5].setLocalTranslation(size * 4, size * 2, 1);
    pics[5].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    Quad q = new Quad(size * 4, size * 3);
    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 : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) Texture2D(com.jme3.texture.Texture2D) Quaternion(com.jme3.math.Quaternion) Picture(com.jme3.ui.Picture) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) Image(com.jme3.texture.Image)

Example 72 with Quaternion

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

the class MatParam method getValueAsString.

/**
     * Returns the material parameter value as it would appear in a J3M
     * file. E.g.<br/>
     * <code>
     * MaterialParameters {<br/>
     *     ABC : 1 2 3 4<br/>
     * }<br/>
     * </code>
     * Assuming "ABC" is a Vector4 parameter, then the value
     * "1 2 3 4" would be returned by this method.
     * <br/><br/>
     * @return material parameter value as it would appear in a J3M file.
     */
public String getValueAsString() {
    switch(type) {
        case Boolean:
        case Float:
        case Int:
            return value.toString();
        case Vector2:
            Vector2f v2 = (Vector2f) value;
            return v2.getX() + " " + v2.getY();
        /* 
This may get used at a later point of time
When arrays can be inserted in J3M files

            case Vector2Array:
                Vector2f[] v2Arr = (Vector2f[]) value;
                String v2str = "";
                for (int i = 0; i < v2Arr.length ; i++) {
                    v2str += v2Arr[i].getX() + " " + v2Arr[i].getY() + "\n";
                }
                return v2str;
*/
        case Vector3:
            Vector3f v3 = (Vector3f) value;
            return v3.getX() + " " + v3.getY() + " " + v3.getZ();
        /*
            case Vector3Array:
                Vector3f[] v3Arr = (Vector3f[]) value;
                String v3str = "";
                for (int i = 0; i < v3Arr.length ; i++) {
                    v3str += v3Arr[i].getX() + " "
                            + v3Arr[i].getY() + " "
                            + v3Arr[i].getZ() + "\n";
                }
                return v3str;
            case Vector4Array:
                // can be either ColorRGBA, Vector4f or Quaternion
                if (value instanceof Vector4f) {
                    Vector4f[] v4arr = (Vector4f[]) value;
                    String v4str = "";
                    for (int i = 0; i < v4arr.length ; i++) {
                        v4str += v4arr[i].getX() + " "
                                + v4arr[i].getY() + " "
                                + v4arr[i].getZ() + " "
                                + v4arr[i].getW() + "\n";
                    }
                    return v4str;
                } else if (value instanceof ColorRGBA) {
                    ColorRGBA[] colorArr = (ColorRGBA[]) value;
                    String colStr = "";
                    for (int i = 0; i < colorArr.length ; i++) {
                        colStr += colorArr[i].getRed() + " "
                                + colorArr[i].getGreen() + " "
                                + colorArr[i].getBlue() + " "
                                + colorArr[i].getAlpha() + "\n";
                    }
                    return colStr;
                } else if (value instanceof Quaternion) {
                    Quaternion[] quatArr = (Quaternion[]) value;
                    String quatStr = "";
                    for (int i = 0; i < quatArr.length ; i++) {
                        quatStr += quatArr[i].getX() + " "
                                + quatArr[i].getY() + " "
                                + quatArr[i].getZ() + " "
                                + quatArr[i].getW() + "\n";
                    }
                    return quatStr;
                } else {
                    throw new UnsupportedOperationException("Unexpected Vector4Array type: " + value);
                }
*/
        case Vector4:
            // can be either ColorRGBA, Vector4f or Quaternion
            if (value instanceof Vector4f) {
                Vector4f v4 = (Vector4f) value;
                return v4.getX() + " " + v4.getY() + " " + v4.getZ() + " " + v4.getW();
            } else if (value instanceof ColorRGBA) {
                ColorRGBA color = (ColorRGBA) value;
                return color.getRed() + " " + color.getGreen() + " " + color.getBlue() + " " + color.getAlpha();
            } else if (value instanceof Quaternion) {
                Quaternion quat = (Quaternion) value;
                return quat.getX() + " " + quat.getY() + " " + quat.getZ() + " " + quat.getW();
            } else {
                throw new UnsupportedOperationException("Unexpected Vector4 type: " + value);
            }
        case Texture2D:
        case Texture3D:
        case TextureArray:
        case TextureBuffer:
        case TextureCubeMap:
            Texture texVal = (Texture) value;
            TextureKey texKey = (TextureKey) texVal.getKey();
            if (texKey == null) {
                // often does as well, even implicitly. 
                return texVal + ":returned null key";
            }
            String ret = "";
            if (texKey.isFlipY()) {
                ret += "Flip ";
            }
            //Wrap mode
            ret += getWrapMode(texVal, Texture.WrapAxis.S);
            ret += getWrapMode(texVal, Texture.WrapAxis.T);
            ret += getWrapMode(texVal, Texture.WrapAxis.R);
            //Min and Mag filter
            Texture.MinFilter def = Texture.MinFilter.BilinearNoMipMaps;
            if (texVal.getImage().hasMipmaps() || texKey.isGenerateMips()) {
                def = Texture.MinFilter.Trilinear;
            }
            if (texVal.getMinFilter() != def) {
                ret += "Min" + texVal.getMinFilter().name() + " ";
            }
            if (texVal.getMagFilter() != Texture.MagFilter.Bilinear) {
                ret += "Mag" + texVal.getMagFilter().name() + " ";
            }
            return ret + "\"" + texKey.getName() + "\"";
        default:
            // parameter type not supported in J3M
            return null;
    }
}
Also used : TextureKey(com.jme3.asset.TextureKey) Texture(com.jme3.texture.Texture)

Example 73 with Quaternion

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

the class FlyByCamera method rotateCamera.

protected void rotateCamera(float value, Vector3f axis) {
    if (dragToRotate) {
        if (canRotate) {
        //                value = -value;
        } else {
            return;
        }
    }
    Matrix3f mat = new Matrix3f();
    mat.fromAngleNormalAxis(rotationSpeed * value, axis);
    Vector3f up = cam.getUp();
    Vector3f left = cam.getLeft();
    Vector3f dir = cam.getDirection();
    mat.mult(up, up);
    mat.mult(left, left);
    mat.mult(dir, dir);
    Quaternion q = new Quaternion();
    q.fromAxes(left, up, dir);
    q.normalizeLocal();
    cam.setAxes(q);
}
Also used : Matrix3f(com.jme3.math.Matrix3f) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f)

Example 74 with Quaternion

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

the class TestMotionPath method simpleInitApp.

@Override
public void simpleInitApp() {
    createScene();
    cam.setLocation(new Vector3f(8.4399185f, 11.189463f, 14.267577f));
    path = new MotionPath();
    path.addWayPoint(new Vector3f(10, 3, 0));
    path.addWayPoint(new Vector3f(10, 3, 10));
    path.addWayPoint(new Vector3f(-40, 3, 10));
    path.addWayPoint(new Vector3f(-40, 3, 0));
    path.addWayPoint(new Vector3f(-40, 8, 0));
    path.addWayPoint(new Vector3f(10, 8, 0));
    path.addWayPoint(new Vector3f(10, 8, 10));
    path.addWayPoint(new Vector3f(15, 8, 10));
    path.enableDebugShape(assetManager, rootNode);
    motionControl = new MotionEvent(teapot, path);
    motionControl.setDirectionType(MotionEvent.Direction.PathAndRotation);
    motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));
    motionControl.setInitialDuration(10f);
    motionControl.setSpeed(2f);
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    final BitmapText wayPointsText = new BitmapText(guiFont, false);
    wayPointsText.setSize(guiFont.getCharSet().getRenderedSize());
    guiNode.attachChild(wayPointsText);
    path.addListener(new MotionPathListener() {

        public void onWayPointReach(MotionEvent control, int wayPointIndex) {
            if (path.getNbWayPoints() == wayPointIndex + 1) {
                wayPointsText.setText(control.getSpatial().getName() + "Finished!!! ");
            } else {
                wayPointsText.setText(control.getSpatial().getName() + " Reached way point " + wayPointIndex);
            }
            wayPointsText.setLocalTranslation((cam.getWidth() - wayPointsText.getLineWidth()) / 2, cam.getHeight(), 0);
        }
    });
    flyCam.setEnabled(false);
    ChaseCamera chaser = new ChaseCamera(cam, teapot);
    //        motionControl.setSpeed(-3f);
    //        motionControl.setLoopMode(LoopMode.Loop);
    //        path.setCycle(true);
    // chaser.setEnabled(false);
    chaser.registerWithInput(inputManager);
    initInputs();
}
Also used : MotionPathListener(com.jme3.cinematic.MotionPathListener) BitmapText(com.jme3.font.BitmapText) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) ChaseCamera(com.jme3.input.ChaseCamera) MotionPath(com.jme3.cinematic.MotionPath) MotionEvent(com.jme3.cinematic.events.MotionEvent)

Example 75 with Quaternion

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

the class SimpleWaterProcessor method createWaterGeometry.

/**
     * Creates a quad with the water material applied to it.
     * @param width
     * @param height
     * @return
     */
public Geometry createWaterGeometry(float width, float height) {
    Quad quad = new Quad(width, height);
    Geometry geom = new Geometry("WaterGeometry", quad);
    geom.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
    geom.setMaterial(material);
    return geom;
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad)

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