Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 28 Apr 2007
Offline Last Active Today, 03:18 PM

#5158797 OpenGL quaternions

Posted by HappyCoder on 06 June 2014 - 04:08 PM

To better understand how Quaternions work I would recommend learning how complex numbers can be used to represent rotation in 2D.



Complex numbers are kinda like the 2D equivalent of Quaternions. The same basic operations can be done with complex numbers as can be done with Quaternions only they are much simpler to comprehend. Once you understand how to manipulate 2D using complex numbers.

#5158520 Full Model Shader

Posted by HappyCoder on 05 June 2014 - 02:53 PM

Are you using an existing game engine?
If you are using your own game engine, are you using OpenGL or DirectX?

#5152590 Variable Size Array Of Structs GLSL

Posted by HappyCoder on 09 May 2014 - 02:14 PM

You can pass the entire array at once using glUniform3fv 
struct Data {
   Vector3 foo;
   Vector3 bar;

vector<Data> data;

// populate data

// 3 floats per vector
// 2 vectors per Data structure
float* floatBuffer = new float[data.size() * 3 * 2];

for (int i = 0; i < data.size(); ++i)
   floatBuffer[i * 6] = data[i].foo.x;
   floatBuffer[i * 6 + 1] = data[i].foo.y;
   floatBuffer[i * 6 + 2] = data[i].foo.z;
   floatBuffer[i * 6 + 3] = data[i].bar.x;
   floatBuffer[i * 6 + 4] = data[i].bar.y;
   floatBuffer[i * 6 + 5] = data[i].bar.z;

glUniform3fv(uniformLocation, data.size() * 2, floatBuffer);
This wont work if you ever mix in non floating point values into your glsl structure. In that case, you could just pass the uniforms in as seperate arrays instead of an array of structures.

#5152588 Fixed timestep + Box2D game loop

Posted by HappyCoder on 09 May 2014 - 02:04 PM

Good choice going for the fixed time step. To answer your questions.


1) You want to update Box2D inside the Logic update loop. Use 'dt' as the timestep in world.step()

2) Experiment with the physics time step and see what works best for you game. There isn't one right answer for all games.

3) No, you don't need to use a fixed timestep for those things, but why wouldn't you? Adding two types of udpates adds unneeded complexity to your code.

#5152584 Variable Size Array Of Structs GLSL

Posted by HappyCoder on 09 May 2014 - 01:54 PM

How much will the number of elements in your array vary? What is the average size?


If the number of elements doesn't vary much and there aren't that many of them. I would just allocate the array to be larger than what the average length is and just accept that there will be unused slots in that array.


If the size will generally be small but occasionally be larger, see if you could process the larger arrays in chunks. For example, say you allocate your shader to support up to 16 structures at once. When you get a batch of 48, you proccess three seperate batches, each of size 16. For more information on doing this, just look up mulit-pass rendering.

#5145759 How to make semi-transparent simple shadows not stack?

Posted by HappyCoder on 09 April 2014 - 02:08 PM

One option would be to render all of your shadows onto an off screen gray-scale texture using a normal blending mode. You then draw that texture to the screen using a multiply with alpha letting you control how dark the shadow is. Unfortunately, the game engine you are using might not have the features to allow you to do that. I am not familiar with HGE so I cannot tell you if it would support that or not.

#5119397 (Cheapest) "Path" Finding

Posted by HappyCoder on 26 December 2013 - 06:19 PM

When actually finding the path, you can use http://en.wikipedia.org/wiki/Dijkstra's_algorithm

The edge length can be whatever metrics you want, such as cost or distance.


If routes never change, I would have all of the routes calculated. The number of paths between cities is only n^2 where n is the number of cities. if all of the paths are bidirectional then the amount of paths is cut in half. If you look at the numbers it isn't too bad for values in the hundreds or less. Lets look at a lookup table with 200 cities. The number of routes is 200x200 or 40,000. If each route takes on average n/2 hops between cities, which is the worst case if all cities were in a straight line and each step in the route takes two bytes to store, that is about 200 bytes per route. So the total amount of memory used to store all routes between the 200 cities is 40,000 routes * 200 bytes per route would be about 8 megabytes. 8 megabytes is easily manageable, 


If you budget around 2 gigabytes to storing the table, you can store up to 1,200 cities still using the worse case of n/2 average hops per route. If the average number of hops is 10, you can store all of the routes between 14,000 cities in 2gb. A database of this size could fit in ram, however as this database gets larger you would want to store the database on the disk and cache frequently used routes in ram

#5111946 Android/IOS securing connection to remote Database

Posted by HappyCoder on 25 November 2013 - 02:52 PM

As frob said, you don't want to connect directly to the database from the client app. You will want to have a server with some sort of REST api that restricts what actions the client can do to the database. Not only is this more secure, but it is better design as well. By hiding the database behind an API your client side app does not need to be concerned with the structure of the database.

If your app connects directly to the database there is absolutely nothing you could do to keep hackers from doing the same. The best think you could do is create a database user with restricted permissions so they aren't allowed to drop tables or do other really damaging things. However, even with restricted permissions attackers could read any information from tables to get other users information as well as change or possibly delete it.

The best way to protect users at login is to establish an ssl connection with your server then send the username and password over that secure connection. Then have the server code do the authentication against the database. Another important thing you should keep in mind is that you should never store users passwords in the database in plain text. Instead you should do a one way hash of the passwords with some salt. This article describes how to do this. Secure Salted Passwords

#5109640 3D full game engine advices

Posted by HappyCoder on 15 November 2013 - 09:43 PM

That is quite the project. My advice to you is to simplify your project and probably, more importantly, to focus on making a game instead. By simply making an engine you end up not having very clear requirements. Features pop up that sound like a good idea, or would be cool, but may not be that useful for making a game. If you are making a game to go along with your engine you add features to the engine as the game requires it and you build up the engine as you go. Make sure you have milestones setup so you can see progress. You don't want to write a bunch of engine code and try to test it all out at once.

A few things I would do. First of all, don't try and do a multithreaded game engine, expecially if you don't have experience with threading. Multiple threads don't simply speed up any program. It can actually hurt performance in some cases. It takes carful planning to make a good multithreaded system. So I would start by dropping that feature. As for the rest, I think it is a great idea to study how unity is put together. I am not saying it is the perfect example of how to make a game engine but you can learn a lot from it, expecially if many of you don't have much game development experience.

For scene management, develop a scene file format that uses json, or xml, my preference is json. Then make sure the file format is easily editable by hand. Make all of your game object file formats the same way. This way you can start making your games with no level editor. You simply modify these resource files by hand only adding features your game requires. Once you get to this point, you can start working on a level editor. The level editor should simplify editing the game object files in your json format.

My general architecture advice. Make sure you seperate out your classes so each class only does one thing. For example, in your game engine you will have a Mesh class. It should only be responsible for storing mesh information. Don't add a load mesh function to the mesh class, instead have a sperate MeshLoader class that creates Mesh objects from a file. You can even make this an abstract class to let you create different subclasses that can handle loading different file formats, so you could start with loading a simple file format using an OBJMeshLoader, later if you need more than what obj offers, you can create an ColladaMeshLoader or even include a seperate library that already loads existing file formats and you simply create a MeshLoader subclass to handle converting the data so you can use it. These MeshLoader classes may end up being part of ObjectLoader classes, since an fbx file, and other formats, contains more than mesh data. The point to take away from this is by seperating out the functionality, you gain a lot of flexibility.

Avoid singletons. I used to use them quite frequntly but after trying to make a fairly large game project without using any singles I learned two things. You don't need singletons and there are much more elegant solutions that you discover when you don't use them.

Anyway, I don't want to overload you with information here. The main takeaway I want you to get from this is to start simple. You may be in love with certian features or ideas for you engine, but you need to kill your babies or they may end up killing your game project.

#5109037 Vector swizzling in C++

Posted by HappyCoder on 13 November 2013 - 01:43 PM

Haven't gotten a chance to look at your library, but why would one want to run GLSL code as C/C++ code. The majority of the issue encountered when writing shaders are usually related/closely tied to the driver implementation. Most high level shading languague HLSL/GLSL provide means to identify simple errors, which, when identified are easy to correct. The more esoteric ones such as application crashing / visualy anomalies are usually not easy to track down, and running the code on the CPU is not going to help identify the issue. If the bulk of the shader code is just arithmetic operations, then a library like yours would help in validation at least to the point where stuff like floating point behavior is similiar. Another good use would be for syntax verification like you alluded to, which would be a plus.

I disagree. I think being able to run shader coder in a debugger would be fantastic. Setting breakpoints as being able to inspect values would be a great help in debugging. This also opens up the possibility of unit testing. That way, you can get the shader code working in at least one spot, then try and work out the problems you described later.

#5108164 Cylinder-Triangle Collision?

Posted by HappyCoder on 09 November 2013 - 04:49 PM

While I cannot give a concrete answer, I can give a few pointers.

First of all, try doing a sphere/triangle collision first if you haven't. It is the easiest collision there is against a triangle and will help you learn some basics.

If you need a cylinder shape for the player I would recommend you use a capsule shape instead. A capsule is like a cylinder only with half spheres covering the caps. This is better for player collision because it allows the player to easily slide over small bumps in terrain where cylinder would get caught, and the capsule is also easier to do collision detection for. It turns out that the flat ends of the cylinder are a little difficult to deal with.

So before I start giving a more elaborate answer perhaps you could give some more context. Specifically, what do you plan on using this for? Would the capsule shape be better suited? Do you need to only detect IF they overlap or do you have to correct the overlap?

#5108043 It's all about the Mechanics!

Posted by HappyCoder on 09 November 2013 - 01:31 AM

Well, I think what the player experiences is the most important thing. The mechanics are definitely part of that, but story, level design, good characters, and yes, the graphics and visual all contribute to the overall experience. The important thing is if the player enjoyed the experience.

That being said I do agree that large game studios tend not to take risks. It doesn't make sense for a large company to put millions towards a game that might do well or might flop when they have a formula that has been shown to already work. However, I wouldn't say innovation is dead in these large companies.

#5107815 Is hacky code allowed in industry?

Posted by HappyCoder on 08 November 2013 - 12:10 AM

I interned at Microsoft and before I could commit my code to the master code repository other people had to review it and they would point out anything I did poorly. They would sometimes suggest alternatives but other times I had to fix it up myself. I realized that many times I would to a hacky solution more because I didn't want to take the time to find a better solution but in the long run you save time by making good design decisions for more elegant solutions. Hacky solutions usually are parts of more bugs later on. If it is allowed will depend on where you work but as I a rule of thumb I think it is good to avoid the hacky solutions, with the possible exception of if you are working on a prototype that you will throw away later.

#5107267 Need a good 2D graphics program

Posted by HappyCoder on 05 November 2013 - 03:29 PM

I also use inkscape all the time. It is the open source manifestation of Illustrator. I find it very useful for many types 2D art, especially if you are going for more of a cartoon look.

#5106388 Browser games magic

Posted by HappyCoder on 01 November 2013 - 11:28 PM

Having made a few html5 games I would definitely say that is a good option. You can make games that don't require plugins and you can make some pretty good content using html5. It is, however, harder to package it up to distribute on the web and due to difference in browsers your game might not work in every browser. Despite that I think it is a good way to go. If you want to get started with some basic 2D games look up how to use the canvas tag for drawing and using requestAnimationFrame to establish a recurring update/draw cycle.

Flash is also a good option but I have never used it so I cannot give much details in my recommendation.