Пример #1
0
        public override bool OnMouse(int button, int state, int x, int y)
        {
            if (button == Glut.GLUT_LEFT_BUTTON && (state == Glut.GLUT_DOWN || state == Glut.GLUT_UP))
            {
//                MouseWorld = RenderLayerGame.ConvertScreenToWorldCoordsNoDepth(x, y, Camera.ViewMatrix, projectionMatrix, Vector3.Zero);
                MouseWorld = RenderLayerGame.ConvertScreenToWorldCoordsNoDepth(x, y, Matrix4.Identity, projectionMatrix,
                                                                               Vector3.Zero, TheRenderStatus);

                foreach (ObjHudPanel aHudObject in theHudPanels)
                {
                    ObjObject tempObj = aHudObject.IsOn((int)MouseWorld.x, (int)MouseWorld.y);
                    if (tempObj != null)
                    {
                        if (tempObj is ObjHudButton)
                        {
                            Tile.TileIds tempTileId;
                            string       tempTileIdName = (string)((ObjHudButton)tempObj).Tag;
                            if (Tile.TileIds.TryParse(tempTileIdName, true, out tempTileId))
                            {
                                selectedTileId = tempTileId;
                                selectedObjHudButton.Material = TheResourceManager.Get("Tile_" + tempTileIdName);
                            }
                        }

                        GameCore.TheGameCore.RaiseMessage("Mouse: [" + x + "," + y + "] on HUD: " + tempObj + ".");
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #2
0
        private ObjHudPanel CreateHudPanel(Size tempSize, Color aColor, ObjHudPanel.Anchors anAnchor)
        {
//            Vector2 tempLoc2 = new Vector2(0, 0);
//
//            SolidBrush tempBrush = new SolidBrush(aColor);
//            Bitmap tempBmp = BitmapHelper.CreatBitamp(new Size(20, 20), tempBrush);
//            ObjMaterial tempMaterial = new ObjMaterial(hudProgram) {DiffuseMap = new Texture(tempBmp)};
            ObjMaterial tempMaterial = TheResourceManager.GetPlainColor(hudProgram, "HudPanelPlain" + aColor.Name,
                                                                        aColor);
            Vector2 tempLoc2 = new Vector2(0, 0);

            ObjHudPanel tempObjObject2 =
                new ObjHudPanel(ObjectPrimitives.CreateSquareWithNormalsYorZ(new Vector3(0, 0, 0),
                                                                             new Vector3(tempSize.Width,
                                                                                         tempSize.Height,
                                                                                         0), true))
            {
                Anchor   = anAnchor,
                Position =
                    tempLoc2,
                Size = tempSize
            };

            tempObjObject2.Size = tempSize;
            tempObjObject2.UpdatePosition(Width, Height);
            tempObjObject2.Material = tempMaterial;
            return(tempObjObject2);
        }
Пример #3
0
        private ObjHudPanel CreateHudPanel(string aBmpPath, ObjHudPanel.Anchors anAnchor)
        {
            ObjMaterial tempMaterial = TheResourceManager.GetFromFile(hudProgram, aBmpPath);
            Size        tempSize     = tempMaterial.DiffuseMap.Size;

            Vector2 tempLoc2 = new Vector2(0, 0);

            ObjHudPanel tempObjObject2 =
                new ObjHudPanel(ObjectPrimitives.CreateSquareWithNormalsYorZ(new Vector3(0, 0, 0),
                                                                             new Vector3(tempSize.Width,
                                                                                         tempSize.Height,
                                                                                         0), true))
            {
                Anchor   = anAnchor,
                Position =
                    tempLoc2,
                Size = tempSize
            };

            tempObjObject2.Size = tempSize;
            tempObjObject2.UpdatePosition(Width, Height);
            tempObjObject2.Material = tempMaterial;
            return(tempObjObject2);
        }
Пример #4
0
        public override void OnLoad()
        {
            GameCore.TheGameCore.TheGameEventHandler += TheGameCore_TheGameEventHandler;


            // create our shader program
            program = new ShaderProgram(VertexShader, FragmentShader);

//            SetupCamera();
//            Camera.SetDirection(new Vector3(0, 0, -1));

            // set up the projection and view matrix
            program.Use();
            projectionMatrix = Matrix4.CreatePerspectiveFieldOfView(TheRenderStatus.Fov,
                                                                    (float)TheRenderStatus.Width / TheRenderStatus.Height, TheRenderStatus.ZNear,
                                                                    TheRenderStatus.ZFar);
            program["projection_matrix"].SetValue(projectionMatrix);
            program["model_matrix"].SetValue(Matrix4.Identity);
            program["light_direction"].SetValue(theEnvironment.LightDirection);
            program["enable_lighting"].SetValue(theEnvironment.Lighting);
            program["ambient"].SetValue(theEnvironment.LightAmbient);

            materialPoint      = TheResourceManager.GetPlainColor(program, "GamePlainRed", Color.Red);
            materialLineMarker = TheResourceManager.GetPlainColor(program, "GamePlainGreenYellow", Color.GreenYellow);

            objMeshs = new List <IObjGroup>();

            ObjGroup tempObjMesh2 = ObjLoader.LoadObjFileToObjMesh(program, @"./Resources/Models/Turret1.obj");

            tempObjMesh2.Location = new Vector3(10, 0, 10);
            tempObjMesh2.Scale    = Vector3.UnitScale * 0.3f;
            objMeshs.Add(tempObjMesh2);

            ObjMaterial tempMaterial = TheResourceManager.GetPlainColor(program, "GamePlainGreen", Color.Green);

            tileTextures = RenderObjects.RenderObjects.CreateTileTextures(new Size(20, 20), program);


            ObjGroup  tempObjGroup = new ObjGroup(program);
            ObjObject tempObj      =
                new ObjObject(ObjectPrimitives.CreateCube(new Vector3(0, 0, 0), new Vector3(1, 1, 1), true))
            {
                Material = tileTextures[Tile.TileIds.Grass].Material
            };

//            ObjObject tempObj = CreateCube(program, new Vector3(1, 1, 1), new Vector3(0, 0, 0));
            tempObjGroup.AddObject(tempObj);
            objMeshs.Add(tempObjGroup);


            tempObjGroup = new ObjGroup(program);
//            tempObj = new ObjObject(ObjectPrimitives.CreateCube(new Vector3(2, 0, 0), new Vector3(3, 1, 1), true))
            tempObj = new ObjObject(ObjectPrimitives.CreateCube(new Vector3(0, 0, 0), new Vector3(1, 1, 1), true))
            {
                Material = tileTextures[Tile.TileIds.Road].Material
            };

            tempObjGroup.AddObject(tempObj);
            tempObjGroup.Location    = new Vector3(1, 0, 5);
            tempObjGroup.Orientation = Quaternion.FromAngleAxis((float)(Math.PI * 0.25), Vector3.Up);
            objMeshs.Add(tempObjGroup);


            tempObjGroup = new ObjGroup(program);
            tempObj      =
                new ObjObject(ObjectPrimitives.CreateSquareWithNormalsYorZ(new Vector3(5, 1, 1), new Vector3(4, 0, 1),
                                                                           true))
            {
                Material = tempMaterial
            };
            tempObjGroup.AddObject(tempObj);

            tempObj =
                new ObjObject(ObjectPrimitives.CreateSquareWithNormalsYorZ(new Vector3(-1, 1, 1), new Vector3(-2, 0, 0),
                                                                           true));
            tempObjGroup.AddObject(tempObj);
            objMeshs.Add(tempObjGroup);


//            tempObjGroup = new ObjGroup(program);
//            theTileObjects = GetTileObjects();
//            tempObjGroup.AddObjects(theTileObjects);
//            objMeshs.Add(tempObjGroup);
//
            objMeshs.AddRange(GetGameObjects());

            thePaths = new ObjGroupPaths(program);
            objMeshs.Add(thePaths);

            Gl.UseProgram(0);
            Gl.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
            Gl.BindBuffer(BufferTarget.ArrayBuffer, 0);

            if (UseObjMap)
            {
                objTileMap = new ObjMap(TheGameStatus.TheMap, TheCamera);
            }
        }
Пример #5
0
        private List <ObjGroup> CreateRenderGameObjects()
        {
            Dictionary <ObjectGame.ObjcetIds, PlainBmpTexture> gameObjectsTextures =
                RenderObjects.RenderObjects.CreateGameObjectsTextures(new Size(20, 20), program);
            List <ObjGroup>   tempObjList = new List <ObjGroup>();
            List <ObjectGame> gameObjects = TheGameStatus.GameObjects;

            foreach (ObjectGame gameObject in gameObjects)
            {
                Vector             tempLoc;
                ObjGroupGameObject tempGroup = null;
                ObjGameObject      tempObjObject;
                switch (gameObject.TheObjectId)
                {
                case ObjectGame.ObjcetIds.Player:
                    tempGroup = new ObjGroupGameObjectPlayer(program)
                    {
                        TheObjectGame = gameObject
                    };
                    tempLoc       = new Vector(0.0f, 0.0f);
                    tempLoc      -= new Vector(gameObject.Diameter * 0.5f, gameObject.Diameter * 0.5f);
                    tempObjObject =
                        new ObjGameObject(ObjectPrimitives.CreateCube(new Vector3(tempLoc.X, 0, tempLoc.Y),
                                                                      new Vector3(tempLoc.X + gameObject.Diameter, gameObject.Diameter,
                                                                                  tempLoc.Y + gameObject.Diameter),
                                                                      true));
                    ObjMaterial tempMaterial = TheResourceManager.GetFromFile(program, "tileTestMike200x200.png");
                    tempObjObject.Material = tempMaterial;
                    tempGroup.AddObject(tempObjObject);
                    playerObjObject    = tempGroup;
                    tempGroup.Location = gameObject.Location;
                    break;

                case ObjectGame.ObjcetIds.Enemy:
                    tempGroup = new ObjGroupGameObjectEnemy(program)
                    {
                        TheObjectGame = gameObject
                    };
                    tempLoc       = new Vector(0.0f, 0.0f);
                    tempLoc      -= new Vector(gameObject.Diameter * 0.5f, gameObject.Diameter * 0.5f);
                    tempObjObject =
                        new ObjGameObject(ObjectPrimitives.CreateCube(new Vector3(tempLoc.X, 0, tempLoc.Y),
                                                                      new Vector3(tempLoc.X + gameObject.Diameter, gameObject.Diameter,
                                                                                  tempLoc.Y + gameObject.Diameter),
                                                                      true));
                    ObjMaterial tempMaterial1 = TheResourceManager.GetFromFile(program, "tileTestMike200x200.png");
                    tempObjObject.Material = tempMaterial1;
                    tempGroup.AddObject(tempObjObject);
                    tempGroup.Location = gameObject.Location;
                    break;

                case ObjectGame.ObjcetIds.Turret:

                    ObjGroup     tempGroup1 = ObjLoader.LoadObjFileToObjMesh(program, @"./Resources/Models/Turret1.obj");
                    ObjectTurret tempTurret = (ObjectTurret)gameObject;
                    tempGroup = new ObjGroupGameObjectTurret(tempGroup1)
                    {
                        Location      = gameObject.Location,
                        Scale         = Vector3.UnitScale * 0.3f,
                        TheObjectGame = tempTurret
                    };
                    //                        tempGroup.Orientation = tempTurret.Orientation;

                    break;

                default:
                    tempLoc       = new Vector(0.0f, 0.0f);
                    tempLoc      -= new Vector(gameObject.Diameter * 0.5f, gameObject.Diameter * 0.5f);
                    tempObjObject =
                        new ObjGameObject(ObjectPrimitives.CreateCube(new Vector3(tempLoc.X, 0, tempLoc.Y),
                                                                      new Vector3(tempLoc.X + gameObject.Diameter, gameObject.Diameter,
                                                                                  tempLoc.Y + gameObject.Diameter),
                                                                      true))
                    {
                        Material = gameObjectsTextures[gameObject.TheObjectId].Material
                    };

                    tempGroup.AddObject(tempObjObject);
                    tempGroup.TheObjectGame = gameObject;
                    break;
                }

                tempObjList.Add(tempGroup);
            }
            return(tempObjList);
        }