PlayStation®Mobile Development Cookbook by Fleischauer Michael

PlayStation®Mobile Development Cookbook by Fleischauer Michael

Author:Fleischauer, Michael [Fleischauer, Michael]
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 0101-01-01T00:00:00+00:00


There's more...

Up until this recipe, we have paid no attention to the actual units we were using; we simply treated one unit in the physics simulation to equal one pixel in the game. There is nothing wrong with this, but it can lead to some remarkably odd values. In this recipe, we convert from pixels to physics units and vice versa. Physics2D is set up so that 1 unit of measurement = 1 meter, while 1 unit of weight = 1 kg and 1 unit of force = 1 Newton. When you start using real world units, the simulation becomes much easier to understand. In this case we are going to translate at a rate of 50 to 1, in that 50 pixels = 1 meter. This value was chosen arbitrarily; feel free to change it.

You may at this point be wondering about the values you pass in to simulate. The first is the index of the item the user clicked (within the SceneBodies array), while clickPosition and diffPosition allow you to specify two points used to apply velocity to the rigid body specified by the clickIndex variable. So basically it allows you to apply motion to the item touched and, frankly, I think it was bad design.

Earlier we mentioned that force was applied as Newtons. Therefore, when we subtract 40 force, we are actually subtracting 40 Newtons. One Newton is equivalent to the force of earth's gravity acting on an object weighing about 100 gms, which is approximately the weight of an apple. Had Newton been hit on the head with say, an anvil, a Newton would be a much different unit of measure!



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.