Search in sources :

Example 96 with Vector2f

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

the class J3MOutputCapsule method formatMatParam.

private String formatMatParam(MatParam param) {
    VarType type = param.getVarType();
    Object val = param.getValue();
    switch(type) {
        case Boolean:
        case Float:
        case Int:
            return val.toString();
        case Vector2:
            Vector2f v2 = (Vector2f) val;
            return v2.getX() + " " + v2.getY();
        case Vector3:
            Vector3f v3 = (Vector3f) val;
            return v3.getX() + " " + v3.getY() + " " + v3.getZ();
        case Vector4:
            // can be either ColorRGBA, Vector4f or Quaternion
            if (val instanceof Vector4f) {
                Vector4f v4 = (Vector4f) val;
                return v4.getX() + " " + v4.getY() + " " + v4.getZ() + " " + v4.getW();
            } else if (val instanceof ColorRGBA) {
                ColorRGBA color = (ColorRGBA) val;
                return color.getRed() + " " + color.getGreen() + " " + color.getBlue() + " " + color.getAlpha();
            } else if (val instanceof Quaternion) {
                Quaternion quat = (Quaternion) val;
                return quat.getX() + " " + quat.getY() + " " + quat.getZ() + " " + quat.getW();
            } else {
                throw new UnsupportedOperationException("Unexpected Vector4 type: " + val);
            }
        default:
            // parameter type not supported in J3M
            return null;
    }
}
Also used : VarType(com.jme3.shader.VarType)

Example 97 with Vector2f

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

the class FbxLayerElement method toVector2.

static Vector2f[] toVector2(double[] data) {
    Vector2f[] vectors = new Vector2f[data.length / 2];
    for (int i = 0; i < vectors.length; i++) {
        float x = (float) data[i * 2];
        float y = (float) data[i * 2 + 1];
        vectors[i] = new Vector2f(x, y);
    }
    return vectors;
}
Also used : Vector2f(com.jme3.math.Vector2f)

Example 98 with Vector2f

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

the class TerrainQuad method createQuad.

/**
     * Quadrants, world coordinates, and heightmap coordinates (Y-up):
     *
     *         -z
     *      -u |
     *    -v  1|3
     *  -x ----+---- x
     *        2|4 u
     *         | v
     *         z
     * <code>createQuad</code> generates four new quads from this quad.
     * The heightmap's top left (0,0) coordinate is at the bottom, -x,-z
     * coordinate of the terrain, so it grows in the positive x.z direction.
     */
protected void createQuad(int blockSize, float[] heightMap) {
    // create 4 terrain quads
    int quarterSize = size >> 2;
    int split = (size + 1) >> 1;
    Vector2f tempOffset = new Vector2f();
    offsetAmount += quarterSize;
    //if (lodCalculator == null)
    //    lodCalculator = createDefaultLodCalculator(); // set a default one
    // 1 upper left of heightmap, upper left quad
    float[] heightBlock1 = createHeightSubBlock(heightMap, 0, 0, split);
    Vector3f origin1 = new Vector3f(-quarterSize * stepScale.x, 0, -quarterSize * stepScale.z);
    tempOffset.x = offset.x;
    tempOffset.y = offset.y;
    tempOffset.x += origin1.x;
    tempOffset.y += origin1.z;
    TerrainQuad quad1 = new TerrainQuad(getName() + "Quad1", blockSize, split, stepScale, heightBlock1, totalSize, tempOffset, offsetAmount);
    quad1.setLocalTranslation(origin1);
    quad1.quadrant = 1;
    this.attachChild(quad1);
    // 2 lower left of heightmap, lower left quad
    float[] heightBlock2 = createHeightSubBlock(heightMap, 0, split - 1, split);
    Vector3f origin2 = new Vector3f(-quarterSize * stepScale.x, 0, quarterSize * stepScale.z);
    tempOffset = new Vector2f();
    tempOffset.x = offset.x;
    tempOffset.y = offset.y;
    tempOffset.x += origin2.x;
    tempOffset.y += origin2.z;
    TerrainQuad quad2 = new TerrainQuad(getName() + "Quad2", blockSize, split, stepScale, heightBlock2, totalSize, tempOffset, offsetAmount);
    quad2.setLocalTranslation(origin2);
    quad2.quadrant = 2;
    this.attachChild(quad2);
    // 3 upper right of heightmap, upper right quad
    float[] heightBlock3 = createHeightSubBlock(heightMap, split - 1, 0, split);
    Vector3f origin3 = new Vector3f(quarterSize * stepScale.x, 0, -quarterSize * stepScale.z);
    tempOffset = new Vector2f();
    tempOffset.x = offset.x;
    tempOffset.y = offset.y;
    tempOffset.x += origin3.x;
    tempOffset.y += origin3.z;
    TerrainQuad quad3 = new TerrainQuad(getName() + "Quad3", blockSize, split, stepScale, heightBlock3, totalSize, tempOffset, offsetAmount);
    quad3.setLocalTranslation(origin3);
    quad3.quadrant = 3;
    this.attachChild(quad3);
    // 4 lower right of heightmap, lower right quad
    float[] heightBlock4 = createHeightSubBlock(heightMap, split - 1, split - 1, split);
    Vector3f origin4 = new Vector3f(quarterSize * stepScale.x, 0, quarterSize * stepScale.z);
    tempOffset = new Vector2f();
    tempOffset.x = offset.x;
    tempOffset.y = offset.y;
    tempOffset.x += origin4.x;
    tempOffset.y += origin4.z;
    TerrainQuad quad4 = new TerrainQuad(getName() + "Quad4", blockSize, split, stepScale, heightBlock4, totalSize, tempOffset, offsetAmount);
    quad4.setLocalTranslation(origin4);
    quad4.quadrant = 4;
    this.attachChild(quad4);
}
Also used : Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f)

Example 99 with Vector2f

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

the class TerrainQuad method read.

@Override
public void read(JmeImporter e) throws IOException {
    super.read(e);
    InputCapsule c = e.getCapsule(this);
    size = c.readInt("size", 0);
    stepScale = (Vector3f) c.readSavable("stepScale", null);
    offset = (Vector2f) c.readSavable("offset", new Vector2f(0, 0));
    offsetAmount = c.readFloat("offsetAmount", 0);
    quadrant = c.readInt("quadrant", 0);
    totalSize = c.readInt("totalSize", 0);
    if (!(getParent() instanceof TerrainQuad)) {
        BoundingBox all = new BoundingBox(getWorldTranslation(), totalSize, totalSize, totalSize);
        affectedAreaBBox = all;
        updateNormals();
    }
}
Also used : InputCapsule(com.jme3.export.InputCapsule) Vector2f(com.jme3.math.Vector2f) BoundingBox(com.jme3.bounding.BoundingBox)

Example 100 with Vector2f

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

the class BresenhamTerrainPicker method getTerrainIntersection.

public Vector3f getTerrainIntersection(Ray worldPick, CollisionResults results) {
    worldPickRay.set(worldPick);
    List<TerrainPickData> pickData = new ArrayList<TerrainPickData>();
    root.findPick(worldPick.clone(), pickData);
    Collections.sort(pickData);
    if (pickData.isEmpty())
        return null;
    workRay.set(worldPick);
    for (TerrainPickData pd : pickData) {
        TerrainPatch patch = pd.targetPatch;
        tracer.getGridSpacing().set(patch.getWorldScale());
        tracer.setGridOrigin(patch.getWorldTranslation());
        workRay.getOrigin().set(worldPick.getDirection()).multLocal(pd.cr.getDistance() - .1f).addLocal(worldPick.getOrigin());
        tracer.startWalk(workRay);
        final Vector3f intersection = new Vector3f();
        final Vector2f loc = tracer.getGridLocation();
        if (tracer.isRayPerpendicularToGrid()) {
            Triangle hit = new Triangle();
            checkTriangles(loc.x, loc.y, workRay, intersection, patch, hit);
            float distance = worldPickRay.origin.distance(intersection);
            CollisionResult cr = new CollisionResult(intersection, distance);
            cr.setGeometry(patch);
            cr.setContactNormal(hit.getNormal());
            results.addCollision(cr);
            return intersection;
        }
        while (loc.x >= -1 && loc.x <= patch.getSize() && loc.y >= -1 && loc.y <= patch.getSize()) {
            //System.out.print(loc.x+","+loc.y+" : ");
            // check the triangles of main square for intersection.
            Triangle hit = new Triangle();
            if (checkTriangles(loc.x, loc.y, workRay, intersection, patch, hit)) {
                // we found an intersection, so return that!
                float distance = worldPickRay.origin.distance(intersection);
                CollisionResult cr = new CollisionResult(intersection, distance);
                cr.setGeometry(patch);
                results.addCollision(cr);
                cr.setContactNormal(hit.getNormal());
                return intersection;
            }
            // because of how we get our height coords, we will
            // sometimes be off by a grid spot, so we check the next
            // grid space up.
            int dx = 0, dz = 0;
            Direction d = tracer.getLastStepDirection();
            switch(d) {
                case PositiveX:
                case NegativeX:
                    dx = 0;
                    dz = 1;
                    break;
                case PositiveZ:
                case NegativeZ:
                    dx = 1;
                    dz = 0;
                    break;
            }
            if (checkTriangles(loc.x + dx, loc.y + dz, workRay, intersection, patch, hit)) {
                // we found an intersection, so return that!
                float distance = worldPickRay.origin.distance(intersection);
                CollisionResult cr = new CollisionResult(intersection, distance);
                results.addCollision(cr);
                cr.setGeometry(patch);
                cr.setContactNormal(hit.getNormal());
                return intersection;
            }
            tracer.next();
        }
    }
    return null;
}
Also used : CollisionResult(com.jme3.collision.CollisionResult) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) ArrayList(java.util.ArrayList) Triangle(com.jme3.math.Triangle) Direction(com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction) TerrainPatch(com.jme3.terrain.geomipmap.TerrainPatch)

Aggregations

Vector2f (com.jme3.math.Vector2f)80 Vector3f (com.jme3.math.Vector3f)38 Geometry (com.jme3.scene.Geometry)22 Material (com.jme3.material.Material)20 Box (com.jme3.scene.shape.Box)17 ArrayList (java.util.ArrayList)14 Texture (com.jme3.texture.Texture)9 List (java.util.List)9 Node (com.jme3.scene.Node)8 Sphere (com.jme3.scene.shape.Sphere)8 FloatBuffer (java.nio.FloatBuffer)8 InputCapsule (com.jme3.export.InputCapsule)7 Spatial (com.jme3.scene.Spatial)7 DirectionalLight (com.jme3.light.DirectionalLight)6 Mesh (com.jme3.scene.Mesh)6 AmbientLight (com.jme3.light.AmbientLight)5 Quad (com.jme3.scene.shape.Quad)5 BoundingBox (com.jme3.bounding.BoundingBox)4 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)4 CollisionResult (com.jme3.collision.CollisionResult)4