So, I'm currently trying to learn OpenGL ES for Android as a part of a project I'm undergoing for a Mobile Programming class. I wanted to make a quick basic 3D game in which the user rotates a "gun" and has to shoot targets under a certain time limit. The problem I am running into is designing my Target shapes.

I want the target shapes to be a basic diamond gem shape. I have read the android developer guide for drawing out Pyramids/Cubes with vertices and indices describing the shapes vectors and face's to be drawn, but I am having a lot of trouble getting my desired shape.

Here is my Target's Vertices and Indices

float[] vertices = 
{ 
    -1.0f, -1.0f, -1.0f, //0. Back Right
    1.0f, -1.0f, -1.0f, // 1. Back Left
    0.0f, 1.0f, 0.0f, // 2. Top
    -1.0f, -1.0f, 1.0f, //3. Front Right
    1.0f, -1.0f, 1.0f, // 4. Front Left
    0.0f, -2.0f, 1.0f //5. Bottom
};
byte[] indices = 
{ 
    3, 2, 4, 4, 5, 3, //draw front face
    0, 2, 4, 5, 4, 0, // draw right face
    1, 0, 5, 2, 0, 1, // draw back face
    3, 1, 2, 5, 1, 3 // draw left
}; // end byte[] indices

Here in the indices I'm trying to draw the top face, than the bottom face, and wrap around my shape in a counter clock wise manner, starting from the front and moving to the right, back and then left respectively. Yet, with this I get a shape that looks like an old Star Fox ship. I've looked for help before, but couldn't find much of anything that helped me, either through my understanding or it was a similar question but about shaders or textures.

I guess my question would be how do you properly apply the drawing for such a shape? I have tried many Counter Clock Wise attempts that always led me to the weirdest shapes. I don't think I'm fully understanding how the indices are drawn in order. I would post some pics, but I'm new to Stackoverflow >.>

Thank you to all help in advance.

有帮助吗?

解决方案

Your indices look somewhat mixed up. Based on my sketch, you mainly have vertex 3 and 4 swapped in the index array. You can tell that it can't be quite right because vertex 3 is commented "Front Right", but it does not show up in the indices under "right face". Vice versa for vertex 4. Most of the triangles are clockwise.

The comments are somewhat misleading. The x-axis is normally drawn left to right. You have the vertices with negative x-coordinates labelled "right", and the ones with positive x-coordinates labelled "left", which seems unusual.

I wonder if you might have used a left-handed coordinate system for your definitions, which would explain much of the above. Make sure that you always use a right-handed coordinate system, and look at the winding order from the outside of the object.

Did you mean to place vertex 5 under the center of the square, or is the y-offset intentional? I moved it under the center in the code below, but you can move it to where you had it without changing the topology.

Based on my paper sketch, the correct version would look something like this (untested):

float[] vertices = 
{ 
    -1.0f, -1.0f, -1.0f, //0. Back Left
    1.0f, -1.0f, -1.0f, // 1. Back Right
    0.0f, 1.0f, 0.0f, // 2. Top
    -1.0f, -1.0f, 1.0f, //3. Front Left
    1.0f, -1.0f, 1.0f, // 4. Front Right
    0.0f, -2.0f, 0.0f //5. Bottom
};
byte[] indices = 
{ 
    3, 4, 2, 4, 3, 5, //draw front face
    0, 3, 2, 5, 3, 0, // draw left face
    1, 5, 0, 2, 1, 0, // draw back face
    4, 1, 2, 5, 1, 4 // draw right
};
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top