Esempio n. 1
0
 public void Apply(ObjectMesh objectMesh)
 {
     CameraConstant.Set(Camera); BillboardTransformConstant.Set(BillboardTransform); DiffuseConstant.Set(Diffuse); ColorPalletConstant.Set(ColorPallet); ScalePalletConstant.Set(ScalePallet);
     ApplyInstanceContants(objectMesh);
     TransformsConstant.Set(Transforms);
     Shader.Apply();
 }
Esempio n. 2
0
        public void Apply(ObjectMesh objectMesh)
        {
            CameraConstant.Set(Camera); LightDirectionConstant.Set(LightDirection); LightColorConstant.Set(LightColor);
            ApplyInstanceContants(objectMesh);

            Shader.Apply();
        }
Esempio n. 3
0
 public void ApplyInstanceContants(ObjectMesh objectMesh)
 {
     if (ApplyObjectMeshCallback != null)
     {
         ApplyObjectMeshCallback(this, objectMesh);
     }
 }
Esempio n. 4
0
        public void Apply(ObjectMesh objectMesh)
        {
            CameraConstant.Set(Camera);
            ApplyInstanceContants(objectMesh);

            Shader.Apply();
        }
Esempio n. 5
0
        public static double GetAngleBetween(ObjectMesh firstObject, ObjectMesh secondObject)
        {
            var x     = secondObject.Position.x - firstObject.Position.x;
            var y     = secondObject.Position.y - firstObject.Position.y;
            var angle = Math.Tan(y / x);

            return(angle);
        }
Esempio n. 6
0
        public static float GetDistanceBetween(ObjectMesh firstObject, ObjectMesh secondObject)
        {
            var x        = secondObject.Position.x - firstObject.Position.x;
            var y        = secondObject.Position.y - firstObject.Position.y;
            var distance = (float)Math.Sqrt((x * x) + (y * y));

            return(distance);
        }
Esempio n. 7
0
 public void ApplyInstanceContants(ObjectMesh objectMesh)
 {
     if (ApplyObjectMeshCallback != null)
     {
         ApplyObjectMeshCallback(this, objectMesh);
     }
     PositionConstant.Set(Position); SizeConstant.Set(Size); PositionUVConstant.Set(PositionUV); SizeUVConstant.Set(SizeUV); TexelOffsetConstant.Set(TexelOffset); ColorConstant.Set(Color); DiffuseTextureConstant.Set(DiffuseTexture);
 }
Esempio n. 8
0
 public void ApplyInstanceContants(ObjectMesh objectMesh)
 {
     if (ApplyObjectMeshCallback != null)
     {
         ApplyObjectMeshCallback(this, objectMesh);
     }
     TransformConstant.Set(Transform); DiffuseConstant.Set(Diffuse);
 }
Esempio n. 9
0
 public void ApplyInstanceContants(ObjectMesh objectMesh)
 {
     if (ApplyObjectMeshCallback != null)
     {
         ApplyObjectMeshCallback(this, objectMesh);
     }
     PositionConstant.Set(Position); SizeConstant.Set(Size); ColorConstant.Set(Color);
 }
Esempio n. 10
0
 public void ApplyInstanceContants(ObjectMesh objectMesh)
 {
     if (ApplyObjectMeshCallback != null)
     {
         ApplyObjectMeshCallback(this, objectMesh);
     }
     PositionConstant.Set(Position); SizeConstant.Set(Size); TexelOffsetConstant.Set(TexelOffset); ColorConstant.Set(Color); FadeConstant.Set(Fade); Fade2Constant.Set(Fade2); MainTextureConstant.Set(MainTexture); MainTexture2Constant.Set(MainTexture2); MainTexture3Constant.Set(MainTexture3);
 }
Esempio n. 11
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.Button == MouseButtons.Left)
            {
                if (_editor.ValidAnimationAndFrames)
                {
                    // Try to do gizmo picking
                    if (Configuration.AnimationEditor_ShowGizmo)
                    {
                        var result = _gizmo.DoPicking(GetRay(e.X, e.Y));
                        if (result != null)
                        {
                            _gizmo.ActivateGizmo(result);
                            _editor.Tool.AnimationEditorGizmoPicked();
                            Invalidate();
                            return;
                        }
                    }

                    // Try to do node picking
                    ObjectMesh foundMesh = null;
                    for (int i = 0; i < _model.Meshes.Count; i++)
                    {
                        float distance    = 0;
                        float minDistance = float.PositiveInfinity;
                        if (DoMeshPicking(GetRay(e.X, e.Y), i, out distance))
                        {
                            if (distance < minDistance)
                            {
                                distance  = minDistance;
                                foundMesh = _model.Meshes[i];
                            }
                        }
                    }

                    if (SelectedMesh != foundMesh)
                    {
                        SelectedMesh = foundMesh;
                        _editor.Tool.AnimationEditorMeshSelected(Model, SelectedMesh);
                    }
                }
                else
                {
                    SelectedMesh = null;
                    _editor.Tool.AnimationEditorMeshSelected(Model, SelectedMesh);
                }
            }

            Invalidate();

            _lastX = e.X;
            _lastY = e.Y;
        }
Esempio n. 12
0
 public void ApplyInstanceContants(ObjectMesh objectMesh)
 {
     if (ApplyObjectMeshCallback != null) ApplyObjectMeshCallback(this, objectMesh);
     PositionConstant.Set(Position);SizeConstant.Set(Size);ColorConstant.Set(Color);
 }
Esempio n. 13
0
        public void Apply(ObjectMesh objectMesh)
        {
            CameraConstant.Set(Camera);
            ApplyInstanceContants(objectMesh);

            Shader.Apply();
        }
Esempio n. 14
0
 public void ApplyInstanceContants(ObjectMesh objectMesh)
 {
     if (ApplyObjectMeshCallback != null) ApplyObjectMeshCallback(this, objectMesh);
     PositionConstant.Set(Position);SizeConstant.Set(Size);PositionUVConstant.Set(PositionUV);SizeUVConstant.Set(SizeUV);TexelOffsetConstant.Set(TexelOffset);ColorConstant.Set(Color);DiffuseTextureConstant.Set(DiffuseTexture);
 }
Esempio n. 15
0
 public void ApplyInstanceContants(ObjectMesh objectMesh)
 {
     if (ApplyObjectMeshCallback != null) ApplyObjectMeshCallback(this, objectMesh);
     PositionConstant.Set(Position);SizeConstant.Set(Size);TexelOffsetConstant.Set(TexelOffset);ColorConstant.Set(Color);FadeConstant.Set(Fade);MainTextureConstant.Set(MainTexture);MainTexture2Constant.Set(MainTexture2);
 }
Esempio n. 16
0
        public void Apply(ObjectMesh objectMesh)
        {
            CameraConstant.Set(Camera);LightDirectionConstant.Set(LightDirection);LightColorConstant.Set(LightColor);
            ApplyInstanceContants(objectMesh);

            Shader.Apply();
        }
Esempio n. 17
0
    public static GameObject GetUserInterface_1_0_1(XmlNode node)
    {
        GameObject retObject = null;

        switch (node.Name)
        {
        case "EZGUI_TEXTURE":
        {
            string ObjectName  = _GetString(node, "Name");
            string ObjectPath  = _GetString(node, "MainPath");
            int    PosX        = _GetInt(node, "Position/x");
            int    PosY        = _GetInt(node, "Position/y");
            int    PosZ        = _GetInt(node, "Position/z");
            string BasePosType = _GetAttribute(node, "BasePosType");

            retObject = ResourceLoad.GetEZGUI_TEXTURE(ObjectName, ObjectPath, PosX, PosY, PosZ, BasePosType);
        } break;

        case "EZGUI_BUTTON":
        {
            string ObjectName  = _GetString(node, "Name");
            string ObjectPath  = _GetString(node, "MainPath");
            int    PosX        = _GetInt(node, "Position/x");
            int    PosY        = _GetInt(node, "Position/y");
            int    PosZ        = _GetInt(node, "Position/z");
            string BasePosType = _GetAttribute(node, "BasePosType");

            retObject = ResourceLoad.GetEZGUI_BUTTON(ObjectName, ObjectPath, PosX, PosY, PosZ, BasePosType);
        } break;

        case "EZGUI_RADIO":
        {
            string ObjectName  = _GetString(node, "Name");
            string ObjectPath  = _GetString(node, "MainPath");
            int    PosX        = _GetInt(node, "Position/x");
            int    PosY        = _GetInt(node, "Position/y");
            int    PosZ        = _GetInt(node, "Position/z");
            string BasePosType = _GetAttribute(node, "BasePosType");

            retObject = ResourceLoad.GetEZGUI_RADIOBUTTON(ObjectName, ObjectPath, PosX, PosY, PosZ, BasePosType);
        } break;

        case "MOBILE_PREFAB_IMAGE":
        {
            string ObjectName = _GetString(node, "Name");
            string ObjectPath = _GetString(node, "MainPath");

            retObject = ResourceLoad.GetMOBILE_PREFAB_IMAGE(ObjectName, ObjectPath);
        } break;

        case "EZTEXT_FIELD":
        {
            string ObjectName  = _GetString(node, "Name");
            string ObjectPath  = _GetString(node, "MainPath");
            int    PosX        = _GetInt(node, "Position/x");
            int    PosY        = _GetInt(node, "Position/y");
            int    PosZ        = _GetInt(node, "Position/z");
            string BasePosType = _GetAttribute(node, "BasePosType");

            retObject = ResourceLoad.GetEZGUI_TEXTFIELD(ObjectName, ObjectPath, PosX, PosY, PosZ, BasePosType);
        } break;

        case "EZGUI_SLIDER":
        {
            string ObjectName  = _GetString(node, "Name");
            string ObjectPath  = _GetString(node, "MainPath");
            int    PosX        = _GetInt(node, "Position/x");
            int    PosY        = _GetInt(node, "Position/y");
            int    PosZ        = _GetInt(node, "Position/z");
            string BasePosType = _GetAttribute(node, "BasePosType");
            string Orientation = _GetAttribute(node, "Orientation");
            string Anchor      = _GetAttribute(node, "Anchor");

            retObject = ResourceLoad.GetEZGUI_SLIDER(ObjectName, ObjectPath, PosX, PosY, PosZ, Orientation, Anchor, BasePosType);
        } break;

        case "EZ_PROGRESS_BAR":
        {
            string ObjectName  = _GetString(node, "Name");
            string ObjectPath  = _GetString(node, "MainPath");
            int    PosX        = _GetInt(node, "Position/x");
            int    PosY        = _GetInt(node, "Position/y");
            int    PosZ        = _GetInt(node, "Position/z");
            string BasePosType = _GetAttribute(node, "BasePosType");

            retObject = ResourceLoad.GetEZGUI_PROGRESSBAR(ObjectName, ObjectPath, PosX, PosY, PosZ, BasePosType);
        } break;

        case "EZGUI_SPRITE_TEXT":
        {
            string ObjectName  = _GetString(node, "Name");
            string ObjectPath  = _GetString(node, "MainPath");
            int    PosX        = _GetInt(node, "Position/x");
            int    PosY        = _GetInt(node, "Position/y");
            int    PosZ        = _GetInt(node, "Position/z");
            string Alignment   = _GetAttribute(node, "Alignment");
            string Anchor      = _GetAttribute(node, "Anchor");
            string Text        = _GetString(node, "Text");
            string BasePosType = _GetAttribute(node, "BasePosType");

            retObject = ResourceLoad.GetEZGUI_SPRITETEXT(ObjectName, ObjectPath, PosX, PosY, PosZ, Anchor, Alignment, Text, BasePosType);
        } break;

        case "EZGUI_OUTLINE_TEXT":
        {
            string ObjectName  = _GetString(node, "Name");
            string FrontPath   = _GetString(node, "MainPath");
            string BackPath    = _GetString(node, "SubPath");
            int    PosX        = _GetInt(node, "Position/x");
            int    PosY        = _GetInt(node, "Position/y");
            int    PosZ        = _GetInt(node, "Position/z");
            string Anchor      = _GetAttribute(node, "Anchor");
            string Alignment   = _GetAttribute(node, "Alignment");
            string Text        = _GetString(node, "Text");
            string BasePosType = _GetAttribute(node, "BasePosType");

            retObject = ResourceLoad.GetEZGUI_OUTLINETEXT(ObjectName, FrontPath, BackPath, PosX, PosY, PosZ, Anchor, Alignment, Text, BasePosType);
        } break;

        case "EZGUI_SCROLL_LIST":
        {
            string ObjectName   = _GetString(node, "Name");
            int    PosX         = _GetInt(node, "Position/x");
            int    PosY         = _GetInt(node, "Position/y");
            int    PosZ         = _GetInt(node, "Position/z");
            int    TextureSizeX = _GetInt(node, "TextureSize/x");
            int    TextureSizeY = _GetInt(node, "TextureSize/y");
            string Orientation  = _GetAttribute(node, "Orientation");
            string Alignment    = _GetAttribute(node, "Alignment");
            string Direction    = _GetAttribute(node, "Direction");
            string BasePosType  = _GetAttribute(node, "BasePosType");

            retObject = ResourceLoad.GetEZGUI_SCROLLLIST(ObjectName, PosX, PosY, PosZ, TextureSizeX, TextureSizeY, Orientation, Direction, Alignment, BasePosType);
        } break;

        case "MESH":
        {
            string ObjectName = _GetString(node, "Name");
            string ObjectPath = _GetString(node, "MainPath");

            float ModelPosX = _GetSingle(node, "RealPosition/x");
            float ModelPosY = _GetSingle(node, "RealPosition/y");
            float ModelPosZ = _GetSingle(node, "RealPosition/z");
            float RotateX   = _GetSingle(node, "RealRotation/x");
            float RotateY   = _GetSingle(node, "RealRotation/y");
            float RotateZ   = _GetSingle(node, "RealRotation/z");
            float ScaleX    = _GetSingle(node, "RealScale/x");
            float ScaleY    = _GetSingle(node, "RealScale/y");
            float ScaleZ    = _GetSingle(node, "RealScale/z");

            retObject = (GameObject)Instantiate(Resources.Load(ObjectPath, typeof(GameObject)), Vector3.zero, Quaternion.identity);

            ObjectMesh objectMesh = retObject.AddComponent <ObjectMesh>();
            objectMesh.Create();
            objectMesh.SetName(ObjectName);
            objectMesh.SetPos(new Vector3(ModelPosX, ModelPosY, ModelPosZ));
            objectMesh.SetRotate(new Vector3(RotateX, RotateY, RotateZ));
            objectMesh.SetScale(new Vector3(ScaleX, ScaleY, ScaleZ));

            retObject.name             = ObjectName;
            retObject.transform.parent = Main.inst.GetResourceObject_MESH().transform;
        } break;

        default:
        {
            DebugManager.Log("Unknown Target!!!");
        } break;
        }

        return(retObject);
    }
Esempio n. 18
0
 public void ApplyInstanceContants(ObjectMesh objectMesh)
 {
     if (ApplyObjectMeshCallback != null) ApplyObjectMeshCallback(this, objectMesh);
     TransformConstant.Set(Transform);DiffuseConstant.Set(Diffuse);
 }
Esempio n. 19
0
 public void Apply(ObjectMesh objectMesh)
 {
     CameraConstant.Set(Camera);BillboardTransformConstant.Set(BillboardTransform);DiffuseConstant.Set(Diffuse);ColorPalletConstant.Set(ColorPallet);ScalePalletConstant.Set(ScalePallet);
     ApplyInstanceContants(objectMesh);
     TransformsConstant.Set(Transforms);
     Shader.Apply();
 }
Esempio n. 20
0
		private void applyTransform(DiffuseTextureMaterial material, ObjectMesh mesh)
		{
			material.Transform = Matrix4.FromAffineTransform(mesh.RotationMatrix, mesh.Scale, mesh.Position);//.RotateAroundAxisY(rot)
		}
Esempio n. 21
0
 public void AnimationEditorMeshSelected(AnimatedModel model, ObjectMesh mesh)
 {
     RaiseEvent(new AnimationEditorMeshSelectedEvent(model, mesh));
 }
Esempio n. 22
0
 public AnimationEditorMeshSelectedEvent(AnimatedModel model, ObjectMesh mesh)
 {
     Model = model;
     Mesh  = mesh;
 }
Esempio n. 23
0
        private void OpenGLControl_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
        {
            Title = "basketball-game";

            OpenGL gl = args.OpenGL;

            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            RenderColor(gl);
            Render3D(gl);

            gl.LoadIdentity();
            //Manipulate Camera
            gl.LookAt(0 - mouseVector.x - movementVector.x, 0 + mouseVector.y - movementVector.y, 20.0f + zoom, 0 - movementVector.x, 0 + mouseVector.y, zoom, 0, 1, 0);
            //Then Translate
            gl.Translate(0.0f, 10.0f, -50.0f);

            //Draw 3D Objects
            #region Draw 3D Objects
            Ball.DrawBasketBall(gl, 60, 0, 0, 0);
            Ground.DrawCube(gl, 0, 120, 0);
            Pole.DrawCube(gl, 100, 100, 100);
            Board.DrawCube(gl, 0, 200, 200);
            RingEdge.DrawCube(gl, 0, 200, 200);

            RimNet.Draw(gl, 50, 50, 50);
            CenNet.Draw(gl, 40, 40, 40);

            //simulatedBall.DrawCircle(gl, 1);
            //Aiming Line Draw
            if (showLine)
            {
                if (isBallThrown)
                {
                    //Line.DrawLine(gl, Ball, Ball.Velocity, 1, 200, 60, 60);
                    Line.DrawSimulatedPath(gl, Ball, Ball.Velocity, 1, 200, 60, 60);
                }
                else
                {
                    //Line.DrawLine(gl, Ball, modifierVector, 1, 200, 60, 60);
                    Line2.DrawSimulatedPath(gl, simulatedBall, simulatedVector, 1, 200, 0, 0);
                }
            }
            //End Drawing Most 3D Objects
            #endregion

            #region Draw Text


            var angle = (Math.Truncate((Math.Atan(modifierVector.y / modifierVector.x) * 180 / Math.PI) * 100.0) / 100.0);
            //Above
            gl.DrawText(5, 630, 1, 0, 0, "Arial", 15, "Round: " + curRound);
            gl.DrawText(5, 600, 1, 0, 0, "Arial", 30, "Score: " + curScore);
            gl.DrawText(5, 570, 1, 0, 0, "Arial", 20, "Camera Movement Enabled: " + Keyboard.IsKeyToggled(toggleMovementKey).ToString());
            gl.DrawText(5, 480, 1, 0, 0, "Arial", 30, gameStage);

            //Below
            gl.DrawText(230, 20, 1, 0, 0, "Arial", 15, "Angle: " + angle);
            gl.DrawText(400, 5, 1, 0, 0, "Arial", 15, "Increments: " + increments);
            gl.DrawText(400, 20, 1, 0, 0, "Arial", 15, "Power: " + power);
            gl.DrawText(900, 20, 1, 0, 0, "Arial", 15, "Reset in: " + curCounter);


            #endregion


            showBall.Rotation += 5;
            #region WINDY Score when > 10
            //WINDY!!!!!!!!!!!!!! --- SCORE > 10
            if (curScore >= 10)
            {
                isWindy   = true;
                gameStage = "It's a bit windy";
                ObjectMesh Leave = new ObjectMesh()
                {
                    Scale = new Vector3(0.5f, 0.5f, 0),
                    Mass  = 0.3f
                };
                leaveRandGaussian = (float)Randomizer.Gaussian(-0, 10);
                leaveRandNorm     = (float)Randomizer.Generate(0.1f, 0.5f);
                Leave.Position    = new Vector3(leaveRandGaussian + 150, leaveRandGaussian, 30);
                Leave.Mass        = leaveRandNorm;
                Leaves.Add(Leave);
                foreach (var leaf in Leaves)
                {
                    leaf.DrawCube(gl, 0, 60, 0);
                    leaf.ApplyGravity();
                    leaf.ApplyForce(rightWindVector);
                    leaf.Velocity.Clamp(-0.2f, -0.2f, 0);
                    if (leaf.HasCollidedWith(Ground))
                    {
                        leaf.Position.y = Ground.Position.y + Ground.Scale.y + leaf.Scale.y;
                        leaf.Velocity.y = (-(leaf.Velocity.y));
                        leaf.ApplyFriction();
                    }
                    else
                    {
                        leaf.ApplyGravity();
                        leaf.ApplyFriction();
                    }
                }
            }
            #endregion

            #region Meteor Fell Score When > 20
            if ((curScore >= 20) && (enabledMetoer))
            {
                gameStage = "Some kind of meteor...";
                Meteor.DrawCircle(gl);
                Meteor.ApplyForce(meteorFallingVector);
                if (Meteor.Position.y <= -30)
                {
                    Meteor.Velocity.y *= 0;
                    Meteor.Position.y  = -30;
                    isMeteorFall       = true;
                }
            }
            #endregion

            #region Ball Thrown Code
            //You pressed Space
            if (isBallThrown)
            {
                curCounter--;
                if (curCounter > maxCounter - 2)
                {
                    Ball.Velocity = modifierVector / 1.5f;
                }
                Ball.Rotation += 10;
            }
            #endregion

            #region Scoring
            if (CenNet.Contains(Ball))
            {
                Console.WriteLine("Ball is in CenNet...");
                if (!isScored)
                {
                    curScore++;
                    randNorm     = (float)Randomizer.Generate(-10, 10);
                    randGaussian = (float)Randomizer.Gaussian(1, 2);
                    Console.WriteLine("Player Scores!");
                    isScored = true;
                }

                Ball.ApplyForce(RimNet.CalculateDragForce(Ball) * 1);
                Ball.ApplyForce(CenNet.CalculateDragForce(Ball) * 2);
            }
            #endregion

            #region Reset Code
            if (curCounter < 0)
            {
                Pole.Position.x     += randNorm;
                Board.Position.x    += randNorm;
                RingEdge.Position.x += randNorm;
                RimNet.x            += randNorm;
                CenNet.x            += randNorm;

                if ((randNorm < 1) && (randNorm > -1))
                {
                    Board.Position.y    += randGaussian;
                    RimNet.y            += randGaussian;
                    CenNet.y            += randGaussian;
                    RingEdge.Position.y += randGaussian;
                }

                if ((Pole.Position.x > 70) || (Pole.Position.x < 30))
                {
                    Pole.Position.x     = 50;
                    Board.Position.x    = 48.5f;
                    RingEdge.Position.x = 42.5f;
                    RimNet.x            = 45.5f;
                    CenNet.x            = 45.5f;
                }
                curCounter = maxCounter;
                isScored   = false;
                curRound++;
            }

            if (curCounter == maxCounter)
            {
                //isSpaceHeld = false;
                isBallThrown     = false;
                Ball.Velocity.x *= 0.0f;
                Ball.Velocity.y *= 0.0f;
                Ball.Position    = BallDefaultPos;
                randNorm        *= 0;
                randGaussian    *= 0;
                isScored         = false;
            }
            #endregion

            #region Controls
            // These controls only available when Ball is not yet thrown
            if (!isBallThrown)
            {
                //Increment Adjuster
                if (Keyboard.IsKeyDown(increaseKey) && !Keyboard.IsKeyToggled(toggleMovementKey))
                {
                    increments -= 0.1f;
                }
                else if (Keyboard.IsKeyDown(decreaseKey) && !Keyboard.IsKeyToggled(toggleMovementKey))
                {
                    increments += 0.2f;
                }
                increments = GameUtils.Constrain(increments, minIncrements, maxIncrements);

                //Adjust Power and Angle modified by Increments
                lineLength = modifierVector.GetLength();
                power      = (Math.Truncate(lineLength * 100.0) / 100.0);
                power     *= 10;


                if (Keyboard.IsKeyDown(upKey) && (power < 100) && !Keyboard.IsKeyToggled(toggleMovementKey))
                {
                    aimAngle          = Math.Atan((modifierVector.y) / (modifierVector.x));
                    modifierVector.x += increments * (float)Math.Cos(aimAngle);
                    modifierVector.y += increments * (float)Math.Sin(aimAngle);
                }
                if (Keyboard.IsKeyDown(downKey) && (power > 10) && !Keyboard.IsKeyToggled(toggleMovementKey))
                {
                    aimAngle          = Math.Atan((modifierVector.y) / (modifierVector.x));
                    modifierVector.x -= increments * (float)Math.Cos(aimAngle);
                    modifierVector.y -= increments * (float)Math.Sin(aimAngle);
                }
                if (Keyboard.IsKeyDown(rightKey) && !Keyboard.IsKeyToggled(toggleMovementKey))
                {
                    aimAngle         = Math.Atan(modifierVector.y / modifierVector.x);
                    aimAngle        -= (Math.PI / 180) + ((Math.PI / 90) * increments);
                    modifierVector.x = lineLength * (float)Math.Cos(aimAngle);
                    modifierVector.y = lineLength * (float)Math.Sin(aimAngle);
                }
                if (Keyboard.IsKeyDown(leftKey) && !Keyboard.IsKeyToggled(toggleMovementKey))
                {
                    aimAngle         = Math.Atan(modifierVector.y / modifierVector.x);
                    aimAngle        += (Math.PI / 180) + ((Math.PI / 90) * increments);
                    modifierVector.x = lineLength * (float)Math.Cos(aimAngle);
                    modifierVector.y = lineLength * (float)Math.Sin(aimAngle);
                }
            }

            //Play Ball
            if (Keyboard.IsKeyDown(shootKey))
            {
                isBallThrown = true;
            }

            //Restart
            if (Keyboard.IsKeyDown(resetKey) && (curCounter < maxCounter))
            {
                curCounter = -2;
            }

            if (Keyboard.IsKeyToggled(toggleLineKey))
            {
                showLine            = false;
                isDrawSimulatedPath = false;
            }
            else
            {
                showLine            = true;
                isDrawSimulatedPath = true;
            }

            //Force Random
            if (Keyboard.IsKeyDown(randomizeKey))
            {
                randNorm     = (float)Randomizer.Generate(-10, 10);
                randGaussian = (float)Randomizer.Gaussian(1, 2);
                curCounter   = -2;
            }

            //Add Score Cheat
            if (Keyboard.IsKeyDown(cheatKey))
            {
                randNorm     = (float)Randomizer.Generate(-10, 10);
                randGaussian = (float)Randomizer.Gaussian(1, 2);
                curCounter   = -2;
                curScore++;
            }

            if (Keyboard.IsKeyToggled(toggleMovementKey))
            {
                mouseVector = new Vector3(mousePos.x / (50 * (1 / sensitivity)), mousePos.y / (30 * (1 / sensitivity)), 0);
                eyex        = 0 - mouseVector.x + movementVector.x;
                eyey        = 0 + mouseVector.y - movementVector.y;
                eyez       += zoom;
                cenx        = 0 - movementVector.x;
                ceny        = 0 + mouseVector.y;
                cenz        = zoom;

                if (Keyboard.IsKeyDown(increaseKey))
                {
                    zoom += 1;
                }
                if (Keyboard.IsKeyDown(decreaseKey))
                {
                    zoom -= 1;
                }
                if (Keyboard.IsKeyDown(upKey))
                {
                    //movementVector.y -= 1;
                    zoom -= 1;
                }
                if (Keyboard.IsKeyDown(downKey))
                {
                    //movementVector.y -= -1;
                    zoom += 1;
                }
                if (Keyboard.IsKeyDown(leftKey))
                {
                    movementVector.x -= -1;
                }
                if (Keyboard.IsKeyDown(rightKey))
                {
                    movementVector.x -= 1;
                }
            }

            if (Keyboard.IsKeyDown(quitKey))
            {
                Environment.Exit(0);
            }
            #endregion

            #region Physics and Collision
            //Simulated Ball


            //Main Ball
            if (Ball.HasCollidedWith(Ground))
            {
                Ball.Velocity.y = (-(Ball.Velocity.y) / 2);
                Ball.Position.y = Ground.Position.y + Ground.Scale.y + Ball.Radius;
                Ball.ApplyFriction();

                if (isWindy)
                {
                    Ball.ApplyForce(rightWindVector);
                }
                if (isMeteorFall)
                {
                    Ball.ApplyForce(Meteor.CalculateAttraction(Ball));
                }
            }
            else
            {
                Ball.ApplyGravity(0.2f);
                Ball.ApplyFriction();
                if (isWindy == true)
                {
                    Ball.ApplyForce(rightWindVector);
                }
                if (isMeteorFall == true)
                {
                    Ball.ApplyForce(Meteor.CalculateAttraction(Ball));
                }
            }

            if (Ball.HasCollidedWith(Board))
            {
                if (Ball.Position.y > Board.Position.y + Board.Scale.y)
                {
                    Ball.Velocity.y = (-(Ball.Velocity.y) / 2);
                }
                Ball.Velocity.x = (-(Ball.Velocity.x) / 1.5f);
            }

            //Ball Collided with Meteor
            //Get distance between Ball and Metoer then check against its scale
            if (GameUtils.GetDistanceBetween(Meteor, Ball) < (Ball.Radius + Meteor.Radius) + 2.0f)
            {
                Ball.Velocity.x = (-(Ball.Velocity.x) / 1.5f);
                Ball.Velocity.y = (-(Ball.Velocity.y) / 1.5f);
            }

            if (Ball.HasCollidedWith(RingEdge))
            {
                if (Ball.Position.y > RingEdge.Position.y + RingEdge.Scale.y)
                {
                    Ball.Velocity.y = (-(Ball.Velocity.y) / 2);
                }
                Ball.Velocity.x = (-(Ball.Velocity.x) / 1.5f);
            }

            if (Ball.HasCollidedWith(Pole))
            {
                Ball.Velocity.x = (-(Ball.Velocity.x) / 1.5f);
            }
            #endregion
        }
Esempio n. 24
0
 public void ApplyInstanceContants(ObjectMesh objectMesh)
 {
     if (ApplyObjectMeshCallback != null) ApplyObjectMeshCallback(this, objectMesh);
 }