From: dsc Date: Mon, 9 May 2011 16:24:58 +0000 (-0700) Subject: Checkpoint on Physics wrapper. X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=43b11e39074b8828d1a3ce944afbc7acbdaee8e9;p=tanks-ios.git Checkpoint on Physics wrapper. --- diff --git a/src/physics/World.h b/src/physics/World.h new file mode 100644 index 0000000..6927a66 --- /dev/null +++ b/src/physics/World.h @@ -0,0 +1,27 @@ +#import +#include + + +@interface World : NSObject { + +@private + b2World* _world; + float _timestep; + int _velocityIterations; + int _positionIterations; +} + +@property (nonatomic, readonly) b2World* world; +@property (nonatomic, assign) float timestep; +@property (nonatomic, assign) int velocityIterations; +@property (nonatomic, assign) int positionIterations; + + +- (World*) init; +- (World*) initWithTimestep:(float)hz; +- (World*) initWithTimestep:(float)hz gravityX:(float)x Y:(float)y; + +- (void) step; + + +@end diff --git a/src/physics/World.mm b/src/physics/World.mm new file mode 100644 index 0000000..0b4a104 --- /dev/null +++ b/src/physics/World.mm @@ -0,0 +1,43 @@ +#import "World.h" + + +@implementation World + +@synthesize world = _world; +@synthesize timestep = _timestep; +@synthesize velocityIterations = _velocityIterations; +@synthesize positionIterations = _positionIterations; + + +- (World*) init { + return [self initWithTimestep:60.0f]; +} + +- (World*) initWithTimestep:(float)hz { + return [self initWithTimestep:hz gravityX:0.0f Y:0.0f]; +} + +- (World*) initWithTimestep:(float)hz gravityX:(float)x Y:(float)y { + if ((self = [super init])) { + b2Vec2 gravity = b2Vec2(x,y); + bool doSleep = true; + _world = new b2World(gravity, doSleep); + + _timestep = 1.0f/hz; + _velocityIterations = 10; + _positionIterations = 10; + } + return self; +} + +- (void) dealloc { + // TODO: track and release all known bodies etc + delete _world; + [super dealloc]; +} + +- (void) step { + self.world->Step(self.timestep, self.velocityIterations, self.positionIterations); +} + +@end diff --git a/tanks.xcodeproj/project.pbxproj b/tanks.xcodeproj/project.pbxproj index 559abcf..c022019 100644 --- a/tanks.xcodeproj/project.pbxproj +++ b/tanks.xcodeproj/project.pbxproj @@ -16,6 +16,8 @@ 49966919136930E8006E8125 /* OpenAL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 49966914136930E8006E8125 /* OpenAL.framework */; }; 4996691A136930E8006E8125 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 49966915136930E8006E8125 /* OpenGLES.framework */; }; 4996691B136930E8006E8125 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 49966916136930E8006E8125 /* QuartzCore.framework */; }; + 49DA67D4137847A7004841E9 /* World.h in Headers */ = {isa = PBXBuildFile; fileRef = 49DA67D2137847A7004841E9 /* World.h */; }; + 49DA67D5137847A7004841E9 /* World.mm in Sources */ = {isa = PBXBuildFile; fileRef = 49DA67D3137847A7004841E9 /* World.mm */; }; 49F2D9C413764666000B6B8C /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 49F2D9B013764666000B6B8C /* main.m */; }; 49F2D9C513764666000B6B8C /* RootAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 49F2D9B513764666000B6B8C /* RootAppDelegate.m */; }; 49F2D9C613764666000B6B8C /* Game.m in Sources */ = {isa = PBXBuildFile; fileRef = 49F2D9B813764666000B6B8C /* Game.m */; }; @@ -156,6 +158,8 @@ 49966914136930E8006E8125 /* OpenAL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenAL.framework; path = System/Library/Frameworks/OpenAL.framework; sourceTree = SDKROOT; }; 49966915136930E8006E8125 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; }; 49966916136930E8006E8125 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; + 49DA67D2137847A7004841E9 /* World.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = World.h; sourceTree = ""; }; + 49DA67D3137847A7004841E9 /* World.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = World.mm; sourceTree = ""; }; 49F2D99B137645DF000B6B8C /* box2d-ios.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "box2d-ios.xcodeproj"; path = "libs/box2d/box2d-ios.xcodeproj"; sourceTree = ""; }; 49F2D9B013764666000B6B8C /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 49F2D9B213764666000B6B8C /* prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = prefix.pch; sourceTree = ""; }; @@ -371,6 +375,8 @@ 49F2D9B113764666000B6B8C /* physics */ = { isa = PBXGroup; children = ( + 49DA67D2137847A7004841E9 /* World.h */, + 49DA67D3137847A7004841E9 /* World.mm */, ); path = physics; sourceTree = ""; @@ -736,6 +742,7 @@ 49F2DADF13764ED6000B6B8C /* Sparrow.h in Headers */, 49F2DAF213765004000B6B8C /* GLES-Render.h in Headers */, 49F2DB341376632E000B6B8C /* Unit.h in Headers */, + 49DA67D4137847A7004841E9 /* World.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -868,6 +875,7 @@ 49F2DADE13764ED6000B6B8C /* SPUtils.m in Sources */, 49F2DAF313765004000B6B8C /* GLES-Render.mm in Sources */, 49F2DB351376632E000B6B8C /* Unit.m in Sources */, + 49DA67D5137847A7004841E9 /* World.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };