List of usage examples for java.lang Float max
public static float max(float a, float b)
From source file:fr.amap.viewer3d.object.camera.TrackballCamera.java
/** * * @param translation translation vector of camera *///from w w w .ja va 2 s. c om @Override public void translate(Vec3F translation) { float copyDistanceToTarget = getDistanceToTarget(); forwardVec = getForwardVector(); forwardVec = Vec3F.normalize(forwardVec); if (translation.x != 0.0f) { Vec3F sideShift = Vec3F.normalize(Vec3F.cross(up, forwardVec)); location = Vec3F.add(location, Vec3F.multiply(sideShift, translation.x)); //target = Vec3F.add(target, Vec3F.multiply(sideShift, translation.x)); } if (translation.y != 0.0f) { Vec3F verticalShift = up; location = Vec3F.add(location, Vec3F.multiply(verticalShift, translation.y)); //target = Vec3F.add(target, Vec3F.multiply(verticalShift, translation.y)); } if (translation.z != 0.0f) { if (perspective) { //target = Vec3F.add(target, Vec3F.multiply(orientation, translation.z)); //use for not reaching the target //setPerspective(70.0f, (1.0f*640)/480, near-translation.z, far-translation.z); } else { if ((left < -1.0f && right > 1.0f) || translation.z < 0) { float widthCoeff = viewportWidth / 100.0f; float heightCoeff = viewportHeight / 100.0f; float leftCopy = left; float rightCopy = right; float topCopy = top; float bottomCopy = bottom; left = left + translation.z * (widthCoeff); right = right - translation.z * (widthCoeff); bottom = bottom + translation.z * (heightCoeff); top = top - translation.z * (heightCoeff); if (left > -1 || right < 1 || bottom > -1 || top < 1) { left = leftCopy; right = rightCopy; bottom = bottomCopy; top = topCopy; } } //updateProjMatrix(); } //copy old location Vec3F oldForwardVector = getForwardVector(); Vec3F oldLocation = location; //test translation effect location = Vec3F.add(location, Vec3F.multiply(forwardVec, translation.z)); Vec3F newForwardVector = getForwardVector(); //if translation is not good, get back to the original location (equivalent to not move) if ((newForwardVector.z < 0 && oldForwardVector.z > 0) || (newForwardVector.z > 0 && oldForwardVector.z < 0)) { location = oldLocation; } } updateViewMatrix(); float distanceToTarget = getDistanceToTarget(); nearPersp = distanceToTarget - 500.0f; nearPersp = Float.max(nearPersp, 0.01f); farPersp = distanceToTarget + 500.0f; //nearOrtho = nearPersp; //farOrtho = farPersp; updateProjMatrix(); }