Skip to content

Commit

Permalink
Added methods to get the cursor position/rotation from a cursor event
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul authored and liaxim committed Nov 23, 2016
1 parent d046615 commit 03fd407
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.gearvrf.GVRBaseSensor;
import org.gearvrf.GVRSceneObject;
import org.joml.Quaternionf;
import org.joml.Vector3f;

/**
Expand All @@ -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;
Expand All @@ -52,6 +56,8 @@ public class CursorEvent {

CursorEvent(){
hitPoint = new Vector3f();
cursorPosition = new Vector3f();
cursorRotation = new Quaternionf();
}

/**
Expand Down Expand Up @@ -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
Expand All @@ -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).
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 03fd407

Please sign in to comment.