1

I am wondering if there is a way to update and move a triangle in OpenGL ES using the vertices. These are the vertices of my triangle:

// in counterclockwise order :

static float triangleCoords[] = {
        0.0f,  0.622008459f, 0.0f,  // top
        -0.5f, -0.311004243f, 0.0f, // bottom left
        0.5f, -0.311004243f, 0.0f   // bottom right
}; 

I wanted to know if it was possible to move the triangle without the matrices.

Thank you!

Nikola Lukic
  • 4,001
  • 6
  • 44
  • 75
Acg N
  • 11
  • 1
  • See: [Android OpenGL ES and 2D](https://stackoverflow.com/q/3553244/295004) Note that asking for tutorials is off-topic (and OpenGL ES programming is a full course/book on its own) – Morrison Chang May 28 '19 at 03:14

2 Answers2

0

Yes it's possible, however it's basically pointless. The fastest way to transform vertices is with a matrix, and there happens to be specialised circuitry on the GPU to make this extremely fast. So if you want to transform and update those vertices yourself, just modify the vertex values prior to submission. It will however be far slower than transforming them in a vertex shader via a matrix.

robthebloke
  • 9,331
  • 9
  • 12
0

Ok i will present you some of my idea (I use ECMA6). Change every number with methods with return. Then in class (model) define what ever you want.

First use class based coding avoid procedural. webGL2 project - object oriented

      class Scale {
    
        constructor() {
    
            this.x = 1;
            this.y = 1;
            this.z = 1;
    
        }
    
        LinearScale(scale_) {
    
            this.x = scale_;
            this.y = scale_;
            this.z = scale_;
    
        }
    
    }
    
        class Point {
    
        constructor(x, y, z) {
    
            if (typeof z == 'undefined') {
                z = 0;
            }
    
            this.x = x;
            this.y = y;
            this.z = z;
            this.scale = new Scale();
    
        }
    
        get X() {
            return parseFloat(this.x * this.scale.x);
        }
        get Y() {
            return parseFloat(this.y * this.scale.y);
        }
        get Z() {
            return parseFloat(this.z * this.scale.z);
        }
    
    }


class TriangleVertex {

    constructor(root) {

        this.root = root;
        this.size = root.size;
        this.dynamicBuffer = App.dynamicBuffer;
        this.pointA = new Point(0.0, 1, 0.0);
        this.pointB = new Point(-1, -1, 0);
        this.pointC = new Point(1, -1, 0);

    }

    // GETTER
    get vertices() {

        return new Float32Array([
                this.pointA.X, this.pointA.Y * this.root.size, this.pointA.Z,

                this.pointB.X * this.root.size, this.pointB.Y * this.root.size, this.pointB.Z,

                this.pointC.X * this.root.size, this.pointC.Y * this.root.size, this.pointC.Z
            ]);

    }

    setScale(scale) {

        this.size = scale;

        if (this.dynamicBuffer == true)
            return;

        App.operation.triangle_buffer_procedure(this.root)

        return 'dynamicBuffer is false but i will update vertex array prototypical.';

    }

}

class Position {

    constructor(x, y, z) {
        //super()

        if (typeof x == 'undefined') {
            x = 0;
        }
        if (typeof y == 'undefined') {
            y = 0;
        }
        if (typeof z == 'undefined') {
            z = 0;
        }

        this.x = x;
        this.y = y;
        this.z = z;

        return this;

    }

    get worldLocation() {

        return [this.x, this.y, this.z];

    }

    SetX(newx) {

        this.x = newx;

    }

    SetY(newy) {

        this.y = newy;

    }

    SetZ(newz) {

        this.z = newz;

    }

    setPosition(newx, newy, newz) {

        this.x = newx;
        this.y = newy;
        this.z = newz;

    }

}
Nikola Lukic
  • 4,001
  • 6
  • 44
  • 75