08 October, 2013

Collisions with triblocks

So I've run into another problem using triblock style voxels.  First a little background into how voxel engines work.  In games like minecraft it seems like there are millions of blocks that are all separate and independent, but the reality is that if each block had to be individually drawn it would slow the system down considerably.  To avoid these millions of draw calls the blocks are instead organized into chunks.  A chunk may be an area of say 16x16x16 blocks that will take into consideration whether the blocks are filled or not and then draws a mesh to represent all of the filled blocks that are next to empty blocks.  When the player interacts with the world and places or removes blocks then the chunk( or chunks in the case of being right on the edge) is redrawn.  Because the whole thing is a mesh together, the collision of the ray from the player's point of view (represented as the sight in the middle of your screen, usually a cross or box) has to determine which box in the chunk is being selected for change, and it accomplishes that in most systems by going halfway into a block and calculating where it is.  Because cubes line up with orthogonal directions fro x, y, and z in a 3d system then they use those directions to identify the block they are in and do the necessary change.  No matter where the collision occurs on the chunk the test will always find the resulting blocks.

My problem is that using equilateral triangles for one of the planes creates a system where sides will be facing directions other than the orthogonal directions of x, y, and z.  To complicate things further if I were to do the same test by going in a half block distance into the block or out from the block using the direction(or negative direction) of the normal vector and the collision occurs near one of the edges I will identify the wrong block for deletion/addition into the mesh.  This is kind of a big problem. One possible solution would be to have each mesh store a triangle list, with each triangle pointing to the block it belongs to and the block it is facing.  The problem with this approach is that even more will have to be stored in memory during run time, and voxel games are already huge memory hogs.  Another issue is that to cut down on the amount of drawing that has to be done if several faces are in the same plane often the triangles are enlarged to cover just the edges of what is showing.  
So what this means is I won't be able to do the large areas I was hoping for back when I first had this grand idea.  Unless of course I figure out how to overcome these obstacles.  Anyway if you are interested in a better explanation please visit https://sites.google.com/site/letsmakeavoxelengine/.  It had a pretty good explanation of what goes into a voxel engine.

13 August, 2013

The clutter of virtual stuff

So I have been playing Hexxit with my wife and kids and I'm noticing something.  For those of you who aren't familiar with Hexxit it is part of a mod package for Minecraft which comes with the Technic launcher. Anyway back to my point, I have a tendency towards hoarding inside of video games, especially MMOs.  I realized that I have been spending hours creating chests and organizing the vast amount of stuff inside of the game.  I have noticed that I have this tendency in other games I play as well, games like Firefall and Aion.  In Firefall the inventory is an endless black hole that I can throw whatever into, which is nice in that I don't have to worry about space but very confusing when looking for something in particular.  In Aion I was forever running out of space for the myriad of items to be found, and finding where I put something could be very annoying as I would have to switch characters and do item juggling just to get the items in the right place.  Even with the difficulties that arise I still find myself justifying keeping every little thing since it may be useful eventually, right?

It is clear that people like stuff, even virtual stuff.  According to this New York Times article, virtual goods are worth billions of dollars, and this was back in 2010.  That is a lot of money for items that aren't really there.  So the question I have is how many items should there be in a game that I create?  In the case of a Minecraft like game there needs to be both a 2D sprite of the object to go into the player's inventory, and usually a 3D representation of the object.  A player inventory implies a multi-level database, as you have the inventory that the player is holding at the moment and more long term storage at the base.  I'm going to learn a bit more about databases this coming semester, and I'm hoping to puzzle out a little of how I'm going to organize this project.  But one thing is clear at least to me, more is not necessarily better.  I think that keeping things to a minimum in the number of things department would be a good thing.  I'll have to think more on this later though as I still need to get the basic mechanics of the world figured out first.

17 June, 2013

Doing things wrong

So I've been enjoying a break from school ( I figure I should do that while I still have the chance) and in between I have been looking at tutorials for how to do a minecraft-like in Unity3D.  The particular video series I followed is by one Craig Perko and can be found at .
So what I have learned from this video is that I was going about creating my scene the wrong way.  I was creating a new mesh for every face that needed to get displayed, rather than making the faces all fit together into a larger mesh.  This would explain why it was performing so badly at my website http://apoidgames.web44.net/wedge.html, I had hundreds of very expensive meshes all trying to fit together.  Unfortunately building all of the faces into a single mesh is not quite so easy when using equilateral triangles for one of the planes.  Also unfortunately I am taking a class called computational geometry over the summer which will again take much of my time, so I will have to put this project on hold for now(again).  Anyway thanks Craig Perko for explaining how minecraft works a little more clearly.

23 April, 2013

The Algorithm for triangles and hexagons

So I thought that it might be a good time to share the algorithm I devised in order to create triangles and hexagons in a standard 3-space.  I'll share just the one for a triangle since the hexagon is just 6 triangles put together.

In order to do it you will need some variables that are important. This will be written in pseudo code and should be easily adapted to whatever language you wish to translate it to.

In order to do it you will need some variables that are important.

// This variable is the height of an equilateral triangle
float depth = Math.sqrt(3)/2;

//Then we need some counters for the loops
float count = 0;
float countstart = 0;
float countstop = 50; // This can be for however large you wish to draw

// This first one is built in 2 space
for( int y = 0, y < 50, y++) //Note that the target number of loops is the same size as countstop
{
    count = countstart;
    while( count < countstop) // This is where the X element is drawn
    {
        Draw an equilateral triangle the uses the following vertices;
        Vertex1 ( x = count, y= y * depth);
        Vertex2 (x = count + 1, y= y * depth );
        Vertex3 (x =count + 0.5, y = (y + 1) * depth );
        count = count + 1;
    }
    countstart = countstart + 0.5;
    countstop = countstop - 0.5;
}

The one for creating triblocks in 3 dimensions is fairly similar

//These variable are used once again
float count = 0;
float countstart = 0;
float countstop = 50; // This can be for however large you wish to draw

//There are only slight variations to build blocks in 3-space
// This second one is built in 3 space
for (int z = 0, z < 50 , z++)
{
    for( int y = 0, y < 20, y++) //Note that the target number of loops is the same size as countstop
    {
        count = countstart;
        while( count < countstop) // This is where the X element is drawn
        {
           if( z=0)
           {
               Only draw a zpos triblock
           }
           else
           {
               Draw a zpos triblock
               Draw a zneg triblock
           }
           count = count + 1;
        }
    }
    countstart = countstart + 0.5;
    countstop = countstop - 0.5;
}

Please note that the y loop can have as many iteration as you wish since the triangle is in the z  and x portions.  Again to create a hexagon one would need 6 of these triangle formations.

28 March, 2013

Early Wedge in Html5

Ok after a long time I finally have a playable demo I can share with everyone via the web.  Just go to

http://apoidgames.web44.net/wedge.html

The controls are basic and it may run a little slow as I only have one type of the two types of triblock showing.  There is also no collision detection so you can walk right through all of the blocks.  I built it using three.js, and I'm hoping to get to the point where it can be edited.  It at the very least will give everyone an idea of what I am going for in the landscape.  Just imagine lots of these triangles put together into one large field.  Anyway I'm back to figuring out how to make this even more interactive.

21 March, 2013

Beginners Ambition

So I've come across this term in my research and I thought I would talk about it a little.  Having spent the last few years of my life pursuing a dream that was far too ambitious for a first project, and also meeting many beginners in the game creation process, I have seen a definite pattern that has emerged.  When someone is unfamiliar with what it takes to make a video game they think remaking some large game or creating an MMO is just a matter of using the existing framework and tweaking it a little.  What happens afterward is a realization of what a colossal effort it takes, as every question they look up on Google leads to two or more new questions, which when followed lead to yet more questions.  Soon a beginner is quite overwhelmed, and that grand game they have thought up becomes an unconquerable beast of a task.

So what advice would I give to someone interested in becoming a game developer.  Well one is start small, with learning how to make pong for example.  Think of pong as the monster conquerable by a beginning adventurer.  It's not that exciting, but given you are just starting out it's where you are and it will give you valuable experience needed for the next level challenge and the challenge after that.  Eventually you will be able to recreate games from the 8-bit era like super mario bros.  Unfortunately there are no shortcuts if you wish to create something truly unique.  If you wish to program a 3D game then you will need to learn matrix math and programming challenges that will really stretch your creative and analytic skill sets.  Perhaps one day, hopefully with the help of others going through a similar journey, you will be able to take on that challenge and make your game.

Also I cannot stress enough that making games is a challenge that will require a good education in math, computer science, and depending on what you want to include in your game a wide variety of other subjects.  It is not a challenge for the faint of heart, and unlike playing most games you will fail many times before you succeed.  I have a great respect for game developers now, and I truly hope that many of the rising generation are able to take on the challenge to become great game developers in the future.

22 February, 2013

Working on Web Programming and Three.js

So I've been doing some soul searching and trying to determine what to teach myself in programming relating to graphics.  I learned a bit about GLUT (an open GL library not really used much these days) and rather than learning older technology I am going to work on understand HTML5, javascript, and WebGL.  I hope to put something together that runs in a browser (probably Chrome, upgrade if you haven't yet) by the end of the semester.

To this end I am learning about an interesting library called THREE.js by one mr.doob.  He has been instrumental in getting several chrome experiments up and running and I feel that the library is approachable as the novice I am.  The cool thing would be that I could share whatever I make on the internet, so hopefully you all can experience it too.  Thanks for reading as always.

12 February, 2013

The power in WebGl

I recently stumbled upon a pretty amazing demo showing just what can be done with javascript and Webgl.  You can check it out at https://developer.mozilla.org/en-US/demos/detail/bananabread . Basically they took a full game engine written in C++ and OpenGL and ported it to javascript and webgl.  It's open source, so I will be able to study it out and get a good idea of where I could go to start my own game later on.

04 January, 2013

Reality Check

I'm coming to the realization yet again that this is no small project that I have undertaken.  I recently had a few good discussions with people on Google+ about game making, and here is what one +Robert Mitchell, who has some experience in the game industry, had to say

"The fact is that the level of competition for good game dev gigs has never been higher. And the reward:risk isn't as good as other sectors unless you offset with an obsession about games in the first place. The likes of EA, for instance, has a tiny fraction of a percent hiring rate for applicants to any given job offer made.

Even then, lucking out with stable employment in this field is just like netting a pink winged unicorn that tastes like chocolate bacon."

Also

"But again, if you find yourself awake at night thinking about how the latest games you played could be improved - and not just from the addition of a new character - and or find yourself in deep thought about the emergent properties found in the interaction of systems around you. Or if you enjoy reading game theory papers talking about conflict and cooperation and Monty Hall's three door game makes obvious sense to you and you don't mind the years it might take to fully pivot over... Game development is incredibly rewarding, IF and ONLY IF you have the love of the craft... because otherwise, this industry will devour your soul and leave you a grumpy, sour mess. I've seen it happen and almost always to good people who just wanted a stable, straight forward job."

I've given a lot of thought to his comments, and the cold hard reality is that I will have to put the needs of my family first and foremost.  I have also come to realize that I am not passionate about making games in general, rather I am passionate about making a game that I think I would enjoy playing.  I probably won't be able to get the resources to make this particular game as it is so ambitious.  I do plan on continuing my education and finishing my master's degree, and I'll find out how much I can get done before that period of my life is finished.  I might end up doing a thesis as opposed to a project, but I still have a long time before I have to make that choice.  To any aspiring game developers who may be reading this, I recommend learning as much as you can as early as you can.  Trying to learn all of this in my mid 30's has been quite tiring.