转换"正常"矩形一套GLES载体? [英] Convert a "normal" rectangle to a set of GLes vectors?

查看:125
本文介绍了转换"正常"矩形一套GLES载体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何转换成一个正常的矩形成一组的的OpenGL ES 顶点。我不擅长几何,所以我不知道怎么顶点的工作,我希望能够操纵的矩形,而不必通过反复试验,以制定出顶点的值。

How would I convert a "normal" rectangle into a set of OpenGL ES vertices. I'm not good at geometry so I have no idea how vertices work, and I want to be able to manipulate rectangles without having to work out the values for the vertices by trial and error.

基本上,我需要这种结构转换:

I basically need to convert this structure:

typedef struct __nrect {
    float width;
    float height;
    float depth;

    /* center */
    float x;
    float y;
    float z;
} simple3dRect;

要像这样:

    const GLfloat cubeVertices[6][12] = {
    { 1,-1, 1, -1,-1, 1,  1, 1, 1, -1, 1, 1 },
    { 1, 1, 1,  1,-1, 1,  1, 1,-1,  1,-1,-1 },
    {-1, 1,-1, -1,-1,-1, -1, 1, 1, -1,-1, 1 },
    { 1, 1, 1, -1, 1, 1,  1, 1,-1, -1, 1,-1 },
    { 1,-1,-1, -1,-1,-1,  1, 1,-1, -1, 1,-1 },
    { 1,-1, 1, -1,-1, 1,  1,-1,-1, -1,-1,-1 },
};

有没有一种简单的方法来做到这一点?

Is there an easy way to do this?

推荐答案

假设所得立方体是轴对齐和宽度对应于x轴,高度为y轴和深度z轴:

Assuming that the resulting cube is axis-aligned and that width corresponds to the x-axis, height to the y-axis and depth to the z-axis:

const GLfloat cubeVertices[6][12] = {
    { x + width/2, y - height/2, z + depth/2,  x - width/2, y - height/2, z + depth/2,  x + width/2, y + height/2, z + depth/2,  x - width/2, y + height/2, z + depth/2 },
    { x + width/2, y + height/2, z + depth/2,  x + width/2, y - height/2, z + depth/2,  x + width/2, y + height/2, z - depth/2,  x + width/2, y - height/2, z - depth/2 },
    { x - width/2, y + height/2, z - depth/2,  x + width/2, y - height/2, z - depth/2,  x - width/2, y + height/2, z + depth/2,  x - width/2, y - height/2, z + depth/2 },
    { x + width/2, y + height/2, z + depth/2,  x - width/2, y + height/2, z + depth/2,  x + width/2, y + height/2, z - depth/2,  x - width/2, y + height/2, z - depth/2 },
    { x + width/2, y - height/2, z - depth/2,  x - width/2, y - height/2, z - depth/2,  x + width/2, y + height/2, z - depth/2,  x - width/2, y + height/2, z - depth/2 },
    { x + width/2, y - height/2, z + depth/2,  x - width/2, y - height/2, z + depth/2,  x + width/2, y - height/2, z - depth/2,  x - width/2, y - height/2, z - depth/2 },
};

显然,这可以简化/由$ P $对 - 计算宽度/ 2等的值最佳化,普通写法包括在这里为了清楚

Clearly, this can be simplified/optimised by pre-computing the width/2, etc. values, longhand included here for clarity.

这篇关于转换"正常"矩形一套GLES载体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