Search in sources :

Example 56 with Point

use of com.jme3.scene.plugins.blender.meshes.Point in project jmonkeyengine by jMonkeyEngine.

the class LineSegment method distanceSquared.

public float distanceSquared(Vector3f point) {
    TempVars vars = TempVars.get();
    Vector3f compVec1 = vars.vect1;
    point.subtract(origin, compVec1);
    float segmentParameter = direction.dot(compVec1);
    if (-extent < segmentParameter) {
        if (segmentParameter < extent) {
            origin.add(direction.mult(segmentParameter, compVec1), compVec1);
        } else {
            origin.add(direction.mult(extent, compVec1), compVec1);
        }
    } else {
        origin.subtract(direction.mult(extent, compVec1), compVec1);
    }
    compVec1.subtractLocal(point);
    float len = compVec1.lengthSquared();
    vars.release();
    return len;
}
Also used : TempVars(com.jme3.util.TempVars)

Example 57 with Point

use of com.jme3.scene.plugins.blender.meshes.Point in project jmonkeyengine by jMonkeyEngine.

the class Camera method setClipPlane.

/**
     * Sets a clipPlane for this camera.
     * The clipPlane is used to recompute the
     * projectionMatrix using the plane as the near plane     
     * This technique is known as the oblique near-plane clipping method introduced by Eric Lengyel
     * more info here
     * <ul>
     * <li><a href="http://www.terathon.com/code/oblique.html">http://www.terathon.com/code/oblique.html</a>
     * <li><a href="http://aras-p.info/texts/obliqueortho.html">http://aras-p.info/texts/obliqueortho.html</a>
     * <li><a href="http://hacksoflife.blogspot.com/2008/12/every-now-and-then-i-come-across.html">http://hacksoflife.blogspot.com/2008/12/every-now-and-then-i-come-across.html</a>
     * </ul>
     *
     * Note that this will work properly only if it's called on each update, and be aware that it won't work properly with the sky bucket.
     * if you want to handle the sky bucket, look at how it's done in SimpleWaterProcessor.java
     * @param clipPlane the plane
     * @param side the side the camera stands from the plane
     */
public void setClipPlane(Plane clipPlane, Plane.Side side) {
    float sideFactor = 1;
    if (side == Plane.Side.Negative) {
        sideFactor = -1;
    }
    //we are on the other side of the plane no need to clip anymore.
    if (clipPlane.whichSide(location) == side) {
        return;
    }
    TempVars vars = TempVars.get();
    try {
        Matrix4f p = projectionMatrixOverride.set(projectionMatrix);
        Matrix4f ivm = viewMatrix;
        Vector3f point = clipPlane.getNormal().mult(clipPlane.getConstant(), vars.vect1);
        Vector3f pp = ivm.mult(point, vars.vect2);
        Vector3f pn = ivm.multNormal(clipPlane.getNormal(), vars.vect3);
        Vector4f clipPlaneV = vars.vect4f1.set(pn.x * sideFactor, pn.y * sideFactor, pn.z * sideFactor, -(pp.dot(pn)) * sideFactor);
        Vector4f v = vars.vect4f2.set(0, 0, 0, 0);
        v.x = (Math.signum(clipPlaneV.x) + p.m02) / p.m00;
        v.y = (Math.signum(clipPlaneV.y) + p.m12) / p.m11;
        v.z = -1.0f;
        v.w = (1.0f + p.m22) / p.m23;
        //clipPlaneV.x * v.x + clipPlaneV.y * v.y + clipPlaneV.z * v.z + clipPlaneV.w * v.w;
        float dot = clipPlaneV.dot(v);
        Vector4f c = clipPlaneV.multLocal(2.0f / dot);
        p.m20 = c.x - p.m30;
        p.m21 = c.y - p.m31;
        p.m22 = c.z - p.m32;
        p.m23 = c.w - p.m33;
        setProjectionMatrix(p);
    } finally {
        vars.release();
    }
}
Also used : TempVars(com.jme3.util.TempVars)

Example 58 with Point

use of com.jme3.scene.plugins.blender.meshes.Point in project jmonkeyengine by jMonkeyEngine.

the class GLRenderer method setupTextureParams.

@SuppressWarnings("fallthrough")
private void setupTextureParams(int unit, Texture tex) {
    Image image = tex.getImage();
    int target = convertTextureType(tex.getType(), image != null ? image.getMultiSamples() : 1, -1);
    boolean haveMips = true;
    if (image != null) {
        haveMips = image.isGeneratedMipmapsRequired() || image.hasMipmaps();
    }
    LastTextureState curState = image.getLastTextureState();
    if (curState.magFilter != tex.getMagFilter()) {
        bindTextureAndUnit(target, image, unit);
        gl.glTexParameteri(target, GL.GL_TEXTURE_MAG_FILTER, convertMagFilter(tex.getMagFilter()));
        curState.magFilter = tex.getMagFilter();
    }
    if (curState.minFilter != tex.getMinFilter()) {
        bindTextureAndUnit(target, image, unit);
        gl.glTexParameteri(target, GL.GL_TEXTURE_MIN_FILTER, convertMinFilter(tex.getMinFilter(), haveMips));
        curState.minFilter = tex.getMinFilter();
    }
    int desiredAnisoFilter = tex.getAnisotropicFilter() == 0 ? defaultAnisotropicFilter : tex.getAnisotropicFilter();
    if (caps.contains(Caps.TextureFilterAnisotropic) && curState.anisoFilter != desiredAnisoFilter) {
        bindTextureAndUnit(target, image, unit);
        gl.glTexParameterf(target, GLExt.GL_TEXTURE_MAX_ANISOTROPY_EXT, desiredAnisoFilter);
        curState.anisoFilter = desiredAnisoFilter;
    }
    switch(tex.getType()) {
        case ThreeDimensional:
        case // cubemaps use 3D coords
        CubeMap:
            if (gl2 != null && curState.rWrap != tex.getWrap(WrapAxis.R)) {
                bindTextureAndUnit(target, image, unit);
                gl2.glTexParameteri(target, GL2.GL_TEXTURE_WRAP_R, convertWrapMode(tex.getWrap(WrapAxis.R)));
                curState.rWrap = tex.getWrap(WrapAxis.R);
            }
        //There is no break statement on purpose here
        case TwoDimensional:
        case TwoDimensionalArray:
            if (curState.tWrap != tex.getWrap(WrapAxis.T)) {
                bindTextureAndUnit(target, image, unit);
                gl.glTexParameteri(target, GL.GL_TEXTURE_WRAP_T, convertWrapMode(tex.getWrap(WrapAxis.T)));
                image.getLastTextureState().tWrap = tex.getWrap(WrapAxis.T);
            }
            if (curState.sWrap != tex.getWrap(WrapAxis.S)) {
                bindTextureAndUnit(target, image, unit);
                gl.glTexParameteri(target, GL.GL_TEXTURE_WRAP_S, convertWrapMode(tex.getWrap(WrapAxis.S)));
                curState.sWrap = tex.getWrap(WrapAxis.S);
            }
            break;
        default:
            throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
    }
    ShadowCompareMode texCompareMode = tex.getShadowCompareMode();
    if (gl2 != null && curState.shadowCompareMode != texCompareMode) {
        bindTextureAndUnit(target, image, unit);
        if (texCompareMode != ShadowCompareMode.Off) {
            gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_REF_TO_TEXTURE);
            if (texCompareMode == ShadowCompareMode.GreaterOrEqual) {
                gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_GEQUAL);
            } else {
                gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_LEQUAL);
            }
        } else {
            gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL.GL_NONE);
        }
        curState.shadowCompareMode = texCompareMode;
    }
    // If at this point we didn't bind the texture, bind it now
    bindTextureOnly(target, image, unit);
}
Also used : ShadowCompareMode(com.jme3.texture.Texture.ShadowCompareMode) LastTextureState(com.jme3.texture.image.LastTextureState) Image(com.jme3.texture.Image)

Example 59 with Point

use of com.jme3.scene.plugins.blender.meshes.Point in project jmonkeyengine by jMonkeyEngine.

the class TangentBinormalGenerator method genNormalLines.

public static Mesh genNormalLines(Mesh mesh, float scale) {
    FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
    FloatBuffer normalBuffer = (FloatBuffer) mesh.getBuffer(Type.Normal).getData();
    ColorRGBA originColor = ColorRGBA.White;
    ColorRGBA normalColor = ColorRGBA.Blue;
    Mesh lineMesh = new Mesh();
    lineMesh.setMode(Mesh.Mode.Lines);
    Vector3f origin = new Vector3f();
    Vector3f point = new Vector3f();
    FloatBuffer lineVertex = BufferUtils.createFloatBuffer(vertexBuffer.limit() * 2);
    FloatBuffer lineColor = BufferUtils.createFloatBuffer(vertexBuffer.limit() / 3 * 4 * 2);
    for (int i = 0; i < vertexBuffer.limit() / 3; i++) {
        populateFromBuffer(origin, vertexBuffer, i);
        populateFromBuffer(point, normalBuffer, i);
        int index = i * 2;
        setInBuffer(origin, lineVertex, index);
        setInBuffer(originColor, lineColor, index);
        point.multLocal(scale);
        point.addLocal(origin);
        setInBuffer(point, lineVertex, index + 1);
        setInBuffer(normalColor, lineColor, index + 1);
    }
    lineMesh.setBuffer(Type.Position, 3, lineVertex);
    lineMesh.setBuffer(Type.Color, 4, lineColor);
    lineMesh.setStatic();
    //lineMesh.setInterleaved();
    return lineMesh;
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) Vector3f(com.jme3.math.Vector3f) FloatBuffer(java.nio.FloatBuffer)

Example 60 with Point

use of com.jme3.scene.plugins.blender.meshes.Point in project jmonkeyengine by jMonkeyEngine.

the class CursorLoader method loadCursor.

private JmeCursor loadCursor(InputStream inStream) throws IOException {
    // new byte [0] facilitates read()
    byte[] icoimages = new byte[0];
    if (isAni) {
        CursorLoader.CursorImageData ciDat = new CursorLoader.CursorImageData();
        int numIcons = 0;
        int jiffy = 0;
        // not using those but keeping references for now.
        int steps = 0;
        int width = 0;
        int height = 0;
        // we don't use that.
        int flag = 0;
        int[] rate = null;
        int[] animSeq = null;
        ArrayList<byte[]> icons;
        DataInput leIn = new LittleEndien(inStream);
        int riff = leIn.readInt();
        if (riff == 0x46464952) {
            // RIFF
            // read next int (file length), discarding it, we don't need that.
            leIn.readInt();
            int nextInt = 0;
            nextInt = getNext(leIn);
            if (nextInt == 0x4e4f4341) {
                // We have ACON, we do nothing
                //                    System.out.println("We have ACON. Next!");
                nextInt = getNext(leIn);
                while (nextInt >= 0) {
                    if (nextInt == 0x68696e61) {
                        //                            System.out.println("we have 'anih' header");
                        // internal struct length (always 36)
                        leIn.skipBytes(8);
                        numIcons = leIn.readInt();
                        // number of blits for ani cycles
                        steps = leIn.readInt();
                        width = leIn.readInt();
                        height = leIn.readInt();
                        leIn.skipBytes(8);
                        jiffy = leIn.readInt();
                        flag = leIn.readInt();
                        nextInt = leIn.readInt();
                    } else if (nextInt == 0x65746172) {
                        // found a 'rate' of animation
                        //                            System.out.println("we have 'rate'.");
                        // Fill rate here.
                        // Rate is synchronous with frames.
                        int length = leIn.readInt();
                        rate = new int[length / 4];
                        for (int i = 0; i < length / 4; i++) {
                            rate[i] = leIn.readInt();
                        }
                        nextInt = leIn.readInt();
                    } else if (nextInt == 0x20716573) {
                        // found a 'seq ' of animation
                        //                            System.out.println("we have 'seq '.");
                        // Fill animation sequence here
                        int length = leIn.readInt();
                        animSeq = new int[length / 4];
                        for (int i = 0; i < length / 4; i++) {
                            animSeq[i] = leIn.readInt();
                        }
                        nextInt = leIn.readInt();
                    } else if (nextInt == 0x5453494c) {
                        // Found a LIST
                        //                            System.out.println("we have 'LIST'.");
                        int length = leIn.readInt();
                        nextInt = leIn.readInt();
                        if (nextInt == 0x4f464e49) {
                            // Got an INFO, skip its length
                            // this part consist  of Author, title, etc
                            leIn.skipBytes(length - 4);
                            //                                System.out.println(" Discarding INFO (skipped = " + skipped + ")");
                            nextInt = leIn.readInt();
                        } else if (nextInt == 0x6d617266) {
                            //                                System.out.println("we have 'fram'.");
                            if (leIn.readInt() == 0x6e6f6369) {
                                // we have 'icon'
                                // We have an icon and from this point on
                                // the rest is only icons.
                                int icoLength = leIn.readInt();
                                ciDat.numImages = numIcons;
                                icons = new ArrayList<byte[]>(numIcons);
                                for (int i = 0; i < numIcons; i++) {
                                    if (i > 0) {
                                        // skip 'icon' header and length as they are
                                        // known already and won't change.
                                        leIn.skipBytes(8);
                                    }
                                    byte[] data = new byte[icoLength];
                                    ((InputStream) leIn).read(data, 0, icoLength);
                                    // get it from first image.
                                    if (width == 0 || height == 0 && i == 1) {
                                        width = data[6];
                                        height = data[7];
                                    }
                                    icons.add(data);
                                }
                                // at this point we have the icons, rates (either
                                // through jiffy or rate array, the sequence (if
                                // applicable) and the ani header info.
                                // Put things together.
                                ciDat.assembleCursor(icons, rate, animSeq, jiffy, steps, width, height);
                                ciDat.completeCursor();
                                nextInt = leIn.readInt();
                                // if for some reason there's JUNK (nextInt > -1)
                                // bail out.
                                nextInt = nextInt > -1 ? -1 : nextInt;
                            }
                        }
                    }
                }
            }
            return setJmeCursor(ciDat);
        } else if (riff == 0x58464952) {
            throw new IllegalArgumentException("Big-Endian RIFX is not supported. Sorry.");
        } else {
            throw new IllegalArgumentException("Unknown format.");
        }
    } else if (isCur || isIco) {
        DataInputStream in = new DataInputStream(inStream);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] buffer = new byte[16384];
        int bytesRead;
        while ((bytesRead = in.read(buffer)) >= 0) {
            out.write(buffer, 0, bytesRead);
        }
        icoimages = out.toByteArray();
    }
    BufferedImage[] bi = parseICOImage(icoimages);
    int hotSpotX = 0;
    int hotSpotY = 0;
    CursorLoader.CursorImageData cid = new CursorLoader.CursorImageData(bi, 0, hotSpotX, hotSpotY, 0);
    if (isCur) {
        /*
             * Per http://msdn.microsoft.com/en-us/library/ms997538.aspx
             * every .cur file should provide hotspot coordinates.
             */
        hotSpotX = icoimages[FDE_OFFSET + 4] + icoimages[FDE_OFFSET + 5] * 255;
        hotSpotY = icoimages[FDE_OFFSET + 6] + icoimages[FDE_OFFSET + 7] * 255;
        cid.xHotSpot = hotSpotX;
        /*
             * Flip the Y-coordinate.
             */
        cid.yHotSpot = cid.height - 1 - hotSpotY;
    }
    cid.completeCursor();
    return setJmeCursor(cid);
}
Also used : DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) LittleEndien(com.jme3.util.LittleEndien) BufferedImage(java.awt.image.BufferedImage) DataInput(java.io.DataInput)

Aggregations

Vector3f (com.jme3.math.Vector3f)27 TempVars (com.jme3.util.TempVars)19 FloatBuffer (java.nio.FloatBuffer)6 ColorRGBA (com.jme3.math.ColorRGBA)5 DirectionalLight (com.jme3.light.DirectionalLight)4 PointLight (com.jme3.light.PointLight)4 SpotLight (com.jme3.light.SpotLight)4 Quaternion (com.jme3.math.Quaternion)4 Spatial (com.jme3.scene.Spatial)4 ArrayList (java.util.ArrayList)4 CollisionResult (com.jme3.collision.CollisionResult)3 Light (com.jme3.light.Light)3 Triangle (com.jme3.math.Triangle)3 Vector2f (com.jme3.math.Vector2f)3 Geometry (com.jme3.scene.Geometry)3 Mesh (com.jme3.scene.Mesh)3 BoundingSphere (com.jme3.bounding.BoundingSphere)2 MotionPath (com.jme3.cinematic.MotionPath)2 MotionPathListener (com.jme3.cinematic.MotionPathListener)2 MotionEvent (com.jme3.cinematic.events.MotionEvent)2