Java Code Examples for com.jme3.math.Vector3f#addLocal()

The following examples show how to use com.jme3.math.Vector3f#addLocal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SkeletonInterBoneWire.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * The method updates the geometry according to the poitions of the bones.
 */
public void updateGeometry() {
    VertexBuffer vb = this.getBuffer(Type.Position);
    FloatBuffer posBuf = this.getFloatBuffer(Type.Position);
    posBuf.clear();
    for (int i = 0; i < skeleton.getBoneCount(); ++i) {
        Bone bone = skeleton.getBone(i);
        Vector3f parentTail = bone.getModelSpacePosition().add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i))));

        for (Bone child : bone.getChildren()) {
            Vector3f childHead = child.getModelSpacePosition();
            Vector3f v = childHead.subtract(parentTail);
            float pointDelta = v.length() / POINT_AMOUNT;
            v.normalizeLocal().multLocal(pointDelta);
            Vector3f pointPosition = parentTail.clone();
            for (int j = 0; j < POINT_AMOUNT; ++j) {
                posBuf.put(pointPosition.getX()).put(pointPosition.getY()).put(pointPosition.getZ());
                pointPosition.addLocal(v);
            }
        }
    }
    posBuf.flip();
    vb.updateData(posBuf);

    this.updateBound();
}
 
Example 2
Source File: TestHoveringTank.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void updateCamera() {
    rootNode.updateGeometricState();

    Vector3f pos = spaceCraft.getWorldTranslation().clone();
    Quaternion rot = spaceCraft.getWorldRotation();
    Vector3f dir = rot.getRotationColumn(2);

    // make it XZ only
    Vector3f camPos = new Vector3f(dir);
    camPos.setY(0);
    camPos.normalizeLocal();

    // negate and multiply by distance from object
    camPos.negateLocal();
    camPos.multLocal(15);

    // add Y distance
    camPos.setY(2);
    camPos.addLocal(pos);
    cam.setLocation(camPos);

    Vector3f lookAt = new Vector3f(dir);
    lookAt.multLocal(7); // look at dist
    lookAt.addLocal(pos);
    cam.lookAt(lookAt, Vector3f.UNIT_Y);
}
 
Example 3
Source File: VRAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get the observer final position within the scene.
 * @return the observer position.
 * @see #getFinalObserverRotation()
 */
public Vector3f getFinalObserverPosition() {
    if( environment.getVRViewManager() == null ) {
        if( environment.getObserver() == null ) {
            return environment.getCamera().getLocation();
        } else{
        	return ((Spatial)environment.getObserver()).getWorldTranslation();            
        }
    }
    
    Vector3f pos = environment.getVRHardware().getPosition();
    if( environment.getObserver() == null ) {
    	environment.getDummyCamera().getRotation().mult(pos, pos);
        return pos.addLocal(environment.getDummyCamera().getLocation());
    } else {
    	((Spatial)environment.getObserver()).getWorldRotation().mult(pos, pos);
        return pos.addLocal(((Spatial)environment.getObserver()).getWorldTranslation());
    }
}
 
Example 4
Source File: UVCoordinatesGenerator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * This method returns the bounding tube of the given mesh.
 * 
 * @param mesh
 *            the mesh
 * @return bounding tube of the given mesh
 */
/* package */static BoundingTube getBoundingTube(Mesh mesh) {
    Vector3f center = new Vector3f();
    float maxx = -Float.MAX_VALUE, minx = Float.MAX_VALUE;
    float maxy = -Float.MAX_VALUE, miny = Float.MAX_VALUE;
    float maxz = -Float.MAX_VALUE, minz = Float.MAX_VALUE;

    FloatBuffer positions = mesh.getFloatBuffer(VertexBuffer.Type.Position);
    int limit = positions.limit();
    for (int i = 0; i < limit; i += 3) {
        float x = positions.get(i);
        float y = positions.get(i + 1);
        float z = positions.get(i + 2);
        center.addLocal(x, y, z);
        maxx = x > maxx ? x : maxx;
        minx = x < minx ? x : minx;
        maxy = y > maxy ? y : maxy;
        miny = y < miny ? y : miny;
        maxz = z > maxz ? z : maxz;
        minz = z < minz ? z : minz;
    }
    center.divideLocal(limit / 3);

    float radius = Math.max(maxx - minx, maxy - miny) * 0.5f;
    return new BoundingTube(radius, maxz - minz, center);
}
 
