Monday, November 18, 2013

Finite Element Method - Elastic Ball


This video is part of the assignemnt of class Physical-based Animation.
I implement the elastic effect with standard Finite Element Method: http://graphics.berkeley.edu/papers/Obrien-GMA-1999-08/

Tuesday, November 12, 2013

On Going Ray-tracing Class Project

Here is my ray-tracing class on going project page:
http://www.cs.utah.edu/~owuntu/cs6620/index.html

Feel free to leave some comments, ask questions, point out problem, or rush my ray!

Ray-tracing Refraction - Floating Point Error

To implement refraction in ray-tracing rendering, we can simply use the refraction equation:
sin(theta1)/sin(theta2) = n2/n1

To compute sin(theta1), simply:
cos(theta1)= v1.dot(N);
sin(theta1) = sqrt(1-cos(theta1) * cos(theta1)); 

where v1 is the incomming ray direction, and N is the surface normal.
However, there may be trouble when this implementation runs in computer. In C++, since we can't avoid floating point error, when v1 is almost perpendicular to the surface, that is, v1 and N almost the same (or they just be the same), cos(theta1) could slightly greater than 1 (something like 1.00001). Then, this result would cause:
1-cos(theta1) * cos(theta1) < 0
And sqrt(a) would return invalid result if a<0. So that sin(theta1) becomes a invalid value. Eventually, all the computation mess up. The pixel we want to shade becomes an error pixel. 
To avoid this, simply put a check routine like:
cos(theta1) = min(1.0f, v1.dot(N))

Never trust floating point number!! 

Wednesday, April 10, 2013

Progress Since Turn to "Vinyl" team

Since "Rover Rescue" get cut, I turn to the "Vinyl" game team.

Vinyl is a music game which it give you audio feedback (or reward) about your game play performance. It is a third person view game, you are looking at the vinyl pin and control it like a skate board. And the pin is traveling inside a vinyl track. We already have a video of the prototype:
http://www.youtube.com/watch?feature=player_embedded&v=IQGS7w8ybnA

Right now I am adding physical simulation to the pin movement. It should look like skate boarding. I am using a 2D space to calculate the position, and then project it back to the actual 3D space. The reason I do in this way is I want the pin constraint on the track surface. So the pin movement is actually in a 2D space. I think this idea maybe similar to a subject in Machine Learning - Kernel Space projection.

"Rover Rescue" Get Cut and Now it Turned to be a "Zombie" Project

Rover Rescue get cut in about one month ago. Sorry for updating it so late.

It was very tough for us to face the truth that our lovely Rover get cut at that time. Every thing seemed very good at that time but suddenly, 4 thesis games cut down to 2 games and Rover was one of them that fail.
However, some of the Rover team member still wanted to make this game. We decide to go on and make Rover as a "Zombie" project. So far our Rover team has 5 people: Zeph, Chongze Yang, Ziyao Chen (new member!), Alice and me. We went over the suggestion from the Gate 1 presentation, and discussed about how to re-design the game. Some features kept and we are going to make another prototype first on CryEngine.

As a programmer, I don't like those GUI game engine such as Unity, CryEngine, UDK. That's because I don't have 100% freedom to build my own thing. However, consider that we don't have many people, and probably don't have much time to work together. Also, if we going to build our own engine first, it would take a long time before we begin to build the game. So I think we can build the game on CryEngine first, build the mechanics, to see if it is great. Then, we can decide whether to build our own engine for the game and redo everything. The idea of this is sometimes maybe CryEngine implement the game in the way not we want, or it may do thing stupid though it still make things work. So we can rebuild the game in our own engine, and make our engine to the right thing.

Of cause, we may not be able to build every thing of the engine if we decide to make it. I'd like to build the engine base on some 3rd party open-source library such as OGRE and Bullet-Physics. Those C++ library doesn't have a GUI environment, but has enough manipulation to build a costume engine as well as some basic support such as rendering and physics simulation.

Be careful when dealing with C++ floating point.

Look at this piece of code:

Vector3 colPlaneNor;

float dx = abs(aabb1->getPosition().x() - aabb2->getPosition().x());
float dy = abs(aabb1->getPosition().y() - aabb2->getPosition().y());

if(dx < (aabb1->_width + obb2->_width)/2.0f)

    colPlaneNor = Vector3::UNIT_Y;
else if(dy < (aabb1->_height + aabb2->_height)/2.0f)
    colPlaneNor = Vector3::UNIT_X;

The idea of these lines of code is to determine the collision plane normal when two AABB boxes collided. The problem here is, floating point calculation is not 100% accurate. Even if the true is

dx == (aabb1->_width + obb2->_width)/2.0f,
 and
dy < (aabb1->_height + aabb2->_height)/2.0f

But in C++, the floating point number dx may slightly less than
(aabb1->_width + obb2->_width ) / 2.0f

That will cause the code pass the if()test first and set the collision plane normal to a wrong vector.
My solution here is to make the threshold a little bit lower:


if(dx < (aabb1->_width + aabb2->_width)*.99f/2.0f)
    colPlaneNor = Vector3::UNIT_Y;
else if(dy < (aabb1->_height + aabb2->_height)*.99f/2.0f)
    colPlaneNor = Vector3::UNIT_X;

Instead of compare the actual sum, I multiply the sum by 0.99. So even if dx is slightly lower than the actual result, it won't pass the if() test and jump into the else if(). If the collision plane normal should be normal Y, dy should still smaller (aabb1->_height + aabb2->_height)*.99f/2.0f.
If both dx and dy are actually equal to the sums, that means the two AABB is colliding on the coner, or maybe very closed to the corner. In this case I can make a default vector for the collision plane normal, such as normal X.

Tuesday, February 26, 2013

After Gate 1 Presentation

Yesterday we did our Gate 1 presentation. We got a lot of useful feedback. Yet Yang and me also worry about our game is too simple to do. If we take out the dog and survival feature, it seems there is nothing more for our game. I think, we do need more on our game.
How about the personalization of each dog? So that different dogs have different abilities. How about the Courage System we just talked before? How about the different forms for dog groups?
Worry about we can't make it? Well, I believe we can make it. Here are the reasons.
First, we have totally a year to make the game. Even if the true time is not an entire year, at least we have several month to make it.
Second, we have 4 engineers, I think it is enough to build our game code. We can handle crap even if Moai, so there should be no problem to use other better engine or library such as OGRE or CryEngine to build our game.
Third, I would like to take my experience as an example to compare to our project. 2 years ago I was in a 9-people team to build a 3D Angry Birds. We don't have artist and producer, all of us were programmer, so that some of us turn to artists and project manager. And the actual number of programmers for coding was 4. However we only had 1 month to build the game, and using OGRE, which was completely new to all of us. And yes, only 1 month, we made it, even if there were a lot of bugs in the game, but at least, the game could be played. And yes again, we built our birds and pigs model, built the configuration file system, built the GUI and control system, involved OGRE and Bullet Physics engine, all by ourselves. So you see, even a team of undergrads can built a fully-play game in only 1 month, with entry level engine architecture, why couldn't our GRADUATED students can make a larger scope game in a year?
So, I hope our naive game design can pass Gate 1. Then, I do like to increase the scope so make the game deeper, more interesting.
明主良相上将俱备,何惧安天下?

Monday, February 11, 2013

Code works first, Optimize it later

This week I implement some features on our prototype. Now in our prototype, the worker can move the Tech Parts back to the base but with low moving speed. And worker can collect oxygen pack as their HP refill (we also have 3D HP bar for workers!),  a minimap showing position information of units and base.
Unity is a powerful tool to make prototype work. I don't need to worry too much about run time error. In Unity, even my script have some stupid operation (use null pointer, etc.), the prototype game can still run, then Unity has its log to indicate where goes wrong.
Also, I haven't consider too much details when I coding. I think that should be how things start, even in software engineering. We can always go on detail design, build framework architecture, and code in deep until final product come out. But at first, is this product, idea, or concept worth to implement? Prototype is for answering this question. We don't need to think too much detail in prototype. All we need to worry is the core concept, core mechanic of the game.
As the title said, after rushing some garbage code, we should think about the real game. What game engine should we use? How the architecture should be? I will prefer to use OGRE as our basic engine. There are several reasons. First, it is completely open-source, so we don't need to worry about license like UDK. Second, OGRE also has its wiki, forum, so that we can always go to find someone for help, and the forum is kept updating. Third, OGRE is a C++ engine, and there are several concept similar to what we learn in Game Engineering II, so that it is a good practice for our engineers. OGRE can also be a good reference for our Game Engineering assignments.

OGRE official website: http://www.ogre3d.org/

Thanks for our producer Zeph, we have our own awesome website. Check it out!

Team dawgz: http://www.teamdawgz.com/

Monday, February 4, 2013

Rushing for prototype

This week we had change a game a lot. Instead of typical RTS combat, we made the game more about survival. In the game you can start with 5 penguin, and your mission is to collect enough technique parts to repair your spaceship so that you can go back to earth. For each penguin it has limited oxygen resources, and the oxygen is time-based consuming. There are multiple oxygen packs randomly spread out in the map. These oxygen packs can refill to the penguins a little bit. And when a penguin pick up a technique part to move it back to the base, the penguin would move slower because it is carrying something.

For the prototype, I am working on the collection and moving speed slow down. With Unity, we already found a raw project done by other from the Internet. To build a prototype, I still need more time to figure it out. So, I create a video to show the idea first just in case I can't make the Unity prototype.

For an RTS game, I think the basics features should be select and give command. I am still looking on it.

Monday, January 28, 2013

RTS Game pitch

Finally we formed another team and decided to build an RTS game.
When we talk about RTS game, it is easily to raise up many typical RTS, such as Warcraft, Starcraft, Age of Empire, Command and Conque, etc. RTS games have many similar feature, and how to make our game unique was our team's No. 1 question. And also because there is 6 members in our team, we can not make a Warcraft scope game like Blizzard. So, we come up with the game idea which is single screen and cute art style game. We also come up with a courage system, which mean the unit ability will affect by its courage value.
For the prototype, we want to make it as simple as possible but also include our core idea. The premise of the game is, you are traveling into the space. Unfortunately, your spaceship crash into Mars, and you need to explore the planet to find parts to repair your spaceship to escape. At the same time, aliens may also attack you, you may need to collect resources to build your defense. For the prototype, you only begin with 5 penguins to collect resources and find parts.
The further work for the game will be: different parts may need different amounts penguins to move it to the base; parts could be alien labs, player can build their own labs base on them and upgrade weapons; it can be 3 kinds of penguin and 3 kinds of alien, they all have their unique ability; penguins could chose to equip different kinds of weapons.
I also have thought about how to apply Kingdom Hierarchy System into the game. The basic thought is, when a group of penguin was defeated, they loose all their weapons, but they still alive with their own level. The penguin could die only if they continue getting attack after they are defeated.

Friday, January 18, 2013

Thesis Game Pitch: Kingdom Hierarchy System

At the beginning of Spring 2013 in Game Project II, we are going to make our thesis game.
At the end of last semester, I did a game pitch of dragon race for the Game Design final project. I like this pitch, however, I prefer to make an RTS game. Specifically, I want this game to be a game with some ancient Chinese culture. And for my favorite, the ancient Chinese culture means the Three Kingdom history.
Currently, there are already many games built on the Three Kingdom history. I want my game has at least one unique feature, and that is the Kingdom Hierarchy System:
The game will suppose to be an isometric view. Here, each player start as civilian. As the player raise crop in farms, make merchandise in factory, or participate into a battle, he will gain experience to grow. Somehow he can become a general, and then a king. The king can be overturn by his general, an the general can be overturn by civilian. If the king was overturned, he become a civilian again, and he can start from the beginning to become a king again.
From civilian to king, player would play more RTS and kingdom management. On the other hand, as a civilian doesn't have much power to domain an area, he can play more RPG feature.
The game will have two modes: Peace mode and Battle mode. In Peace mode, kingdoms could not attack each other, and generals, civilians can not overturn their kings too. At this time, players are suppose to do more kingdom development, such as raising the farm, build more barrack, etc. At a specific time period, the game turns into Battle mode. Now kingdoms could attack others, or defense themselves. King could be suddenly overturned by his generals or civilians at this time too. King, generals and civilians can also suspend to their enemy at this time.
A more visual view of this game would be: WarCraft III + Ragnarok + Romance of The Three Kingdoms. So, player normally is just like playing Ragnarok: go out to hunt some animal, raise their farms, earn money and exp. to upgrade level. As the battle mode unlock, they will play like WarCraft III: train military in barrack, send out dominion to attack or defense, control their hero character to enhance advantage. If they win the battle, they gain more terrain for their kingdom. Generals and civilians may suddenly overturn their king at this time.
However, this game idea maybe too huge for a student thesis project. There are many detail should figure out how to make the game work. If this game going to be built, I would do more detail design about the Kingdom Hierarchy System first, to make it simpler first for the game.

Acknowledgement: The Kingdom Hierarchy System is first came out by Zhi Dong. He discussed this idea with me two days before the game pitch presentation.