Calculating the intersection point of Ray and Scene2d UI plane
up vote
0
down vote
favorite
I am rendering a Scene2d UI table on the 3D world using SpriteBatch
, projection matrix
and PerspectiveCamera
public void render (float delta)
spriteBatch.setProjectionMatrix(projectionMatrix.set(camera.combined).mul(transform));
spriteBatch.begin();
rootTable.draw(spriteBatch, 1.0f);
spriteBatch.end();
The mouse pointer is hidden and locked to the centre of the screen. When a touchUp event is fired, if the mouse is inside the bounding box of the table, I want to calculate the Vector2
position where the mouse was actually clicked inside the table, so I can call the Table.hit
function to get the clicked Actor
. Also is this the right approach to draw 2D menu on the 3D world.
I am using this code to do a Ray intersection test.
Ray ray = camera.getPickRay(screenX, screenY);
int result = -1;
float distance = -1;
transform.getTranslation(position);
if (Intersector.intersectRayBoundsFast(ray, position, new Vector3(40, 40, 20) ))
Gdx.app.log("RAY", "Table Clicked");
The Scene2d coordinates start from the bottom left corner and in 3D they start from the centre. I used new Vector3(40, 40, 20)
as dummy bounds.
java android 3d libgdx game-development
add a comment |
up vote
0
down vote
favorite
I am rendering a Scene2d UI table on the 3D world using SpriteBatch
, projection matrix
and PerspectiveCamera
public void render (float delta)
spriteBatch.setProjectionMatrix(projectionMatrix.set(camera.combined).mul(transform));
spriteBatch.begin();
rootTable.draw(spriteBatch, 1.0f);
spriteBatch.end();
The mouse pointer is hidden and locked to the centre of the screen. When a touchUp event is fired, if the mouse is inside the bounding box of the table, I want to calculate the Vector2
position where the mouse was actually clicked inside the table, so I can call the Table.hit
function to get the clicked Actor
. Also is this the right approach to draw 2D menu on the 3D world.
I am using this code to do a Ray intersection test.
Ray ray = camera.getPickRay(screenX, screenY);
int result = -1;
float distance = -1;
transform.getTranslation(position);
if (Intersector.intersectRayBoundsFast(ray, position, new Vector3(40, 40, 20) ))
Gdx.app.log("RAY", "Table Clicked");
The Scene2d coordinates start from the bottom left corner and in 3D they start from the centre. I used new Vector3(40, 40, 20)
as dummy bounds.
java android 3d libgdx game-development
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am rendering a Scene2d UI table on the 3D world using SpriteBatch
, projection matrix
and PerspectiveCamera
public void render (float delta)
spriteBatch.setProjectionMatrix(projectionMatrix.set(camera.combined).mul(transform));
spriteBatch.begin();
rootTable.draw(spriteBatch, 1.0f);
spriteBatch.end();
The mouse pointer is hidden and locked to the centre of the screen. When a touchUp event is fired, if the mouse is inside the bounding box of the table, I want to calculate the Vector2
position where the mouse was actually clicked inside the table, so I can call the Table.hit
function to get the clicked Actor
. Also is this the right approach to draw 2D menu on the 3D world.
I am using this code to do a Ray intersection test.
Ray ray = camera.getPickRay(screenX, screenY);
int result = -1;
float distance = -1;
transform.getTranslation(position);
if (Intersector.intersectRayBoundsFast(ray, position, new Vector3(40, 40, 20) ))
Gdx.app.log("RAY", "Table Clicked");
The Scene2d coordinates start from the bottom left corner and in 3D they start from the centre. I used new Vector3(40, 40, 20)
as dummy bounds.
java android 3d libgdx game-development
I am rendering a Scene2d UI table on the 3D world using SpriteBatch
, projection matrix
and PerspectiveCamera
public void render (float delta)
spriteBatch.setProjectionMatrix(projectionMatrix.set(camera.combined).mul(transform));
spriteBatch.begin();
rootTable.draw(spriteBatch, 1.0f);
spriteBatch.end();
The mouse pointer is hidden and locked to the centre of the screen. When a touchUp event is fired, if the mouse is inside the bounding box of the table, I want to calculate the Vector2
position where the mouse was actually clicked inside the table, so I can call the Table.hit
function to get the clicked Actor
. Also is this the right approach to draw 2D menu on the 3D world.
I am using this code to do a Ray intersection test.
Ray ray = camera.getPickRay(screenX, screenY);
int result = -1;
float distance = -1;
transform.getTranslation(position);
if (Intersector.intersectRayBoundsFast(ray, position, new Vector3(40, 40, 20) ))
Gdx.app.log("RAY", "Table Clicked");
The Scene2d coordinates start from the bottom left corner and in 3D they start from the centre. I used new Vector3(40, 40, 20)
as dummy bounds.
java android 3d libgdx game-development
java android 3d libgdx game-development
asked 2 days ago
Pratik Velani
356
356
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237936%2fcalculating-the-intersection-point-of-ray-and-scene2d-ui-plane%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password