Floppyman Physics

Blitz3D Forums/Blitz3D Programming/Floppyman Physics

JoshK(Posted 2003) [#1]
http://www.leadwerks.com/floppyman.zip
Hold space to lift head. Arrow keys move.

No constraints, but the existing code is completely solid. I did a lot of testing just getting the basic sphere bouncing and collisions right, and the routines don't produce those jitters that a lot of physics code makes.

I'm not sure how to do constraints. The link type should be pretty self-explanatory.


MattG(Posted 2003) [#2]
do i need something extra ? getting errors that it can't find function Magnitude()

Matt


JoshK(Posted 2003) [#3]
Sorry. You need my maths3d lib. I keep forgetting people don't have it because it's something I use in every program I write:
www.leadwerks.com/code/userlibs/


Ross C(Posted 2003) [#4]
Halo, try using this for your fps code

graphics3d 800,600
setbuffer backbuffer()

camera=createcamera()
positionentity camera,0,2,-10

cube=createcube()
pointentity camera,cube

light=createlight()

while not keyhit(1)


	If MilliSecs()<timer+1000 Then
								    frame=frame+1
	Else
								    fps=frame
								    frame=0
								    timer=MilliSecs()
	End If

        updateworld
        renderworld
        text 0,0,"fps="+fps
        flip

wend
end


updates the fps every second. Obviously turn flip to flip false to get the true fps.


NTense(Posted 2003) [#5]
Wow Halo, this is nice! I've been working on ragdoll physics, and it's interesting to see that your approach is very similar to mine. You're much further along though :/ .. I'm trying to use pivots at on the joints and assign rotational constraints to them. Haven't quite figured out how to apply the direction of rotation based on the force exerted on the extremeties though. (I'm rummaging through my old physics books to try and figure this out). Anyway, this is great!!


JoshK(Posted 2003) [#6]
The code I posted is extremely stable, and extremely simple. First I established really solid ball physics, then worked to get a simple link between two balls. Without any special routines, I added the ragdoll, and even made boxes, just by creating links between joints. The strength of this code is that it uses rock-solid routines to handle the simple things, so it can handle more complex situations without any special help.

The problem of angular constraints begins with figuring out which way the joints are actually rotated. The spheres in this demo are always rotated to 0,0,0, and don't actually turn as the joints move. I think the next step is to adjust the rotations of two spheres joined in a link. From there, the system should automatically adjust for more complex situations.


NTense(Posted 2003) [#7]
Well, I constrained one of my characters, and it looked really nice for about 3/4's of a second. The parts all moved nice, but no rotation. I'll play around with it and see if I can rig something up. This is really cool though!


JoshK(Posted 2003) [#8]
I finished it. Constraining an angle is actually really easy if you think about it in terms of distance. All you're doing is saying "these two entities can't be any further away from each other than X units" (or closer).

The same simple commands that allow ragdoll physics can be used for ridid bodies, cloth, or anything else I can think of that computers have simulated.




NTense(Posted 2003) [#9]
Hmm.. I don't quite understand how you're constraining the angles using distance, but the screenshot looks good (a bit stiff, but good).


JoshK(Posted 2003) [#10]


Okay, when you contrain and angle, you are saying "Dont let the angle made by the position of entity a,b and c get smaller than this minimum value, or larger than this maximum value", where the min and max are angles between 0 and 180, right?

Look at the leg. Let's constrain the angle made by the foot, knee, and hip to between 90 and 180 degrees. So what we do is we find the distance between the foot and the hip when the knee is rotated to 90 degrees. We know the length from the hip to knee, and we know the distance from the knee to foot, and we know the angle, so you are just solving for the third leg of a triangle. Get that length, and somewhere is your physics routine, have it check the distance from the foot to the hip. If that distance is leff than the minimum length you figured out, move the two entities away from each other.

You still need additional constraints to keep it from rotating around and lifting the knee in the wrong direction. That cannnot be done with a 1-dimnsional limb like this. The skeleton actually has a bunch of invisible, non-colliding joints sticking out that make the legs 3-dimensional, and allow us to add contraints that keep the leg pointing forwards.


NTense(Posted 2003) [#11]
But, for a .b3d mesh, we need to apply rotational values to the joints. Now that I think about it, I suppose we could track the rotational value based on the angle calculations of the constraints, and then apply them as an override to the mesh's joints.


Miracle(Posted 2003) [#12]
The skeleton actually has a bunch of invisible, non-colliding joints sticking out that make the legs 3-dimensional, and allow us to add contraints that keep the leg pointing forwards.

AH HA!