Java Code Examples for com.jme3.math.Vector3f#equals()
The following examples show how to use
com.jme3.math.Vector3f#equals() .
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: AudioListenerState.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void render(RenderManager rm) { if (!isEnabled() || listener == null) { return; } Vector3f lastLocation = listener.getLocation(); Vector3f currentLocation = camera.getLocation(); Vector3f velocity = listener.getVelocity(); if (!lastLocation.equals(currentLocation)) { velocity.set(currentLocation).subtractLocal(lastLocation); velocity.multLocal(1f / lastTpf); listener.setLocation(currentLocation); listener.setVelocity(velocity); } else if (!velocity.equals(Vector3f.ZERO)) { listener.setVelocity(Vector3f.ZERO); } Quaternion lastRotation = listener.getRotation(); Quaternion currentRotation = camera.getRotation(); if (!lastRotation.equals(currentRotation)) { listener.setRotation(currentRotation); } }
Example 2
Source File: AbstractCameraController.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
protected void rotateCamera(Vector3f axis, float amount) { if (axis.equals(cam.getLeft())) { float elevation = -FastMath.asin(cam.getDirection().y); amount = Math.min(Math.max(elevation + amount, -FastMath.HALF_PI), FastMath.HALF_PI) - elevation; } rot.fromAngleAxis(amount, axis); cam.getLocation().subtract(focus, vector); rot.mult(vector, vector); focus.add(vector, cam.getLocation()); Quaternion curRot = cam.getRotation().clone(); cam.setRotation(rot.mult(curRot)); java.awt.EventQueue.invokeLater(new Runnable() { public void run() { SceneViewerTopComponent svtc = SceneViewerTopComponent.findInstance(); if (svtc != null) { CameraToolbar.getInstance().switchToView(View.User); } } }); }
Example 3
Source File: TerrainLodControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private boolean lastCameraLocationsTheSame(List<Vector3f> locations) { boolean theSame = true; for (Vector3f l : locations) { for (Vector3f v : lastCameraLocations) { if (!v.equals(l) ) { theSame = false; return false; } } } return theSame; }
Example 4
Source File: SpawnPaintingStateWithEditorTool.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Set the models min scale. * * @param minScale the models min scale. */ @FxThread public void setMinScale(@NotNull Vector3f minScale) { final boolean changed = !minScale.equals(getMinScale()); this.minScale = minScale; if (changed) notifyChange(); }
Example 5
Source File: SpawnPaintingStateWithEditorTool.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Set the models max scale. * * @param maxScale the models max scale. */ @FxThread public void setMaxScale(@NotNull Vector3f maxScale) { final boolean changed = !maxScale.equals(getMaxScale()); this.maxScale = maxScale; if (changed) notifyChange(); }
Example 6
Source File: SpawnPaintingStateWithEditorTool.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Set the models padding. * * @param padding the models padding. */ @FxThread public void setPadding(@NotNull Vector3f padding) { final boolean changed = !padding.equals(getPadding()); this.padding = padding; if (changed) notifyChange(); }
Example 7
Source File: SphereWanderBehavior.java From MonkeyBrains with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Metod for changing target position. * * @param tpf time per frame */ protected void changeTargetPosition(float tpf) { time -= tpf; Vector3f forward; if (this.agent.getVelocity() != null) { forward = this.agent.getVelocity().normalize(); } else { forward = this.agent.fordwardVector(); } if (forward.equals(Vector3f.UNIT_Y)) { forward = forward.add(new Vector3f(0, 0, SphereWanderBehavior.SIDE_REFERENCE_OFFSET)); } //Update sphere position this.wanderSphere.setCenter(this.agent.getLocalTranslation().add(forward.mult(SphereWanderBehavior.OFFSET_DISTANCE + this.agent.getRadius() + this.sphereRadius))); if (time <= 0) { this.calculateNewRandomDir(); time = timeInterval; } Vector3f sideVector = forward.cross(Vector3f.UNIT_Y).normalize(); Vector3f rayDir = (this.agent.offset(wanderSphere.getCenter())).add(sideVector.mult(this.randomDirection.x));//.add(Vector3f.UNIT_Y.mult(this.randomDirection.y)); Ray ray = new Ray(this.agent.getLocalTranslation(), rayDir); CollisionResults results = new CollisionResults(); this.wanderSphere.collideWith(ray, results); CollisionResult collisionResult = results.getCollision(1); //The collision with the second hemisphere this.targetPosition = collisionResult.getContactPoint(); }
Example 8
Source File: AbstractStrengthSteeringBehavior.java From MonkeyBrains with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Calculates the steering force with the specified strength. <br><br> * * If the strength was not setted up it the return calculateSteering(), the * unmodified force. * * @return The steering force with the specified strength. */ @Override protected Vector3f calculateSteering() { Vector3f strengthSteeringForce = calculateRawSteering(); switch (this.type) { case SCALAR: strengthSteeringForce = strengthSteeringForce.mult(this.scalar); break; case AXIS: strengthSteeringForce.setX(strengthSteeringForce.getX() * this.x); strengthSteeringForce.setY(strengthSteeringForce.getY() * this.y); strengthSteeringForce.setZ(strengthSteeringForce.getZ() * this.z); break; case PLANE: strengthSteeringForce = this.plane.getClosestPoint(strengthSteeringForce).mult(this.scalar); break; } //if there is no steering force, than the steering vector is zero if (strengthSteeringForce.equals(Vector3f.NAN)) { strengthSteeringForce = Vector3f.ZERO.clone(); } return strengthSteeringForce; }
Example 9
Source File: QueuingBehavior.java From MonkeyBrains with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @see AbstractStrengthSteeringBehavior#calculateRawSteering() */ @Override protected Vector3f calculateRawSteering() { Vector3f agentVelocity = this.agent.getVelocity(); int numberObstaclesFactor = 1; float distanceFactor = 1; float velocityFactor = 1; if (agentVelocity != null && !agentVelocity.equals(Vector3f.ZERO)) { for (Agent neighbour : this.neighbours) { Vector3f neighVel = neighbour.getVelocity(); float fordwardness = this.agent.forwardness(neighbour); float velDiff; float distance; if (neighbour != this.agent && (distance = this.agent.distanceRelativeToGameEntity(neighbour)) < this.minDistance && fordwardness > 0 && neighVel != null && (velDiff = neighVel.length() - agentVelocity.length()) < 0) { distanceFactor *= distance / this.minDistance; velocityFactor *= -velDiff / this.agent.getMoveSpeed(); numberObstaclesFactor++; } } } this.setBrakingFactor((distanceFactor + velocityFactor + (1 / numberObstaclesFactor)) / 3); return new Vector3f(); }
Example 10
Source File: BillboardControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Aligns this Billboard so that it points to the camera position. * * @param camera * Camera */ private void rotateCameraAligned(Camera camera) { look.set(camera.getLocation()).subtractLocal( spatial.getWorldTranslation()); // coopt left for our own purposes. Vector3f xzp = left; // The xzp vector is the projection of the look vector on the xz plane xzp.set(look.x, 0, look.z); // check for undefined rotation... if (xzp.equals(Vector3f.ZERO)) { return; } look.normalizeLocal(); xzp.normalizeLocal(); float cosp = look.dot(xzp); // compute the local orientation matrix for the billboard orient.set(0, 0, xzp.z); orient.set(0, 1, xzp.x * -look.y); orient.set(0, 2, xzp.x * cosp); orient.set(1, 0, 0); orient.set(1, 1, cosp); orient.set(1, 2, look.y); orient.set(2, 0, -xzp.x); orient.set(2, 1, xzp.z * -look.y); orient.set(2, 2, xzp.z * cosp); // The billboard must be oriented to face the camera before it is // transformed into the world. spatial.setLocalRotation(orient); fixRefreshFlags(); }
Example 11
Source File: MikktspaceTangentGenerator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
static void MergeVertsSlow(int piTriList_in_and_out[], final MikkTSpaceContext mikkTSpace, final int pTable[], final int iEntries) { // this can be optimized further using a tree structure or more hashing. for (int e = 0; e < iEntries; e++) { int i = pTable[e]; final int index = piTriList_in_and_out[i]; final Vector3f vP = getPosition(mikkTSpace, index); final Vector3f vN = getNormal(mikkTSpace, index); final Vector3f vT = getTexCoord(mikkTSpace, index); boolean bNotFound = true; int e2 = 0, i2rec = -1; while (e2 < e && bNotFound) { final int i2 = pTable[e2]; final int index2 = piTriList_in_and_out[i2]; final Vector3f vP2 = getPosition(mikkTSpace, index2); final Vector3f vN2 = getNormal(mikkTSpace, index2); final Vector3f vT2 = getTexCoord(mikkTSpace, index2); i2rec = i2; if (vP.equals(vP2) && vN.equals(vN2) && vT.equals(vT2)) { bNotFound = false; } else { ++e2; } } // merge if previously found if (!bNotFound) { piTriList_in_and_out[i] = piTriList_in_and_out[i2rec]; } } }
Example 12
Source File: BillboardControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Aligns this Billboard so that it points to the camera position. * * @param camera * Camera */ private void rotateCameraAligned(Camera camera) { look.set(camera.getLocation()).subtractLocal( spatial.getWorldTranslation()); // coopt left for our own purposes. Vector3f xzp = left; // The xzp vector is the projection of the look vector on the xz plane xzp.set(look.x, 0, look.z); // check for undefined rotation... if (xzp.equals(Vector3f.ZERO)) { return; } look.normalizeLocal(); xzp.normalizeLocal(); float cosp = look.dot(xzp); // compute the local orientation matrix for the billboard orient.set(0, 0, xzp.z); orient.set(0, 1, xzp.x * -look.y); orient.set(0, 2, xzp.x * cosp); orient.set(1, 0, 0); orient.set(1, 1, cosp); orient.set(1, 2, look.y); orient.set(2, 0, -xzp.x); orient.set(2, 1, xzp.z * -look.y); orient.set(2, 2, xzp.z * cosp); // The billboard must be oriented to face the camera before it is // transformed into the world. spatial.setLocalRotation(orient); fixRefreshFlags(); }
Example 13
Source File: ApplyScaleToPhysicsControlsHandler.java From jmonkeybuilder with Apache License 2.0 | 4 votes |
@JmeThread protected boolean isChanged(@NotNull final Spatial sp) { final Vector3f prevScale = previousScales.remove(sp); return prevScale != null && !prevScale.equals(sp.getWorldScale()); }
Example 14
Source File: ObstacleAvoidanceBehavior.java From MonkeyBrains with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * @see AbstractSteeringBehavior#calculateSteering() */ @Override protected Vector3f calculateRawSteering() { Vector3f nearestObstacleSteerForce = new Vector3f(); if (this.agent.getVelocity() != null) { float agentVel = this.agent.getVelocity().length(); float minDistanceToCollision = agentVel * timePerFrame * this.minTimeToCollision; // test all obstacles for intersection with my forward axis, // select the one whose intersection is nearest for (GameEntity obstacle : this.obstacles) { float distanceFromCenterToCenter = this.agent.distanceRelativeToGameEntity(obstacle); if (distanceFromCenterToCenter > this.minDistance) { break; } float distanceFromCenterToObstacleSuperf = distanceFromCenterToCenter - obstacle.getRadius(); float distance = distanceFromCenterToObstacleSuperf - this.agent.getRadius(); if (distanceFromCenterToObstacleSuperf < 0) { distanceFromCenterToObstacleSuperf = 0; } if (distance < 0) { distance = 0; } // if it is at least in the radius of the collision cylinder and we are facing the obstacle if (this.agent.forwardness(obstacle) > 0 && //Are we facing the obstacle ? distance * distance < ((minDistanceToCollision * minDistanceToCollision) + (this.agent.getRadius() * this.agent.getRadius())) //Pythagoras Theorem ) { Vector3f velocityNormalized = this.agent.getVelocity().normalize(); Vector3f distanceVec = this.agent.offset(obstacle).normalize().mult(distanceFromCenterToObstacleSuperf); Vector3f projectedVector = velocityNormalized.mult(velocityNormalized.dot(distanceVec)); Vector3f collisionDistanceOffset = projectedVector.subtract(distanceVec); if (collisionDistanceOffset.length() < this.agent.getRadius()) { Vector3f collisionDistanceDirection; if (!collisionDistanceOffset.equals(Vector3f.ZERO)) { collisionDistanceDirection = collisionDistanceOffset.normalize(); } else { collisionDistanceDirection = randomVectInPlane(this.agent.getVelocity(), this.agent.getLocalTranslation()).normalize(); } Vector3f steerForce = collisionDistanceDirection.mult((this.agent.getRadius() - collisionDistanceOffset.length()) / this.agent.getRadius()); if (steerForce.length() > nearestObstacleSteerForce.length()) { nearestObstacleSteerForce = steerForce; } } } } } return nearestObstacleSteerForce; }
Example 15
Source File: AdvancedAbstractEditor3DPart.java From jmonkeybuilder with Apache License 2.0 | 4 votes |
/** * Check camera changes. * * @param editorCamera the editor camera */ @JmeThread protected void checkCameraChanges(@NotNull final EditorCamera editorCamera) { int changes = 0; final Node nodeForCamera = getNodeForCamera(); final Vector3f prevCameraLocation = getPrevCameraLocation(); final Vector3f cameraLocation = nodeForCamera.getLocalTranslation(); final float prevHRotation = getPrevHRotation(); final float hRotation = editorCamera.getHorizontalRotation(); final float prevVRotation = getPrevVRotation(); final float vRotation = editorCamera.getVerticalRotation(); final float prevTargetDistance = getPrevTargetDistance(); final float targetDistance = editorCamera.getTargetDistance(); final float cameraSpeed = getCameraSpeed(); final float prevCameraSpeed = getPrevCameraSpeed(); if (!prevCameraLocation.equals(cameraLocation)) { changes++; } else if (prevHRotation != hRotation || prevVRotation != vRotation) { changes++; } else if (prevTargetDistance != targetDistance) { changes++; } else if (cameraSpeed != prevCameraSpeed) { changes++; } if (changes > 0) { notifyChangedCameraSettings(cameraLocation, hRotation, vRotation, targetDistance, cameraSpeed); } prevCameraLocation.set(cameraLocation); setPrevHRotation(hRotation); setPrevVRotation(vRotation); setPrevTargetDistance(targetDistance); setPrevCameraSpeed(cameraSpeed); }
Example 16
Source File: BufferUtils.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 3 votes |
/** * Checks to see if the given Vector3f is equals to the data stored in the * buffer at the given data index. * * @param check * the vector to check against - null will return false. * @param buf * the buffer to compare data with * @param index * the position (in terms of vectors, not floats) of the vector * in the buffer to check against * @return */ public static boolean equals(Vector3f check, FloatBuffer buf, int index) { TempVars vars = TempVars.get(); Vector3f tempVec3 = vars.vect1; populateFromBuffer(tempVec3, buf, index); boolean eq = tempVec3.equals(check); vars.release(); return eq; }
Example 17
Source File: SphereCollisionShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Alter the scaling factors of this shape. Scaling is disabled * for sphere shapes. * * @param scale the desired scaling factor for each local axis (not null, no * negative component, unaffected, default=1,1,1) */ @Override public void setScale(Vector3f scale) { if (!scale.equals(Vector3f.UNIT_XYZ)) { Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "SphereCollisionShape cannot be scaled"); } }
Example 18
Source File: CylinderCollisionShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Alter the scaling factors of this shape. Scaling is disabled * for cylinder shapes. * * @param scale the desired scaling factor for each local axis (not null, no * negative component, unaffected, default=1,1,1) */ @Override public void setScale(Vector3f scale) { if (!scale.equals(Vector3f.UNIT_XYZ)) { Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "CylinderCollisionShape cannot be scaled"); } }
Example 19
Source File: CapsuleCollisionShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Alter the scaling factors of this shape. Scaling is disabled * for capsule shapes. * * @param scale the desired scaling factor for each local axis (not null, no * negative component, unaffected, default=1,1,1) */ @Override public void setScale(Vector3f scale) { if (!scale.equals(Vector3f.UNIT_XYZ)) { Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "CapsuleCollisionShape cannot be scaled"); } }
Example 20
Source File: BufferUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Checks to see if the given Vector3f is equals to the data stored in the * buffer at the given data index. * * @param check * the vector to check against - null will return false. * @param buf * the buffer to compare data with * @param index * the position (in terms of vectors, not floats) of the vector * in the buffer to check against * @return true if the data is equivalent, otherwise false. */ public static boolean equals(Vector3f check, FloatBuffer buf, int index) { TempVars vars = TempVars.get(); Vector3f tempVec3 = vars.vect1; populateFromBuffer(tempVec3, buf, index); boolean eq = tempVec3.equals(check); vars.release(); return eq; }