private void UpdateObjectCBs()
        {
            foreach (RenderItem e in _allRitems)
            {
                // Only update the cbuffer data if the constants have changed.
                // This needs to be tracked per frame resource.
                if (e.NumFramesDirty > 0)
                {
                    var objConstants = new ObjectConstants {
                        World = Matrix.Transpose(e.World)
                    };
                    CurrFrameResource.ObjectCB.CopyData(e.ObjCBIndex, ref objConstants);

                    // Next FrameResource need to be updated too.
                    e.NumFramesDirty--;
                }
            }
        }
Example #2
0
        protected override void Update(GameTimer gt)
        {
            // Convert Spherical to Cartesian coordinates.
            float x = _radius * MathHelper.Sinf(_phi) * MathHelper.Cosf(_theta);
            float z = _radius * MathHelper.Sinf(_phi) * MathHelper.Sinf(_theta);
            float y = _radius * MathHelper.Cosf(_phi);

            // Build the view matrix.
            _view = Matrix.LookAtLH(new Vector3(x, y, z), Vector3.Zero, Vector3.Up);

            // Simply use identity for world matrix for this demo.
            Matrix world = Matrix.Identity;

            var cb = new ObjectConstants
            {
                WorldViewProj = Matrix.Transpose(world * _view * _proj)
            };

            // Update the constant buffer with the latest worldViewProj matrix.
            _objectCB.CopyData(0, ref cb);
        }