相关疑难解决方法(0)

如何从头开始用人类可读的角度组成旋转矩阵?

总是阻碍我做3D编程的一件事是无法理解数学是如何工作的.我可以使用方法和函数在编程流程中使用数学,然后它对我来说都是清晰和合乎逻辑的,但在数学符号中,我无法从它做出正面或反面.

我一直在阅读网站,观看研究所试图解释这个问题的视频,但他们都使用数学符号,我只是迷失在其中,我的思想不会将其转化为可理解的东西.我可能有缺陷.

另外,只是使用某人的代码不是我的兴趣,我想了解它背后的机制,逻辑.我很乐意使用其他人的代码,但我真的想了解它是如何工作的.

这个问题

你能用简单的术语向我解释没有数学符号,只是编程符号/函数/伪代码,如何沿所有3轴实现矩阵变换?

理想情况下我想要的是编写方法/对象的材料/理解,我可以在其中定义3个轴的角度,类似于glRotate,以旋转我所拥有的四边形/三角形的集合.(我正在尝试编写立方体形状的3D旋转而无需访问OpenGL函数来为我执行此操作,因为每次在显示列表中发生更改时,都会在一次绘制调用中完成.)

我做了什么?

我试图制作一个90度的变换函数来获得数学的悬念,但是在制作一个理论上最简单的矩阵时却完全失败了.你可以在http://jsfiddle.net/bLfg0tj8/5/看到我失败的尝试.

Vec3 = function(x,y,z) {
    this.x = x;
    this.y = y;
    this.z = z;
}
Matrix = function Matrix() {
    this.matrixPoints = new Array();    
    this.rotationPoint = new Vec3(0,0,0);
    this.rotationAngle = 90;
}
Matrix.prototype.addVector = function(vector) {
    this.matrixPoints.push(vector);
}
Matrix.prototype.setRotationPoint = function(vector) {
    this.rotationPoint = vector; 
}
Matrix.prototype.setRotationAngle = function(angle) {
    this.rotationAngle = angle;
}
Matrix.prototype.populate = function() {
    translateToOrigin =     [[1,0,0-this.rotationPoint.x],
                                  [0,1,0-this.rotationPoint.y],
                                  [0,0,0-this.rotationPoint.z]];
    rotationMatrix =         [[0,-1,0],
                                  [0,1,0],
                                  [0,0,1]];
    translateEnd …
Run Code Online (Sandbox Code Playgroud)

opengl math 3d matrix

23
推荐指数
1
解决办法
6941
查看次数

OpenGL - OBJ中的顶点法线

我想知道如何使用顶点法线来实现闪电效果?目前我所拥有的是我可以将顶点和纹理坐标发送到着色器并使用它们但是使用法线,我不知道如何在着色器程序中使用它们.以下是我到目前为止的情况.

    // vertex shader
    layout(location = 0) in vec4 vert;
    layout(location = 1) in vec4 color;
    layout(location = 2) in vec2 texcoord;
    uniform mat4 m_model;
    uniform mat4 m_view;
    uniform mat4 m_proj;
    void main() {
        gl_Position = m_proj * m_view * m_model * vert;
    }

    // fragment shader
    in vec2 fragtexcoord;
    out vec4 color;
    uniform sampler2D textureunit;
    void main(void) {
        color = texture(textureunit, fragtexcoord);
    }
Run Code Online (Sandbox Code Playgroud)

编辑 以下是我的着色器.

顶点着色器

    layout(location = 0) in vec4 vert;
    layout(location = 1) in vec4 color;
    layout(location …
Run Code Online (Sandbox Code Playgroud)

c++ opengl shader opengl-es wavefront

5
推荐指数
1
解决办法
3216
查看次数

标签 统计

opengl ×2

3d ×1

c++ ×1

math ×1

matrix ×1

opengl-es ×1

shader ×1

wavefront ×1