faking 3D physics

@Jmv38 @Ignatz @yojimbo2000 I very much apologize for offending you. I know you are all here out of goodwill and it’s possibly less than pleasant to have someone you’re trying to help seem totally ungrateful. I am grateful.

@Jmv38, especially, I want to say I don’t think you’re stodgy and I appreciate your help.

@Ignatz & @yojimbo2000 the last thing I want to do alienate or offend you guys, I feel very honored whenever you respond to anything I post, and that’s the truth.

@Ignatz, for what it’s worth, it always surprises me when you say you want to avoid math because you seem so adept at it.

I hate it when people are apologizing to me and they try to explain what they meant, because it seems like they’re telling me I’m wrong to be perturbed, so on top of offending me they’re calling me wrong. Which is just to say: I erred and I won’t prolong it by defending it. I’m sorry.

Oh, and: you’re certainly right about this: I am trying to do it right now, and it isn’t easy.

I am certainly not adept at this. I should be good at math, being a former actuary, but I still find it very difficult, and I also find it hard to visualise things.

Given this (lack of) natural talent, I am very grateful for my friend Mr Google, and for the help of our resident mathematician, who skips over math problems like a mountain goat.

I couldn’t resist prettying this up, adding some basic lighting, and it looks great (except YouTube reduces the quality so much).

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

Code here: link

@UberGoober Hey man don’t worry about offending anyone. Look, you had a truly terrible idea that will never in a million years work. Don’t worry, I get five of those a day. And of course you’re going to ignore the chorus of people telling you it’s a truly terrible idea that will never in a million years work, because only you can prove to yourself, with your own blood and tears, that it’s a truly terrible idea that will never in a million years work.

@yojimbo2000 …yes, either that …or I’m Tesla. :wink:

(I can taste that crow already!)

@Ignatz–it does look great–just wondering, would it be hard to show rotation?

Probably, yes, so you’d do well to cheat by using a uniform colour instead of a texture. As it is, I’m not showing the transfer of momentum between balls.

Okay, so, you guys said you’d take a look at my code even though it’s a rotten idea! So I wrote some.

I’ve been working off of Ignatz’s code to try and do this the way I was picturing, and I can’t get the 3D sphere to move.

I’ve got the 2D circles doing what I want but the sphere just sits there.

Gist: https://gist.github.com/DolenzSong/f9b0d5e0253cbfee70f58030b327d79a

The relevant parts, I think, are the updatePosition() function in Fake3DSphere and the translate(…) function inside the main draw() function.

Btw: double-tap to create a new circle/sphere object.

@Ignatz @yojimbo2000 Now it’s working, inasmuch as the 3D matches the 2D. Don’t have collisions in yet though.

@Ignatz @yojimbo2000 I added in Ignatz’s fancy shading because he’s right, it looks great.

While I still don’t have collisions in, there are a couple things this is doing that Ignatz’s version of this fake didn’t do:

  1. It has acceleration and deceleration, which requires averaging of each 2D ball’s y values to look right
  2. The 2D model generates rotation information, though I’ve no idea how to show it on the 3D model

To really see the full effect here, you have to double-tap to create the 2D/3D balls, and then drag the 2D balls in different directions to get them bouncing around.

It’s all based off of combining Ignatz’s first take on faking 3D physics with the interactive 2D demos from the Physics Lab.

This version correctly handles momentum changes on collision

Rotation is very difficult.

https://gist.githubusercontent.com/dermotbalson/caa3fdc7015ffb6c600c346ca4094154/raw/74e1c21f431c7a90af59a435e9e9beb61cdd8ff5/gistfile1.txt

Okay I’m trying really hard to stop wasting time but I had a sudden insight into a bug I had had on this. So I corrected it, and here’s my last version I hope:

https://gist.github.com/DolenzSong/f9b0d5e0253cbfee70f58030b327d79a

How-to:

  • Double-tap anywhere on screen to create a ball
  • Use the accelerometer to shake the balls around. But be careful because there’s no top on the box.
  • There is a very faint almost-full-screen overlay that shows all the 2D physics bodies, which are all in one location now. You can directly interact with these, by tapping on a circle and dragging it around. The corresponding 3D ball will follow the motion along the axis of whatever ball you tapped; there are balls for the x axis and balls for the z axis. I believe the faintly green balls are the x axis and the faintly orange ones are z.
  • The x and z balls use a prismatic joint to enforce a consistent y height between them, which works great but seems to put some friction on them, with the result being that their lateral momentum drops off faster than their vertical momentum. The practical effect is that if you make a bunch off balls and bounce them around they’ll all come to a stop at various places on the floor but still be bouncing directly up and down for a bit afterward. I couldn’t figure out a way around this.

You know, maybe it wasn’t worth the effort, but at least it works. Mostly.

There’s only one last thing I wish I could correct: I never really nailed the scaling between the 2D and 3D worlds, so sometimes it looks like balls are passing through things in the 3D world. @Ignatz, if you happen to take a glance and see where I’ve screwed that up, I’d love to know.

And what the heck, here’s a video. Anyone who was confused about the concept should get it pretty easily by watching this.

https://youtu.be/r7ND9NTZWHE

First Codea video ever! Wheeee!