Click here to Skip to main content
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.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using gefx;
using MTV3D65;

namespace SceneEditor
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        gefx.gefxs Engine = new gefx.gefxs();
        SaveScene scenes = new SaveScene();

        bool bMove = false;
        bool bScale = false;
        bool bRotate = false;



        private void Form1_Load(object sender, EventArgs e)
        {
            this.Show();
            this.Focus();
            this.picScene.MouseMove += new System.Windows.Forms.MouseEventHandler(this.picScene_MouseMove);

            Engine.SetUpScene(picScene.Handle, 800, 600, true, CONST_TV_MULTISAMPLE_TYPE.TV_MULTISAMPLE_4_SAMPLES, true, true);
            Application.DoEvents();
            

            Engine.GameLoop();
            Application.Exit();
            


        }
        public void picScene_MouseMove(object sender, EventArgs e)
        {
            //this.picScene.Focus();

         
        }

        private void picScene_Click(object sender, EventArgs e)
        {
            this.picScene.Focus();

        }

        private void button4_Click(object sender, EventArgs e)
        {
            lblAction.Text = "Scale";
            bMove = false;
            bScale = true;
            bRotate = false;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            lblAction.Text = "Rotate";
            bMove = false;
            bScale = false;
            bRotate = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            lblAction.Text = "Move";
            bMove = true;
            bScale = false;
            bRotate = false;
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            lblAction.Text = "No action";
            bMove = false;
            bScale = false;
            bRotate = false;
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            
        }

        private void button5_Click(object sender, EventArgs e)
        {

            

        }

        #region STRING FUNKCIJE
        public static string Left(string param, int length)
        {
            //we start at 0 since we want to get the characters starting from the
            //left and with the specified lenght and assign it to a variable
            string result = param.Substring(0, length);
            //return the result of the operation
            return result;
        }
        public static string Right(string param, int length)
        {
            //start at the index based on the lenght of the sting minus
            //the specified lenght and assign it a variable
            string result = param.Substring(param.Length - length, length);
            //return the result of the operation
            return result;
        }

        public static string Mid(string param, int startIndex, int length)
        {
            //start at the specified index in the string ang get N number of
            //characters depending on the lenght and assign it to a variable
            string result = param.Substring(startIndex, length);
            //return the result of the operation
            return result;
        }

        public static string Mid(string param, int startIndex)
        {
            //start at the specified index and return all characters after it
            //and assign it to a variable
            string result = param.Substring(startIndex);
            //return the result of the operation
            return result;
        } 
        #endregion


        private void button1_Click(object sender, EventArgs e)
        {

            if (txtUnitName.Text.Length <= 1)
            {



            }
            else
            {
                if (Engine.XActor.CheckUnitNameExsist(txtUnitName.Text))
                {
                    txtUnitName.Text = Engine.XActor.SetRandomUnitName();

                }
                else
                {

                    if (Engine.XModel.CheckUnitNameExsist(txtUnitName.Text))
                    {

                        txtUnitName.Text = Engine.XModel.SetRandomUnitName();

                    }
                    else
                    {

                        if (rbUnitTypeActor.Checked)
                        {

                            oLoadUnitMesh.Filter = "Animirani |*.tva";
                            oLoadUnitMesh.ShowDialog();
                            string f = oLoadUnitMesh.FileName;
                            Engine.XActor.AddUnit(txtUnitName.Text.ToString(), f, ref Engine, XTModelActor.ModelActorType.TVA);



                        }

                        if (rbUnitTypeMesh.Checked)
                        {
                            oLoadUnitMesh.Filter = "Model|*.tvm|DirectX |*.x";
                            oLoadUnitMesh.ShowDialog();
                            string f = oLoadUnitMesh.FileName;
                            if (Right(f, 3) == "tvm" || Right(f, 3) == "TVM")
                            {

                                Engine.XModel.AddStaticUnit(txtUnitName.Text.ToString(), f, ref Engine, XTModel.ModelType.TVM);
                            }
                            if (Right(f, 1) == "x" || Right(f, 1) == "X")
                            {

                                Engine.XModel.AddStaticUnit(txtUnitName.Text.ToString(), f, ref Engine, XTModel.ModelType.StaticX);
                            }


                        }
                    }

                }

                


            }



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

            Engine.Kamera2.GetMSpacePos((float )Engine.Kamera2.tmpMouseX, (float )Engine.Kamera2.tmpMouseY, ref vc);

            //Engine.XModel.SetUnitMatrix(txtUnitName.Text, Engine.Kamera2._camera.GetMatrix());

            TV_3DVECTOR offset = new TV_3DVECTOR(0, 0, 20);

            //offset = Engine.Kamera2.GetCameraDirection();
            Engine.XActor.MoveUnit(txtUnitName.Text, v, ref Engine.Fizika.PhysX);
            Engine.XModel.MoveUnit(txtUnitName.Text, v, ref Engine.Fizika.PhysX);
           
            //Engine.XModel.SetPhysics(ref Engine.Fizika.PhysX, txtUnitName.Text);
            //Engine.XActor.SetPhysics(ref Engine.Fizika.PhysX, txtUnitName.Text);


            TreeNode node;

            //node = tvUnitsList.Nodes.Add("Fruits");
            //node.Nodes[0].Nodes.Add("ts");
            //node.Nodes.Add("Peach");

          


        }
        TV_3DVECTOR v = new TV_3DVECTOR(0, 0, 0);
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (Engine.Kamera2.tmpMouseB2)
            {


                v.x = Engine.GetMouseLandPosition.x;
                v.y = Engine.GetMouseLandPosition.y;
                v.z = Engine.GetMouseLandPosition.z;
            }


            if (Engine.Kamera2.tmpMouseB2)
            {
                lblSelectedUnit.Text = Engine.XModel.MouseUnitPick(ref Engine.Scene, Engine.Kamera2.tmpMouseX, Engine.Kamera2.tmpMouseY);

                //this.Text = Engine.Kamera2.tmpMouseX.ToString() + "   " + Engine.Kamera2.tmpMouseY.ToString();
                Engine.XModel.ShowUnitBoundingBox("Sve", false);


                Engine.XModel.ShowUnitBoundingBox(lblSelectedUnit.Text, true);




                if (bMove)
                {
                    TV_3DVECTOR v= Engine.XModel.GetUnitPosition(lblSelectedUnit.Text);
                    txtMX.Text = v.x.ToString();
                    txtMY.Text = v.y.ToString();
                    txtMZ.Text = v.z.ToString();



                }

                if (bRotate)
                {
                    TV_3DVECTOR v = Engine.XModel.GetUnitRotate (lblSelectedUnit.Text);
                    txtMX.Text = v.x.ToString();
                    txtMY.Text = v.y.ToString();
                    txtMZ.Text = v.z.ToString();


                }

                if (bScale)
                {

                    TV_3DVECTOR v = Engine.XModel.GetUnitScale (lblSelectedUnit.Text);
                    txtMX.Text = v.x.ToString();
                    txtMY.Text = v.y.ToString();
                    txtMZ.Text = v.z.ToString();

                }

               
                   
                

            }




        }

        private void timer1_Tick(object sender, EventArgs e)
        {

        }

        private void saveToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            sfdUnit.ShowDialog();
            string f = sfdUnit.FileName;

            if (Engine.XModel.CheckUnitNameExsist(lblSelectedUnit.Text))
            {

                Engine.XModel.SaveUnitToXMLFile(lblSelectedUnit.Text, f );
            }

        }

        private void button6_Click(object sender, EventArgs e)
        {
            Engine.XModel.RemoveStaticUnit(lblSelectedUnit.Text, ref Engine.Scene,ref Engine.Fizika.PhysX );

        }

        private void hX_Scroll(object sender, ScrollEventArgs e)
        {

        }

        private void txtMY_TextChanged(object sender, EventArgs e)
        {

        }

        private void button7_Click(object sender, EventArgs e)
        {
            float x = (float )System.Convert.ToSingle(txtMX.Text ) ;
            float y= (float )System.Convert.ToSingle(txtMY.Text );
            float z= (float )System.Convert.ToSingle(txtMZ.Text );
            if (bMove)
            {
                Engine.XModel.MoveUnit(lblSelectedUnit.Text ,new TV_3DVECTOR(x,y,z));

            }

            if (bRotate)
            {

                Engine.XModel.RotateUnit(lblSelectedUnit.Text, new TV_3DVECTOR(x, y, z));

            }

            if (bScale)
            {

                Engine.XModel.ScaleUnit(lblSelectedUnit.Text, new TV_3DVECTOR(x, y, z));

            }

        }

        private void button8_Click(object sender, EventArgs e)
        {
            oLandHM.Filter = "Mesh terrein|*.tvm|DDS|*.dds|JPEG Images|*.jpg|BITMAPS|*.bmp";

            oLandHM.ShowDialog();

            string f = oLandHM.FileName;

            

            Engine.Teren.AddHeightMap(f,true , ref Engine.Scene);
            Engine.Teren.AddTerrainPhysics(ref Engine.Fizika.PhysX);
            Engine.Teren.AddLight(ref Engine.Scene, ref Engine.Globals);

            

            if (Engine.Teren.Lights == null)
            {
                Engine.Teren.AddLight(ref Engine.Scene, ref Engine.Globals);
            }

            try
            {

                picHmap.Load(f);
            }
            catch (Exception x)
            {


            }
            

        }

        private void button9_Click(object sender, EventArgs e)
        {
            oBaseTex.Filter = "DDS|*.dds|JPEG Images|*.jpg|BITMAPS|*.bmp";

            oBaseTex.ShowDialog();

            lblBaseTex.Text = oBaseTex.FileName;
            try
            {
                picBase.Load(lblBaseTex.Text);
            }
            catch (Exception x)
            {


            }
            Engine.Teren.AddTexture(lblBaseTex.Text);


        }

        private void button12_Click(object sender, EventArgs e)
        {
            oBaseTex.Filter = "DDS|*.dds|JPEG Images|*.jpg|BITMAPS|*.bmp";

            oBaseTex.ShowDialog();

            lblDuduv.Text = oBaseTex.FileName;

            if (Engine.Teren.Land != null)
            {

                Engine.AddWater(lblDuduv.Text, Engine.Teren.Land);


            }
        }

        private void button13_Click(object sender, EventArgs e)
        {
            oBaseTex.Filter = "DDS|*.dds|JPEG Images|*.jpg|BITMAPS|*.bmp";

            oBaseTex.ShowDialog();

            lblSkyTop.Text = oBaseTex.FileName;

        }

        private void button14_Click(object sender, EventArgs e)
        {
            oBaseTex.Filter = "DDS|*.dds|JPEG Images|*.jpg|BITMAPS|*.bmp";

            oBaseTex.ShowDialog();

            lblSkyDown.Text  = oBaseTex.FileName;
        }

        private void button15_Click(object sender, EventArgs e)
        {
            oBaseTex.Filter = "DDS|*.dds|JPEG Images|*.jpg|BITMAPS|*.bmp";

            oBaseTex.ShowDialog();

            lblSkyLeft.Text  = oBaseTex.FileName;
        }

        private void button16_Click(object sender, EventArgs e)
        {
            oBaseTex.Filter = "DDS|*.dds|JPEG Images|*.jpg|BITMAPS|*.bmp";

            oBaseTex.ShowDialog();

            lblSkyRight.Text  = oBaseTex.FileName;
        }

        private void button17_Click(object sender, EventArgs e)
        {
            oBaseTex.Filter = "DDS|*.dds|JPEG Images|*.jpg|BITMAPS|*.bmp";

            oBaseTex.ShowDialog();

            lblSkyBack.Text  = oBaseTex.FileName;
        }

        private void button18_Click(object sender, EventArgs e)
        {
            oBaseTex.Filter = "DDS|*.dds|JPEG Images|*.jpg|BITMAPS|*.bmp";

            oBaseTex.ShowDialog();

            lblSkyFront .Text  = oBaseTex.FileName;
        }

        private void button19_Click(object sender, EventArgs e)
        {



        }

        private void button10_Click(object sender, EventArgs e)
        {

            oBaseTex.Filter = "DDS|*.dds|JPEG Images|*.jpg|BITMAPS|*.bmp";

            oBaseTex.ShowDialog();

            lblDetail.Text  = oBaseTex.FileName;

        }

        private void button11_Click(object sender, EventArgs e)
        {
            oBaseTex.Filter = "DDS|*.dds|JPEG Images|*.jpg|BITMAPS|*.bmp";
            oBaseTex.ShowDialog();
            lblAlfaTex.Text  = oBaseTex.FileName;
            Engine.Teren.AddSplatTexture(lblBaseTex.Text, lblDetail.Text, lblAlfaTex.Text);

        }
        private void btnPhysics_Click(object sender, EventArgs e)
        {
            if (Engine.SimuLatePhysics)
            {
                this.btnPhysics.BackColor = Color.White ;
                this.Engine.SimuLatePhysics = false;
                this.btnPhysics.Text = "Start physics";
            }
            else
            {
                this.Engine.SimuLatePhysics = true;
                this.btnPhysics.BackColor = Color.Red;
                this.btnPhysics.Text = "Stop physics";
            }
        }

        private void button3_Click_2(object sender, EventArgs e)
        {

            Engine.Fizika.Expolosion(Engine.XModel.GetUnitPosition(lblSelectedUnit.Text), System.Convert.ToSingle(txtRadius.Text),
                System.Convert.ToSingle(txtStrenght.Text));



        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button4_Click_1(object sender, EventArgs e)
        {
            oBaseTex.Filter = "DDS|*.dds|JPEG Images|*.jpg|BITMAPS|*.bmp";

            oBaseTex.ShowDialog();

            lblCloudsTexture.Text  = oBaseTex.FileName;

            if (Engine.Oblaci.Atmos != null )
            {

                Engine.Oblaci.AddClouds(lblCloudsTexture.Text);


            }
        }

        private void button5_Click_1(object sender, EventArgs e)
        {

            Engine.AddSkyBox(
                lblSkyTop.Text,
                lblSkyDown.Text,
                lblSkyLeft.Text,
                lblSkyRight.Text,
                lblSkyFront.Text,
                lblSkyBack.Text);
        }

        private void saveToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            sfdSaveScene.ShowDialog();

            string fs = sfdSaveScene.FileName;
            scenes.WriteTerrein(fs, ref Engine.Teren, ref Engine.Voda, ref Engine.SkyBoxs, ref Engine.Oblaci,ref Engine.Magla );

            
        }

        private void loadToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ofdLoadScene.Filter = "Scena|*.ter";
            ofdLoadScene.ShowDialog();

            string fname = ofdLoadScene.FileName;
            scenes.RelativeToP = Application.StartupPath;

            Engine.Teren.AddLight(ref Engine.Scene, ref Engine.Globals);
            scenes.LoadTerrein(fname, ref Engine.Teren,
            ref Engine.Voda, ref Engine.SkyBoxs,
            ref Engine.Scene, ref Engine.Globals, ref Engine);
           

        }

        private void button20_Click(object sender, EventArgs e)
        {

            int Speed = System.Convert.ToInt32(txtSpeed.Text);

            Engine.Oblaci.AddSpeed((float)Speed, 0);


        }

        private void button21_Click(object sender, EventArgs e)
        {
            Engine.Magla.AddFog(new TV_COLOR(1f, 0.9f, 0.6f, 10),0.1f);


        }

        private void button22_Click(object sender, EventArgs e)
        {
            Engine.Magla.SetFogpParametsers(0, 0, float.Parse(textBox1.Text ));

        }

       

   
    }
}

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
Web02 | 2.8.1411028.1 | Last Updated 20 Nov 2009
Article Copyright 2009 by Member 3873633
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid