【问题标题】:How do I move an object in opengles using vertices?如何使用顶点在opengles中移动对象?
【发布时间】:2019-05-28 00:22:11
【问题描述】:

我想知道是否有一种方法可以使用顶点在 OpenGL ES 中更新和移动三角形。这些是我三角形的顶点:

// 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
}; 

我想知道是否可以在没有矩阵的情况下移动三角形。

谢谢!

【问题讨论】:

  • 参见:Android OpenGL ES and 2D 请注意,要求教程是题外话(而 OpenGL ES 编程本身就是一门完整的课程/书)

标签: java android opengl-es


【解决方案1】:

是的,这是可能的,但基本上没有意义。转换顶点的最快方法是使用矩阵,而 GPU 上恰好有专门的电路来使这个速度非常快。因此,如果您想自己转换和更新这些顶点,只需在提交之前修改顶点值即可。然而,它比通过矩阵在顶点着色器中转换它们要慢得多。

【讨论】:

    【解决方案2】:

    好的,我将向您介绍我的一些想法(我使用 ECMA6)。使用返回方法更改每个数字。然后在类(模型)中定义你想要的。

    首先使用基于类的编码避免程序化。 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;
    
        }
    
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-28
      • 1970-01-01
      • 1970-01-01
      • 2017-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多