简体   繁体   English

OpenGL3 围绕自身中心旋转 object

[英]OpenGL3 Rotate object around itself center

Ill try to rotate object in openGL (using OpenTK framework), but he rotate around zero point.我将尝试在 openGL 中旋转 object(使用 OpenTK 框架),但他围绕零点旋转。 Its logicly that object rotating around center, but i dont known how shoud hes rotating aroud itself center (or other point)从逻辑上讲,object 围绕中心旋转,但我不知道他应该如何围绕自己的中心(或其他点)旋转

    public static void Texture(Region region, float x, float y, float z, float rotateX, float rotateY, float rotateZ)
        => Texture(
            region,
            Matrix4.CreateTranslation(x, y, z),
            Matrix4.CreateRotationX(rotateX) * Matrix4.CreateRotationY(rotateY) * Matrix4.CreateRotationZ(rotateZ),
            TestGame.Camera.GetViewMatrix(),
            TestGame.Camera.GetProjectionMatrix()
            );
    public static void Texture(Region region, Matrix4 translate, Matrix4 model, Matrix4 view, Matrix4 projection)
    {
        Shaders.TextureShader.Texture(TextureUnit.Texture0); //Bind texture as 0 in shader
        region.Reference.Use(); //Bind texture as 0

        Shaders.TextureShader.Matrix4("translate", translate);
        Shaders.TextureShader.Matrix4("model", model);
        Shaders.TextureShader.Matrix4("view", view);
        Shaders.TextureShader.Matrix4("projection", projection);
        Shaders.TextureShader.Draw();
    }
#version 330 core

layout(location = 0) in vec3 aPosition;
layout(location = 1) in vec2 aTexCoord;

out vec2 texCoord;

uniform mat4 translate;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main(void)
{
    texCoord = aTexCoord;

    gl_Position = vec4(aPosition, 1) * translate * model * view * projection;
}

Matrix multiplications are not Commutative , the order mattes.矩阵乘法不是可交换的,顺序很重要。 Rotate the object before translating it:在翻译之前旋转 object:

gl_Position = vec4(aPosition, 1) * translate * model * view * projection;

gl_Position = vec4(aPosition, 1) * model * translate * view * projection;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM