Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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] 2 3 ... 25
1  Game Development / Newbie & Debugging Questions / Re: [Solved] Calculating normal vectors on: 2014-07-13 15:15:35
a good way to calculate the normal from a height map, is to use the sobel filter on the height data.
2  Discussions / General Discussions / Re: Android Billing API Restricts China on: 2014-06-23 22:06:58
Also, noone uses the play store over there.
3  Game Development / Newbie & Debugging Questions / Re: Reduce the polys in a voxel engine? on: 2014-06-14 12:21:39
take a look: http://0fps.net/2012/06/30/meshing-in-a-minecraft-game/
4  Games Center / WIP games, tools & toy projects / Re: MERCury - 2d Game Library on: 2014-06-13 08:52:59
If you are using maven, which is a great choice. You shoul get rid of any project folders from any IDE, configurate everything in maven.
If you need help with a proper .gitignore file, go to: gitignore.io
5  Games Center / WIP games, tools & toy projects / Re: MERCury - 2d Game Library on: 2014-06-12 22:45:24
how about:

1  
2  
3  
4  
5  
6  
int v = 0;
while( v < vertices.length)
{
    Vec2 l1v1 = vertices[v], l1v2 = vertices[++v % vertices.length];
    //...
}
6  Discussions / Miscellaneous Topics / Re: Code-style: Cringe pics on: 2014-06-04 20:47:29
I give you some code I had to deal with lately (legacy Java 1.3 or 4 code):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public Double addTwoDouble(Double a, Double b)
{
  if(a != null)
    if(b != null)
      return new Double(a.doubleValue() + b.doubleValue());
    else
      return new Double(0.0);
  else
    return null;
//and the other way around
}


yes I know why they did it, but it is so cringe worthy not the less.
7  Discussions / Miscellaneous Topics / Re: Random syntax tweaks! on: 2014-06-01 16:10:13
This ?? operator just tries to hide a problem instead of fixing it. Getting rid of null and using something like a Option type is way better in my opinion.
8  Game Development / Game Mechanics / Re: Calculating Tangent from Normal on: 2014-05-30 15:03:35
Yes you can do all the work in the shader, but as you can see this requires a lot of math and will slow down the shader considerably.
You will have to decide for yourself which way is easier for you to support and use.
9  Game Development / Game Mechanics / Re: Calculating Tangent from Normal on: 2014-05-30 14:02:03
you only calculate one tangent per triangle, but you have to calculate it for each vertex of every triangle.

lets say that my code is a function which takes three vertices or indices into your vertex array. you would have to call it three times for each trinalge.

