Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (731)
Games in Android Showcase (217)
games submitted by our members
Games in WIP (798)
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
1  Game Development / Newbie & Debugging Questions / Re: How would you do this? on: 2017-05-05 05:48:29
If you can manage to restrict access to the actual values via private modifiers, getters, setters, and that sort (Though reflection may bypass this), then you could check for legal moves in the Deck.

Perhaps store a pre-modification copy of Deck, and check to make sure only the thing that was supposed to happen, happened.  Dunno how you'd make sure that you can't get at the copy though.

I.E. if you play 1 card that doesn't do anything beyond subtracting that card from the deck, if anything else changes, you know something's up, and you can replace the deck with the correct one and, I dunno, I guess you'd first inform the player that an illegal move was made, and if it keeps happening, penalize them more and more, until the other person just wins by forfeit?

Again, there are probably ways around this (there are ALWAYS ways around security, no matter how obscure).  I just figured I'd toss in my two cents.
2  Games Center / Cube World Projects / Re: [LWJGL] [JOML] Some instancing queries on: 2017-05-05 05:28:47
My own little voxel project, though I've not touched it for a long time, renders blocks by constructing a single mesh for the entire chunk (32 blocks per axis), using a greedy-meshing algorithm, combining any similar blocks next to each other into larger quads with texture coordinates to match.  For example, an even plane of stone blocks is rendered as 6 quads, and looks just fine.

My voxels need several things.  Texture, vertex color, and maybe normal mapping if I ever get around to that.  There are pre-set values for baking the most rudimentary of lighting onto them.  For example, if a block's top face has the color of (1, 1, 1, 1), then the "north" face will be (0.7, 0.7, 0.7, 0.7) to help see the block shapes.  That's probably not going to stay forever, but it helps enormously for now.  For now, animated textures are outside the realm of what I need, except for on special blocks, which are their own case.  I also haven't yet done any lighting or shadows except for the basic stuff described above.

I've seen talk of using 6 VBO's, one for each set of faces, IE a "north-face" vbo, etc, and you'd only ever have to draw three of them at once (How are you going to see the top and bottom of a block all at once?  That'd be weird).  That might be worthwhile, but I've yet to implement such a thing, though the greedy meshing I use is a prime candidate since each set of faces is computed in a separate sweep anyway.

Though, since having to regenerate them each frame when checking in what direction the player is looking sounds bad, you'd probably need to generate all 6 VBO's in advance, and select which ones to render.  Whether or not the performance gained from not drawing the entire chunk geometry in one draw call, vs the overhead from drawing 3 VBO's, is a question I've no answer to, though I'm sure there are very smart folks around who could tell you.  I'll probably try and profile each method myself to figure that out, it's rather intriguing.

It's even murkier if you're doing transparency stuff too.  I don't know how it's done the "recommended" way; I just generate another set of geometry for the transparent stuff, since I've not the foggiest idea how to do transparent and opaque blocks in the same set of geometry.  It's probably possible, but not by such a plebian person as myself.  My first guess is geometry shading plus some sort of binary value, but I really don't know.

Using instancing to render the blocks themselves, from what I'm getting here, seems a little odd.  Not wrong, never wrong, just not a use-case that I've ever considered.

For me, I store 1 short per normal terrain block in a big 1D array, which I access using a hashing function.  That means there can be a little over 30 thousand different block types in the world, more if I used unsigned shorts.  I think that'd be like 65536 different types?  Plenty, even if people ever picked up modding for it.  Whether or not that is actually more space efficient, I don't know; I remember reading that Java uses 32 bits for each value anyway.  Plus, the whole having to cast to shorts probably doesn't help, though there's probably a more effective method lurking on the internet.

32 x 32 x 32 shorts for tile IDs, 3 integers for the chunk index, and a pointer to the parent "grid" make up a Chunk.  If / when I get around to it, each Chunk may contain a list of their own self-contained, so-called "tile entities" I.E. a furnace, and if that chunk ever gets unloaded while working, when it's reloaded, you can calculate the work it was supposed to have done while away.  So, at the very least, a Chunk takes up 66~ ish kilobytes.

That ain't so bad!  Though if I ever have rotate-able blocks, I'll need to start storing rotation data for them, which I'll endeavor to have no more than double the size of the chunk.  Should be well within the realm of possibility, and 132~ kb / chunk is... well, it isn't amazing, but it'll work faster than if I were to pack everything as close together as possible.  Hashing and bit manipulation probably costs more than it's worth at that point.

A Grid contains a unique identifier name, and a HashMap<Vector3i, Chunk> map of chunks.  It's easy to figure out chunks, since I'd just divide and round down any in-world position by 32, and that would give me chunk indices.  So if my player is at (20, 20, 20), he's in chunk (0, 0, 0) and, in-chunk, he's at (20, 20, 20).  It even works for negative indices if you fiddle with the hashing function, something that I thought was taken for granted but apparently is not; if he were at (-1, -1, -1) then a lot of the time the calculation would put him in (0, 0, 0) when he should actually be at chunk (-1, -1, -1), in-chunk (31, 31, 31).  Rounding has a lot to do with it, as well as integer division.  I've not yet figured out the correct hashing function so it always works, but I'm getting there.

Loading and unloading chunks to-disk is easy as checking their distance from where the player is; if the chunk's too far away, unload it.  However, if there are any special blocks that are doing work, save their current progress so you can calculate what needs to happen the next time that chunk is loaded.  It might also be an idea to unload chunks that haven't had any change happen to them for a certain amount of time, but keep the mesh; upon the player re-entering, or upon the modification of such a chunk, record the changes, reload it, apply the changes, and continue as usual.

For example, a giant bomb going off far away would need to make changes, so you could design a slower-paced solver for that bomb blast, have it trudge along so it doesn't slow down the actual action zone, and when it's done, unload everything.  Or, if the player gets close enough that the job needs to be finished, switch over to a faster solver.  Perhaps modify the speed based on how far away the player is.

I digress.  And it'll happen again, probably.  ANYWAYS!

The worst-case scenario for meshing means I'm generating 6 quads per block, I.E. a 3D checkerboard of glass and stone where there are the maximum number of visible faces possible, since there'd be two worst-case scenarios, one for opaque blocks, and another for transparent.  That's fine, I'm pretty sure something like that is literally unavoidable for such a situation, and is incredibly unlikely to occur in normal play.

Special blocks, like a furnace or something, would probably be handled with instancing, as they're a higher-poly model, and I can supply the shader with a series of positions and rotations, probably condensed down into as little information as possible.  Or a transformation matrix, that could work.  If this is the sort of thing you're trying to figure out, then:

My matrix math is rough at best, and I really need to work on that.  However, I'm sure you can find that information on google somewhere, on how to create a transformation matrix.  Keeping a list of "special" blocks and their positions and orientations, and sending that data to be instanced, should be very possible.  Each matrix would need to be constructed with one position and one orientation, yeah?

For position, a couple floats would probably be fine, X Y and Z.  For rotation, 2 bits per axis, 0 being 0 degrees, with 1 being 90, 2 being 180, and 3 being 270, would probably work, and you can supply that in the form of a byte with 2 dummy bits at the end you can ignore.  YMMV on that one, I've not done a ton with memory packing like this, though it seems promising or at least worth investigating.  Maybe using another float would be a good idea.

Constructing the matrix in the shader might be worthwhile.  From what I've read about recent technology, the GPU has a ridiculous amount of horsepower at its disposal that the CPU does not, and that may be one of those calculation-heavy tasks that the CPU would struggle with that the GPU would be fine with.  I'd recommend testing both methods; in-shader and out.

The big thing I always seem to consider is, "Is it worth the processing to figure out exactly which set of voxel faces what needs rendering?"  Each face is 2 quads, it can't hurt that much to be a little more efficient with CPU to have a few extra triangles for the GPU.

Bear in mind, I've not touched the thing for a year and a half.  The trends and methodology for rendering voxels might have evolved since then.

However, for some specs, I can render a space of 8x8x8 chunks, which is... 16,777,216 blocks in volume, 256 blocks per edge, and it does rather well.  I've not even gotten into culling the chunks that are underground, that you wouldn't even be able to see anyway, so the overhead from their draw calls and 6 quads are included in that too.

Further optimizations may include the whole 6 vbo deal, and when tile entities come around, raycasting or frustum culling to make sure that they're visible will eliminate the ones that aren't.  You could even frustum cull chunks too.

Another way it just occurred to me, for the 6 vbo deal, is to only have 1 VBO and to put all the data you need into it, and just render a subset of that data for each face that's visible.  Might be worthwhile.

I get rather excited about these things and waffle on a great deal.  I'm no authority on the subject, but there's some stuff I've been reading that might help:

https://lwjglgamedev.gitbooks.io/3d-game-development-with-lwjgl/content/
That's what I'm using to help build from the ground up, since I wanted my own engine!  Maybe a bit ambitious, but hey, it's fun to learn. Cool

http://www.sea-of-memes.com/summary/blog_parts.html
A very interesting blog that has a bit of a disjointed deal to its progress, but still fun and engaging to read!

Plus various articles I found by googling everything under the sun about voxels.

Hope this was at the very least informative, if not actually helpful!   Grin
3  Game Development / Newbie & Debugging Questions / LibGDX project setup? on: 2016-07-26 13:40:24
Is it possible to have LibGDX only create one project?  And if so, how would I go about doing that?
4  Game Development / Newbie & Debugging Questions / How to efficiently store values, and benefit? on: 2016-02-22 19:50:23
Essentially, I have an array of 3 sets of values, 0-3.  I can store the 4 values in 2 bits, yeah?  And each 3 values are related to each other - they represent rotation on X, Y, or Z.  My question is, how would I go about storing these values in a single container in an array - preferably not a class as those add overhead?

Also, is there a gain in performance to storing and getting the values from these bits?  Right now, I'm storing the values in a 4-dimensional byte array, as I have a 3D array of 3 values for each X, Y, and Z in space.  I might just be jumping the gun, but this seems like bad practice to me.  I've considered writing a utility class that uses a BitSet, but I've heard that those aren't all they're cracked up to be, simple though it might be.

For the former, original question, what I have boiled it down to is that I need to use bitshifting (> and <) as well as masking AND and OR in order to shift.

1  
2  
3  
4  
5  
6  
7  
8  
public void setBit(byte b, int pos, boolean truth) {
    if (truth) {
        b |= (1 << pos);
    }
    else {
        b &= ~(1 << pos);
    }
}


It's kinda messy and that's only how to SET the bits - I'm still unsure of how to read specific bits.

For the second method with the BitSet, it would be much easier - every six bits = the three 2-bit values, offset by 6 * whatever.  But I don't know if it's a viable method, as the array size that I calculate I need for the values per "chunk" of data is like, ~3KB in bits alone.  It would still be miles easier though... I think?

Sorry if anything is kinda oddly-worded!
5  Games Center / WIP games, tools & toy projects / Re: Pong in Java on: 2016-01-21 23:04:05
Y'know somethin'?  You completed a game.  That puts you ahead of my years of fiddling with stuff but never quite creating something that was, well, y'know, playable.  Even if pong is just pong, it's definitely an excellent first project!
6  Games Center / WIP games, tools & toy projects / Re: Vangard on: 2016-01-19 02:09:28
Maybe the ingredients used in an item can determine whether it's magic?  I mean, a regular iron sword isn't going to be anything incredibly special, but what about one made from a dragon's fang?  What about a set of armor made from woven Warg fur, or the hide of a sea serpent?

Maybe some materials aren't actively magical, but hold the potential for magic much better, like the aforementioned dragon's fang - it would take very well indeed to magic concerning flame, as it has been exposed to dragon's fire for a long time.  The smith might, after years and years of practice, be able to draw out that nature into a blade that spits and hisses with fires whenever it's swung.

But powerful magic may be even further beyond that, requiring divine guidance.  That dragon fang sword that spits fire is impressive, but the smith had guidance - now the blade itself can absorb fire, lob it, even cause an eruption of flames.  Maybe he was even able to recreate the dragon's essence with runework - and the sword summons small fire dragons, or maybe even not-so-small exploding fire dragons.

Depending on how large you want magic to scale, an artifact made of the highest-quality materials, by the greatest of smiths and with guidance from the gods themselves - such an artifact might have some truly insane capabilities.

... On a side note, suggestions are fun!  I had to struggle not to start getting really crazy with the ideas!
7  Games Center / WIP games, tools & toy projects / Re: Vangard on: 2015-10-27 00:51:08
I'm curious as to how you're going about the entities.  Is it an entity system?  Or are you using inheritance / composition?  Whatever it is, it seems very, very cool!
8  Game Development / Newbie & Debugging Questions / World architecture and internal construction? on: 2015-08-02 06:13:04
I have a WorldMap class that currently stores arrays of Rooms, Regions, and Connections, kinda like a big node-looking map.

- Rooms are more broad than a house room, a room can be thought of as any one screen, or one level, but much less complex at the moment.
- Connections connect two Rooms at specific points.  The entrances have specific styles associated with them (fancy, plain, (boss!), etc).
- Regions are simply a bucket of Rooms that will later provide rendering details (styles, etc), so rooms within a Castle region will have brick walls (probably).

My question is, what would JGO recommend when it comes to just how stuff is structured internally?  The ideas I have in mind are:

1. see the above, basically the world is a big bag of everything.  Objects have a global identifier instead of more localized ones.  Arguably with this approach, I could get rid of Regions and instead make rooms self-contained with stuff for styles and traps and everything else.  It feels a lot closer to entity-component-based design at that point, unless I'm crazy, which could potentially work very well for whenever I decide to add dungeon traps and loot and everything else that a game could probably have, since stuff is "decoupled" so to speak.

2. The world stores an array of regions and an array of connections between regions.  The regions store a collection of rooms and a collection of connections between those rooms.  The objects would instead have a local identifier value, instead of one as it would be in the entire world.  This feels more like regular object-orientated, inheritance-like (or at least tree-like), since the tree of objects is world, region, room.  (Connections kinda exist in limbo like branches, whatever)  This approach is kinda nice since I won't have spare rooms floating about that I forget to attach or something.  I also don't want to slip into the mindset that I should try to fit everything into ECS design, because there are some things that I feel just don't quite jive with it.

3.  Kinda weak-feeling, but posted for the sake of completeness:  make each room self-contained, with references to its own paths and the region it is in, along with whatever else might come along.  The only problem is that I feel like this is inefficient, not in an optimization sense, but in the sense that I need to store objects repeatedly in different objects and have multiple references.  It sounds like a web instead of a well-ordered chaos, and potentially very messy.

Any feedback is appreciated!  I'm not looking for hard answers, just for some feedback for those that have likely been doing this for probably quite a bit longer than I have.

[EDIT]:  Now that I think about it, this probably belongs in Game Design.  Kinda muddled.
9  Java Game APIs & Engines / Engines, Libraries and Tools / LibGDX drawing of sprites? on: 2015-04-24 05:17:05
So, I have a grid of tiles I wish to render, along with various other objects and bits / pieces atop those tiles.  I've determined that the way I should go about it is to only render the tiles around the player's position, which isn't too hard.

The thing is, LibGDX's SpriteBatch has a maximum size of 5460 sprites per drawing call, correct?  There might well be more than that at any given point, considering the tiles are 8x8 and the screen is 640 x 480, coming up to 4800 sprites in tiles alone.  On top of those might be items and entities and other such nonsense.

Does anyone have any advice for me, whether to use separate spritebatches or something like that?  Would it be more efficient?  Or can I increase the maximum size of a spritebatch and would THAT be more efficient?

Thanks!
10  Game Development / Newbie & Debugging Questions / Drawing voxel pixels? on: 2015-04-23 00:58:05
So, I've looked at games like Voxatron and that weird little thing that Kevglass made, and I liked his strange 2d-3d voxel pixel things enough that I wanted to create something like it.

So far as I've found, I need a 3d grid of cells, and the cells can be occupied by a kind of block with a color.  However, the way to "cull" the blocks (Not draw those behind others to avoid drawing pixels) escapes me.

For that matter, I've looked into rendering with pixels, and I've seen a couple methods, such as OpenGL's glDrawPixels() method and using a BufferedImage and modifying its RGB buffer.  But both were apparently not very good in the optimization department.  For reference, the area that must be rendered in pixels is 640 x 480.

I can easily create a 3d grid system with chunks (also dubious, but seem necessary) but I'm not sure how to translate 3d grid into the individual pixels.

Can anyone give me any pointers to methods of rendering, and how to implement them?
11  Game Development / Newbie & Debugging Questions / Rotation issue - pointing at a certain point on: 2015-03-01 20:11:45
So, I have code here for rotation of an entity.  This is on LIBGDX, if that's important.

1  
rotation.degrees = (MathUtils.atan2(pos.y - position.y , pos.x - position.x) * MathUtils.radiansToDegrees) - 90;


where pos is the position of the mouse, and position is the entity's position.  The strange thing is that atan2 is returning incorrectly or something, since the values I'm getting are NOT what I need.  It's like, the more I go along the X or Y axis, the more it rotates, but only within 90 degrees or something like that.

What am I doing wrong?  I've looked up several solutions and every single one pointed to this code, or a variant thereof.


EDIT: I fixed the problem.  It turns out that it was not a calculations problem, but rather a rendering problem - I didn't account for the rendering system's offset.
12  Game Development / Newbie & Debugging Questions / Strange issue with recursion? on: 2013-12-28 21:26:07
So essentially, the following snippet of code loops endlessly.

1  
2  
3  
4  
5  
      while (parent != null) {
         System.out.println(parent);
         offset.add(offsetFromParentWithRotation());
         parent = parent.getParent();
      }


Why is that?  Am I not allowed to set the parent like that, or am I missing something very obvious?
13  Game Development / Newbie & Debugging Questions / Re: OOP Noob - Extending Classes, or How Else to Create Unique NPCs? on: 2013-11-16 14:13:03
This may be a bit advanced or a jump to get into, but a component-system based approach is quite efficient, from my own experience.  Essentially, each entity is simply an ID that's assigned predefined component classes - like health, or damage, or movement - that another class, a system or handler, takes into account to make the entity do what you want it to.

The one I like currently is the Artemis Entity System.  http://gamadu.com/artemis/
14  Game Development / Game Play & Game Design / Re: Creating a circular "grid" ? on: 2013-11-16 01:28:32
Abuse has the right idea, and philfrei goes a little more in depth.
15  Game Development / Game Play & Game Design / Re: Creating a circular "grid" ? on: 2013-11-11 16:17:46
I would do it that way, were it not for that you're supposed to be viewing these at all angles - the "up" can be in any direction along this single plane.  But since it's like that, it's supposed to look like everything is going towards the center - if I were to use a square grid in this case, if you were looking at it at a 45 degree angle, everything would be diagonal.
16  Game Development / Game Play & Game Design / Creating a circular "grid" ? on: 2013-11-11 15:55:33
My quest is to essentially create different-sized rings, centered around the same point, that are made of 1-unit pieces.

My problems are that I have difficulty understanding the math required to create such.  I know how to create rings that are made of differing SIZED pieces, like 360 degrees = 360 pieces per ring, but the pieces get progressively larger as you go away from the origin point.  I don't want that - I want the pieces to stay the same size, instead creating more as you go outward.

I was hoping someone would help me figure out how to fix up my code in order to do this.


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
      float radians = (float) Math.toRadians(degrees);
     
      float[] data = new float[] {};
     
      float circ = MathUtil.getCircumference(depth); // Get the circumference at the chosen depth
      float circt = MathUtil.fastfloor(circ); // Round the circumference
     
      for (int c = 0; c < circt; c++) { // For every 1 "unit" do
         float rads = (float) c / circt; // Dividing the count by the circumference gives us the radian measure for each block
         
      }


That was as far as I had gotten before this made itself clear to my mind.
17  Game Development / Newbie & Debugging Questions / Re: Using LWJGL color API? on: 2013-07-13 03:45:16
Adding this snippet of code to ask:  Am I going about this the correct way?  I need 4 floats (one representing each of r, g, b, a) and they're supposed to be values between 0 and 1.  I'm trying to convert from a hexadecimal integer (eg 0xFFFFFFFF) to the four floats.

1  
2  
3  
4  
5  
6  
7  
8  
   protected float[] getRGBA(int color) {
      return new float[] {
            (color & 0xFF) / 255f,
            (color >> 8 & 0xFF) / 255f,
            (color >> 16 & 0xFF) / 255f,
            (color >> 24 & 0xFF) / 255f
      };
   }


Am I thinking about this the right way?
18  Game Development / Newbie & Debugging Questions / Re: Face culling on voxels. on: 2013-07-13 01:26:48
Ahh, that's actually what I was busy doing.  I eventually figured out the whole access issue, although I'm not sure the method that I went about is correct.

By the way, there is no World class;  each voxel group effectively needs to know about all the voxels it contains.  So i suppose there are many World classes in that respect; the basic group and all of the ones that extend it (so they can behave differently - ie a turret of a ship needs to rotate differently than the ship itself.)  To that end, this is what I've come up with:

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  
   public void updateVBO() {
      int numfaces = 0;
      boolean front = false, back = false, left = false, right = false, top = false, bottom = false;
      for (int x = 0; x < width; x++) {
         for (int y = 0; y < height; y++) {
            for (int z = 0; z < length; z++) {

               if (isOOB(x+1, y, z) || !isOCC(x+1, y, z)) {right = true; numfaces++;}
               if (isOOB(x-1, y, z) || !isOCC(x-1, y, z)) {left = true; numfaces++;}
               if (isOOB(x, y+1, z) || !isOCC(x, y+1, z)) {top = true; numfaces++;}
               if (isOOB(x, y-1, z) || !isOCC(x, y-1, z)) {bottom = true; numfaces++;}
               if (isOOB(x, y, z+1) || !isOCC(x, y, z+1)) {right = true; numfaces++;}
               if (isOOB(x, y, z-1) || !isOCC(x, y, z-1)) {left = true; numfaces++;}

               voxelData(x, y, z, voxels[x][y][z].type, numfaces, front, back, left, right, top, bottom);

            }
         }
      }
   }

   protected boolean isOOB(int x, int y, int z) {
      if (x * y * z > width * height * length || x * y * z < 0) return true;
      return false;
   }
   protected boolean isOCC(int x, int y, int z) {
      if (!isOOB(x, y, z)) if (voxels[x][y][z].opaque) return true;
      return false;
   }


