Click here to Skip to main content
11,412,182 members (58,565 online)
Click here to Skip to main content
Articles » Multimedia » DirectX » Games » Downloads
Add your own
alternative version

Game Engine

, 20 Nov 2009 CPL
A game engine first prototype
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO;

using MTV3D65;
using IrrKlang; 

namespace gefx
{
    public class XTMannagerStatic
    {
        public  List<XTModel> UnitS = new List<XTModel>();

       public void AddStaticUnit(string UnitName,string pathtomodel,ref gefxs GE,XTModel.ModelType Type)
       {

           UnitS.Add(new XTModel(ref  GE.Scene,ref  GE.Globals,UnitName,pathtomodel,Type )) ;

       }

       public void AddStaticUnit(string UnitName,  ref gefxs GE, XTModel.ModelType Type)
       {

           UnitS.Add(new XTModel(ref  GE.Scene, ref  GE.Globals, UnitName, Type));

       }

       public void RemoveStaticUnit(string UnitName, ref TVScene scene)
       {
           try
           {

               int index = 0;
               foreach (XTModel u in UnitS)
               {

                   if (u.UnitName == UnitName)
                   {

                       u.MakniJedinicu(ref scene);

                       break;

                   }
                   index++;

               }

               UnitS.RemoveAt(index);
           }
           catch (Exception e)
           {
                throw new System.ArgumentException("Greska : " + e.Message.ToString());
            
           }

       }
       public void RemoveStaticUnit(string UnitName, ref TVScene scene,ref TVPhysics Physics)
       {
           try
           {

               int index = 0;
               foreach (XTModel u in UnitS)
               {

                   if (u.UnitName == UnitName)
                   {

                       u.MakniJedinicu(ref scene,ref Physics );

                       break;

                   }
                   index++;

               }

               UnitS.RemoveAt(index);
           }
           catch (Exception e)
           {
               //throw new System.ArgumentException("Greska : " + e.Message.ToString());

           }

       }

       public void MoveUnit(string Name, float x, float y, float z)
       {

           foreach (XTModel u in UnitS)
           {

               if (u.UnitName == Name)
               {
                   u.SetUnitPosition(x, y, z);

               }

           }

       }
       public void MoveUnit(string Name, TV_3DVECTOR VektorPozicija)
       {

           foreach (XTModel u in UnitS)
           {

               if (u.UnitName == Name)
               {
                   u.SetUnitPosition(VektorPozicija);

               }

           }

       }

       public void MoveUnit(string Name, float x, float y, float z,ref TVPhysics TVP)
       {

           foreach (XTModel u in UnitS)
           {

               if (u.UnitName == Name)
               {
                   u.SetUnitPosition(x, y, z, ref TVP);

               }

           }

       }
       public void MoveUnit(string Name, TV_3DVECTOR VektorPozicija,ref TVPhysics TVP)
       {

           foreach (XTModel u in UnitS)
           {

               if (u.UnitName == Name)
               {
                   u.SetUnitPosition(VektorPozicija,ref TVP );

               }

           }

       }

