faking 3D physics

I agree it’s better to use the math (and I say that reluctantly because I find it hard).

It’s really hard to make a case of any kind without a specific application to analyze, but I’d ask both you gents to reflect on your knowledge of software development.

Look at @Ignatz’s post about making his math-based version. It starts off with “this is much simpler, here’s how I did it,” and it ends with “there’s just one special case problem I’d have to fix to make it work perfectly.”

…you guys are software developers–what runs through your mind when you hear someone say “I just have to fix this one easy thing, then it’ll be good to go”?

I mean, it definitely could be easy. Maybe that special-case is trivial. But maybe fixing it brings up another unforeseen special-case that needs to be checked. Or maybe it doesn’t–but something else definitely will. This is how coding goes.

The fact is that making any code work correctly at all is a process of, again and again, slapping your forehead and realizing you have to account for something you hadn’t thought of beforehand. I think with our combined experience we can agree that any time you have to choose between writing something yourself and using an established, road-tested API, the API is going to be faster, if only because they’ve already done all the forehead-slapping that needs to be done.

So the chief benefit of my proposed approach is being able to use a pre-forehead-slapped API. To suggest that it’d be simpler to set about doing it from scratch seems like, literally, signing yourself up for a regimen of forehead-slapping in order to solve a bunch of problems that have already been slapped to death.

Just to point out, too, the category mismatch in our discussion: I’m talking about a way to access the all the functions of a platform (Box2D) in a 3D space, and the rebuttals to date have focused on the one function I brought up as an example. This system provides a starting point from which to explore the application of all the Box2D abilities in a 3D space. To say that it’d be simpler to re-write this one function from scratch is to miss the forest for one tree.

(And lastly I’ll admit that you guys are smarter than I am mathematically, so it’s totally possible that, for you, manually re-implementing a physics engine is simpler than this technique. Do bear the opposite in mind: trivial maths for you may be quite challenging for me, and being able to access Box2D whenever possible is a huge time savings for me that it wouldn’t be for you.)

The problem is that before long, your approach is going to run into a brick wall. There’s only so much it can do, while math can do just about anything.

And a classic rule of software development is to retain as much flexibility as possible, ie don’t paint yourself into corners.

@Ignatz but everything cuts both ways; sometimes running into a brick wall is the best thing that can happen. Often limitations are also freedoms.

It was ever thus. Simplicity is limiting but also efficient; complexity is powerful but cumbersome. If you have just two colors you can still make a painting; if you have a million colors you can get stuck choosing between them. If you want to get things done, nothing beats an API; if you want to run down rabbit holes, nothing beats re-engineering solved problems.

To me, the proposition “how far could you push this simple cheat on Box2D” is intriguing, but that’s me. I’m curious how much you could actually do. Could you make 3D ragdolls? It doesn’t seem impossible. Could you create particle emitters? Again, doesn’t seem completely out of the range of possibilities. Could you make a space-combat sim? Absolutely, I’d think.

At all of those propositions, it seems like you and @yojimbo2000’s first thought is “that seems so much harder than writing the math yourself”! Fair enough–one person’s fun thing to think about is another’s waste of time. Here too, it was ever thus.

Yes, but we have some experience in building 3D apps and models. And most have them have objects which are not spherical.

I just don’t think it’d work. Try putting in 1 extra ball and see what happens. You’re saying it’d be possible to detect the rough proximity of the objects, and then turn on/off Box2D collision between them with a system of bitmasks. I’m saying that that would be incredibly hard and I’d be very surprised if it works accurately.

@yojimbo2000 “Incredibly hard”? Think of it entirely as a box2D challenge; the 3-D merely follows what’s going on there.

Can Box2D track two objects, and flip a bit whenever they pass through each other? Easy. Can it then track two other objects, making them ignore the first two, and making them flip another bit only when the two new objects intersect? Also easy. Can Codea track both bits, and selectively activate collisions only when both bits are true? Sure, I think, no problem, right?

