Permalink
Browse files

b2Body bridge

  • Loading branch information...
1 parent 3280a82 commit cb6527b7f8eeca7261d4c5fa01f9f60113670526 @asivitz committed Jul 10, 2012
Showing with 133 additions and 243 deletions.
  1. +1 −0 .gitignore
  2. +60 −0 ext/Body.cpp
  3. +23 −0 ext/Body.h
  4. +0 −225 ext/Makefile
  5. +5 −10 ext/Physics.cpp
  6. +7 −4 ext/Physics.h
  7. +29 −2 ext/Platform.cpp
  8. +2 −1 ext/Platform.h
  9. +3 −0 ext/extconf.rb
  10. +3 −1 main.rb
View
@@ -2,3 +2,4 @@ bin/
*.o
*.log
*.bundle
+ext/Makefile
View
@@ -0,0 +1,60 @@
+#include "Body.h"
+#include <iostream>
+
+#include "rice/Class.hpp"
+#include "rice/String.hpp"
+#include "rice/Array.hpp"
+#include "rice/Constructor.hpp"
+#include "rice/Data_Type.hpp"
+
+#include <SFML/Graphics.hpp>
+//#include <SFML/Image.hpp>
+
+using namespace Rice;
+using namespace std;
+
+/*
+Body::Body(Object self) : Rice::Director(self)
+{
+}
+*/
+
+/*
+Body::~Body()
+{
+}
+*/
+
+template<>
+Rice::Object to_ruby<vec2>(vec2 const & param)
+{
+ Array arr;
+ arr.push(param.x);
+ arr.push(param.y);
+ return arr;
+}
+
+template<>
+vec2 from_ruby<vec2>(Rice::Object x)
+{
+ Array arr(x);
+ if (arr.size() == 2)
+ {
+ vec2 v;
+ VALUE * carr = arr.to_c_array();
+ v.x = NUM2DBL(carr[0]);
+ v.y = NUM2DBL(carr[1]);
+ return v;
+ }
+ return VECNULL;
+}
+
+Object Body::pos()
+{
+ vec2 pos = body->GetPosition();
+ return to_ruby<vec2>(pos);
+ //Array arr;
+ //arr.push(pos.x);
+ //arr.push(pos.y);
+ //return arr;
+}
View
@@ -0,0 +1,23 @@
+#ifndef MLD_BODY_H_
+#define MLD_BODY_H_
+
+#include "Renderer.h"
+#include "Physics.h"
+#include "rice/Array.hpp"
+#include "rice/Director.hpp"
+#include <SFML/Window.hpp>
+
+using namespace Rice;
+
+class Body // : public Rice::Director
+{
+
+ public:
+ b2Body * body;
+ //Platform(Object self);
+ //~Body(Object self);
+ Object pos();
+};
+
+#endif
+
View
@@ -1,225 +0,0 @@
-
-SHELL = /bin/sh
-
-#### Start of system configuration section. ####
-
-srcdir = .
-topdir = /Users/axis/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1
-hdrdir = /Users/axis/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1
-arch_hdrdir = /Users/axis/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/$(arch)
-VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
-
-prefix = $(DESTDIR)/Users/axis/.rvm/rubies/ruby-1.9.2-p290
-
-rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
-
-exec_prefix = $(prefix)
-
-vendorhdrdir = $(rubyhdrdir)/vendor_ruby
-
-sitehdrdir = $(rubyhdrdir)/site_ruby
-
-rubyhdrdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version)
-
-vendordir = $(rubylibprefix)/vendor_ruby
-
-sitedir = $(rubylibprefix)/site_ruby
-
-ridir = $(datarootdir)/$(RI_BASE_NAME)
-
-mandir = $(datarootdir)/man
-
-localedir = $(datarootdir)/locale
-
-libdir = $(exec_prefix)/lib
-
-psdir = $(docdir)
-
-pdfdir = $(docdir)
-
-dvidir = $(docdir)
-
-htmldir = $(docdir)
-
-infodir = $(datarootdir)/info
-
-docdir = $(datarootdir)/doc/$(PACKAGE)
-
-oldincludedir = $(DESTDIR)/usr/include
-
-includedir = $(prefix)/include
-
-localstatedir = $(prefix)/var
-
-sharedstatedir = $(prefix)/com
-
-sysconfdir = $(prefix)/etc
-
-datadir = $(datarootdir)
-
-datarootdir = $(prefix)/share
-
-libexecdir = $(exec_prefix)/libexec
-
-sbindir = $(exec_prefix)/sbin
-
-bindir = $(exec_prefix)/bin
-
-rubylibdir = $(rubylibprefix)/$(ruby_version)
-
-archdir = $(rubylibdir)/$(arch)
-
-sitelibdir = $(sitedir)/$(ruby_version)
-
-sitearchdir = $(sitelibdir)/$(sitearch)
-
-vendorlibdir = $(vendordir)/$(ruby_version)
-
-vendorarchdir = $(vendorlibdir)/$(sitearch)
-
-
-CC = /usr/bin/gcc-4.2
-CXX = g++
-LIBRUBY = $(LIBRUBY_SO)
-LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
-LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
-LIBRUBYARG_STATIC = -lruby.1.9.1-static
-OUTFLAG = -o
-COUTFLAG = -o
-
-RUBY_EXTCONF_H =
-cflags = $(optflags) $(debugflags) $(warnflags)
-optflags = -O3
-debugflags = -ggdb
-warnflags = -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long
-CFLAGS = -fno-common $(cflags) -fno-common -pipe
-INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
-DEFS =
-CPPFLAGS = -I/Users/axis/Development/Box2D_v2.2.1/ -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags) -I/Users/axis/.rvm/gems/ruby-1.9.2-p290/gems/rice-1.4.3/ruby/lib/include
-CXXFLAGS = $(CFLAGS) -Wall -g
-ldflags = -L. -L/Users/axis/.rvm/gems/ruby-1.9.2-p290/gems/rice-1.4.3/ruby/lib/lib -framework OpenGL -framework SFML -framework sfml-graphics -framework sfml-window -framework sfml-system -lBox2D
-dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace
-ARCH_FLAG =
-DLDFLAGS = $(ldflags) $(dldflags)
-LDSHARED = g++ -dynamic -bundle
-LDSHAREDXX = $(CXX) -dynamic -bundle
-AR = ar
-EXEEXT =
-
-RUBY_BASE_NAME = ruby
-RUBY_INSTALL_NAME = ruby
-RUBY_SO_NAME = ruby.1.9.1
-arch = x86_64-darwin11.2.0
-sitearch = $(arch)
-ruby_version = 1.9.1
-ruby = /Users/axis/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
-RUBY = $(ruby)
-RM = rm -f
-RM_RF = $(RUBY) -run -e rm -- -rf
-RMDIRS = $(RUBY) -run -e rmdir -- -p
-MAKEDIRS = mkdir -p
-INSTALL = /usr/bin/install -c
-INSTALL_PROG = $(INSTALL) -m 0755
-INSTALL_DATA = $(INSTALL) -m 644
-COPY = cp
-
-#### End of system configuration section. ####
-
-preload =
-
-
-CXX = g++
-
-libpath = . $(libdir) /Users/axis/Development/Box2D_v2.2.1/Build/Box2D/
-LIBPATH = -L. -L$(libdir) -L/Users/axis/Development/Box2D_v2.2.1/Build/Box2D/
-DEFFILE =
-
-CLEANFILES = mkmf.log
-DISTCLEANFILES =
-DISTCLEANDIRS =
-
-extout =
-extout_prefix =
-target_prefix =
-LOCAL_LIBS =
-LIBS = -lrice -lruby.1.9.1 -lpthread -ldl -lobjc
-SRCS = GLES-Render.cpp Physics.cpp Platform.cpp Renderer.cpp ShaderProgram.cpp
-OBJS = GLES-Render.o Physics.o Platform.o Renderer.o ShaderProgram.o
-TARGET = engine
-DLLIB = $(TARGET).bundle
-EXTSTATIC =
-STATIC_LIB =
-
-BINDIR = $(bindir)
-RUBYCOMMONDIR = $(sitedir)$(target_prefix)
-RUBYLIBDIR = $(sitelibdir)$(target_prefix)
-RUBYARCHDIR = $(sitearchdir)$(target_prefix)
-HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
-ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
-
-TARGET_SO = $(DLLIB)
-CLEANLIBS = $(TARGET).bundle
-CLEANOBJS = *.o *.bak
-
-all: $(DLLIB)
-static: $(STATIC_LIB)
-.PHONY: all install static install-so install-rb
-.PHONY: clean clean-so clean-rb
-
-clean-rb-default::
-clean-rb::
-clean-so::
-clean: clean-so clean-rb-default clean-rb
- @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
-
-distclean-rb-default::
-distclean-rb::
-distclean-so::
-distclean: clean distclean-so distclean-rb-default distclean-rb
- @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
- @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
- @-$(RMDIRS) $(DISTCLEANDIRS)
-
-realclean: distclean
-install: install-so install-rb
-
-install-so: $(RUBYARCHDIR)
-install-so: $(RUBYARCHDIR)/$(DLLIB)
-$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
- @-$(MAKEDIRS) $(@D)
- $(INSTALL_PROG) $(DLLIB) $(@D)
-install-rb: pre-install-rb install-rb-default
-install-rb-default: pre-install-rb-default
-pre-install-rb: Makefile
-pre-install-rb-default: Makefile
-$(RUBYARCHDIR):
- $(MAKEDIRS) $@
-
-site-install: site-install-so site-install-rb
-site-install-so: install-so
-site-install-rb: install-rb
-
-.SUFFIXES: .c .m .cc .cxx .cpp .C .o
-
-.cc.o:
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
-
-.cxx.o:
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
-
-.cpp.o:
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
-
-.C.o:
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
-
-.c.o:
- $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
-
-$(DLLIB): $(OBJS) Makefile
- @-$(RM) $(@)
- $(LDSHAREDXX) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
-
-
-
-$(OBJS): $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/config.h
View
@@ -292,13 +292,13 @@ b2Body * Physics::addParticle(vec2 pos)
return body;
}
-b2Body * Physics::addProjectile(vec2 pos, float size)
+b2Body * Physics::addGrenade(vec2 pos, float size)
{
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(pos.x, pos.y);
- bodyDef.fixedRotation = true;
+ //bodyDef.fixedRotation = true;
bodyDef.bullet = true;
b2Body* body = boxworld->CreateBody(&bodyDef);
@@ -309,15 +309,10 @@ b2Body * Physics::addProjectile(vec2 pos, float size)
fixtureDef.shape = &dynamicCircle;
- b2Filter filter;
- filter.categoryBits = 0x0020;
- filter.maskBits = 0xFFFF;
- filter.groupIndex = 0;
-
- fixtureDef.filter = filter;
- fixtureDef.density = 0.1f;
+ fixtureDef.filter = defaultFilter;
+ fixtureDef.density = 1.0f;
fixtureDef.friction = 10.0f;
- fixtureDef.restitution = 0.1;
+ fixtureDef.restitution = 1.0;
body->CreateFixture(&fixtureDef);
return body;
View
@@ -1,3 +1,5 @@
+#ifndef _PHYSICS__H_
+#define _PHYSICS__H_
//
// Physics.h
// Button
@@ -6,8 +8,8 @@
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
-#import <Box2D/Box2D.h>
-#import "GLES-Render.h"
+#include <Box2D/Box2D.h>
+#include "GLES-Render.h"
//#import "BContactListener.h"
//#import <vector>
@@ -49,8 +51,7 @@ class Physics
b2Body * addParticle(vec2 pos);
b2Body * addSensor(vec2 pos, vec2 extens);
b2Body * addWormSection(vec2 pos, float radius);
- b2Body * addProjectile(vec2 pos);
- b2Body * addProjectile(vec2 pos, float size);
+ b2Body * addGrenade(vec2 pos, float size);
b2Body * addEmptyBody(vec2 pos);
b2Body * addDummy(vec2 pos, vec2 extens);
void remove(b2Body * obj);
@@ -64,3 +65,5 @@ vec2 rotate(vec2 inVec, float angle);
vec2 randomOffset();
vec2 lerp(vec2 one, vec2 two, float interp);
vec2 centerPoint(vec2 inPoint);
+
+#endif
Oops, something went wrong.

0 comments on commit cb6527b

Please sign in to comment.