       public void RotateUnit(string Name, float x, float y, float z)
       {

           foreach (XTModel u in UnitS)
           {
               if (u.UnitName == Name)
               {
                   u.SetUnitRotation(x, y, z);

               }

           }


       }
       public void RotateUnit(string Name, float x, float y, float z, float time)
       {
           foreach (XTModel u in UnitS)
           {
               if (u.UnitName == Name)
               {
                   u.SetUnitRotation(x, y, z,time );

               }

           }

       }
       public void RotateUnit(string Name, TV_3DVECTOR r)
       {

           foreach (XTModel u in UnitS)
           {
               if (u.UnitName == Name)
               {
                   u.SetUnitRotation(r);

               }

           }
       }
       public void RotateUnit(string Name, TV_3DVECTOR r, float time)
       {
           foreach (XTModel u in UnitS)
           {
               if (u.UnitName == Name)
               {
                   u.SetUnitRotation(r,time);

               }

           }

       }
       public void RotateUnit(string Name, float x, float y, float z, ref TVPhysics TVP)
       {

           foreach (XTModel u in UnitS)
           {
               if (u.UnitName == Name)
               {
                   u.SetUnitRotation(x, y, z, ref TVP );

               }

           }


       }
       public void RotateUnit(string Name, float x, float y, float z, float time, ref TVPhysics TVP)
       {
           foreach (XTModel u in UnitS)
           {
               if (u.UnitName == Name)
               {
                   u.SetUnitRotation(x, y, z, time, ref TVP );

               }

           }

       }
       public void RotateUnit(string Name, TV_3DVECTOR r, ref TVPhysics TVP)
       {

           foreach (XTModel u in UnitS)
           {
               if (u.UnitName == Name)
               {
                   u.SetUnitRotation(r,ref TVP );

               }

           }
       }
       public void RotateUnit(string Name, TV_3DVECTOR r, float time, ref TVPhysics TVP)
       {
           foreach (XTModel u in UnitS)
           {
               if (u.UnitName == Name)
               {
                   u.SetUnitRotation(r, time, ref TVP );

               }

           }

       }

       public void ScaleUnit(string Name, float x, float y, float z)
       {
           foreach (XTModel u in UnitS)
           {

               if (u.UnitName == Name)
               {
                   u.SetUnitScale(x, y, z);

               }

           }

       }
       public void ScaleUnit(string Name, TV_3DVECTOR s)
       {
           foreach (XTModel u in UnitS)
           {

               if (u.UnitName == Name)
               {
                   u.SetUnitScale(s);

               }

           }

       }
       public void ScaleUnit(string Name, float x, float y, float z,ref TVPhysics TVP)
       {
           foreach (XTModel u in UnitS)
           {

               if (u.UnitName == Name)
               {

                   
                   TVP.DestroyBody(u.RigidBodyIndex);
                   u.SetUnitScale(x, y, z);
                   SetPhysics(ref TVP, u.UnitName, u.PhysicObjectType, u.ModelMass);
               }

           }

       }
       public void ScaleUnit(string Name, TV_3DVECTOR s,ref TVPhysics TVP)
       {
           foreach (XTModel u in UnitS)
           {

               if (u.UnitName == Name)
               {
                  
                   TVP.DestroyBody(u.RigidBodyIndex);
                   u.SetUnitScale(s);
                   SetPhysics(ref TVP, u.UnitName,u.PhysicObjectType,u.ModelMass );

               }

           }

       }

       public string MouseUnitPick(ref TVScene Scene, int  MousePosX, int  MousePosY)
       {
           string Name="";


           foreach (XTModel u in UnitS)
           {

               if (u.CheckMousePick(MousePosX, MousePosY, ref Scene))
               {
                   Name = u.UnitName;
                   break;
               }

           }

           return Name;

       }
       public string MouseUnitPick(ref TVScene Scene, int MousePosX, int MousePosY, bool ShowBB)
       {
           string Name = "";


           foreach (XTModel u in UnitS)
           {

               if (u.CheckMousePick(MousePosX, MousePosY, ref Scene))
               {
                   Name = u.UnitName;
                   u.ShowUnitBoundingBox(ShowBB);
                   break;
               }

           }

           return Name;

       }
       public void CrtajJedinice(string Name)
       {

           if (Name == "Sve")
           {

               foreach (XTModel u in UnitS)
               {

                   u.CrtajJedinicu();
               }
           }
           else
           {

               foreach (XTModel u in UnitS)
               {
                   if (u.UnitName == Name)
                   {
                       u.CrtajJedinicu();
                       break;
                   }
               }


           }

       }
       public void DodajMaterijalNaJedinicuIzFilea(string UName, string MatFileParh,ref TVGlobals Globals, ref TVMaterialFactory Materijali)
       {

           foreach (XTModel u in UnitS)
           {

               if (u.UnitName == UName)
               {
                   u.AddMaterialUnitFromFile(MatFileParh,ref Materijali, ref Globals );
                   break;

               }

           }

       }
       public  void ShowUnitBoundingBox(string UnitName, bool show)
       {

           if (UnitName == "Sve")
           {
               foreach (XTModel u in UnitS)
               {
                   u.ShowUnitBoundingBox(show);


               }


           }
           else
           {

               foreach (XTModel u in UnitS)
               {

                   if (u.UnitName == UnitName)
                   {
                       u.ShowUnitBoundingBox(show);
                       break;
                   }

               }
           }

           

       }


