Author Topic: Zedd Physics Library  (Read 30571 times)

0 Members and 2 Guests are viewing this topic.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Zedd Physics Library
« Reply #45 on: June 01, 2010, 08:43:57 pm »
I don't know if this has been said, but just having this as a mini-physics playground (like phun, but scaled down a lot) would be pretty awesome.
Yup!  I've been wondering, how easy is this to pass values to?  What do you have to pass to it, and how many bytes is that (normally).  :)

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Zedd Physics Library
« Reply #46 on: June 01, 2010, 10:59:09 pm »
Ya, they really need to make school districts more uniform in the US :P

But anywho, I agree! Back on topic. How is this coming?
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Zedd Physics Library
« Reply #47 on: June 01, 2010, 11:20:23 pm »
Not much has been worked on in regards to zedd right now, i have been (ans still am) very busy with school and finals.  School will be totaly out in about 1.5 weeks so yay :)

As for how the engine manipulation is going to work, it will have a bunch of usefull subs that you can access with arguments, and also return values.  Here are some that i am thinking about

GetPosition             returns the current position of the object (upper left corner)
 in:  N - index
 out: A - X position
      B - Y position

GetSize            returns the height and width of the object (currently locked at 8x8)
 in:  N - index
 out: A - width
      B - height

GetVelocity            returns the current velocity of the object
 in:  N - index
 out: C - X velocity
      D - Y velocity

GetFriction            returns the amount of friction the object experiences when sliding
 in:  N - index
 out: E - object friciton

SetPosition           change the current position of the object (does not account for collision errors)
 in: N - index
     A - X position
     B - Y position

ApplyForce            applies a force on the object with a given direction
 in: N - index
     C - X force
     D - Y force

Move                   moves an object a given distance (does not account for collision errors)
 in: N - index
     A - x distance
     B - y distance

SetFriction           sets the amount of friction an object experiences
 in: N - index
     E - friction

Collision             tests if there is a collision between 2 objects
 in:  N - index 1
      O - index 2
 out: A - 1:true  0:false

CollisionAny        tests if a given object is colliding with any objects
 in:  N - index
 out: A - 1:true  0:false


Note that you cant change size, as this would cause bad game errors on most occasions.  I might include some routines that check for safety, but it would be a tad bit slow, checking against all other objects.  We shall see.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Zedd Physics Library
« Reply #48 on: June 02, 2010, 08:18:56 am »
That sounds really useful. :)
Can we use Zedd in our Axe contest entries, or is that against the rules?

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Zedd Physics Library
« Reply #49 on: June 02, 2010, 12:54:59 pm »
mhmm interesting stuff. I hope it is easy to integrate in many types of games such as ones with tile-mapping.

@Ztrumpet it is, since help is allowed, but if like half of your game code is Builderboy's I think it's a bit unfair for him if you win, since you would get a prize even if you only did like half of the work. Plus, using someone else's code (if we discover it) can affect your originality score as much as if you make a clone/port of an already existing game. This is stuff to think about when participating, although again it is up to people if they wish to volunteer to help or not.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Zedd Physics Library
« Reply #50 on: June 02, 2010, 04:49:02 pm »
@Ztrumpet it is, since help is allowed, but if like half of your game code is Builderboy's I think it's a bit unfair for him if you win, since you would get a prize even if you only did like half of the work. Plus, using someone else's code (if we discover it) can affect your originality score as much as if you make a clone/port of an already existing game. This is stuff to think about when participating, although again it is up to people if they wish to volunteer to help or not.
Ah, okay.  I don't think I'll use it, but it's nice to know that I could. :)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Zedd Physics Library
« Reply #51 on: August 17, 2010, 05:28:02 pm »
Alright after a long period of nothing happening on Zedd, i am releasing the unoptimized and messy source.  Feel free to mess with it and play around with it.

