Changeset 7176 for 2015


Ignore:
Timestamp:
2016-06-04 11:33:00 (3 years ago)
Author:
sieerinn
Message:
 
Location:
2015/koodauskerho/sieerinn/JypeliShaderTest/JypeliShaderTest
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • 2015/koodauskerho/sieerinn/JypeliShaderTest/JypeliShaderTest/JypeliShaderTest/JypeliShaderTest.cs

    r7171 r7176  
    2727    private SpriteBatch spriteBatch; 
    2828 
     29    struct Shockwave 
     30    { 
     31        public Vector Center; 
     32        public double Time; 
     33    } 
     34 
     35    private const int MAX_WAVES = 8; 
     36    private readonly Shockwave[] waves = new Shockwave[MAX_WAVES]; 
     37    private int waveIndex = 0; 
     38 
     39    private void NewWave(Vector position) 
     40    { 
     41        waves[waveIndex].Time = 0f; 
     42        waves[waveIndex].Center = position; 
     43        waveIndex = ++waveIndex % MAX_WAVES; 
     44    } 
     45 
    2946    public override void Begin() 
    3047    { 
     
    3350            GraphicsDevice.PresentationParameters.BackBufferHeight); 
    3451 
    35         effect = Content.Load<Effect>("TestShader"); 
     52        effect = Content.Load<Effect>("Shockwave"); 
    3653        spriteBatch = new SpriteBatch(GraphicsDevice); 
    3754 
     55        IsMouseVisible = true; 
    3856        Gravity = new Vector(0, -1000); 
    3957 
    4058        LuoKentta(); 
    4159        LisaaNappaimet(); 
     60 
     61        Mouse.Listen(MouseButton.Left, ButtonState.Pressed, () => NewWave(Mouse.PositionOnWorld), null); 
    4262 
    4363        Camera.Follow(pelaaja1); 
     
    5878        effect.Parameters["MatrixTransform"].SetValue(halfPixelOffset * projection); 
    5979 
    60         effect.Parameters["Resolution"].SetValue(new Vector2(GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight)); 
    61         effect.Parameters["Misalign"].SetValue(0.003f); 
    62         effect.Parameters["Time"].SetValue(100f * (float)gameTime.TotalGameTime.TotalSeconds); 
     80        // TestShader 
     81        //effect.Parameters["Resolution"].SetValue(new Vector2(GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight)); 
     82        //effect.Parameters["Misalign"].SetValue(0.003f); 
     83        //effect.Parameters["Time"].SetValue(100f * (float)gameTime.TotalGameTime.TotalSeconds); 
     84 
     85        // Shockwave 
     86        var waveArray = new Vector4[MAX_WAVES]; 
     87        for (int i = 0; i < MAX_WAVES; i++) 
     88        { 
     89            waves[i].Time += 0.5 * gameTime.ElapsedGameTime.TotalSeconds; 
     90            Vector resolution = new Vector(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); 
     91            Vector screenCoord = Camera.WorldToScreen(waves[i].Center); 
     92            screenCoord.Y = resolution.Y - screenCoord.Y; 
     93            screenCoord.X /= resolution.X; 
     94            screenCoord.Y /= resolution.Y; 
     95            screenCoord += new Vector(0.5f, -0.5f); 
     96 
     97            var v = new Vector4((float)screenCoord.X, (float)screenCoord.Y, (float)waves[i].Time, 1f); 
     98            waveArray[i] = v; 
     99        } 
     100 
     101        effect.Parameters["Waves"].SetValue(waveArray); 
    63102 
    64103        GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.Black); 
  • 2015/koodauskerho/sieerinn/JypeliShaderTest/JypeliShaderTest/JypeliShaderTestContent/JypeliShaderTestContent.contentproj

    r7171 r7176  
    7474    </Compile> 
    7575  </ItemGroup> 
     76  <ItemGroup> 
     77    <Compile Include="Shockwave.fx"> 
     78      <Name>Shockwave</Name> 
     79      <Importer>EffectImporter</Importer> 
     80      <Processor>EffectProcessor</Processor> 
     81    </Compile> 
     82  </ItemGroup> 
    7683  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 
    7784  <!--  To modify your build process, add your task inside one of the targets below and uncomment it.  
Note: See TracChangeset for help on using the changeset viewer.