diff --git a/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/Cursor.java b/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/Cursor.java index 199d1ac1e..f0fa96035 100644 --- a/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/Cursor.java +++ b/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/Cursor.java @@ -213,7 +213,7 @@ public void setPosition(float x, float y, float z) { /** * Get the current absolute x position of this {@link Cursor}. * - * @return the current x position of the {@link Cursor} + * @return the current x position of the {@link Cursor} */ public float getPositionX() { return cursorSceneObject.getPositionX(); @@ -231,12 +231,48 @@ public float getPositionY() { /** * Get the current absolute z position of this {@link Cursor}. * - * @return the current z position of the {@link Cursor} + * @return the current z position of the {@link Cursor} */ public float getPositionZ() { return cursorSceneObject.getPositionZ(); } + /** + * Get the current 'w' component of this {@link Cursor}'s rotation quaternion. + * + * @return the current 'w' component of this {@link Cursor}'s rotation quaternion. + */ + public float getRotationW() { + return cursorSceneObject.getRotationW(); + } + + /** + * Get the current 'x' component of this {@link Cursor}'s rotation quaternion. + * + * @return the current 'x' component of this {@link Cursor}'s rotation quaternion. + */ + public float getRotationX() { + return cursorSceneObject.getRotationX(); + } + + /** + * Get the current 'y' component of this {@link Cursor}'s rotation quaternion. + * + * @return the current 'y' component of this {@link Cursor}'s rotation quaternion. + */ + public float getRotationY() { + return cursorSceneObject.getRotationY(); + } + + /** + * Get the current 'z' component of this {@link Cursor}'s rotation quaternion. + * + * @return the current 'z' component of this {@link Cursor}'s rotation quaternion. + */ + public float getRotationZ() { + return cursorSceneObject.getRotationZ(); + } + /** * The method will force a process cycle that may result in an * {@link CursorEvent}s being generated if there is a significant event diff --git a/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/CursorEvent.java b/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/CursorEvent.java index 82f86136b..a6f48b874 100644 --- a/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/CursorEvent.java +++ b/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/CursorEvent.java @@ -19,6 +19,7 @@ import org.gearvrf.GVRBaseSensor; import org.gearvrf.GVRSceneObject; +import org.joml.Quaternionf; import org.joml.Vector3f; /** @@ -41,6 +42,9 @@ public class CursorEvent { private Cursor cursor; private KeyEvent keyEvent; + private Vector3f cursorPosition; + private Quaternionf cursorRotation; + // We take a leaf out of the MotionEvent book to implement linked // recycling of objects. private static final int MAX_RECYCLED = 5; @@ -52,6 +56,8 @@ public class CursorEvent { CursorEvent(){ hitPoint = new Vector3f(); + cursorPosition = new Vector3f(); + cursorRotation = new Quaternionf(); } /** @@ -86,8 +92,6 @@ void setCursor(Cursor cursor) { * Set the coordinates of the intersection between the cursor and the * affected object. * - * This call returns the coordinates of the hit point with respect to the center of the affected object. - * * @param hitX X co-ordinate of the hit point * @param hitY Y co-ordinate of the hit point * @param hitZ Z co-ordinate of the hit point @@ -96,6 +100,29 @@ void setHitPoint(float hitX, float hitY, float hitZ) { hitPoint.set(hitX, hitY, hitZ); } + /** + * Save the current position coordinates of the {@link Cursor} that generated this event. + * + * @param x X co-ordinate of the {@link Cursor}'s position. + * @param y Y co-ordinate of the {@link Cursor}'s position. + * @param z Z co-ordinate of the {@link Cursor}'s position. + */ + void setCursorPosition(float x, float y, float z) { + cursorPosition.set(x, y, z); + } + + /** + * Save the current rotation quaternion of the {@link Cursor} that generated this event. + * + * @param w W component of the {@link Cursor}'s rotation quaternion. + * @param x X component of the {@link Cursor}'s rotation quaternion. + * @param y Y component of the {@link Cursor}'s rotation quaternion. + * @param z Z component of the {@link Cursor}'s rotation quaternion. + */ + void setCursorRotation(float w, float x, float y, float z) { + cursorRotation.set(x, y, z, w); + } + /** * Set the key event associated with this {@link CursorEvent}(if * there is one). @@ -165,6 +192,97 @@ public boolean isColliding() { return isColliding; } + /** + * Get the 'X' position component of the {@link Cursor} that generated this event. + * + * The values returned by this call persist only for the duration of the + * {@link CursorEventListener#onEvent(CursorEvent)} call. Make sure to make a copy of this + * value if you wish to use it past its lifetime. + * + * @return 'X' position component of the {@link Cursor} that generated this event. + */ + public float getCursorPositionX() { + return cursorPosition.x; + } + + /** + * Get the 'Y' position component of the {@link Cursor} that generated this event. + * + * The values returned by this call persist only for the duration of the + * {@link CursorEventListener#onEvent(CursorEvent)} call. Make sure to make a copy of this + * value if you wish to use it past its lifetime. + * + * @return 'Y' position component of the {@link Cursor} that generated this event. + */ + public float getCursorPositionY() { + return cursorPosition.y; + } + + /** + * Get the 'Z' position component of the {@link Cursor} that generated this event. + * + * The values returned by this call persist only for the duration of the + * {@link CursorEventListener#onEvent(CursorEvent)} call. Make sure to make a copy of this + * value if you wish to use it past its lifetime. + * + * @return 'Z' position component of the {@link Cursor} that generated this event. + */ + public float getCursorPositionZ() { + return cursorPosition.z; + } + + /** + * Get the 'W' rotation component of the {@link Cursor} that generated this event. + * + * The values returned by this call persist only for the duration of the + * {@link CursorEventListener#onEvent(CursorEvent)} call. Make sure to make a copy of this + * value if you wish to use it past its lifetime. + * + * @return 'W' quaternion component of the {@link Cursor} that generated this event. + */ + float getCursorRotationW() { + return cursorRotation.w; + } + + /** + * Get the 'X' rotation component of the {@link Cursor} that generated this event. + * + * The values returned by this call persist only for the duration of the + * {@link CursorEventListener#onEvent(CursorEvent)} call. Make sure to make a copy of this + * value if you wish to use it past its lifetime. + * + * @return 'X' quaternion component of the {@link Cursor} that generated this event. + */ + float getCursorRotationX() { + return cursorRotation.x; + } + + /** + * Get the 'Y' rotation component of the {@link Cursor} that generated this event. + * + * The values returned by this call persist only for the duration of the + * {@link CursorEventListener#onEvent(CursorEvent)} call. Make sure to make a copy of this + * value if you wish to use it past its lifetime. + * + * @return 'Y' quaternion component of the {@link Cursor} that generated this event. + */ + float getCursorRotationY() { + return cursorRotation.y; + } + + /** + * Get the 'Z' rotation component of the {@link Cursor} that generated this event. + * + * The values returned by this call persist only for the duration of the + * {@link CursorEventListener#onEvent(CursorEvent)} call. Make sure to make a copy of this + * value if you wish to use it past its lifetime. + * + * @return 'Z' quaternion component of the {@link Cursor} that generated this event. + */ + float getCursorRotationZ() { + return cursorRotation.z; + } + /** * Get the X component of the hit point. * diff --git a/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/CursorSceneObject.java b/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/CursorSceneObject.java index 47c5918ef..9b78a3083 100644 --- a/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/CursorSceneObject.java +++ b/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/CursorSceneObject.java @@ -52,18 +52,69 @@ class CursorSceneObject { this.id = id; } + /** + * Get the x position coordinate of the main scene object that is controlled by the cursor. + * + * @return the x position coordinate of the main scene object that is controlled by the cursor. + */ float getPositionX() { return mainObject.getTransform().getPositionX(); } + /** + * Get the y position coordinate of the main scene object that is controlled by the cursor. + * + * @return the y position coordinate of the main scene object that is controlled by the cursor. + */ float getPositionY() { return mainObject.getTransform().getPositionY(); } + /** + * Get the x position coordinate of the main scene object that is controlled by the cursor. + * + * @return the x position coordinate of the main scene object that is controlled by the cursor. + */ float getPositionZ() { return mainObject.getTransform().getPositionZ(); } + /** + * Get the w quaternion component of the main scene object that is controlled by the cursor. + * + * @return the w quaternion component of the main scene object that is controlled by the cursor. + */ + float getRotationW() { + return mainObject.getTransform().getRotationW(); + } + + /** + * Get the x quaternion component of the main scene object that is controlled by the cursor. + * + * @return the x quaternion component of the main scene object that is controlled by the cursor. + */ + float getRotationX() { + return mainObject.getTransform().getRotationX(); + } + + /** + * Get the y quaternion component of the main scene object that is controlled by the cursor. + * + * @return the y quaternion component of the main scene object that is controlled by the cursor. + */ + float getRotationY() { + return mainObject.getTransform().getRotationY(); + } + + /** + * Get the z quaternion component of the main scene object that is controlled by the cursor. + * + * @return the z quaternion component of the main scene object that is controlled by the cursor. + */ + float getRotationZ() { + return mainObject.getTransform().getRotationZ(); + } + GVRSceneObject getMainSceneObject() { return mainObject; } diff --git a/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/LaserCursor.java b/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/LaserCursor.java index d94c9e45f..69883c9c5 100644 --- a/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/LaserCursor.java +++ b/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/LaserCursor.java @@ -52,6 +52,9 @@ void dispatchSensorEvent(SensorEvent event) { cursorEvent.setCursor(this); cursorEvent.setObject(event.getObject()); cursorEvent.setHitPoint(event.getHitX(), event.getHitY(), event.getHitZ()); + cursorEvent.setCursorPosition(getPositionX(), getPositionY(), getPositionZ()); + cursorEvent.setCursorRotation(getRotationW(), getRotationX(), getRotationY(), + getRotationZ()); cursorEvent.setKeyEvent(event.getCursorController().getKeyEvent()); if (event.isActive()) { diff --git a/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/ObjectCursor.java b/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/ObjectCursor.java index adcf9cd95..eae91d390 100644 --- a/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/ObjectCursor.java +++ b/GVRf/Extensions/3DCursor/3DCursorLibrary/src/main/java/org/gearvrf/io/cursor3d/ObjectCursor.java @@ -69,6 +69,9 @@ private void createAndSendCursorEvent(GVRSceneObject sceneObject, boolean collid CursorEvent cursorEvent = CursorEvent.obtain(); cursorEvent.setColliding(colliding); cursorEvent.setHitPoint(hitX, hitY, hitZ); + cursorEvent.setCursorPosition(getPositionX(), getPositionY(), getPositionZ()); + cursorEvent.setCursorRotation(getRotationW(), getRotationX(), getRotationY(), + getRotationZ()); cursorEvent.setOver(isOver); cursorEvent.setObject(sceneObject); cursorEvent.setActive(isActive);