Click here to Skip to main content
12,623,776 members (34,602 online)
Click here to Skip to main content
Articles » Multimedia » DirectX » Games » Downloads

Stats

28.6K views
1.4K downloads
34 bookmarked
Posted

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 XTMannagerActor
    {

        public  List<XTModelActor> UnitD = new List<XTModelActor>();

        public void AddUnit(string UnitName, string pathtomodel, ref gefxs GE, gefx.XTModelActor.ModelActorType Type)
        {

            UnitD.Add(new XTModelActor(ref  GE.Scene, ref  GE.Globals, UnitName, pathtomodel, Type));

        }

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

                int index = 0;
                foreach (XTModelActor u in UnitD)
                {

                    if (u.UnitActorName == UnitName)
                    {

                        u.MakniJedinicu(ref scene, ref Physics );

                        break;

                    }
                    index++;

                }

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

            }

        }

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

                int index = 0;
                foreach (XTModelActor u in UnitD)
                {

                    if (u.UnitActorName == UnitName)
                    {

                        u.MakniJedinicu(ref scene, ref Physics,ref GE );

                        break;

                    }
                    index++;

                }

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

            }

        }

        public void DestroyAttachedBoneMesh(string name,ref gefxs GE)
        {
            foreach (XTModelActor a in UnitD)
            {
                if (a.UnitActorName == name)
                {
                    a.DestroyAttachedBoneMesh(ref GE.XModel, ref GE.Scene, ref GE.Fizika.PhysX);
                    break;

                }

            }

        }


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

            foreach (XTModelActor u in UnitD)
            {

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

                }

            }

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

            foreach (XTModelActor u in UnitD)
            {

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

                }

            }

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

            foreach (XTModelActor u in UnitD)
            {
                if (u.UnitActorName == Name)
                {
                    u.SetUnitRotation(x, y, z);

                }

            }


        }
        public void RotateUnit(string Name, float x, float y, float z, float time)
        {
            foreach (XTModelActor u in UnitD)
            {
                if (u.UnitActorName == Name)
                {
                    u.SetUnitRotation(x, y, z, time);

                }

            }

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

            foreach (XTModelActor u in UnitD)
            {
                if (u.UnitActorName == Name)
                {
                    u.SetUnitRotation(r);

                }

            }
        }
        public void RotateUnit(string Name, TV_3DVECTOR r, float time)
        {
            foreach (XTModelActor u in UnitD)
            {
                if (u.UnitActorName == Name)
                {
                    u.SetUnitRotation(r, time);

                }

            }

        }

        

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

            foreach (XTModelActor u in UnitD)
            {

                if (u.UnitActorName == Name)
                {
                    u.SetUnitPosition(x, y, z,ref TvP );

                }

            }

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

            foreach (XTModelActor u in UnitD)
            {

                if (u.UnitActorName == Name)
                {
                    u.SetUnitPosition(VektorPozicija, ref TvP);

                }

            }

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

            foreach (XTModelActor u in UnitD)
            {
                if (u.UnitActorName == 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 (XTModelActor u in UnitD)
            {
                if (u.UnitActorName == Name)
                {
                    u.SetUnitRotation(x, y, z, time, ref TvP);

                }

            }

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

            foreach (XTModelActor u in UnitD)
            {
                if (u.UnitActorName == Name)
                {
                    u.SetUnitRotation(r, ref TvP);

                }

            }
        }
        public void RotateUnit(string Name, TV_3DVECTOR r, float time, ref TVPhysics TvP)
        {
            foreach (XTModelActor u in UnitD)
            {
                if (u.UnitActorName == Name)
                {
                    u.SetUnitRotation(r, time, ref TvP);

                }

            }

        }


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

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

                }

            }

        }
        public void ScaleUnit(string Name, TV_3DVECTOR s)
        {
            foreach (XTModelActor u in UnitD)
            {

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

                }

            }

        }


        public void ScaleUnit(string Name, float x, float y, float z, ref TVPhysics TVP)
        {
            foreach (XTModelActor u in UnitD)
            {

                if (u.UnitActorName == Name)
                {
                   
                    TVP.DestroyBody(u.RigidBodyIndex);
                    u.SetUnitScale(x, y, z);
                    SetPhysics(ref  TVP, u.UnitActorName,u.PhysicObjectType,u.ModelMass );

                }

            }

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

                if (u.UnitActorName == Name)
                {
                    TVP.DestroyBody(u.RigidBodyIndex);
                    u.SetUnitScale(s);

                    SetPhysics(ref  TVP, u.UnitActorName, u.PhysicObjectType, u.ModelMass);



                }

            }

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


            foreach (XTModelActor u in UnitD)
            {

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

            }

            return Name;

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


            foreach (XTModelActor u in UnitD)
            {

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

            }

            return Name;

        }
        public void CrtajJedinice(string Name)
        {

            if (Name == "Sve")
            {

                foreach (XTModelActor u in UnitD)
                {

                    u.CrtajJedinicu();
                    if (u.IsSelected)
                    {



                    }
                }
            }
            else
            {

                foreach (XTModelActor u in UnitD)
                {
                    if (u.UnitActorName == Name)
                    {
                        u.CrtajJedinicu();
                        break;
                    }
                }


            }



        }
        public void CrtajJedinice(string Name, ref TVScreen2DText Text2D,ref TVGlobals Globals)
        {

            if (Name == "Sve")
            {

                foreach (XTModelActor u in UnitD)
                {

                    
                    if (u.IsSelected)
                    {

                        Text2D.TextureFont_DrawBillboardText(u.UnitActorName,
                            u.GetUnitPosition().x,
                            u.GetUnitPosition().y + 15,
                            u.GetUnitPosition().z, 
                            Globals.RGBA(0, 1, 0, 1), 
                            Text2D.TextureFont_GetFontByName("font_tex2"), 10, 10);


                    }
                    u.CrtajJedinicu();
                }
            }
            else
            {

                foreach (XTModelActor u in UnitD)
                {
                    if (u.UnitActorName == Name)
                    {
                        u.CrtajJedinicu();
                        break;
                    }
                }


            }



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

            foreach (XTModelActor u in UnitD)
            {

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

                }

            }

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

            if (UnitName == "Sve")
            {
                foreach (XTModelActor u in UnitD)
                {
                    u.ShowUnitBoundingBox(show);


                }


            }
            else
            {

                foreach (XTModelActor u in UnitD)
                {

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

                }
            }



        }
        public void PlayAnimation(string Animation, string Name)
        {
            foreach (XTModelActor Actor in UnitD)
            {

                if (Actor.UnitActorName  == Name)
                {
                    Actor.PlayAnimation(Animation);

                    break;
                }
            }

        }
        public void SetAnimLoop(string Name, bool f)
        {
            foreach (XTModelActor Actor in UnitD)
            {
                if (Actor.UnitActorName  == Name)
                {
                    Actor.ChangeAnimLoop(f);
                    break;
                }
            }
        }
        public string[] GetListAnimation(string Name)
        {
            string[] r = new string[0];



            foreach (XTModelActor Actor in UnitD)
            {

                if (Actor.UnitActorName  == Name)
                {

                    r = Actor.GetListAnimation();

                    break;
                }
            }

            return r;


        }

        public void SaveUnitToXMLFile(string UnitName, string FileName)
        {

            foreach (XTModelActor u in UnitD)
            {
                if (u.UnitActorName  == UnitName)
                {

                    u.SaveUnitsToFile(FileName);
                    break;
                }

            }

        }

        public void StopPlayAnimation(string name)
        {


            foreach (XTModelActor u in UnitD)
            {
                if (u.UnitActorName == name)
                {

                    u.StopPlayingAnimation();
                    break;
                }

            }


        }

        public void ResumeAnimation(string name)
        {


            foreach (XTModelActor u in UnitD)
            {
                if (u.UnitActorName == name)
                {

                    u.ResumePlayAnimation();
                    break;
                }

            }


        }


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

            foreach (XTModelActor a in UnitD)
            {

                if (a.UnitActorName == Name)
                {

                    r = true;
                    break;
                }

            }

            return r;
        }


        public string SetRandomUnitName()
        {

            string un = "";

            un ="Unit" + UnitD.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 (XTModelActor  u in UnitD)
            {

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

                }

            }

        }



        #region GET Scale, Rotate, Position, Matrix
        public TV_3DVECTOR GetUnitScale(string name)
        {

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

            foreach (XTModelActor x in UnitD)
            {

                if (x.UnitActorName == name)
                {

                    v = x.GetUnitScale();
                    break;

                }

            }

            return v;

        }

        public TV_3DVECTOR GetUnitPosition(string name)
        {

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

            foreach (XTModelActor x in UnitD)
            {

                if (x.UnitActorName == name)
                {

                    v = x.GetUnitPosition();
                    break;

                }

            }

            return v;

        }

        public TV_3DVECTOR GetUnitRotate(string name)
        {

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

            foreach (XTModelActor x in UnitD)
            {

                if (x.UnitActorName == name)
                {

                    v = x.GetUnitRotate();
                    break;

                }

            }

            return v;

        }

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



            foreach (XTModelActor x in UnitD)
            {

                if (x.UnitActorName == name)
                {

                    MatrixR = x.GetUnitRotateMatrix();
                    break;

                }

            } 
        #endregion



        }


        public void SetPhysics(ref  TVPhysics P, string Name)
        {
            foreach (XTModelActor  m in UnitD)
            {
                if (m.UnitActorName == Name)
                {

                    //P.
                    int _ballPhysicBody;
                    _ballPhysicBody = P.CreateBody(100f);
                    //P.AddMesh(_ballPhysicBody, m.Unit, CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_BOX, true);
                    P.AddActor(_ballPhysicBody, m.UnitActor, 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 (XTModelActor m in UnitD)
            {
                if (m.UnitActorName == Name)
                {

                    //P.
                    int _ballPhysicBody;
                    _ballPhysicBody = P.CreateBody(Mass);
                    P.AddActor(_ballPhysicBody, m.UnitActor, 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 (XTModelActor m in UnitD)
            {
                if (m.UnitActorName == Name)
                {

                    //P.
                    int _ballPhysicBody;
                    _ballPhysicBody = P.CreateBody(100f);
                    //P.AddMesh(_ballPhysicBody, m.Unit, CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_BOX, true);
                    P.AddActor(_ballPhysicBody, m.UnitActor, 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 (XTModelActor m in UnitD)
            {
                if (m.UnitActorName == Name)
                {

                    //P.
                    int _ballPhysicBody;
                    _ballPhysicBody = P.CreateBody(Mass);
                    P.AddActor(_ballPhysicBody, m.UnitActor, Type, true);
                    P.SetBodyMovable(_ballPhysicBody, true);
                    m.PhysicObjectType = Type;
                    m.ModelMass = Mass;
                    //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 TV_3DVECTOR GetPhysicsBodyPosition(string Name, ref TVPhysics P)
        {
            TV_3DVECTOR v = new TV_3DVECTOR(0, 0, 0);

            foreach (XTModelActor m in UnitD)
            {

                if (m.UnitActorName  == Name)
                {

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

                }



            }

            return v;



        }



        public void DrawCoordinateArroundActor(string name, float length)
        {

            foreach (XTModelActor m in UnitD)
            {


                if (m.UnitActorName == name)
                {

                    m.DrawCoordinateSystem(length);
                    break;
                }

            }
        }


        public string [] GetListBones(string name)
        {
            string[] r = new string[0];

            foreach (XTModelActor m in UnitD)
            {

                if (m.UnitActorName == name)
                {

                    r = m.GetBones();
                    break;
                }


            }

            return r;


        }

        public int GetBoneCount(string name)
        {

            int i = -127000;

            foreach (XTModelActor x in UnitD)
            {
                if (x.UnitActorName == name)
                {
                    i = x.GetBoneCount();
                    break;
                }


            }
            return i;

        }

        public void UpdateActors()
        {

            foreach (XTModelActor a in UnitD)
            {

                a.UpdateActor();

            }

        }

        public void UpdateActors(ref gefxs GE,bool see)
        {

            foreach (XTModelActor a in UnitD)
            {

                a.UpdateActor(ref GE,see);

            }

        }

        public void UpdateActors(ref XTMannagerStatic  GE, bool see)
        {

            foreach (XTModelActor a in UnitD)
            {

                a.UpdateActor(ref GE, see);

            }

        }


        public void UpdateActors(float MouseX, float MouseY, bool MouseB1, TVScene Scene, TVInputEngine Inp)
        {

            foreach (XTModelActor a in UnitD)
            {
                SelectUnitsRTS(MouseX, MouseY, MouseB1, Scene, Inp);

                a.UpdateActor();

            }

        }

        public void Walk(TV_3DVECTOR DestinationPoint, string name, ref TVPhysics TVP, float fTime, float speed,TVLandscape Land)
        {

            foreach (XTModelActor m in UnitD)
            {

                if (m.UnitActorName == name)
                {
                    m.Walk(DestinationPoint, ref TVP, fTime, speed, Land);

                    break;
                }


            }

        }


        public void WalkAllSelected(TV_3DVECTOR DestinationPoint, 
            string name,
            ref TVPhysics TVP,
            float fTime, 
            float speed,
            TVLandscape Land, 
            ref gefxs GE,
            bool GenerirajDecole,
            float DecolTimeLive)
        {

          

            foreach (XTModelActor m in UnitD)
            {

     

                if (m.IsSelected && GE.Kamera2.tmpMouseB2   )
                {
                  
                        m.AddActorPath(DestinationPoint);
                       
                    
                       
                }

                if (m.IsMoving)
                {

                    m.Walk(fTime, speed, ref GE, false, 0, "");
                }
               


            }

        }

         
        public  TV_2DVECTOR Mouse1Coor;
        public  TV_2DVECTOR Mouse2Coor;
        TV_2DVECTOR Mouse3Coor;
        TV_2DVECTOR Mouse4Coor;
        TV_2DVECTOR tMouse1Coor;
        TV_2DVECTOR tMouse2Coor;
        TV_3DVECTOR tmpDest;
        TV_3DVECTOR tmpDest2;


        public void SelectUnitsRTS(float MouseX, float MouseY, bool MouseB1, TVScene Scene, TVInputEngine Inp)
        {
            TVCollisionResult CollResult = new TVCollisionResult();
            if (Inp.IsMouseButtonPressed(0) == true)
            {
                if (MouseB1 == false)
                {
                    Mouse1Coor.x = MouseX;
                    Mouse1Coor.y = MouseY;
                    MouseB1 = true;
                    Mouse2Coor.x = MouseX;
                    Mouse2Coor.y = MouseY;
                }
            }

            if (MouseB1 == true)
            {
                Mouse2Coor.x = MouseX;
                Mouse2Coor.y = MouseY;
            }

            if (Inp.IsMouseButtonPressed(0) == false)
            {
                if (MouseB1 == true)
                {
                    
                    Mouse2Coor.x = MouseX;
                    Mouse2Coor.y = MouseY;

                    Mouse3Coor.x = Mouse1Coor.x;
                    Mouse3Coor.y = Mouse2Coor.y;
                    Mouse4Coor.x = Mouse2Coor.x;
                    Mouse4Coor.y = Mouse1Coor.y;
                    MouseB1 = false;
                    int tx1 = System.Convert.ToInt32(Mouse1Coor.x);
                    int tx2 = System.Convert.ToInt32(Mouse1Coor.y);


                    //select units
                    CollResult = Scene.MousePick(tx1, tx2, (int)CONST_TV_OBJECT_TYPE.TV_OBJECT_LANDSCAPE, CONST_TV_TESTTYPE.TV_TESTTYPE_ACCURATETESTING );
                    Mouse1Coor.x = CollResult.GetCollisionImpact().x;
                    Mouse1Coor.y = CollResult.GetCollisionImpact().z;
                    CollResult = Scene.MousePick((int)Mouse2Coor.x, (int)Mouse2Coor.y, (int)CONST_TV_OBJECT_TYPE.TV_OBJECT_LANDSCAPE, CONST_TV_TESTTYPE.TV_TESTTYPE_ACCURATETESTING);
                    Mouse2Coor.x = CollResult.GetCollisionImpact().x;
                    Mouse2Coor.y = CollResult.GetCollisionImpact().z;

                    tMouse1Coor = Mouse1Coor;
                    tMouse2Coor = Mouse2Coor;

                    foreach (XTModelActor Unit in UnitD)
                    {

                        if (Mouse1Coor.x < Mouse2Coor.x & Mouse1Coor.y < Mouse2Coor.y)
                        {
                            tMouse1Coor.y = Mouse2Coor.y;
                            tMouse2Coor.y = Mouse1Coor.y;
                        }
                        else if (Mouse1Coor.x < Mouse2Coor.x & Mouse1Coor.y > Mouse2Coor.y)
                        {
                            tMouse1Coor = Mouse1Coor;
                            tMouse2Coor = Mouse2Coor;
                        }
                        else if (Mouse1Coor.x > Mouse2Coor.x & Mouse1Coor.y > Mouse2Coor.y)
                        {
                            tMouse1Coor.x = Mouse2Coor.x;
                            tMouse2Coor.x = Mouse1Coor.x;
                        }
                        else if (Mouse1Coor.x > Mouse2Coor.x & Mouse1Coor.y < Mouse2Coor.y)
                        {
                            tMouse1Coor = Mouse2Coor;
                            tMouse2Coor = Mouse1Coor;
                        }
                        //Unit.IsUsed == true &
                        if ( Unit.Team == 0)
                        {
                            if (Unit.GetUnitPosition().x > tMouse1Coor.x & Unit.GetUnitPosition().x < tMouse2Coor.x)
                            {
                                if (Unit.GetUnitPosition().z < tMouse1Coor.y & Unit.GetUnitPosition().z > tMouse2Coor.y)
                                {
                                    Unit.IsSelected = true;


                                    Unit.IsUsed = true;
                                   
                                }
                                else
                                {
                                    Unit.IsSelected = false;

                                }
                            }

                        }
                    }
                }
            }




        }

        public void DeselectUnits()
        {

            foreach (XTModelActor a in UnitD)
            {

                a.IsSelected = false;
                
            }
        }

        public void SetActorBoneSkelet(string whichOne,ref gefxs GE)
        {
            if (whichOne == "Sve")
            {

                foreach (XTModelActor m in UnitD)
                {
                    if (m.UnitActor != null)
                    {
                        m.SetActorBoneBB(ref GE );
                    }

                }



            }
            else
            {

                foreach (XTModelActor m in UnitD)
                {
                    if (m.UnitActor != null)
                    {

                        if (m.UnitActorName == whichOne)
                        {

                            m.SetActorBoneBB(ref GE );

                            break;
                        }

                    }

                }



            }



        }


        public void TestPhysicsCollision(ref  TVPhysics PHY)
        {

            foreach (XTModelActor a in UnitD)
            {

                foreach (XTModelActor aa in UnitD)
                {
                    if (PHY.TestCollision(a.RigidBodyIndex, aa.RigidBodyIndex, true))
                    {
                        if (a.GetActorType() == aa.GetActorType())
                        {
                            TV_3DVECTOR px = a.UnitPath;
                            TV_3DVECTOR offset = new TV_3DVECTOR(0,0,5);
                            a.SetUnitPosition(px + offset, ref PHY);                            
                        }
                    }
                }
            }
        }
        TVCollisionResult CollisionResult;
        TVMathLibrary MathLib= new TVMathLibrary();
        TV_3DVECTOR v1;
        TV_3DVECTOR v2;
        public void TestSpoted(TVScene Scene)
        {
            foreach (XTModelActor a in UnitD)
            {

                foreach (XTModelActor aa in UnitD)
                {
                    if (a.UnitActorName != aa.UnitActorName)
                    {

                        v1= MathLib.VNormalize(MathLib.VSubtract(a.GetUnitPosition(), aa.GetUnitPosition()));
                        v2 = MathLib.VNormalize(MathLib.VSubtract(a.UnitPath  , aa.GetUnitPosition()));

                       float kut = MathLib.VDotProduct(v1, v2);

                       if (kut >= 0.7071f && kut <= 1)
                       {

                           a.UnitStatus = "Spooted +" + aa.UnitActorName + " " + kut.ToString();



                       }
                       else
                       {

                           a.UnitStatus = "null";

                       }

                      

                    }
                }
            }


            

        }

        public string GetUnitStatus(string UnitName)
        {
            string r = "null";
            foreach (XTModelActor m in UnitD)
            {

                if (m.UnitActorName == UnitName)
                {

                    r = m.UnitStatus;

                }

            }

            return r;

        }

    }
}

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

You may also be interested in...

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