Example 5
Source File: EmitterMeshFaceShape.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * This method fills the point with coordinates of randomly selected point on a random face.
 * The normal param is filled with selected face's normal.
 * @param store
 *        the variable to store with coordinates of randomly selected selected point on a random face
 * @param normal
 *        filled with selected face's normal
 */
@Override
public void getRandomPointAndNormal(Vector3f store, Vector3f normal) {
    int meshIndex = FastMath.nextRandomInt(0, vertices.size() - 1);
    // the index of the first vertex of a face (must be dividable by 3)
    int faceIndex = FastMath.nextRandomInt(0, vertices.get(meshIndex).size() / 3 - 1);
    int vertIndex = faceIndex * 3;
    // put the point somewhere between the first and the second vertex of a face
    float moveFactor = FastMath.nextRandomFloat();
    store.set(Vector3f.ZERO);
    store.addLocal(vertices.get(meshIndex).get(vertIndex));
    store.addLocal((vertices.get(meshIndex).get(vertIndex + 1).x - vertices.get(meshIndex).get(vertIndex).x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).y - vertices.get(meshIndex).get(vertIndex).y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).z - vertices.get(meshIndex).get(vertIndex).z) * moveFactor);
    // move the result towards the last face vertex
    moveFactor = FastMath.nextRandomFloat();
    store.addLocal((vertices.get(meshIndex).get(vertIndex + 2).x - store.x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).y - store.y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).z - store.z) * moveFactor);
    normal.set(normals.get(meshIndex).get(faceIndex));
}
 
Example 6
Source File: ConstraintDefinitionSizeLike.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void bake(Transform ownerTransform, Transform targetTransform, float influence) {
    Vector3f ownerScale = ownerTransform.getScale();
    Vector3f targetScale = targetTransform.getScale();

    Vector3f offset = Vector3f.ZERO;
    if ((flag & LOCLIKE_OFFSET) != 0) {// we add the original scale to the
                                       // copied scale
        offset = ownerScale.clone();
    }

    if ((flag & SIZELIKE_X) != 0) {
        ownerScale.x = targetScale.x * influence + (1.0f - influence) * ownerScale.x;
    }
    if ((flag & SIZELIKE_Y) != 0) {
        ownerScale.y = targetScale.y * influence + (1.0f - influence) * ownerScale.y;
    }
    if ((flag & SIZELIKE_Z) != 0) {
        ownerScale.z = targetScale.z * influence + (1.0f - influence) * ownerScale.z;
    }
    ownerScale.addLocal(offset);
}
 
Example 7
Source File: WorldOfInception.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Geometry getRandomBall(Vector3f location) {
    Vector3f localLocation = new Vector3f();
    localLocation.set(location);
    localLocation.addLocal(new Vector3f(random.nextFloat() - 0.5f, random.nextFloat() - 0.5f, random.nextFloat() - 0.5f).normalize().mult(3));
    Geometry poiGeom = new Geometry("ball", ballMesh);
    poiGeom.setLocalTranslation(localLocation);
    poiGeom.setMaterial(ballMaterial);
    RigidBodyControl control = new RigidBodyControl(ballCollisionShape, 1);
    //!!! Important
    control.setApplyPhysicsLocal(true);
    poiGeom.addControl(control);
    float x = (random.nextFloat() - 0.5f) * 100;
    float y = (random.nextFloat() - 0.5f) * 100;
    float z = (random.nextFloat() - 0.5f) * 100;
    control.setLinearVelocity(new Vector3f(x, y, z));
    return poiGeom;
}
 
Example 8
Source File: EditorAudioNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Update position and rotation of a model.
 */
@JmeThread
public void updateModel() {

    final AudioNode audioNode = getAudioNode();
    final Node model = getModel();
    if (model == null || audioNode == null) return;

    final Node parent = audioNode.getParent();

    if (parent != null) {
        setLocalTranslation(parent.getWorldTranslation());
        setLocalRotation(parent.getWorldRotation());
        setLocalScale(parent.getWorldScale());
    }

    final Node editedNode = getEditedNode();
    final LocalObjects local = LocalObjects.get();
    final Vector3f positionOnCamera = local.nextVector();
    positionOnCamera.set(editedNode.getWorldTranslation()).subtractLocal(camera.getLocation());
    positionOnCamera.normalizeLocal();
    positionOnCamera.multLocal(camera.getFrustumNear() + 0.4f);
    positionOnCamera.addLocal(camera.getLocation());

    model.setLocalTranslation(positionOnCamera);
    model.setLocalRotation(editedNode.getLocalRotation());
}
 
Example 9
Source File: EmitterMeshFaceShape.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * This method fills the point with coordinates of randomly selected point on a random face.
 * @param store
 *        the variable to store with coordinates of randomly selected selected point on a random face
 */
@Override
public void getRandomPoint(Vector3f store) {
    int meshIndex = FastMath.nextRandomInt(0, vertices.size() - 1);
    // the index of the first vertex of a face (must be dividable by 3)
    int vertIndex = FastMath.nextRandomInt(0, vertices.get(meshIndex).size() / 3 - 1) * 3;
    // put the point somewhere between the first and the second vertex of a face
    float moveFactor = FastMath.nextRandomFloat();
    store.set(Vector3f.ZERO);
    store.addLocal(vertices.get(meshIndex).get(vertIndex));
    store.addLocal((vertices.get(meshIndex).get(vertIndex + 1).x - vertices.get(meshIndex).get(vertIndex).x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).y - vertices.get(meshIndex).get(vertIndex).y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).z - vertices.get(meshIndex).get(vertIndex).z) * moveFactor);
    // move the result towards the last face vertex
    moveFactor = FastMath.nextRandomFloat();
    store.addLocal((vertices.get(meshIndex).get(vertIndex + 2).x - store.x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).y - store.y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).z - store.z) * moveFactor);
}
 
Example 10
Source File: WorldOfInception.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void scaleAsParent(float percent, Vector3f playerPos, Vector3f dist) {
    float scale = mapValue(percent, 1.0f, poiRadius);
    Vector3f distToHorizon = dist.subtract(dist.normalize());
    Vector3f offLocation = playerPos.add(distToHorizon);
    Vector3f rootOff = offLocation.mult(scale).negate();
    rootOff.addLocal(dist);
    debugTools.setGreenArrow(Vector3f.ZERO, offLocation);
    getRootNode().setLocalScale(scale);
    getRootNode().setLocalTranslation(rootOff);
}
 
Example 11
Source File: RollingTheMonkey.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf) {
    // Update and position the score
    scoreText.setText("Score: " + score);
    scoreText.setLocalTranslation((cam.getWidth() - scoreText.getLineWidth()) / 2.0f,
            scoreText.getLineHeight(), 0.0f);
    
    // Rotate all the pickups
    float pickUpSpeed = PICKUP_SPEED * tpf;
    for(Spatial pickUp : pickUps.getChildren()) {
        pickUp.rotate(pickUpSpeed, pickUpSpeed, pickUpSpeed);
    }
    
    Vector3f centralForce = new Vector3f();
    
    if(keyForward) centralForce.addLocal(cam.getDirection());
    if(keyBackward) centralForce.addLocal(cam.getDirection().negate());
    if(keyLeft) centralForce.addLocal(cam.getLeft());
    if(keyRight) centralForce.addLocal(cam.getLeft().negate());
    
    if(!Vector3f.ZERO.equals(centralForce)) {
        centralForce.setY(0);                   // stop ball from pusing down or flying up
        centralForce.normalizeLocal();          // normalize force
        centralForce.multLocal(PLAYER_FORCE);   // scale vector to force

        player.applyCentralForce(centralForce); // apply force to player
    }
    
    cam.lookAt(player.getPhysicsLocation(), Vector3f.UNIT_Y);
}
 
Example 12
Source File: FlyByCamera.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void riseCamera(float value){
    Vector3f vel = new Vector3f(0, value * moveSpeed, 0);
    Vector3f pos = cam.getLocation().clone();

    if (motionAllowed != null)
        motionAllowed.checkMotionAllowed(pos, vel);
    else
        pos.addLocal(vel);

    cam.setLocation(pos);
}
 
Example 13
Source File: TangentBinormalGenerator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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.capacity() * 2);
    FloatBuffer lineColor = BufferUtils.createFloatBuffer(vertexBuffer.capacity() / 3 * 4 * 2);

    for (int i = 0; i < vertexBuffer.capacity() / 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;
}
 
Example 14
Source File: EmitterMeshFaceShape.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * This method fills the point with coordinates of randomly selected point on a random face.
 * @param store
 *        the variable to store with coordinates of randomly selected selected point on a random face
 */