       public void SaveUnitToXMLFile(string UnitName, string FileName)
       {

           foreach (XTModel u in UnitS)
           {
               if (u.UnitName == UnitName)
               {

                   u.SaveUnitsToFile(FileName);
                   break;
               }

           }

       }
       public bool CheckUnitNameExsist(string Name)
       {
           bool r = false;

           foreach (XTModel a in UnitS)
           {

               if (a.UnitName == Name)
               {

                   r = true;
                   break;
               }

           }

           return r;
       }
       public string SetRandomUnitName()
       {

           string un = "";

           un = "Unit" + UnitS.Count.ToString() + RandomNumber(10, 10000).ToString();

           return un;

       }

       private int RandomNumber(int min, int max)
       {
           Random random = new Random();
           return random.Next(min, max);
       }

       public void SetUnitMatrix(string UnitName, TV_3DMATRIX matrix)
       {

           foreach (XTModel u in UnitS)
           {

               if (u.UnitName == UnitName)
               {
                   u.SetUnitMatrix(matrix);

               }

           }

       }


       public TV_3DVECTOR GetUnitScale(string name)
       {

           TV_3DVECTOR v = new TV_3DVECTOR(0, 0, 0);

           foreach(XTModel x in UnitS )
           {

               if (x.UnitName == name)
               {

                   v = x.GetUnitScale();
                   break;

               }

           }

           return v;

       }

       public TV_3DVECTOR GetUnitPosition(string name)
       {

           TV_3DVECTOR v = new TV_3DVECTOR(0, 0, 0);

           foreach (XTModel x in UnitS)
           {

               if (x.UnitName == name)
               {

                   v = x.GetUnitPosition();
                   break;

               }

           }

           return v;

       }

       #region GET scale, rotate, position and rotate matrix
       public TV_3DVECTOR GetUnitRotate(string name)
       {

           TV_3DVECTOR v = new TV_3DVECTOR(0, 0, 0);

           foreach (XTModel x in UnitS)
           {

               if (x.UnitName == name)
               {

                   v = x.GetUnitRotate();
                   break;

               }

           }

           return v;

       }

       public void GetUnitRotateMatrix(string name, ref TV_3DMATRIX MatrixR)
       {



           foreach (XTModel x in UnitS)
           {

               if (x.UnitName == name)
               {

                   MatrixR = x.GetUnitRotateMatrix();
                   break;

               }

           }



       }

        
       #endregion

       public void SetPhysics(ref  TVPhysics P, string Name)
       {
           foreach (XTModel m in UnitS)
           {
               if (m.UnitName == Name)
               {

                   //P.
                   int _ballPhysicBody;
                   _ballPhysicBody = P.CreateBody(100f);
                   P.AddMesh(_ballPhysicBody, m.Unit, CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_BOX, true );
                   P.SetBodyMovable(_ballPhysicBody, true);
                   //P.SetBodyPosition(_ballPhysicBody, m.Unit.GetPosition().x, m.Unit.GetPosition().y, m.Unit.GetPosition().z);
                   //P.SetBodyRotation(_ballPhysicBody, m.Unit.GetRotation().x, m.Unit.GetRotation().y, m.Unit.GetRotation().z);
                   m.RigidBodyIndex = _ballPhysicBody;
                   P.SetMaterialInteractionBounciness(0, 0, 0.6f);
                   break;


               }


           }

       }

