Example #1
0
        public void Render(DeviceContext context, Matrix screen, Matrix projection, Color3 light)
        {
            //Render First person view of the tool, only if the tool is used by the current playing person !
            _cubeToolEffect.Begin(context);
            _cubeToolEffect.CBPerDraw.Values.Projection = Matrix.Transpose(projection);
            _cubeToolEffect.CBPerDraw.Values.Screen     = Matrix.Transpose(screen);
            _cubeToolEffect.CBPerDraw.Values.LightColor = light;
            _cubeToolEffect.CBPerDraw.IsDirty           = true;

            _cubeToolEffect.Apply(context);
            //Set the buffer to the device
            _cubeVb.SetToDevice(context, 0);
            _cubeIb.SetToDevice(context, 0);

            //Draw things here.
            context.DrawIndexed(_cubeIb.IndicesCount, 0, 0);
        }
        private void DrawCube(DeviceContext context, CubeResource cube, CharacterEntity charEntity)
        {
            if (charEntity.ModelInstance == null)
            {
                return;
            }

            //Get the cube profile.
            var blockProfile = _visualWorldParameters.WorldParameters.Configuration.BlockProfiles[cube.CubeId];

            //Prapare to creation a new mesh with the correct texture mapping ID
            _materialChangeMapping[0] = blockProfile.Tex_Back.TextureArrayId;    //Change the Back Texture Id
            _materialChangeMapping[1] = blockProfile.Tex_Front.TextureArrayId;   //Change the Front Texture Id
            _materialChangeMapping[2] = blockProfile.Tex_Bottom.TextureArrayId;  //Change the Bottom Texture Id
            _materialChangeMapping[3] = blockProfile.Tex_Top.TextureArrayId;     //Change the Top Texture Id
            _materialChangeMapping[4] = blockProfile.Tex_Left.TextureArrayId;    //Change the Left Texture Id
            _materialChangeMapping[5] = blockProfile.Tex_Right.TextureArrayId;   //Change the Right Texture Id

            //Create the cube Mesh from the blue Print one
            _cubeMesh = _cubeMeshBluePrint.Clone(_materialChangeMapping);

            //Refresh the mesh data inside the buffers
            _cubeVb.SetData(context, _cubeMesh.Vertices);
            _cubeIb.SetData(context, _cubeMesh.Indices);

            //Render First person view of the tool, only if the tool is used by the current playing person !
            _cubeToolEffect.Begin(context);
            _cubeToolEffect.CBPerDraw.Values.Projection = Matrix.Transpose(_camManager.ActiveCamera.ViewProjection3D);
            _cubeToolEffect.CBPerDraw.Values.Screen     = Matrix.Transpose(Matrix.Scaling(10.0f) * Matrix.Translation(0f, 5.5f, 1.8f) * charEntity.ModelInstance.GetToolTransform());
            _cubeToolEffect.CBPerDraw.Values.LightColor = charEntity.ModelInstance.LightColor;
            _cubeToolEffect.CBPerDraw.IsDirty           = true;

            _cubeToolEffect.Apply(context);
            //Set the buffer to the device
            _cubeVb.SetToDevice(context, 0);
            _cubeIb.SetToDevice(context, 0);

            //Draw things here.
            context.DrawIndexed(_cubeIb.IndicesCount, 0, 0);
        }