Friday, May 27, 2016




FREE APP

DOWNLOAD HERE FROM Google Play

A simple way to draw a 3D model and show it on your device.

Easy 3D Sketch is an Android utility you can use on your tablet or phone to see how your kitchen table will look. All you have to do is prepare .csv (Excel) file with coordinates.

You can also use it to draw 3D objects for school lessons. For example, a cube, pyramid, etc.

You have to upload the coordinates because drawing on a tablet would be too imprecise, and using Excel lets you use all its features (functions, etc.).






The file with object coordinates should look like this:

1,10,-9,1,2,1,-7
2,10,-8,1,1,0,-6
3,10,-7,1,2,0,-5
4,9,-6,1,3,1,-4
5,9,-5,1,4,1,-3
6,8,-4,2,5,1,-2
6,8,-3,2,6,1,-1
7,7,-2,2,6,1,0
8,6,-1,2,7,1,1
8,5,0,2,8,1,2
9,5,1,3,8,1,3
9,4,2,3,9,1,4
10,3,3,3,9,1,5
10,2,4,3,10,1,6
10,1,5,3,10,1,7
10,0,6,3,10,1,8
10,-1,7,1,10,1,9
10,-2,8,1,10,1,10
9,-3,9,1,10,1,11
9,-4,10,1,9,1,12
9,-5,11,2,9,1,13
8,-6,12,2,9,1,14
7,-7,13,2,8,1,15
7,-7,14,2,7,1,16
6,-8,15,1,7,0,17
5,-9,16,1,6,0,18
4,-9,17,1,5,0,19
3,-9,18,1,4,0,20
2,-10,19,1,3,0,21
1,-10,20,1,2,0,22





You can even prepare it in Notepad. The first three numbers are X, Y, and Z coordinates, and the fourth number is meant to be the color. The next three numbers are X,Y and Z coordinates of a second point. Every two points represent one line.

The file can be prepared using Excel, and you can use formulas to calculate the function.





Important: coordinates must be integer numbers.

Save it as an ESFigure.csv  file:



Place the file in the root of your device storage.

Open 'Easy 3D Sketch' and tap on 'Open'.


Easy Sketch - How It Was Created

3D Wireframe Engine

1. Overview

Easy Sketch is an Android/LibGDX application for displaying and manipulating three-dimensional wireframe objects.

The application does not rely on a conventional 3D rendering engine for the main object visualization. Instead, it implements a lightweight custom 3D renderer.

The central concept is:

CSV coordinates → 3D line segments → transformations → 2D projection → screen rendering

The user can:

  • load a wireframe object from a CSV file;

  • display the object as connected 3D line segments;

  • move the object across the screen;

  • rotate it with touch gestures;

  • zoom it using a two-finger pinch gesture;

  • rotate it using device motion/orientation sensors;

  • display coordinate axes and a grid;

  • edit individual line coordinates;

  • save the wireframe back to CSV.

The main implementation is contained in TriDim.java, while the mathematical 3D operations are implemented in Grafika3Dracun.java.


2. Main Components

TriDim.java

This is the main application screen and contains most of the application logic.

It is responsible for:

  • user interaction;

  • gesture processing;

  • sensor input;

  • CSV loading;

  • CSV saving;

  • storage of the 3D geometry;

  • object centering;

  • zoom;

  • rotation state;

  • movement of the displayed object;

  • grid and axis generation;

  • rendering.

Grafika3Dracun.java

This class implements custom 3D mathematics.

It provides:

  • 4×4 matrix multiplication;

  • translation;

  • X-axis rotation;

  • Y-axis rotation;

  • Z-axis rotation;

  • combined XYZ rotation.

screen.java / screenmanager.java

These provide a simple screen abstraction and screen management mechanism.

OrthoCamera.java / VirtualViewport.java

These classes provide the LibGDX camera/viewport infrastructure.

Interestingly, the main wireframe object is not rendered through the camera's normal 3D pipeline. TriDim explicitly sets a 2D orthographic projection and performs its own 3D-to-2D transformation.

ActionResolverM.java

This is the interface between the LibGDX application and the Android-specific part of the application.

It provides operations such as:

  • opening a file;

  • saving a file;

  • checking file operations;

  • exiting;

  • sharing an image.



3. Internal Representation of a Wireframe

The geometry is stored in a three-dimensional array:

float[][][] shema;

The important dimensions represent:

shema[version][point][coordinate]

Each point contains four values:

[0] = X
[1] = Y
[2] = Z
[3] = colour

A line therefore occupies two consecutive entries.

For example:

point 0 = first endpoint
point 1 = second endpoint
point 2 = first endpoint of next line
point 3 = second endpoint of next line
...

The number of lines is stored in:

brlinija[AktivnaVerzija]

This means the application does not store a conventional list of 3D objects, meshes, or triangles.

It stores the model simply as a collection of independent line segments.


4. CSV File Format

The CSV format represents one line of the wireframe per row.

The structure is:

X1,Y1,Z1,Colour,X2,Y2,Z2

For example:

0,0,0,1,100,0,0

represents a line from:

(0, 0, 0)

to:

(100, 0, 0)

with colour value 1.

The parser reads the first four values:

R1 R2 R3 R4

and then the second point:

RA1 RA2 RA3

The colour of the first point/line is stored as R4.

The same colour is then assigned to the second endpoint because the application treats colour as a property of the complete line rather than independently coloured endpoints.


5. CSV Parsing

Parse() and ParseFajl() implement the CSV parser manually.

The parser searches for commas using:

text.indexOf(",", i)

and extracts individual fields using substring().

The helper method:

IzbaciOsimBr()

removes everything except digits and a possible minus sign.

This means the parser is intentionally tolerant of some non-numeric characters.

After a row has been parsed, its two endpoints are inserted into shema.

The parser also calculates:

MaxR

which represents the largest absolute coordinate found in the object.

This value is then stored as:

maxim = MaxR;

6. Automatic Object Scaling

After loading an object, the application does not immediately render the raw coordinates.

It first determines the largest coordinate magnitude.

For example, if the model contains:

X = 500
Y = -300
Z = 150

then maxim becomes:

500

This value is subsequently used by the grid/axis system and object initialization.

The initial zoom is set to:

zumiraj = 10f;

for objects loaded through the general parser.

Built-in gallery objects may subsequently receive their own initial zoom values.


7. Finding the Object Centre

The method:

Centar(int b)

calculates the average X, Y and Z coordinates of all endpoints.

Conceptually:

CentreX = sum(X) / number_of_points
CentreY = sum(Y) / number_of_points
CentreZ = sum(Z) / number_of_points

This centre is extremely important for rotation.

Instead of rotating the object around the global origin, crtajSliku() first translate every point so that the calculated object centre becomes the origin.

Conceptually:

original point
      ↓
subtract object centre
      ↓
rotate around (0,0,0)
      ↓
project to screen

This is what makes the object rotate around itself rather than around an arbitrary point in space.


8. Custom 3D Mathematics

Grafika3Dracun implements the mathematical transformation system.

A point is represented internally using homogeneous coordinates:

[x, y, z, 1]

The additional 1 allows translation to be represented as a matrix operation.

The matrix multiplication routine is:

MnoziMatrice()

It multiplies the point vector by a 4×4 transformation matrix.


9. Translation

The method:

translacija(x, y, z, tx, ty, tz)

moves a point by:

X' = X + tx
Y' = Y + ty
Z' = Z + tz

For rendering the object, the application uses this operation to subtract the object centre.

For example:

G3DR.translacija(
    x1,
    y1,
    z1,
    -CentarX * zumiraj,
    -CentarY * zumiraj,
    -CentarZ * zumiraj
);

Thus the object's calculated centre becomes the rotation centre.


10. Rotation Around X

RotacijaX() uses the standard X-axis rotation matrix.

Conceptually:

X' = X

Y' = Y cos(a) + Z sin(a)

Z' = -Y sin(a) + Z cos(a)

The angle is represented by alfa.


11. Rotation Around Y

RotacijaY() performs rotation around the Y axis.

The transformation is equivalent to:

X' = X cos(b) - Z sin(b)

Y' = Y

Z' = X sin(b) + Z cos(b)

The angle is represented by beta.


12. Rotation Around Z

RotacijaZ() performs rotation around the Z axis.

Conceptually:

X' = X cos(c) + Y sin(c)

Y' = -X sin(c) + Y cos(c)

Z' = Z

The angle is represented by gama.


13. Combined Rotation

ProjekcijaXY() performs the complete rotation sequence:

RotacijaX(x1, y1, z1, alfa);
RotacijaY(x, y, z, beta);
RotacijaZ(x, y, z, gama);

Therefore, the transformation order is:

X rotation
      ↓
Y rotation
      ↓
Z rotation

The order is important because 3D rotations are not commutative.

Changing the order would produce a different visual result.


14. 3D to 2D Projection

Easy Sketch does not use a conventional perspective camera for the main object.

After rotation, crtajSliku() simply takes the transformed:

X
Y

coordinates.

The Z coordinate is not used to calculate perspective size.

Therefore, the projection is essentially orthographic.

This means:

object closer to viewer

does not automatically become larger.

The only global magnification is controlled explicitly through:

zumiraj

This is appropriate for a technical wireframe viewer because the geometry remains visually stable while being rotated.


15. Complete Rendering Pipeline

For every line, crtajSliku() performs approximately the following algorithm:

Read endpoint A
Read endpoint B

        ↓

Apply zoom

        ↓

Translate A so object centre becomes origin
Translate B so object centre becomes origin

        ↓

Rotate A around X
Rotate A around Y
Rotate A around Z

Rotate B around X
Rotate B around Y
Rotate B around Z

        ↓

Take transformed X/Y coordinates

        ↓

Add screen offset PrviX / PrviY

        ↓

ShapeRenderer.line()

The final rendering operation is:

shapeRenderer.line(
    x1 + PrviX,
    y1 + PrviY,
    x2 + PrviX,
    y2 + PrviY
);

Thus the actual screen drawing is only 2D line drawing.

The 3D effect is entirely produced by the mathematical transformations performed beforehand.


16. Moving the Object With the Finger

The application has a MOVE mode.

During a pan gesture:

PrviX += deltaX / 2;
PrviY -= deltaY / 2;

PrviX and PrviY are therefore the final screen-space translation.

The division by two reduces the movement sensitivity.

The values are bounded so that the object cannot be moved arbitrarily far outside the usable screen area.

This movement occurs after the 3D transformation.

Therefore:

3D rotation
      ↓
2D projection
      ↓
screen movement

rather than moving the actual 3D coordinates.


17. Rotating With a Finger

The application has a separate ROTATE mode.

When the user pans:

horizontal finger movement
        ↓
SlajdY
        ↓
VelicinaS
        ↓
alfa

and:

vertical finger movement
        ↓
Slajd2Y
        ↓
Velicina2S
        ↓
beta

The actual angles are calculated as:

alfa = VelicinaS * 2;
beta = Velicina2S * 2;
gama = Velicina3S * 2;

Consequently, the user is not directly manipulating the 3D coordinates.

The gesture modifies the rotation angles, and the renderer recalculates every endpoint on every frame.


18. Pinch-to-Zoom

Zooming uses the LibGDX gesture detector.

When the user places two fingers on the screen, the application remembers the initial zoom:

initialScale = zumiraj;

During the pinch:

ratio = currentDistance / originalDistance;

and:

zumiraj = initialScale * ratio;

Therefore:

fingers apart
    → distance increases
    → ratio > 1
    → zoom increases

and:

fingers together
    → distance decreases
    → ratio < 1
    → zoom decreases

The zoom is limited to:

0.02 ≤ zumiraj ≤ 800

19. Device Motion / Accelerometer Rotation

The application contains a separate accelerometer mode.

The accelerometer values are obtained using:

Gdx.input.getAccelerometerY()
Gdx.input.getAccelerometerX()

When:

FixRotacija == 2

the accelerometer changes the rotation state:

accelerometer X
      ↓
SlajdY
      ↓
VelicinaS
      ↓
X rotation

accelerometer Y
      ↓
Slajd2Y
      ↓
Velicina2S
      ↓
Y rotation

The values are accumulated rather than directly replacing the angles.

This produces a tilt-controlled rotation.


20. Device Orientation / Compass Mode

There is another mode:

FixRotacija == 3

The source calls this the compass rotation mode.

When the device provides the required sensor information, the application reads:

getAzimuth()
getPitch()
getRoll()

and converts the values to the application's rotation parameters:

Velicina3S = azimuth / 360 * PI;
Velicina2S = -pitch / 360 * PI;
VelicinaS  = roll / 360 * PI;

Thus the three device orientation values control the three-dimensional rotation.

Although the UI contains a GYRO/COMPASS concept, the source code specifically exposes the LibGDX orientation APIs azimuth, pitch and roll. The exact Android sensor fusion underneath those APIs is outside this source package.


21. Grid and Coordinate Axes

NapuniGrid() creates the coordinate system as additional line segments.

The grid is itself stored in the same shema structure.

The application creates:

  • X axis;

  • Y axis;

  • Z axis;

  • arrowheads;

  • XY grid lines.

The grid coordinates are scaled using maxim.

This is an elegant design because the grid does not require a separate 3D rendering system.

It is simply another collection of line segments that goes through the same transformation pipeline.


22. Multiple Projections

The application contains a special projection display implemented by:

crtajSlikuProjekcija()

This draws the object's projections on different coordinate planes.

The source explicitly draws:

XY
XZ
YZ

style views.

This allows the application to display the same 3D geometry from several orthographic directions simultaneously.

That is useful for a technical drawing application because the user can inspect the object's projections rather than only its perspective-like wireframe view.


23. Editing Geometry

The application also supports manual coordinate editing.

Six values are maintained:

R1 R2 R3
R4 R5 R6

representing:

first point:
X Y Z

second point:
X Y Z

After the user finishes entering the six values, the corresponding two points in shema are updated.

Lines can also be deleted.

BrisiLiniju() removes a selected line by shifting all subsequent line endpoints one position upward in the array.

Thus the geometry is editable without rebuilding the entire model.


24. Saving

The method:

PripremiStringZaSnimanje()

reconstructs the CSV representation from the internal shema array.

The resulting format is again:

X1,Y1,Z1,1,X2,Y2,Z2

SnimiTekstFajl() writes the result to:

ESFigure.csv

using LibGDX's external file system.

The actual Android-specific handling of external storage is partly abstracted behind the platform integration and is not included in the uploaded source.


25. Built-in Objects

The application also contains predefined geometric objects.

For example:

  • dodecahedron;

  • tetrahedron;

  • octahedron;

  • icosahedron.

They are loaded from CSV resources such as:

Dodecaedar.csv
Tetraedar.csv
Oktaedar.csv
Ikosaedar.csv

A built-in polyhedron and a user-created CSV object ultimately become the same internal structure:

shema[][]

and go through the same transformation pipeline.


26. Why the Application Looks Like a 3D Engine

Although the actual drawing command is only:

shapeRenderer.line(...)

the application behaves like a small 3D engine because it implements the essential stages itself:

                3D MODEL
                   │
                   ▼
          coordinate storage
                   │
                   ▼
             translation
          (centre at origin)
                   │
                   ▼
              rotation X
                   │
                   ▼
              rotation Y
                   │
                   ▼
              rotation Z
                   │
                   ▼
            orthographic view
                   │
                   ▼
            2D screen position
                   │
                   ▼
          ShapeRenderer.line()

The important point is that LibGDX is primarily being used as the application framework and 2D drawing layer. The actual wireframe 3D mathematics was implemented manually.


27. Architecture Summary

