Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed licensing, readme and updated with more APIs

  • Loading branch information...
commit 37915c3218382b6b08d0a95da48fea6a1368e60c 1 parent acd7167
@jhaynie authored
Showing with 164 additions and 8 deletions.
  1. +120 −1 Classes/TiBox2dBodyProxy.mm
  2. +13 −1 LICENSE
  3. +29 −4 README.md
  4. +2 −2 manifest
View
121 Classes/TiBox2dBodyProxy.mm
@@ -12,7 +12,7 @@ @implementation TiBox2dBodyProxy
-(id)initWithBody:(b2Body*)body_ viewproxy:(TiViewProxy*)vp pageContext:(id<TiEvaluator>)context
{
- if (self = [super _initWithPageContext:context])
+ if ((self = [super _initWithPageContext:context]))
{
body = body_;
viewproxy = [vp retain];
@@ -31,4 +31,123 @@ -(TiViewProxy*)viewproxy
return viewproxy;
}
+#define B2VEC2_ARRAY(v) [NSArray arrayWithObjects:NUMDOUBLE(v.x), NUMDOUBLE(v.y),nil];
+#define ARRAY_B2VEC2(a,b) b2Vec2 b([TiUtils doubleValue:[a objectAtIndex:0]], [TiUtils doubleValue:[a objectAtIndex:1]]);
+
+-(NSArray*)getLocalCenter:(id)args
+{
+ const b2Vec2& center = body->GetLocalCenter();
+ return B2VEC2_ARRAY(center);
+}
+
+-(NSArray*)getWorldCenter:(id)args
+{
+ const b2Vec2& center = body->GetWorldCenter();
+ return B2VEC2_ARRAY(center);
+}
+
+-(NSArray*)getLinearVelocity:(id)args
+{
+ const b2Vec2& velocity = body->GetLinearVelocity();
+ return B2VEC2_ARRAY(velocity);
+}
+
+-(NSArray*)getPosition:(id)args
+{
+ const b2Vec2& velocity = body->GetPosition();
+ return B2VEC2_ARRAY(velocity);
+}
+
+-(id)getAngularVelocity:(id)args
+{
+ float v = body->GetAngularVelocity();
+ return NUMFLOAT(v);
+}
+
+-(id)getMass:(id)args
+{
+ float v = body->GetMass();
+ return NUMFLOAT(v);
+}
+
+-(id)getInertia:(id)args
+{
+ float v = body->GetInertia();
+ return NUMFLOAT(v);
+}
+
+-(id)isAwake:(id)args
+{
+ return NUMBOOL(body->IsAwake());
+}
+
+-(void)setAwake:(id)args
+{
+ ENSURE_SINGLE_ARG(args,NSNumber);
+
+ bool x = [TiUtils boolValue:args];
+ body->SetAwake(x);
+}
+
+-(void)setLinearVelocity:(id)args
+{
+ ENSURE_SINGLE_ARG(args,NSArray);
+ ARRAY_B2VEC2(args,v);
+ body->SetLinearVelocity(v);
+}
+
+//
+// body.applyForce([1,0], [1,2])
+//
+-(void)applyForce:(id)args
+{
+ ENSURE_ARG_COUNT(args, 2);
+
+ NSArray *a1 = [args objectAtIndex:0];
+ NSArray *a2 = [args objectAtIndex:1];
+
+ ARRAY_B2VEC2(a1,force);
+ ARRAY_B2VEC2(a2,point);
+
+ body->ApplyForce(force, point);
+}
+
+//
+// body.applyLinearImpulse([1,0], [1,2])
+//
+-(void)applyLinearImpulse:(id)args
+{
+ ENSURE_ARG_COUNT(args, 2);
+
+ NSArray *a1 = [args objectAtIndex:0];
+ NSArray *a2 = [args objectAtIndex:1];
+
+ ARRAY_B2VEC2(a1,force);
+ ARRAY_B2VEC2(a2,point);
+
+ body->ApplyLinearImpulse(force, point);
+}
+
+//
+// body.applyTorque(1.0f)
+//
+-(void)applyTorque:(id)args
+{
+ ENSURE_SINGLE_ARG(args,NSNumber);
+
+ CGFloat t = [TiUtils floatValue:args];
+ body->ApplyTorque(t);
+}
+
+//
+// body.applyAngularImpulse(1.0f)
+//
+-(void)applyAngularImpulse:(id)args
+{
+ ENSURE_SINGLE_ARG(args,NSNumber);
+
+ CGFloat i = [TiUtils floatValue:args];
+ body->ApplyAngularImpulse(i);
+}
+
@end
View
14 LICENSE
@@ -1,2 +1,14 @@
-Appcelerator Commercial License
+Copyright 2011 Jeff Haynie
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
View
33 README.md
@@ -1,8 +1,12 @@
-Titanium Box2D Module for iOS
-=============================
+Appcelerator Titanium Box2D Module for iOS
+==========================================
This is a Box2D module for iOS developed by Jeff Haynie.
+[Box2D](http://www.box2d.org/) is one of the most popular physics engines used for all sorts of
+cool things from popular games like Angry Birds to engineering simulations.
+
+
Basic usage:
~~~
@@ -51,8 +55,29 @@ TODO
There's a lot that's not currently supported and needs to be implemented.
Right now, I basically only support adding either a rectangle or cirlce body
-to the world and the various body properties. No complex polygons. I don't
-yet support applying force or other more sophisticated physics capabilities.
+to the world and the various body properties. No complex polygons.
+
+
+HOW TO HELP
+==========
+
+Here's how you can help me make this full featured.
+
+- Write lots of sample apps!
+- Write API documentation
+- Write better usage guides
+- Find and report bugs (for now, just use GitHub issues)
+- Fork it and add other missing APIs
+- Port to Android
+- Port to HTML5
+
+
+LICENSE
+=======
+Apache Public License version 2
+COPYRIGHT
+=========
+Copyright (c) 2011 by Jeff Haynie. All Rights Reserved.
View
4 manifest
@@ -5,8 +5,8 @@
version: 0.1
description: Box2D physics engine
author: Jeff Haynie
-license: Appcelerator Commercial License
-copyright: Copyright (c) 2011 by Appcelerator, Inc.
+license: Apache Public License v2
+copyright: Copyright (c) 2011 by Jeff Haynie
# these should not be edited
Please sign in to comment.
Something went wrong with that request. Please try again.