@Override
public void getRandomPoint(Vector3f store) {
    int meshIndex = FastMath.nextRandomInt(0, vertices.size() - 1);
    // the index of the first vertex of a face (must be dividable by 3)
    int vertIndex = FastMath.nextRandomInt(0, vertices.get(meshIndex).size() / 3 - 1) * 3;
    // put the point somewhere between the first and the second vertex of a face
    float moveFactor = FastMath.nextRandomFloat();
    store.set(Vector3f.ZERO);
    store.addLocal(vertices.get(meshIndex).get(vertIndex));
    store.addLocal((vertices.get(meshIndex).get(vertIndex + 1).x - vertices.get(meshIndex).get(vertIndex).x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).y - vertices.get(meshIndex).get(vertIndex).y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 1).z - vertices.get(meshIndex).get(vertIndex).z) * moveFactor);
    // move the result towards the last face vertex
    moveFactor = FastMath.nextRandomFloat();
    store.addLocal((vertices.get(meshIndex).get(vertIndex + 2).x - store.x) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).y - store.y) * moveFactor, (vertices.get(meshIndex).get(vertIndex + 2).z - store.z) * moveFactor);
}
 
Example 15
Source File: AdvancedAbstractEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Move a camera to direction.
 *
 * @param value the value to move.
 */
@JmeThread
private void moveDirectionCamera(final float value, final boolean isAction, final boolean isPressed, final int key) {

    if (!canCameraMove()) {
        return;
    } else if (isAction && isPressed) {
        startCameraMoving(key);
    } else if (isAction) {
        finishCameraMoving(key, false);
    }

    if (!isCameraMoving() || isAction) {
        return;
    }

    final EditorCamera editorCamera = getEditorCamera();
    if (editorCamera == null) {
        return;
    }

    final Camera camera = EditorUtil.getGlobalCamera();
    final Node nodeForCamera = getNodeForCamera();

    final LocalObjects local = LocalObjects.get();
    final Vector3f direction = camera.getDirection(local.nextVector());
    direction.multLocal(value * cameraSpeed);
    direction.addLocal(nodeForCamera.getLocalTranslation());

    nodeForCamera.setLocalTranslation(direction);
}
 
