Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (580)
Games in Android Showcase (162)
games submitted by our members
Games in WIP (632)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 ... 7 8 [9] 10
 81 
 on: 2015-05-21 19:49:34 
Started by irradiancegames - Last post by irradiancegames
I've also noticed some formulas use the inverse projection matrix - while some use the inverse projection * view matrix. Can anybody explain to me why the matrix used isn't constant?

 82 
 on: 2015-05-21 19:28:16 
Started by irradiancegames - Last post by KaiHH
Ah, it seems my advice actually was wrong and you already do it correctly Smiley as this post points out:
http://gamedev.stackexchange.com/questions/71652/opengl-reconstructing-position-from-depth
But furthermore: You store linear depth; or in other words: gl_Position.z does not contain the depth value stored by OpenGL in the depth buffer, because it is missing the perspective divide as well as the interval mapping of the value to [0..1]. The formula you are using however applies to the non-linear depth value stored by OpenGL. So, you might just want to sample a GL_DEPTH texture instead.

 83 
 on: 2015-05-21 19:14:52 
Started by irradiancegames - Last post by irradiancegames
Thanks, but sadly it didn't work.  Sad

Also, here is how I am rendering the depth texture:

Vertex shader (for rendering the depth texture, all objects are rendered using this and then the texture is stored as the depth texture):

1  
2  
3  
4  
5  
6  
7  
void main() {

        v_texCoord0 = a_texCoord0;
   vec4 pos = u_worldTrans * vec4(a_position, 1.0);
        gl_Position = u_projViewTrans * pos;
   v_depth = gl_Position.z;
}


Fragment shader:

1  
2  
3  
void main() {
      gl_FragColor = v_depth;
}

 84 
 on: 2015-05-21 19:09:30 
Started by irradiancegames - Last post by KaiHH
You should not apply interval mapping to your depth and w=1.0 values in getPosition in your fragment shader.
Only to the xy-coordinates (uv).
Change line 10 of the fragment shader listing from:
1  
vec4 pos = vec4(uv, depth, 1.0)*2.0-1.0;

to:
1  
vec4 pos = vec4(uv*2.0-1.0, depth, 1.0);

 85 
 on: 2015-05-21 19:01:22 
Started by Computerology - Last post by BurntPizza
There's also the stdlib Rectangle2D's implementation:

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  
public boolean intersectsLine(double x1, double y1, double x2, double y2) {
    int out1, out2;
    if ((out2 = outcode(x2, y2)) == 0) {
        return true;
    }
    while ((out1 = outcode(x1, y1)) != 0) {
        if ((out1 & out2) != 0) {
            return false;
        }
        if ((out1 & (OUT_LEFT | OUT_RIGHT)) != 0) {
            double x = getX();
            if ((out1 & OUT_RIGHT) != 0) {
                x += getWidth();
            }
            y1 = y1 + (x - x1) * (y2 - y1) / (x2 - x1);
            x1 = x;
        } else {
            double y = getY();
            if ((out1 & OUT_BOTTOM) != 0) {
                y += getHeight();
            }
            x1 = x1 + (y - y1) * (x2 - x1) / (y2 - y1);
            y1 = y;
        }
    }
    return true;
}


I guess I never realized the complexity of rect-line intersection testing.

 86 
 on: 2015-05-21 18:43:14 
Started by Computerology - Last post by Computerology
Hey!

I recently needed a method that...well, the title says it all. This method takes the x, y, width and height values of a rectangle, and the two endpoints of a line, and returns true if the line intersects the rectangle range at all.

Here ya go Smiley

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  
public static boolean rectangleIntersectsLine(double x, double y, int w, int h, double lx1, double ly1, double lx2, double ly2) {
    //determine values to be used in the equation for the line
    double m = (ly2-ly1)/(lx2-lx1);
    double p = lx1, q = ly1; //p = the offset from left side of screen, q = offset from bottom
    //if point l2 is closer to x = 0 than l1, set p and q to lx2's coordinates
    if (lx2 < lx1) {
        p = lx2;
        q = ly2;
    }
    //test if both end points of line are on left side, right, top, or bottom
    //if any is true, then the line does not intersect
    boolean on_left = (lx1 < x && lx2 < x), on_right = (lx1 > x+w && lx2 > x+w),
            on_top = (ly1 < y && ly2 < y), on_bottom = (ly1 > y+h && ly2 > y+h);
    if (!on_left && !on_right && !on_top && !on_bottom) {
        if (((y < (m*(x-p)+q)) && (y+h > (m*(x-p)+q)))
                || ((y < (m*(x+w-p)+q)) && (y+h > (m*(x+w-p)+q)))) { //if left side or right side of rectangle intersects line
            return true;
        }
        if ((x < (((y-q)/m)+p) && x+w > (((y-q)/m)+p))
            || (x < (((y+h-m)/q)+p) && x+w > (((y+h-q)/m)+p))) { //if top side or bottom side of rectangle intersects line
            return true;
        }
    }
    return false;
}

 87 
 on: 2015-05-21 18:27:37 
Started by xpe - Last post by irradiancegames
Very interesting! I'll be watching for more of this Smiley

 88 
 on: 2015-05-21 18:21:12 
Started by irradiancegames - Last post by irradiancegames
Hey everyone! New to the forum. Came here desperately looking for help with something I've been struggling with over the last few days.  Huh
For some bizarre reason, there seems to be something wrong with my matrices when I try to reconstruct the world position from a depth texture - everything seems to skewed.
Here is some of my GLSL code:


Vertex Shader:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
attribute vec4 a_Position;     
                 attribute vec4 a_Color;
                 attribute vec2 a_texCoords;
                 varying vec4 v_Color;
                 varying vec2 v_texCoords;
                 void main()                  
                 {                            
                    v_Color = a_Color;
                    v_texCoords = a_texCoords;
                    gl_Position =   a_Position;  
                 }    


Fragment Shader:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
#ifdef GL_ES
                 precision mediump float;
                 #endif
                 varying vec4 v_Color;
                 varying vec2 v_texCoords;
                 uniform sampler2D u_depthMap;
                 uniform mat4 u_invProjView;
                 
                 vec3 getPosition(vec2 uv, float depth) {
                      vec4 pos = vec4(uv, depth, 1.0)*2.0-1.0;
                      pos = u_invProjView * pos;
                      pos = pos/pos.w;
                      return pos.xyz;
                 }
                 
                 
                 void main()                                  
                 {                                            
                   float depth = texture2D(u_depthMap, v_texCoords).r;

                   gl_FragColor = vec4(getPosition(v_texCoords, depth), 1.0);
                 }



Here is an image of what appears immediately:
http://imgur.com/HEiV3qO


And after I move the camera:
http://imgur.com/vFed7ap



 89 
 on: 2015-05-21 17:44:36 
Started by steg90 - Last post by philfrei
So the value back from noise will state how many to draw vertically (height wise)?

If you are using the same sequence of air/grass/dirt/rock/coal/lava in each column, and only the height varies, then yes.

If there are variations in the the thickness of the layers (implied by the graphic on your link), then you'll need to do more. You could use a Perlin noise function to determine each of those thicknesses, again as a 1-dimensional value, then assemble the results into your array.

 90 
 on: 2015-05-21 17:23:40 
Started by Baseball435 - Last post by yourjavaisbroken
Looks promising!
I will be following this one!

GNetLib is a whole different audience, but I say this can be given to beginners as-is!

Pages: 1 ... 7 8 [9] 10
 
Waterwolf (22 views)
2015-05-20 15:01:45

chrislo27 (26 views)
2015-05-20 03:42:21

BurntPizza (60 views)
2015-05-10 15:53:18

FrozenShade (46 views)
2015-05-07 09:11:21

TheLopais (209 views)
2015-05-06 13:36:48

TheLopais (193 views)
2015-05-06 13:35:14

TheLopais (200 views)
2015-05-06 13:33:39

TheLopais (217 views)
2015-05-06 13:32:48

TheLopais (215 views)
2015-05-06 13:31:28

ClaasJG (237 views)
2015-04-30 20:33:25
List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!