Also, I've refrained from putting data into the actual floatbuffer for now because I don't want the buffer being too big.  That being said, compacting it would work to remove the extra space, right?
19  Game Development / Newbie & Debugging Questions / Re: Using LWJGL color API? on: 2013-07-12 23:19:41
So would I only need 1 color "vertex" when interleaving color with position in my FloatBuffer?  From what it looks like, that seems to be the case.
20  Game Development / Newbie & Debugging Questions / Face culling on voxels. on: 2013-07-12 19:56:41
I have a segment of code here that's supposed to cull faces of voxels that should be invisible.

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  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
   private FloatBuffer voxelData(int x, int y, int z) {
      float r = rand.nextFloat(), g = rand.nextFloat(), b = rand.nextFloat();
      float xscale = x * scale, yscale = y * scale, zscale = z * scale;
      int numfaces = 6;

      boolean top = true, bottom = false, left = true, right = true, front = true, back = true;
      if (x != width--  && voxels[x + 1][y][z].isActive) {right = false; numfaces--;}
      if (x != 0         && voxels[x - 1][y][z].isActive) {left = false; numfaces--;}
      if (y != height-- && voxels[x][y + 1][z].isActive) {top = false; numfaces--;}
      if (y != 0         && voxels[x][y - 1][z].isActive) {bottom = false; numfaces--;}
      if (z != length-- && voxels[x][y][z + 1].isActive) {front = false; numfaces--;}
      if (z != 0         && voxels[x][y][z - 1].isActive) {back = false; numfaces--;}

      if (numfaces == 0) return null;

      FloatBuffer data = BufferUtils.createFloatBuffer(numfaces * 24);

      if (top) { data.put(new float[] {
            this.x + xscale + 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
      });}

      if (bottom) { data.put(new float[] {
            this.x + xscale - 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
      });}

      if (left) { data.put(new float[] {
            this.x + xscale - 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
      });}

      if (right) { data.put(new float[] {
            this.x + xscale + 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
      });}

      if (front) { data.put(new float[] {
            this.x + xscale + 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale + 0.5f * scale,   r, g, b,
      });}

      if (back) { data.put(new float[] {
            this.x + xscale + 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale - 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale - 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
            this.x + xscale + 0.5f * scale,      this.y + yscale + 0.5f * scale,      this.z + zscale - 0.5f * scale,   r, g, b,
      });}

      data.flip();
      return data;
   }

The segment is passed the x, y, and z values through a triple-nested for-loop checking each voxel in a 3d array.  However, the code seems to only output left and back sides; never any others.  Even then, it's only the left-bottom-back corner that renders, and not even the bottom face; just the back, and three left faces from the edge, and a face one above that.
Here's a screenshot:  
21  Game Development / Newbie & Debugging Questions / Re: About lists and the elements inside of them. on: 2013-07-12 14:45:13
That's actually a very good tip.  However, isn't it sort of misleading when you're going through the interfaces for each component type rather than the actual object itself?

Also, I've abandoned that method of components for now and instead have a basic VoxelGroup class that has an enum of GroupTypes to determine how it should behave (Another class entirely).  The list of voxels from before is non-existant

With that in mind, would your interface method still work properly?  Or should I change my architecture slightly to accomodate?

And the idea of an abstract base class; would that replace the VoxelGroup class, and then I would create multiple classes for different types of groups, all of which would use an interface for commonly needed methods - that about sum it up?
22  Game Development / Newbie & Debugging Questions / Re: Using LWJGL color API? on: 2013-07-12 03:26:24
Indeed, the bytes thing is a good idea.  Could anyone give me a small example of how to convert bytes to a color, though?  It'd be very, very helpful indeed.
23  Game Development / Game Play & Game Design / Re: Intuitive Interface Design on: 2013-07-12 02:15:14
I like design B more.  It positions all the data that the player (Probably) cares about closer together.  The recent screenshot looks really nice, actually.  Oskuro's suggestion is a very good one too.

Perhaps there should be a way to assign hotkeys?  Those are always nice to have.

Also, a purely aesthetic idea, perhaps make it so that the player can change the GUI color?  Grayscale images + color interpretation?
24  Game Development / Game Play & Game Design / Re: Data structure for voxels? on: 2013-07-11 22:52:44
Would I not have to loop through with an array for collisions, then?  If you could explain a little more how a 3d (or even 1d) array wouldn't require looping for collisions, that'd make it a bit easier for me to wrap my head around.

