We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › GLModel Vertices Coordinates
Page Index Toggle Pages: 1
GLModel Vertices Coordinates (Read 974 times)
GLModel Vertices Coordinates
Dec 22nd, 2009, 10:32am
 
Hey,
I'm quite new to the OpenGL Stuff, so this might be a very easy question:

I'm using the GLGraphics Library. In my code i created some VBOs via GLModel. I wondered if there is a quick method or function to get the Coordinates of the Vertices I created?

Thanks!
Chris
Re: GLModel Vertices Coordinates
Reply #1 - Jan 3rd, 2010, 10:48pm
 
From the time you call GLModel.beginUpdateVertices() until you do GLModel.endUpdateVertices(), all the vertex coordinates are accessible through GLModel.vertices, which is a java FloatBuffer. Example:

Code:

float[] vertArray = new float[4 * model.getSize()];
model.beginUpdateVertices();
model.vertices.get(vertArray); // Copy coordinates to float array.

// Do some operation on the vertices (scaling in this case):
for (int i = 0; i < model.getSize(); i++) {
 vertArray[4 * i + 0] *= 2;  // X coordinate of vertex i.
 vertArray[4 * i + 1] *= 2;  // Y coordinate of vertex i.
 vertArray[4 * i + 2] *= 2;  // Z coordinate of vertex i.
}

model.vertices.put(vertArray); // Copy float array back to model.

model.endUpdateVertices();
// model.vertices cannot be accessed after
// beginUpdateVertices()/endUpdateVertices()

Re: GLModel Vertices Coordinates
Reply #2 - Jan 6th, 2010, 2:42pm
 
Great!

This helps alot!

Chris.
Re: GLModel Vertices Coordinates
Reply #3 - Jan 6th, 2010, 4:06pm
 
You are welcome. One small detail though. I mentioned the method model.getSize() in the code snipped in my previous post. I added it recently, but is not available yet in the version you can download from sourceforge. So just replace model.getSize() by the number of vertices you specified in the constructor.
Page Index Toggle Pages: 1