有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用顶点在opengles中移动对象?

我想知道是否有一种方法可以使用顶点在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
}; 

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

谢谢!


共 (1) 个答案

  1. # 1 楼答案

    好的,我将向您介绍我的一些想法(我使用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;
    
        }
    
    }