Also, for the if statement, do you mean checking each index in the array like this, sorta?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
...
for (int x = 0; x < width; x++ {
     for (int y = 0; y < height; y++) {
          for (int z = 0; z < depth; z++) {
               if (voxels[x][y][z] != null) {
                    // mesh update code
               }
          }
     }
}
...


As it stands, that's what I'm using to create the VBO for the object.

While I'm typing this, another question:  how would I go about applying rotations to each object individually?  I know glRotate and glTranslate would work for the entire world or a single object, but I need to be able to move / rotate individual voxel groups, as well as individual voxels within a group.  If I wanted rotating / moving voxels within the group, it seems inefficient to have to go through and re-work the entire mesh of the thing.  So by that logic, I'm assuming I'd need to have the object have multiple groups of voxels?

Again, just brainstorming, putting it out there for any constructive folk who happen along.

EDIT:  On the subject of "subgroups", perhaps have an enum of what types of subgroups there are?

Also, things like:  Would the gun on a turret need to know about what's going on in the casing it's attached to, AND the main body of a ship?  Or would it just need to know the turret only, since the turret would already compensate for knowing the main body?  Is that kind of "inheritance" going to cause issues?  If so, is there another method around this?  (I'm thinking mainly rotation along this path; the main hull would have its rotation, the turret casing would have its rotation relevant to the hull, and the weapons on the turret would have its rotation relevant to the casing, which is relevant to the hull.)

And on the same topic, what about collisions within the same structure?  What if the turret gun knows about the casing, but not about the main ship?  It would collide / be restricted to the casing, but how would it know to collide with or interact with the main hull?  Is it possible to create a system that does all the collision checking and (possibly) queuing for them?  How would it work?  Raycasting?  Or perhaps another method.
25  Game Development / Game Play & Game Design / Re: Data structure for voxels? on: 2013-07-11 22:20:07
But that array again is larger than what's necessary.  Maybe the memory isn't a big issue, but the extra space still has to be looped through.  Wouldn't that affect the cpu load required rather significantly?
26  Game Development / Game Play & Game Design / Data structure for voxels? on: 2013-07-11 20:52:01
Well, I've thought about this for quite some time now, and I've come to hit what I believe is a roadblock.  If you're really going to help me, prepare for a bit of a read since I tend to over-explain things.

See, each of my voxels currently stores its own position values in 3 integers: x, y, z.  I understand that this is very inefficient in most cases, but more on that in a second.  Within my current structure, the voxels are assigned into groups that don't have a fixed count to them, nor a fixed position; they need to be dynamic as the player will be interacting with them, and also each group needs to be able to do things on its own - move, rotate, etc.  When I got to the point of storing the data, I had two separate ideas, which are below.  I'm doing the second option currently.

1  
2  
3  
4  
5  
// first option
private Voxel[][][] group_voxels = new Voxel[w][h][l];

// second option?
private List<Voxel> voxels = new ArrayList<Voxel>();


Now, the question comes down to efficiency of storage and data, as well as perhaps processing and rendering speed - though I'm not 100 percent certain about that last one.

For the first option, the pros are that I can infer the integer positions for each voxel through the index it's at in the 3d array.  However, doing this also creates a lot of wasted space, since odds are the entire group of voxels will never be filled (Giant cube structures aren't going to be very common).  For example, if I have a tree that's 48 voxels tall, 25 voxels wide, and 25 voxels in depth overall, the empty space (like around the trunk) is sitting there and taking up memory (I think?) where it could be better spent on other things.  It also introduces a bit of unneccessary checking when looping through, since it needs to check those empty spaces as well as the far more important occupied spaces.

For the second option, the plus is that there shouldn't ever be wasted space inside of the list, since only enough voxels are assigned at any point to the list to create their object; the wasted space around the tree trunk would disappear since the list never even bothers about that spot.  In addition, I believe that there would be a boost in general speed since when iterating through the list, it again never bothers to check what isn't there.  However, with this method, I can't come up with any way to infer the position of the voxels through usage of indices; the list doesn't know anything about the width or length or height, it just stores the voxels.  This leads me to using the 3-integer method described as above.

My question is, which is more efficient?  I'm not that experienced with serious programming structure and the sort, usually I just throw it together without a care for the efficiency, so I'd like a few opinions as well as maybe some tips and tricks if anyone's willing to share.

Also, if you actually read all of that, thanks for sticking with it.  I can really be a little too wordy at times.
27  Game Development / Newbie & Debugging Questions / Camera rotation around a central pivot point? on: 2013-07-10 21:23:18
I'm trying to use vector math to rotate the view around a central pivot point, which may move around.  This is the code that I have so far:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
   public void followObject(Object target) {
      if (target instanceof Voxel) {
         Vector3f tpos = new Vector3f(((Voxel)target).x, ((Voxel)target).y, ((Voxel)target).z);
         pitch = Vector3f.angle(new Vector3f(1, 0, 0), tpos);
         yaw = Vector3f.angle(new Vector3f(0, 1, 0), tpos);
         roll = Vector3f.angle(new Vector3f(0, 0, 1), tpos);
         this.setPosition(tpos.x + (pitch * 10.0f * zoom), tpos.y + (yaw * 10.0f * zoom), tpos.z +(roll * 10.0f * zoom));
         GLU.gluLookAt(this.x, this.y, this.z, tpos.x, tpos.y, tpos.z, 0, 1.0f, 0);
      }
   }


Could anyone give me tips or pointers as to how I can get this to work?
28  Game Development / Newbie & Debugging Questions / Using LWJGL color API? on: 2013-07-10 16:16:50
Could anyone break down how to use the Color API of LWJGL to me?  From my testing, all of these colors are apparently the same:
1  
2  
3  
4  
5  
// Color c = new Color(r, g, b, a);

Color c = new Color(255, 155, 0, 255);
Color c = new Color(155, 255, 0, 255);
Color c = new Color(100, 200, 0, 255);

I searched on google for about an hour and didn't come up with anything substantial.  Although I am aware of bitshifting.  Do I need to shift
29  Game Development / Newbie & Debugging Questions / Code snippet that needs reviewing? on: 2013-07-10 05:04:31
I have a segment of code that's supposed to put floats into a FloatBuffer to create a small voxel; however, whenever I try to render it, it comes out as a flat plane.
Could anyone help me with this?

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  
   public float[] voxelVertices(float x, float y, float z) {
      float xx = x * 0.2f, yy = y * 0.2f, zz = z * 0.2f;
      return new float[] {
            //   x,         y,            z
            // Top quad
            xx + 0.1f,      yy + 0.1f,      zz + 0.1f,
            xx - 0.1f,      yy + 0.1f,      zz + 0.1f,
            xx - 0.1f,      yy + 0.1f,      zz - 0.1f,
            xx + 0.1f,      yy + 0.1f,      zz - 0.1f,
            // Bottom quad
            xx + 0.1f,      yy - 0.1f,       zz - 0.1f,
            xx - 0.1f,      yy - 0.1f,      zz - 0.1f,
            xx - 0.1f,      yy - 0.1f,      zz + 0.1f,
            xx + 0.1f,      yy - 0.1f,      zz + 0.1f,
            // Front quad
            xx + 0.1f,      yy + 0.1f,      zz - 0.1f,
            xx - 0.1f,      yy + 0.1f,      zz - 0.1f,
            xx - 0.1f,      yy - 0.1f,      zz - 0.1f,
            xx + 0.1f,      yy - 0.1f,      zz - 0.1f,
            // Back quad
            xx + 0.1f,      yy - 0.1f,       zz + 0.1f,
            xx - 0.1f,      yy - 0.1f,       zz + 0.1f,
            xx - 0.1f,      yy + 0.1f,       zz + 0.1f,
            xx + 0.1f,      yy + 0.1f,       zz + 0.1f,
            // left quad
            xx - 0.1f,      yy + 0.1f,       zz - 0.1f,
            xx - 0.1f,      yy + 0.1f,       zz + 0.1f,
            xx - 0.1f,      yy - 0.1f,      zz + 0.1f,
            xx - 0.1f,      yy - 0.1f,      zz - 0.1f,
            // right quad
            xx + 0.1f,      yy + 0.1f,       zz + 0.1f,
            xx + 0.1f,      yy + 0.1f,      zz - 0.1f,
            xx + 0.1f,      yy - 0.1f,       zz - 0.1f,
            xx + 0.1f,      yy - 0.1f,       zz + 0.1f};
   }
30  Game Development / Newbie & Debugging Questions / Camera spazzing out, as well as render method not working as intended on: 2013-07-09 22:42:50
Never mind, I have figured out what the problem was.  Could someone remove this?
Pages: [1] 2
 
Archive (336 views)
2017-04-27 17:45:51

buddyBro (534 views)
2017-04-05 03:38:00

CopyableCougar4 (977 views)
2017-03-24 15:39:42

theagentd (1011 views)
2017-03-24 15:32:08

Rule (991 views)
2017-03-19 12:43:22

Rule (972 views)
2017-03-19 12:42:17

Rule (968 views)
2017-03-19 12:36:21

theagentd (1069 views)
2017-03-16 05:07:07

theagentd (990 views)
2017-03-15 22:37:06

theagentd (759 views)
2017-03-15 22:32:18
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!