Example 16
Source File: LODGeomap.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public FloatBuffer writeNormalArray(FloatBuffer store, Vector3f scale) {
    if (!isLoaded()) {
        throw new NullPointerException();
    }

    if (store != null) {
        if (store.remaining() < getWidth() * getHeight() * 3) {
            throw new BufferUnderflowException();
        }
    } else {
        store = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3);
    }
    store.rewind();

    TempVars vars = TempVars.get();
    
    Vector3f rootPoint = vars.vect1;
    Vector3f rightPoint = vars.vect2;
    Vector3f leftPoint = vars.vect3;
    Vector3f topPoint = vars.vect4;
    Vector3f bottomPoint = vars.vect5;
    
    Vector3f tmp1 = vars.vect6;

    // calculate normals for each polygon
    for (int r = 0; r < getHeight(); r++) {
        for (int c = 0; c < getWidth(); c++) {

            rootPoint.set(0, getValue(c, r), 0);
            Vector3f normal = vars.vect8;

            if (r == 0) { // first row
                if (c == 0) { // first column
                    rightPoint.set(1, getValue(c + 1, r), 0);
                    bottomPoint.set(0, getValue(c, r + 1), 1);
                    getNormal(bottomPoint, rootPoint, rightPoint, scale, normal);
                } else if (c == getWidth() - 1) { // last column
                    leftPoint.set(-1, getValue(c - 1, r), 0);
                    bottomPoint.set(0, getValue(c, r + 1), 1);
                    getNormal(leftPoint, rootPoint, bottomPoint, scale, normal);
                } else { // all middle columns
                    leftPoint.set(-1, getValue(c - 1, r), 0);
                    rightPoint.set(1, getValue(c + 1, r), 0);
                    bottomPoint.set(0, getValue(c, r + 1), 1);
                    
                    normal.set( getNormal(leftPoint, rootPoint, bottomPoint, scale, tmp1) );
                    normal.addLocal( getNormal(bottomPoint, rootPoint, rightPoint, scale, tmp1) );
                }
            } else if (r == getHeight() - 1) { // last row
                if (c == 0) { // first column
                    topPoint.set(0, getValue(c, r - 1), -1);
                    rightPoint.set(1, getValue(c + 1, r), 0);
                    getNormal(rightPoint, rootPoint, topPoint, scale, normal);
                } else if (c == getWidth() - 1) { // last column
                    topPoint.set(0, getValue(c, r - 1), -1);
                    leftPoint.set(-1, getValue(c - 1, r), 0);
                    getNormal(topPoint, rootPoint, leftPoint, scale, normal);
                } else { // all middle columns
                    topPoint.set(0, getValue(c, r - 1), -1);
                    leftPoint.set(-1, getValue(c - 1, r), 0);
                    rightPoint.set(1, getValue(c + 1, r), 0);
                    
                    normal.set( getNormal(topPoint, rootPoint, leftPoint, scale, tmp1) );
                    normal.addLocal( getNormal(rightPoint, rootPoint, topPoint, scale, tmp1) );
                }
            } else { // all middle rows
                if (c == 0) { // first column
                    topPoint.set(0, getValue(c, r - 1), -1);
                    rightPoint.set(1, getValue(c + 1, r), 0);
                    bottomPoint.set(0, getValue(c, r + 1), 1);
                    
                    normal.set( getNormal(rightPoint, rootPoint, topPoint, scale, tmp1) );
                    normal.addLocal( getNormal(bottomPoint, rootPoint, rightPoint, scale, tmp1) );
                } else if (c == getWidth() - 1) { // last column
                    topPoint.set(0, getValue(c, r - 1), -1);
                    leftPoint.set(-1, getValue(c - 1, r), 0);
                    bottomPoint.set(0, getValue(c, r + 1), 1);

                    normal.set( getNormal(topPoint, rootPoint, leftPoint, scale, tmp1) );
                    normal.addLocal( getNormal(leftPoint, rootPoint, bottomPoint, scale, tmp1) );
                } else { // all middle columns
                    topPoint.set(0, getValue(c, r - 1), -1);
                    leftPoint.set(-1, getValue(c - 1, r), 0);
                    rightPoint.set(1, getValue(c + 1, r), 0);
                    bottomPoint.set(0, getValue(c, r + 1), 1);
                    
                    normal.set( getNormal(topPoint,  rootPoint, leftPoint, scale, tmp1 ) );
                    normal.addLocal( getNormal(leftPoint, rootPoint, bottomPoint, scale, tmp1) );
                    normal.addLocal( getNormal(bottomPoint, rootPoint, rightPoint, scale, tmp1) );
                    normal.addLocal( getNormal(rightPoint, rootPoint, topPoint, scale, tmp1) );
                }
            }
            normal.normalizeLocal();
            BufferUtils.setInBuffer(normal, store, (r * getWidth() + c)); // save the normal
        }
    }
    vars.release();
    
    return store;
}
 
Example 17
Source File: ScaleToolControl.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@JmeThread
@Override
public void processTransform() {

    final EditorTransformSupport editorControl = getEditorControl();

    final LocalObjects local = LocalObjects.get();
    final Camera camera = editorControl.getCamera();
    final InputManager inputManager = EditorUtil.getInputManager();
    final Transform transform = notNull(editorControl.getTransformCenter());

    // cursor position and selected position vectors
    final Vector2f cursorPos = inputManager.getCursorPosition();
    final Vector3f transformOnScreen = camera.getScreenCoordinates(transform.getTranslation(), local.nextVector());
    final Vector2f selectedCoords = local.nextVector(transformOnScreen.getX(), transformOnScreen.getY());

    // set new deltaVector if it's not set (scale tool stores position of a cursor)
    if (Float.isNaN(editorControl.getTransformDeltaX())) {
        editorControl.setTransformDeltaX(cursorPos.getX());
        editorControl.setTransformDeltaY(cursorPos.getY());
    }

    final Node parentNode = getParentNode();
    final Node childNode = getChildNode();

    // Picked vector
    final Spatial toTransform = notNull(editorControl.getToTransform());
    final TransformationMode transformationMode = editorControl.getTransformationMode();
    transformationMode.prepareToScale(parentNode, childNode, transform, camera);

    // scale according to distance
    final Vector3f deltaVector = local.nextVector(editorControl.getTransformDeltaX(), editorControl.getTransformDeltaY(), 0F);
    final Vector2f delta2d = local.nextVector(deltaVector.getX(), deltaVector.getY());
    final Vector3f baseScale = local.nextVector(transform.getScale()); // default scale
    final Vector3f pickedVector = local.nextVector(transformationMode.getScaleAxis(transform, editorControl.getPickedAxis(), camera));
    pickedVector.setX(abs(pickedVector.getX()));
    pickedVector.setY(abs(pickedVector.getY()));
    pickedVector.setZ(abs(pickedVector.getZ()));

    if (Config.DEV_TRANSFORMS_DEBUG) {
        System.out.println("Base scale " + baseScale + ", pickedVector " + pickedVector);
    }

    // scale object
    float disCursor = cursorPos.distance(selectedCoords);
    float disDelta = delta2d.distance(selectedCoords);
    float scaleValue = (float) (cursorPos.distance(delta2d) * 0.01f * Math.sqrt(baseScale.length()));

    if (disCursor > disDelta) {
        baseScale.addLocal(pickedVector.mult(scaleValue, local.nextVector()));
    } else {
        scaleValue = Math.min(scaleValue, 0.999f); // remove negateve values
        baseScale.subtractLocal(pickedVector.mult(scaleValue, local.nextVector()));
    }

    parentNode.setLocalScale(baseScale);

    if (Config.DEV_TRANSFORMS_DEBUG) {
        System.out.println("New scale " + baseScale + ", result world " + childNode.getWorldScale());
    }

    parentNode.setLocalScale(baseScale);
    toTransform.setLocalScale(childNode.getWorldScale());

    editorControl.notifyTransformed(toTransform);
}
 
