/** * Rotates this object (optionally from its initial orientation) around the provided axis by the * specified angle. * * @param axis {@link Vector3} The axis or rotation. * @param angle {@code double} The angle of rotation. * @param append {@code boolean} If true, the rotation is applied to the current orientation. */ public void rotateAround(Vector3 axis, double angle, boolean append) { if (append) { mTmpOrientation.fromAngleAxis(axis, angle); mOrientation.multiply(mTmpOrientation); } else { mOrientation.fromAngleAxis(axis, angle); } markModelMatrixDirty(); }
public Plane(Vector3 normal, double distance) { this.normal = normal; this.distance = distance; this.planeOrigin = normal.clone().multiply(distance); this.planeZRotation = normal.clone().getRotationTo(new Vector3(0, 0, 1)); this.inversePlaneZRotation = planeZRotation.clone().inverse(); }
/** * Sets the up axis for this {@link ATransformable3D} object. If this is part of a scene graph, * the graph will be notified of the change. * * @param x double The x component of the new up axis. * @param y double The y component of the new up axis. * @param z double The z component of the new up axis. * @return A reference to this {@link ATransformable3D} to facilitate chaining. */ public ATransformable3D setUpAxis(double x, double y, double z) { mUpAxis.setAll(x, y, z); if (mLookAtEnabled && mLookAtValid) { mOrientation.lookAt(mLookAt, mUpAxis); markModelMatrixDirty(); } return this; }
/** * Resets the up axis for this {@link ATransformable3D} object to the +Y axis. If this is part of * a scene graph, the graph will be notified of the change. * * @return A reference to this {@link ATransformable3D} to facilitate chaining. */ public ATransformable3D resetUpAxis() { mUpAxis.setAll(Vector3.getAxisVector(Vector3.Axis.Y)); if (mLookAtEnabled && mLookAtValid) { mOrientation.lookAt(mLookAt, mUpAxis); markModelMatrixDirty(); } return this; }
/** * Resets the orientation of this {@link ATransformable3D} object to look at its look at target * and use the specified {@link Vector3} as up. If this is part of a scene graph, the graph will * be notified of the change. * * @param upAxis {@link Vector3} The direction to use as the up axis. * @return A reference to this {@link ATransformable3D} to facilitate chaining. */ public ATransformable3D resetToLookAt(Vector3 upAxis) { mTempVec.subtractAndSet(mLookAt, mPosition); // In OpenGL, Cameras are defined such that their forward axis is -Z, not +Z like we have // defined objects. if (mIsCamera) mTempVec.inverse(); mOrientation.lookAt(mTempVec, upAxis); mLookAtValid = true; markModelMatrixDirty(); return this; }
public void setSensorOrientation(float[] quaternion) { synchronized (mCameraOrientationLock) { mCameraOrientation.x = quaternion[1]; mCameraOrientation.y = quaternion[2]; mCameraOrientation.z = quaternion[3]; mCameraOrientation.w = quaternion[0]; mScratchQuaternion1.fromAngleAxis(Axis.X, -90); mScratchQuaternion1.multiply(mCameraOrientation); mScratchQuaternion2.fromAngleAxis(Axis.Z, -90); mScratchQuaternion1.multiply(mScratchQuaternion2); mCameraOrientation.setAll(mScratchQuaternion1); } }
private void showHudPositionHelper(Quaternion currentOrientation) { final Vector3 movement = WorldParameters.FORWARD_AXIS.clone(); Quaternion relative = currentOrientation.clone(); movement.rotateBy(relative).multiply(3); movement.inverse(); centralPane.getPosition().add(movement); // TODO move off to the side. leftTopPlane.getPosition().add(movement); // leftBottomPlane.getPosition().add(movement); }
/** * Displays different heads-up display components. These are rendered on different planes which * are positioned depending on current camera position and orientation. */ private void showHudComponents() { Quaternion currentOrientation = getCurrentCamera().getOrientation(); Vector3 currentPosition = getCurrentCamera().getPosition(); showHudHelper(currentOrientation.clone(), currentPosition); showHudPositionHelper(currentOrientation); // Show points and remaining rockets. // int rockets = state.getTopLevelManager().getRocketsAvailable(); // int totalAsteroids = state.getAsteroidManager().getAsteroids().size(); Bitmap pointBitmap = drawTextToBitmap(state.displayString); Texture currentTexture = (Texture) leftTopPlane.getMaterial().getTextureList().get(0); currentTexture.getBitmap().recycle(); currentTexture.setBitmap(pointBitmap); getTextureManager().replaceTexture(currentTexture); // leftTopPlane.getMaterial().addTexture(new Texture("123", pointBitmap)); // TODO // Show remaining rockets. // TODO. }
private void createFloor() { // // -- Load a bitmap that represents the terrain. Its color values will // be used to generate heights. // Plane mPlane = new Plane(500, 500, 100, 100); mPlane.setPosition(0, 0, 0); mPlane.setDoubleSided(true); Material material1 = new Material(); material1.setColorInfluence(0); Bitmap picTexture = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.squares_big); try { material1.addTexture(new Texture("squares", picTexture)); } catch (TextureException e) { e.printStackTrace(); } mPlane.setMaterial(material1); // Set orientation of the plane. Quaternion q = new Quaternion(); q.fromAngleAxis(Vector3.Axis.X, 90); mPlane.setOrientation(q); getCurrentScene().addChild(mPlane); try { getCurrentScene() .setSkybox( R.drawable.right, R.drawable.left, R.drawable.top, R.drawable.bottom, R.drawable.front, R.drawable.back); } catch (TextureException e) { e.printStackTrace(); } }
private void showHudHelper(Quaternion orientation, Vector3 position) { Quaternion currentOrientation = orientation.clone(); // Central plane. centralPane.setOrientation(currentOrientation); centralPane.setPosition(position); getCurrentScene().removeChild(centralPane); getCurrentScene().addChild(centralPane); // Left top plane. leftTopPlane.setOrientation(currentOrientation); leftTopPlane.setPosition(position); getCurrentScene().removeChild(leftTopPlane); getCurrentScene().addChild(leftTopPlane); // Left bottom plane. leftBottomPlane.setOrientation(currentOrientation); leftBottomPlane.setPosition(position); getCurrentScene().removeChild(leftBottomPlane); getCurrentScene().addChild(leftBottomPlane); }
/** * Sets the rotation of this {@link ATransformable3D} by the rotation described by the provided * Euler angles. If this is part of a scene graph, the graph will be notified of the change. * * @param rotation {@link Vector3} whose components represent the Euler angles in degrees. X = * Roll, Y = Yaw, Z = Pitch. * @return A reference to this {@link ATransformable3D} to facilitate chaining. */ public ATransformable3D setRotation(Vector3 rotation) { mOrientation.fromEuler(rotation.y, rotation.z, rotation.x); mLookAtValid = false; markModelMatrixDirty(); return this; }
/** * Sets the rotation of this {@link ATransformable3D} by the rotation described by the provided * Euler angles. If this is part of a scene graph, the graph will be notified of the change. * * @param rotX double The roll angle in degrees. * @param rotY double The yaw angle in degrees. * @param rotZ double The pitch angle in degrees. * @return A reference to this {@link ATransformable3D} to facilitate chaining. */ public ATransformable3D setRotation(double rotX, double rotY, double rotZ) { mOrientation.fromEuler(rotY, rotZ, rotX); mLookAtValid = false; markModelMatrixDirty(); return this; }
public void setCameraOrientation(Quaternion cameraOrientation) { synchronized (mCameraOrientationLock) { mCameraOrientation.setAll(cameraOrientation); } }
/** * Adjusts the rotation of this {@link ATransformable3D} by the rotation described by the provided * Euler angle. If this is part of a scene graph, the graph will be notified of the change. * * @param rotZ double The pitch angle in degrees. * @return A reference to this {@link ATransformable3D} to facilitate chaining. */ public ATransformable3D setRotZ(double rotZ) { mOrientation.fromEuler(mOrientation.getYaw(), rotZ, mOrientation.getRoll()); mLookAtValid = false; markModelMatrixDirty(); return this; }
/** * Adjusts the rotation of this {@link ATransformable3D} by the rotation described by the provided * Euler angle. If this is part of a scene graph, the graph will be notified of the change. * * @param rotY double The yaw angle in degrees. * @return A reference to this {@link ATransformable3D} to facilitate chaining. */ public ATransformable3D setRotY(double rotY) { mOrientation.fromEuler(rotY, mOrientation.getPitch(), mOrientation.getRoll()); mLookAtValid = false; markModelMatrixDirty(); return this; }
/** * Gets the current orientation of this {@link ATransformable3D} object. * * @param quat {@link Quaternion} To copy the orientation into. * @return The provided {@link Quaternion} to facilitate chaining. */ public Quaternion getOrientation(Quaternion quat) { quat.setAll(mOrientation); return quat; }
/** * Sets the rotation of this {@link ATransformable3D} by the rotation described by the provided * {@link Matrix4}. If this is part of a scene graph, the graph will be notified of the change. * * @param matrix {@link Matrix4} describing the rotation to apply. * @return A reference to this {@link ATransformable3D} to facilitate chaining. */ public ATransformable3D setRotation(final Matrix4 matrix) { mOrientation.multiply(mTmpOrientation.fromMatrix(matrix)); mLookAtValid = false; markModelMatrixDirty(); return this; }
/** * Extracts the roll Euler angle from the current orientation. * * @return double The roll Euler angle. */ public double getRotX() { return mOrientation.getPitch(); }
/** * Extracts the pitch Euler angle from the current orientation. * * @return double The pitch Euler angle. */ public double getRotZ() { return mOrientation.getRoll(); }
/** * Extracts the yaw Euler angle from the current orientation. * * @return double The yaw Euler angle. */ public double getRotY() { return mOrientation.getYaw(); }
/** * Sets the rotation of this {@link ATransformable3D} by the rotation described by the provided * {@link Vector3.Axis} cardinal axis and angle of rotation. If this is part of a scene graph, the * graph will be notified of the change. * * @param axis {@link Vector3.Axis} The axis of rotation. * @param angle double The angle of rotation in degrees. * @return A reference to this {@link ATransformable3D} to facilitate chaining. */ public ATransformable3D setRotation(final Vector3.Axis axis, double angle) { mOrientation.multiply(mTmpOrientation.fromAngleAxis(axis, angle)); mLookAtValid = false; markModelMatrixDirty(); return this; }
/** * Sets the rotation of this {@link ATransformable3D} by the rotation described by the provided * axis and angle of rotation. If this is part of a scene graph, the graph will be notified of the * change. * * @param x double The x component of the axis of rotation. * @param y double The y component of the axis of rotation. * @param z double The z component of the axis of rotation. * @param angle double The angle of rotation in degrees. * @return A reference to this {@link ATransformable3D} to facilitate chaining. */ public ATransformable3D setRotation(double x, double y, double z, double angle) { mOrientation.multiply(mTmpOrientation.fromAngleAxis(x, y, z, angle)); mLookAtValid = false; markModelMatrixDirty(); return this; }
/** * Sets the orientation of this {@link ATransformable3D} object. * * @param quat {@link Quaternion} to copy the orientation from. The values of this object are * copied and the passed object is not retained. * @return A reference to this {@link ATransformable3D} to facilitate chaining. */ public ATransformable3D setOrientation(Quaternion quat) { mOrientation.setAll(quat); mLookAtValid = false; markModelMatrixDirty(); return this; }
/** * Rotates this {@link ATransformable3D} by the rotation described by the provided {@link * Quaternion}. If this is part of a scene graph, the graph will be notified of the change. * * @param quat {@link Quaternion} describing the additional rotation. * @return A reference to this {@link ATransformable3D} to facilitate chaining. */ public ATransformable3D rotate(final Quaternion quat) { mOrientation.multiply(quat); mLookAtValid = false; markModelMatrixDirty(); return this; }