我想知道缩放和轨道运行出了什么问题

2024-01-28

我希望能够平移、缩放和绕立方体旋转。我想知道为什么立方体在屏幕上显示为完全缩放,以至于我必须向后移动才能查看整个立方体。我还想将缩放控件更改为 Alt 和鼠标右键以进行缩放和轨道旋转,但我无法让它工作。任何援助将不胜感激。

/*/header inclusions*/
#include <iostream> // Includes C++ i/o stream
#include <GL/glew.h> // Includes glew header
#include <GL/freeglut.h> // Includes freeglut header

// GLM Math inclusions
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include<glm/gtc/type_ptr.hpp>

using namespace std; // Uses the standard namespace

#define WINDOW_TITLE "Modern OpenGL" // Macro for window title

//Vertex and fragment shader
#ifndef GLSL
#define GLSL(Version, source) "#version " #Version "\n" #source
#endif


// Variables for window width and height
GLint ShaderProgram, WindowWidth = 800, WindowHeight = 600;
GLuint VBO, VAO;

GLfloat cameraSpeed = 0.0005f;

GLchar currentKey;

GLfloat lastMouseX = 400, lastMouseY = 300;
GLfloat mouseXOffset, mouseYOffset, yaw = 0.0f, pitch = 0.0f;
GLfloat sensitivity = 0.5f;
bool mouseDetected = true;


//global vectors declaration
glm::vec3 cameraPosition = glm::vec3(0.0f,0.0f,0.0f);
glm::vec3 CameraUpY = glm::vec3(0.0f,1.0f,0.0f);
glm::vec3 CameraForwardZ = glm::vec3(0.0f,0.0f,-1.0f);
glm::vec3 front;


/* User-defined Function prototypes to:*/
void UResizeWindow(int,int);
void URenderGraphics(void);
void UCreateShader(void);
void UCreateBuffers(void);
void UKeyboard(unsigned char key, int x, int y);
void UKeyReleased(unsigned char key, int x, int y);
void UMouseMove(int x, int y);

/*Vertex shader source code*/
const GLchar * vertexShaderSource = GLSL(330,
layout(location=0) in vec3 position;
layout(location=1) in vec3 color;

out vec3 mobileColor; //declare a vec 4 variable

//Global variables for the transform matrices
    uniform mat4 model;
    uniform mat4 view;
    uniform mat4 projection;

 void main(){
        gl_Position = projection * view * model * vec4(position, 1.0f);//transform vertices
            mobileColor = color;
        }
);


/*Fragment shader program source code*/
const GLchar * fragmentShaderSource = GLSL(330,
in vec3 mobileColor;

out vec4 gpuColor;//out vertex_Color;

    void main(){

      gpuColor = vec4 (mobileColor, 1.0);

    }
);


//main program
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(WindowWidth, WindowHeight);
glutCreateWindow(WINDOW_TITLE);

glutReshapeFunc(UResizeWindow);


glewExperimental = GL_TRUE;
    if (glewInit()!= GLEW_OK)
    {
    std::cout << "Failed to initialize GLEW" << std::endl;
    return -1;
    }

    UCreateShader();

    UCreateBuffers();

    // Use the Shader program
    glUseProgram(ShaderProgram);


    glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color

    glutDisplayFunc(URenderGraphics);

    glutKeyboardFunc(UKeyboard);

    glutKeyboardUpFunc(UKeyReleased);

    glutPassiveMotionFunc(UMouseMove);

    glutMainLoop();

    // Destroys Buffer objects once used
    glDeleteVertexArrays(1, &VAO);
    glDeleteBuffers(1, &VBO);

    return 0;

}

/* Resizes the window*/
void UResizeWindow(int w, int h)
{
WindowWidth = w;
    WindowHeight = h;
    glViewport(0, 0, WindowWidth, WindowHeight);
 }


 /* Renders graphics */