The most important classes can be viewed as follows:

                  Android application
                         │
                         ▼
                    easysketch
                         │
                         ▼
                      TriDim
                  ┌──────┼───────┐
                  │      │       │
                  ▼      ▼       ▼
              gestures sensors  files
                  │      │       │
                  └──────┼───────┘
                         ▼
                      shema
                  3D line segments
                         │
                         ▼
                Grafika3Dracun
                         │
          ┌──────────────┼──────────────┐
          ▼              ▼              ▼
      translate       rotate        projection
          │              │              │
          └──────────────┼──────────────┘
                         ▼
                   2D coordinates
                         │
                         ▼
                 ShapeRenderer
                         │
                         ▼
                      screen

28. Important Design Characteristics

The implementation has several characteristics worth preserving if the application is ever modernized.

No polygon mesh is required

The model is purely a set of lines.

No OpenGL 3D mesh is required

The application performs its own transformations and uses ShapeRenderer only for the final lines.

Rotation is mathematically independent of the UI

Touch, accelerometer, and device orientation do not directly rotate the geometry.

They only modify:

alfa
beta
gama

The same renderer then handles all three cases.

Zoom is independent of rotation

zumiraj changes the scale before the 3D transformation.

Movement is screen-space

PrviX and PrviY move the final projected image rather than changing the model coordinates.

This separation is one of the cleaner aspects of the design.



Matrix Multiplication

The 3D calculations in Easy Sketch are based on matrix multiplication. Although the mathematics is simple, understanding it makes the implementation in Grafika3Dracun much easier to follow.

A 3D point can be represented as a column vector:




The additional 1 is used because the application uses homogeneous coordinates. This allows translation, rotation, and other transformations to be represented using matrices.

Suppose we have a transformation matrix:




The transformed point is obtained by multiplying the matrix by the point vector:

The individual values are calculated by multiplying each row of the matrix by the column vector:



and:

w′=mx+ny+oz+p

In Easy Sketch, the last coordinate normally remains 1.

Why use a fourth coordinate?

Normally, a 3D point only needs three coordinates:

(x,y,z)

However, translation cannot be represented by a simple 3×3 rotation/scaling matrix. By adding a fourth coordinate:

(x,y,z,1)

translation can also be represented as a matrix operation.

For example, to move a point by tx, ty,tz​:



This is exactly the principle used by the translacija() method.


Deriving the Rotation Transformations

The rotation matrices used by Easy Sketch can be derived from ordinary two-dimensional trigonometry.

2D Rotation

Consider a point at distance r from the origin:

If the point is rotated by an angle θ, its new angle is:

φ+θ
Therefore:
x′=rcos(φ+θ)
y′=rsin(φ+θ)
Using the angle-sum identities:
cos(φ+θ)=cosφcosθ−sinφsinθ
and:
sin(φ+θ)=sinφcosθ+cosφsinθ
We obtain:
This can be written as a matrix:


This simple 2D rotation is the basis for the 3D rotation matrices.


Rotation Around the X Axis

When rotating a 3D point around the X axis, the X coordinate does not change.

The Y and Z coordinates form a 2D plane and are rotated within that plane.

Therefore:

 
 

The corresponding homogeneous transformation matrix is:


This is the mathematical basis of RotacijaX().


Rotation Around the Y Axis

For rotation around the Y axis, the Y coordinate remains unchanged.

The X and Z coordinates rotate in their plane:

 
 

The transformation matrix is:





This corresponds to RotacijaY().


Rotation Around the Z Axis

For rotation around the Z axis, Z remains unchanged.

The X and Y coordinates form the rotating 2D plane:

 

The matrix is:




This corresponds to RotacijaZ().


Combining Rotations

The really important part is that several transformations can be applied one after another.

For example:

then:

and finally:

which can be written as:

This is essentially what Easy Sketch does in ProjekcijaXY():

Point
  ↓
Rotation X
  ↓
Rotation Y
  ↓
Rotation Z
  ↓
2D projection

The order of the rotations is important.

In general:

because matrix multiplication is not commutative.

This is one of the fundamental concepts in 3D graphics: rotating around X, then Y, then Z does not produce the same result as rotating around Z, then Y, then X.


The complete transformation of a point in Easy Sketch can therefore be understood as:




Conceptually:

Original CSV coordinate
↓
Move object centre to origin
↓
Scale
↓
Rotate around X
↓
Rotate around Y
↓
Rotate around Z
↓
Project 3D → 2D
↓
Move to screen position
↓
ShapeRenderer.line()


Java code snippets:

Mathematical transformations:


package com.easysketch.game;

import com.badlogic.gdx.math.MathUtils;


public class Grafika3Dracun {

    public float x=0;
    public float y=0;
    public float z=0;


    // mnozenje matrice a i b
    public void MnoziMatrice(float[] a, float[][] b) {
        int i;
        int j;
        float c[];
        c = new float[5];
        for (i = 1; i <= 4; i++) {
            c[i] = 0;
            for (j = 1; j <= 4; j++)
                c[i] = c[i] + a[j] * b[j][i];
        }

        for (i = 1; i <= 4; i++)
            a[i] = c[i];
    }

    public void translacija(float x1, float y1, float z1, float tx, float ty, float tz) {
        float a[];//(4) As Double
        float b[][];//(4, 4) As Double
        a = new float[5];
        b = new float[5][5];
        a[1] = x1;
        a[2] = y1;
        a[3] = z1;
        a[4] = 1;
        b[1][1] = 1;
        b[2][2] = 1;
        b[3][3] = 1;
        b[4][4] = 1;
        b[4][1] = tx;
        b[4][2] = ty;
        b[4][3] = tz;

        b[1][2] = 0;
        b[1][3] = 0;
        b[1][4] = 0;
        b[2][1] = 0;
        b[2][3] = 0;
        b[2][4] = 0;
        b[3][1] = 0;
        b[3][2] = 0;
        b[3][4] = 0;

        MnoziMatrice(a, b);
        x = a[1];
        y = a[2];
        z = a[3];
    }


    public void RotacijaX(float x1, float y1, float z1, float alfa) {
        float a[];//(4) As Double
        float b[][];//(4, 4) As Double
        a = new float[5];
        b = new float[5][5];

        a[1] = x1;
        a[2] = y1;
        a[3] = z1;
        a[4] = 1;

        b[1][1] = 1;
        b[2][2] = MathUtils.cos(alfa);
        b[3][3] = MathUtils.cos(alfa);
        b[2][3] = MathUtils.sin(alfa);
        b[3][2] = -MathUtils.sin(alfa);
        b[4][4] = 1;

        b[1][2] = 0;
        b[1][3] = 0;
        b[1][4] = 0;
        b[2][1] = 0;
        b[2][4] = 0;
        b[3][1] = 0;
        b[3][4] = 0;
        b[4][1] = 0;
        b[4][2] = 0;
        b[4][3] = 0;

        MnoziMatrice(a, b);

        x = a[1];
        y = a[2];
        z = a[3];
    }


    public void RotacijaY(float x1, float y1, float z1, float alfa) {
        float a[];//(4) As Double
        float b[][];//(4, 4) As Double
        a = new float[5];
        b = new float[5][5];

        a[1] = x1;
        a[2] = y1;
        a[3] = z1;
        a[4] = 1;

        b[2][2] = 1;
        b[1][1] = MathUtils.cos(alfa);
        b[3][3] = MathUtils.cos(alfa);
        b[3][1] = MathUtils.sin(alfa);
        b[1][3] = -MathUtils.sin(alfa);
        b[4][4] = 1;


        b[1][2] = 0;
        b[1][4] = 0;

        b[2][1] = 0;
        b[2][3] = 0;
        b[2][4] = 0;

        b[3][2] = 0;
        b[3][4] = 0;

        b[4][1] = 0;
        b[4][2] = 0;
        b[4][3] = 0;

        MnoziMatrice(a, b);

        x = a[1];
        y = a[2];
        z = a[3];
    }


    public void RotacijaZ(float x1, float y1, float z1, float alfa) {
        float a[];//(4) As Double
        float b[][];//(4, 4) As Double
        a = new float[5];
        b = new float[5][5];

        a[1] = x1;
        a[2] = y1;
        a[3] = z1;
        a[4] = 1;

        b[3][3] = 1;
        b[1][1] = MathUtils.cos(alfa);
        b[2][2] = MathUtils.cos(alfa);
        b[1][2] = MathUtils.sin(alfa);
        b[2][1] = -MathUtils.sin(alfa);
        b[4][4] = 1;


        b[1][3] = 0;
        b[1][4] = 0;

        b[2][3] = 0;
        b[2][4] = 0;

        b[3][1] = 0;
        b[3][2] = 0;
        b[3][4] = 0;

        b[4][1] = 0;
        b[4][2] = 0;
        b[4][3] = 0;

        MnoziMatrice(a, b);

        x = a[1];
        y = a[2];
        z = a[3];
    }

    public void ProjekcijaXY(float x1, float y1, float z1, float alfa, float beta, float gama)
    {

    RotacijaX(x1, y1, z1, alfa);
    RotacijaY(x, y, z, beta);
    RotacijaZ(x, y, z, gama);

    }


}

Main Java Code:

package com.easysketch.screen;



        import com.badlogic.gdx.ApplicationListener;
        import com.badlogic.gdx.Input;
        import com.badlogic.gdx.files.FileHandle;
        import com.badlogic.gdx.graphics.Color;

        import com.badlogic.gdx.graphics.OrthographicCamera;
        import com.badlogic.gdx.graphics.Pixmap;
        import com.badlogic.gdx.graphics.PixmapIO;
        import com.badlogic.gdx.graphics.glutils.FrameBuffer;
        import com.badlogic.gdx.graphics.glutils.ShapeRenderer;


        import com.badlogic.gdx.Gdx;
        import com.badlogic.gdx.Preferences;
        import com.badlogic.gdx.graphics.GL20;
        import com.badlogic.gdx.graphics.Texture;
        import com.badlogic.gdx.graphics.g2d.Sprite;
        import com.badlogic.gdx.graphics.g2d.SpriteBatch;
        import com.badlogic.gdx.graphics.g2d.TextureRegion;

        import com.badlogic.gdx.input.GestureDetector;
        import com.badlogic.gdx.input.GestureDetector.GestureListener;


        import com.badlogic.gdx.math.MathUtils;
        import com.badlogic.gdx.math.Vector2;

        import com.badlogic.gdx.utils.ScreenUtils;
        import com.easysketch.camera.OrthoCamera;

        import com.easysketch.game.Grafika3Dracun;
        import com.easysketch.game.easysketch;
        import com.easysketch.game.texturemanager;

        import java.io.IOException;
        import java.nio.ByteBuffer;





public class TriDim extends screen implements ApplicationListener {






    private int MaxLista=5; // max proj stavki na listi u galeriji
    private int ListaPozicija =0; // trenutna pozicija u galeriji
    private String [][] ListaImenaStr;
    private int ListaBrStavki=0;
    private String ListaImenaGalerija="";//  Galerija za koju je izvucena lista imena

    private int CitajListu=0;
    private String ListaImena="";
    private String IzborGalerija="";
    private int IscrtavanjeSlike=1;
    private int MeniGalerija=0;



    private boolean compassAvail=false;
    private float accelX = 0;
    private float accelY = 0;
    private int LinijaSelektovana=0;
    private int LinijaPomeraj=0;
    private int LinijaBr=0;
    private int i0;
    private int SakrijFullscr=0;
    private int KeyPadX=1; // tastatura
    private int KeyPadY=390;
    private float KeyPadProziran=0;
    private int Znak=1;
    private String TekstR1="0";
    private String TekstR2="0";
    private String TekstR3="0";
    private int R1=0;
    private int R2=0;
    private int R3=0;
    private String TekstR4="0";
    private String TekstR5="0";
    private String TekstR6="0";
    private int R4=0;
    private int R5=0;
    private int R6=0;

    private int Radni=1;

    private int Galerija=1; // oznacava koju smo slikicu preuzeli iz galerije - kocku, dodekaedar...
    private float [] BrojacKlik;
    private String Tekst="";
    private int TekstBroj=0;
    private int KeupadOn=0;
    private int Pomoc=0;
    private int BrojacSakrij=-100;
    private int Projections=1;
    private int Osa=1;
    private float speed=0.001f;
    private int Sakrij=0;
    private int BrojacPoruka=200;
    private String Poruka="";
    private float PocetakBrojac=180f;
    private static TextureRegion Ikona;

    private int SharePict=0;
    private int SnimiSliku=0;
    OrthographicCamera camera1;
    CameraController controller;
    GestureDetector gestureDetector;
    private float CentarX=0;
    private float CentarY=0;
    private float CentarZ=0;
    private float alfa;//180f*MathUtils.PI;
    private float beta;//180f*MathUtils.PI;
    private float gama ;//180f*MathUtils.PI;

    private int AktivnaVerzija= 0; // koju skicu prikazujemo?
    private int Grid = 1;
    private int RotirajX = 1;
    private int RotirajY = 1;
    private int RotirajZ = 1;


    private int FixRotacija = 0;

    private float zumirajU=1;
    private float PrviXU = 0;
    private float PrviYU = 0;


    private float zumiraj=1;
    private float centarX=0;
    private float centarY=0;
    private Grafika3Dracun G3DR;
    private int Ulaz = 1;
    private int Crtaj = 0;

    private float[][][] shema;

    private float vreme = 0;
    private int okreci = 0;
    private float maxim = 200; // uvecanje
    private int [] brlinija ;

    private float FunkTalas[][];
    private int demo=0;
    private int width;
    private int height;
    private ShapeRenderer shapeRenderer;

    private int Status = 0;
    int i2;

    private float PrviX = 0;
    private float PrviY = 0;

    private int LinijaPravac=0;
    private float TouchX = 0;
    private float TouchY = 0;

    private float PrviX1 = 0;
    private float PrviY1 = 0;
    private float PrviX2 = 0;
    private float PrviY2 = 0;


    private float SlajdY = 1;
    private float Slajd2Y = 1;
    private float Slajd3Y = 1;

    private float VelicinaS = 1;
    private float Velicina2S = 1;
    private float Velicina3S = 1;

    private float Fejd = 1f;

    private static TextureRegion Exit2;
    private TextureRegion pixmaptexR;

    private static TextureRegion Slajd;
    private static TextureRegion SlajdDugme;


    private static TextureRegion Levo;
    private static TextureRegion Desno;
    private static TextureRegion DugmeDugacko;
    private static TextureRegion Compass;

    private static TextureRegion DugmeKlik;

    private static TextureRegion KeypadMali;
    private static TextureRegion Keypad;

    private static TextureRegion Gyro;
    private static TextureRegion Uputstvo;
    private static TextureRegion Klik;
    private static TextureRegion New;
    private static TextureRegion Gumica;

    private static TextureRegion Brojevi;
    private static TextureRegion Help;
    private static TextureRegion Share;
    private static TextureRegion Pozadina;
    private static TextureRegion Kocka;
    private static TextureRegion Povecaj;
    private static TextureRegion Smanji;
    private static TextureRegion OpenFile;
    private static TextureRegion SaveFile;

    private static TextureRegion Dugme;
    private static TextureRegion FullScr;
    private static TextureRegion Ose;
    private static TextureRegion GridT;
    private static TextureRegion Projekcija;
    private static TextureRegion RotacijaX;
    private static TextureRegion RotacijaY;
    private static TextureRegion RotacijaZ;
    private static TextureRegion Centar;
    private static TextureRegion Move;
    private static TextureRegion Rotate;



    private OrthoCamera camera;
    private long LastFire = 0;


    private int dodirnut = 0;

    private float svetlo = 0;
    private float rot = 200f;
    private int Brisiekran = 0;







    private float scrollTimer = 0f;
    private int Brojackraj = 0;



    private float m_fboScaler = 1f;
    private boolean m_fboEnabled = true;
    private FrameBuffer m_fbo = null;
    private TextureRegion m_fboRegion = null;


    private boolean m_fboEnabled1 = true;
    private FrameBuffer m_fbo1 = null;
    private TextureRegion m_fboRegion1 = null;

    private int Gwidth; // stvarna sirina ekrana
    private int Gheight;// stvarna visina ekrana




    private Texture screenClearTexture;
    private Sprite screenClearSprite;



    class CameraController implements GestureListener {
        float velX, velY;
        boolean flinging = false;
        float initialScale = 1;
        float initialScaleU = 1;

        public boolean touchDown (float x, float y, int pointer, int button) {

            initialScale = zumiraj;
            initialScaleU = zumirajU;
            return false;
        }

        public void pinchStop()
        {
            return ;
        }

        @Override
        public boolean tap (float x, float y, int count, int button) {

            return false;
        }

        @Override
        public boolean longPress (float x, float y) {

            return false;
        }

        @Override
        public boolean fling (float velocityX, float velocityY, int button) {

            return false;
        }

        @Override
        public boolean pan (float x, float y, float deltaX, float deltaY) {

            if (KeupadOn == 1 && Pomoc==0)// ako unosimo rucno - pomeranje liste
            {
                if(LinijaPravac==0)
                    LinijaPravac=(int)Math.signum(deltaY);

            }
            else
            if(Pomoc==1)// ovo je za uputstvo
            {
                PrviXU -= deltaX / 2;
                PrviYU -= deltaY / 2;
                if (PrviXU > 1200) PrviXU = 1200;
                if (PrviXU < 0) PrviXU = 0;
                if (PrviYU > 700) PrviYU = 700;
                if (PrviYU < -400) PrviYU = -400;

            }
            else
            {
            if(FixRotacija==0)// move
            {
                PrviX+=deltaX/2;
                PrviY-=deltaY/2;
                if (PrviX > 1200) PrviX = 1200;
                if (PrviX < 0) PrviX = 0;
                if (PrviY > 700) PrviY = 700;
                if (PrviY < 0) PrviY = 0;
            }
            if (FixRotacija == 1)//rotate
            {
                SlajdY += deltaX/ 600f;
                if (SlajdY > 1200) SlajdY = 1200;
                VelicinaS = SlajdY;
                Slajd2Y += deltaY/ 600f;
                if (Slajd2Y > 1200) Slajd2Y = 1200;
                Velicina2S= Slajd2Y;
            }

            }

            return false;
        }

        @Override
        public boolean panStop (float x, float y, int pointer, int button) {

            return false;
        }

        @Override
        public boolean zoom (float originalDistance, float currentDistance) {
            float ratio =  currentDistance/originalDistance ;
            if(Pomoc==0) {
                zumiraj = initialScale * ratio;


                if (zumiraj < .02f) zumiraj = .02f;

                if (zumiraj > 800f) zumiraj = 800f;
            } else
            {

            zumirajU= initialScaleU * ratio;

            if(zumirajU<1f)zumirajU=1f;

            if(zumirajU>4f)zumirajU=4f;
            }

            return false;
        }

        @Override
        public boolean pinch (Vector2 initialFirstPointer, Vector2 initialSecondPointer, Vector2 firstPointer, Vector2 secondPointer) {
            return false;
        }

        public void update () {

        }


    }

    public void ResetujVelicinuEkrana()
    {
        Gwidth=Gdx.graphics.getWidth(); // stvarna sirina ekrana
        Gheight=Gdx.graphics.getHeight(); // stvarna visinaekrana
    }

    @Override
    public void create() {

        ResetujVelicinuEkrana();


        compassAvail = Gdx.input.isPeripheralAvailable(Input.Peripheral.Compass);


        ListaImenaStr=new String[10][2]; // par - naziv skice, key
        FunkTalas= new float[40][40];

        shema = new float[4][1000][5];
        brlinija= new int[4];

        G3DR = new Grafika3Dracun();

        int i;
        shapeRenderer = new ShapeRenderer();




        camera = new OrthoCamera();
        camera.resize();
        LastFire = System.currentTimeMillis();







        Levo=new TextureRegion(texturemanager.LEVO, 0,0, texturemanager.LEVO.getWidth(),
                texturemanager.LEVO.getHeight());
        Desno=new TextureRegion(texturemanager.DESNO, 0,0, texturemanager.DESNO.getWidth(),
                texturemanager.DESNO.getHeight());

        DugmeDugacko=new TextureRegion(texturemanager.DUGMEDUGACKO, 0,0, texturemanager.DUGMEDUGACKO.getWidth(),
                texturemanager.DUGMEDUGACKO.getHeight());

        Compass=new TextureRegion(texturemanager.COMPASS, 0,0, texturemanager.COMPASS.getWidth(),
                texturemanager.COMPASS.getHeight());

        Gyro=new TextureRegion(texturemanager.GYRO, 0,0, texturemanager.GYRO.getWidth(),
                texturemanager.GYRO.getHeight());
        Gumica=new TextureRegion(texturemanager.GUMICA, 0,0, texturemanager.GUMICA.getWidth(),
                texturemanager.GUMICA.getHeight());

        Brojevi=new TextureRegion(texturemanager.BROJEVI, 0,0, texturemanager.BROJEVI.getWidth(),
                texturemanager.BROJEVI.getHeight());

        DugmeKlik=new TextureRegion(texturemanager.DUGMEKLIK, 0,0, texturemanager.DUGMEKLIK.getWidth(),
                texturemanager.DUGMEKLIK.getHeight());
        Klik=new TextureRegion(texturemanager.KLIK, 0,0, texturemanager.KLIK.getWidth(),
                texturemanager.KLIK.getHeight());
        New=new TextureRegion(texturemanager.NEW, 0,0, texturemanager.NEW.getWidth(),
                texturemanager.NEW.getHeight());

        Keypad=new TextureRegion(texturemanager.KEYPAD, 0,0, texturemanager.KEYPAD.getWidth(),
                texturemanager.KEYPAD.getHeight());
        KeypadMali=new TextureRegion(texturemanager.KEYPADMALI, 0,0, texturemanager.KEYPADMALI.getWidth(),
                texturemanager.KEYPADMALI.getHeight());

        Uputstvo=new TextureRegion(texturemanager.UPUTSTVO, 0,0, texturemanager.UPUTSTVO.getWidth(),
                texturemanager.UPUTSTVO.getHeight());

        Help=new TextureRegion(texturemanager.HELP, 0,0, texturemanager.HELP.getWidth(),
                texturemanager.HELP.getHeight());
        Share=new TextureRegion(texturemanager.SHARE, 0,0, texturemanager.SHARE.getWidth(),
                texturemanager.SHARE.getHeight());

        Kocka=new TextureRegion(texturemanager.KOCKA, 0,0, texturemanager.KOCKA.getWidth(),
                texturemanager.KOCKA.getHeight());
        Povecaj=new TextureRegion(texturemanager.POVECAJ, 0,0, texturemanager.POVECAJ.getWidth(),
                texturemanager.POVECAJ.getHeight());
        Smanji=new TextureRegion(texturemanager.SMANJI, 0,0, texturemanager.SMANJI.getWidth(),
                texturemanager.SMANJI.getHeight());
        OpenFile=new TextureRegion(texturemanager.OPENFILE, 0,0, texturemanager.OPENFILE.getWidth(),
                texturemanager.OPENFILE.getHeight());
        SaveFile=new TextureRegion(texturemanager.SAVEFILE, 0,0, texturemanager.SAVEFILE.getWidth(),
                texturemanager.SAVEFILE.getHeight());
        Pozadina=new TextureRegion(texturemanager.POZADINA, 0,0, texturemanager.POZADINA.getWidth(),
                texturemanager.POZADINA.getHeight());


        Dugme=new TextureRegion(texturemanager.DUGME, 0,0, texturemanager.DUGME.getWidth(),
                texturemanager.DUGME.getHeight());
        FullScr=new TextureRegion(texturemanager.FULLSCR, 0,0, texturemanager.FULLSCR.getWidth(),
                texturemanager.FULLSCR.getHeight());
        Ose=new TextureRegion(texturemanager.OSE, 0,0, texturemanager.OSE.getWidth(),
                texturemanager.OSE.getHeight());
        GridT=new TextureRegion(texturemanager.GRID, 0,0, texturemanager.GRID.getWidth(),
                texturemanager.GRID.getHeight());
        Projekcija=new TextureRegion(texturemanager.PROJEKCIJA, 0,0, texturemanager.PROJEKCIJA.getWidth(),
                texturemanager.PROJEKCIJA.getHeight());
        RotacijaX=new TextureRegion(texturemanager.ROTACIJAX, 0,0, texturemanager.ROTACIJAX.getWidth(),
                texturemanager.ROTACIJAX.getHeight());
        RotacijaY=new TextureRegion(texturemanager.ROTACIJAY, 0,0, texturemanager.ROTACIJAY.getWidth(),
                texturemanager.ROTACIJAY.getHeight());
        RotacijaZ=new TextureRegion(texturemanager.ROTACIJAZ, 0,0, texturemanager.ROTACIJAZ.getWidth(),
                texturemanager.ROTACIJAX.getHeight());
        Centar=new TextureRegion(texturemanager.CENTAR, 0,0, texturemanager.CENTAR.getWidth(),
                texturemanager.CENTAR.getHeight());
        Move=new TextureRegion(texturemanager.MOVE, 0,0, texturemanager.MOVE.getWidth(),
                texturemanager.MOVE.getHeight());
        Rotate=new TextureRegion(texturemanager.ROTATE, 0,0, texturemanager.ROTATE.getWidth(),
                texturemanager.ROTATE.getHeight());




        BrojacKlik=new float[100];
        for(i0=0;i0<100;i0++)
            BrojacKlik[i0]=.9f;

        Ikona=new TextureRegion(texturemanager.IKONA, 0,0, texturemanager.IKONA.getWidth(),
                texturemanager.IKONA.getHeight());


        Status = 1;
        svetlo = 0;

        width = easysketch.width;
        height = easysketch.height ;

        Pixmap screenClearPixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);
        screenClearPixmap.setColor(Color.rgba8888(0f, 0f, 0f, 0.01f));
        screenClearPixmap.fill();

        screenClearTexture = new Texture(screenClearPixmap);

        screenClearPixmap.dispose();


        Brisiekran = 1;




        controller = new CameraController();
        gestureDetector = new GestureDetector(20, 0.5f, 2, 0.15f, controller);
        Gdx.input.setInputProcessor(gestureDetector);
    }











    public void render() {}

    @Override
    public void render(SpriteBatch sb) {




        controller.update();

        if(vreme++>100000)vreme=0;

        if (m_fboEnabled1)      // enable or disable the supersampling
        {
            if (m_fbo1 == null) {



                m_fbo1 = new FrameBuffer(Pixmap.Format.RGBA8888, width, height, false);
                m_fboRegion1 = new TextureRegion(m_fbo1.getColorBufferTexture());
                m_fboRegion1.flip(false, true);
            }

            m_fbo1.begin();
            Gdx.gl.glClearColor(.0f, .0f, 0f, 0f);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);


            sb.getProjectionMatrix().setToOrtho2D(0, 0, width, height);
            sb.begin();
            easysketch.Mojfont1.setColor(1,1,1,1f);




            int spid= (int) (speed *1000);
            String str2="S: "+ spid;

            if(PocetakBrojac>0)
            {
                PocetakBrojac-=2;
                Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
                Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
                if (PocetakBrojac < 150)
                {
                    sb.setColor(new Color(1, 1, 1, 1f / 150f * PocetakBrojac));
                    sb.draw(Ikona, easysketch.width / 2 - texturemanager.IKONA.getWidth() / 2, easysketch.height / 2 - texturemanager.IKONA.getHeight() / 2);
                }
            }
            else

                {
                    if (Sakrij == 0) {
                        if (BrojacSakrij < 0)
                            BrojacSakrij += 8;
                        else
                            BrojacSakrij = 0;
                        if(SakrijFullscr==0)
                        {
                            sb.draw(Dugme, 1, 690);
                            sb.draw(FullScr, 1, 690);
                        }
                    } else {
                        if (BrojacSakrij > -400)
                            BrojacSakrij -= 8;
                        else
                            BrojacSakrij = -400;
                        sb.setColor(1, 1, 1, .4f);
                        if(SakrijFullscr==0)
                        {
                            sb.draw(Dugme, 1, 690);
                            sb.draw(FullScr, 1, 690);
                        }
                        sb.setColor(1, 1, 1, 1f);
                    }
                    if(BrojacKlik[20]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[20]));
                        sb.draw(DugmeKlik, 1, 690);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[20] -= .02f;
                    }

                    int BrojacSakrij1 = BrojacSakrij;
                    if (BrojacSakrij1 > 0) BrojacSakrij1 = 0;

                    sb.setColor(1, 1, 1, 1f + BrojacSakrij1 / 400f);
                    sb.draw(Pozadina, 140, 76);
                    sb.setColor(1, 1, 1, 1f);


                    sb.setColor(1, 1, 1, .9f);
                    if(Pomoc==1)
                        sb.draw(texturemanager.UPUTSTVO, 160, 92,0,0,810*zumirajU,658*zumirajU,1,1,0f,(int) PrviXU,(int) PrviYU,810,658,false,false);





                    sb.draw(Dugme, 1 + BrojacSakrij1, 623);

                    if(BrojacKlik[21]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[21]));
                        sb.draw(DugmeKlik,1 + BrojacSakrij1, 623);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[21] -= .02f;
                    }

                    if (Osa!=1) sb.setColor(1, 1, 1, .7f);
                    sb.draw(Ose, 1 + BrojacSakrij1, 623);

                    sb.setColor(1, 1, 1, 1f);




                    if (BrojacSakrij1 > 0) BrojacSakrij1 = 0;

                    sb.draw(Dugme, 1 + BrojacSakrij1, 556);
                    if(BrojacKlik[22]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[22]));
                        sb.draw(DugmeKlik,1 + BrojacSakrij1, 556);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[22] -= .02f;
                    }
                    if (Grid!=1) sb.setColor(1, 1, 1, .7f);
                    sb.draw(GridT, 1 + BrojacSakrij1, 556);
                    sb.setColor(1, 1, 1, 1f);



                    if (BrojacSakrij1 > 0) BrojacSakrij1 = 0;

                    sb.draw(Dugme, 1 + BrojacSakrij1, 489);
                    if(BrojacKlik[23]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[23]));
                        sb.draw(DugmeKlik,1 + BrojacSakrij1, 489);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[23] -= .02f;
                    }
                    if (Projections != 1) sb.setColor(1, 1, 1, .7f);
                    sb.draw(Projekcija, 1 + BrojacSakrij1, 489);
                    sb.setColor(1, 1, 1, 1f);


                    if (BrojacSakrij1 > 0) BrojacSakrij1 = 0;

                    sb.draw(Dugme, 1 + BrojacSakrij1, 422);
                    if(BrojacKlik[24]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[24]));
                        sb.draw(DugmeKlik,1 + BrojacSakrij1, 422);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[24] -= .02f;
                    }

                    if (RotirajX != 1) sb.setColor(1, 1, 1, .7f);
                    sb.draw(RotacijaX, 1 + BrojacSakrij1, 422);
                    sb.setColor(1, 1, 1, 1f);


                    if (BrojacSakrij1 > 0) BrojacSakrij1 = 0;

                    sb.draw(Dugme, 1 + BrojacSakrij1, 355);
                    if(BrojacKlik[25]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[25]));
                        sb.draw(DugmeKlik,1 + BrojacSakrij1, 355);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[25] -= .02f;
                    }

                    if (RotirajY != 1) sb.setColor(1, 1, 1, .7f);
                    sb.draw(RotacijaY, 1 + BrojacSakrij1, 355);
                    sb.setColor(1, 1, 1, 1f);


                    if (BrojacSakrij1 > 0) BrojacSakrij1 = 0;

                    sb.draw(Dugme, 1 + BrojacSakrij1, 288);
                    if(BrojacKlik[26]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[26]));
                        sb.draw(DugmeKlik,1 + BrojacSakrij1,288);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[26] -= .02f;
                    }
                    if (RotirajZ != 1) sb.setColor(1, 1, 1, .7f);
                    sb.draw(RotacijaZ, 1 + BrojacSakrij1, 288);
                    sb.setColor(1, 1, 1, 1f);


                    if (BrojacSakrij1 > 0) BrojacSakrij1 = 0;

                    sb.draw(Dugme, 1 + BrojacSakrij1, 221);
                    if(BrojacKlik[27]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[27]));
                        sb.draw(DugmeKlik,1 + BrojacSakrij1,221);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[27] -= .02f;
                    }
                    sb.draw(Centar, 1 + BrojacSakrij1, 221);


                    if (BrojacSakrij1 > 0) BrojacSakrij1 = 0;

                    sb.draw(Dugme, 1 + BrojacSakrij1, 154);
                    if(BrojacKlik[28]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[28]));
                        sb.draw(DugmeKlik,1 + BrojacSakrij1,154);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[28] -= .02f;
                    }
                    sb.draw(Povecaj, 1 + BrojacSakrij1, 154);


                    if (BrojacSakrij1 > 0) BrojacSakrij1 = 0;

                    sb.draw(Dugme, 1 + BrojacSakrij1, 87);
                    if(BrojacKlik[29]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[29]));
                        sb.draw(DugmeKlik,1 + BrojacSakrij1,87);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[29] -= .02f;
                    }
                    sb.draw(Smanji, 1 + BrojacSakrij1, 87);




                    BrojacSakrij1 = BrojacSakrij + 10;
                    if (BrojacSakrij1 > 0) BrojacSakrij1 = 0;


                    sb.draw(Dugme, 1, 1 + BrojacSakrij1);
                    if(BrojacKlik[30]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[30]));
                        sb.draw(DugmeKlik,1,1 + BrojacSakrij1);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[30] -= .02f;
                    }

                    if (FixRotacija == 0)
                        sb.draw(Move, 1, 1 + BrojacSakrij1);
                    if (FixRotacija == 1)
                        sb.draw(Rotate, 1, 1 + BrojacSakrij1);
                    if (FixRotacija == 2)
                        sb.draw(Gyro, 1, 1 + BrojacSakrij1);
                    if (FixRotacija == 3)//compass
                        sb.draw(Compass, 1, 1 + BrojacSakrij1);

                    if (BrojacSakrij1 > 0) BrojacSakrij1 = 0;

                    sb.draw(Dugme, 140, 1 + BrojacSakrij1);
                    if(BrojacKlik[31]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[31]));
                        sb.draw(DugmeKlik,140,1 + BrojacSakrij1);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[31] -= .02f;
                    }

                    sb.draw(Kocka, 140, 1 + BrojacSakrij1);


                    if (BrojacSakrij1 > 0) BrojacSakrij1 = 0;

                    if(KeupadOn==1)
                        sb.draw(Dugme, 280, 1 );
                    else
                        sb.draw(Dugme, 280, 1 + BrojacSakrij1);

                    if(BrojacKlik[32]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[32]));
                        if(KeupadOn==1)
                            sb.draw(DugmeKlik,280,1);
                        else
                            sb.draw(DugmeKlik,280,1 + BrojacSakrij1);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[32] -= .02f;
                    }
                    if(KeupadOn==1)
                        sb.draw(OpenFile, 280, 1 );
                    else
                        sb.draw(OpenFile, 280, 1 + BrojacSakrij1);


                    if (BrojacSakrij1 > 0) BrojacSakrij1 = 0;

                    if(KeupadOn==1)
                        sb.draw(Dugme, 420, 1 );
                    else
                        sb.draw(Dugme, 420, 1 + BrojacSakrij1);
                    if(BrojacKlik[33]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[33]));
                        if(KeupadOn==1)
                            sb.draw(DugmeKlik,420,1);
                        else
                            sb.draw(DugmeKlik,420,1 + BrojacSakrij1);

                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[33] -= .02f;
                    }
                    if(KeupadOn==1)
                        sb.draw(SaveFile, 420, 1 );
                    else
                        sb.draw(SaveFile, 420, 1 + BrojacSakrij1);

                    if(KeupadOn==1)
                        sb.draw(Dugme, 560, 1);
                    else
                        sb.draw(Dugme, 560, 1 + BrojacSakrij1);
                    if(BrojacKlik[34]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[34]));
                        if(KeupadOn==1)
                            sb.draw(DugmeKlik,560,1);
                        else
                            sb.draw(DugmeKlik,560,1 + BrojacSakrij1);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[34] -= .02f;
                    }
                    if(KeupadOn==1)
                        sb.draw(New, 560, 1);
                    else
                        sb.draw(Share, 560, 1 + BrojacSakrij1);

                    if(KeupadOn==1)
                        sb.draw(Dugme, 700, 1);
                    else
                        sb.draw(Dugme, 700, 1 + BrojacSakrij1);
                    if(BrojacKlik[35]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[35]));
                        if(KeupadOn==1)
                            sb.draw(DugmeKlik,700,1);
                        else
                            sb.draw(DugmeKlik,700,1 + BrojacSakrij1);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[35] -= .02f;
                    }
                    if(KeupadOn==1)
                        sb.draw(Gumica, 700, 1);
                    else
                        sb.draw(Help, 700, 1 + BrojacSakrij1);

                    if(KeupadOn==1)
                        sb.draw(Dugme, 840, 1 );
                    else
                        sb.draw(Dugme, 840, 1 + BrojacSakrij1);
                    if(BrojacKlik[36]>0)
                    {
                        sb.setColor(new Color(1, 1, 1, BrojacKlik[36]));
                        if(KeupadOn==1)
                            sb.draw(DugmeKlik,840,1);
                        else
                            sb.draw(DugmeKlik,840,1 + BrojacSakrij1);
                        sb.setColor(new Color(1, 1, 1, 1f));
                        BrojacKlik[36] -= .02f;
                    }
                    if(KeupadOn==1)
                    sb.draw(KeypadMali, 840, 1 );
                        else
                    sb.draw(KeypadMali, 840, 1 + BrojacSakrij1);

                    sb.setColor(new Color(1, 1, 1, KeyPadProziran));
                    sb.draw(Keypad, KeyPadX, KeyPadY);
                    sb.setColor(new Color(1, 1, 1, 1f));

                    if (KeupadOn == 1 && Pomoc==0)
                    {

                        if(KeyPadProziran<.9f)KeyPadProziran+=.02;

                        easysketch.Mojfont2.draw(sb, "X", KeyPadX +325+ 100*0, KeyPadY+370);
                        easysketch.Mojfont2.draw(sb, "Y", KeyPadX +325+ 100*1, KeyPadY+370);
                        easysketch.Mojfont2.draw(sb, "Z", KeyPadX +325+ 100*2, KeyPadY+370);
                        easysketch.Mojfont2.draw(sb, "X1", KeyPadX +325+ 100*3, KeyPadY+370);
                        easysketch.Mojfont2.draw(sb, "Y1", KeyPadX +325+ 100*4, KeyPadY+370);
                        easysketch.Mojfont2.draw(sb, "Z1", KeyPadX +325+ 100*5, KeyPadY+370);
                        easysketch.Mojfont2.draw(sb, "Ln", KeyPadX +325+ 100*6, KeyPadY+370);

                        if (LinijaBr == 0 && LinijaPravac==1) LinijaPravac = 0;
                        if (LinijaBr == brlinija[AktivnaVerzija] && LinijaPravac==-1)LinijaPravac = 0;

                        LinijaPomeraj+=LinijaPravac*4;
                        if(LinijaPomeraj==40 || LinijaPomeraj==-40)
                        {

                            LinijaBr -= LinijaPravac;
                            if (LinijaBr < 0) LinijaBr = 0;
                            if (LinijaBr > brlinija[AktivnaVerzija])
                                LinijaBr = brlinija[AktivnaVerzija];
                            LinijaPravac = 0;
                            LinijaPomeraj=0;
                        }
                        for(int ib=LinijaBr;ib<brlinija[AktivnaVerzija] && ib<LinijaBr+15;ib++)
                        {// prikazujemo prvih 6 linija
                            for(int jb=0;jb<3;jb++)
                            {
                                String aa = Integer.toString((int)shema[AktivnaVerzija][ib*2][jb]);
                                if(ib==LinijaSelektovana)
                                {
                                easysketch.Mojfont.draw(sb, aa, KeyPadX +325+ 100*jb, KeyPadY+350 - 40*(ib-LinijaBr+1)-LinijaPomeraj);
                                aa = Integer.toString((int)shema[AktivnaVerzija][ib*2+1][jb]);
                                easysketch.Mojfont.draw(sb, aa, KeyPadX +325+ 100*jb+300, KeyPadY+350 - 40*(ib-LinijaBr+1)-LinijaPomeraj);
                                }
                                else
                                {
                                    easysketch.Mojfont2.draw(sb, aa, KeyPadX +325+ 100*jb, KeyPadY+350 - 40*(ib-LinijaBr+1)-LinijaPomeraj);
                                    aa = Integer.toString((int)shema[AktivnaVerzija][ib*2+1][jb]);
                                    easysketch.Mojfont2.draw(sb, aa, KeyPadX +325+ 100*jb+300, KeyPadY+350 - 40*(ib-LinijaBr+1)-LinijaPomeraj);
                                }
                            }
                            easysketch.Mojfont2.draw(sb, Integer.toString(ib+1), KeyPadX +325+ 100*3+300, KeyPadY+350 - 40*(ib-LinijaBr+1)-LinijaPomeraj);
                        }
                        sb.draw(Brojevi, KeyPadX, KeyPadY-80);
                        sb.draw(Brojevi, KeyPadX, KeyPadY-160);
                        sb.draw(Brojevi, KeyPadX, KeyPadY-240);

                        easysketch.Mojfont.draw(sb, "X", KeyPadX+30, KeyPadY-30);
                        easysketch.Mojfont.draw(sb, "Y", KeyPadX+130, KeyPadY-30);
                        easysketch.Mojfont.draw(sb, "Z", KeyPadX+230, KeyPadY-30);

                        if(Radni==1)
                            easysketch.Mojfont1.draw(sb, Tekst, KeyPadX+20, KeyPadY-110);
                        else
                            easysketch.Mojfont.draw(sb, TekstR1, KeyPadX+20, KeyPadY-110);

                        if(Radni==2)
                            easysketch.Mojfont1.draw(sb, Tekst, KeyPadX+120, KeyPadY-110);
                        else
                            easysketch.Mojfont.draw(sb, TekstR2, KeyPadX+120, KeyPadY-110);

                        if(Radni==3)
                            easysketch.Mojfont1.draw(sb, Tekst, KeyPadX+220, KeyPadY-110);
                        else
                            easysketch.Mojfont.draw(sb, TekstR3, KeyPadX+220, KeyPadY-110);
                        if(Radni==4)
                            easysketch.Mojfont1.draw(sb, Tekst, KeyPadX+20, KeyPadY-190);
                        else
                            easysketch.Mojfont.draw(sb, TekstR4, KeyPadX+20, KeyPadY-190);

                        if(Radni==5)
                            easysketch.Mojfont1.draw(sb, Tekst, KeyPadX+120, KeyPadY-190);
                        else
                            easysketch.Mojfont.draw(sb, TekstR5, KeyPadX+120, KeyPadY-190);

                        if(Radni==6)
                            easysketch.Mojfont1.draw(sb, Tekst, KeyPadX+220, KeyPadY-190);
                        else
                            easysketch.Mojfont.draw(sb, TekstR6, KeyPadX+220, KeyPadY-190);
                            int x0=0;
                            int y0=0;
                            for(i0=0;i0<15;i0++)
                            {
                                if(BrojacKlik[i0]>0)
                                {



                                    sb.setColor(new Color(1, 1, 1, BrojacKlik[i0]));
                                    sb.draw(Klik, KeyPadX+x0, KeyPadY+y0);
                                    sb.setColor(new Color(1, 1, 1, 1f));

                                    BrojacKlik[i0] -= .02f;
                                }
                                x0+=104;
                                    if(x0>104)x0+=3;
                                    if(x0>212)
                                        {
                                            if(y0==0)
                                                y0+=71;
                                            else
                                                y0+=73;
                                            if(y0>210)y0+=3;

                                            x0=0;
                                        }
                            }
                    }
                    else
                    if(KeyPadProziran>0f)KeyPadProziran-=.02;



                    if (BrojacPoruka > 0) {
                        BrojacPoruka--;
                        easysketch.Mojfont.draw(sb, Poruka, 400, 450);
                    }



                }
            sb.end();
            m_fbo1.end();
        }


        if (m_fboEnabled)      // enable or disable the supersampling
        {
            if (m_fbo == null) {



                m_fbo = new FrameBuffer(Pixmap.Format.RGBA8888, width, height, false);
                m_fboRegion = new TextureRegion(m_fbo.getColorBufferTexture());
                m_fboRegion.flip(false, true);
            }

            m_fbo.begin();
        }


        if (dodirnut == 2)
            Fejd -= .01f;
        else
            Fejd = 1;


        sb.getProjectionMatrix().setToOrtho2D(0, 0, width, height); // ovo je reslo problem sklairanja

            Gdx.gl.glClearColor(0, 0, .3f, 1f);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);








        shapeRenderer.getProjectionMatrix().setToOrtho2D(0, 0, width, height);
        shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
        shapeRenderer.setColor(1, 1, 1, 1f);

        if(Pomoc==0 && IscrtavanjeSlike==1) // ako je help na ekranu ne crtamo sliku
        {

            crtajSliku(3);// 3 je verzija za grid - pozivamo u svakom slucaju, a prilikom punjenja


            if (Projections == 1 && KeupadOn == 0)
                crtajSlikuProjekcija(AktivnaVerzija);

            if (demo == 0) {
                crtajSliku(AktivnaVerzija);
            } else
                crtajTalase();
        }



        shapeRenderer.end();


        if (m_fbo != null) {


            m_fbo.end();




            sb.getProjectionMatrix().setToOrtho2D(0, 0, Gwidth, Gheight);
            camera.update();

            sb.begin();

                sb.setColor(new Color(1, 1, 1, 1f));
                sb.draw(m_fboRegion, 0, 0, Gwidth, Gheight);

                if(SnimiSliku==0)
                    sb.draw(m_fboRegion1, 0, 0, Gwidth, Gheight);

            sb.end();

            if(SnimiSliku==1)
            {
                SnimiSliku=0;
                Snimi();
                if(SharePict==1)
                {
                    easysketch.kraj=55;//share






                    SharePict=0;
                }
            }

        }



    }


    @Override
    public void resize(int width, int height) {
        camera.resize();
    }




public void SpremiSeZaCitanjeListe()// ako je menigalerija=13
{
    Preferences prefs = Gdx.app.getPreferences("Putanje");
    prefs.putString("ListaProcitana","0");
    prefs.flush();

    CitajListu=1;// signaliziramo da treba proveravati da li je procitana lista
    easysketch.kraj=70;//ide na citanje liste
    easysketch.IzborGalerija = IzborGalerija;
    IscrtavanjeSlike=0; // ne iscrtavamo sliku
    Sakrij = 1;// ne iscrtavamo sliku
}

    public void BrisiGaleriju()// ako je menigalerija=13
    {
        easysketch.kraj=71;//ide na citanje liste
        easysketch.IzborGalerija = IzborGalerija;
        IscrtavanjeSlike=1; //  iscrtavamo sliku
        Sakrij = 0;//  iscrtavamo sliku
        BrojacPoruka=200;
        Poruka="Sketch deleted from gallery:" + IzborGalerija;
    }
    @Override
    public void update()
    {
        if(easysketch.SnimljenFajl.equals("Uspesno"))
        {
            BrojacPoruka=200;
            Poruka="Saved to download: ESFigure.csv";
            easysketch.SnimljenFajl="";
        }
        if(easysketch.SnimljenFajl.equals("Neuspesno"))
        {
            BrojacPoruka=200;
            Poruka="Failed to save to download: ESFigure.csv";
            easysketch.SnimljenFajl="";
        }

        if(easysketch.OtvorenFajl.equals("Uspesno"))
        {
            BrojacPoruka=200;
            Poruka="Opened successfully download: ESFigure.csv";
            easysketch.OtvorenFajl="";
            ParseFajl(easysketch.ProcitanFajl);
        }

        if(easysketch.OtvorenFajl.equals("Neuspesno"))
        {
            BrojacPoruka=200;
            Poruka="Failed to open file download: ESFigure.csv";
            easysketch.OtvorenFajl="";
        }



        if(easysketch.ResetujVelEkrana==1)
        {
            ResetujVelicinuEkrana(); // ako je sklonjeg oglas
            easysketch.ResetujVelEkrana=0;
        }

    if(easysketch.PoceoCitanjeFIREBASE==2)
    {
        Parse(easysketch.SkicaString);
        zumiraj=easysketch.zumiraj;
        maxim=easysketch.maxim;
        easysketch.PoceoCitanjeFIREBASE=0;
    }

        if(MeniGalerija==22) // bili smo na unosu imena slike, sada proveravamo da li je zavrseno
        {
            Preferences prefs = Gdx.app.getPreferences("Putanje");

            String saved=prefs.getString("FileNameSavedGallery");
            String ImeSkice=prefs.getString("FileNameGallery");
            if(saved.equals("1"))
            {
                easysketch.ImeSkice=ImeSkice;
                easysketch.kraj = 66;// UPISI NA FIREBASE - TEST
            }

        }
        if (MeniGalerija == 13)// citanje galerije
        {
            MeniGalerija = 23; // prikaz liste

            easysketch.IzborGalerija = IzborGalerija;

        }



    if(Gdx.input.isPeripheralAvailable(Input.Peripheral.Accelerometer))
    {
    accelX = Gdx.input.getAccelerometerY();
    accelY = Gdx.input.getAccelerometerX();
    if (FixRotacija == 3)//rotate COMPASS
    {
        if(compassAvail==true)
        {
            Velicina3S = Gdx.input.getAzimuth()/360f*3.141592653f;
            Velicina2S= -Gdx.input.getPitch()/360f*3.141592653f;
            VelicinaS= Gdx.input.getRoll()/360f*3.141592653f;
        }

    }

    if (FixRotacija == 2)//rotate ACCEL
        {
        SlajdY += accelX / 200f;
        if (SlajdY > 1200) SlajdY = 1200;
        VelicinaS = SlajdY;

        Slajd2Y += accelY / 200f;
        if (Slajd2Y > 1200) Slajd2Y = 1200;
        Velicina2S = Slajd2Y;


        }
    }
        camera.update();


        {

            int i;

            if (Gdx.input.isTouched()) {

                if (dodirnut == 0)
                    dodirnut = 1;
                else
                    dodirnut = 2;
            } else {
                dodirnut = 0;
                Ulaz = 0;
            }


            if (Gdx.input.isTouched() && dodirnut > 0)
            {
                Vector2 touch1 = camera.unprojectCoordinates(Gdx.input.getX(), Gdx.input.getY());
                PrviX2 = touch1.x;
                PrviY2 = touch1.y;

                touch1.x=Gdx.input.getX()*width/Gwidth;






                PrviX1 = touch1.x;
                PrviY1 = touch1.y;

                TouchX = Gdx.input.getX();
                TouchY = Gdx.input.getY();


                Crtaj = 0;

                if (touch1.x >  KeyPadX+20  &&   touch1.x <  KeyPadX+120 && touch1.y >KeyPadY-190 && touch1.y <KeyPadY-110 && dodirnut ==1 && KeupadOn==1 )
                {
                    Radni=1;
                    TekstBroj=R1;
                    if(TekstBroj!=0)
                        Znak=Integer.signum(TekstBroj);
                    else
                        Znak=1;
                    TekstBroj=Math.abs(TekstBroj);
                    Tekst=Integer.toString(Znak*TekstBroj);
                }
                if (touch1.x >  KeyPadX+120  &&   touch1.x <  KeyPadX+220 && touch1.y >KeyPadY-190 && touch1.y <KeyPadY-110 && dodirnut ==1 && KeupadOn==1 )
                {
                    Radni=2;
                    TekstBroj=R2;
                    if(TekstBroj!=0)
                        Znak=Integer.signum(TekstBroj);
                    else
                        Znak=1;
                    TekstBroj=Math.abs(TekstBroj);
                    Tekst=Integer.toString(Znak*TekstBroj);
                }
                if (touch1.x >  KeyPadX+220  &&   touch1.x <  KeyPadX+320 && touch1.y >KeyPadY-190 && touch1.y <KeyPadY-110 && dodirnut ==1 && KeupadOn==1 )
                {
                    Radni=3;
                    TekstBroj=R3;
                    if(TekstBroj!=0)
                        Znak=Integer.signum(TekstBroj);
                    else
                        Znak=1;
                    TekstBroj=Math.abs(TekstBroj);
                    Tekst=Integer.toString(Znak*TekstBroj);
                }


                if (touch1.x >  KeyPadX+20  &&   touch1.x <  KeyPadX+120 && touch1.y >KeyPadY-270 && touch1.y <KeyPadY-190 && dodirnut ==1 && KeupadOn==1 )
                {
                    Radni=4;
                    TekstBroj=R4;
                    if(TekstBroj!=0)
                        Znak=Integer.signum(TekstBroj);
                    else
                        Znak=1;
                    TekstBroj=Math.abs(TekstBroj);
                    Tekst=Integer.toString(Znak*TekstBroj);
                }
                if (touch1.x >  KeyPadX+120  &&   touch1.x <  KeyPadX+220 && touch1.y >KeyPadY-270 && touch1.y <KeyPadY-190  && dodirnut ==1 && KeupadOn==1 )
                {
                    Radni=5;
                    TekstBroj=R5;
                    if(TekstBroj!=0)
                        Znak=Integer.signum(TekstBroj);
                    else
                        Znak=1;
                    TekstBroj=Math.abs(TekstBroj);
                    Tekst=Integer.toString(Znak*TekstBroj);
                }
                if (touch1.x >  KeyPadX+220  &&   touch1.x <  KeyPadX+320 && touch1.y >KeyPadY-270 && touch1.y <KeyPadY-190  && dodirnut ==1 && KeupadOn==1 )
                {
                    Radni=6;
                    TekstBroj=R6;
                    if(TekstBroj!=0)
                        Znak=Integer.signum(TekstBroj);
                    else
                        Znak=1;
                    TekstBroj=Math.abs(TekstBroj);
                    Tekst=Integer.toString(Znak*TekstBroj);
                }



                if (touch1.x > KeyPadX +325   && touch1.y >KeyPadY-160 && dodirnut ==1 && KeupadOn==1 && brlinija[AktivnaVerzija]>0 )
                {
                    LinijaSelektovana=LinijaBr-1- ((int)touch1.y-(KeyPadY+350))/40;
                    if(LinijaSelektovana<0)LinijaSelektovana=0;
                    if(LinijaSelektovana>=brlinija[AktivnaVerzija])LinijaSelektovana=brlinija[AktivnaVerzija]-1;
                    Radni=1;
                    R1=(int)shema[AktivnaVerzija][LinijaSelektovana*2][0];
                    TekstR1=Integer.toString(R1);
                    Znak=1;
                    TekstBroj=R1;
                    Tekst=Integer.toString(Znak*TekstBroj);

                    R2=(int)shema[AktivnaVerzija][LinijaSelektovana*2][1];
                    TekstR2=Integer.toString(R2);
                    R3=(int)shema[AktivnaVerzija][LinijaSelektovana*2][2];
                    TekstR3=Integer.toString(R3);
                    R4=(int)shema[AktivnaVerzija][LinijaSelektovana*2+1][0];
                    TekstR4=Integer.toString(R4);
                    R5=(int)shema[AktivnaVerzija][LinijaSelektovana*2+1][1];
                    TekstR5=Integer.toString(R5);
                    R6=(int)shema[AktivnaVerzija][LinijaSelektovana*2+1][2];
                    TekstR6=Integer.toString(R6);
                    if(TekstBroj!=0)
                        Znak=Integer.signum(TekstBroj);
                    else
                        Znak=1;
                    TekstBroj=Math.abs(TekstBroj);
                    Tekst=Integer.toString(Znak*TekstBroj);

                }

                if (touch1.x > 0 && touch1.x <145  && touch1.y < 70 && dodirnut ==1 && Sakrij == 0)
                {

                    if(++FixRotacija>3)FixRotacija=0; // fixrotacija - 0 pomeraj, 1 rotiraj, 2 accel rotraj, 3 kompas rotiraj
                    BrojacKlik[30]=.9f;
                    if (FixRotacija == 3)//rotate COMPASS
                    {
                        RotirajX = 0;
                        RotirajY = 0;
                        RotirajZ = 0;
                    }
                }

                if (touch1.x > 150 && touch1.x <300  && touch1.y < 70 && dodirnut ==1 && Sakrij == 0)
                {
                    easysketch.kraj=50; //Umesto Galerije - izlaz iz app
                    BrojacKlik[31]=.9f;
                }








                if (touch1.x > 1 && touch1.x <100  && touch1.y > 422 && touch1.y < 497 && dodirnut ==1 && Sakrij == 0)
                {
                    RotirajX = 1-RotirajX;
                    BrojacKlik[24]=.9f;
                }
                if (touch1.x > 1 && touch1.x <150  && touch1.y > 355 && touch1.y < 420 && dodirnut ==1 && Sakrij == 0)
                {
                    RotirajY = 1-RotirajY;
                    BrojacKlik[25]=.9f;
                }
                if (touch1.x > 1 && touch1.x <150  && touch1.y > 288 && touch1.y < 350 && dodirnut ==1 && Sakrij == 0)
                {
                    RotirajZ = 1-RotirajZ;
                    BrojacKlik[26]=.9f;
                }



                if (touch1.x > 1 && touch1.x <150    && touch1.y > 221 && touch1.y < 285 && dodirnut ==1 && Sakrij == 0)
                {

                    demo=0;
                    Galerija++;
                    if(Galerija>5)Galerija=1;

                    if(Galerija==1)
                        shemaD2();
                    else
                        UcitajGaleriju(Galerija);






                    BrojacKlik[27]=.9f;
                }




                if (touch1.x > 1 && touch1.x <150    && touch1.y > 154 && touch1.y < 215 && dodirnut ==1 && Sakrij == 0)
                {
                    speed+=.0005;
                    if (speed>.1f)speed=.1f;
                    BrojacKlik[28]=.9f;
                }

                if (touch1.x > 1 && touch1.x <150    && touch1.y > 87 && touch1.y < 145 && dodirnut ==1 && Sakrij == 0)
                {
                    speed-=.0005;
                    if (speed<-.1f)speed=-.1f;
                    BrojacKlik[29]=.9f;
                }




                if (touch1.x > 1 && touch1.x <150    && touch1.y > 690 && dodirnut ==1 && SakrijFullscr==0)
                {
                    Sakrij=1-Sakrij;
                    BrojacKlik[20]=.9f;
                    if(Sakrij==0)// iskljucujem meni ako je bio ukljucen
                    {

                        IscrtavanjeSlike=1;
                    }

                }





                if (touch1.x > 280 && touch1.x <430  && touch1.y < 70 && dodirnut ==1 && (KeupadOn==1 || Sakrij == 0))
                {
                     easysketch.OtvorenFajl="Otvori";

                    easysketch.kraj=53;
                    BrojacKlik[32]=.9f;

                }

                if (touch1.x > 10 && touch1.x <150  && touch1.y > 556 && touch1.y < 630 && dodirnut ==1 && Sakrij == 0)
                {
                    Grid= 1-Grid;
                    NapuniGrid();
                    BrojacKlik[22]=.9f;
                }

                if (touch1.x > 1 && touch1.x <150  && touch1.y > 623 && touch1.y < 695 && dodirnut ==1 && Sakrij == 0)
                {
                    Osa= 1-Osa;
                    NapuniGrid();
                    BrojacKlik[21]=.9f;
                }

                if (touch1.x > 1 && touch1.x <150  && touch1.y > 489 && touch1.y < 564 && dodirnut ==1 && Sakrij == 0)
                {
                    Projections= 1-Projections;
                    BrojacKlik[23]=.9f;
                }


                if (touch1.x > 420 && touch1.x <560  && touch1.y < 70 && dodirnut ==1 && (KeupadOn==1 || Sakrij == 0))
                {


                    {

                        easysketch.PodaciZaSnimanje=PripremiStringZaSnimanje();
                        BrojacKlik[33]=.9f;
                        easysketch.kraj=51;
                    }

                }

                if (touch1.x > 562 && touch1.x <700  && touch1.y < 70 && dodirnut ==1 && (KeupadOn==1 || Sakrij == 0))
                {
                    if(KeupadOn==1)//new data
                    {
                        brlinija[AktivnaVerzija] = 0;
                        BrojacKlik[34] = .9f;
                    }
                    else//share
                    {
                        easysketch.kraj=55;

                        BrojacKlik[34] = .9f;
                    }

                }

                if (touch1.x > 700 && touch1.x <840  && touch1.y < 70 && dodirnut ==1 && (KeupadOn==1 || Sakrij == 0))
                {
                    if(KeupadOn==1)//brisi red
                    {
                        BrisiLiniju(LinijaSelektovana);
                    }
                    else//help
                    {
                        Pomoc = 1 - Pomoc;
                        zumirajU = 1;
                        PrviXU = 0;
                        PrviYU = 0;
                        BrojacKlik[35] = .9f;
                    }
                }

                if (touch1.x > 840 && touch1.x <980  && touch1.y < 70 && dodirnut ==1 && (KeupadOn==1 || Sakrij == 0))
                {
                    KeupadOn=1-KeupadOn;
                    Sakrij=KeupadOn;
                    SakrijFullscr=KeupadOn;
                    BrojacKlik[36]=.9f;
                }

                if(KeupadOn==1) {



                    if (touch1.x > KeyPadX && touch1.x < KeyPadX+104 && touch1.y >KeyPadY && touch1.y < KeyPadY+75 && dodirnut == 1)
                    {

                        TekstBroj/=10;// delete
                        BrojacKlik[0]=.9f;
                    }
                    if (touch1.x > KeyPadX +104 && touch1.x < KeyPadX+208 && touch1.y >KeyPadY && touch1.y < KeyPadY+75 && dodirnut == 1)
                    {

                        BrojacKlik[1]=.9f;
                        Tekst=Integer.toString(Znak*TekstBroj);
                        switch (Radni)
                        {
                            case 1:
                                Radni=2;
                                TekstR1=Tekst;
                                R1=Znak*TekstBroj;
                                TekstBroj=R2;
                                break;
                            case 2:
                                Radni=3;
                                TekstR2=Tekst;
                                R2=Znak*TekstBroj;
                                TekstBroj=R3;
                                break;
                            case 3:
                                Radni=4;
                                TekstR3=Tekst;
                                R3=Znak*TekstBroj;
                                TekstBroj=R4;
                                break;
                            case 4:
                                Radni=5;
                                TekstR4=Tekst;
                                R4=Znak*TekstBroj;
                                TekstBroj=R5;
                                break;
                            case 5:
                                Radni=6;
                                TekstR5=Tekst;
                                R5=Znak*TekstBroj;
                                TekstBroj=R6;
                                break;
                            case 6:
                                Radni=1;
                                TekstR6=Tekst;
                                R6=Znak*TekstBroj;
                                TekstBroj=R1;

                                if(brlinija[AktivnaVerzija]<490) brlinija[AktivnaVerzija]++;

                                int b=brlinija[AktivnaVerzija]*2-2;
                                shema[AktivnaVerzija][b][0] = R1;
                                shema[AktivnaVerzija][b][1] = R2;
                                shema[AktivnaVerzija][b][2] = R3;
                                shema[AktivnaVerzija][b+1][0] = R4;
                                shema[AktivnaVerzija][b+1][1] = R5;
                                shema[AktivnaVerzija][b+1][2] = R6;
                                break;

                        }

                        if(TekstBroj!=0)
                            Znak=Integer.signum(TekstBroj);
                        else
                            Znak=1;
                        TekstBroj=Math.abs(TekstBroj);

                        Tekst=Integer.toString(Znak*TekstBroj);
                    }



                    if (touch1.x > KeyPadX + 208 && touch1.x < KeyPadX+312 && touch1.y >KeyPadY && touch1.y < KeyPadY+75 && dodirnut == 1)
                    { // ENT-update aktivnog
                        BrojacKlik[2]=.9f;
                        Tekst=Integer.toString(Znak*TekstBroj);
                        switch (Radni)
                        {
                            case 1:
                                Radni=2;
                                TekstR1=Tekst;
                                R1=Znak*TekstBroj;
                                TekstBroj=R2;
                                break;
                            case 2:
                                Radni=3;
                                TekstR2=Tekst;
                                R2=Znak*TekstBroj;
                                TekstBroj=R3;
                                break;
                            case 3:
                                Radni=4;
                                TekstR3=Tekst;
                                R3=Znak*TekstBroj;
                                TekstBroj=R4;
                                break;
                            case 4:
                                Radni=5;
                                TekstR4=Tekst;
                                R4=Znak*TekstBroj;
                                TekstBroj=R5;
                                break;
                            case 5:
                                Radni=6;
                                TekstR5=Tekst;
                                R5=Znak*TekstBroj;
                                TekstBroj=R6;
                                break;
                            case 6:
                                Radni=1;
                                TekstR6=Tekst;
                                R6=Znak*TekstBroj;
                                TekstBroj=R1;


                                int b=LinijaSelektovana*2;
                                shema[AktivnaVerzija][b][0] = R1;
                                shema[AktivnaVerzija][b][1] = R2;
                                shema[AktivnaVerzija][b][2] = R3;
                                shema[AktivnaVerzija][b+1][0] = R4;
                                shema[AktivnaVerzija][b+1][1] = R5;
                                shema[AktivnaVerzija][b+1][2] = R6;
                                break;

                        }

                        if(TekstBroj!=0)
                            Znak=Integer.signum(TekstBroj);
                        else
                            Znak=1;
                        TekstBroj=Math.abs(TekstBroj);

                        Tekst=Integer.toString(Znak*TekstBroj);

                    }


                    if (touch1.x > KeyPadX && touch1.x < KeyPadX+104 && touch1.y >KeyPadY+75 && touch1.y < KeyPadY+150 && dodirnut == 1)
                    {
                        TekstBroj=0;// Clear
                        BrojacKlik[3]=.9f;
                    }
                    if (touch1.x > KeyPadX +104 && touch1.x < KeyPadX+208 && touch1.y >KeyPadY+75 && touch1.y < KeyPadY+150  && dodirnut == 1)
                    {

                        if(TekstBroj<10000) TekstBroj*=10;
                        BrojacKlik[4]=.9f;
                    }
                    if (touch1.x > KeyPadX + 208 && touch1.x < KeyPadX+312 && touch1.y >KeyPadY+75 && touch1.y < KeyPadY+150  && dodirnut == 1)
                    {
                        Znak=-Znak;//minus
                        BrojacKlik[5]=.9f;
                    }




                    if (touch1.x > KeyPadX && touch1.x < KeyPadX+104 && touch1.y >KeyPadY+150 && touch1.y < KeyPadY+225 && dodirnut == 1)
                    {
                        if(TekstBroj<10000) TekstBroj=TekstBroj*10+7;// 7
                        BrojacKlik[6]=.9f;
                    }
                    if (touch1.x > KeyPadX +104 && touch1.x < KeyPadX+208 && touch1.y >KeyPadY+150 && touch1.y < KeyPadY+225 && dodirnut == 1)
                    {
                        if(TekstBroj<10000) TekstBroj=TekstBroj*10+8;// 8
                        BrojacKlik[7]=.9f;
                    }
                    if (touch1.x > KeyPadX + 208 && touch1.x < KeyPadX+312 && touch1.y >KeyPadY+150 && touch1.y < KeyPadY+225 && dodirnut == 1)
                    {
                        if(TekstBroj<10000) TekstBroj=TekstBroj*10+9;// 9
                        BrojacKlik[8]=.9f;
                    }


                    if (touch1.x > KeyPadX && touch1.x < KeyPadX+104 && touch1.y >KeyPadY+225 && touch1.y < KeyPadY+300 && dodirnut == 1)
                    {
                        if(TekstBroj<10000) TekstBroj=TekstBroj*10+4;// 4
                        BrojacKlik[9]=.9f;
                    }
                    if (touch1.x > KeyPadX +104 && touch1.x < KeyPadX+208 && touch1.y >KeyPadY+225 && touch1.y < KeyPadY+300 && dodirnut == 1)
                    {
                        if(TekstBroj<10000) TekstBroj=TekstBroj*10+5;// 5
                        BrojacKlik[10]=.9f;
                    }
                    if (touch1.x > KeyPadX + 208 && touch1.x < KeyPadX+312 && touch1.y >KeyPadY+225 && touch1.y < KeyPadY+300 && dodirnut == 1)
                    {
                        if(TekstBroj<10000) TekstBroj=TekstBroj*10+6;// 6
                        BrojacKlik[11]=.9f;
                    }


                    if (touch1.x > KeyPadX && touch1.x < KeyPadX+104 && touch1.y >KeyPadY+300 && touch1.y < KeyPadY+375 && dodirnut == 1)
                    {
                        if(TekstBroj<10000) TekstBroj=TekstBroj*10+1;// 1
                        BrojacKlik[12]=.9f;
                    }
                    if (touch1.x > KeyPadX +104 && touch1.x < KeyPadX+208 && touch1.y >KeyPadY+300 && touch1.y < KeyPadY+375 && dodirnut == 1)
                    {
                        if(TekstBroj<10000) TekstBroj=TekstBroj*10+2;// 2
                        BrojacKlik[13]=.9f;
                    }
                    if (touch1.x > KeyPadX + 208 && touch1.x < KeyPadX+312 && touch1.y >KeyPadY+300 && touch1.y < KeyPadY+375 && dodirnut == 1)
                    {
                        if(TekstBroj<10000) TekstBroj=TekstBroj*10+3;// 3
                        BrojacKlik[14]=.9f;
                    }

                    Tekst=Integer.toString(Znak*TekstBroj);
                }



            }
        }


    }


    @Override
    public void dispose() {

    }

    @Override
    public void pause() {
    }

    @Override
    public void resume() {

    }








    public void BrisiLiniju(int LinijaSelektovana)
    {
        int i;
        for(i=LinijaSelektovana*2;i<(brlinija[AktivnaVerzija]-1)*2;i+=2)
        {
            shema[AktivnaVerzija][i][0] = shema[AktivnaVerzija][i + 2][0];
            shema[AktivnaVerzija][i][1] = shema[AktivnaVerzija][i + 2][1];
            shema[AktivnaVerzija][i][2] = shema[AktivnaVerzija][i + 2][2];
            shema[AktivnaVerzija][i][3] = shema[AktivnaVerzija][i + 2][3];

            shema[AktivnaVerzija][i+1][0] = shema[AktivnaVerzija][i + 3][0];
            shema[AktivnaVerzija][i+1][1] = shema[AktivnaVerzija][i + 3][1];
            shema[AktivnaVerzija][i+1][2] = shema[AktivnaVerzija][i + 3][2];
            shema[AktivnaVerzija][i+1][3] = shema[AktivnaVerzija][i + 3][3];

        }
        if(brlinija[AktivnaVerzija]>0)brlinija[AktivnaVerzija]--;
    }

    public void crtajSlikuProjekcija(int Verzija) {
        float x1;
        float y1;
        float z1;

        float x2;
        float y2;
        float z2;
        float maxim1=1;
        int AktivnaVerzija2=AktivnaVerzija;
        AktivnaVerzija=Verzija;
        int i;




        if (RotirajX == 1)

        {
            VelicinaS+=speed;//0.005f;
            SlajdY=VelicinaS;
        }

        alfa = VelicinaS*2;

        if (RotirajY == 1)
        {
            Velicina2S+=speed;//0.005f;
            Slajd2Y=Velicina2S;
        }


        beta  = Velicina2S*2;


        if (RotirajZ == 1)Velicina3S+=speed;//0.005f;

        gama = Velicina3S*2;


        shapeRenderer.setColor(.1f, .1f, 1, 1F);

        shapeRenderer.line(700, 450, 700, 750);


        shapeRenderer.line(705, 740, 700, 750);
        shapeRenderer.line(695, 740, 700, 750);

        shapeRenderer.line(550, 600, 850, 600);

        shapeRenderer.line(840, 605, 850, 600);
        shapeRenderer.line(840, 595, 850, 600);

        shapeRenderer.line(150, 600, 450, 600);

        shapeRenderer.line(440, 605, 450, 600);
        shapeRenderer.line(440, 595, 450, 600);

        shapeRenderer.line(300, 450, 300, 750);

        shapeRenderer.line(305, 740, 300, 750);
        shapeRenderer.line(295, 740, 300, 750);

        shapeRenderer.line(150, 200, 450, 200);

        shapeRenderer.line(440, 205, 450, 200);
        shapeRenderer.line(440, 195, 450, 200);

        shapeRenderer.line(300, 50, 300, 350);

        shapeRenderer.line(305, 340, 300, 350);
        shapeRenderer.line(295, 340, 300, 350);

        shapeRenderer.setColor(1, 1, 1, 1);
        for (i = -2; i < brlinija[AktivnaVerzija] * 2; i += 2)
        {
            if(i>-2) {
                x1 = shema[AktivnaVerzija][i][0] * maxim1 * zumiraj;
                y1 = shema[AktivnaVerzija][i][1] * maxim1 * zumiraj;
                z1 = shema[AktivnaVerzija][i][2] * maxim1 * zumiraj;
                x2 = shema[AktivnaVerzija][i + 1][0] * maxim1 * zumiraj;
                y2 = shema[AktivnaVerzija][i + 1][1] * maxim1 * zumiraj;
                z2 = shema[AktivnaVerzija][i + 1][2] * maxim1 * zumiraj;
            }
            else
            {
                x1 = CentarX* maxim1 * zumiraj;
                y1 = CentarY* maxim1 * zumiraj;
                z1 = CentarZ* maxim1 * zumiraj;
                x2 = CentarX* maxim1 * zumiraj;
                y2 = CentarY* maxim1 * zumiraj;
                z2 = CentarZ* maxim1 * zumiraj;
            }



            if(i>-2)
            {
                if(shema[AktivnaVerzija][i][3]==0) shapeRenderer.setColor(1, 1, 1f, 1f);
                if(shema[AktivnaVerzija][i][3]==1) shapeRenderer.setColor(1, 1, .5f, 1f);
                if(shema[AktivnaVerzija][i][3]==2) shapeRenderer.setColor(1, .5f, 1f, 1f);
                if(shema[AktivnaVerzija][i][3]==3) shapeRenderer.setColor(.5f, 1f, 1f, 1f);
                if(shema[AktivnaVerzija][i][3]==4)shapeRenderer.setColor(.1f, .1f, 1, 1F);

                shapeRenderer.line(x1 + 700, y1 + 600, x2 + 700, y2 + 600);
                shapeRenderer.line(x1 + 300, z1 + 600, x2 + 300, z2 + 600);
                shapeRenderer.line(y1 + 300, z1 + 200, y2 + 300, z2 + 200);
            }


        }


        AktivnaVerzija=AktivnaVerzija2;

    }



    public void crtajSliku(int Verzija) {
        float x1;
        float y1;
        float z1;

        float x2;
        float y2;
        float z2;
        float maxim1=1;
        int AktivnaVerzija2=AktivnaVerzija;
        AktivnaVerzija=Verzija;
        int i;




        if (RotirajX == 1)

        {
            VelicinaS+=speed;//0.005f;
            SlajdY=VelicinaS;
        }

            alfa = VelicinaS*2;

        if (RotirajY == 1)
        {
            Velicina2S+=speed;//0.005f;
            Slajd2Y=Velicina2S;
        }


        beta  = Velicina2S*2;


        if (RotirajZ == 1)Velicina3S+=speed;//0.005f;

            gama = Velicina3S*2;



        shapeRenderer.setColor(1, 1, 1, 1);
        for (i = -2; i < brlinija[AktivnaVerzija] * 2; i += 2)
        {
            if(i>-2) {
                x1 = shema[AktivnaVerzija][i][0] * maxim1 * zumiraj;
                y1 = shema[AktivnaVerzija][i][1] * maxim1 * zumiraj;
                z1 = shema[AktivnaVerzija][i][2] * maxim1 * zumiraj;
                x2 = shema[AktivnaVerzija][i + 1][0] * maxim1 * zumiraj;
                y2 = shema[AktivnaVerzija][i + 1][1] * maxim1 * zumiraj;
                z2 = shema[AktivnaVerzija][i + 1][2] * maxim1 * zumiraj;
            }
            else
            {
                x1 = CentarX* maxim1 * zumiraj;
                y1 = CentarY* maxim1 * zumiraj;
                z1 = CentarZ* maxim1 * zumiraj;
                x2 = CentarX* maxim1 * zumiraj;
                y2 = CentarY* maxim1 * zumiraj;
                z2 = CentarZ* maxim1 * zumiraj;
            }

            G3DR.translacija(x1, y1, z1, -CentarX* maxim1 * zumiraj, -CentarY* maxim1 * zumiraj, -CentarZ* maxim1 * zumiraj);
            G3DR.ProjekcijaXY(G3DR.x, G3DR.y, G3DR.z, alfa, beta, gama);


            x1 = G3DR.x;
            y1 = G3DR.y;
            G3DR.translacija(x2, y2, z2, -CentarX* maxim1 * zumiraj, -CentarY* maxim1 * zumiraj, -CentarZ* maxim1 * zumiraj);
            G3DR.ProjekcijaXY(G3DR.x, G3DR.y, G3DR.z, alfa, beta, gama);


            x2 = G3DR.x;
            y2 = G3DR.y;


            if(i>-2)
            {
                if(shema[AktivnaVerzija][i][3]==0) shapeRenderer.setColor(1, 1, 1f, 1f);
                if(shema[AktivnaVerzija][i][3]==1) shapeRenderer.setColor(1, 1, .5f, 1f);
                if(shema[AktivnaVerzija][i][3]==2) shapeRenderer.setColor(1, .5f, 1f, 1f);
                if(shema[AktivnaVerzija][i][3]==3) shapeRenderer.setColor(.5f, 1f, 1f, 1f);
                if(shema[AktivnaVerzija][i][3]==4)shapeRenderer.setColor(.1f, .1f, 1, 1F);

                if(i/2==LinijaSelektovana && KeupadOn==1 && Verzija!=3)shapeRenderer.setColor(1f, .3f, .3f, 1F);

                shapeRenderer.line(x1 + PrviX, y1 + PrviY, x2 + PrviX, y2 + PrviY);

            }
            else
                if(FixRotacija!=0)
                {
                    shapeRenderer.circle(x1+PrviX, y1+PrviY, 10);
                }

        }
        AktivnaVerzija=AktivnaVerzija2;

    }

    public void crtajGrid()
    {
        float x1=0;
        float y1=0;
        float z1=0;

        float x2=0;
        float y2=0;
        float z2=0;
        float i;

        for (i = -10; i <11; i += 1)
        {
                x1 = i* maxim * zumiraj/5;
                y1 = -10* maxim * zumiraj/5;
                z1 = 0;//.5f * maxim * zumiraj;
                x2 = i * maxim * zumiraj/5;
                y2 = 10 * maxim * zumiraj/5;
                z2 =   0;//.5f * maxim * zumiraj;.5f * maxim * zumiraj;


            G3DR.ProjekcijaXY(x1, y1, z1, alfa, beta, gama);
            G3DR.translacija(G3DR.x, G3DR.y, G3DR.z, -CentarX* maxim * zumiraj, -CentarY* maxim * zumiraj, -CentarZ* maxim * zumiraj);

            x1 = G3DR.x;
            y1 = G3DR.y;



            G3DR.ProjekcijaXY(x2, y2, z2, alfa, beta, gama);
            G3DR.translacija(G3DR.x, G3DR.y, G3DR.z, -CentarX* maxim * zumiraj, -CentarY* maxim * zumiraj, -CentarZ* maxim * zumiraj);


            x2 = G3DR.x;
            y2 = G3DR.y;

            shapeRenderer.line(x1+PrviX, y1+PrviY, x2+PrviX, y2+PrviY);
        }

        for (i = -10; i <11; i += 1)
        {
                x1 = -10* maxim * zumiraj/5;
                y1 = i* maxim * zumiraj/5;
                z1 =   0;//.5f * maxim * zumiraj;
                x2 = 10 * maxim * zumiraj/5;
                y2 = i * maxim * zumiraj/5;
                z2 =   0;//.5f * maxim * zumiraj;


            G3DR.ProjekcijaXY(x1, y1, z1, alfa, beta, gama);
            G3DR.translacija(G3DR.x, G3DR.y, G3DR.z, -CentarX* maxim * zumiraj, -CentarY* maxim * zumiraj, -CentarZ* maxim * zumiraj);

            x1 = G3DR.x;
            y1 = G3DR.y;


            G3DR.ProjekcijaXY(x2, y2, z2, alfa, beta, gama);
            G3DR.translacija(G3DR.x, G3DR.y, G3DR.z, -CentarX* maxim * zumiraj, -CentarY* maxim * zumiraj, -CentarZ* maxim * zumiraj);

            x2 = G3DR.x;
            y2 = G3DR.y;

            shapeRenderer.line(x1+PrviX, y1+PrviY, x2+PrviX, y2+PrviY);



        }



    }


    public void cetvorougao(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
        shapeRenderer.line(x1, y1, x2, y2);
        shapeRenderer.line(x2, y2, x3, y3);
        shapeRenderer.line(x3, y3, x4, y4);
        shapeRenderer.line(x4, y4, x1, y1);
    }

    public void pravougaonik(float x1, float y1, float x2, float y2)
    {
        shapeRenderer.line(x1, y1, x2, y1);
        shapeRenderer.line(x1, y1, x1, y2);
        shapeRenderer.line(x2, y1, x2, y2);
        shapeRenderer.line(x2, y2, x1, y2);
    }

    public float fun(float f, float g)
    {
        float m;
        float n;
        float m1;
        float n1;

        m = g;
        n = f;
        m=m-30;
        n=n-30;
        m1=g-10f;
        n1=f-10f;
        return MathUtils.sin((float)(1.3f*Math.sqrt(m1*m1+n1*n1)-vreme/3f)/1.5f)*10f;

    }

    public void ResetGame() {
        zumiraj = 1;
        Crtaj = 0;
        Ulaz = 1;
        dodirnut = 1;
        SlajdY = 130;
        Slajd2Y = 130;
        Slajd3Y = 130;
        VelicinaS = 1;
        Velicina2S = 1;
        Velicina3S = 1;
        Brojackraj = 0;
        Status = 1;
        svetlo = 0;

        PrviX = 800;
        PrviY = 300;
        shemaD2();
    }
    private void shemaD2()
    {
        shema[0][0][0] = 0;
        shema[0][0][1] = 0;
        shema[0][0][2] = 0;

        shema[0][1][0] = 1;
        shema[0][1][1] = 0;
        shema[0][1][2] = 0;


        shema[0][2][0] = 0;
        shema[0][2][1] = 0;
        shema[0][2][2] = 0;

        shema[0][3][0] = 0;
        shema[0][3][1] = 1;
        shema[0][3][2] = 0;


        shema[0][4][0] = 0;
        shema[0][4][1] = 0;
        shema[0][4][2] = 0;

        shema[0][5][0] = 0;
        shema[0][5][1] = 0;
        shema[0][5][2] = 1;


        shema[0][6][0] = 1;
        shema[0][6][1] = 0;
        shema[0][6][2] = 0;

        shema[0][7][0] = 1;
        shema[0][7][1] = 1;
        shema[0][7][2] = 0;


        shema[0][8][0] = 1;
        shema[0][8][1] = 0;
        shema[0][8][2] = 0;

        shema[0][9][0] = 1;
        shema[0][9][1] = 0;
        shema[0][9][2] = 1;


        shema[0][10][0] = 1;
        shema[0][10][1] = 1;
        shema[0][10][2] = 0;

        shema[0][11][0] = 1;
        shema[0][11][1] = 1;
        shema[0][11][2] = 1;


        shema[0][12][0] = 1;
        shema[0][12][1] = 1;
        shema[0][12][2] = 0;

        shema[0][13][0] = 0;
        shema[0][13][1] = 1;
        shema[0][13][2] = 0;


        shema[0][14][0] = 1;
        shema[0][14][1] = 1;
        shema[0][14][2] = 1;

        shema[0][15][0] = 0;
        shema[0][15][1] = 1;
        shema[0][15][2] = 1;


        shema[0][16][0] = 1;
        shema[0][16][1] = 1;
        shema[0][16][2] = 1;

        shema[0][17][0] = 1;
        shema[0][17][1] = 0;
        shema[0][17][2] = 1;


        shema[0][18][0] = 0;
        shema[0][18][1] = 1;
        shema[0][18][2] = 1;

        shema[0][19][0] = 0;
        shema[0][19][1] = 0;
        shema[0][19][2] = 1;


        shema[0][20][0] = 0;
        shema[0][20][1] = 1;
        shema[0][20][2] = 0;

        shema[0][21][0] = 0;
        shema[0][21][1] = 1;
        shema[0][21][2] = 1;


        shema[0][22][0] = 1;
        shema[0][22][1] = 0;
        shema[0][22][2] = 1;

        shema[0][23][0] = 0;
        shema[0][23][1] = 0;
        shema[0][23][2] = 1;
        brlinija[0] = 12;
        AktivnaVerzija=0;
        maxim = 1;
        zumiraj=30;
        Centar(0);
        NapuniGrid();
    }

    private void shemaD1()
    {
        maxim = 1; // uvecanje

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


        int i2;
        for(i2=0;i2<250;i2++)
        {
            shema[1][i2][0] =shema[1][i2+1][1];
            shema[1][i2][1] =shema[1][i2+1][2];
            shema[1][i2][2] =shema[1][i2+1][3];
            shema[1][i2][3] =shema[1][i2+1][4];
        }
        brlinija[1]=225;
        AktivnaVerzija=1;
        Centar(1);
    }
    private void Centar(int b)
    {
        int i;
        CentarX=0;
        CentarY=0;
        CentarZ=0;
        for (i = 0; i < brlinija[AktivnaVerzija] * 2; i += 1)
        {
            CentarX+=shema[b][i][0];
            CentarY+=shema[b][i][1];
            CentarZ+=shema[b][i][2];
        }
        CentarX/=(brlinija[AktivnaVerzija]*2);
        CentarY/=(brlinija[AktivnaVerzija]*2);
        CentarZ/=(brlinija[AktivnaVerzija]*2);
    }



    public void NapuniGrid()
    {


        float j=0;
        int i=0;
        brlinija[3]=0;
        if(Grid==1) // puni grid
        {
            for (i = -20; i <= 20; i += 2) {


                shema[3][i + 20][0] = i / 4f * maxim;
                shema[3][i + 20][1] = -5 * maxim;
                shema[3][i + 20][2] = 0;
                shema[3][i + 20][3] = 4;

                shema[3][i + 21][0] = i / 4f * maxim;
                shema[3][i + 21][1] = 5 * maxim;
                shema[3][i + 21][2] = 0;
                shema[3][i + 21][3] = 4;


                shema[3][i + 62][0] = -5 * maxim;
                shema[3][i + 62][1] = i / 4f * maxim;
                shema[3][i + 62][2] = 0;
                shema[3][i + 62][3] = 4;

                shema[3][i + 63][0] = 5 * maxim;
                shema[3][i + 63][1] = i / 4f * maxim;
                shema[3][i + 63][2] = 0;
                shema[3][i + 63][3] = 4;

                j++;
            }
            brlinija[3]=42;
            i=84;
        }

        if(Osa==1)
        {


            shema[3][i][0] = 0;
            shema[3][i][1] = 0;
            shema[3][i][2] = -5 * maxim;
            shema[3][i][3] = 3;

            i++;
            shema[3][i][0] = 0;
            shema[3][i][1] = 0;
            shema[3][i][2] = 5 * maxim;
            shema[3][i][3] = 3;
            i++;



            shema[3][i][0] = 0;
            shema[3][i][1] = 0;
            shema[3][i][2] = 5 * maxim;
            shema[3][i][3] = 3;


            i++;

            shema[3][i][0] = 0;
            shema[3][i][1] = .1f* maxim;
            shema[3][i][2] = 4.5f * maxim;
            shema[3][i][3] = 3;

            i++;

            shema[3][i][0] = 0;
            shema[3][i][1] = 0;
            shema[3][i][2] = 5 * maxim;
            shema[3][i][3] = 3;


            i++;

            shema[3][i][0] = 0;
            shema[3][i][1] = -.1f* maxim;
            shema[3][i][2] = 4.5f * maxim;
            shema[3][i][3] = 3;

            i++;




            shema[3][i][0] = -5 * maxim;
            shema[3][i][1] = 0;
            shema[3][i][2] = 0;
            shema[3][i][3] = 1;
            i++;

            shema[3][i][0] = 5 * maxim;
            shema[3][i][1] = 0;
            shema[3][i][2] = 0;
            shema[3][i][3] = 1;
            i++;

            shema[3][i][0] = 5 * maxim;
            shema[3][i][1] = 0;
            shema[3][i][2] = 0;
            shema[3][i][3] = 1;
            i++;
            shema[3][i][0] = 4.5f * maxim;
            shema[3][i][1] = .1f* maxim;
            shema[3][i][2] = 0;
            shema[3][i][3] = 1;
            i++;
            shema[3][i][0] = 5 * maxim;
            shema[3][i][1] = 0;
            shema[3][i][2] = 0;
            shema[3][i][3] = 1;
            i++;
            shema[3][i][0] = 4.5f * maxim;
            shema[3][i][1] = -.1f* maxim;
            shema[3][i][2] = 0;
            shema[3][i][3] = 1;
            i++;


            shema[3][i][0] = 0;
            shema[3][i][1] = -5 * maxim;
            shema[3][i][2] = 0;
            shema[3][i][3] = 2;
            i++;

            shema[3][i][0] = 0;
            shema[3][i][1] = 5 * maxim;
            shema[3][i][2] = 0;
            shema[3][i][3] = 2;
            i++;

            shema[3][i][0] = 0;
            shema[3][i][1] = 5 * maxim;
            shema[3][i][2] = 0;
            shema[3][i][3] = 2;
            i++;

            shema[3][i][0] = 0;
            shema[3][i][1] = 4.5f * maxim;
            shema[3][i][2] = .1f* maxim;
            shema[3][i][3] = 2;
            i++;

            shema[3][i][0] = 0;
            shema[3][i][1] = 5 * maxim;
            shema[3][i][2] = 0;
            shema[3][i][3] = 2;
            i++;

            shema[3][i][0] = 0;
            shema[3][i][1] = 4.5f * maxim;
            shema[3][i][2] = -.1f* maxim;
            shema[3][i][3] = 2;

            brlinija[3]+=9;
        }


    }






    public void NapuniFunkciju()
    {
        int a;
        int b;
        float j=0;
        int i=0;
        brlinija[0]=0;
        for (a = 0; a < 20; a++)
            for (b = 0; b < 21; b++)
                FunkTalas[a][b]=fun((float) a, (float) b);
        {
            for (i = 0; i <= 2; i += 1) {


                shema[0][i + 20][0] = i / 4f * maxim;
                shema[0][i + 20][1] = -5 * maxim;
                shema[0][i + 20][2] = FunkTalas[0][i+20];
                shema[0][i + 20][3] = 4;

                shema[0][i + 21][0] = i / 4f * maxim;
                shema[0][i + 21][1] = 5 * maxim;
                shema[0][i + 21][2] = FunkTalas[0][i + 21];
                shema[0][i + 21][3] = 4;


                shema[0][i + 62][0] = -5 * maxim;
                shema[0][i + 62][1] = i / 4f * maxim;
                shema[0][i + 62][2] = FunkTalas[0][i + 62];
                shema[0][i + 62][3] = 4;

                shema[0][i + 63][0] = 5 * maxim;
                shema[0][i + 63][1] = i / 4f * maxim;
                shema[0][i + 63][2] = FunkTalas[0][i + 63];
                shema[0][i + 63][3] = 4;

                j++;
            }
            brlinija[0]=42;
            i=84;
        }

    }

    public void UcitajGaleriju(int Galerija)
    {



        String fname="";
        if(Galerija==2) fname="Dodecaedar.csv";
        if(Galerija==3) fname="Tetraedar.csv";
        if(Galerija==4) fname="Oktaedar.csv";
        if(Galerija==5) fname="Ikosaedar.csv";
            try {

                    FileHandle fh = Gdx.files.internal(fname);
                    String text = fh.readString();
                    Parse(text);

                if(Galerija==2) zumiraj=.02f;
                if(Galerija==3) zumiraj=30f;
                if(Galerija==4) zumiraj=30f;
                if(Galerija==5) zumiraj=.2f;


            }
            catch (Exception e)
            {
                BrojacPoruka=200;
                Poruka="Failed to open galery";
            }

    }
    public void OtvoriFajl()
    {

        boolean isExtAvailable = Gdx.files.isExternalStorageAvailable();

        if(isExtAvailable) // ako postoji ext memorija
        {

            String fname="ESFigure.csv";
            try {
                boolean existsF = Gdx.files.external(fname).exists();
                if (existsF)
                {
                    FileHandle fh = Gdx.files.external(fname);
                    String text = fh.readString();
                    Parse(text);
                }
                else
                {
                    BrojacPoruka=200;
                    Poruka="File ESFigure.csv does not exist!";
                }

            }
            catch (Exception e)
            {
                BrojacPoruka=200;
                Poruka="Failed to open ESFigure.csv";
            }
        }
    }


    public String PripremiStringZaSnimanje()
    {
        String a="";
        for(int ib=0;ib<brlinija[AktivnaVerzija];ib++)
        {
            String aa="";
            String bb="";
            aa = aa + Integer.toString((int)shema[AktivnaVerzija][ib*2][0]) + ",";
            bb = bb + Integer.toString((int)shema[AktivnaVerzija][ib*2+1][0]) + ",";
            aa = aa + Integer.toString((int)shema[AktivnaVerzija][ib*2][1]) + ",";
            bb = bb + Integer.toString((int)shema[AktivnaVerzija][ib*2+1][1]) + ",";
            aa = aa + Integer.toString((int)shema[AktivnaVerzija][ib*2][2]) + ",1,";
            bb = bb + Integer.toString((int)shema[AktivnaVerzija][ib*2+1][2]) + "";
            aa=aa+bb+ "\r\n";
            a=a+aa;
        }
        return a;
    }

    public void SnimiTekstFajl()
    {

        boolean isExtAvailable = Gdx.files.isExternalStorageAvailable();
        try {
        if(isExtAvailable) // ako postoji ext memorija
        {

            String fname="ESFigure.csv";

                FileHandle fh = Gdx.files.external(fname);

                fh.writeString("", false);
                for(int ib=0;ib<brlinija[AktivnaVerzija];ib++)
                {
                    String aa="";
                    String bb="";
                    aa = aa + Integer.toString((int)shema[AktivnaVerzija][ib*2][0]) + ",";
                    bb = bb + Integer.toString((int)shema[AktivnaVerzija][ib*2+1][0]) + ",";
                    aa = aa + Integer.toString((int)shema[AktivnaVerzija][ib*2][1]) + ",";
                    bb = bb + Integer.toString((int)shema[AktivnaVerzija][ib*2+1][1]) + ",";
                    aa = aa + Integer.toString((int)shema[AktivnaVerzija][ib*2][2]) + ",1,";
                    bb = bb + Integer.toString((int)shema[AktivnaVerzija][ib*2+1][2]) + "";
                    aa=aa+bb+ "\r\n";
                    fh.writeString(aa, true);
                }
                BrojacPoruka=200;
                Poruka="Saved to download\\ESFigure.csv";
            }

        }
        catch (Exception e)
        {
            BrojacPoruka=200;
            Poruka="Failed to save to download\\ESFigure.csv";
        }
    }



    public  String IzbaciOsimBr(String text) //izbaci iz stringa sve osim cifri
    {
        int i;
        int minus=0;
        String a="";
        for(i=0;i<text.length();i++)
        {
            String b=text.substring(i,i+1);
            char[] charArray = b.toCharArray();
            if(Character.isDigit(charArray[0]))
            {
                a=a.concat(b); // prenosimo samo cifre
            }
            else
                if(charArray[0]=='-')
                    minus=1;
        }
        if(minus==1)
            a="-"+a;
        return a;
    }

    public  void ParseFajl(String text)
    {
        float MaxR=0;
        int R1=0;
        int R2=0;
        int R3=0;
        int R4=0;

        int RA1=0;
        int RA2=0;
        int RA3=0;
        int RA4=0;

        String txt1="";

        int i=0;
        int j=0;
        int greska=0;
        int duzina=text.length();
        int BrRedova=0;
        int PoslednjaLinija=0;


        try {
            while (i < duzina && BrRedova < 990) {

                j = text.indexOf(",", i);
                if (j > -1) {
                    txt1 = text.substring(i, j);
                    R1 = Integer.parseInt(IzbaciOsimBr(txt1));
                    i = j + 1;

                    j = text.indexOf(",", i);
                    if (j > -1) {
                        txt1 = text.substring(i, j);
                        R2 = Integer.parseInt(IzbaciOsimBr(txt1));
                        i = j + 1;

                        j = text.indexOf(",", i);
                        if (j > -1) {
                            txt1 = text.substring(i, j);
                            R3 = Integer.parseInt(IzbaciOsimBr(txt1));
                            i = j + 1;

                            j = text.indexOf(",", i);
                            if (j > -1) {
                                txt1 = text.substring(i, j);
                                R4 = Integer.parseInt(IzbaciOsimBr(txt1));
                                i = j + 1;


                                j = text.indexOf(",", i);
                                if (j > -1) {
                                    txt1 = text.substring(i, j);
                                    RA1 = Integer.parseInt(IzbaciOsimBr(txt1));
                                    i = j + 1;
                                    j = text.indexOf(",", i);
                                    if (j > -1) {
                                        txt1 = text.substring(i, j);
                                        RA2 = Integer.parseInt(IzbaciOsimBr(txt1));
                                        i = j + 1;
                                        j = text.indexOf("\n", i);
                                        if (j > -1) {
                                            txt1 = text.substring(i, j);
                                            RA3 = Integer.parseInt(IzbaciOsimBr(txt1));
                                            i = j + 1;

                                        } else {
                                            j = text.length() - i;
                                            txt1 = text.substring(i, j);
                                            RA3 = Integer.parseInt(IzbaciOsimBr(txt1));
                                            i = j + 1;

                                        }
                                    } else {
                                        i = duzina;
                                        greska = 1;
                                    }

                                } else {
                                    i = duzina;
                                    greska = 1;
                                }
                            } else {
                                i = duzina;
                                greska = 1;
                            }

                        } else {
                            i = duzina;
                            greska = 1;
                        }

                    } else {
                        i = duzina;
                        greska = 1;
                    }

                } else {
                    PoslednjaLinija = 1;
                    if (text.length() > i + 1) {
                        j = text.length() - i;
                        txt1 = text.substring(i, j);
                        if (txt1.trim() != "") //ako nema nista vise - onda nije greska - zavrsavaj
                        {
                            i = duzina;
                            greska = 1;
                        }

                    } else
                        i = duzina;
                }
                if (greska == 0 && PoslednjaLinija == 0) {

                    BrRedova++;
                    shema[0][BrRedova - 1][0] = R1;
                    shema[0][BrRedova - 1][1] = R2;
                    shema[0][BrRedova - 1][2] = R3;
                    shema[0][BrRedova - 1][3] = R4;

                    if (Math.abs(R1) > MaxR) MaxR = Math.abs(R1);
                    if (Math.abs(R2) > MaxR) MaxR = Math.abs(R2);
                    if (Math.abs(R3) > MaxR) MaxR = Math.abs(R3);

                    BrRedova++;
                    shema[0][BrRedova - 1][0] = RA1;
                    shema[0][BrRedova - 1][1] = RA2;
                    shema[0][BrRedova - 1][2] = RA3;
                    shema[0][BrRedova - 1][3] = R4; // ponavljam R4, nema razloga da ima dve boje za jednu liniju

                    if (Math.abs(RA1) > MaxR) MaxR = Math.abs(RA1);
                    if (Math.abs(RA2) > MaxR) MaxR = Math.abs(RA2);
                    if (Math.abs(RA3) > MaxR) MaxR = Math.abs(RA3);

                }
                if (greska != 0) {
                    BrojacPoruka = 200;
                    Poruka = "Error loading file!";
                }
            }

            brlinija[0] = BrRedova / 2;


            AktivnaVerzija = 0;
            maxim = MaxR;

            zumiraj = 10f;
            Centar(0);
            NapuniGrid();
        }
        catch (Exception e) {BrojacPoruka = 200;
            Poruka = "Error in file data!";}
    }


    public  void Parse(String text)
    {
        float MaxR=0;
        int R1=0;
        int R2=0;
        int R3=0;
        int R4=0;

        int RA1=0;
        int RA2=0;
        int RA3=0;
        int RA4=0;

        String txt1="";

        int i=0;
        int j=0;
        int greska=0;
        int duzina=text.length();
        int BrRedova=0;
        int PoslednjaLinija=0;



        while(i<duzina && BrRedova<990)
        {

            j=text.indexOf(",",i);
            if(j>-1)
            {
                txt1=text.substring(i, j);
                R1= Integer.parseInt(IzbaciOsimBr(txt1));
                i=j+1;

                j=text.indexOf(",",i);
                if(j>-1)
                {
                    txt1 = text.substring(i, j);
                    R2 = Integer.parseInt(IzbaciOsimBr(txt1));
                    i = j+1;

                    j=text.indexOf(",",i);
                    if(j>-1)
                    {
                        txt1 = text.substring(i, j);
                        R3 = Integer.parseInt(IzbaciOsimBr(txt1));
                        i = j+1;

                        j=text.indexOf(",",i);
                        if(j>-1)
                        {
                            txt1 = text.substring(i, j);
                            R4 = Integer.parseInt(IzbaciOsimBr(txt1));
                            i = j+1;


                            j=text.indexOf(",",i);
                            if(j>-1)
                            {
                                txt1 = text.substring(i, j);
                                RA1 = Integer.parseInt(IzbaciOsimBr(txt1));
                                i = j + 1;
                                j=text.indexOf(",",i);
                                if(j>-1)
                                {
                                    txt1 = text.substring(i, j);
                                    RA2 = Integer.parseInt(IzbaciOsimBr(txt1));
                                    i = j + 1;
                                    j=text.indexOf("\r",i);
                                    if(j>-1)
                                    {
                                        txt1 = text.substring(i, j);
                                        RA3 = Integer.parseInt(IzbaciOsimBr(txt1));
                                        i = j + 1;

                                    }
                                    else
                                    {
                                        j=text.length()-i;
                                        txt1 = text.substring(i, j);
                                        RA3 = Integer.parseInt(IzbaciOsimBr(txt1));
                                        i = j + 1;

                                    }
                                }
                                else
                                {
                                    i=duzina;
                                    greska=1;
                                }

                            }
                            else
                            {
                                i=duzina;
                                greska=1;
                            }
                        }
                        else
                        {
                            i=duzina;
                            greska=1;
                        }

                    }
                    else
                    {
                        i=duzina;
                        greska=1;
                    }

                }
                else
                {
                    i=duzina;
                    greska=1;
                }

            }
            else
            {
                PoslednjaLinija=1;
                if(text.length()>i+1)
                {
                    j=text.length()-i;
                    txt1 = text.substring(i, j);
                    if(txt1.trim()!="") //ako nema nista vise - onda nije greska - zavrsavaj
                    {
                        i = duzina;
                        greska = 1;
                    }

                }
                else
                    i = duzina;
            }
        if(greska==0 && PoslednjaLinija==0)
            {

                BrRedova++;
                shema[0][BrRedova-1][0] = R1;
                shema[0][BrRedova-1][1] = R2;
                shema[0][BrRedova-1][2] = R3;
                shema[0][BrRedova-1][3] = R4;

                if(Math.abs(R1)>MaxR)MaxR=Math.abs(R1);
                if(Math.abs(R2)>MaxR)MaxR=Math.abs(R2);
                if(Math.abs(R3)>MaxR)MaxR=Math.abs(R3);

                BrRedova++;
                shema[0][BrRedova-1][0] = RA1;
                shema[0][BrRedova-1][1] = RA2;
                shema[0][BrRedova-1][2] = RA3;
                shema[0][BrRedova-1][3] = R4; // ponavljam R4, nema razloga da ima dve boje za jednu liniju

                if(Math.abs(RA1)>MaxR)MaxR=Math.abs(RA1);
                if(Math.abs(RA2)>MaxR)MaxR=Math.abs(RA2);
                if(Math.abs(RA3)>MaxR)MaxR=Math.abs(RA3);

            }
            if(greska!=0)
                {
                    BrojacPoruka=200;
                    Poruka="Error loading file!";
                }
        }

        brlinija[0] = BrRedova/2;


        AktivnaVerzija=0;
        maxim = MaxR;

        Centar(0);
        NapuniGrid();
    }


    private static Pixmap getScreenshot(int x, int y, int w, int h, boolean yDown)
    {
        final Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(x, y, w, h);

        if (yDown)
        {

            ByteBuffer pixels = pixmap.getPixels();
            int numBytes = w * h * 4;
            byte[] lines = new byte[numBytes];
            int numBytesPerLine = w * 4;
            for (int i = 0; i < h; i++) {
                pixels.position((h - i - 1) * numBytesPerLine);
                pixels.get(lines, i * numBytesPerLine, numBytesPerLine);
            }
            pixels.clear();
            pixels.put(lines);
        }

        return pixmap;
    }

    public  void Snimi()
    {

        boolean isExtAvailable = Gdx.files.isExternalStorageAvailable();
        try {
        if(isExtAvailable) // ako postoji ext memorija
        {






            String fname="Easy3DSketchIMG.png";

            FileHandle fh = Gdx.files.external(fname);
            Pixmap pixmap = getScreenshot(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),true);
            PixmapIO.writePNG(fh, pixmap);
            pixmap.dispose();

            BrojacPoruka=200;
            Poruka="Image saved to Easy3DSketchIMG.png";
        }
            else
        {
            BrojacPoruka=200;
            Poruka="Failed, no access to memory!";
        }
        }
        catch (Exception e)
        {
            BrojacPoruka=200;
            Poruka="Failed to save to Easy3DSketchIMG.png";
        }
    }

    public void crtajTalase() {
        int px;
        int py;
        int a;
        int b;

        float f;
        float g;
        float t1;
        float t2;
        float t3;
        float t4;

        float x1;
        float y1;

        float x2;
        float y2;

        float x3;
        float y3;

        float x4;
        float y4;

        float alfa = VelicinaS*4;//180f*MathUtils.PI;
        float beta = Velicina2S*4+vreme/80f;//180f*MathUtils.PI;
        float gama = Velicina3S*4;//180f*MathUtils.PI;


        for (a = 0; a < 20; a++)
            for (b = 0; b < 21; b++)
                FunkTalas[a][b]=fun((float) a, (float) b);

        for (a = 0; a < 20; a++)
            for (b = 0; b < 21; b++)

            {
                f=a;
                g=b;
                t1 =FunkTalas[a][b];//fun(f, g);

                t2 =FunkTalas[a+1][b];//fun(f + 1, g);

                t3 =FunkTalas[a+1][b+1];//fun(f, g + 1);

                t4 =FunkTalas[a][b+1];//fun(f + 1, g + 1);

                f = f - 10*zumiraj;
                g = g - 10*zumiraj;
                x1 = f * 10*zumiraj;
                y1 = g * 10*zumiraj;
                x2 = (f + 1) * 10*zumiraj;
                y2 = g * 10*zumiraj;
                x3 = (f + 1) * 10*zumiraj;
                y3 = (g + 1) * 10*zumiraj;
                x4 = f * 10*zumiraj;
                y4 = (g + 1) * 10*zumiraj;
                f = f + 10*zumiraj;
                g = g + 10*zumiraj;

                G3DR.ProjekcijaXY(x1, y1, t1, alfa, beta, gama);
                x1 = G3DR.x+PrviX+centarX;
                y1 = G3DR.y+PrviY+centarY;

                G3DR.ProjekcijaXY(x2, y2, t2, alfa, beta, gama);
                x2 = G3DR.x+PrviX+centarX;
                y2 = G3DR.y+PrviY+centarY;

                G3DR.ProjekcijaXY(x3, y3, t3, alfa, beta, gama);
                x3 = G3DR.x+PrviX+centarX;
                y3 = G3DR.y+PrviY+centarY;

                G3DR.ProjekcijaXY(x4, y4, t4, alfa, beta, gama);
                x4 = G3DR.x+PrviX+centarX;
                y4 = G3DR.y+PrviY+centarY;

                cetvorougao(x1, y1, x2, y2, x3, y3, x4, y4);

            }
    }


}