Example 18
Source File: BasicShadowRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void postQueue(RenderQueue rq) {
        GeometryList occluders = rq.getShadowQueueContent(ShadowMode.Cast);
        if (occluders.size() == 0) {
            noOccluders = true;
            return;
        } else {
            noOccluders = false;
        }

        GeometryList receivers = rq.getShadowQueueContent(ShadowMode.Receive);

        // update frustum points based on current camera
        Camera viewCam = viewPort.getCamera();
        ShadowUtil.updateFrustumPoints(viewCam,
                viewCam.getFrustumNear(),
                viewCam.getFrustumFar(),
                1.0f,
                points);

        Vector3f frustaCenter = new Vector3f();
        for (Vector3f point : points) {
            frustaCenter.addLocal(point);
        }
        frustaCenter.multLocal(1f / 8f);

        // update light direction
        shadowCam.setProjectionMatrix(null);
        shadowCam.setParallelProjection(true);
//        shadowCam.setFrustumPerspective(45, 1, 1, 20);

        shadowCam.lookAtDirection(direction, Vector3f.UNIT_Y);
        shadowCam.update();
        shadowCam.setLocation(frustaCenter);
        shadowCam.update();
        shadowCam.updateViewProjection();

        // render shadow casters to shadow map
        ShadowUtil.updateShadowCamera(occluders, receivers, shadowCam, points);

        Renderer r = renderManager.getRenderer();
        renderManager.setCamera(shadowCam, false);
        renderManager.setForcedMaterial(preshadowMat);

        r.setFrameBuffer(shadowFB);
        r.clearBuffers(false, true, false);
        viewPort.getQueue().renderShadowQueue(ShadowMode.Cast, renderManager, shadowCam, true);
        r.setFrameBuffer(viewPort.getOutputFrameBuffer());

        renderManager.setForcedMaterial(null);
        renderManager.setCamera(viewCam, false);
    }
 
Example 19
Source File: BufferUtils.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Add to a Vector3f in-buffer.
 *
 * @param toAdd
 *            the vector to add from
 * @param buf
 *            the buffer to find the Vector3f within
 * @param index
 *            the position (in terms of vectors, not floats) of the vector
 *            to add to
 */
public static void addInBuffer(Vector3f toAdd, FloatBuffer buf, int index) {
    TempVars vars = TempVars.get();
    Vector3f tempVec3 = vars.vect1;
    populateFromBuffer(tempVec3, buf, index);
    tempVec3.addLocal(toAdd);
    setInBuffer(tempVec3, buf, index);
    vars.release();
}
 
Example 20
Source File: CurvesHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * the method applies scale for the given bevel points. The points table is
 * being modified so expect ypur result there.
 * 
 * @param points
 *            the bevel points
 * @param centerPoint
 *            the center point of the bevel
 * @param scale
 *            the scale to be applied
 */
private void applyScale(Vector3f[] points, Vector3f centerPoint, float scale) {
    Vector3f taperScaleVector = new Vector3f();
    for (Vector3f p : points) {
        taperScaleVector.set(centerPoint).subtractLocal(p).multLocal(1 - scale);
        p.addLocal(taperScaleVector);
    }
}