Geometry q1 = new Geometry(“Quad”, q);

rootNode.attachChild(q1);

What can I use to move one of its vertices?

[java]

VertexBuffer buffer = q1.getMesh().getBuffer(Type.Position);

float[] vertexArray = BufferUtils.getFloatArray((FloatBuffer) buffer.getData());

//update vertexArray

buffer.updateData(BufferUtils.createFloatBuffer(vertexArray));[/java]

something like that

Thanks, but what do I have to change to move vertices? I still can’t understand. A statement would be helpful.

If you can’t translate:

//update vertexArray

into:

vertexArray = someNewXValue

vertexArray = someNewYValue

vertexArray = someNewZValue

Or did you really mean some other question?

2 Likes

I thought there was some other code I had to use before. Thanks though.

As length for vertexArray, I get 12. What does this mean?

Yeah, and I get a length of 72 on a cube, feels like there only should be a length of 6/side since there is 6 vertices/side.

Which means you should get a length of 6 and I 36. So I wonder what they represent too.

I get 12. That means that each vertex has four variables assigned. I don’t know what happens to you…

I managed to get it to ‘work’, however, the only thing it does is make the quad go darker, while the vertices do not appear to move. What is the problem?

public void simpleUpdate(float tpf) {

vertexArray += 0.001f;

buffer.updateData(BufferUtils.createFloatBuffer(vertexArray));

}

I’m looking some in the Quad and Box class, seems like there is three values/vertex. I guess they are the tree-dimensional values (one for x, one for y, and one for z).

Not sure yet thou Can you help me with moving the vertices please? When I move 0 (which I assume is x), it’s area just gets darker. The vertex doesn’t move at all. This happens for 2 and 3, and up to 12.

These are good questions.

The float array represents the x,y,z of the vertexes. A quad has four vertexes so you get 4 * 3 floats.

A cube has 6 quads so you get 6 * 4 vertexes… or 72 floats.

You are mistaken in thinking that the cube can share 8 corners because it needs to have different normals for each surface… so each is essentially it’s own quad with its own four vertexes. You can only share vertexes when they have the same position, same normal, and same texture coordinate, etc. (Like the quad and the cube do share some vertexes because each face is really two triangles.)

1 Like

Thanks for the information! It’s really helpful. I didn’t consider that a cube is made up of four quads.

So how can I move the actual vertices?

Note you can look in the code for Quad and Box to see what vertexes, normals, etc. that they make. Things might make more sense then. Never be afraid to peek into the code for stuff like that.

Great to hear that we were on the right track.

I guess we need to change all the values inside the array right? What happens if we don’t?

If you have a quad that is 100, 100 then in wezrule’s code, replace:

//update vertexArray

with:

vertexArray = -25;

vertexArray = -25;

And you will have moved the first corner in the x,y plane (which is what the quad is in… vertexArray should be 0).

vertexArray, vertexArray would be the x,y of the second corner, and so on.

Sorry to post again. Just wanted to tell you that I got it sorted out. I was not using Type.Position, but Type.Normal. I changed it for testing and forgot to put it as it was before. Thanks for all your help.

@Iohnn, if you need anything, just message me EDIT: Thanks pspeed and wezrule.

Thanks for the help!

Will have it worked out as soon as I’ve figured out which vertex is which xD

Will do @memonick! Wait, one more question!

I’ve done my own Box class (basically copy-paste), where I’ve cut off the bottom part in all the arrays, which means only 5 faces. But the length is still 72, what is the reason for that? shows creating a quad from scratch as well, may be useful

edit: 6 Quads, each quad has 4 vertices, which have 3 positions in space.

6 * 4 * 3 = 72

Yeah, that’s a problem For my quad, you have to move anti-clockwise, with the bottom-left vertex being 0. Thanks for your help earlier That’s quite complicated for me wezrule, but I will keep it for future use. Thanks!

EDIT: wezrule, Iohnn ‘deleted’ one quad. That makes it 543, which is not 72.