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;

1 comment: