//--------------------------------------
        // NON-PUBLIC METHODS
        //--------------------------------------

        /// <summary>Creates a new ball in the scene with the given position and velocity.</summary>
        /// <param name="p">The ball position, in world-space.</param>
        /// <param name="v">The initial velocity to give to the ball.</param>
        /// <param name="r">The ball radius.</param>
        private int CreateBall(Vector3 p, Vector3 v, float r = 1.0f)
        {
            var ball = AddEntity();

            AddComponent(ball, new CBody {
                Aabb     = new BoundingBox(-r * Vector3.One, r * Vector3.One),
                Radius   = r,
                LinDrag  = 0.1f,
                Position = p,
                Velocity = v
            });

            AddComponent(ball, new CTransform {
                Position = p,
                Rotation = Matrix.Identity,
                Scale    = r * Vector3.One
            });

            EnvMapMaterial envMap = null;

            AddComponent <C3DRenderable>(ball, new CImportedModel {
                model = Game1.Inst.Content.Load <Model>("Models/DummySphere")
            });


            return(ball);
        }
Ejemplo n.º 2
0
        //--------------------------------------
        // NON-PUBLIC METHODS
        //--------------------------------------

        /// <summary>Creates a new ball in the scene with the given position and velocity.</summary>
        /// <param name="p">The ball position, in world-space.</param>
        /// <param name="v">The initial velocity to give to the ball.</param>
        /// <param name="r">The ball radius.</param>
        /// <param name="reflective">Whether to use an environment mapped material.</param>
        private int CreateBall(Vector3 p, Vector3 v, float r = 1.0f, bool reflective = false)
        {
            var ball = AddEntity();

            AddComponent(ball, new CBody {
                Aabb     = new BoundingBox(-r * Vector3.One, r * Vector3.One),
                Radius   = r,
                LinDrag  = 0.1f,
                Velocity = v
            });

            CTransform transf;

            AddComponent(ball, transf = new CTransform {
                Position = p,
                Rotation = Matrix.Identity,
                Scale    = r * Vector3.One
            });

            EnvMapMaterial envMap = null;

            if (reflective)
            {
                var rot = 0.0f;
                envMap = new EnvMapMaterial(mRenderer,
                                            ball,
                                            (CTransform)GetComponentFromEntity <CTransform>(ball),
                                            Game1.Inst.Content.Load <Texture2D>("Textures/Bumpmap0"));

                // TODO: If the camera moves, this needs to be done every frame.
                //envMap.SetCameraPos(new Vector3(9.0f, 12.0f, 18.0f));
                AddComponent(ball, new CLogic {
                    Fn = (t, dt) => {
                        rot            += 1.0f * dt;
                        transf.Rotation = Matrix.CreateRotationX(rot)
                                          * Matrix.CreateRotationY(0.7f * rot);

                        envMap.Update();
                    },
                    InvHz = 1.0f / 30.0f
                });
            }

            AddComponent <C3DRenderable>(ball, new CImportedModel {
                materials = new Dictionary <int, MaterialShader> {
                    { 0, reflective ? envMap : null }
                },
                model = Game1.Inst.Content.Load <Model>("Models/DummySphere")
            });

            return(ball);
        }
        //--------------------------------------
        // NON-PUBLIC METHODS
        //--------------------------------------

        /// <summary>Creates a new ball in the scene with the given position and velocity.</summary>
        /// <param name="p">The ball position, in world-space.</param>
        /// <param name="v">The initial velocity to give to the ball.</param>
        /// <param name="r">The ball radius.</param>
        /// <param name="reflective">Whether to use an environment mapped material.</param>
        private int CreateBall(Vector3 p, Vector3 v, float r = 1.0f, bool reflective = false)
        {
            var ball = AddEntity();

            AddComponent(ball, new CBody {
                Aabb     = new BoundingBox(-r * Vector3.One, r * Vector3.One),
                Radius   = r,
                LinDrag  = 0.1f,
                Position = p,
                Velocity = v
            });
            CTransform transf;

            AddComponent(ball, transf = new CTransform {
                Position = p,
                Rotation = Matrix.Identity,
                Scale    = r * Vector3.One
            });


            if (reflective)
            {
                var rot = 0.0f;
                AddComponent(ball, new CInput());

                envMap = new EnvMapMaterial(mRenderer,
                                            ball,
                                            (CTransform)GetComponentFromEntity <CTransform>(ball),
                                            mSkybox);

                AddComponent(ball, new CLogic {
                    Fn = (t, dt) => {
                        rot            += 1.0f * dt;
                        transf.Rotation = Matrix.CreateRotationX(rot)
                                          * Matrix.CreateRotationY(0.7f * rot);
                        envMap.Update();
                    },
                    InvHz = 1.0f / 30.0f
                });
            }

            AddComponent <C3DRenderable>(ball, new CImportedModel {
                material = reflective ? envMap : null,
                model    = Game1.Inst.Content.Load <Model>("Models/DummySphere")
            });

            return(ball);
        }