void URenderGraphics(void)
{

    glEnable(GL_DEPTH_TEST); // Enable z-depth

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clears the screen

    glBindVertexArray(VAO); // Activate the Vertex Array Object before rendering and transforming them

    //camera movement logic
    if(currentKey == 'w')
        cameraPosition += cameraSpeed * CameraForwardZ;

    if(currentKey == 's')
            cameraPosition -= cameraSpeed * CameraForwardZ;

    if(currentKey == 'a')
        cameraPosition -= glm::normalize(glm::cross(CameraForwardZ, CameraUpY)) * cameraSpeed;

    if(currentKey == 'd')
            cameraPosition += glm::normalize(glm::cross(CameraForwardZ, CameraUpY)) * cameraSpeed;
            CameraForwardZ = front;

    // Transforms the object
    glm::mat4 model;
    model = glm::translate(model, glm::vec3(0.0, 0.0f, 0.0f)); // Place the object at the center of the 7i,p9rA
    model = glm::rotate(model, 45.0f, glm::vec3(1.0, 1.0f, 1.0f)); // Rotate the object 45 degrees on the XYZ
    model = glm::scale(model, glm::vec3(1.0f, 1.0f, -1.0f)); // Increase the object size by a scale of 2

    // Transforms the camera
    glm::mat4 view;
    view = glm::lookAt(cameraPosition, cameraPosition + CameraForwardZ, CameraUpY); //Moves the world 0.5 units on X and -5 units in Z

    // Creates a perspective projection
    glm::mat4 projection;
    projection = glm::perspective(45.0f, (GLfloat)WindowWidth / (GLfloat)WindowHeight, 0.1f, 100.0f);

    // Retrieves and passes transform matrices to the Shader program
    GLint modelLoc = glGetUniformLocation(ShaderProgram, "model");
    GLint viewLoc = glGetUniformLocation(ShaderProgram, "view");
    GLint projLoc = glGetUniformLocation(ShaderProgram, "projection");

    glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
    glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
    glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection));

    glutPostRedisplay();

// Draws the triangles
    glDrawArrays(GL_TRIANGLES,0, 36);

    glBindVertexArray(0); // Deactivate the Vertex Array Object

    glutSwapBuffers(); // Flips the the back buffer with the front buffer every frame. Similar to GL FLush

 }

 /*Creates the Shader program*/
 void UCreateShader()
 {

    // Vertex shader
    GLint vertexShader = glCreateShader(GL_VERTEX_SHADER); // Creates the Vertex Shader
    glShaderSource(vertexShader, 1, &vertexShaderSource, NULL); // Attaches the Vertex Shader to the source code
    glCompileShader(vertexShader); // Compiles the Vertex Shader

    // Fragment Shader
    GLint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); // Creates the Fragment Shader
    glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);// Attaches the Fragment Shader to the source code
    glCompileShader(fragmentShader); // Compiles the Fragment Shader

    // Shader program
    ShaderProgram = glCreateProgram(); // Creates the Shader program and returns an id
    glAttachShader(ShaderProgram, vertexShader); // Attach Vertex Shader to the Shader program
    glAttachShader(ShaderProgram, fragmentShader);; // Attach Fragment Shader to the Shader program
    glLinkProgram(ShaderProgram); //Link Vertex and Fragment shader, to Shader program

    // Delete the Vertex and Fragment shaders once linked
    glDeleteShader(vertexShader);
    glDeleteShader(fragmentShader);

 }


/*creates the buffer and array object*/
 void UCreateBuffers()
 {

     //position and color data
     GLfloat vertices[] = {
                        //vertex positions and colors
                    -0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
                     0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
                     0.5f,  0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
                     0.5f,  0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
                    -0.5f,  0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
                    -0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,

                    -0.5f, -0.5f,  0.5f, 0.0f, 1.0f, 0.0f,
                     0.5f, -0.5f,  0.5f, 0.0f, 1.0f, 0.0f,
                     0.5f,  0.5f,  0.5f, 0.0f, 1.0f, 0.0f,
                     0.5f,  0.5f,  0.5f, 0.0f, 1.0f, 0.0f,
                    -0.5f,  0.5f,  0.5f, 0.0f, 1.0f, 0.0f,
                    -0.5f, -0.5f,  0.5f, 0.0f, 1.0f, 0.0f,

                    -0.5f,  0.5f,  0.5f, 0.0f, 0.0f, 1.0f,
                    -0.5f,  0.5f, -0.5f, 0.0f, 0.0f, 1.0f,
                    -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f,
                    -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f,
                    -0.5f, -0.5f,  0.5f, 0.0f, 0.0f, 1.0f,
                    -0.5f,  0.5f,  0.5f, 0.0f, 0.0f, 1.0f,

                     0.5f,  0.5f,  0.5f, 1.0f, 1.0f, 0.0f,
                     0.5f,  0.5f, -0.5f, 1.0f, 1.0f, 0.0f,
                     0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 0.0f,
                     0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 0.0f,
                     0.5f, -0.5f,  0.5f, 1.0f, 1.0f, 0.0f,
                     0.5f,  0.5f,  0.5f, 1.0f, 1.0f, 0.0f,

                    -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 1.0f,
                     0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 1.0f,
                     0.5f, -0.5f,  0.5f, 0.0f, 1.0f, 1.0f,
                     0.5f, -0.5f,  0.5f, 0.0f, 1.0f, 1.0f,
                    -0.5f, -0.5f,  0.5f, 0.0f, 1.0f, 1.0f,
                    -0.5f, -0.5f, -0.5f, 0.0f, 1.0f, 1.0f,

                    -0.5f,  0.5f, -0.5f, 1.0f, 0.0f, 1.0f,
                     0.5f,  0.5f, -0.5f, 1.0f, 0.0f, 1.0f,
                     0.5f,  0.5f,  0.5f, 1.0f, 0.0f, 1.0f,
                     0.5f,  0.5f,  0.5f, 1.0f, 0.0f, 1.0f,
                    -0.5f,  0.5f,  0.5f, 1.0f, 0.0f, 1.0f,
                    -0.5f,  0.5f, -0.5f, 1.0f, 0.0f, 1.0f,

                };


     //Generate buffer id,
    glGenVertexArrays(1, &VAO);
    glGenBuffers(1,&VBO);


// Activate the Vertex Array Object before binding and setting any VB0s and Vertex Attribute Pointers.
    glBindVertexArray(VAO);

    // Activate the VBO
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); //Copy vertices to VBO

// Set attribute pointer 0 to hold Position data
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);
glEnableVertexAttribArray(0); // Enables vertex attribute

// Set attribute pointer 1 to hold Color data
 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
 glEnableVertexAttribArray(1); // Enables vertex attribute

glBindVertexArray(0); // Deactivates the VAC, which is good practice

}


 //implement the UKeyboard function
 void UKeyboard(unsigned char key, GLint x, GLint y)
 {
     switch(key){
                 case 'w':
                     currentKey = key;
                     cout<<"You Pressed W"<<endl;
                     break;

                case 's':
                     currentKey = key;
                     cout<<"You Pressed S"<<endl;
                     break;

             case 'a':
                     currentKey = key;
                     cout<<"You Pressed A"<<endl;
                     break;

            case 'd':
                     currentKey = key;
                     cout<<"You Pressed D"<<endl;
                     break;

            default:
                cout<<"Press a key!"<<endl;
     }

 }

     //implement the UKeyReleased function
 void UKeyReleased(unsigned char key, GLint x, GLint y)
  {
     cout<<"Key Released!"<<endl;
         currentKey = '0';
  }

 //implement UMouseMove function
 void UMouseMove(int x, int y)
   {

         if(mouseDetected)
         {
             lastMouseX = x;
             lastMouseY = y;
             mouseDetected = false;
         }

     //get the direction mouse was moved
         mouseXOffset = x - lastMouseX;
        mouseYOffset = lastMouseY - y;

        //update new coordinates
        lastMouseX = x;
        lastMouseY = y;

        //apply sensitivity
        mouseXOffset *= sensitivity;
        mouseYOffset *= sensitivity;

        //accumulate yaw and pitch
        yaw += mouseXOffset;
        pitch += mouseYOffset;

        //maintain 90 degree pitch
        if (pitch > 89.0f)
             pitch = 89.0f;

        if (pitch > -89.0f)
             pitch = -89.0f;

        //convert mouse coordinates
        front.x = cos(glm::radians(pitch)) * cos(glm::radians(yaw));
        front.y = sin(glm::radians(pitch));
        front.z = cos(glm::radians(pitch)) * sin(glm::radians(yaw));

   }

从相机位置开始,该位置沿 z 轴正方向平移(例如 (0, 0, 10))。front必须初始化:

glm::vec3 cameraPosition = glm::vec3(0.0f,0.0f,10.0f);
glm::vec3 CameraUpY      = glm::vec3(0.0f,1.0f,0.0f);
glm::vec3 CameraForwardZ = glm::vec3(0.0f,0.0f,-1.0f);
glm::vec3 front          = glm::vec3(0.0f,0.0f,-1.0f);

您必须初始化模型矩阵变量glm::mat4 model.

The glm API 文档 https://glm.g-truc.net/0.9.8/api/index.html指的是OpenGL 着色语言规范 4.20 https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.20.pdf.

5.4.2 向量和矩阵构造函数

如果向量构造函数有一个标量参数,则它用于将构造向量的所有组件初始化为该标量的值。如果矩阵构造函数有一个标量参数,则它用于初始化矩阵对角线上的所有分量,其余分量初始化为 0.0。

这意味着,一个单位矩阵 https://en.wikipedia.org/wiki/Identity_matrix可以通过单个参数1.0来初始化:

glm::mat4 model(1.0f);

角度的单位为OpenGL数学 https://glm.g-truc.net/0.9.9/index.html是弧度而不是角度。 (glm::perspective, glm::rotate):

// Transforms the object
glm::mat4 model(1.0f);
model = glm::translate(model, glm::vec3(0.0, 0.0f, 0.0f)); // Place the object at the center of the 7i,p9rA
model = glm::rotate(model, glm::radians(45.0f), glm::vec3(1.0, 1.0f, 1.0f)); // Rotate the object 45 degrees on the XYZ
model = glm::scale(model, glm::vec3(1.0f, 1.0f, -1.0f)); // Increase the object size by a scale of 2

// Transforms the camera
glm::mat4 view = glm::lookAt(cameraPosition, cameraPosition +  CameraForwardZ, CameraUpY); //Moves the world 0.5 units on X and -5 units in Z

// Creates a perspective projection
glm::mat4 projection = glm::perspective(glm::radians(45.0f), (GLfloat)WindowWidth / (GLfloat)WindowHeight, 0.1f, 100.0f);

时有一些错误front被计算。pitch < -89.0f而不是pitch > -89.0f。 x 轴是sin(glm::radians(yaw))z 轴是-cos(glm::radians(yaw)):

//maintain 90 degree pitch
if (pitch > 89.0f)
      pitch = 89.0f;

if (pitch < -89.0f)
      pitch = -89.0f;

//convert mouse coordinates
front.x = cos(glm::radians(pitch)) * sin(glm::radians(yaw));
front.y = sin(glm::radians(pitch));
front.z = cos(glm::radians(pitch)) * -cos(glm::radians(yaw));

此外,sensitivity接缝太强,我建议减少它(例如GLfloat sensitivity = 0.05f;).

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我想知道缩放和轨道运行出了什么问题 的相关文章

  • 如何使用最小起订量模拟私有只读 IList 属性

    我试图嘲笑这个列表 private readonly IList
  • C++0x 初始值设定项列表示例

    我想看看这个现有代码示例如何利用 C 0x 初始化列表功能 示例0 include
  • 如何检查号码是否只有唯一的数字?

    例如 2345 是唯一的数字 因为没有数字显示两次 但 3324 不是唯一的数字 因为 3 出现了两次 我尝试使用 但我 代码 显示但我没有得到数字我得到了数字 编辑 你不能使用字符串 number 10 number 100 number
  • 静态 OpenCV 库中未定义的引用

    我有一个使用 OpenCV 3 1 的 C 项目 并且使用共享库可以正常工作 但现在我想使用静态库 位于项目目录中的文件夹中 来编译它 因为我希望能够在未安装 OpenCV 的情况下导出它 如果需要还可以编辑和重新编译 这次我重新编译了 O
  • c 使用 lseek 以相反顺序复制文件

    我已经知道如何从一开始就将一个文件复制到另一个文件 但是我如何修改程序以按相反的顺序复制它 源文件应具有读取访问权限 目标文件应具有读写执行权限 我必须使用文件控制库 例如 FILE A File B should be ABCDEF FE
  • 为什么我在 WinForms 列表框中得到“System.Data.DataRowView”而不是实际值?

    每当我运行代码并尝试查看highscore我在列表框中得到的只是System Data DataRowView 谁能明白为什么吗 Code MySqlConnection myConn new MySqlConnection connStr
  • 重定向 std::cout

    我需要一个类 在其对象的生命周期内将一个 ostream 重定向到另一个 ostream 经过一番修补后 我想出了这个 include
  • 如何使用 C# 将表格粘贴到 Ms-Word 文档的末尾

    我有一个预制的 Word 模板 其中有一个表格 我想打开它 然后在文档末尾添加 粘贴 另一个表格 问题是它不会转到文档的末尾 而是将新表格粘贴到原始表格的第一个单元格中 任何帮助将不胜感激 previous code copied a ta
  • List 或其他类型上的 string.Join

    我想将整数数组或列表转换为逗号分隔的字符串 如下所示 string myFunction List
  • Code::Blocks 中的调试似乎不起作用 - 缺少调试符号

    我正在尝试在 Code Blocks 中调试程序 我跟着本指南 http wiki codeblocks org index php title Debugging with Code Blocks and 这个短视频 http www y
  • 如何阻止 Control-I 在 CoreWindow 范围内的 UWP 文本框中插入选项卡?

    当我在 UWP 应用程序中有一个 TextBox 时 对我来说 奇怪的行为 在 Windows 10 中创建通用的空白应用程序 UWP 应用程序 使用以下代码将文本框添加到默认网格
  • 如何在 SQLite 中检查数据库是否存在 C#

    我目前正在用 C 编写一个应用程序 并使用 sqlite 作为嵌入式数据库 我的应用程序在启动时创建一个新数据库 但如何让它检查数据库是否存在 如果它确实存在 我如何让它使用它 如果不存在如何创建一个新数据库 这是我到目前为止所拥有的 pr
  • 动态菜单创建IoC

    我想知道是否有人知道我如何创建如何使用 AutoFac 之类的东西来让我动态地允许 dll 创建自己的表单和菜单项以在运行时调用它们 所以如果我有一个 员工 dll 新入门表格 证书表格 供应商 dll 供应商详细信息来自 产品形态 在我的
  • 使用 WinAPI 连接禁用的显示设备

    我的问题是启用禁用的监视器ChangeDisplaySettingsEx 我想这不是火箭科学 但经过一番挖掘后 它看起来仍然是不可能的 我找到了一种根据找到的 Microsoft 代码示例禁用所有辅助显示器的方法here https msd
  • 按 Enter 继续

    这不起作用 string temp cout lt lt Press Enter to Continue cin gt gt temp cout lt lt Press Enter to Continue cin ignore 或更好 in
  • 如何使 WinForms UserControl 填充其容器的大小

    我正在尝试创建一个多布局主屏幕应用程序 我在顶部有一些按钮链接到应用程序的主要部分 例如模型中每个实体的管理窗口 单击这些按钮中的任何一个都会在面板中显示关联的用户控件 面板包含用户控件 而用户控件又包含用户界面 WinForms User
  • C# 模式匹配

    我对 C 有点陌生 我正在寻找一个字符串匹配模式来执行以下操作 我有一个像这样的字符串 该书将在 唐宁街 11 号接待处 并将由主要医疗保健人员参加 我需要创建一个 span 标签来使用 startIndex 和 length 突出显示一些
  • 使用方法的状态模式

    我正在尝试使用方法作为状态而不是类来基于状态模式的修改版本来实现一个简单的状态机 如下所示 private Action
  • 包含从代码隐藏 (ASP.NET C#) 到 ASPX 中的图像概述的图像列表 [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • 如何创建实体集或模型而不在数据库中创建相应的表 - 实体框架

    我的 sqlserver 数据库中有一个存储过程 它返回多个结果集 我正在使用 msdn 中的以下链接从实体框架中的 SP 读取多个结果集 https msdn microsoft com en us library jj691402 v

随机推荐

  • C++ 参考——它们只是语法糖吗?

    C 参考只是语法糖 还是在某些情况下提供任何加速 例如 无论如何 指针调用都涉及副本 对于引用调用似乎也是如此 基本机制似乎是相同的 编辑 在大约六个答案和许多评论之后 我仍然认为引用只是语法糖 人们是否可以直接回答 是 或 否 以及是否有
  • 以批处理模式运行时提示输入 SAS ODBC 连接密码

    由于各种原因 我更喜欢尽可能以批处理模式运行 SAS 程序 出于安全原因 我希望每当与 Teredata 仓库建立 ODBC 连接时 SAS 都会提示我输入密码 我可以同时拥有这两个东西吗 以下代码在从 SAS 交互运行时工作正常 但在批量
  • 在 C 函数声明中,“...”作为最后一个参数的作用是什么?

    我经常看到这样声明的函数 void Feeder char buff 这是什么意思 它允许可变数量的未指定类型的参数 例如printf does 您必须使用以下命令访问参数va start va arg and va end功能 See h
  • ZipException:重复条目:com/google/android/gms/internal/zzbtt.class

    错误 任务 app transformClassesWithJarMergingForDebug 执行失败 com android build api transform TransformException java util zip Z
  • ol/ul 应该在

    内部还是外部?

    这两者之间哪个符合标准 p Text text text p ol li First element li ol p Other text text p OR p Text text text p ol li First element l
  • 在 MySQL 插入语句中使用 Python 变量

    我已经尝试了一段时间了 在网上查了一下 但无法弄清楚 变量是numbers and animals sql INSERT INTO favourite number info VALUES numbers animals cursor ex
  • 在 MVC Core 应用程序中使用 AddAzureADB2C 时向 ClaimsPrincipal 添加自定义声明

    使用 azure AzureADB2C 进行身份验证时 我想将在门户中管理的自定义声明添加到声明原则 current code in start up services AddAuthentication AzureADB2CDefault
  • 一次读取时按长度对文件中的所有单词进行排序。 (爪哇)

    我的数据结构课的作业是找到从一个单词到另一个单词的最短路径 即开始 流血 gt 混合 gt 金发 gt 结束 血液 成本为 3 我得到了一个单词列表 我必须使用地图对其进行分组 在哪里 键 单词的长度 值 具有该长度的所有单词的集合 我已经
  • “双重”分配——应该避免吗?

    考虑一下你有一些像这样的表达 i j 0 假设这是在您选择的语言中明确定义的 通常将其分成两个表达式会更好吗 i 0 j 0 我有时会在库代码中看到这一点 就简洁性而言 它似乎并没有给您带来太多好处 并且不应该比这两个语句执行得更好 尽管这
  • Hazelcast 中基于时间的驱逐

    我正在满足一个要求 即我有 N 个 hazelcast 实例在集群中运行 并且 kafka 消费者在所有实例上运行 现在的问题是 kafka 上传入的每条消息都应添加到分布式映射中 并且必须每 20 秒驱逐该条目 这是我通过在映射中结合使用
  • Lint-staged 找不到与 glob 匹配的暂存文件

    我正在使用 NodeJS Typescript 我想设置lint staged在提交之前验证我的文件 但它不起作用 我从指南中添加如下 husky hooks pre commit lint staged lint staged js js
  • 如何将数组中的值复制到新数组中?

    我已经断断续续地尝试解决这个问题一个星期了 但我不断遇到问题 我的目标 编写一个为整数数组分配内存的函数 该函数将整数指针 数组大小和要分配的 newSize 作为参数 该函数返回一个指向分配的缓冲区的指针 第一次调用该函数时 大小将为零并
  • 获取与 XEP-0313 每次对话的最后一条消息?

    我正在使用一个 XMPP 服务器来实现XEP 0313 http xmpp org extensions xep 0313 html用于检索对话历史记录 我只想获取每个对话的最后一条消息 以便我可以构建您最近的对话列表 预览最后一条消息 我
  • CALL 命令与带 /WAIT 选项的 START 命令

    带有 WAIT 选项的 START 命令如何 START wait notepad exe START wait notepad exe 与使用 CALL 命令有什么不同吗 CALL notepad exe CALL notepad exe
  • 在 32 位 .NET 进程中分配超过 1,000 MB 的内存

    我想知道为什么我无法在 32 位 NET 进程中分配超过 1 000 MB 的内存 以下迷你应用程序在分配 1 000 MB 后抛出 OutOfMemoryException 为什么是 1 000 MB 而不是 1 8 GB 是否有我可以更
  • Java 中 JTable 的 JDBC TableModel?

    我想将数据库表显示为 JTable 我以前从未使用过 JTable 所以我用 google 搜索了 JTable 和 TableModel 通过谷歌搜索 我可以编写自己的自定义 TableModel 它显示存储在中的数据 Object da
  • 如何在 android 中使用 java 8 库?

    我正在尝试在我的 android 项目中使用一个使用 java 8 的库 我无法找到一种方法来完成这项工作 我尝试过使用复古 lambda 但没有帮助 我不断收到错误 com android dx cf iface ParseExcepti
  • acosf() 返回 NaN

    我有一个用 Objective C 编写的 iPhone 应用程序 我在其中收集用户在屏幕上绘制的触摸点以创建路径 我希望能够精简这些数据 我的目标之一是检查点的角度是否超过某个阈值 例如 如果我在名为 a b c 的线上取任意三个相邻点
  • AngularJS 路由参数可以包含任意字符

    我是 AngularJS 的新手 所以如果这是显而易见的 请原谅我 但我正在寻找可以回答这个棘手问题的人 我正在实现一个应用程序 需要将一些参数传递到特定视图以显示有关书籍的详细信息 基本上我希望能够使用以下路由表达式 bookApp co
  • 我想知道缩放和轨道运行出了什么问题

    我希望能够平移 缩放和绕立方体旋转 我想知道为什么立方体在屏幕上显示为完全缩放 以至于我必须向后移动才能查看整个立方体 我还想将缩放控件更改为 Alt 和鼠标右键以进行缩放和轨道旋转 但我无法让它工作 任何援助将不胜感激 header in