Advertise Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

sdkIQ for iPhone
($4.99)

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Dual Matches
($0.99)

Calcuccino Programmers' Calculator
($2.99)

SDKtoday
(free)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-02-2010, 12:17 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 214
Default OpenGL | ES Question

Ok, so I am just trying to teach myself OpenGL ES, and have a couple of roadblocks. They seem so simple, yet so difficult at the same time. One of which has to do with Normals.

I have a GLfloat array of vertices created from an OBJ file. In order for the lighting to work, I need normals.

How can I calculate normals based on the array of GLfloats?

Thanks.
flamingliquid is offline   Reply With Quote
Old 02-02-2010, 12:29 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 195
Default

Quote:
Originally Posted by flamingliquid View Post
Ok, so I am just trying to teach myself OpenGL ES, and have a couple of roadblocks. They seem so simple, yet so difficult at the same time. One of which has to do with Normals.

I have a GLfloat array of vertices created from an OBJ file. In order for the lighting to work, I need normals.

How can I calculate normals based on the array of GLfloats?

Thanks.
You can't.

You can only calculate normals for triangles which means you will have to know which of these floats are connected together to form triangles ( normally you would get that from indices)

Once you have your triangle data you can just simple look it up on the net.

Calculate the normal of a triangle with three vertices - XNA Community Forums
warmi is offline   Reply With Quote
Old 02-02-2010, 12:38 AM   #3 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 214
Default

That helps, thanks!
flamingliquid is offline   Reply With Quote
Old 02-02-2010, 08:04 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 214
Default

Gahh this doesn't make sense. I exported (from Blender) an OBJ file. I then used a Perl script to create an array of vertices from this OBJ file. How can I calculate the triangles / normals from this vertex array / original OBJ file?

NOTE: I feel like I might be doing something wrong with the actual export into OBJ or the conversion because it appears that the perl script is able to make a normals array.

I've included all of the files, of the random shape that I created and called a 'flamethrower'.

Im such a noob, haha
flamingliquid is offline   Reply With Quote
Old 02-02-2010, 08:06 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 214
Default

Oops I forgot to attach the files.

untitled.blend.zip

obj2opengl.pl.zip

flamethrower.h.zip
flamingliquid is offline   Reply With Quote
Old 02-02-2010, 09:02 PM   #6 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 13
Default

Hey, calculating normals on the iphone would be a waste time, the normals are already pre-calculated and sitting in the .obj file you exported. The only thing I am confused about is.. Why are you using the perl script to further parse the data? What is your setup right now, do you export from blender and then use the perl script to put the data into a format you can understand? Anyways, I read through the perl script and basically it prints the vertex data, then the normal data and then the texture coords. So you should already have all the data you need. Let me know what your setup is so I can help more with this.
averagejoe_85 is offline   Reply With Quote
Old 02-02-2010, 10:42 PM   #7 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 214
Default

Export Blender > Perl Script (Creates header file) > import Header into OpenGL

Thats what I thought about the normals, but in the header file I don't see any sort of normal array, only indications that one should be there. Am I exporting it incorrectly into OBJ from Blender?
flamingliquid is offline   Reply With Quote
Old 02-03-2010, 12:32 PM   #8 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 195
Default

Quote:
Originally Posted by flamingliquid View Post
Export Blender > Perl Script (Creates header file) > import Header into OpenGL

Thats what I thought about the normals, but in the header file I don't see any sort of normal array, only indications that one should be there. Am I exporting it incorrectly into OBJ from Blender?
You should be exporting your models as indexed arrays suitable for using glDrawElements.

I am not familiar with Blender so I don't really know what Header/OpenGL exporting does but here is a script which is iPhone specific:

iPhone Development: Improved Blender Export
warmi is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


» Advertisements
» Stats
Members: 41,862
Threads: 49,770
Posts: 213,057
Top Poster: BrianSlick (3,139)
Welcome to our newest member, futurevilla216
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:02 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0