Show Posts

Pages: [1] 2 3 ... 14

4

Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LWJGL] Library for rendering text.

on: 20150505 12:54:33

The absolute easiest way is to have prebaked images with the text you want on them. Obviously that isn't the best since no dynamic text.
If you want dynamic text, the easiest way (and it is still pretty easy as long as you have some experience) is to have a texture with every single character on it. You just have to know where each character is and then you can specify texture coordinates such that you get the right character. Downsides to this are: you will probably end up drawing one character at a time, creating the texture with all the characters can be time consuming unless you write a program to do it for you (which I would suggest, again not too difficult) and you need a new texture for each font you want to use.



5

Game Development / Newbie & Debugging Questions / Re: Make a camera with changeable size

on: 20150505 12:48:16

So many +1 to @KevinWorkman.
But to answer your question, it depends on the type of camera you are talking about. If you are talking first person then no. But I presume you aren't talking that. If it's 2D platformer or in fact anything 2D then yes.
However will not be efficient. I've never worked with Java2D for games but I would guess you would have to mess around with he transform associated with the Graphics object. Someone who knows what they're talking about can confirm or not that.



6

Game Development / Newbie & Debugging Questions / Re: Issue with path movement/speed

on: 20150430 09:47:11

A problem you will often get with stuff like this if(entity.getX() == path.getPath().get(entity.getPathIndex()).getX() && entity.getY() == path.getPath().get(entity.getPathIndex()).getY()){ is that due to floating point inaccuracy, two values can be not quite equal but instead 1E20 off. Which can cause unexpected issues. Try instead of using the equality comparator, using a method like this: 1 2 3
 public static boolean equalsTolerance(float f, float g) { return Maths.abs(f  g) < TOLERANCE; } 
Where TOLERANCE is some very small constant. Probably try it out somewhere in the order 1E5 to start with.



7

Game Development / Newbie & Debugging Questions / Re: LWJGL 2D Point lighting

on: 20150426 18:18:41

OK so here's a really simple example of lighting using a single white point light using a square attenuation model. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 #version 400 core
in vec3 position; in vec2 textureCoords;
out vec2 out_TextureCoords; out vec2 out_WorldPos;
uniform mat4 projectionMatrix; uniform mat4 transformationMatrix; uniform mat4 viewMatrix;
void main(void){ out_TextureCoords = vec2(textureCoords.x,textureCoords.y);
vec4 worldView = viewMatrix * transformationMatrix * vec4(position,1.0); out_WorldPos = position.xy; gl_Position = projectionMatrix * worldView; } 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 #version 400 core #define ATTENUATION_COEFFICIENT 0.1
in vec2 out_TextureCoords; in vec2 out_WorldPos;
out vec4 out_Colour;
uniform sampler2D texture0; uniform vec3 light;
void main(void){ float d = length(light.xy  out_WorldPos); float a = light.z / (d * d * ATTENUATION_COEFFICIENT); out_Colour = a * texture(texture0, out_TextureCoords);
} 
I HAVE NOT TESTED THIS CODE. It should give you an idea of how to go about this even if it doesn't work.



8

Game Development / Newbie & Debugging Questions / Re: LWJGL/OpenGL 3.3+ Voxel Chunk Management

on: 20150403 15:11:02

So surely just: 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
 public class Chunk {
private static final int CHUNK_SIZE = 64; private static final int CHUNK_HEIGHT = 128;
public static void create(int chunkX, int chunkZ) { float xOffset = CHUNK_SIZE * chunkX; float zOffset = CHUNK_SIZE * chunkZ; for (int x = 0; x < CHUNK_SIZE; x++) { for (int y = 0; y < CHUNK_HEIGHT; y++) { for (int z = 0; z < CHUNK_SIZE; z++) { if (y < 16) { if (StartClient.rand.nextInt(2) == 0) { if (StartClient.rand.nextBoolean()) { StartClient.allCubes.add(new Entity( Blocks.cubeStone, new Vector3f(x + xOffset, y, z + zOffset ), 0f, 0f, 0f, 1f)); } if (StartClient.rand.nextInt(2) == 0) { StartClient.allCubes.add(new Entity( Blocks.cubeSand, new Vector3f(x + xOffset, y, z + zOffset), 0f, 0f, 0f, 1f)); } } } } } } } } 
And also by the looks of it, your code will generate stone blocks and sand blocks in the same location.



9

Java Game APIs & Engines / Engines, Libraries and Tools / Re: [LibGDX] How to check if Object is in certain part of camera?

on: 20150330 13:26:35

Yes, I did mean for the full stop "." to denote the vector dot product (aka scalar product). Sorry for all the confusion, I normally define that. And fyi, I don't use "*" so as not to confuse with the cross product (aka vector product).
As for how to get the left vector, I thought you would already have that to do the frustum test. Essentially you can take it directly from the rotation matrix of the camera. That is the matrix that defines the rotation. Not the viewing matrix (which includes translation) not the projection matrix. Just the rotation matrix.
A1 A2 A3 A4 B1 B2 B3 B4 C1 C2 C3 C4 D1 D2 D3 D4
Then the left vector is just (A1, A2, A3) although if you're using a right handed coordinate system this is the right vector. If you're interested, (B1, B2, B3) is the "up" vector and (C1, C2, C3) is the "forward" vector.
Sorry again for all the confusion.



15

Discussions / Miscellaneous Topics / Re: What I did today

on: 20150310 08:53:57

...
Your third system would fall apart very quickly , the outer planet is moving faster than the inner ones , if that is the required orbit velocity at that radius then the other two will fall into the star , if it is moving too quickly it will fly off into space. Still very cool effects , would be great to see where these space projects go. I agree. And it can be proven mathematically. If you equate the gravitational force with the centripetal force: F = G*m*M / (r^2) = m*(v^2) / rWhere G is the gravitational constant, m is the mass of the satellite, M is the mass of the sun, r is the radius of the orbit and v is the tangential velocity of the satellite. Cancelling ' m's and ' r's. G*M / r = v^2Since G and M are constant, the speed is inversely proportional to the square root of the radius. The greater the radius, the smaller the velocity. You can use v = w*r to find the angular velocity. G*M / r = (w*r)^2G*M / (r^3) = w^2Hence the angular velocity is inversely proportional to the radius to the power 3 / 2. It seems like you've gone to a lot of effort to make the star types and positions, it'd be a shame if your orbits weren't right.



17

Java Game APIs & Engines / Engines, Libraries and Tools / Re: Java Model Importer  Design Discussion

on: 20150302 19:10:32

So I have done something like this before for a few formats. Essentially I just built everything around the way COLLADA structures it's data. It's an extremely comprehensive format that covers everything and it's designed by lots of collaborators (the Khronos ARB) so it's quite a good average of all the stuff out there.
Also it'll probably be the most complex format you will support so better that you bend everything else to fit it than vice versa.



19

Java Game APIs & Engines / Engines, Libraries and Tools / Re: Java OpenGL Math Library (JOML)

on: 20150220 21:33:03

Additionally angles are usefully avoidable in the first place.
Yes. Vectors, matrices, quaternions are all better than angles in every respect. Certainly for a computer. As with most complex things in maths, learning about them is the hard part but once you have, then they make things so much more simple and general case. And "degrees" is more natural is mostly myth. That's only true for very large angles.
I disagree. Certainly most people would be fine with pi/3, pi/2, pi etc. but once you go to more complex multiples than that then you have to think about it to figure out how big the angle actually is. Or at least I do. And I am studying engineering which is practically maths. I wouldn't be surprised if they dropped you marks if you tried to solve a problem in degrees instead of radians.



20

Java Game APIs & Engines / Engines, Libraries and Tools / Re: Java OpenGL Math Library (JOML)

on: 20150220 09:19:23

The idea of degrees is that it takes the sun exactly 360 days to travel around the earth. And that's exactly how useful they are.
And it doesn't even do that. But degrees have a use in that they are what people know about. They are what people learn about and hence what most of us think about intuitively with angles. So why not have a degrees to radians method so that people can use their intuitive knowledge in, for example, initial conditions. Yes you should discourage people from using degrees but you shouldn't prevent them entirely.



21

Game Development / Game Mechanics / Re: Calculate Derivatives for Newton's Method

on: 20150216 09:21:36

So the first thing to understand about the NewtonRaphson method is that is is an iterative process. You take the answer from the last iteration ( x_{n}), stick it into the next iteration ( x_{n1}). Now as you keenly noticed, this requires an initial starting point. The way to get this is to guess an answer, for a human quite simple, for a computer I don't know of any methods of guessing an answer. If you choose well and your guess is near to a root then the solution will converge quickly (in fewer iterations) if you guess poorly then it will take longer. Also, if the function has multiple roots, then the starting point will affect which root is converged upon. Now calculating derivatives. A derivative is actually defined as: Now computationally, since we are just using approximations anyway, why not approximate the derivative by using a value of h close to 0. Like 1E10 for example. That's very simple for a computer to do. (And although I've never heard of it before, I thought secant was a trig function, it seems like this is what they mean by the secant method although they apply it to second derivatives)



22

Game Development / Game Mechanics / Re: questions on opengl, lwjgl(slick util)

on: 20150208 22:15:36

1) Depends on impl a bit and what generation you are working with and stuff. In general not the most expensive method but not to be abused either. If you can easily cut down on texture binds then great, if not then lets remember about how sick and evil premature optimization is.
2) No.
3) Don't know the actual implementation in Slick (the method doc should really say) but I would guess yes  it releases the OpenGL texture object.
4) Releases all textures, buffers, shaders etc. and the whole OpenGL context.
5) Premature optimization again but if Slick has some kind of "Source" class, then I would expect that also has a "release()" method.
6) A PNG is a compressed image file format. When you load a texture, it is stored in a non compressed format so it can be accessed quickly. How much space it takes up depends on the format you store it in. A typical RGBA format is 4 floats per pixel so will take up (roughly) 4 * 4 = 16 bytes per pixel. You will know when you're video card is stressed when the program starts lagging. Premature optimization.
7) I know of no conventional way. Your enum method sounded good. But do what is easier and what works. Premature optimization.



23

Discussions / Miscellaneous Topics / Re: The joys of game dev in C++

on: 20150202 11:39:55

... Yes, it crashes lol.
Well to be more specific, it throws an Exception. The exception can be caught to avoid a crash. That is a quite significant difference to c++ null pointers being dereferenced. In practise though it makes no difference (although I think Java's handling of exceptions makes an NPE easier to debug) since we rarely catch NPEs but rather check to see if a variable is null before dereferencing as you would in c++. But we are good programmers so let's be precise.



24

Discussions / Miscellaneous Topics / Re: Java Certificates

on: 20150131 18:23:45

So what value do these certificates have?
As much as you paid for them. I have never seen anyone put any value into certification as far as job prospects are concerned. And neither would I.



25

Java Game APIs & Engines / OpenGL Development / Re: Applying transformations to vertices

on: 20150129 11:13:49

Not in the same FloatBuffer object but you should stick it in a ByteBuffer. So your "creating the buffer" code will look like this. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 private ByteBuffer createInterleavedArray() { ByteBuffer bb = BuferUtils.createByteBuffer(m_vertices.length * 52); for(int j = 0; j < m_vertices.length; j++) { bb.putFloat(m_vertices[j].m_position.m_x); bb.putFloat(m_vertices[j].m_position.m_y); bb.putFloat(m_vertices[j].m_position.m_z); bb.putFloat(m_vertices[j].m_normal.m_x); bb.putFloat(m_vertices[j].m_normal.m_y); bb.putFloat(m_vertices[j].m_normal.m_z); bb.putFloat(m_vertices[j].m_uv.m_x); bb.putFloat(m_vertices[j].m_uv.m_y); bb.put(m_vertices[j].m_influences[0].m_bone_index); bb.put(m_vertices[j].m_influences[1].m_bone_index); bb.put(m_vertices[j].m_influences[2].m_bone_index); bb.put(m_vertices[j].m_influences[3].m_bone_index); bb.putFloat(m_vertices[j].m_influences[0].m_bone_weight); bb.putFloat(m_vertices[j].m_influences[1].m_bone_weight); bb.putFloat(m_vertices[j].m_influences[2].m_bone_weight); bb.putFloat(m_vertices[j].m_influences[3].m_bone_weight); } bb.flip(); return bb; } 
and then setting up your pointers. 1 2 3 4 5
 glVertexAttribPointer(vert_pos, 3, GL_FLOAT, false, 52, 0); glVertexAttribPointer(color, 3, GL_FLOAT, false, 52, 12); glVertexAttribPointer(tex_coord, 2, GL_FLOAT, false, 52, 24); glVertexAttribPointer(joint_indices, 4, GL_BYTE, false, 52, 32); glVertexAttribPointer(joint_weights, 4, GL_FLOAT, false, 52, 36); 
So you see ByteBuffers are great because you can mix and match data however you want.



26

Java Game APIs & Engines / OpenGL Development / Re: Applying transformations to vertices

on: 20150128 15:12:56

The one thing I could see was these two lines: 1 2
 gl.glVertexAttribPointer(joint_indices, 4, GL.GL_BYTE, false, Buffers.SIZEOF_FLOAT * Vertex.SIZE, Buffers.SIZEOF_FLOAT * 8); gl.glVertexAttribPointer(joint_weights, 4, GL.GL_FLOAT, false, Buffers.SIZEOF_FLOAT * Vertex.SIZE, Buffers.SIZEOF_FLOAT * 12); 
So when you create the buffer, you specify the joint indices as a float each. But then you interpret the indices as a byte in your pointer. That can't be good. Also a byte is obviously one byte long and you have 4 of them for the indices. However you have the offset of joint_weights (and I would guess the stride as well) set as if the they were 4 floats (for 16 bytes). But to be honest I would have thought that these issues would have caused more problems. But correct them and we'll see what happens.



28

Game Development / Newbie & Debugging Questions / Re: Texture always facing the camera

on: 20150118 17:39:59

This is called billboarding. And there are essentially two methods or doing it. 1) Don't use the camera rotation as part of the view transform when you are billboarding. The translation part yes but not the rotation method.
2) You can create the geometry you're rendering using the camera's left and up axis for the geometry's left and up axes. Example: To render a quad of width "w" and height "h" at position "P" with a camera left axis "L" and up axis "U", then the 4 points of the quad would be: P, P + w*L, P + w*L + h*U, p + h*U
For more help, ask a more specific question and give some information about your current setup.



