Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: chutia (posted 2014-06-07 08:42:41, viewed 57 times)

1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96   97   98   99   100   101   102   103   104   105   106   107   108   109   110   111   112   113   114   115   116   117   118   119   120   121   122   123   124   125   126   127   128   129   130   131   132   133   134   135   136   137   138   139   140   141   142   143   144   145   146   147   148   149   150   151   152   153   154   155   156   157   158   159   160   161   162   163   164   165   166   167   168   169   170   171   172   173   174   175   176   177   178   179   180   181   182   183   184   185   186   187   188   189   190   191   192   193   194   195   196   197   198   199   200   201   202   203   204   205   206   207   208   209   210   211   212   213   214   215   216   217   218   219   220   221   222   223   224   225   226   227   228   229   230   231   232   233   234   235  
public class MyGdxGame extends Game {

   private SpriteBatch batch;
   private Texture texture;
   private OrthographicCamera myCamera;
   private float w;
   private float h;
   private ShaderProgram circleSegShader;
   private Mesh circleScaleSegMesh;
   private Stage stage;
   private float TotalSegments;
   Vector3 virtualres;


   @Override
   public void create() {      
      w = Gdx.graphics.getWidth();
      h = Gdx.graphics.getHeight();

      batch = new SpriteBatch();

      ViewPortsize = new Vector2();
      TotalSegments = 4.0f;
      virtualres = new Vector3(1280.0f, 720.0f, 0.0f);
      myCamera = new OrthographicCamera();
      myCamera.setToOrtho(false, w, h);

      texture = new Texture(Gdx.files.internal("data/libgdx.png"));
      texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

      circleScaleSegMesh = createCircleMesh_V3(0.0f,0.0f,200.0f, 30.0f,3, (360.0f /TotalSegments) );
      circleSegShader = loadShaderFromFile(new String("circleseg.vert"), new String("circleseg.frag"));
      shaderProgram.pedantic = false;

      stage = new Stage();
      stage.setViewport(new ExtendViewport(w, h));

      Gdx.input.setInputProcessor(stage);

   }

   @Override
   public void render() {      

      ....

      //render
      renderInit();
      renderCircleScaledSegment();

   }


   @Override
   public void resize(int width, int height) {

      stage.getViewport().update(width, height, true);

      myCamera.position.set( virtualres.x/2.0f, virtualres.y/2.0f, 0.0f);
      myCamera.update();

   }

   public void renderInit(){

      Gdx.gl20.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
      Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

      batch.setShader(null);   
      batch.setProjectionMatrix(myCamera.combined);

   }

   public void renderCircleScaledSegment(){

      Gdx.gl20.glEnable(GL20.GL_DEPTH_TEST);
      Gdx.gl20.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
      Gdx.gl20.glEnable(GL20.GL_BLEND);

      batch.begin();
      circleSegShader.begin();

      Matrix4 modelMatrix = new Matrix4();
      Matrix4 cameraMatrix = new Matrix4();
      Matrix4 cameraMatrix2 = new Matrix4();
      Matrix4 cameraMatrix3 = new Matrix4();
      Matrix4 cameraMatrix4 = new Matrix4();

      cameraMatrix = myCamera.combined.cpy();
      modelMatrix.idt().rotate(new Vector3(0.0f,0.0f,1.0f), 0.0f - ((360.0f /TotalSegments)/ 2.0f)).trn(virtualres.x/2.0f,virtualres.y/2.0f, 0.0f);
      cameraMatrix.mul(modelMatrix);

      cameraMatrix2 = myCamera.combined.cpy();
      modelMatrix.idt().rotate(new Vector3(0.0f,0.0f,1.0f), 0.0f - ((360.0f /TotalSegments)/ 2.0f) +(360.0f /TotalSegments) ).trn(virtualres.x/2.0f,virtualres.y/2.0f, 0.0f);
      cameraMatrix2.mul(modelMatrix);

      cameraMatrix3 = myCamera.combined.cpy();
      modelMatrix.idt().rotate(new Vector3(0.0f,0.0f,1.0f), 0.0f - ((360.0f /TotalSegments)/ 2.0f) +(2*(360.0f /TotalSegments))).trn(virtualres.x/2.0f,virtualres.y/2.0f, 0.0f);
      cameraMatrix3.mul(modelMatrix);

      cameraMatrix4 = myCamera.combined.cpy();
      modelMatrix.idt().rotate(new Vector3(0.0f,0.0f,1.0f),0.0f - ((360.0f /TotalSegments)/ 2.0f) +(3*(360.0f /TotalSegments)) ).trn(virtualres.x/2.0f,virtualres.y/2.0f, 0.0f);
      cameraMatrix4.mul(modelMatrix);

      Vector3 box2dpos = new Vector3(0.0f, 0.0f, 0.0f);

      circleSegShader.setUniformMatrix("u_projTrans",  cameraMatrix);
      circleSegShader.setUniformf("u_box2dpos", box2dpos);
      circleSegShader.setUniformi("u_texture",   0);
      texture.bind();
      circleScaleSegMesh.render(circleSegShader, GL20.GL_TRIANGLES);

      circleSegShader.setUniformMatrix("u_projTrans",  cameraMatrix2);
      circleSegShader.setUniformf("u_box2dpos", box2dpos);
      circleSegShader.setUniformi("u_texture",   0);
      texture.bind();
      circleScaleSegMesh.render(circleSegShader, GL20.GL_TRIANGLES);

      circleSegShader.setUniformMatrix("u_projTrans",  cameraMatrix3);
      circleSegShader.setUniformf("u_box2dpos", box2dpos);
      circleSegShader.setUniformi("u_texture",   0);
      texture.bind();
      circleScaleSegMesh.render(circleSegShader, GL20.GL_TRIANGLES);

      circleSegShader.setUniformMatrix("u_projTrans",  cameraMatrix4);
      circleSegShader.setUniformf("u_box2dpos", box2dpos);
      circleSegShader.setUniformi("u_texture",   0);
      texture.bind();
      circleScaleSegMesh.render(circleSegShader, GL20.GL_TRIANGLES);

      circleSegShader.end();
      batch.flush();
      batch.end();

      Gdx.gl20.glDisable(GL20.GL_DEPTH_TEST);
      Gdx.gl20.glDisable(GL20.GL_BLEND);

   }

   public Mesh createCircleMesh_V3(float cx, float cy, float r_out, float r_in, int num_segments, float segmentSizeDegrees){

         float theta = (float) (2.0f * MathUtils.PI / (num_segments * (360.0f / segmentSizeDegrees)));
         float c = MathUtils.cos(theta);//precalculate the sine and cosine
         float s = MathUtils.sin(theta);
         float t,t2;

         float x = r_out;//we start at angle = 0
         float y = 0;

         float x2 = r_in;//we start at angle = 0
         float y2 = 0;

         float[] meshCoords = new float[num_segments *2 *3  *7];
         int arrayIndex = 0;

         //array for triangles without indices
         for(int ii = 0; ii < num_segments; ii++)
         {


               meshCoords[arrayIndex] = x2+cx;
               meshCoords[arrayIndex +1] = y2+cy;
               meshCoords[arrayIndex +2] = 0.0f;
               meshCoords[arrayIndex +3] = 63.0f/255.0f;
               meshCoords[arrayIndex +4] = 139.0f/255.0f;
               meshCoords[arrayIndex +5] = 217.0f/255.0f;
               meshCoords[arrayIndex +6] = 0.7f;
               arrayIndex = arrayIndex + 7;


               meshCoords[arrayIndex] = x+cx;
               meshCoords[arrayIndex +1] = y+cy;
               meshCoords[arrayIndex +2] = 0.0f;
               meshCoords[arrayIndex +3] = 63.0f/255.0f;
               meshCoords[arrayIndex +4] = 139.0f/255.0f;
               meshCoords[arrayIndex +5] = 217.0f/255.0f;
               meshCoords[arrayIndex +6] = 0.7f;
               arrayIndex = arrayIndex + 7;

               t = x;
               x = c * x - s * y;
               y = s * t + c * y;

               meshCoords[arrayIndex] = x+cx;
               meshCoords[arrayIndex +1] = y+cy;
               meshCoords[arrayIndex +2] = 0.0f;
               meshCoords[arrayIndex +3] = 63.0f/255.0f;
               meshCoords[arrayIndex +4] = 139.0f/255.0f;
               meshCoords[arrayIndex +5] = 217.0f/255.0f;
               meshCoords[arrayIndex +6] = 0.7f;
               arrayIndex = arrayIndex + 7;


               meshCoords[arrayIndex] = x2+cx;
               meshCoords[arrayIndex +1] = y2+cy;
               meshCoords[arrayIndex +2] = 0.0f;
               meshCoords[arrayIndex +3] = 63.0f/255.0f;
               meshCoords[arrayIndex +4] = 139.0f/255.0f;
               meshCoords[arrayIndex +5] = 217.0f/255.0f;
               meshCoords[arrayIndex +6] = 0.7f;
               arrayIndex = arrayIndex + 7;

               meshCoords[arrayIndex] = x+cx;
               meshCoords[arrayIndex +1] = y+cy;
               meshCoords[arrayIndex +2] = 0.0f;
               meshCoords[arrayIndex +3] = 63.0f/255.0f;
               meshCoords[arrayIndex +4] = 139.0f/255.0f;
               meshCoords[arrayIndex +5] = 217.0f/255.0f;
               meshCoords[arrayIndex +6] = 0.7f;
               arrayIndex = arrayIndex + 7;

               t2 = x2;
               x2 = c * x2 - s * y2;
               y2 = s * t2 + c * y2;   

               meshCoords[arrayIndex] = x2+cx;
               meshCoords[arrayIndex +1] = y2+cy;
               meshCoords[arrayIndex +2] = 0.0f;
               meshCoords[arrayIndex +3] = 63.0f/255.0f;
               meshCoords[arrayIndex +4] = 139.0f/255.0f;
               meshCoords[arrayIndex +5] = 217.0f/255.0f;
               meshCoords[arrayIndex +6] = 0.7f;
               arrayIndex = arrayIndex + 7;
         }


      Mesh myMesh = new Mesh(VertexDataType.VertexArray, false, meshCoords.length, 0,
            new VertexAttribute(VertexAttributes.Usage.Position, 3, "a_position"),
            new VertexAttribute(VertexAttributes.Usage.Color, 4, "a_color"));         

      myMesh.setVertices(meshCoords);   

      return myMesh;    
    }
}





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (66 views)
2014-10-14 00:35:47

TehJavaDev (59 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!