Ejemplo n.º 1
0
        protected override void PostInitializeComponent()
        {
            ModelComponent model_component = ParentObject.GetComponent(ModelComponent.ID) as ModelComponent;

            if (model_component == null)
            {
                return;
            }
            GameObject go = model_component.GetUnityGameObject();

            if (go == null)
            {
                return;
            }
            Transform child = go.transform.FindChild(m_animation_path);

            if (child == null)
            {
                return;
            }
            m_unity_animation_cmp = child.GetComponent <Animation>();
            PlayerAnimation(AnimationName.IDLE, true);

            LocomotorComponent locomotor_componnet = GetLogicEntity().GetComponent(LocomotorComponent.ID) as LocomotorComponent;

            if (locomotor_componnet != null)
            {
                m_locomotor_animation_speed = (float)locomotor_componnet.LocomotorSpeedRate;
            }
        }
Ejemplo n.º 2
0
        public void Update(GameTime gameTime)
        {
            if (inputManager.IsKeyDown(Keys.Left))
            {
                ParentObject.Transform.Velocity -= Vector3.Left * speed;
            }
            if (inputManager.IsKeyDown(Keys.Right))
            {
                ParentObject.Transform.Velocity += Vector3.Left * speed;
            }
            if (inputManager.IsKeyDown(Keys.Up))
            {
                ParentObject.Transform.Velocity -= Vector3.Forward * speed;
            }
            if (inputManager.IsKeyDown(Keys.Down))
            {
                ParentObject.Transform.Velocity += Vector3.Forward * speed;
            }
            ParentObject.Transform.Velocity *= 0.95f;

            RayCastResult result;

            if (inputManager.GetMouseImpact(out result))
            {
                Vector3 point = result.HitData.Location.ToXNAVector();
                point.Y = ParentObject.Transform.AbsoluteTransform.Translation.Y; //keeps the rotation clean
                Vector3 lookAt = ParentObject.Transform.AbsoluteTransform.Translation - point;
                lookAt.Normalize();
                ParentObject.Transform.SetLookAndUp(lookAt, Vector3.Up);
            }

            ParentObject.GetComponent <PhysicsComponent>().DoCollisionResponse(speed);
        }
Ejemplo n.º 3
0
 public void Initialise()
 {
     Enabled       = true;
     physicsEntity = ParentObject.GetComponent <PhysicsComponent>();
     input         = SystemCore.Input;
     AddInputBindings();
 }
Ejemplo n.º 4
0
        public virtual void AssignMatrixParameters()
        {
            var    transform     = ParentObject.GetComponent <TransformComponent>();
            Matrix world         = Matrix.CreateWorld(SystemCore.ActiveCamera.Position, Vector3.Forward, Vector3.Up);
            Matrix worldViewProj = Matrix.CreateScale(ParentObject.Transform.Scale) * world;

            worldViewProj *= SystemCore.ActiveCamera.View;
            worldViewProj *= SystemCore.ActiveCamera.Projection;

            if (ParameterExists("World"))
            {
                effect.Parameters["World"].SetValue(Matrix.CreateScale(ParentObject.Transform.Scale) * world);
            }

            if (ParameterExists("View"))
            {
                effect.Parameters["View"].SetValue(SystemCore.ActiveCamera.View);
            }

            if (ParameterExists("Projection"))
            {
                effect.Parameters["Projection"].SetValue(SystemCore.ActiveCamera.Projection);
            }

            if (ParameterExists("WorldViewProjection"))
            {
                effect.Parameters["WorldViewProjection"].SetValue(worldViewProj);
            }
        }
Ejemplo n.º 5
0
        public virtual void Draw(GameTime gameTime)
        {
            if (!Visible)
            {
                return;
            }

            PreDraw(gameTime);

            if (ParameterExists("time"))
            {
                effect.Parameters["time"].SetValue((float)gameTime.TotalGameTime.TotalMilliseconds);
            }

            var renderGeometry = ParentObject.GetComponent <RenderGeometryComponent>();

            if (renderGeometry != null)
            {
                SystemCore.GraphicsDevice.SetVertexBuffer(renderGeometry.VertexBuffer);
                SystemCore.GraphicsDevice.Indices = renderGeometry.IndexBuffer;

                GameObjectManager.verts      += renderGeometry.VertexBuffer.VertexCount;
                GameObjectManager.primitives += renderGeometry.PrimitiveCount;


                for (int i = 0; i < effect.CurrentTechnique.Passes.Count; i++)
                {
                    effect.CurrentTechnique.Passes[i].Apply();
                    SystemCore.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, renderGeometry.VertexBuffer.VertexCount, 0, renderGeometry.PrimitiveCount);
                }
            }

            var modelComponent = ParentObject.GetComponent <ModelComponent>();

            if (modelComponent != null)
            {
                Model m = modelComponent.Model;
                foreach (var mesh in m.Meshes)
                {
                    foreach (ModelMeshPart p in mesh.MeshParts)
                    {
                        SystemCore.GraphicsDevice.SetVertexBuffer(p.VertexBuffer);
                        SystemCore.GraphicsDevice.Indices = p.IndexBuffer;

                        GameObjectManager.verts      += p.VertexBuffer.VertexCount;
                        GameObjectManager.primitives += p.IndexBuffer.IndexCount;

                        for (int i = 0; i < effect.CurrentTechnique.Passes.Count; i++)
                        {
                            effect.CurrentTechnique.Passes[i].Apply();
                            SystemCore.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, p.PrimitiveCount);
                        }
                    }
                }
            }

            PostDraw(gameTime);
        }
Ejemplo n.º 6
0
        public void SetHighPrecisionPosition(Vector3 position)
        {
            if (highPrecisionPosition == null)
            {
                highPrecisionPosition = ParentObject.GetComponent <HighPrecisionPosition>();
            }

            highPrecisionPosition.Position = new Vector3d(position);
        }
Ejemplo n.º 7
0
        void Resurrect()
        {
            StateComponent state_component = ParentObject.GetComponent(StateComponent.ID) as StateComponent;

            if (state_component != null)
            {
                state_component.RemoveState(StateSystem.DEAD_STATE, 0);
            }
        }
        /// <summary>
        /// unity Awake method
        /// is called when the script instance is being loaded
        /// </summary>
        void Awake()
        {
            if (!ParentObject)
            {
                Debug.LogError("BodyColliderScript has not assigned 'ParentObject'"); return;
            }

            // get game character interface
            m_GCharacterOwner = ParentObject.GetComponent <IGameCharacter>();
        }
Ejemplo n.º 9
0
        public override void OnResurrect()
        {
            StateComponent state_component = ParentObject.GetComponent(StateComponent.ID) as StateComponent;

            if (state_component != null)
            {
                state_component.RemoveState(StateSystem.DEAD_STATE, 0);
            }
            GetLogicWorld().AddSimpleRenderMessage(RenderMessageType.Show, GetOwnerEntityID());
        }
Ejemplo n.º 10
0
        private void GenerateSphereCollider()
        {
            RenderGeometryComponent geometry = ParentObject.GetComponent <RenderGeometryComponent>();
            List <Vector3>          verts    = geometry.GetVertices();
            BoundingSphere          sphere   = BoundingSphere.CreateFromPoints(verts);

            PhysicsEntity = new Sphere(MonoMathHelper.Translate(ParentObject.Transform.AbsoluteTransform.Translation),
                                       sphere.Radius, 1);
            PhysicsEntity.Tag = ParentObject;
        }
