Search in sources :

Example 51 with Direction

use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.

the class BresenhamYUpGridTracer method startWalk.

public void startWalk(final Ray walkRay) {
    // store ray
    this.walkRay.set(walkRay);
    // simplify access to direction
    Vector3f direction = this.walkRay.getDirection();
    // Move start point to grid space
    Vector3f start = this.walkRay.getOrigin().subtract(gridOrigin);
    gridLocation.x = (int) (start.x / gridSpacing.x);
    gridLocation.y = (int) (start.z / gridSpacing.z);
    Vector3f ooDirection = new Vector3f(1.0f / direction.x, 1, 1.0f / direction.z);
    // Check which direction on the X world axis we are moving.
    if (direction.x > TOLERANCE) {
        distToNextXIntersection = ((gridLocation.x + 1) * gridSpacing.x - start.x) * ooDirection.x;
        distBetweenXIntersections = gridSpacing.x * ooDirection.x;
        stepXDirection = 1;
    } else if (direction.x < -TOLERANCE) {
        distToNextXIntersection = (start.x - (gridLocation.x * gridSpacing.x)) * -direction.x;
        distBetweenXIntersections = -gridSpacing.x * ooDirection.x;
        stepXDirection = -1;
    } else {
        distToNextXIntersection = Float.MAX_VALUE;
        distBetweenXIntersections = Float.MAX_VALUE;
        stepXDirection = 0;
    }
    // Check which direction on the Z world axis we are moving.
    if (direction.z > TOLERANCE) {
        distToNextZIntersection = ((gridLocation.y + 1) * gridSpacing.z - start.z) * ooDirection.z;
        distBetweenZIntersections = gridSpacing.z * ooDirection.z;
        stepZDirection = 1;
    } else if (direction.z < -TOLERANCE) {
        distToNextZIntersection = (start.z - (gridLocation.y * gridSpacing.z)) * -direction.z;
        distBetweenZIntersections = -gridSpacing.z * ooDirection.z;
        stepZDirection = -1;
    } else {
        distToNextZIntersection = Float.MAX_VALUE;
        distBetweenZIntersections = Float.MAX_VALUE;
        stepZDirection = 0;
    }
    // Reset some variables
    rayLocation.set(start);
    rayLength = 0.0f;
    stepDirection = Direction.None;
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 52 with Direction

use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.

the class VRGuiManager method rotateScreenTo.

/**
	 * Rotate the GUI to the given direction.
	 * @param dir the direction to rotate to.
	 * @param tpf the time per frame.
	 */
private void rotateScreenTo(Quaternion dir, float tpf) {
    dir.getRotationColumn(2, look).negateLocal();
    dir.getRotationColumn(0, left).negateLocal();
    orient.fromAxes(left, dir.getRotationColumn(1, up), look);
    Quaternion rot = tempq.fromRotationMatrix(orient);
    if (posMode == VRGUIPositioningMode.AUTO_CAM_ALL_SKIP_PITCH) {
        VRUtil.stripToYaw(rot);
    }
    if (guiPositioningElastic > 0f && posMode != VRGUIPositioningMode.MANUAL) {
        // mix pos & dir with current pos & dir            
        EoldDir.nlerp(rot, tpf * guiPositioningElastic);
        guiQuadNode.setLocalRotation(EoldDir);
    } else {
        guiQuadNode.setLocalRotation(rot);
    }
}
Also used : Quaternion(com.jme3.math.Quaternion)

Aggregations

Vector3f (com.jme3.math.Vector3f)26 TempVars (com.jme3.util.TempVars)19 CollisionResult (com.jme3.collision.CollisionResult)6 ColorRGBA (com.jme3.math.ColorRGBA)6 Quaternion (com.jme3.math.Quaternion)6 Geometry (com.jme3.scene.Geometry)4 CollisionResults (com.jme3.collision.CollisionResults)3 DirectionalLight (com.jme3.light.DirectionalLight)3 Ray (com.jme3.math.Ray)3 Vector2f (com.jme3.math.Vector2f)3 Renderer (com.jme3.renderer.Renderer)3 CameraNode (com.jme3.scene.CameraNode)3 Node (com.jme3.scene.Node)3 BoundingSphere (com.jme3.bounding.BoundingSphere)2 VehicleWheel (com.jme3.bullet.objects.VehicleWheel)2 InputCapsule (com.jme3.export.InputCapsule)2 OutputCapsule (com.jme3.export.OutputCapsule)2 AmbientLight (com.jme3.light.AmbientLight)2 Light (com.jme3.light.Light)2 PointLight (com.jme3.light.PointLight)2