开发者

how to get new vertex coordinates of a rectangular block after applying glRotate()

I am drawing a rectangular block:

GLfloat cubeVertexV[] = {
    // FRONT
    -0.5f, -1.0f,  0.5f,
     0.5f, -1.0f,  0.5f,
    -0.5f,  1.0f,  0.5f,
     0.5f,  1.0f,  0.5f,
    // BACK
    -0.5f, -1.0f,  -0.5f,
     0.5f, -1.0f,  -0.5f,
    -0.5f,  1.0f,  -0.5f,
     0.5f,  1.0f,  -0.5f,
    // LEFT
    -0.5f, -1.0f,  0.5f,
    -0.5f,  1.0f,  0.5f,
    -0.5f, -1.0f, -0.5f,
    -0.5f,  1.0f, -0.5f,
    // RIG开发者_StackOverflowHT
     0.5f, -1.0f, -0.5f,
     0.5f,  1.0f, -0.5f,
     0.5f, -1.0f,  0.5f,
     0.5f,  1.0f,  0.5f,
    // TOP
    -0.5f,  1.0f,  0.5f,
     0.5f,  1.0f,  0.5f,
     -0.5f,  1.0f, -0.5f,
     0.5f,  1.0f, -0.5f,
    // BOTTOM
    -0.5f, -1.0f,  0.5f,
    -0.5f, -1.0f, -0.5f,
     0.5f, -1.0f,  0.5f,
     0.5f, -1.0f, -0.5f,
};

Now I apply glRotate() in x, y, and z axes on this block. Now I want to change the cubeVertex array with the new coordinates resulting from the application of glRotate call. Is this possible in OpenGL?


Generally speaking, OpenGL will just accumulate the transforms, and only actually apply them to the data when you render it. In the plain old fixed-function graphics pipeline, there's no way to do it. However, as programmability has been increasing every generation, there is support for this now via OpenGL extensions, provided you're using a recent enough graphics card. Whether you have an nVidia or ATI card might also make a difference, as they don't always support the same extensions.

It's been some time since I did much OpenGL, so this is going to be a little vague, but the general idea is:

  • you bind a pair of Vertex Buffer Objects,
  • put your data in the first one,
  • use Transform Feedback to render the transformed vertices into the second,
  • and you can then read back data from the second VBO into memory.

The nVidia Transform Feedback Fractal demo on their OpenGL Code Samples page should help you with the actual code for this.

If you want to do more general math on your GPU, you should look into GPGPU techniques, there's a LOT more stuff you can do, and with CUDA / OpenCL / etc. it gets a lot easier to code, too.


You can use glGet with GL_MODELVIEW_MATRIX to get the current modelview matrix (assuming you applied the glRotate call to it). Then, manually transform your vertices by the matrix.


It's not trivial, but look up glRenderMode(GL_FEEDBACK); to get started. This will give you not only the coordinates, but also (for example) colors after lighting has been applied.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