Ejemplo n.º 11
0
        private void FeelForward()
        {
            DoomComponent playerDoomComponent = ParentObject.GetComponent <DoomComponent>();

            Vector3 pos        = ParentObject.Transform.AbsoluteTransform.Translation;
            Vector3 forwardVec = ParentObject.Transform.AbsoluteTransform.Translation + ParentObject.Transform.AbsoluteTransform.Forward * playerDoomComponent.HitVectorSize;
            Vector3 rightVec   = MonoMathHelper.RotateAroundPoint(forwardVec, ParentObject.Transform.AbsoluteTransform.Translation, Vector3.Up, MathHelper.PiOver4 / 2);
            Vector3 leftVec    = MonoMathHelper.RotateAroundPoint(forwardVec, ParentObject.Transform.AbsoluteTransform.Translation, Vector3.Up, -MathHelper.PiOver4 / 2);

            pos.Y        = 0;
            forwardVec.Y = 0;
            rightVec.Y   = 0;
            leftVec.Y    = 0;



            Color forwardColor = Color.Red;
            Color leftColor    = Color.Red;
            Color rightColor   = Color.Red;


            if (mapHandler.IntersectsLevel(pos, forwardVec))
            {
                forwardColor = Color.Blue;
            }
            if (mapHandler.IntersectsLevel(pos, rightVec))
            {
                rightColor = Color.Blue;

                var strafe = new RestRequest("player/actions", Method.POST);
                strafe.RequestFormat = DataFormat.Json;
                strafe.AddBody(new PlayerAction()
                {
                    type = "strafe-left", amount = 2
                });
                apiHandler.EnqueueCoolDownRequest("strafe-left", strafe, 400, x => { });
            }
            if (mapHandler.IntersectsLevel(pos, leftVec))
            {
                leftColor = Color.Blue;

                var strafe = new RestRequest("player/actions", Method.POST);
                strafe.RequestFormat = DataFormat.Json;
                strafe.AddBody(new PlayerAction()
                {
                    type = "strafe-right", amount = 2
                });
                apiHandler.EnqueueCoolDownRequest("strafe-right", strafe, 400, x => { });
            }

            DebugShapeRenderer.AddLine(pos, forwardVec, forwardColor);
            DebugShapeRenderer.AddLine(pos, leftVec, leftColor);
            DebugShapeRenderer.AddLine(pos, rightVec, rightColor);
        }
Ejemplo n.º 12
0
        public void KillOwner(int killer_id)
        {
            //ZZWTODO Resurrect

            if (m_die_task != null)
            {
                m_die_task.Cancel();
            }
            LogicWorld logic_world = GetLogicWorld();

            Entity killer = logic_world.GetEntityManager().GetObject(killer_id);

            if (!DieSilently && killer_id != ParentObject.ID && m_killer_generator != null && killer != null)
            {
                EffectApplicationData app_data = RecyclableObject.Create <EffectApplicationData>();
                app_data.m_original_entity_id = ParentObject.ID;
                app_data.m_source_entity_id   = ParentObject.ID;
                m_killer_generator.Activate(app_data, killer);
                RecyclableObject.Recycle(app_data);
            }

            var schedeler = logic_world.GetTaskScheduler();

            if (DieSilently)
            {
                logic_world.AddSimpleRenderMessage(RenderMessageType.Hide, ParentObject.ID);
            }
            else
            {
                HideEntityTask hide_task = LogicTask.Create <HideEntityTask>();
                hide_task.Construct(ParentObject.ID);
                schedeler.Schedule(hide_task, GetCurrentTime(), m_hide_delay);
            }

            ParentObject.DeletePending = true;
            ParentObject.SendSignal(SignalType.Die);
            logic_world.AddSimpleRenderMessage(RenderMessageType.Die, ParentObject.ID);

            StateComponent state_component = ParentObject.GetComponent(StateComponent.ID) as StateComponent;

            if (state_component != null)
            {
                state_component.AddState(StateSystem.DEAD_STATE, 0);
            }

            if (!m_can_resurrect)
            {
                DeleteEntityTask delete_task = LogicTask.Create <DeleteEntityTask>();
                delete_task.Construct(ParentObject.ID);
                schedeler.Schedule(delete_task, GetCurrentTime(), m_delete_delay);
            }

            logic_world.OnKillEntity(killer, GetOwnerEntity());
        }
Ejemplo n.º 13
0
        public virtual void Draw(GameTime gameTime)
        {
            if (!Visible)
            {
                return;
            }

            Matrix lightViewProj = SystemCore.ShadowMapRenderer.LightViewProj;

            effect.Parameters["LightWorldViewProjection"].SetValue(Matrix.CreateScale(ParentObject.Transform.Scale) * ParentObject.Transform.AbsoluteTransform * lightViewProj);


            var renderGeometry = ParentObject.GetComponent <RenderGeometryComponent>();

            if (renderGeometry != null)
            {
                SystemCore.GraphicsDevice.SetVertexBuffer(renderGeometry.VertexBuffer);
                SystemCore.GraphicsDevice.Indices = renderGeometry.IndexBuffer;

                GameObjectManager.verts      += renderGeometry.VertexBuffer.VertexCount;
                GameObjectManager.primitives += renderGeometry.PrimitiveCount;


                for (int i = 0; i < effect.CurrentTechnique.Passes.Count; i++)
                {
                    effect.CurrentTechnique.Passes[i].Apply();
                    SystemCore.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, renderGeometry.VertexBuffer.VertexCount, 0, renderGeometry.PrimitiveCount);
                }
            }

            var modelComponent = ParentObject.GetComponent <ModelComponent>();

            if (modelComponent != null)
            {
                Model m = modelComponent.Model;
                foreach (var mesh in m.Meshes)
                {
                    foreach (ModelMeshPart p in mesh.MeshParts)
                    {
                        SystemCore.GraphicsDevice.SetVertexBuffer(p.VertexBuffer);
                        SystemCore.GraphicsDevice.Indices = p.IndexBuffer;

                        GameObjectManager.verts      += p.VertexBuffer.VertexCount;
                        GameObjectManager.primitives += p.IndexBuffer.IndexCount;

                        for (int i = 0; i < effect.CurrentTechnique.Passes.Count; i++)
                        {
                            effect.CurrentTechnique.Passes[i].Apply();
                            SystemCore.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, p.PrimitiveCount);
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
0
        private void GenerateBoxCollider()
        {
            RenderGeometryComponent geometry = ParentObject.GetComponent <RenderGeometryComponent>();
            List <Vector3>          verts    = geometry.GetVertices();
            BoundingBox             testBox  = BoundingBox.CreateFromPoints(verts);
            float width  = testBox.Max.X - testBox.Min.X;
            float height = testBox.Max.Y - testBox.Min.Y;
            float depth  = testBox.Max.Z - testBox.Min.Z;

            PhysicsEntity = new Box(new BEPUutilities.Vector3(ParentObject.Transform.AbsoluteTransform.Translation.X,
                                                              ParentObject.Transform.AbsoluteTransform.Translation.X,
                                                              ParentObject.Transform.AbsoluteTransform.Translation.X), width, height, depth, 1);
        }
Ejemplo n.º 15
0
 protected override void PostInitializeComponent()
 {
     m_target_gathering_param           = new TargetGatheringParam();
     m_target_gathering_param.m_type    = TargetGatheringType.SurroundingRing;
     m_target_gathering_param.m_param1  = m_guard_range;
     m_target_gathering_param.m_faction = FactionRelation.Enemy;
     m_targeting_component = ParentObject.GetComponent(TargetingComponent.ID) as TargetingComponent;
     if (m_targeting_component == null)
     {
         return;
     }
     m_listener_context = SignalListenerContext.CreateForEntityComponent(GetLogicWorld().GenerateSignalListenerID(), ParentObject.ID, m_component_type_id);
     Schedule();
 }
Ejemplo n.º 16
0
        public void PostInitialise()
        {
            player = ParentObject as Player;
            this.physicsComponent = ParentObject.GetComponent <PhysicsComponent>();

            mover   = new EntityMover(physicsComponent.PhysicsEntity);
            rotator = new EntityRotator(physicsComponent.PhysicsEntity);
            SystemCore.PhysicsSimulation.Add(mover);
            SystemCore.PhysicsSimulation.Add(rotator);


            mover.LinearMotor.Settings.Servo.SpringSettings.Stiffness /= 10000;
            mover.LinearMotor.Settings.Servo.SpringSettings.Damping   /= 1000;
        }
Ejemplo n.º 17
0
        protected override void PostInitializeComponent()
        {
            LogicWorld logic_world = GetLogicWorld();
            var        enumerator  = m_index2id.GetEnumerator();

            while (enumerator.MoveNext())
            {
                int skill_index = enumerator.Current.Key;
                int skill_cfgid = enumerator.Current.Value;
                CreateSkill(skill_index, skill_cfgid);
            }
            m_locomotor_cmp    = ParentObject.GetComponent(LocomotorComponent.ID) as LocomotorComponent;
            m_listener_context = SignalListenerContext.CreateForEntityComponent(logic_world.GenerateSignalListenerID(), ParentObject.ID, m_component_type_id);
            ParentObject.AddListener(SignalType.StartMoving, m_listener_context);
        }
Ejemplo n.º 18
0
        public override EntityComponent Create()
        {
            if (TypeObject.Naming?.Value)
            {
                var namingFactory = new NamingFactory(TypeObject.Naming.Value, GameObject);
                namingFactory.Create();
            }

            var parentLocationComponent = ParentObject.GetComponent <LocationComponent>();

            if (parentLocationComponent)
            {
                Component.Position = parentLocationComponent.EntryCell.ToWorld();
            }

            return(Component);
        }
Ejemplo n.º 19
0
    public ShipPart(float initial_health, GameObject obj, float mass)
    {
        OwnObject = obj;
        Transform = obj.transform;
        Mass      = mass;

        ParentObject  = obj.transform.root.gameObject;
        parent_script = ParentObject.GetComponent <ShipControl>();
        if (parent_script == null)
        {
            throw new System.NullReferenceException("No ShipControl here");
        }
        HP                = InitHP = initial_health;
        ParentShip        = parent_script.myship;
        parent_collection = ParentShip.Parts;
        parent_collection.Add(this);
    }
Ejemplo n.º 20
0
        void ActivateState(StateData data)
        {
            for (int i = 0; i < data.m_disable_componnets.Count; ++i)
            {
                Component component = ParentObject.GetComponent(data.m_disable_componnets[i]);
                if (component != null)
                {
                    component.Disable();
                }
            }
#if COMBAT_CLIENT
            if (data.m_render_effect_cfgid > 0)
            {
                PlayRenderEffectMessage msg = RenderMessage.Create <PlayRenderEffectMessage>();
                msg.ConstructAsPlay(GetOwnerEntityID(), data.m_render_effect_cfgid, FixPoint.MinusOne);
                GetLogicWorld().AddRenderMessage(msg);
            }
#endif
        }
Ejemplo n.º 21
0
        void StopMoveAnimation()
        {
            if (m_locomotor_component.IsAnimationBlocked)
            {
                return;
            }
            AnimationComponent animation_component = ParentObject.GetComponent(AnimationComponent.ID) as AnimationComponent;

            if (animation_component != null)
            {
                animation_component.PlayerAnimation(AnimationName.IDLE, true);
            }
            AnimatorComponent animator_component = ParentObject.GetComponent(AnimatorComponent.ID) as AnimatorComponent;

            if (animator_component != null)
            {
                animator_component.PlayAnimation(AnimationName.IDLE);
            }
        }
        public override void Awake()
        {
            Parent = ReinterpretObject <DatabaseObject>(ParentObject);
            SynchronizedContexts = new ConcurrentDictionary <int, DatabaseContext>();
            RemovableIdentifiers = new ConcurrentStack <int>();

            var visualUpdater = ParentObject.GetComponent <DatabaseVisualUpdaterComponent>();

            if (visualUpdater != null)
            {
                visualUpdater.AddUpdatabableControl(new UpdatableControl("SyncContextsInfoLabel", (control) =>
                {
                    control.Text = $"Synchronized contexts: {SynchronizedContexts.Count}";
                }));

                visualUpdater.AddUpdatabableControl(new UpdatableControl("QueriesProgress", (control) =>
                {
                    if (control is Guna2ProgressBar progress)
                    {
                        progress.Maximum = Settings.Read <int>("max_queries_limiter", "statistics");
                        progress.Value   = CurrentQueriesSummaryInfo;
                    }
                }));
                visualUpdater.AddUpdatabableControl(new UpdatableControl("QueriesCountLabel", (control) =>
                {
                    control.Text = $"{CurrentQueriesSummaryInfo} / {Settings.Read<int>("max_queries_limiter", "statistics")}";
                }));

                visualUpdater.AddUpdatabableControl(new UpdatableControl("AccessesProgress", (control) =>
                {
                    if (control is Guna2ProgressBar progress)
                    {
                        progress.Maximum = Settings.Read <int>("max_accesses_limiter", "statistics");
                        progress.Value   = CurrentAccessesSummaryInfo;
                    }
                }));
                visualUpdater.AddUpdatabableControl(new UpdatableControl("AccessesCountLabel", (control) =>
                {
                    control.Text = $"{CurrentAccessesSummaryInfo} / {Settings.Read<int>("max_accesses_limiter", "statistics")}";
                }));
            }
        }
Ejemplo n.º 23
0
        protected override void PostInitializeComponent()
        {
            m_model_component = ParentObject.GetComponent(ModelComponent.ID) as ModelComponent;
            if (m_model_component == null)
            {
                return;
            }
            GameObject go = m_model_component.GetUnityGameObject();

            if (go == null)
            {
                return;
            }
            m_interpolation_tr = go.transform;
            m_model_component.SetPredictComponent(this);
            Entity entity = GetLogicEntity();

            m_position_component  = entity.GetComponent(PositionComponent.ID) as PositionComponent;
            m_locomotor_component = entity.GetComponent(LocomotorComponent.ID) as LocomotorComponent;
        }
Ejemplo n.º 24
0
        FixPoint CalculateFinalDamageAmount(Damage damage, Entity attacker)
        {
            FixPoint damage_amount = damage.m_damage_amount;

            if (attacker != null)
            {
                DamageModificationComponent attacker_cmp = attacker.GetComponent(DamageModificationComponent.ID) as DamageModificationComponent;
                if (attacker_cmp != null)
                {
                    damage_amount = attacker_cmp.ApplyModifiersToDamage(damage, damage_amount, ParentObject, true);
                }
            }
            DamageModificationComponent self_cmp = ParentObject.GetComponent(DamageModificationComponent.ID) as DamageModificationComponent;

            if (self_cmp != null)
            {
                damage_amount = self_cmp.ApplyModifiersToDamage(damage, damage_amount, attacker, false);
            }
            return(damage_amount);
        }
Ejemplo n.º 25
0
        void PlayMoveAnimation(Vector3 direction)
        {
            if (m_locomotor_component.IsAnimationBlocked)
            {
                return;
            }
            m_model_component.SetBaseAngle(Mathf.Atan2(-direction.z, direction.x) * 180 / Mathf.PI);
            AnimationComponent animation_component = ParentObject.GetComponent(AnimationComponent.ID) as AnimationComponent;

            if (animation_component != null)
            {
                animation_component.PlayerAnimation(animation_component.LocomotorAnimationName, true);
            }
            AnimatorComponent animator_component = ParentObject.GetComponent(AnimatorComponent.ID) as AnimatorComponent;

            if (animator_component != null)
            {
                animator_component.PlayAnimation(animator_component.LocomotorAnimationName);
            }
        }
Ejemplo n.º 26
0
        //FixPoint m_tolerance = FixPoint.One / FixPoint.Ten;
        //Vector3FP m_destination = new Vector3FP(new FixPoint(99999), FixPoint.Zero, new FixPoint(99999));

        public bool FindPath(Vector3FP destination)
        {
            if (!IsEnable())
            {
                return(false);
            }
            //if (FixPoint.Abs(destination.x - m_destination.x) + FixPoint.Abs(destination.z - m_destination.z) < m_tolerance)
            //    return true;
            LocomotorComponent locomotor_cmp = ParentObject.GetComponent(LocomotorComponent.ID) as LocomotorComponent;

            if (locomotor_cmp == null)
            {
                return(false);
            }
            PositionComponent position_cmp = ParentObject.GetComponent(PositionComponent.ID) as PositionComponent;

            if (position_cmp == null)
            {
                return(false);
            }
            GridGraph graph = position_cmp.GetGridGraph();

            if (graph == null)
            {
                return(false);
            }
            if (!graph.FindPath(position_cmp.CurrentPosition, destination))
            {
                locomotor_cmp.StopMoving();
                return(false);
            }
            List <Vector3FP> path = graph.GetPath();

            if (!locomotor_cmp.MoveAlongPath(path, false))
            {
                return(false);
            }
            //m_destination = destination;
            return(true);
        }
Ejemplo n.º 27
0
        public virtual void AssignMatrixParameters()
        {
            var    transform     = ParentObject.GetComponent <TransformComponent>();
            Matrix worldViewProj = Matrix.CreateScale(ParentObject.Transform.Scale) * transform.AbsoluteTransform;

            worldViewProj *= SystemCore.GetCamera(Camera).View;
            worldViewProj *= SystemCore.GetCamera(Camera).Projection;

            if (ParameterExists("World"))
            {
                effect.Parameters["World"].SetValue(Matrix.CreateScale(ParentObject.Transform.Scale) * transform.AbsoluteTransform);
            }

            if (ParameterExists("View"))
            {
                effect.Parameters["View"].SetValue(SystemCore.GetCamera(Camera).View);
            }

            if (ParameterExists("Projection"))
            {
                effect.Parameters["Projection"].SetValue(SystemCore.GetCamera(Camera).Projection);
            }

            if (ParameterExists("WorldViewProjection"))
            {
                effect.Parameters["WorldViewProjection"].SetValue(worldViewProj);
            }

            if (ParameterExists("CameraPosition"))
            {
                effect.Parameters["CameraPosition"].SetValue(SystemCore.GetCamera(Camera).Position);
            }

            if (ParameterExists("ViewInvert"))
            {
                effect.Parameters["ViewInvert"].SetValue(Matrix.Invert(SystemCore.GetCamera(Camera).View));
            }
        }
Ejemplo n.º 28
0
        public virtual void Draw(GameTime gameTime)
        {
            if (!Visible)
            {
                return;
            }

            PreDraw(gameTime);

            var renderGeometry = ParentObject.GetComponent <RenderGeometryComponent>();

            SystemCore.GraphicsDevice.SetVertexBuffer(renderGeometry.VertexBuffer);
            SystemCore.GraphicsDevice.Indices = renderGeometry.IndexBuffer;

            GameObjectManager.verts      += renderGeometry.VertexBuffer.VertexCount;
            GameObjectManager.primitives += renderGeometry.PrimitiveCount;


            for (int i = 0; i < effect.CurrentTechnique.Passes.Count; i++)
            {
                effect.CurrentTechnique.Passes[i].Apply();
                SystemCore.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, renderGeometry.VertexBuffer.VertexCount, 0, renderGeometry.PrimitiveCount);
            }
        }
Ejemplo n.º 29
0
        private void AssignTextureParameters()
        {
            //check it has a texture

            var material = ParentObject.GetComponent <MaterialComponent>();

            if (material != null)
            {
                if (!string.IsNullOrEmpty(material.TextureName))
                {
                    Texture2D t = SystemCore.ContentManager.Load <Texture2D>(material.TextureName);

                    if (ParameterExists("ModelTexture"))
                    {
                        effect.Parameters["ModelTexture"].SetValue(t);
                    }

                    if (ParameterExists("TextureIntensity"))
                    {
                        effect.Parameters["TextureIntensity"].SetValue(material.TextureIntensity);
                    }
                }
            }
        }
Ejemplo n.º 30
0
        public virtual void Draw(GameTime gameTime)
        {
            if (!Visible)
            {
                return;
            }

            var tempDepthState = new DepthStencilState();

            tempDepthState.DepthBufferWriteEnable       = false;
            SystemCore.GraphicsDevice.DepthStencilState = tempDepthState;
            PreDraw(gameTime);

            var renderGeometry = ParentObject.GetComponent <RenderGeometryComponent>();

            SystemCore.GraphicsDevice.SetVertexBuffer(renderGeometry.VertexBuffer);
            SystemCore.GraphicsDevice.Indices = renderGeometry.IndexBuffer;

            GameObjectManager.verts      += renderGeometry.VertexBuffer.VertexCount;
            GameObjectManager.primitives += renderGeometry.PrimitiveCount;


            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                SystemCore.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, renderGeometry.VertexBuffer.VertexCount, 0, renderGeometry.PrimitiveCount);
            }

            PostDraw(gameTime);

            var depthState = new DepthStencilState();

            depthState.DepthBufferEnable                = true;
            depthState.DepthBufferWriteEnable           = true;
            SystemCore.GraphicsDevice.DepthStencilState = depthState;
        }