question about gltranslate, glscale and molecules

4 replies [Last post]
blamejane
User offline. Last seen 10 years 12 weeks ago. Offline
Joined: 02/20/2011
Posts:

Brad I wanted to thank you for sharing your molecules source and knowledge you've learned. I've been developing for the ipad for 5 weeks and I always come back to your source.

In your "lessons from molecules" you mentioned using gltranslate, glscale and glrotate for the zoom/pan and rotate of molecules. I want to implement the same behavior with my 3D model, but havent been successful with the panning. This is because I was going about it all wrong...using a UIScrollView rather than just translating my model. After trying your molecules app again, I see that you've implemented the pan successfully, which is what I want to mimic. Now my problem is, I have your latest source molectules (1/9/2011), but I don't see that you're using the gltranslate, glscale and glrotate.

I'm more familiar with these calls versus CATransform3DTranslate. Can you tell me if I'm just not seeing these calls?

Thanks so much.

Valerie

Brad Larson
Brad Larson's picture
User offline. Last seen 4 years 22 weeks ago. Offline
Joined: 05/14/2008
Posts:

Yes, I replaced all of the glTranslate() and glScale() functions with equivalent matrix manipulations through CATransform3D since the launch of the application. The reasons I did so are detailed here.

Basically, in order to manipulate the model view matrix in a way that would allow me to rotate the model properly in response to use input, I had to know the current state of that matrix at each frame. The initial way I did this was to read the model view matrix back before performing the rotation and scaling operations. This led to performance degradation because the rendering pipeline was halted every time I read back the current state.

Instead, I chose to use the Core Animation helper functions to manipulate my own copy of the model view matrix, then write out the result of these operations every frame. A CATransform3D struct has the same internal structure as a model view matrix, and the operations used in Core Animation do the same math as glRotate(), etc., so I could save having to write these operations myself by leveraging stuff built into iOS. That's why you see me using those methods.

It turned out to be a good decision, because now that I'm moving to OpenGL ES 2.0 (which lacks an explicit model view matrix and the functions that deal with it like glRotate()), I need to do these calculations myself anyways.

blamejane
User offline. Last seen 10 years 12 weeks ago. Offline
Joined: 02/20/2011
Posts:

Thanks very much for the detailed response Brad. I hope that I can make the same changes. I'm encouraged by your success at turning molecules out after 3 weeks of learning, but I'm past that and it's still a bit confusing. I'm going to read your detailed explanation for replacing the glx() functions with equivalent matrix manipulations and see what I can learn. Prior to reading it though, I will say that I have the pan/zoom/rotate all working the way I want, though the pan is very jumpy. I suspect its happening when I pan diagonally and the model is transforming first on y value then on x value, making it appear to jump a little.

In any case, I'm developing my app for the iPad, but I'd like it to then port to iphones. I'm thinking like you that I should be looking to port to opengles 2.0.

Do you think it matters that my model is very high in poly count? It's a model of a sculpted rocking chair built in 3ds max and exported using PoverVR sdk to a POD file.

Thanks again.

Valerie

Brad Larson
Brad Larson's picture
User offline. Last seen 4 years 22 weeks ago. Offline
Joined: 05/14/2008
Posts:

How high is high in regards to the triangle count? In my benchmarks, the original iPhone can push around 420,000 triangles / s in my Molecules application, with the iPhone 4 and iPad coming in around 1,800,000 triangles / s. This is with simple smooth shading and a single light source, so texturing and other additions will probably reduce these rendering rates.

Still, that's a lot of triangles that you can use for your geometry. Beyond that, I'm working on some interesting things in OpenGL ES 2.0 that let the shaders do some of the work that you normally needed complex geometry for. There are plenty of ways to fool the eye.

blamejane
User offline. Last seen 10 years 12 weeks ago. Offline
Joined: 02/20/2011
Posts:

Thanks Brad. Well I'm not sure how to get the triangle count with the sdk, but in Max the face count (in this case a mesh-triangles not polys) is 44k.

Syndicate content