29

Game Development / Game Mechanics / Re: Translate Point By Pitch/Roll

on: 20150114 22:49:57

Also, this must be without any matrices or quaternions.
Why are you trying to make things difficult for yourself? If there is a good reason I will be happy to help you out but I cannot imagine a situation where using matrices wouldn't make this task a whole lot easier. Seriously, try and imagine rotating a vector about the y axis, the about the x axis and finally about the z axis? Confused yet? No, try drawing down a diagram for each stage with a nice little right angled triangle so you can work out the trigonometry. I say these things because I have tried and it is not worth the effort.



30

Game Development / Newbie & Debugging Questions / Re: Up Vector calculation for matrices

on: 20150114 17:27:40

Only normalize a vector when the length isn't one. That should fix this issue.
The issue is that when you cross two parallel vectors, you get a zero magnitude vector so if the forward vector is (0, 1, 0) or (0, 1, 0). Then you normalize a zero vector (giving NaN) or cross it to get another vector (giving another zero vector). ...
Setting the direction to a vector of (0.1, 1.0, 0.0) or (0.0, 1.0, 0.001) seems to work perfectly. It'll work until you have a forward vector of (0.1, 1, 0) or (0, 1, 0.001). If you are in a situation where your forward vector might be pointing straight up, better to do a check to make sure it doesn't. One conditional is not going to be noticed.





javagaming.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

