1 / 41

Animation 1

Animation 1. In animation. The code needs to cut and show different parts of the picture below. actorvertexbuffer = new VertexBuffer ( typeof ( CustomVertex.PositionTextured ), 4 , device, 0, CustomVertex.PositionTextured.Format , Pool.Default );.

chipo
Download Presentation

Animation 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Animation 1

  2. In animation

  3. The code needs to cut and show different parts of the picture below

  4. actorvertexbuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, device, 0, CustomVertex.PositionTextured.Format, Pool.Default);

  5. actorvertexbuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, device, 0, CustomVertex.PositionTextured.Format, Pool.Default); The four decides the number of postions in the buffer, previously we needed four. Since we usen 4 courdinates to render a rectangel shape / tile

  6. In the vertex buffer we save the coordinates for the 4 ”corners” of the picture

  7. Obs this is a rectangel • actorvertexbuffer[0].X = 0.25f; actorvertexbuffer[0].Y = 0f;actorvertexbuffer[0].Z = 0.5f;actorvertexbuffer[1].X = 0.25f; actorvertexbuffer[1].Y = -0.50f; actorvertexbuffer[1].Z = 0.5f; actorvertexbuffer[2].X = 0f; actorvertexbuffer[2].Y = -0.50f; actorvertexbuffer[2].Z = 0.5f; actorvertexbuffer[3].X = 0f;actorvertexbuffer[3].Y = 0f; actorvertexbuffer[3].Z = 0.5f;

  8. One picture only

  9. In the vertex buffer there is also information regarding what part of the picture to show • // Top Right Hand Corneractorvertexbuffer[0].Tu = 1.0f;actorvertexbuffer [0].Tv = 0.0f; //Bottom Right HAnd Corneractorvertexbuffer[1].Tu = 1.0f;actorvertexbuffer [1].Tv = 1.0f;//Bottom Left Hand Corneractorvertexbuffer [2].Tu = 0.0f;actorvertexbuffer [2].Tv = 1.0f; //Top Left Hand Corneractorvertexbuffer [3].Tu = 0.0f;actorvertexbuffer[3].Tv = 0.0f;

  10. You can try to change the vaues • // Top Right Hand Corneractorvertexbuffer[0].Tu = 0.5f;actorvertexbuffer [0].Tv = 0.0f; //Bottom Right HAnd Corneractorvertexbuffer[1].Tu = 0.5f;actorvertexbuffer [1].Tv = 1.0f;//Bottom Left Hand Corneractorvertexbuffer [2].Tu = 0.0f;actorvertexbuffer [2].Tv = 1.0f; //Top Left Hand Corneractorvertexbuffer [3].Tu = 0.0f;actorvertexbuffer[3].Tv = 0.0f;

  11. The man is half...

  12. So we can use these coordinates to cut in the picture • next

  13. In order to animate show one third of the picture at the time

  14. First we need to fix the vertex buffer • Instead of coordinates for one square //or rectangle we need coordinates for three different squares/rectangles

  15. What should we change the 4 to? • actorvertexbuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, device, 0, CustomVertex.PositionTextured.Format, Pool.Default); The four decides the number of postions in the buffer, previously we needed four. Since we usen 4 courdinates to render a rectangel shape / tile

  16. We need information of 3*4 different corners... That would be 12 positions in the buffer actorvertexbuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), 12, device, 0, CustomVertex.PositionTextured.Format, Pool.Default);

  17. In position 0-3 we will store information about the first postion • // Top Right Hand Corneractorvertexbuffer[0].Tu = 0.33f;actorvertexbuffer[0].Tv = 0.0f; //Bottom Right HAnd Corneractorvertexbuffer[1].Tu = 0.33f;actorvertexbuffer[ [1].Tv = 1.0f;//Bottom Left Hand Corneractorvertexbuffer[ [2].Tu = 0.0f;actorvertexbuffer[2].Tv = 1.0f; //Top Left Hand Corneractorvertexbuffer[ [3].Tu = 0.0f;actorvertexbuffer[ [3].Tv = 0.0f;

  18. We still need to give the x,y,z coordinates... • actorvertexbuffer[0].X = 0.25f; actorvertexbuffer[0].Y = 0f;actorvertexbuffer[0].Z = 0.5f;actorvertexbuffer[1].X = 0.25f; actorvertexbuffer[1].Y = -0.50f; actorvertexbuffer[1].Z = 0.5f; actorvertexbuffer[2].X = 0f; actorvertexbuffer[2].Y = -0.50f; actorvertexbuffer[2].Z = 0.5f; actorvertexbuffer[3].X = 0f;actorvertexbuffer[3].Y = 0f; actorvertexbuffer[3].Z = 0.5f;

  19. In position 4-7 we will store information about the second postion • // Top Right Hand Corneractorvertexbuffer[4].Tu= 0.66f;actorvertexbuffer[4].Tv = 0.0f; //Bottom Right HAnd Corneractorvertexbuffer[5].Tu = 0.66f;actorvertexbuffer[ [5].Tv = 1.0f;//Bottom Left Hand Corneractorvertexbuffer[ [6].Tu = 0.33f;actorvertexbuffer[6].Tv = 1.0f; //Top Left Hand Corneractorvertexbuffer[ [7].Tu = 0.33f;actorvertexbuffer[ [7].Tv = 0.0f;

  20. What about the coordinates

  21. They will be the same we do not want to change the position only the piece of the picture that is used .. • actorvertexbuffer[4].X = 0.25f; actorvertexbuffer[4].Y = 0f;actorvertexbuffer[4].Z = 0.5f;actorvertexbuffer[5].X = 0.25f; actorvertexbuffer[5].Y = -0.50f; actorvertexbuffer[5].Z = 0.5f; actorvertexbuffer[6].X = 0f; actorvertexbuffer[6].Y = -0.50f; actorvertexbuffer[6].Z = 0.5f; actorvertexbuffer[7].X = 0f;actorvertexbuffer[7].Y = 0f; actorvertexbuffer[7].Z = 0.5f;

  22. In position 8-12 we will store information about the third postion • // Top Right Hand Corneractorvertexbuffer[8].Tu= 1.0f;actorvertexbuffer[8].Tv = 0.0f; //Bottom Right HAnd Corneractorvertexbuffer[9].Tu = 1.0f;actorvertexbuffer[ [9].Tv = 1.0f;//Bottom Left Hand Corneractorvertexbuffer[ 10].Tu = 0.66f;actorvertexbuffer[10].Tv = 1.0f; //Top Left Hand Corneractorvertexbuffer [12].Tu = 0.66f;actorvertexbuffer[12].Tv = 0.0f;

  23. And of course the postion coordinates are still the same

  24. Coordinates are still the same • actorvertexbuffer[8].X = 0.25f; actorvertexbuffer[8].Y = 0f;actorvertexbuffer[8].Z = 0.5f;actorvertexbuffer[9].X = 0.25f; actorvertexbuffer[9].Y = -0.50f; actorvertexbuffer[9].Z = 0.5f; actorvertexbuffer[10].X = 0f; actorvertexbuffer[10].Y = -0.50f; actorvertexbuffer[10].Z = 0.5f; actorvertexbuffer[11].X = 0f;actorvertexbuffer[11].Y = 0f; actorvertexbuffer[11].Z = 0.5f;

  25. When all the information is stored into the vertexbuffer • How do we get the program to read from the right postion in the buffer

  26. When all the information is stored into the vertexbuffer • How do we get the program to read from the right postion in the buffer • When we want to show the middle picture we want the program to read from postion 4 and so on...

  27. Where the render functions should start reading in the vertex buffer is Decided by the integer at position below marked in red • mydevice.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);

  28. So if want to show the middle part of the picture • Render function need to start reading at postion 4 in the buffer. • mydevice.DrawPrimitives(PrimitiveType.TriangleFan, 4, 2);

  29. mindevice.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);

  30. mindevice.DrawPrimitives(PrimitiveType.TriangleFan, 4, 2);

  31. mindevice.DrawPrimitives(PrimitiveType.TriangleFan, 8, 2);

  32. Need a new variable • int offset

  33. Offset need to alternate between 0,4,and 8 • if(offset==8){offset=0;}else{offset=offset+4;}

  34. mindevice.DrawPrimitives(PrimitiveType.TriangleFan,offset, 2);

  35. This will work as an animation • The joker will be running very fast on the same spot. • How can we slow him down?

  36. We can make a first attemt to create a very simple clock • If (clock==10) {clock=0;} • else • {clock=clock+1;}

  37. So postion is only changed when clock is 10 • if (clock == 10) { clock = 0; } else { clock = clock + 1; } • QuadMatrix.Translate(0.4f, 1.0f, 0f); • if (clock == 10) • { • if (arrayposition == 8) • { arrayposition = 0; } • else • { arrayposition = arrayposition + 4; } • } • mindevice.SetTransform(TransformType.World, QuadMatrix); • mindevice.SetStreamSource(0, spelaren.actorvertexbuffer , 0); • mindevice.SetTexture(0, spelare); • mindevice.RenderState.AlphaTestEnable = true; mindevice.RenderState.AlphaFunction = Compare.NotEqual; • mindevice.DrawPrimitives(PrimitiveType.TriangleFan, arrayposition, 2);

  38. Now he needs to move... • Not just run at same spot.. • So how can we move him forward? • It is time to connect the keyboard.. • But before we do that try to hard code a motion forwar on the screen....

More Related