Drawing an OBJ from structs

Moderator
Posts: 3,579
Joined: 2003.06
Post: #31
Ingemar Wrote:Like you say, the important thing is straightening out the data so it can be passed as array. If I managed to get the speed up, the better..

Well, it's much faster than my full-featured loader, not SimpleObjLoader (about the same speed there). BTW, I call it "simple" because I didn't bother writing a decent generalized parser for it like yours, and I just spent a few hours on it, but now I'm jealous, so I might re-write that part. Wink

Blahblah: My full-featured obj loader is all Cocoa and is over-complicated but robust in comparison to SimpleObjLoader, but slow. That wasn't a problem before because like I mentioned earlier I use it for off-line processing, but it looks like my current project will need to take users' data in obj format (to customize the program), and I'm shooting for cross-platform with it, so my full-featured Cocoa obj loader isn't going to cut it. Plus Frogblast posted a really cool snippet a while back using C++ for duplicate vertex removal that I've been kind of wanting to try out. Although now that I saw that hash map in yours I might try to figure that one out too. As I mentioned earlier, it is really expensive to use NSDictionary for duplicate vertex removal [vertex reuse], although it works perfectly.
Quote this message in a reply
Member
Posts: 260
Joined: 2005.05
Post: #32
Well, I guess we can take some inspiration from each other's code. Smile
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #33
Ingemar Wrote:Well, I guess we can take some inspiration from each other's code. Smile

Heh, yes, your loader got my gears spinning on a couple of ideas I could implement in my next obj loader. Smile
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #34
Just as a quick update to my objLoader:
- I added face normals so that obj's that don't have normals will at least get flat shaded lighting.
- It should now be able to deal with file names that have spaces in them. (I don't know why I didn't do that to begin with...)
Quote this message in a reply
Member
Posts: 281
Joined: 2009.04
Post: #35
Well, I've got it now working now! Smile I think I'm going to try Ingemar's Loader soon too.

Now, let's see ...

Can anyone help with collision detection? Rasp

~ Bring a Pen ~
Quote this message in a reply
Member
Posts: 227
Joined: 2008.08
Post: #36
Start with basic sphere-sphere collision.
Code:
float i=(o1.radius+o2.radius);//The sum of the radii
i*=i;//We square it to be comparable to the squared distance
float squaredDistance=o1.x-o2.x+o1.y-o2.y+o1.z-o2.z;//squared to avoid a costly sqrt
if(squaredDistance<0) squaredDistance*=-1;//absolute value
if(squaredDistance<i) //o1 and o2 colided if their distance is less than their combined size
else //They didn't collide
This is code you will find everywhere, but it is useful, even for situations where you want to do a pre-check for optomization purposes. (And visiblity tests Smile)

Then try looking up stuff for triangle-triangle collision and ray-triangle collision.
After that, you will understand how to detect objects colliding.
Quote this message in a reply
Member
Posts: 24
Joined: 2008.02
Post: #37
Not to go farther off topic, but for collision detection and a bunch of other useful math stuff, check out this site: http://local.wasp.uwa.edu.au/~pbourke//geometry/ It has been a very useful resource.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #38
I second Oddity007's recommendation of doing sphere-sphere collision detection first.

Man With No Name Wrote:Not to go farther off topic, but for collision detection and a bunch of other useful math stuff, check out this site: http://local.wasp.uwa.edu.au/~pbourke//geometry/ It has been a very useful resource.

Oh yeah, Paul Bourke has a whole bunch of pages I've bookmarked over the years. Lots and lots of useful tidbits all over his site. Smile
Quote this message in a reply
Member
Posts: 281
Joined: 2009.04
Post: #39
OK, thanks! Sphere - Sphere collision is not the most useful thing in the world now... I'll check out Mr.Bourke's Resources, and keep you posted! Rasp

~ Bring a Pen ~
Quote this message in a reply
Member
Posts: 281
Joined: 2009.04
Post: #40
I've looked, and I don't really get any of it. Maybe I'm missing something, but how can I specify Normals as N? What does the dot mean? And what does p mean? Is there something a little more basic out there?

~ Bring a Pen ~
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #41
Look closely at Oddity007's example. That gives you sphere-sphere collision detection. I know it doesn't seem like sphere-sphere is useful but it is far more useful than you might imagine. Basically, all you're doing is checking to see if two objects are close enough together to be touching, using the standard distance equation (actually Oddity007 is using a little optimization and skipping the square root calculation, but you can just use the full distance equation first if that makes more sense). While sphere-sphere is not usually very accurate (unless you're colliding spheres), it gets you a rough approximation. Believe me, you don't want to fiddle with other stuff like OBB (Oriented Bounding Boxes) or convex hulls right now. Even with OBB, convex hulls, etc., you'll do your rough collision first with the sphere-sphere, then do fine collision after that if they are colliding in sphere-sphere. That saves loads of processing. So what I'm saying is that you should start with sphere-sphere regardless. Wink (you could use AABB instead of sphere-sphere, but I prefer spheres)

BTW, you'll probably only ever need normals for collisions if you're calculating contacts for physics [edit] forgot: or triangle collisions I suppose [/edit]. In the case of physics, I would instead recommend spending your time learning how to use a physics lib like Newton or ODE or Bullet (Newton is probably easiest). Calculating collision contacts for anything but boxes and spheres goes down a long and winding path that you don't want to mess with -- I tried it myself and decided it isn't worth the trouble nowadays with 3rd party physics libs being freely available.
Quote this message in a reply
Member
Posts: 281
Joined: 2009.04
Post: #42
Thanks, I'll try to find something to use Sphere-Sphere collision with. I wasn't hoping for that much collision detection anyway.

Have you ever played Ghost Recon (PC,PS2,XBOX) ? It's physics are what I'd quite like. Gameplay Video. In short:

You can't walk through walls more then 45º. You walk on the floor, if it drops, you drop. You can walk up hills less than 45º. You can't jump.

I guess for the walking up hills and over rough surfaces I could just find the nearest vertex' Y, then compare that to the player's Y. Since you can't see yourself (FPS) It would work quite well.

Do you think that'd work?

~ Bring a Pen ~
Quote this message in a reply
Member
Posts: 281
Joined: 2009.04
Post: #43
I guess if I ever went third person or wanted more accuracy, I could find the width of the polygon the player's standing on, then subdivide accordingly then calculate the averages of the vertices' Y positions. The more I subdivide, the more accurate the detection is.

~ Bring a Pen ~
Quote this message in a reply
Member
Posts: 227
Joined: 2008.08
Post: #44
The subdivision may end up being quite slow. Finding the nearest vertex would work only if the object's size is larger than a face of the world. Otherwise you would "fall through" the world.
Quote this message in a reply
Member
Posts: 281
Joined: 2009.04
Post: #45
Ok then, could I calculate the average of all the vertex' Y positions, then use that? I will make sure I subdivide my models beforehand. So, the next question is, how do I find the vertices? I'll delve into AnotherJake's code....

~ Bring a Pen ~
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Weird behaviour with structs and the = operand Jones 2 2,677 Oct 12, 2006 07:11 PM
Last Post: Jones
  Free Structs Justin Brimm 4 3,486 May 30, 2006 06:20 AM
Last Post: Jones