Would it be perceptibly inaccurate? I don’t see why we’d assume that.

I don’t have the time to program it, or I would, sorry to say. But just as a theoretical discussion, I can’t see the part you call incredibly hard.

@yojimbo2000 actually, now that I describe the steps, it seems so simple that I might be able to find the time for it. If I get a moment or two, I’ll take a swing at it.

I admire your commitment, but it’s really not going to work. Ok, say you have an XY plane and an ZY plane. How are you going to constrain the two versions of each ball so that they always have the same Y value? Have you done any work with constraints in Box2D? If there’s one thing rigid body physics simulations don’t like, it’s you trying to break the laws of physics by telling them where you think the bodies should be. I predict the bodies will glitch, pass through each other etc. Plus, what’s the point of using a physics simulation to resolve collisions if you’re going to try to override the resulting resolution by trying to restrict one of the axes?

@yojimbo2000, my first plan re: Y axis would be to look at how @Ignatz did it, since he already did it successfully.

But I don’t think he is constraining them, he just ignores one of the axes.

Really? I’m not sure, but that might still work.

Yes, I used two physics planes, XY and XZ, as per the original suggestion above.

I don’t see the point of pursuing this, because even if it works, it can only handle spheres, which makes it of little general use.

@Ignatz to me it’s an interesting puzzle, and I’m glad you helped solve part of it.

I think the general uses expand when you realize that the sphere and the 3D object needn’t be the same. You could do a hopping frog, for example, with the bulk of its body inside the sphere, and the legs protruding out and animating as needed.

As well, physics aside, there could be a very useful application as collision detection in 3D space. Collision detection of all kinds relies on masking complex shapes with simpler ones. Say you were making 3D boxers and you need to know when a fist hit a head. This would be an easy way to do that.

But again, the puzzle is interesting to me to begin with, and finding usefulness is secondary. Thanks for helping so much.

@ubergoober just to let you know one more pov: ignatz and yojimbo are right. If objects different from spheres collide, the result will be physically incorrect and looking weird quite often.

But you can try it and see for yourself.

I’ve done quite a few 3D projects and most of them have involved collision detection, but often it requires specialised calculation, eg if you shoot an object and you need to know the hit point and angle. And most objects are not spheres.

@Ignatz, @Jmv38, @yojimbo2000 just a reality check here, guys.

To date, you guys have been saying “no, no, no” to this idea, and there’s been exactly one experiment, and it proved me right.

Right now you guys are acting like the veritable Stodgy Council of Elders, and you’re casting me in the role of Young Visionary with ideas too radical for the old guard. As the record stands, you look like Edison and I look like Tesla, which totally isnt true.

So cut it out, fellas! Quit it with the “this will never work because I’m an expert and I know better”! Come on and join me on the Tesla side, it’s way more fun!

We aren’t stodgy elders at all. I am happy to use any technique that saves time and spares me from math.

But so far, the method above works for one sphere in a box, and that’s all. Even if it works for two, I’ll bet the code required to do it won’t be easy. And the math approach is much simpler. The video below shows 12 balls bouncing off the walls - and each other. The math is extremely simple. Now try doing that with 2D physics.

http://www.youtube.com/watch?v=prXhXUHv8Hs

So using physics was a fun demo, but it’s not a technique with broader practical use. It can only substitute for math where the math is very simple, which kind of defeats the purpose, I think.

@UberGoober i dont like that you call me ‘Stodgy’.
i was just trying to help enlighten you, but sorry for that, be sure i wont do it again!
And I’ll be so glad to test your code when you post it, thanks in advance for sharing.

@UberGoober I’m glad I didn’t get in the above conversation with all of those stodgy people. My suggestion is to write your code however you want. You got a lot of suggestions and examples that should help you no matter which way you do it. Thats the whole purpose of this forum, to get different ideas.