Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  2D over 3D mouse question  (Read 1228 times)
0 Members and 1 Guest are viewing this topic.
Offline ahottev

Senior Newbie





« Posted 2010-11-26 17:57:05 »

Hello,

I have this Canvas3D (using Java3D) with my 3D scene in it, with a PickMouseBehavior, and then a JPanel on the side for debugging. Thing is, i also have some 2D images on top of my canvas3D (using postRender(), think of it as an overlay menu) which also has to be able to read the mouse input, but only if the mouse is over a 2D image, so that it won't go through the 3D picking instead.

How do you do this?

I figured i could somehow hack the picking behavior, but i'm not sure it's the best way. Any help or suggestion appreciated!

Thanks!

edit: I'm thinking of creating a class called Button2D containing the position and rectangle of each buttons in my overlay, add them in an ArrayList, pass it to the mouse picking and test it against the cursor's position before the actual 3D picking. If the cursor is withing bounds, return the Button2D's ID.

I guess it could work?

edit2: Well, it's working fine Smiley I guess i just needed to think "aloud", heh.  Anyway, if there's better solutions, i'd still like to hear them. Tongue
Offline SimonH
« Reply #1 - Posted 2010-11-26 18:26:30 »

edit: I'm thinking of creating a class called Button2D containing the position and rectangle of each buttons in my overlay, add them in an ArrayList, pass it to the mouse picking and test it against the cursor's position before the actual 3D picking. If the cursor is withing bounds, return the Button2D's ID.
That would work. Another option would be to place your 2D images in the 3D scene as planes facing the camera (so they appear 2D). That way the poly-picker could find them.

People make games and games make people
Offline ahottev

Senior Newbie





« Reply #2 - Posted 2010-11-26 18:30:39 »

That would work. Another option would be to place your 2D images in the 3D scene as planes facing the camera (so they appear 2D). That way the poly-picker could find them.

Oh yeah, i thought about that, but it would have been complicated to keep the plane at exactly the right position since you can move, rotate and zoom in every directions...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lhkbob

JGO Knight


Medals: 32



« Reply #3 - Posted 2010-11-27 05:57:14 »

See if Java3D has something to help with billboarding, if they do, it should be pretty easy to set it up so that an object always faces the camera.

Offline tom
« Reply #4 - Posted 2010-11-27 13:30:30 »

You can add it to the view transform group. Then it will follow the camera. However placing the object at the correct position can be tricky. Especially if you want to support the ultra complex Java3D view model. Also you will have problems with the hud being rendered behind the geometry in world. You'd have to make the hud elements transparent and disable depth test. Even then it can be drawn behind transparent objects in the world. That can be fixed by creating your own transparency sorter (com.sun.j3d.utils.scenegraph.transparency).

The problem with the way you're doing it now is that:
1) it is slow
2) the size of the hud your rendering is fixed to the size of the window when it started. If you try to resize the window you will see that it stretces. This makes it impossible to create pixel perfect huds.

Creating a hud in Java3D is impossible without it having some negative side effects.

Offline ahottev

Senior Newbie





« Reply #5 - Posted 2010-11-29 13:49:25 »

You can add it to the view transform group. Then it will follow the camera. However placing the object at the correct position can be tricky. Especially if you want to support the ultra complex Java3D view model. Also you will have problems with the hud being rendered behind the geometry in world. You'd have to make the hud elements transparent and disable depth test. Even then it can be drawn behind transparent objects in the world. That can be fixed by creating your own transparency sorter (com.sun.j3d.utils.scenegraph.transparency).

The problem with the way you're doing it now is that:
1) it is slow
2) the size of the hud your rendering is fixed to the size of the window when it started. If you try to resize the window you will see that it stretces. This makes it impossible to create pixel perfect huds.

Creating a hud in Java3D is impossible without it having some negative side effects.

Ouch, yeah i saw what you meant. Maybe i'll just set it to non-resizable for now, though. OTOH, is post-rendering that slow? Is is slower to draw lots of pixels each frame than calculating a few vertices + material of the billboard each frame (should still be the same number of pixels...) ?  Currently, i'm not noticing any FPS drop, but i guess that's due to not having an FPS counter, which i'll be adding right away. Smiley

Honnestly, i'll probably switch to openGL for my next project, but right now, i guess it's just too late.
Offline tom
« Reply #6 - Posted 2010-11-29 16:07:51 »

"draw lots of pixels" also means uploading it to the graphics card. This is slow. When using a billboard the texture is uploaded ahead of time and this is fast.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (28 views)
2014-12-15 09:26:44

Mr.CodeIt (19 views)
2014-12-14 19:50:38

BurntPizza (37 views)
2014-12-09 22:41:13

BurntPizza (72 views)
2014-12-08 04:46:31

JscottyBieshaar (34 views)
2014-12-05 12:39:02

SHC (46 views)
2014-12-03 16:27:13

CopyableCougar4 (42 views)
2014-11-29 21:32:03

toopeicgaming1999 (110 views)
2014-11-26 15:22:04

toopeicgaming1999 (96 views)
2014-11-26 15:20:36

toopeicgaming1999 (29 views)
2014-11-26 15:20:08
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!