Also, i am going to now do a detailed explanation of how Zedd does its physics calculations.  Each object has multiple variables, 256x precision location, and regular velocity variables.  In the physics portion, Zedd loops through each object.  For each object, the object is moved along its Y axis in the distance of its Y velocity.  It then checks for any collisions with any objects, and if there is a collision, the movement is reversed, then the transfer of forces takes place.  All forces acting on the current object in the Y direction are transfered to the colliding object(s) and all colliding objects transfer any forces they are experiencing in the Y direction onto the current object.  The velocities are recalculated with momentum and energy equations, also taking into account a 'stickiness' threshold, where if the objects are moving at a slow enough velocity, they will both just stick to each other.  There is also friction calculated in the X direction, perpendicular to the plane of movement.  And there is also tipping calculated, if an object rests on the edge of another object, it will 'tip', as in a force is applied to the object to make it slip off the edge.  This entire process is then repeated for the X direction.  After handling the floors and sides in a similar manner, the process is now complete, and the loop moves onto the next object.

The most magnificent thing about Zedd is the transfer of forces, objects collide with other objects and transfer their forces onto others, so if you put a block on top of another, it pushes that block down, and the more blocks you stack, the more force there is. 

As for how the individual scenarios work, here is an example behind the physics of the specific things:

1st screenshot:  Is pure Zedd, the only thing added is forces attached to the keypresses.

2nd screenshot:  Springs.  The way springs work, is that there is a force applied to each box, and it is a direct relation to the distance between them.  So if the X distance is 500, the force is 5, if the distance is 100, the force is 1 lets say.  Since forces are independent of Axis, you do that for both objects, in both axis, and you are golden :)  A fancy spring animation seals the deal.

3rd screenshot:  Water buoyancy.  The physics that makes this screenshot cool are more Zedd than the custom water physics, its really not that complicated.  When a box is fully submerged, there is a constant force of say 500 upward.  The complicated part is where the border is.  Basically you take a percentage of how submerged each object is, and you take the same percentage of the force.  50% submerged is 50% of 500.  20%, take 20% of 500.  Not submerged at all, there is no force :) Zedd takes care of the rest.  So that you get these fun stacking effects with he transfer of forces.

SirCmpwn

  • Guest
Re: Zedd Physics Library
« Reply #52 on: August 17, 2010, 05:28:49 pm »
^_^ finally!
HL2: OC is probably back on track now.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Zedd Physics Library
« Reply #53 on: August 17, 2010, 05:32:09 pm »
So water acts like antigravity? :P
Nice to see a release, I hope you can get more work done on it.
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Zedd Physics Library
« Reply #54 on: August 17, 2010, 05:34:52 pm »
Wow.  I wasn't expecting it to make this much sense, but still, Wow.  Wonderful program.  I can't wait to try it. ;D

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Zedd Physics Library
« Reply #55 on: August 17, 2010, 05:38:52 pm »
Yep, basically water acts like anti gravity ;D There isnt any dampening to speak of, although that wouldn't be too hard to implement.  The reason the boxes flicker and jump in the screenshot is because the boundary of the water is right at the transition of one pixel to the next.  I changed it to in the middle of a pixel and everything looks a lot smoother :)

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Zedd Physics Library
« Reply #56 on: August 17, 2010, 05:40:18 pm »
Um, prgmZedd does not have a header.  Shouldn't it be .Z1? :)

Wow, this is fun to play with. ;D

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Zedd Physics Library
« Reply #57 on: August 17, 2010, 05:40:36 pm »
Wow, awesome work :) Glad this is finally in some sort of releasement stage ;D
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Zedd Physics Library
« Reply #58 on: August 17, 2010, 05:42:56 pm »
Um, prgmZedd does not have a header.  Shouldn't it be .Z1? :)

Wow, this is fun to play with. ;D

Oh whoops ;D The original Zedd was created back when Axe didn't have headers if i remember correctly.  An easy fix ^^

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Zedd Physics Library
« Reply #59 on: August 17, 2010, 05:43:05 pm »
It probably didn't have a header because it was developed before the recent versions of Axe that allowed external libraries.
Before those versions you'd have to recall the library into the program manually, making a header meaningless.
Just my guess ;D
Edit: Ninja'd :P
« Last Edit: August 17, 2010, 05:43:29 pm by calcdude84se »
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.