       public void SetPhysics(ref  TVPhysics P, string Name,float Mass)
       {
           foreach (XTModel m in UnitS)
           {
               if (m.UnitName == Name)
               {

                   //P.
                   int _ballPhysicBody;
                   _ballPhysicBody = P.CreateBody(Mass);
                   P.AddMesh(_ballPhysicBody, m.Unit, CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_BOX, true);
                   P.SetBodyMovable(_ballPhysicBody, true);
                   //P.SetBodyPosition(_ballPhysicBody, m.Unit.GetPosition().x, m.Unit.GetPosition().y, m.Unit.GetPosition().z);
                   //P.SetBodyRotation(_ballPhysicBody, m.Unit.GetRotation().x, m.Unit.GetRotation().y, m.Unit.GetRotation().z);
                   m.RigidBodyIndex = _ballPhysicBody;
                   P.SetMaterialInteractionBounciness(0, 0, 0.6f);
                   break;


               }


           }

       }

       public void SetPhysics(ref  TVPhysics P, string Name,CONST_TV_PHYSICSBODY_BOUNDING Type)
       {
           foreach (XTModel m in UnitS)
           {
               if (m.UnitName == Name)
               {

                   //P.
                   int _ballPhysicBody;
                   _ballPhysicBody = P.CreateBody(100f);
                   P.AddMesh(_ballPhysicBody, m.Unit, Type, true);
                   m.PhysicObjectType = Type;
                   P.SetBodyMovable(_ballPhysicBody, true);
                   //P.SetBodyPosition(_ballPhysicBody, m.Unit.GetPosition().x, m.Unit.GetPosition().y, m.Unit.GetPosition().z);
                   //P.SetBodyRotation(_ballPhysicBody, m.Unit.GetRotation().x, m.Unit.GetRotation().y, m.Unit.GetRotation().z);
                   m.RigidBodyIndex = _ballPhysicBody;
                   P.SetMaterialInteractionBounciness(0, 0, 0.6f);
                   break;


               }


           }

       }

       public void SetPhysics(ref  TVPhysics P, string Name, CONST_TV_PHYSICSBODY_BOUNDING Type, float Mass)
       {
           foreach (XTModel m in UnitS)
           {
               if (m.UnitName == Name)
               {

                   //P.
                   int _ballPhysicBody;
                   m.ModelMass = Mass;
                   m.PhysicObjectType = Type;
                   _ballPhysicBody = P.CreateBody(Mass);
                   P.AddMesh(_ballPhysicBody, m.Unit, Type, true);
                   P.SetBodyMovable(_ballPhysicBody, true);
                   //P.SetBodyPosition(_ballPhysicBody, m.Unit.GetPosition().x, m.Unit.GetPosition().y, m.Unit.GetPosition().z);
                   //P.SetBodyRotation(_ballPhysicBody, m.Unit.GetRotation().x, m.Unit.GetRotation().y, m.Unit.GetRotation().z);
                   m.RigidBodyIndex = _ballPhysicBody;
                   P.SetMaterialInteractionBounciness(0, 0, 0.6f);
                   break;


               }


           }

       }

       public int GetPhysxBodyIndex(string Name)
       {

           int r = 0;

           foreach (XTModel m in UnitS)
           {
               if (m.UnitName == Name)
               {
                   r = m.RigidBodyIndex;
                   break;
               }

           }

           return r;

       }

       public TV_3DVECTOR GetPhysicsBodyPosition(string Name, ref TVPhysics P)
       {
           TV_3DVECTOR v = new TV_3DVECTOR(0, 0, 0);

           foreach (XTModel m in UnitS)
           {

               if (m.UnitName == Name)
               {

                   v = P.GetBodyPosition(m.RigidBodyIndex);
                   break;

               }



           }

           return v;



       }

       public void DrawCoordinateArroundActor(string name, float length)
       {

           foreach (XTModel m in UnitS)
           {


               if (m.UnitName == name)
               {

                   m.DrawCoordinateSystem(length);
                   break;
               }

           }
       }


       public void UpdateUnits()
       {

           foreach (XTModel m in UnitS)
           {

               m.Update();

           }

       }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Public License Version 1.0 (CPL)

Share

About the Author

Member 3873633
Software Developer
Croatia Croatia
Programer

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150414.5 | Last Updated 20 Nov 2009
Article Copyright 2009 by Member 3873633
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid