Why my mesh vertices are moved by the same offset and not by offset calculated by bezier curve

I have a tough one (I think) problem. I am prepearing a game with a part, which is a race. I want to make it similar to oldschool "Lotus" games. Player will see a car from behind, a a road should have turns from time to time. So my idea is to make a Mesh (road), which will have updated vertexes based on bezier curve. A game should check every vertex on the left edge of the mesh and check how much should it be moved to left or right. Same for right edge. Below is my code based on:

http://www.andengine.org/forums/post47301.html?hilit=%20mesh#p47301

Calculations of bezier curve are taken from QuadraticBezierCurveMoveModifier included in andEngine.

private Mesh createRoad(){

    //create triangles
    //
    //   E--F
    //   |\ |
    //   B--D
    //   |\ |
    //   A--C

    final int triangleCount = 10;
    int i = 0;
    final float pInitialX = 0;
    float pInintialY = 0;
    int vertexCount = Mesh.VERTEX_SIZE * triangleCount * 4;
    final float pColor = new Color(0f,0f,0f).getABGRPackedFloat();
    final float pBufferData[] = new float[vertexCount];

    for(int triangleIndex = 0; triangleIndex < triangleCount; triangleIndex++){

        pBufferData[(i * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_X] = pInitialX;
        pBufferData[(i * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_Y] = pInintialY;
        pBufferData[(i * Mesh.VERTEX_SIZE) + Mesh.COLOR_INDEX] = pColor;

        pBufferData[((i+1) * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_X] = pInitialX;
        pBufferData[((i+1) * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_Y] = pInintialY + 30;
        pBufferData[((i+1) * Mesh.VERTEX_SIZE) + Mesh.COLOR_INDEX] = pColor;

        pBufferData[((i+2) * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_X] = pInitialX + 200;
        pBufferData[((i+2) * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_Y] = pInintialY; 
        pBufferData[((i+2) * Mesh.VERTEX_SIZE) + Mesh.COLOR_INDEX] = pColor;

        pBufferData[((i+3) * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_X] = pInitialX + 200;
        pBufferData[((i+3) * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_Y] = pInintialY + 30;    
        pBufferData[((i+3) * Mesh.VERTEX_SIZE) + Mesh.COLOR_INDEX] = pColor;

        i = i + 4;
        pInintialY = pInintialY + 30;


    }

    final VertexBufferObjectManager vbom = engine.getVertexBufferObjectManager();
    final HighPerformanceMeshVertexBufferObject pMeshVBOM = new HighPerformanceMeshVertexBufferObject(vbom, pBufferData, pBufferData.length, DrawType.STREAM, true, Mesh.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT);

    road = new Mesh(300, 50, vertexCount, DrawMode.TRIANGLE_STRIP, pMeshVBOM){

        @Override
        protected void onManagedUpdate(final float pSecondsElapsed) {
            super.onManagedUpdate(pSecondsElapsed);
            drawByBezier();
            onUpdateVertices();
            this.mMeshVertexBufferObject.setDirtyOnHardware();

        };

        void drawByBezier(){
            float pBuff[] = pMeshVBOM.getBufferData();
            int i = 0;
            for (int triangleIndex = 0; triangleIndex < triangleCount; triangleIndex++) {

                pBuff[(i * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_X] = getBezierX(i, 100, 0, 0);
                pBuff[((i+1) * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_X] = getBezierX(i+1, 0, 0, 0);
                pBuff[((i+2) * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_X] = getBezierX(i+2, 0, 0, 0) + 200;
                pBuff[((i+3) * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_X] = getBezierX(i+3, 0, 0, 0) + 200;


                i = i + 4;



            }
        }
        float bezierX; 

        float getBezierX(int triangleIndex, float P1X, float PcX, float P2X){

            float t = triangleIndex / (triangleCount * 4);
            float u = 1 - t; 
            float tt = t * t; 
            float uu = u * u; 
            float ut2 = 2 * u * t; 


            return bezierX = (uu * P1X) + (ut2 * PcX) + (tt * P2X);
        }

    };


    return road;
}

Results are: When I put (i,0,0,0) in all getBezierX() (for all vertices:

https://www.dropbox.com/s/upuyjti66rtm44i/Screenshot_2015-05-07-15-02-17.png?dl=0

When I put (i, 100, 0, 0) for first one getBezierX() the result is:

https://www.dropbox.com/s/w3231zxrwytot71/Screenshot_2015-05-07-15-03-41.png?dl=0

As you can see all first vertexes are moved by the same offset to the right (100). It does not matter what are other parameters, it is always moved by value of the first parameter. Why is that? Do I miss anything here?

EDIT

To clarify. I want to make this black block to be curved like a turn on the road. So its left and right edge should be curved. I wannt to use bezier curve to calculate x position of every vertice of every triangle of a mesh used. y positions should be same as they are. A mesh diagram is commented in the begining of the code. Co I would like to position points A, B , E along one curve , and C, D, F along another moved to the right.

Answers


Ok I found a problem but I dont really understand why it was a problem. So in:

float getBezierX(int triangleIndex, float P1X, float PcX, float P2X){

        float t = triangleIndex / (triangleCount * 4);
        float u = 1 - t; 
        float tt = t * t; 
        float uu = u * u; 
        float ut2 = 2 * u * t; 


        return bezierX = (uu * P1X) + (ut2 * PcX) + (tt * P2X);
    }

I changed float getBezierX(int triangleIndex, float P1X, float PcX, float P2X) to float getBezierX(float triangleIndex, float P1X, float PcX, float P2X)and it works now. But why the int was a problem?


Need Your Help

QT and C#: Can I mix them for mobile development?

c# qt mobile

I heard, c#.net and QT can be mixed for mobile development. I shall like to share of your experience with the same.

C# udpclient/udp socket — working locally but not on global addresses

c# udp

I have a very annoying problem. I have a mIRC/Skype application, meaning chatroom with text and voice. The text &amp; chatroom stuff goes through TCP and works flawlessly, while the UDP only relays

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.