Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (527)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (594)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / OpenGL Development / Re: gluProject problem on: 2012-09-10 21:02:10
Solved this myself, like this:

1  
screenPos.z = -(screenPos.z * (zFar - zNear) + zNear);


-Knut
2  Games Center / Featured Games / Re: Overbind on: 2012-09-03 16:44:45
Cool game. I like the visual style and the gamplay is cool and unusual Smiley
3  Games Center / Showcase / Re: Arrow Runner 2.0 on: 2012-09-03 16:32:36
Game freezes randomly after a few seconds (less than 30). No error messages, sounds keeps playing.

Is there a log somewhere?
4  Discussions / Miscellaneous Topics / Re: Things you disagree with in the java language on: 2012-09-02 16:16:51
Yes, operator overloading can definately give room for confusing code. I would like it just for my own types (i.e. no changing the behavior of the build in classes), and even then one would have to be very careful when using the feature. Also, JavaDoc would help alot I think. It's not something I miss alot, but something that would be useful sometimes.
5  Discussions / Miscellaneous Topics / Re: Things you disagree with in the java language on: 2012-09-01 22:18:33
Operator overloading for my own classes would be nice  Smiley
6  Java Game APIs & Engines / OpenGL Development / SOLVED: gluProject problem on: 2012-09-01 20:31:40
Hi guys,

I'm having some trouble with gluProject. I'm working on a small game, and I need the user to be able to click on entities and get information etc about them. To archieve this, I have been trying to mix 3d graphics (for the entities) with 2d graphics (for the GUI parts). The entities are rendered in perspective mode, while the GUI parts are rendered in ortho mode.

When rendering the entities, the model-view matrix is set according to the camera position and rotation, and passed to the shaders. For each model, the models position and rotation is also passed to the shader separately.

So to archieve things like selection marker, I have been using gluProject. The projection and view-port matrices are stored in the beginning of the program execution, and the model-view matrix is stored during each frame. The matrices are read from OpenGL itself. They are all used in this method:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
    /*
     * (non-Javadoc)
     * @see no.bog.starship.services.Renderer#project(no.bog.starship.glutil.GLVector)
     */

   @Override
   public GLVector project(GLVector worldSpaceVector) {
      GLU.gluProject(worldSpaceVector.x, worldSpaceVector.y, worldSpaceVector.z,
            this.mvMatrixBuffer, this.projectionMatrixBuffer, this.viewPortMatrixBuffer,
            this.screenPositionBuffer);
      GLVector rc = new GLVector(new float[]{this.screenPositionBuffer.get(), this.screenPositionBuffer.get(), this.screenPositionBuffer.get()});
      this.screenPositionBuffer.rewind();
      return rc;
   }


To switch between 3D and 2D mode, I have these functions, which are called before rendering:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
   /**
    * Prepare for 3D rendering.
    */

   protected void prepare3D() {
       GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();
       GLU.gluPerspective(
           45.0f,
           (float) this.windowWidth / (float) this.windowHeight,
           1.0f,
           1000.0f);
     
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glLoadIdentity();
   }
   
   /**
    * Prepare for 2D rendering.
    */

   protected void prepare2D() {
      //Prepare projection matrix to render in 2D
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();                 // clear the perspective matrix
        GL11.glOrtho(                          // turn on 2D mode
              0, this.windowWidth,    // left, right
              0, this.windowHeight,    // bottom, top
              -1, 1);                        // Zfar, Znear
       
        //Prepare the modelview matrix
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glLoadIdentity();               //Clear the Modelview Matrix
   }


When using this, I have managed to create some selection markers, which I have simply implemented as quads with a texture aligned next to the model, as you can see in this picture. These quads are all rendered with z-value set to zero. (In other words, I am using gluProject to simply find the x and y coordinates to use).

I am now trying to add a feature where the user is shown a "map" around the selected entity (think move range or something like this). I want to draw it in ortho so the texture on it is not distorted by perspective. However, I am having trouble when I try to use gluProject to do this. I am trying to add a simple quad with the same y-coord as the entity and the x and z set to +/- 10...but the values returned by gluProject does not make sence to me...it seems the center of this quad is not in the same position as the entity (a simple cube in 0,0,0), especially when the camera is close to 0,0,0.

Can anyone tell me what I need to do with the z value to be able to use it?
I am thinking of rendering with depth test...will this work?
Is there any other way of rendering these kinds of things which are easier/nicer?

Thank you in advance
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

PocketCrafter7 (14 views)
2014-11-28 16:25:35

PocketCrafter7 (9 views)
2014-11-28 16:25:09

PocketCrafter7 (10 views)
2014-11-28 16:24:29

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

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

toopeicgaming1999 (16 views)
2014-11-26 15:20:08

SHC (30 views)
2014-11-25 12:00:59

SHC (28 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (28 views)
2014-11-24 19:59:16
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!