Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (564)
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  
  Vertex3f's to hold properties?  (Read 1098 times)
0 Members and 1 Guest are viewing this topic.
Offline xEnt

Junior Newbie





« Posted 2008-12-22 00:30:52 »

Hi, im new to OpenGL for java, now id like to make a map of tiles (square 1 sided tiles) going 48*48, i have done this using the following code.
int count = 0;
for(int i=0; i < 48*48; i++) {
                        count++;
         gl.glVertex3f(AcrossTwo, DownTwo, -0.4f);
         gl.glVertex3f(AcrossTwo,  DownOne, -0.4f);
         gl.glVertex3f(AcrossOne,  DownOne, -0.4f);
         gl.glVertex3f(AcrossOne, DownTwo, -0.4f);

         AcrossOne+= 1.02f;
         AcrossTwo+= 1.02f;
                        // After 48 tiles have been layed, it moves the position down and resets horizontal back to the start to lay another 48 under it.
         if(count == 48) {
            count = 0;
            DownOne+= 1.02f;
            DownTwo+= 1.02f;
            AcrossOne = 1.0f;
            AcrossTwo = 0.0f;
         }

}

Now this does show the tiles i created, except im completely lost in how i go about accessing them, lets say i click a tile on my screen, id like to be able to change that tile's color. I know this isnt structured properly (Normally id create a Tile class, holding all it's properties) except i don't actually know how to access each vertex3f by a mouse click?

Thanks for whoever helps Tongue
Offline irreversible_kev

Junior Member





« Reply #1 - Posted 2008-12-22 00:41:36 »

In computer graphics its called SELECTION or PICKING.

OpenGL provides built in functionality for this ( glRenderMode(GL_SELECT) ) but you must not use it as it can be slow and OpenGL  themselves have said they regret implementing it in the first place.


 Selection and Picking and Feedback Mode

A modern OpenGL program should not use the selection buffer or feedback mode. These are not 3D graphics rendering features yet they have been added to GL since version 1.0. Selection and feedback runs in software (CPU side). On some implementations, when used along with VBOs, it has been reported that performance is lousy.
A modern OpenGL program should do color picking (render each object with some unique color and glReadPixels to find out what object your mouse was on) or do the picking with some 3rd party mathematics library.


So what to use?

1) Colour coded picking @ http://www.lighthouse3d.com/opengl/picking/index.php3?color1
2) Transform your 2D mouse click point (xm,ym) into a ray in your 3D world and do collision detection with each of your objects (Simple in the case of 'tiles') (You might use gluUnproject)
Offline xEnt

Junior Newbie





« Reply #2 - Posted 2008-12-22 01:05:49 »

In computer graphics its called SELECTION or PICKING.

OpenGL provides built in functionality for this ( glRenderMode(GL_SELECT) ) but you must not use it as it can be slow and OpenGL  themselves have said they regret implementing it in the first place.

So what to use?

1) Colour coded picking @ http://www.lighthouse3d.com/opengl/picking/index.php3?color1
2) Transform your 2D mouse click point (xm,ym) into a ray in your 3D world and do collision detection with each of your objects (Simple in the case of 'tiles') (You might use gluUnproject)

Okay, if i do the color coded picking, Lets say were using the color light green, is there 3000 different colored light greens that would look the same to the eye? even by adjusting each tile's color up by a unnoticible notch, but 3000 times?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline irreversible_kev

Junior Member





« Reply #3 - Posted 2008-12-22 01:22:34 »

In your main rendering loop you draw your tiles in their "real colour" (IE they might all be white at first).

if the mouse is clicked at (x,y) {
BEFORE drawing your tiles in their "real colour" you draw them with a "colour code" that must be unique to each tile.
You then read the colour of the pixel at (x,y) and check against your list of colour codes. This tells you which tile you clicked (if any).
Finally you draw your tiles in their "real colour" so that the user never sees the strange colour codes.
}

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
renderLoop() {

    if (mouseClicked) {
        drawColourCodedTiles();
        int selectedTile = checkIfColourMatchesAColourCode(x,y);
        tiles[selectedTile].setColour(BLOO);
    }

    drawTiles();
}





I am tired so my answer is not very polished but hopefully it helps



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.

Grunnt (20 views)
2014-09-23 14:38:19

radar3301 (14 views)
2014-09-21 23:33:17

BurntPizza (31 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (29 views)
2014-09-20 20:14:06

BurntPizza (33 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (75 views)
2014-09-10 13:57:51

TehJavaDev (108 views)
2014-09-10 06:39:09
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!