rotation 相关问题

旋转是物体围绕旋转中心(或点)的圆周运动。在移动设备上,它表示方向的变化。

改变对象的变换,使其父对象与其子对象相匹配

为此而疯狂。我正在尝试找出一种方法,以便当我抓取一个对象时,我可以设置该对象的旋转和位置,以便原始对象的旋转和位置

回答 1 投票 0

如何在Python中使用旋转坐标网格在Mollweide投影中绘制地图?

在Python中,我尝试在Mollweide投影中绘制全天空地图。我希望能够显示具有任意旋转坐标和坐标网格的地图。请参阅以下通用网格图像 (

回答 1 投票 0

使用Python计算两个坐标系之间的旋转矩阵,以确定UR5机器人末端执行器的目标位置

我有一个UR5 CB3机械臂,需要训练它来捡西瓜。为此,我安装了一个摄像头,用于确定西瓜相对于 TCP(或末端执行器/

回答 1 投票 0

将绕任意轴的旋转解析为绕X、Y和Z轴的旋转

我目前正在尝试利用 GLUT 库在 OpenGL 中实现虚拟轨迹球。 截至目前,我正在通过对...进行标准轨迹球计算来计算旋转轴和旋转角度。

回答 3 投票 0

如何解决卡尔曼滤波器旋转翻转问题

我会尝试使用Unity卡尔曼滤波器。但我发现了一个问题。 应用卡尔曼滤波器后,位置应用得很好。然而,旋转并没有得到很好的应用。当物体旋转(x或y...

回答 2 投票 0

在 openGL 中使用索引缓冲区绘制立方体

#包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #include <stdio.h> #include <stdlib.h> #include <string> #include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <GL/glew.h> #include <GL/glut.h> #include <GL/glm/glm.hpp> #include <GL/glm/gtx/transform.hpp> // rotate(), scale(), translate() #include <GL/glm/gtc/quaternion.hpp> #include <GL/glm/gtc/type_ptr.hpp> using namespace std; GLuint VertexArrayID; GLuint programID; float sx = 0; float sy = 0; bool projMode = true; // true: perspective, false: ortho GLuint LoadShaders(const char* vertex_file_path, const char* fragment_file_path) { //create the shaders GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER); GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER); GLint Result = GL_FALSE; int InfoLogLength; //Read the vertex shader code from the file string VertexShaderCode; ifstream VertexShaderStream(vertex_file_path, ios::in); if (VertexShaderStream.is_open()) { string Line = ""; while (getline(VertexShaderStream, Line)) VertexShaderCode += "\n" + Line; VertexShaderStream.close(); } //Compile Vertex Shader printf("Compiling shader : %s\n", vertex_file_path); char const* VertexSourcePointer = VertexShaderCode.c_str(); glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL); glCompileShader(VertexShaderID); //Check Vertex Shader glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result); glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); if (InfoLogLength > 0) { vector<char> VertexShaderErrorMessage(InfoLogLength); glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]); fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]); } //Read the fragment shader code from the file string FragmentShaderCode; ifstream FragmentShaderStream(fragment_file_path, ios::in); if (FragmentShaderStream.is_open()) { string Line = ""; while (getline(FragmentShaderStream, Line)) FragmentShaderCode += "\n" + Line; FragmentShaderStream.close(); } //Compile Fragment Shader printf("Compiling shader : %s\n", fragment_file_path); char const* FragmentSourcePointer = FragmentShaderCode.c_str(); glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL); glCompileShader(FragmentShaderID); //Check Fragment Shader glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result); glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength); if (InfoLogLength > 0) { vector<char> FragmentShaderErrorMessage(InfoLogLength); glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]); fprintf(stdout, "%s\n", &FragmentShaderErrorMessage[0]); } //Link the program fprintf(stdout, "Linking program\n"); GLuint ProgramID = glCreateProgram(); glAttachShader(ProgramID, VertexShaderID); glAttachShader(ProgramID, FragmentShaderID); glLinkProgram(ProgramID); // Check the program glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result); glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength); vector<char> ProgramErrorMessage(max(InfoLogLength, int(1))); glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]); fprintf(stdout, "%s\n", &ProgramErrorMessage[0]); glDeleteShader(VertexShaderID); glDeleteShader(FragmentShaderID); return ProgramID; } void renderScene(void) { //Clear all pixels glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Let's draw something here glBindVertexArray(VertexArrayID); //define the size of point and draw a point. glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, 0); //Double buffer glutSwapBuffers(); } void mouse(int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { projMode = !projMode; } } void init() { //initilize the glew and check the errors. GLenum res = glewInit(); if (res != GLEW_OK) { fprintf(stderr, "Error: '%s' \n", glewGetErrorString(res)); } //select the background color glClearColor(1.0, 1.0, 1.0, 1.0); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glDepthRange(0.0f, 1.0f); } GLfloat cubeVertices[] = { // front -0.1f, 0.1f, 0.1f, -0.1f,-0.1f, 0.1f, 0.1f,-0.1f, 0.1f, 0.1f, 0.1f, 0.1f, -0.1f, 0.1f, 0.1f, 0.1f,-0.1f, 0.1f, // back 0.1f, 0.1f,-0.1f, -0.1f,-0.1f,-0.1f, -0.1f, 0.1f,-0.1f, 0.1f, 0.1f,-0.1f, 0.1f,-0.1f,-0.1f, -0.1f,-0.1f,-0.1f, // left -0.1f,-0.1f,-0.1f, -0.1f,-0.1f, 0.1f, -0.1f, 0.1f, 0.1f, -0.1f,-0.1f,-0.1f, -0.1f, 0.1f, 0.1f, -0.1f, 0.1f,-0.1f, // right 0.1f, 0.1f, 0.1f, 0.1f,-0.1f,-0.1f, 0.1f, 0.1f,-0.1f, 0.1f,-0.1f,-0.1f, 0.1f,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1,1) 1 | (-1, 1, 1) 2 | (-1,-1,1) 3 | (1, -1, 1) 4 | (1, -1, -1) 5 | (1, 1, -1) 6 | (-1, 1, -1) 7 | (-1, -1, -1) */ GLfloat cubeIndices[] = { // front 0, 1, 2, 0, 1, 3, // back 5, 6, 7, 5, 6, 4, // left 1, 2, 6, 1, 2, 7, // right 0, 3, 4, 0, 4, 5, // top 0, 1, 5, 0, 1, 6, // bottom 2, 3, 4, 2, 4, 7, }; int main(int argc, char** argv) { //init GLUT and create Window //initialize the GLUT glutInit(&argc, argv); //GLUT_DOUBLE enables double buffering (drawing to a background buffer while the other buffer is displayed) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); //These two functions are used to define the position and size of the window. glutInitWindowPosition(200, 200); glutInitWindowSize(480, 480); //This is used to define the name of the window. glutCreateWindow("Simple OpenGL Window"); //call initization function init(); //0. programID = LoadShaders("VertexShader.txt", "FragmentShader.txt"); glUseProgram(programID); /**************************************************/ // model matrix glm::mat4 model = glm::mat4(1.0f); float rotateAngle = 45.0f; glm::vec3 rotateAxis(0.0f, 1.0f, 0.0f); model = glm::rotate(model, glm::radians(rotateAngle), rotateAxis); glm::vec3 scaleVec(5.0f, 5.0f, 5.0f); model = glm::scale(model, scaleVec); glm::vec3 translateVec(0.0f, 0.0f, 0.0f); model = glm::translate(model, translateVec); // view matrix glm::mat4 view = glm::lookAt(glm::vec3(5.0f, -5.0f, -5.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)); // proj matrix glm::mat4 proj; int width = glutGet(GLUT_WINDOW_WIDTH); int height = glutGet(GLUT_WINDOW_HEIGHT); if (projMode) { float aspectRatio = float(width) / height; proj = glm::perspective(glm::radians(45.0f), aspectRatio, 0.1f, 100.0f); } else { float orthoSize = 5.0f; proj = glm::ortho(-orthoSize, orthoSize, -orthoSize, orthoSize, 0.1f, 0.6f); } // model, view, proj matrix to shader GLint modelLoc = glGetUniformLocation(programID, "model"); glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); GLint viewLoc = glGetUniformLocation(programID, "view"); glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view)); GLint projLoc = glGetUniformLocation(programID, "proj"); glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(proj)); /**************************************************/ glGenVertexArrays(1, &VertexArrayID); glBindVertexArray(VertexArrayID); float vtxs[] = { -0.5, 0.0, 0.0, 0.5, 0.3, 0.0 }; GLuint VBOs[3]; glGenBuffers(3, VBOs); glBindBuffer(GL_ARRAY_BUFFER, VBOs[0]); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 3 * 2 * 6, cubeVertices, GL_STATIC_DRAW); GLuint posAttribLoc = glGetAttribLocation(programID, "inPos"); glVertexAttribPointer(posAttribLoc, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0)); glEnableVertexAttribArray(posAttribLoc); glBindBuffer(GL_ARRAY_BUFFER, VBOs[1]); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 4 * 3 * 2 * 6, cubeColors, GL_STATIC_DRAW); GLuint colAttribLoc = glGetAttribLocation(programID, "color"); glVertexAttribPointer(colAttribLoc, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0)); glEnableVertexAttribArray(colAttribLoc); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBOs[2]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(float) * 6 * 6, cubeIndices, GL_STATIC_DRAW); GLuint idxAttribLoc = glGetAttribLocation(programID, "index"); glVertexAttribPointer(idxAttribLoc, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)(0)); glEnableVertexAttribArray(idxAttribLoc); glutDisplayFunc(renderScene); glutMouseFunc(mouse); //enter GLUT event processing cycle glutMainLoop(); glDeleteVertexArrays(1, &VertexArrayID); return 1; } 我想用上面的代码绘制一个 3D 立方体,但我得到一个白色的窗口。如何在窗口上显示 3D 立方体? 如果我对 VBO 和 IBO 使用像“VBOs”这样的数组,如上面的代码所示,会出现问题吗? 另外,你能告诉我如何绘制多个立方体吗? 最后,如果您告诉我我的代码中还有其他问题,我将非常感谢您。 我是一个完全的初学者,说实话,我并不完全理解图形管道。但我真的很感谢你对我的作业的帮助。 type的参数glDrawElements为整数1。 您已将索引定义为实数数组: GLfloat cubeIndices[] = { // front 0, 1, 2, 因此,当 glDrawElements 工作并读取 cubeIndices 的内存时,它会遇到一些巨大的值(例如,整数值 1 作为浮点数为 0x3f80'0000)。您定义的索引完全不在顶点属性数组确定的范围内。

回答 1 投票 0

如何在 Godot 4 中正确应用补间到 3D 旋转?

我有一个 Node3D,我想平滑地过渡到某个目标旋转(以欧拉角(以度为单位)给出)。 当我在欧拉角 ve 的所有 3 个维度上手动应用 lerp(...) 时...

回答 1 投票 0

如何在android中按Y轴旋转View?

在我的应用程序中,我想通过 setRotationY() 旋转 ImageView。事实上,确实如此。就像从b到d一样,镜像效果,当我在setRotationY()之前使用setRotation(45)时,结果是setRot...

回答 3 投票 0

在Python中根据数据旋转一维函数绘制曲面

我有一个代表径向密度 f(r) 及其相应 r 值的点数据集(基本上我有两个数组)。我想用这些点在 matplolib 中绘制一个曲面,制作一个

回答 1 投票 0

如何在pygame中的按键上旋转多边形?

我正在尝试使我的多边形能够旋转。但是当我输入 new_point 时,报告是 new_point 未定义。这让我很头疼 def xoay_hinh(键): lx, ly = zip(*hinh) 分钟_x,分钟...

回答 1 投票 0

绕垂直轴旋转 45 度元素

我有一系列元素,如下图所示: 它们向一侧旋转 45 度(内部内容 -45 度,保持直立)。 现在我想围绕

回答 4 投票 0

在 Unity 中,围绕另一个对象旋转一个对象就像在场景编辑器中按住 Alt 并单击左键进行旋转

我尝试过组合两个RotateAround,然后读取鼠标偏移量,但是当它到达顶部时它会剧烈摇晃。我尝试将其锁定在90度,但还是不行。我没有……

回答 1 投票 0

在pygame中旋转命中框矩形

我目前正在构建一个自上而下的赛车,但是我正在尝试与静态方形物体进行准确的碰撞检测。 最好的方法是什么? 这是我的代码的一部分: ...

回答 2 投票 0

旋转 90 并使用 ffmpeg 连接视频

我有几个以横向和纵向模式制作的视频。我想将它们连接成一部电影。 为此,我旋转了肖像视频: ffmpeg -i in.mp4 -vf transpose=1 out.mp4 建造了

回答 1 投票 0

使用四元数和 scipy.spatial.transform.Rotation 进行 6 自由度模拟旋转

我正在为遥控水下航行器(ROV)编写一个简单的模拟器。我想使用四元数的 scipy 实现,而不是之前基于构造旋转的方法

回答 1 投票 0

android图像旋转x轴

我找到了很多解决方案如何相对于点旋转图像,例如whis。 但我需要相对于 x 轴旋转图像,就像这样。 任何帮助表示赞赏。

回答 2 投票 0

为什么两个不同的旋转矩阵在点积到向量时会给出相同的结果?

我有两个不同的旋转矩阵,当将它们点积为向量时,我得到了相同的结果。这是什么意思? 这是旋转矩阵和向量 向量 = [-7.74299796, 7.

回答 1 投票 0

使用 python opencv 绕任意点旋转后将图像裁剪到新的四个角

如何绕图像中心旋转有很多答案,但如何绕原始图像中的任意点旋转并在旋转后将新的旋转图像裁剪到新的四个角...

回答 1 投票 0

在 UIKit 中将最上面的标签添加到旋转轮的中心

我正在用 Swift 语言完成一项作业。我正在尝试实现具有旋转轮视图的功能,并且将多个标签添加为轮子周围的项目。我可以旋转

回答 1 投票 0

旋转传单中的标记

如何旋转传单中的标记?我将有很多标记,所有标记都有旋转角度。 我已经在 GitHub 上的 Leaflet 上尝试过 runanet/coomsie 的解决方案,但我的市场没有任何反应...

回答 5 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.