Skip to content

Commit

Permalink
Geometry: add 3 accessors for the orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Aug 24, 2023
1 parent 643dce4 commit 8624d51
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lib/src/main/java/com/github/stephengold/vsport/Geometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
package com.github.stephengold.vsport;

import com.jme3.bullet.CollisionSpace;
import com.jme3.math.Quaternion;
import java.nio.ByteBuffer;
import jme3utilities.Validate;
import org.joml.Matrix3fc;
Expand Down Expand Up @@ -319,6 +320,18 @@ public Quaternionf orientation(Quaternionf storeResult) {
return result;
}

/**
* Return a copy of the mesh-to-world coordinate rotation.
*
* @param storeResult storage for the result (modified if not null)
* @return a unit quaternion (either {@code storeResult} or a new
* quaternion)
*/
public Quaternion orientationJme(Quaternion storeResult) {
Quaternion result = uniformValues.orientationJme(storeResult);
return result;
}

/**
* Return the point size for sprites.
*
Expand Down Expand Up @@ -550,6 +563,20 @@ public Geometry setOrientation(Matrix3fc orientation) {
return this;
}

/**
* Alter the orientation without translating the mesh origin.
*
* @param orientation the desired orientation (not null, not zero,
* unaffected)
* @return the (modified) current geometry (for chaining)
*/
public Geometry setOrientation(Quaternion orientation) {
Validate.nonZero(orientation, "orientation");
uniformValues.setOrientationQuaternion(orientation.getX(),
orientation.getY(), orientation.getZ(), orientation.getW());
return this;
}

/**
* Alter the orientation without translating the mesh origin.
*
Expand All @@ -564,6 +591,33 @@ public Geometry setOrientation(Quaternionfc orientation) {
return this;
}

/**
* Alter the orientation without translating the mesh origin.
* <p>
* The arguments are assumed to form an orthonormal basis.
*
* @param xDir the desired direction of the mesh X axis (unit vector in
* world coordinates, not null, unaffected)
* @param yDir the desired direction of the mesh Y axis (unit vector in
* world coordinates, not null, unaffected)
* @param zDir the desired direction of the mesh Z axis (unit vector in
* world coordinates, not null, unaffected)
* @return the (modified) current geometry (for chaining)
*/
public Geometry setOrientation(com.jme3.math.Vector3f xDir,
com.jme3.math.Vector3f yDir, com.jme3.math.Vector3f zDir) {
Validate.nonZero(xDir, "x direction");
Validate.nonZero(yDir, "y direction");
Validate.nonZero(zDir, "z direction");

com.jme3.math.Quaternion q = new Quaternion();
q.fromAxes(xDir, yDir, zDir);
uniformValues.setOrientationQuaternion(
q.getX(), q.getY(), q.getZ(), q.getW());

return this;
}

/**
* Alter the point size for sprites.
*
Expand Down

0 comments on commit 8624d51

Please sign in to comment.