1  
2  
3  
4  
5  
6  
Vector3f calcTangent(int v1, int v2, int v3);
for(int i = 0; i < getVerts().length; i += 3) {
getVerts()[i].setTXYZ(calcTangent(i, i + 1, i +2);
getVerts()[i+1].setTXYZ(calcTangent(i+1, i + 2, i);
getVerts()[i+2].setTXYZ(calcTangent(i+2, i, i +1);
}
10  Game Development / Game Mechanics / Re: Calculating Tangent from Normal on: 2014-05-25 18:01:27
As roquen pointed out, you have to use the gradient of the texture coordinates to identify the direction of the tangent. You need to do this if you want your normal maps to work.

I dug out some code I used to do this task:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
//the three position vectors creating a triangle
       Vector3 pos1,  pos2, pos3;
//the three texture coordinate vectors of the same three vertices
       Vector2 uv1,  uv2, uv3;
//the normal of the vector we want to calculate the tangent for (pos1, uv1 int this case)
       Vector3 n;

        Vector3 v2v1 = pos2.sub(pos1);
        Vector3 v3v1 = pos3.sub(pos1);

        float c2c1b = uv2.getY() - uv1.getY();
        float c3c1b = uv3.getY() - uv1.getY();

        Vector3 t = v2v1.mult(c3c1b).sub(v3v1.mult(c2c1b));

        Vector3 b = n.cross(t);

//the final tangent
       Vector3 smoothTangent = b.cross(n).normalize();      
11  Game Development / Newbie & Debugging Questions / Re: Uniform locations return -1 on: 2014-05-25 00:35:02
also, you have to bind the texture unit not the texture id.
GL_Texture0 == 0
GL_Texture1 == 1
...
12  Game Development / Newbie & Debugging Questions / Re: Does anyone create custom annotations in their game code? on: 2014-05-21 21:50:36
Sadly I can't find another example not involving Riven at the moment persecutioncomplex

Sad don't forget my awesome resource injection lib (topic).
I used annotations to collect all used resources at compile time and be able to optimize them (declare single images in code, but the compiler will add them together into texture atlases)
13  Discussions / General Discussions / Re: FastTuple - fast primitive tuples via bytecode generation on: 2014-05-20 19:59:15
Wouldn't it be enough if the identity is only accessible at the native interop layer? They could add stuff to JNI (or the new interface they are planing?) and nobody would care in Java land.
14  Java Game APIs & Engines / OpenGL Development / Re: Problems with Modern OpenGL lighting on: 2014-05-14 23:47:35
They way most people did it was to have an uniform array with data for multiple lights. Such an array will have a constant size, which may be choosen either by performance or memory concerns.

If you have more lights in your scene then you can render at once, you can do two things. Either choose only the most important light sources for each object, or render each object in multiple passes.

Lets say you can only render 5 lights at the same time, but have many 13 lights in total:
1. somehow order the lights for each object(e.g. 1/distance² * intensity) and only select the top 5.
2. render all lights in 3 passes which are blended together. Only apply the ambient term once.
15  Java Game APIs & Engines / OpenGL Development / Re: Problems with Modern OpenGL lighting on: 2014-05-14 08:21:07
The light direction is constant in view space and not in world-space, because your lighting calculation happens in view space. Declare it as a uniform and transform it each frame into view-space on the CPU.

1  
2  
3  
4  
5  
6  
7  
Vec3 lightDir = ...;
Matrix4 view = ...;

Vec3 vsLightDir = view.mult(lightDir);
shader.updateLightDir(vsLightDir);

renderScene();
16  Java Game APIs & Engines / OpenGL Development / Re: Problems with Modern OpenGL lighting on: 2014-05-13 08:32:13
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  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
#version 120

varying vec4 color;
varying vec3 vertex;
varying vec3 normal;

uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 normalMatrix;

void main() {
    color = gl_Color;
    vertex = vec3(viewMatrix * modelMatrix * gl_Vertex);
-    normal = vec3(normalize(normalMatrix * gl_Vertex));
+    normal = vec3(viewMatrix * normalMatrix * normal);
    gl_Position = projectionMatrix * viewMatrix * modelMatrix * gl_Vertex;
}

Fragment Shader:
#version 120

varying vec4 color;
varying vec3 vertex;
varying vec3 normal;

vec3 lightSource = vec3(0, 10, 0);
vec4 ambientTerm = vec4(0.1, 0.1, 0.1, 1);
vec4 diffuse = vec4(0.5, 0.5, 0.5, 1);
vec4 specular = vec4(0.1, 0.1, 0.1, 1);
float shininess = 0.1;

void main() {
+   vec3 N = normalize(normal);
   vec3 light =  normalize(lightSource - vertex);
   vec3 eyeCoords = normalize(-vertex);
-   vec3 reflection = normalize(-reflect(light, normal));
+   vec3 reflection = reflect(light, N);
   
   vec4 diffuseTerm = diffuse * max(dot(N, light), 0.0);
-   diffuseTerm = clamp(diffuseTerm, 0.0, 1.0);
   
   vec4 specularTerm = specular * pow(max(dot(reflection, eyeCoords),0.0), 0.3 * shininess);
   specularTerm = clamp(specularTerm, 0.0, 1.0);
   
-    gl_FragColor = color + ambientTerm + diffuseTerm+ specularTerm;
+    gl_FragColor = color * (ambientTerm + diffuseTerm) + specularTerm;
}
17  Java Game APIs & Engines / OpenGL Development / Re: Problems with Modern OpenGL lighting on: 2014-05-12 20:44:30
there shouldn't be any matrices in the fragment shader. Calculate the position, normal and lightdir in the vertex shader. You only need to normalize the normal in the fragment shader.

your fragment shader should look something like this(from my code base):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
    vec3 N = normalize(normal);

    vec3 color, dcolor;
    color = vec3(0.);
    dcolor = diffuse;

    float NdotL = dot(N, light_pos);

    if(NdotL > 0.0){
        float HdotN = dot(N, halfvector);
        vec3 scolor = specular;
        #ifdef SPECULAR_MAPPING
            scolor *= texture(specular_sampler, texcoord).rgb;
        #endif
        color += scolor * pow(max(HdotN, 0.), mat_spec_exp);
        color += dcolor * NdotL;
    }
    color += ambient * dcolor;


where "halfvector" is the vector with half the angle between the eye and the light vector. Calculating the lighting in eye-space instead of world-space(what you tried to do), makes it much easier to calculate this halfvector. Just place this in the vertex shader:
1  
2  
  vec3 normal = view_matrix * normal_matrix * in_normal;
  vec3 halfvector = normalize(normal + vec3(0,0,1))
18  Games Center / WIP games, tools & toy projects / Re: MERCury - 2d Game Library on: 2014-05-05 15:22:14
nobody wants to download a doc to be able to read it, please upload it to some website or add it as a github wiki.
19  Game Development / Newbie & Debugging Questions / Re: A* Pathfinding, multiple paths with equal lengths. on: 2014-05-02 19:23:05
Have a read of the very good introduction to A* of the Stanford University.

The problem of how to break ties is discussed on the second page.
20  Game Development / Newbie & Debugging Questions / Re: Editing a text-file stored inside a JAR on: 2014-04-30 23:39:10
With Java 7, which added Filesystem implementations in nio2, there is a something called ZipFileSystem.

You can open a zip file as a Filesystem and then do normal File operations as you do all the time, which operate directly on the Jar.
An URL to your running Jar can be retrieved by the getURLs method of the classloader.
21  Game Development / Performance Tuning / Re: Parallel insertion sort for almost sorted data sets on: 2014-04-29 22:27:19
where is the code? Wink
22  Game Development / Newbie & Debugging Questions / Re: Reading files within an Executeable JAR file on: 2014-04-28 18:40:08
reading text files can be done a lot easier:
1  
2  
3  
4  
5  
6  
7  
8  
Inputstream in = ...;
try(BufferedReader br = new BufferedReader(new InputstreamReader(in)))
{
   List<String> lines = new Arraylist<String>();
   String line;
   while((line = br.readLine()) != null)
      lines.add(line);
}
23  Game Development / Newbie & Debugging Questions / Re: ConcurrentModificationException when removing an item from an arraylist on: 2014-04-26 17:48:51
The best way is to use two
ArrayList
objects - one contains the actual objects and the other one to store the objects that are marked for removal. Remove at the end of the iteration.

No!
don't do a remove all, this is a very expansive operation. Just double-buffer your entity list.
  • use 2 lists
  • each iteration move all still living entities to the next list
  • clear the first list
  • swap the two lists, so the second(which you just filled with the live entities is now the first)
  • render the first list and repeat
24  Game Development / Newbie & Debugging Questions / Re: ConcurrentModificationException when removing an item from an arraylist on: 2014-04-26 09:11:13
either do
1  
2  
3  
4  
5  
for(Iterator<E> i = entities.iterator(); i.hasNext();)
{
  E e = i.next();
  if(...) i.remove();
}


or

1  
2  
3  
4  
5  
for(int i=entities.size()-1; i>=0; i--)
{
  E e = entities.get(i);
  if(...) entities.remove(i);
}
25  Game Development / Newbie & Debugging Questions / Re: How do you control game speed? on: 2014-04-24 20:08:53
You may want to take a look at my time package I wrote for my framework.

I created a little GameTime system, supporting fixed and delta time callbacks and setting a time scale.

This code might give you an idea how to resolve this problem, or just copy my code and be done Smiley.
26  Game Development / Newbie & Debugging Questions / Re: returning a new object from an array on: 2014-04-21 10:40:02
Pls don't use reflection in this way.
One better solution would be to use factories. Factories are Objects/Classes which know how to instantiate a specific Object.

I don't know why you want to store these factories in an array, but you could use Enums for example:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
interface Factory<E>
{
  E create();
}

enum TileFactories implements Factory<Tile>
{
   GRASS {
      Tile create(){ return new GrassTile(); }
   },
   ROCK {
      Tile create(){ return new RockTile(); }
   },
   SPECIAL_ROCK {
      Tile create(){
        RockTile t  = new RockTile();
        t.setSpezial(true);
        return t;
      }
   }
}


Tile t = TileFactories.getValues()[1].create();
27  Discussions / General Discussions / Re: Coding like its for other people on: 2014-04-20 11:53:12
It's called the Reverse domain name notation and is used to prevent naming collisions.
28  Game Development / Newbie & Debugging Questions / Re: Force an image to render on top of another *regardless* of code excution order. on: 2014-04-17 09:41:28
did you try stencil testing?
29  Game Development / Newbie & Debugging Questions / Re: Bitmasking with multiple tiles on: 2014-04-16 17:03:04
I would recommend to create one sprite sheet for each type (bit-values of 1-48) with a transparent background. Then define a fixed order for the types (sand < stone < gras). Contrary to the tutorial you then calculate bit-values for all terrain types, because all types are "solid". While calculating consider all neighbor tiles of the same type and of an higher order as "solid". Finally render all the tiles from lowest to highest order. I think there is still some thinking to do how you handle type borders, but this should be trivial.
30  Game Development / Newbie & Debugging Questions / Re: Loading Resources in Runnable Jar on: 2014-04-16 16:33:32
I did exactly the thing you want to do in my resource lib.
The trick is to ask the Classloader for all class-path elements (folder like the working-dir and Jar files).
I implemented this search in a little helper class. I have a dependency on Google Guava, but it should be straight forward to factor this out.

with this class you can to the following:
1  
2  
3  
4  
5  
6  
7  
Collection<URL> images = ClasspathHelper.elementsOfFolder("resources/graphics/", "png");

for(URL url: images)
{
    Texture temp = TextureLoader.getTexture("PNG", url.openStream());
    texture.put(url.getFileName(), temp);
}


and you will get all images, independent if they are located in the working-dir or some library Jar.
Pages: [1] 2 3 ... 25
 

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

The first screenshot will be displayed as a thumbnail.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (20 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (57 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!