Friday, October 29, 2010

3D Transformation Working!

Update on capstone:
I think I finished Level class methods save, load, delete. It was tested and works ok. Need something to save from Level, have no idea how to build the game level yet. I would like to start creating a load screen now.

Combined model working!
Back to previous block I think I finished it. My 3D model didn't have any ModelBones so it was done by combining several 3D models together. It uses AddChild() methods that add child GameObjects to its parent GameObject. Unfortunately it is a tree-like structure and I am not looping through it very efficiently. The question is if there are a lot of children what the game frame-rate would be. I believe it can be used for up to 2 levels of tree (child<-parent<-grandpa). I got a help with math from Yen, a phd student at SCI Institude. I have to admit this was hard to see how it works. I think it is still not finished and needs some testing. Here is the video shot from the XNA test, submoon<-moon<-planet<-sun, there are 4 planets, sun si moving in +x direction and the whole system is following it.

I put a forum thread about this at Gamedev.net http://www.gamedev.net/community/forums/topic.asp?topic_id=586310.

How to use it:
in Upload()
star = new GameObject(Content.Load("Models\\star"));
star.Scale = 4.0f;
star.Position = new Vector3(-10.0f, 0.0f, 0.0f);

planet1 = new GameObject(Content.Load("Models\\blue_star"));
planet1.Scale = 0.5f;
planet1.Position = new Vector3(3.0f, 0.0f, 0.0f);
star.AddChild("planet1", planet1);

planet2 = new GameObject(Content.Load("Models\\blue_star"));
planet2.Scale = 0.5f;
planet2.Position = new Vector3(-3.0f, 0.0f, 0.0f);

star.AddChild("planet2", planet2);
planet3 = new GameObject(Content.Load("Models\\blue_star"));
planet3.Scale = 0.5f;
planet3.Position = new Vector3(0.0f, 0.0f, 3.0f);

star.AddChild("planet3", planet3);
planet4 = new GameObject(Content.Load("Models\\blue_star"));
planet4.Scale = 0.5f;
planet4.Position = new Vector3(0.0f, 0.0f, -3.0f);

star.AddChild("planet4", planet4);
moon = new GameObject(Content.Load("Models\\red_star"));
moon.Position = new Vector3(0.0f, -2.0f, 0.0f);
planet2.AddChild("moon", moon);

moon2 = new GameObject(Content.Load("Models\\red_star"));
moon2.Scale = 0.5f;
moon2.Position = new Vector3(0.0f, 1.0f, 0.0f);
moon.AddChild("moon2", moon2);


in Update()
star.Rotation.Y += 0.01f;
star.Position.X += 0.01f;
planet2.Rotation.X += 0.01f;
moon.Rotation.Z -= 0.2f;

Thursday, October 28, 2010

Game Save and ModelBone Class

So I started working on game level save, load, delete options. In regards to file system I've chosen to save games in the given location the gamer can't change. Files will be handled in the directory next to .exe file (bin folder) where also the image storage is. Need to figure out exactly what StorageDevice class does.
Sources:
http://msdn.microsoft.com/en-us/library/bb199073(v=XNAGameStudio.31).aspx
http://msdn.microsoft.com/en-us/library/bb200105.aspx

In regards to previous blog I finally found a tutorial for animations in XNA 3.1. It uses ModelBone class and seems to be quite usefull. I am planning to wrap it in AddChild(), RemoveChild(), Transfer(), Rotate() methods. Combined model can move as one and its parts can move independently relatively to the model's center. Here is the video shot from the tutorial to get the idea:



This would allow us to build modular ships and some cool animations with complex models.
Sources:
http://create.msdn.com/en-US/education/catalog/sample/simple_animation (XNA 4.0)
http://www.toymaker.info/Games/XNA/html/xna_matrix.html (XNA 3.1)
http://www.toymaker.info/Games/XNA/html/xna_models.html

Monday, October 25, 2010

3D Modularity and Animations

I spent some time on this but still not sure how to do it in XNA... the idea is to create some

parentModel.AddChild(childModel);

function that adds (attaches) a child 3d model to other parent 3d model. The coordinates of the child would be relative to the parent's one. If

parentModel.childModel.Position

is changed it will do that in regards to the center of the parent model but not change the parentModel position itself.
Then the beauty of all of it would be that moving or rotating the parent by changing

parentModel.Position
parentModel.rotate

would move or rotate all those 2 models together as one. By combining children and parents and changing their relative positions (rotations) would enable us to code in C# some cool animations or build complex models like we were able to do in our other class CS2420 with C++ OpenGL http://eng.utah.edu/~dusatko/CS2420-EAE/hw6.html (video shot).

Another example would be the automobile model. The automobile has wheels that turn independently when the whole model is moving (preferably wheels turning faster when car speeds up)

Thursday, October 21, 2010

Game Engine Ideas

I believe that introducing force will save a lot of time when working on effects or with the environment. Then we can introduce some more interesting game-play with puzzles. The only difference from the version we have now is that you put a Newton law between and calculate position and speed by it.

// this would be inside your Movable class (or defined by interface)
public void Move(float time)
{
position += velocity * time;
velocity += _force * inverseMass * time;
}

public void AddForce(Vector3 force)
{
_force += force;
}

public void ClearForces()
{
_force = Vector3.Zero;
}

Then from your game class inside your Update() you would just apply to certain (or to all, or to just one) Movable objects a force... this force can be anything... then if there are no forces it would just not move or stay moving in constant speed.

// Inside Update()
//whatever objects you decide to act force on
foreach (GameObject enemy in enemies)
{
//whatever force you decide
enemy.AddForce(GetGravityAt(enemy.position));
enemy.Move( 0.001f);
enemy.ClearForces();
}

aside from the movable class there would be collidable one making sure that everything explodes or bounces properly if their bounding boxes collide...

Some examples of use:

  1. ship's racket engine - just applying force in direction you want to move or in the opposite to break. Here is the example please notice how there is a lag when firing the engine and how the movements of the ship are smooth - this would not be possible without using forces http://eng.utah.edu/~dusatko/CS1410-EAE/asteroids.html (CS1410 class, forces used)
  2. simple AI - you can code it the way that your ship's position vector is passed to your enemies, enemy class then calculates its direction vector to your position and applies it as a force. If the enemy is already passing by your ship it will start circling around you, then if it gets to certain distance it can start shooting at you (you decide). Here is the example, sharks get the force applied so they are circling around you http://eng.utah.edu/~dusatko/CS2420-EAE/finalProject.html (CS2420 class, forces used)
  3. Tractor beam - lets say you want to pull some asteroid, just aim and push the button, this would create some long 3d cylinder object starting from you and if it touches your chosen asteroid then it would have a collision with it and trigger adding some force to it in your direction
  4. Sticky nebula - this would be position dependent, if you get between certain coordinates in whatever direction you are moving the small force (smaller then your engines have) would act in opposite direction of your velocity. This would go for all movable objects that get to this sticky area.
  5. Black hole - this would be also position dependent, once you create a black hole it will check the nearest objects and add forces to them so they move to it. There would be some effect when they collide with the actual bounding box of the black hole.
I believe we can come up with many more ideas how to use this force. I think it is ok without the forces but all effects will not come so naturally and we may actually spend more time just figuring them out how to do some hacks to the game
engine.

Wednesday, October 6, 2010

Possible Storyline and Game Levels

I was lately contemplating over the story that would fit our spacecraft game. Here are two options I think I may like:
  1. The player is fighting and at the same time running away from some evil corporation. The only way to win is to find enough evidence about the company and bring them to justice. The player wanders through the space following the scrums of information and getting closer to the final resolution. Similar to plot in the movie Firefly but with only one character. Hyper jumps available or just classic space travel between levels. Ship repair or upgrades available.
  2. The player is lost in space and with half damaged ship is trying to find the way back home to the Earth. Each hyper jump or classic space travel gets the player to other more difficult level but closer to the Earth. Similar to the plot in the movie Lost in Space. Ship repair or upgrades available.
From our other EAE game design classes I found the level creation to be the most difficult task. To give it an early start I am brainstorming some possible ones here:
  1. To train the pilot the 1st level would be just classical getting out of the asteroid field
  2. Asteroid field + dangerous radiation star - pilot hast to pass by the dangerous radiation star, the only possible defence against the radiation is to tractor the asteroid so the player stays in its shadow. The asteroids are being vaporized and when too small the pilot needs to find another one to stay hidden from radiation rays.

  3. Defend the passenger ship against evil robots - classical space shooter fight defending the helpless ship
  4. Red matter escape - to finish this level and get to the other one is to penetrate an asteroid field surrounding the red star and avoid the evil enemy robot ships and shoot the Red matter into the star. This would create the black hole and the hyper-jump to next level would be possible.


  5. Sticky nebula - again fighting the evil robot ships with possibility to get stuck in dangerous slowing down sticky nebula
The final level can be a spectacular battle (similar to Star Wars) combined with all above difficulties, boss ship possible...

Saturday, October 2, 2010

Red Matter Test

Here is the small test I did in XNA for a possible new weapon, it works similar to the StarTrek's red matter. When it is shot into the star it creates a "black hole". The same game engine can be used for a tractor beam. Only instead of pulling all stars it would pull the one that collides with some tractor beam 3D model (maybe something like a long cylinder?). Here is the footage of the red matter prototype, the red star is the black hole now and it slowly pulses...

Friday, October 1, 2010

Space the Final Frontier

So I am a new member of the Space team. I am quite happy with this choice since I am a hard core Sci-Fi fan.

I think the idea of the red matter from the new Star Trek movie is just awesome. It can be used as a weapon (shooting it into the planet or star close to the enemies) or as a mean of escaping through its black hole. Here is some video that shows how the black hole may look like
http://www.youtube.com/watch?v=gCwlj4XJPMo&feature=related

In regards to changing gravity, we just need to tweak the game engine a little bit... in addition to checking on collisions it would recalculate distances between the enemy ships and the location of the gravity pull. This would also quite easily enable us to have the tractor beam.

I started playing with 3D engine and I hope to simulate some gravity pull and have it ready for the next week.