code:
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8

# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target

#=============================================================================
# Special targets provided by cmake.

# Disable implicit rules so canoncical targets will work.
.SUFFIXES:

# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =

.SUFFIXES: .hpux_make_needs_suffix_list

# Suppress display of executed commands.
$(VERBOSE).SILENT:

# A target that is always out of date.
cmake_force:
.PHONY : cmake_force

#=============================================================================
# Set environment variables for the build.

# The shell in which to execute make rules.
SHELL = /bin/sh

# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake

# The command to remove a file.
RM = /usr/bin/cmake -E remove -f

# The program to use to edit the cache.
CMAKE_EDIT_COMMAND = /usr/bin/cmake-gui

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/laschweinski/git/cocos2d-x/chipmunk

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/laschweinski/git/cocos2d-x/chipmunk

#=============================================================================
# Targets provided globally by CMake.

# Special rule for the target edit_cache
edit_cache:
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
	/usr/bin/cmake-gui -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache

# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast

# Special rule for the target install
install: preinstall
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
	/usr/bin/cmake -P cmake_install.cmake
.PHONY : install

# Special rule for the target install
install/fast: preinstall/fast
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
	/usr/bin/cmake -P cmake_install.cmake
.PHONY : install/fast

# Special rule for the target install/local
install/local: preinstall
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
	/usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
.PHONY : install/local

# Special rule for the target install/local
install/local/fast: install/local
.PHONY : install/local/fast

# Special rule for the target install/strip
install/strip: preinstall
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
	/usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
.PHONY : install/strip

# Special rule for the target install/strip
install/strip/fast: install/strip
.PHONY : install/strip/fast

# Special rule for the target list_install_components
list_install_components:
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\""
.PHONY : list_install_components

# Special rule for the target list_install_components
list_install_components/fast: list_install_components
.PHONY : list_install_components/fast

# Special rule for the target rebuild_cache
rebuild_cache:
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
	/usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache

# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast

# The main all target
all: cmake_check_build_system
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(CMAKE_COMMAND) -E cmake_progress_start /home/laschweinski/git/cocos2d-x/chipmunk/CMakeFiles /home/laschweinski/git/cocos2d-x/chipmunk/src/CMakeFiles/progress.marks
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f CMakeFiles/Makefile2 src/all
	$(CMAKE_COMMAND) -E cmake_progress_start /home/laschweinski/git/cocos2d-x/chipmunk/CMakeFiles 0
.PHONY : all

# The main clean target
clean:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f CMakeFiles/Makefile2 src/clean
.PHONY : clean

# The main clean target
clean/fast: clean
.PHONY : clean/fast

# Prepare targets for installation.
preinstall: all
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f CMakeFiles/Makefile2 src/preinstall
.PHONY : preinstall

# Prepare targets for installation.
preinstall/fast:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f CMakeFiles/Makefile2 src/preinstall
.PHONY : preinstall/fast

# clear depends
depend:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend

# Convenience name for target.
src/CMakeFiles/chipmunk.dir/rule:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f CMakeFiles/Makefile2 src/CMakeFiles/chipmunk.dir/rule
.PHONY : src/CMakeFiles/chipmunk.dir/rule

# Convenience name for target.
chipmunk: src/CMakeFiles/chipmunk.dir/rule
.PHONY : chipmunk

# fast build rule for target.
chipmunk/fast:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/build
.PHONY : chipmunk/fast

# Convenience name for target.
src/CMakeFiles/chipmunk_static.dir/rule:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f CMakeFiles/Makefile2 src/CMakeFiles/chipmunk_static.dir/rule
.PHONY : src/CMakeFiles/chipmunk_static.dir/rule

# Convenience name for target.
chipmunk_static: src/CMakeFiles/chipmunk_static.dir/rule
.PHONY : chipmunk_static

# fast build rule for target.
chipmunk_static/fast:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/build
.PHONY : chipmunk_static/fast

chipmunk.o: chipmunk.c.o
.PHONY : chipmunk.o

# target to build an object file
chipmunk.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/chipmunk.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/chipmunk.c.o
.PHONY : chipmunk.c.o

chipmunk.i: chipmunk.c.i
.PHONY : chipmunk.i

# target to preprocess a source file
chipmunk.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/chipmunk.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/chipmunk.c.i
.PHONY : chipmunk.c.i

chipmunk.s: chipmunk.c.s
.PHONY : chipmunk.s

# target to generate assembly for a file
chipmunk.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/chipmunk.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/chipmunk.c.s
.PHONY : chipmunk.c.s

constraints/cpConstraint.o: constraints/cpConstraint.c.o
.PHONY : constraints/cpConstraint.o

# target to build an object file
constraints/cpConstraint.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpConstraint.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpConstraint.c.o
.PHONY : constraints/cpConstraint.c.o

constraints/cpConstraint.i: constraints/cpConstraint.c.i
.PHONY : constraints/cpConstraint.i

# target to preprocess a source file
constraints/cpConstraint.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpConstraint.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpConstraint.c.i
.PHONY : constraints/cpConstraint.c.i

constraints/cpConstraint.s: constraints/cpConstraint.c.s
.PHONY : constraints/cpConstraint.s

# target to generate assembly for a file
constraints/cpConstraint.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpConstraint.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpConstraint.c.s
.PHONY : constraints/cpConstraint.c.s

constraints/cpDampedRotarySpring.o: constraints/cpDampedRotarySpring.c.o
.PHONY : constraints/cpDampedRotarySpring.o

# target to build an object file
constraints/cpDampedRotarySpring.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpDampedRotarySpring.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpDampedRotarySpring.c.o
.PHONY : constraints/cpDampedRotarySpring.c.o

constraints/cpDampedRotarySpring.i: constraints/cpDampedRotarySpring.c.i
.PHONY : constraints/cpDampedRotarySpring.i

# target to preprocess a source file
constraints/cpDampedRotarySpring.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpDampedRotarySpring.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpDampedRotarySpring.c.i
.PHONY : constraints/cpDampedRotarySpring.c.i

constraints/cpDampedRotarySpring.s: constraints/cpDampedRotarySpring.c.s
.PHONY : constraints/cpDampedRotarySpring.s

# target to generate assembly for a file
constraints/cpDampedRotarySpring.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpDampedRotarySpring.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpDampedRotarySpring.c.s
.PHONY : constraints/cpDampedRotarySpring.c.s

constraints/cpDampedSpring.o: constraints/cpDampedSpring.c.o
.PHONY : constraints/cpDampedSpring.o

# target to build an object file
constraints/cpDampedSpring.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpDampedSpring.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpDampedSpring.c.o
.PHONY : constraints/cpDampedSpring.c.o

constraints/cpDampedSpring.i: constraints/cpDampedSpring.c.i
.PHONY : constraints/cpDampedSpring.i

# target to preprocess a source file
constraints/cpDampedSpring.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpDampedSpring.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpDampedSpring.c.i
.PHONY : constraints/cpDampedSpring.c.i

constraints/cpDampedSpring.s: constraints/cpDampedSpring.c.s
.PHONY : constraints/cpDampedSpring.s

# target to generate assembly for a file
constraints/cpDampedSpring.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpDampedSpring.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpDampedSpring.c.s
.PHONY : constraints/cpDampedSpring.c.s

constraints/cpGearJoint.o: constraints/cpGearJoint.c.o
.PHONY : constraints/cpGearJoint.o

# target to build an object file
constraints/cpGearJoint.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpGearJoint.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpGearJoint.c.o
.PHONY : constraints/cpGearJoint.c.o

constraints/cpGearJoint.i: constraints/cpGearJoint.c.i
.PHONY : constraints/cpGearJoint.i

# target to preprocess a source file
constraints/cpGearJoint.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpGearJoint.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpGearJoint.c.i
.PHONY : constraints/cpGearJoint.c.i

constraints/cpGearJoint.s: constraints/cpGearJoint.c.s
.PHONY : constraints/cpGearJoint.s

# target to generate assembly for a file
constraints/cpGearJoint.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpGearJoint.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpGearJoint.c.s
.PHONY : constraints/cpGearJoint.c.s

constraints/cpGrooveJoint.o: constraints/cpGrooveJoint.c.o
.PHONY : constraints/cpGrooveJoint.o

# target to build an object file
constraints/cpGrooveJoint.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpGrooveJoint.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpGrooveJoint.c.o
.PHONY : constraints/cpGrooveJoint.c.o

constraints/cpGrooveJoint.i: constraints/cpGrooveJoint.c.i
.PHONY : constraints/cpGrooveJoint.i

# target to preprocess a source file
constraints/cpGrooveJoint.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpGrooveJoint.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpGrooveJoint.c.i
.PHONY : constraints/cpGrooveJoint.c.i

constraints/cpGrooveJoint.s: constraints/cpGrooveJoint.c.s
.PHONY : constraints/cpGrooveJoint.s

# target to generate assembly for a file
constraints/cpGrooveJoint.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpGrooveJoint.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpGrooveJoint.c.s
.PHONY : constraints/cpGrooveJoint.c.s

constraints/cpPinJoint.o: constraints/cpPinJoint.c.o
.PHONY : constraints/cpPinJoint.o

# target to build an object file
constraints/cpPinJoint.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpPinJoint.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpPinJoint.c.o
.PHONY : constraints/cpPinJoint.c.o

constraints/cpPinJoint.i: constraints/cpPinJoint.c.i
.PHONY : constraints/cpPinJoint.i

# target to preprocess a source file
constraints/cpPinJoint.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpPinJoint.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpPinJoint.c.i
.PHONY : constraints/cpPinJoint.c.i

constraints/cpPinJoint.s: constraints/cpPinJoint.c.s
.PHONY : constraints/cpPinJoint.s

# target to generate assembly for a file
constraints/cpPinJoint.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpPinJoint.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpPinJoint.c.s
.PHONY : constraints/cpPinJoint.c.s

constraints/cpPivotJoint.o: constraints/cpPivotJoint.c.o
.PHONY : constraints/cpPivotJoint.o

# target to build an object file
constraints/cpPivotJoint.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpPivotJoint.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpPivotJoint.c.o
.PHONY : constraints/cpPivotJoint.c.o

constraints/cpPivotJoint.i: constraints/cpPivotJoint.c.i
.PHONY : constraints/cpPivotJoint.i

# target to preprocess a source file
constraints/cpPivotJoint.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpPivotJoint.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpPivotJoint.c.i
.PHONY : constraints/cpPivotJoint.c.i

constraints/cpPivotJoint.s: constraints/cpPivotJoint.c.s
.PHONY : constraints/cpPivotJoint.s

# target to generate assembly for a file
constraints/cpPivotJoint.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpPivotJoint.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpPivotJoint.c.s
.PHONY : constraints/cpPivotJoint.c.s

constraints/cpRatchetJoint.o: constraints/cpRatchetJoint.c.o
.PHONY : constraints/cpRatchetJoint.o

# target to build an object file
constraints/cpRatchetJoint.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpRatchetJoint.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpRatchetJoint.c.o
.PHONY : constraints/cpRatchetJoint.c.o

constraints/cpRatchetJoint.i: constraints/cpRatchetJoint.c.i
.PHONY : constraints/cpRatchetJoint.i

# target to preprocess a source file
constraints/cpRatchetJoint.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpRatchetJoint.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpRatchetJoint.c.i
.PHONY : constraints/cpRatchetJoint.c.i

constraints/cpRatchetJoint.s: constraints/cpRatchetJoint.c.s
.PHONY : constraints/cpRatchetJoint.s

# target to generate assembly for a file
constraints/cpRatchetJoint.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpRatchetJoint.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpRatchetJoint.c.s
.PHONY : constraints/cpRatchetJoint.c.s

constraints/cpRotaryLimitJoint.o: constraints/cpRotaryLimitJoint.c.o
.PHONY : constraints/cpRotaryLimitJoint.o

# target to build an object file
constraints/cpRotaryLimitJoint.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpRotaryLimitJoint.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpRotaryLimitJoint.c.o
.PHONY : constraints/cpRotaryLimitJoint.c.o

constraints/cpRotaryLimitJoint.i: constraints/cpRotaryLimitJoint.c.i
.PHONY : constraints/cpRotaryLimitJoint.i

# target to preprocess a source file
constraints/cpRotaryLimitJoint.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpRotaryLimitJoint.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpRotaryLimitJoint.c.i
.PHONY : constraints/cpRotaryLimitJoint.c.i

constraints/cpRotaryLimitJoint.s: constraints/cpRotaryLimitJoint.c.s
.PHONY : constraints/cpRotaryLimitJoint.s

# target to generate assembly for a file
constraints/cpRotaryLimitJoint.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpRotaryLimitJoint.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpRotaryLimitJoint.c.s
.PHONY : constraints/cpRotaryLimitJoint.c.s

constraints/cpSimpleMotor.o: constraints/cpSimpleMotor.c.o
.PHONY : constraints/cpSimpleMotor.o

# target to build an object file
constraints/cpSimpleMotor.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpSimpleMotor.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpSimpleMotor.c.o
.PHONY : constraints/cpSimpleMotor.c.o

constraints/cpSimpleMotor.i: constraints/cpSimpleMotor.c.i
.PHONY : constraints/cpSimpleMotor.i

# target to preprocess a source file
constraints/cpSimpleMotor.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpSimpleMotor.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpSimpleMotor.c.i
.PHONY : constraints/cpSimpleMotor.c.i

constraints/cpSimpleMotor.s: constraints/cpSimpleMotor.c.s
.PHONY : constraints/cpSimpleMotor.s

# target to generate assembly for a file
constraints/cpSimpleMotor.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpSimpleMotor.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpSimpleMotor.c.s
.PHONY : constraints/cpSimpleMotor.c.s

constraints/cpSlideJoint.o: constraints/cpSlideJoint.c.o
.PHONY : constraints/cpSlideJoint.o

# target to build an object file
constraints/cpSlideJoint.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpSlideJoint.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpSlideJoint.c.o
.PHONY : constraints/cpSlideJoint.c.o

constraints/cpSlideJoint.i: constraints/cpSlideJoint.c.i
.PHONY : constraints/cpSlideJoint.i

# target to preprocess a source file
constraints/cpSlideJoint.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpSlideJoint.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpSlideJoint.c.i
.PHONY : constraints/cpSlideJoint.c.i

constraints/cpSlideJoint.s: constraints/cpSlideJoint.c.s
.PHONY : constraints/cpSlideJoint.s

# target to generate assembly for a file
constraints/cpSlideJoint.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/constraints/cpSlideJoint.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/constraints/cpSlideJoint.c.s
.PHONY : constraints/cpSlideJoint.c.s

cpArbiter.o: cpArbiter.c.o
.PHONY : cpArbiter.o

# target to build an object file
cpArbiter.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpArbiter.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpArbiter.c.o
.PHONY : cpArbiter.c.o

cpArbiter.i: cpArbiter.c.i
.PHONY : cpArbiter.i

# target to preprocess a source file
cpArbiter.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpArbiter.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpArbiter.c.i
.PHONY : cpArbiter.c.i

cpArbiter.s: cpArbiter.c.s
.PHONY : cpArbiter.s

# target to generate assembly for a file
cpArbiter.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpArbiter.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpArbiter.c.s
.PHONY : cpArbiter.c.s

cpArray.o: cpArray.c.o
.PHONY : cpArray.o

# target to build an object file
cpArray.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpArray.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpArray.c.o
.PHONY : cpArray.c.o

cpArray.i: cpArray.c.i
.PHONY : cpArray.i

# target to preprocess a source file
cpArray.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpArray.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpArray.c.i
.PHONY : cpArray.c.i

cpArray.s: cpArray.c.s
.PHONY : cpArray.s

# target to generate assembly for a file
cpArray.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpArray.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpArray.c.s
.PHONY : cpArray.c.s

cpBB.o: cpBB.c.o
.PHONY : cpBB.o

# target to build an object file
cpBB.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpBB.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpBB.c.o
.PHONY : cpBB.c.o

cpBB.i: cpBB.c.i
.PHONY : cpBB.i

# target to preprocess a source file
cpBB.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpBB.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpBB.c.i
.PHONY : cpBB.c.i

cpBB.s: cpBB.c.s
.PHONY : cpBB.s

# target to generate assembly for a file
cpBB.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpBB.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpBB.c.s
.PHONY : cpBB.c.s

cpBody.o: cpBody.c.o
.PHONY : cpBody.o

# target to build an object file
cpBody.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpBody.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpBody.c.o
.PHONY : cpBody.c.o

cpBody.i: cpBody.c.i
.PHONY : cpBody.i

# target to preprocess a source file
cpBody.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpBody.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpBody.c.i
.PHONY : cpBody.c.i

cpBody.s: cpBody.c.s
.PHONY : cpBody.s

# target to generate assembly for a file
cpBody.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpBody.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpBody.c.s
.PHONY : cpBody.c.s

cpCollision.o: cpCollision.c.o
.PHONY : cpCollision.o

# target to build an object file
cpCollision.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpCollision.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpCollision.c.o
.PHONY : cpCollision.c.o

cpCollision.i: cpCollision.c.i
.PHONY : cpCollision.i

# target to preprocess a source file
cpCollision.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpCollision.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpCollision.c.i
.PHONY : cpCollision.c.i

cpCollision.s: cpCollision.c.s
.PHONY : cpCollision.s

# target to generate assembly for a file
cpCollision.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpCollision.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpCollision.c.s
.PHONY : cpCollision.c.s

cpHashSet.o: cpHashSet.c.o
.PHONY : cpHashSet.o

# target to build an object file
cpHashSet.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpHashSet.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpHashSet.c.o
.PHONY : cpHashSet.c.o

cpHashSet.i: cpHashSet.c.i
.PHONY : cpHashSet.i

# target to preprocess a source file
cpHashSet.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpHashSet.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpHashSet.c.i
.PHONY : cpHashSet.c.i

cpHashSet.s: cpHashSet.c.s
.PHONY : cpHashSet.s

# target to generate assembly for a file
cpHashSet.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpHashSet.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpHashSet.c.s
.PHONY : cpHashSet.c.s

cpPolyShape.o: cpPolyShape.c.o
.PHONY : cpPolyShape.o

# target to build an object file
cpPolyShape.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpPolyShape.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpPolyShape.c.o
.PHONY : cpPolyShape.c.o

cpPolyShape.i: cpPolyShape.c.i
.PHONY : cpPolyShape.i

# target to preprocess a source file
cpPolyShape.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpPolyShape.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpPolyShape.c.i
.PHONY : cpPolyShape.c.i

cpPolyShape.s: cpPolyShape.c.s
.PHONY : cpPolyShape.s

# target to generate assembly for a file
cpPolyShape.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpPolyShape.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpPolyShape.c.s
.PHONY : cpPolyShape.c.s

cpShape.o: cpShape.c.o
.PHONY : cpShape.o

# target to build an object file
cpShape.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpShape.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpShape.c.o
.PHONY : cpShape.c.o

cpShape.i: cpShape.c.i
.PHONY : cpShape.i

# target to preprocess a source file
cpShape.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpShape.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpShape.c.i
.PHONY : cpShape.c.i

cpShape.s: cpShape.c.s
.PHONY : cpShape.s

# target to generate assembly for a file
cpShape.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpShape.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpShape.c.s
.PHONY : cpShape.c.s

cpSpace.o: cpSpace.c.o
.PHONY : cpSpace.o

# target to build an object file
cpSpace.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpSpace.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpSpace.c.o
.PHONY : cpSpace.c.o

cpSpace.i: cpSpace.c.i
.PHONY : cpSpace.i

# target to preprocess a source file
cpSpace.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpSpace.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpSpace.c.i
.PHONY : cpSpace.c.i

cpSpace.s: cpSpace.c.s
.PHONY : cpSpace.s

# target to generate assembly for a file
cpSpace.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpSpace.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpSpace.c.s
.PHONY : cpSpace.c.s

cpSpaceComponent.o: cpSpaceComponent.c.o
.PHONY : cpSpaceComponent.o

# target to build an object file
cpSpaceComponent.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpSpaceComponent.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpSpaceComponent.c.o
.PHONY : cpSpaceComponent.c.o

cpSpaceComponent.i: cpSpaceComponent.c.i
.PHONY : cpSpaceComponent.i

# target to preprocess a source file
cpSpaceComponent.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpSpaceComponent.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpSpaceComponent.c.i
.PHONY : cpSpaceComponent.c.i

cpSpaceComponent.s: cpSpaceComponent.c.s
.PHONY : cpSpaceComponent.s

# target to generate assembly for a file
cpSpaceComponent.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpSpaceComponent.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpSpaceComponent.c.s
.PHONY : cpSpaceComponent.c.s

cpSpaceHash.o: cpSpaceHash.c.o
.PHONY : cpSpaceHash.o

# target to build an object file
cpSpaceHash.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpSpaceHash.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpSpaceHash.c.o
.PHONY : cpSpaceHash.c.o

cpSpaceHash.i: cpSpaceHash.c.i
.PHONY : cpSpaceHash.i

# target to preprocess a source file
cpSpaceHash.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpSpaceHash.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpSpaceHash.c.i
.PHONY : cpSpaceHash.c.i

cpSpaceHash.s: cpSpaceHash.c.s
.PHONY : cpSpaceHash.s

# target to generate assembly for a file
cpSpaceHash.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpSpaceHash.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpSpaceHash.c.s
.PHONY : cpSpaceHash.c.s

cpSpaceQuery.o: cpSpaceQuery.c.o
.PHONY : cpSpaceQuery.o

# target to build an object file
cpSpaceQuery.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpSpaceQuery.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpSpaceQuery.c.o
.PHONY : cpSpaceQuery.c.o

cpSpaceQuery.i: cpSpaceQuery.c.i
.PHONY : cpSpaceQuery.i

# target to preprocess a source file
cpSpaceQuery.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpSpaceQuery.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpSpaceQuery.c.i
.PHONY : cpSpaceQuery.c.i

cpSpaceQuery.s: cpSpaceQuery.c.s
.PHONY : cpSpaceQuery.s

# target to generate assembly for a file
cpSpaceQuery.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpSpaceQuery.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpSpaceQuery.c.s
.PHONY : cpSpaceQuery.c.s

cpSpaceStep.o: cpSpaceStep.c.o
.PHONY : cpSpaceStep.o

# target to build an object file
cpSpaceStep.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpSpaceStep.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpSpaceStep.c.o
.PHONY : cpSpaceStep.c.o

cpSpaceStep.i: cpSpaceStep.c.i
.PHONY : cpSpaceStep.i

# target to preprocess a source file
cpSpaceStep.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpSpaceStep.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpSpaceStep.c.i
.PHONY : cpSpaceStep.c.i

cpSpaceStep.s: cpSpaceStep.c.s
.PHONY : cpSpaceStep.s

# target to generate assembly for a file
cpSpaceStep.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpSpaceStep.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpSpaceStep.c.s
.PHONY : cpSpaceStep.c.s

cpVect.o: cpVect.c.o
.PHONY : cpVect.o

# target to build an object file
cpVect.c.o:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpVect.c.o
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpVect.c.o
.PHONY : cpVect.c.o

cpVect.i: cpVect.c.i
.PHONY : cpVect.i

# target to preprocess a source file
cpVect.c.i:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpVect.c.i
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpVect.c.i
.PHONY : cpVect.c.i

cpVect.s: cpVect.c.s
.PHONY : cpVect.s

# target to generate assembly for a file
cpVect.c.s:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk.dir/build.make src/CMakeFiles/chipmunk.dir/cpVect.c.s
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(MAKE) -f src/CMakeFiles/chipmunk_static.dir/build.make src/CMakeFiles/chipmunk_static.dir/cpVect.c.s
.PHONY : cpVect.c.s

# Help Target
help:
	@echo "The following are some of the valid targets for this Makefile:"
	@echo "... all (the default if no target is provided)"
	@echo "... clean"
	@echo "... depend"
	@echo "... chipmunk"
	@echo "... chipmunk_static"
	@echo "... edit_cache"
	@echo "... install"
	@echo "... install/local"
	@echo "... install/strip"
	@echo "... list_install_components"
	@echo "... rebuild_cache"
	@echo "... chipmunk.o"
	@echo "... chipmunk.i"
	@echo "... chipmunk.s"
	@echo "... constraints/cpConstraint.o"
	@echo "... constraints/cpConstraint.i"
	@echo "... constraints/cpConstraint.s"
	@echo "... constraints/cpDampedRotarySpring.o"
	@echo "... constraints/cpDampedRotarySpring.i"
	@echo "... constraints/cpDampedRotarySpring.s"
	@echo "... constraints/cpDampedSpring.o"
	@echo "... constraints/cpDampedSpring.i"
	@echo "... constraints/cpDampedSpring.s"
	@echo "... constraints/cpGearJoint.o"
	@echo "... constraints/cpGearJoint.i"
	@echo "... constraints/cpGearJoint.s"
	@echo "... constraints/cpGrooveJoint.o"
	@echo "... constraints/cpGrooveJoint.i"
	@echo "... constraints/cpGrooveJoint.s"
	@echo "... constraints/cpPinJoint.o"
	@echo "... constraints/cpPinJoint.i"
	@echo "... constraints/cpPinJoint.s"
	@echo "... constraints/cpPivotJoint.o"
	@echo "... constraints/cpPivotJoint.i"
	@echo "... constraints/cpPivotJoint.s"
	@echo "... constraints/cpRatchetJoint.o"
	@echo "... constraints/cpRatchetJoint.i"
	@echo "... constraints/cpRatchetJoint.s"
	@echo "... constraints/cpRotaryLimitJoint.o"
	@echo "... constraints/cpRotaryLimitJoint.i"
	@echo "... constraints/cpRotaryLimitJoint.s"
	@echo "... constraints/cpSimpleMotor.o"
	@echo "... constraints/cpSimpleMotor.i"
	@echo "... constraints/cpSimpleMotor.s"
	@echo "... constraints/cpSlideJoint.o"
	@echo "... constraints/cpSlideJoint.i"
	@echo "... constraints/cpSlideJoint.s"
	@echo "... cpArbiter.o"
	@echo "... cpArbiter.i"
	@echo "... cpArbiter.s"
	@echo "... cpArray.o"
	@echo "... cpArray.i"
	@echo "... cpArray.s"
	@echo "... cpBB.o"
	@echo "... cpBB.i"
	@echo "... cpBB.s"
	@echo "... cpBody.o"
	@echo "... cpBody.i"
	@echo "... cpBody.s"
	@echo "... cpCollision.o"
	@echo "... cpCollision.i"
	@echo "... cpCollision.s"
	@echo "... cpHashSet.o"
	@echo "... cpHashSet.i"
	@echo "... cpHashSet.s"
	@echo "... cpPolyShape.o"
	@echo "... cpPolyShape.i"
	@echo "... cpPolyShape.s"
	@echo "... cpShape.o"
	@echo "... cpShape.i"
	@echo "... cpShape.s"
	@echo "... cpSpace.o"
	@echo "... cpSpace.i"
	@echo "... cpSpace.s"
	@echo "... cpSpaceComponent.o"
	@echo "... cpSpaceComponent.i"
	@echo "... cpSpaceComponent.s"
	@echo "... cpSpaceHash.o"
	@echo "... cpSpaceHash.i"
	@echo "... cpSpaceHash.s"
	@echo "... cpSpaceQuery.o"
	@echo "... cpSpaceQuery.i"
	@echo "... cpSpaceQuery.s"
	@echo "... cpSpaceStep.o"
	@echo "... cpSpaceStep.i"
	@echo "... cpSpaceStep.s"
	@echo "... cpVect.o"
	@echo "... cpVect.i"
	@echo "... cpVect.s"
.PHONY : help

#=============================================================================
# Special targets to cleanup operation of make.

# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
	cd /home/laschweinski/git/cocos2d-x/chipmunk && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

path: chipmunk/src/Makefile


code:
/* Copyright (c) 2007 Scott Lembcke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>

#include "chipmunk.h"

#ifdef __cplusplus
extern "C" {
#endif
	void cpInitCollisionFuncs(void);
#ifdef __cplusplus
}
#endif

void
cpMessage(const char *message, const char *condition, const char *file, int line, int isError)
{
#ifndef SHP
	fprintf(stderr, (isError ? "Aborting due to Chipmunk error: %s\n" : "Chipmunk warning: %s\n"), message);
	fprintf(stderr, "\tFailed condition: %s\n", condition);
	fprintf(stderr, "\tSource:%s:%d\n", file, line);
#endif
	if(isError) abort();
}

const char *cpVersionString = "5.3.5";

void
cpInitChipmunk(void)
{
#ifndef NDEBUG
#ifndef SHP
	printf("Initializing Chipmunk v%s (Debug Enabled)\n", cpVersionString);
	printf("Compile with -DNDEBUG defined to disable debug mode and runtime assertion checks\n");
#endif
#endif
	cpInitCollisionFuncs();
}

cpFloat
cpMomentForCircle(cpFloat m, cpFloat r1, cpFloat r2, cpVect offset)
{
	return m*(0.5f*(r1*r1 + r2*r2) + cpvlengthsq(offset));
}

cpFloat
cpAreaForCircle(cpFloat r1, cpFloat r2)
{
	return 2.0f*(cpFloat)M_PI*cpfabs(r1*r1 - r2*r2);
}

cpFloat
cpMomentForSegment(cpFloat m, cpVect a, cpVect b)
{
	cpFloat length = cpvlength(cpvsub(b, a));
	cpVect offset = cpvmult(cpvadd(a, b), 1.0f/2.0f);

	return m*(length*length/12.0f + cpvlengthsq(offset));
}

cpFloat
cpAreaForSegment(cpVect a, cpVect b, cpFloat r)
{
	return 2.0f*r*((cpFloat)M_PI*r + cpvdist(a, b));
}

cpFloat
cpMomentForPoly(cpFloat m, const int numVerts, const cpVect *verts, cpVect offset)
{
	cpFloat sum1 = 0.0f;
	cpFloat sum2 = 0.0f;
	for(int i=0; i<numVerts; i++){
		cpVect v1 = cpvadd(verts[i], offset);
		cpVect v2 = cpvadd(verts[(i+1)%numVerts], offset);

		cpFloat a = cpvcross(v2, v1);
		cpFloat b = cpvdot(v1, v1) + cpvdot(v1, v2) + cpvdot(v2, v2);

		sum1 += a*b;
		sum2 += a;
	}

	return (m*sum1)/(6.0f*sum2);
}

cpFloat
cpAreaForPoly(const int numVerts, const cpVect *verts)
{
	cpFloat area = 0.0f;
	for(int i=0; i<numVerts; i++){
		area += cpvcross(verts[i], verts[(i+1)%numVerts]);
	}

	return area/2.0f;
}

cpVect
cpCentroidForPoly(const int numVerts, const cpVect *verts)
{
	cpFloat sum = 0.0f;
	cpVect vsum = cpvzero;

	for(int i=0; i<numVerts; i++){
		cpVect v1 = verts[i];
		cpVect v2 = verts[(i+1)%numVerts];
		cpFloat cross = cpvcross(v1, v2);

		sum += cross;
		vsum = cpvadd(vsum, cpvmult(cpvadd(v1, v2), cross));
	}

	return cpvmult(vsum, 1.0f/(3.0f*sum));
}

void
cpRecenterPoly(const int numVerts, cpVect *verts){
	cpVect centroid = cpCentroidForPoly(numVerts, verts);

	for(int i=0; i<numVerts; i++){
		verts[i] = cpvsub(verts[i], centroid);
	}
}

cpFloat
cpMomentForBox(cpFloat m, cpFloat width, cpFloat height)
{
	return m*(width*width + height*height)/12.0f;
}

#include "chipmunk_ffi.h"

license: mit


code:
/* Copyright (c) 2007 Scott Lembcke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>

#include "chipmunk_private.h"
#include "constraints/util.h"

// TODO: Comment me!

cpFloat cp_constraint_bias_coef = 0.1f;

void cpConstraintDestroy(cpConstraint *constraint){}

void
cpConstraintFree(cpConstraint *constraint)
{
	if(constraint){
		cpConstraintDestroy(constraint);
		cpfree(constraint);
	}
}

// *** defined in util.h

void
cpConstraintInit(cpConstraint *constraint, const cpConstraintClass *klass, cpBody *a, cpBody *b)
{
	constraint->klass = klass;
	constraint->a = a;
	constraint->b = b;

	constraint->maxForce = (cpFloat)INFINITY;
	constraint->biasCoef = cp_constraint_bias_coef;
	constraint->maxBias = (cpFloat)INFINITY;
}


code:
/* Copyright (c) 2007 Scott Lembcke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>
#include <math.h>

#include "chipmunk_private.h"
#include "constraints/util.h"

static cpFloat
defaultSpringTorque(cpDampedRotarySpring *spring, cpFloat relativeAngle){
	return (relativeAngle - spring->restAngle)*spring->stiffness;
}

static void
preStep(cpDampedRotarySpring *spring, cpFloat dt, cpFloat dt_inv)
{
	CONSTRAINT_BEGIN(spring, a, b);

	cpFloat moment = a->i_inv + b->i_inv;
	spring->iSum = 1.0f/moment;

	spring->w_coef = 1.0f - cpfexp(-spring->damping*dt*moment);
	spring->target_wrn = 0.0f;

	// apply spring torque
	cpFloat j_spring = spring->springTorqueFunc((cpConstraint *)spring, a->a - b->a)*dt;
	a->w -= j_spring*a->i_inv;
	b->w += j_spring*b->i_inv;
}

static void
applyImpulse(cpDampedRotarySpring *spring)
{
	CONSTRAINT_BEGIN(spring, a, b);

	// compute relative velocity
	cpFloat wrn = a->w - b->w;//normal_relative_velocity(a, b, r1, r2, n) - spring->target_vrn;

	// compute velocity loss from drag
	// not 100% certain this is derived correctly, though it makes sense
	cpFloat w_damp = wrn*spring->w_coef;
	spring->target_wrn = wrn - w_damp;

	//apply_impulses(a, b, spring->r1, spring->r2, cpvmult(spring->n, v_damp*spring->nMass));
	cpFloat j_damp = w_damp*spring->iSum;
	a->w -= j_damp*a->i_inv;
	b->w += j_damp*b->i_inv;
}

static cpFloat
getImpulse(cpConstraint *constraint)
{
	return 0.0f;
}

const cpConstraintClass * cpDampedRotarySpringGetClass();
static const cpConstraintClass klass = {
	(cpConstraintPreStepFunction)preStep,
	(cpConstraintApplyImpulseFunction)applyImpulse,
	(cpConstraintGetImpulseFunction)getImpulse,
};
CP_DefineClassGetter(cpDampedRotarySpring)

cpDampedRotarySpring *
cpDampedRotarySpringAlloc(void)
{
	return (cpDampedRotarySpring *)cpcalloc(1, sizeof(cpDampedRotarySpring));
}

cpDampedRotarySpring *
cpDampedRotarySpringInit(cpDampedRotarySpring *spring, cpBody *a, cpBody *b, cpFloat restAngle, cpFloat stiffness, cpFloat damping)
{
	cpConstraintInit((cpConstraint *)spring, &klass, a, b);

	spring->restAngle = restAngle;
	spring->stiffness = stiffness;
	spring->damping = damping;
	spring->springTorqueFunc = (cpDampedRotarySpringTorqueFunc)defaultSpringTorque;

	return spring;
}

cpConstraint *
cpDampedRotarySpringNew(cpBody *a, cpBody *b, cpFloat restAngle, cpFloat stiffness, cpFloat damping)
{
	return (cpConstraint *)cpDampedRotarySpringInit(cpDampedRotarySpringAlloc(), a, b, restAngle, stiffness, damping);
}


code:
/* Copyright (c) 2007 Scott Lembcke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>
#include <math.h>

#include "chipmunk_private.h"
#include "constraints/util.h"

static cpFloat
defaultSpringForce(cpDampedSpring *spring, cpFloat dist){
	return (spring->restLength - dist)*spring->stiffness;
}

static void
preStep(cpDampedSpring *spring, cpFloat dt, cpFloat dt_inv)
{
	CONSTRAINT_BEGIN(spring, a, b);

	spring->r1 = cpvrotate(spring->anchr1, a->rot);
	spring->r2 = cpvrotate(spring->anchr2, b->rot);

	cpVect delta = cpvsub(cpvadd(b->p, spring->r2), cpvadd(a->p, spring->r1));
	cpFloat dist = cpvlength(delta);
	spring->n = cpvmult(delta, 1.0f/(dist ? dist : INFINITY));

	cpFloat k = k_scalar(a, b, spring->r1, spring->r2, spring->n);
	spring->nMass = 1.0f/k;

	spring->target_vrn = 0.0f;
	spring->v_coef = 1.0f - cpfexp(-spring->damping*dt*k);

	// apply spring force
	cpFloat f_spring = spring->springForceFunc((cpConstraint *)spring, dist);
	apply_impulses(a, b, spring->r1, spring->r2, cpvmult(spring->n, f_spring*dt));
}

static void
applyImpulse(cpDampedSpring *spring)
{
	CONSTRAINT_BEGIN(spring, a, b);

	cpVect n = spring->n;
	cpVect r1 = spring->r1;
	cpVect r2 = spring->r2;

	// compute relative velocity
	cpFloat vrn = normal_relative_velocity(a, b, r1, r2, n) - spring->target_vrn;

	// compute velocity loss from drag
	// not 100% certain this is derived correctly, though it makes sense
	cpFloat v_damp = -vrn*spring->v_coef;
	spring->target_vrn = vrn + v_damp;

	apply_impulses(a, b, spring->r1, spring->r2, cpvmult(spring->n, v_damp*spring->nMass));
}

static cpFloat
getImpulse(cpConstraint *constraint)
{
	return 0.0f;
}

static const cpConstraintClass klass = {
	(cpConstraintPreStepFunction)preStep,
	(cpConstraintApplyImpulseFunction)applyImpulse,
	(cpConstraintGetImpulseFunction)getImpulse,
};
CP_DefineClassGetter(cpDampedSpring)

cpDampedSpring *
cpDampedSpringAlloc(void)
{
	return (cpDampedSpring *)cpcalloc(1, sizeof(cpDampedSpring));
}

cpDampedSpring *
cpDampedSpringInit(cpDampedSpring *spring, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping)
{
	cpConstraintInit((cpConstraint *)spring, cpDampedSpringGetClass(), a, b);

	spring->anchr1 = anchr1;
	spring->anchr2 = anchr2;

	spring->restLength = restLength;
	spring->stiffness = stiffness;
	spring->damping = damping;
	spring->springForceFunc = (cpDampedSpringForceFunc)defaultSpringForce;

	return spring;
}

cpConstraint *
cpDampedSpringNew(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping)
{
	return (cpConstraint *)cpDampedSpringInit(cpDampedSpringAlloc(), a, b, anchr1, anchr2, restLength, stiffness, damping);
}


code:
/* Copyright (c) 2007 Scott Lembcke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>

#include "chipmunk_private.h"
#include "constraints/util.h"

static void
preStep(cpGearJoint *joint, cpFloat dt, cpFloat dt_inv)
{
	CONSTRAINT_BEGIN(joint, a, b);

	// calculate moment of inertia coefficient.
	joint->iSum = 1.0f/(a->i_inv*joint->ratio_inv + joint->ratio*b->i_inv);

	// calculate bias velocity
	cpFloat maxBias = joint->constraint.maxBias;
	joint->bias = cpfclamp(-joint->constraint.biasCoef*dt_inv*(b->a*joint->ratio - a->a - joint->phase), -maxBias, maxBias);

	// compute max impulse
	joint->jMax = J_MAX(joint, dt);

	// apply joint torque
	cpFloat j = joint->jAcc;
	a->w -= j*a->i_inv*joint->ratio_inv;
	b->w += j*b->i_inv;
}

static void
applyImpulse(cpGearJoint *joint)
{
	CONSTRAINT_BEGIN(joint, a, b);

	// compute relative rotational velocity
	cpFloat wr = b->w*joint->ratio - a->w;

	// compute normal impulse
	cpFloat j = (joint->bias - wr)*joint->iSum;
	cpFloat jOld = joint->jAcc;
	joint->jAcc = cpfclamp(jOld + j, -joint->jMax, joint->jMax);
	j = joint->jAcc - jOld;

	// apply impulse
	a->w -= j*a->i_inv*joint->ratio_inv;
	b->w += j*b->i_inv;
}

static cpFloat
getImpulse(cpGearJoint *joint)
{
	return cpfabs(joint->jAcc);
}

static const cpConstraintClass klass = {
	(cpConstraintPreStepFunction)preStep,
	(cpConstraintApplyImpulseFunction)applyImpulse,
	(cpConstraintGetImpulseFunction)getImpulse,
};
CP_DefineClassGetter(cpGearJoint)

cpGearJoint *
cpGearJointAlloc(void)
{
	return (cpGearJoint *)cpcalloc(1, sizeof(cpGearJoint));
}

cpGearJoint *
cpGearJointInit(cpGearJoint *joint, cpBody *a, cpBody *b, cpFloat phase, cpFloat ratio)
{
	cpConstraintInit((cpConstraint *)joint, &klass, a, b);

	joint->phase = phase;
	joint->ratio = ratio;
	joint->ratio_inv = 1.0f/ratio;

	joint->jAcc = 0.0f;

	return joint;
}

cpConstraint *
cpGearJointNew(cpBody *a, cpBody *b, cpFloat phase, cpFloat ratio)
{
	return (cpConstraint *)cpGearJointInit(cpGearJointAlloc(), a, b, phase, ratio);
}

void
cpGearJointSetRatio(cpConstraint *constraint, cpFloat value)
{
	cpConstraintCheckCast(constraint, cpGearJoint);
	((cpGearJoint *)constraint)->ratio = value;
	((cpGearJoint *)constraint)->ratio_inv = 1.0f/value;
	cpConstraintActivateBodies(constraint);
}


code:
/* Copyright (c) 2007 Scott Lembcke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>

#include "chipmunk_private.h"
#include "constraints/util.h"

static void
preStep(cpGrooveJoint *joint, cpFloat dt, cpFloat dt_inv)
{
	CONSTRAINT_BEGIN(joint, a, b);

	// calculate endpoints in worldspace
	cpVect ta = cpBodyLocal2World(a, joint->grv_a);
	cpVect tb = cpBodyLocal2World(a, joint->grv_b);

	// calculate axis
	cpVect n = cpvrotate(joint->grv_n, a->rot);
	cpFloat d = cpvdot(ta, n);

	joint->grv_tn = n;
	joint->r2 = cpvrotate(joint->anchr2, b->rot);

	// calculate tangential distance along the axis of r2
	cpFloat td = cpvcross(cpvadd(b->p, joint->r2), n);
	// calculate clamping factor and r2
	if(td <= cpvcross(ta, n)){
		joint->clamp = 1.0f;
		joint->r1 = cpvsub(ta, a->p);
	} else if(td >= cpvcross(tb, n)){
		joint->clamp = -1.0f;
		joint->r1 = cpvsub(tb, a->p);
	} else {
		joint->clamp = 0.0f;
		joint->r1 = cpvsub(cpvadd(cpvmult(cpvperp(n), -td), cpvmult(n, d)), a->p);
	}

	// Calculate mass tensor
	k_tensor(a, b, joint->r1, joint->r2, &joint->k1, &joint->k2);

	// compute max impulse
	joint->jMaxLen = J_MAX(joint, dt);

	// calculate bias velocity
	cpVect delta = cpvsub(cpvadd(b->p, joint->r2), cpvadd(a->p, joint->r1));
	joint->bias = cpvclamp(cpvmult(delta, -joint->constraint.biasCoef*dt_inv), joint->constraint.maxBias);

	// apply accumulated impulse
	apply_impulses(a, b, joint->r1, joint->r2, joint->jAcc);
}

static inline cpVect
grooveConstrain(cpGrooveJoint *joint, cpVect j){
	cpVect n = joint->grv_tn;
	cpVect jClamp = (joint->clamp*cpvcross(j, n) > 0.0f) ? j : cpvproject(j, n);
	return cpvclamp(jClamp, joint->jMaxLen);
}

static void
applyImpulse(cpGrooveJoint *joint)
{
	CONSTRAINT_BEGIN(joint, a, b);

	cpVect r1 = joint->r1;
	cpVect r2 = joint->r2;

	// compute impulse
	cpVect vr = relative_velocity(a, b, r1, r2);

	cpVect j = mult_k(cpvsub(joint->bias, vr), joint->k1, joint->k2);
	cpVect jOld = joint->jAcc;
	joint->jAcc = grooveConstrain(joint, cpvadd(jOld, j));
	j = cpvsub(joint->jAcc, jOld);

	// apply impulse
	apply_impulses(a, b, joint->r1, joint->r2, j);
}

static cpFloat
getImpulse(cpGrooveJoint *joint)
{
	return cpvlength(joint->jAcc);
}

static const cpConstraintClass klass = {
	(cpConstraintPreStepFunction)preStep,
	(cpConstraintApplyImpulseFunction)applyImpulse,
	(cpConstraintGetImpulseFunction)getImpulse,
};
CP_DefineClassGetter(cpGrooveJoint)

cpGrooveJoint *
cpGrooveJointAlloc(void)
{
	return (cpGrooveJoint *)cpcalloc(1, sizeof(cpGrooveJoint));
}

cpGrooveJoint *
cpGrooveJointInit(cpGrooveJoint *joint, cpBody *a, cpBody *b, cpVect groove_a, cpVect groove_b, cpVect anchr2)
{
	cpConstraintInit((cpConstraint *)joint, &klass, a, b);

	joint->grv_a = groove_a;
	joint->grv_b = groove_b;
	joint->grv_n = cpvperp(cpvnormalize(cpvsub(groove_b, groove_a)));
	joint->anchr2 = anchr2;

	joint->jAcc = cpvzero;

	return joint;
}

cpConstraint *
cpGrooveJointNew(cpBody *a, cpBody *b, cpVect groove_a, cpVect groove_b, cpVect anchr2)
{
	return (cpConstraint *)cpGrooveJointInit(cpGrooveJointAlloc(), a, b, groove_a, groove_b, anchr2);
}

void
cpGrooveJointSetGrooveA(cpConstraint *constraint, cpVect value)
{
	cpGrooveJoint *g = (cpGrooveJoint *)constraint;
	cpConstraintCheckCast(constraint, cpGrooveJoint);

	g->grv_a = value;
	g->grv_n = cpvperp(cpvnormalize(cpvsub(g->grv_b, value)));

	cpConstraintActivateBodies(constraint);
}

void
cpGrooveJointSetGrooveB(cpConstraint *constraint, cpVect value)
{
	cpGrooveJoint *g = (cpGrooveJoint *)constraint;
	cpConstraintCheckCast(constraint, cpGrooveJoint);

	g->grv_b = value;
	g->grv_n = cpvperp(cpvnormalize(cpvsub(value, g->grv_a)));

	cpConstraintActivateBodies(constraint);
}


code:
/* Copyright (c) 2007 Scott Lembcke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>
//#include <math.h>

#include "chipmunk_private.h"
#include "constraints/util.h"

static void
preStep(cpPinJoint *joint, cpFloat dt, cpFloat dt_inv)
{
	CONSTRAINT_BEGIN(joint, a, b);

	joint->r1 = cpvrotate(joint->anchr1, a->rot);
	joint->r2 = cpvrotate(joint->anchr2, b->rot);

	cpVect delta = cpvsub(cpvadd(b->p, joint->r2), cpvadd(a->p, joint->r1));
	cpFloat dist = cpvlength(delta);
	joint->n = cpvmult(delta, 1.0f/(dist ? dist : (cpFloat)INFINITY));

	// calculate mass normal
	joint->nMass = 1.0f/k_scalar(a, b, joint->r1, joint->r2, joint->n);

	// calculate bias velocity
	cpFloat maxBias = joint->constraint.maxBias;
	joint->bias = cpfclamp(-joint->constraint.biasCoef*dt_inv*(dist - joint->dist), -maxBias, maxBias);

	// compute max impulse
	joint->jnMax = J_MAX(joint, dt);

	// apply accumulated impulse
	cpVect j = cpvmult(joint->n, joint->jnAcc);
	apply_impulses(a, b, joint->r1, joint->r2, j);
}

static void
applyImpulse(cpPinJoint *joint)
{
	CONSTRAINT_BEGIN(joint, a, b);
	cpVect n = joint->n;

	// compute relative velocity
	cpFloat vrn = normal_relative_velocity(a, b, joint->r1, joint->r2, n);

	// compute normal impulse
	cpFloat jn = (joint->bias - vrn)*joint->nMass;
	cpFloat jnOld = joint->jnAcc;
	joint->jnAcc = cpfclamp(jnOld + jn, -joint->jnMax, joint->jnMax);
	jn = joint->jnAcc - jnOld;

	// apply impulse
	apply_impulses(a, b, joint->r1, joint->r2, cpvmult(n, jn));
}

static cpFloat
getImpulse(cpPinJoint *joint)
{
	return cpfabs(joint->jnAcc);
}

static const cpConstraintClass klass = {
	(cpConstraintPreStepFunction)preStep,
	(cpConstraintApplyImpulseFunction)applyImpulse,
	(cpConstraintGetImpulseFunction)getImpulse,
};
CP_DefineClassGetter(cpPinJoint);

cpPinJoint *
cpPinJointAlloc(void)
{
	return (cpPinJoint *)cpcalloc(1, sizeof(cpPinJoint));
}

cpPinJoint *
cpPinJointInit(cpPinJoint *joint, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2)
{
	cpConstraintInit((cpConstraint *)joint, &klass, a, b);

	joint->anchr1 = anchr1;
	joint->anchr2 = anchr2;

	// STATIC_BODY_CHECK
	cpVect p1 = (a ? cpvadd(a->p, cpvrotate(anchr1, a->rot)) : anchr1);
	cpVect p2 = (b ? cpvadd(b->p, cpvrotate(anchr2, b->rot)) : anchr2);
	joint->dist = cpvlength(cpvsub(p2, p1));

	joint->jnAcc = 0.0f;

	return joint;
}

cpConstraint *
cpPinJointNew(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2)
{
	return (cpConstraint *)cpPinJointInit(cpPinJointAlloc(), a, b, anchr1, anchr2);
}


code:
/* Copyright (c) 2007 Scott Lembcke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>

#include "chipmunk_private.h"
#include "constraints/util.h"

static void
preStep(cpPivotJoint *joint, cpFloat dt, cpFloat dt_inv)
{
	CONSTRAINT_BEGIN(joint, a, b);

	joint->r1 = cpvrotate(joint->anchr1, a->rot);
	joint->r2 = cpvrotate(joint->anchr2, b->rot);

	// Calculate mass tensor
	k_tensor(a, b, joint->r1, joint->r2, &joint->k1, &joint->k2);

	// compute max impulse
	joint->jMaxLen = J_MAX(joint, dt);

	// calculate bias velocity
	cpVect delta = cpvsub(cpvadd(b->p, joint->r2), cpvadd(a->p, joint->r1));
	joint->bias = cpvclamp(cpvmult(delta, -joint->constraint.biasCoef*dt_inv), joint->constraint.maxBias);

	// apply accumulated impulse
	apply_impulses(a, b, joint->r1, joint->r2, joint->jAcc);
}

static void
applyImpulse(cpPivotJoint *joint)
{
	CONSTRAINT_BEGIN(joint, a, b);

	cpVect r1 = joint->r1;
	cpVect r2 = joint->r2;

	// compute relative velocity
	cpVect vr = relative_velocity(a, b, r1, r2);

	// compute normal impulse
	cpVect j = mult_k(cpvsub(joint->bias, vr), joint->k1, joint->k2);
	cpVect jOld = joint->jAcc;
	joint->jAcc = cpvclamp(cpvadd(joint->jAcc, j), joint->jMaxLen);
	j = cpvsub(joint->jAcc, jOld);

	// apply impulse
	apply_impulses(a, b, joint->r1, joint->r2, j);
}

static cpFloat
getImpulse(cpConstraint *joint)
{
	return cpvlength(((cpPivotJoint *)joint)->jAcc);
}

static const cpConstraintClass klass = {
	(cpConstraintPreStepFunction)preStep,
	(cpConstraintApplyImpulseFunction)applyImpulse,
	(cpConstraintGetImpulseFunction)getImpulse,
};
CP_DefineClassGetter(cpPivotJoint)

cpPivotJoint *
cpPivotJointAlloc(void)
{
	return (cpPivotJoint *)cpcalloc(1, sizeof(cpPivotJoint));
}

cpPivotJoint *
cpPivotJointInit(cpPivotJoint *joint, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2)
{
	cpConstraintInit((cpConstraint *)joint, &klass, a, b);

	joint->anchr1 = anchr1;
	joint->anchr2 = anchr2;

	joint->jAcc = cpvzero;

	return joint;
}

cpConstraint *
cpPivotJointNew2(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2)
{
	return (cpConstraint *)cpPivotJointInit(cpPivotJointAlloc(), a, b, anchr1, anchr2);
}

cpConstraint *
cpPivotJointNew(cpBody *a, cpBody *b, cpVect pivot)
{
	cpVect anchr1 = (a ? cpBodyWorld2Local(a, pivot) : pivot);
	cpVect anchr2 = (b ? cpBodyWorld2Local(b, pivot) : pivot);
	return cpPivotJointNew2(a, b, anchr1, anchr2);
}


code:
/* Copyright (c) 2007 Scott Lembcke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>
#include <math.h>

#include "chipmunk_private.h"
#include "constraints/util.h"

static void
preStep(cpRatchetJoint *joint, cpFloat dt, cpFloat dt_inv)
{
	CONSTRAINT_BEGIN(joint, a, b);

	cpFloat angle = joint->angle;
	cpFloat phase = joint->phase;
	cpFloat ratchet = joint->ratchet;

	cpFloat delta = b->a - a->a;
	cpFloat diff = angle - delta;
	cpFloat pdist = 0.0f;

	if(diff*ratchet > 0.0f){
		pdist = diff;
	} else {
		joint->angle = cpffloor((delta - phase)/ratchet)*ratchet + phase;
	}

	// calculate moment of inertia coefficient.
	joint->iSum = 1.0f/(a->i_inv + b->i_inv);

	// calculate bias velocity
	cpFloat maxBias = joint->constraint.maxBias;
	joint->bias = cpfclamp(-joint->constraint.biasCoef*dt_inv*pdist, -maxBias, maxBias);

	// compute max impulse
	joint->jMax = J_MAX(joint, dt);

	// If the bias is 0, the joint is not at a limit. Reset the impulse.
	if(!joint->bias)
		joint->jAcc = 0.0f;

	// apply joint torque
	a->w -= joint->jAcc*a->i_inv;
	b->w += joint->jAcc*b->i_inv;
}

static void
applyImpulse(cpRatchetJoint *joint)
{
	if(!joint->bias) return; // early exit

	CONSTRAINT_BEGIN(joint, a, b);

	// compute relative rotational velocity
	cpFloat wr = b->w - a->w;
	cpFloat ratchet = joint->ratchet;

	// compute normal impulse
	cpFloat j = -(joint->bias + wr)*joint->iSum;
	cpFloat jOld = joint->jAcc;
	joint->jAcc = cpfclamp((jOld + j)*ratchet, 0.0f, joint->jMax*cpfabs(ratchet))/ratchet;
	j = joint->jAcc - jOld;

	// apply impulse
	a->w -= j*a->i_inv;
	b->w += j*b->i_inv;
}

static cpFloat
getImpulse(cpRatchetJoint *joint)
{
	return cpfabs(joint->jAcc);
}

static const cpConstraintClass klass = {
	(cpConstraintPreStepFunction)preStep,
	(cpConstraintApplyImpulseFunction)applyImpulse,
	(cpConstraintGetImpulseFunction)getImpulse,
};
CP_DefineClassGetter(cpRatchetJoint)

cpRatchetJoint *
cpRatchetJointAlloc(void)
{
	return (cpRatchetJoint *)cpcalloc(1, sizeof(cpRatchetJoint));
}

cpRatchetJoint *
cpRatchetJointInit(cpRatchetJoint *joint, cpBody *a, cpBody *b, cpFloat phase, cpFloat ratchet)
{
	cpConstraintInit((cpConstraint *)joint, &klass, a, b);

	joint->angle = 0.0f;
	joint->phase = phase;
	joint->ratchet = ratchet;

	// STATIC_BODY_CHECK
	joint->angle = (b ? b->a : 0.0f) - (a ? a->a : 0.0f);

	return joint;
}

cpConstraint *
cpRatchetJointNew(cpBody *a, cpBody *b, cpFloat phase, cpFloat ratchet)
{
	return (cpConstraint *)cpRatchetJointInit(cpRatchetJointAlloc(), a, b, phase, ratchet);
}


code:
/* Copyright (c) 2007 Scott Lembcke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>

#include "chipmunk_private.h"
#include "constraints/util.h"

static void
preStep(cpRotaryLimitJoint *joint, cpFloat dt, cpFloat dt_inv)
{
	CONSTRAINT_BEGIN(joint, a, b);

	cpFloat dist = b->a - a->a;
	cpFloat pdist = 0.0f;
	if(dist > joint->max) {
		pdist = joint->max - dist;
	} else if(dist < joint->min) {
		pdist = joint->min - dist;
	}

	// calculate moment of inertia coefficient.
	joint->iSum = 1.0f/(a->i_inv + b->i_inv);

	// calculate bias velocity
	cpFloat maxBias = joint->constraint.maxBias;
	joint->bias = cpfclamp(-joint->constraint.biasCoef*dt_inv*(pdist), -maxBias, maxBias);

	// compute max impulse
	joint->jMax = J_MAX(joint, dt);

	// If the bias is 0, the joint is not at a limit. Reset the impulse.
	if(!joint->bias)
		joint->jAcc = 0.0f;

	// apply joint torque
	a->w -= joint->jAcc*a->i_inv;
	b->w += joint->jAcc*b->i_inv;
}

static void
applyImpulse(cpRotaryLimitJoint *joint)
{
	if(!joint->bias) return; // early exit

	CONSTRAINT_BEGIN(joint, a, b);

	// compute relative rotational velocity
	cpFloat wr = b->w - a->w;

	// compute normal impulse
	cpFloat j = -(joint->bias + wr)*joint->iSum;
	cpFloat jOld = joint->jAcc;
	if(joint->bias < 0.0f){
		joint->jAcc = cpfclamp(jOld + j, 0.0f, joint->jMax);
	} else {
		joint->jAcc = cpfclamp(jOld + j, -joint->jMax, 0.0f);
	}
	j = joint->jAcc - jOld;

	// apply impulse
	a->w -= j*a->i_inv;
	b->w += j*b->i_inv;
}

static cpFloat
getImpulse(cpRotaryLimitJoint *joint)
{
	return cpfabs(joint->jAcc);
}

static const cpConstraintClass klass = {
	(cpConstraintPreStepFunction)preStep,
	(cpConstraintApplyImpulseFunction)applyImpulse,
	(cpConstraintGetImpulseFunction)getImpulse,
};
CP_DefineClassGetter(cpRotaryLimitJoint)

cpRotaryLimitJoint *
cpRotaryLimitJointAlloc(void)
{
	return (cpRotaryLimitJoint *)cpcalloc(1, sizeof(cpRotaryLimitJoint));
}

cpRotaryLimitJoint *
cpRotaryLimitJointInit(cpRotaryLimitJoint *joint, cpBody *a, cpBody *b, cpFloat min, cpFloat max)
{
	cpConstraintInit((cpConstraint *)joint, &klass, a, b);

	joint->min = min;
	joint->max  = max;

	joint->jAcc = 0.0f;

	return joint;
}

cpConstraint *
cpRotaryLimitJointNew(cpBody *a, cpBody *b, cpFloat min, cpFloat max)
{
	return (cpConstraint *)cpRotaryLimitJointInit(cpRotaryLimitJointAlloc(), a, b, min, max);
}


code:
/* Copyright (c) 2007 Scott Lembcke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>

#include "chipmunk_private.h"
#include "constraints/util.h"

static void
preStep(cpSimpleMotor *joint, cpFloat dt, cpFloat dt_inv)
{
	CONSTRAINT_BEGIN(joint, a, b);

	// calculate moment of inertia coefficient.
	joint->iSum = 1.0f/(a->i_inv + b->i_inv);

	// compute max impulse
	joint->jMax = J_MAX(joint, dt);

	// apply joint torque
	a->w -= joint->jAcc*a->i_inv;
	b->w += joint->jAcc*b->i_inv;
}

static void
applyImpulse(cpSimpleMotor *joint)
{
	CONSTRAINT_BEGIN(joint, a, b);

	// compute relative rotational velocity
	cpFloat wr = b->w - a->w + joint->rate;

	// compute normal impulse
	cpFloat j = -wr*joint->iSum;
	cpFloat jOld = joint->jAcc;
	joint->jAcc = cpfclamp(jOld + j, -joint->jMax, joint->jMax);
	j = joint->jAcc - jOld;

	// apply impulse
	a->w -= j*a->i_inv;
	b->w += j*b->i_inv;
}

static cpFloat
getImpulse(cpSimpleMotor *joint)
{
	return cpfabs(joint->jAcc);
}

static const cpConstraintClass klass = {
	(cpConstraintPreStepFunction)preStep,
	(cpConstraintApplyImpulseFunction)applyImpulse,
	(cpConstraintGetImpulseFunction)getImpulse,
};
CP_DefineClassGetter(cpSimpleMotor)

cpSimpleMotor *
cpSimpleMotorAlloc(void)
{
	return (cpSimpleMotor *)cpcalloc(1, sizeof(cpSimpleMotor));
}

cpSimpleMotor *
cpSimpleMotorInit(cpSimpleMotor *joint, cpBody *a, cpBody *b, cpFloat rate)
{
	cpConstraintInit((cpConstraint *)joint, &klass, a, b);

	joint->rate = rate;

	joint->jAcc = 0.0f;

	return joint;
}

cpConstraint *
cpSimpleMotorNew(cpBody *a, cpBody *b, cpFloat rate)
{
	return (cpConstraint *)cpSimpleMotorInit(cpSimpleMotorAlloc(), a, b, rate);
}


code:
/* Copyright (c) 2007 Scott Lembcke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>

#include "chipmunk_private.h"
#include "constraints/util.h"

static void
preStep(cpSlideJoint *joint, cpFloat dt, cpFloat dt_inv)
{
	CONSTRAINT_BEGIN(joint, a, b);

	joint->r1 = cpvrotate(joint->anchr1, a->rot);
	joint->r2 = cpvrotate(joint->anchr2, b->rot);

	cpVect delta = cpvsub(cpvadd(b->p, joint->r2), cpvadd(a->p, joint->r1));
	cpFloat dist = cpvlength(delta);
	cpFloat pdist = 0.0f;
	if(dist > joint->max) {
		pdist = dist - joint->max;
	} else if(dist < joint->min) {
		pdist = joint->min - dist;
		dist = -dist;
	}
	joint->n = cpvmult(delta, 1.0f/(dist ? dist : (cpFloat)INFINITY));

	// calculate mass normal
	joint->nMass = 1.0f/k_scalar(a, b, joint->r1, joint->r2, joint->n);

	// calculate bias velocity
	cpFloat maxBias = joint->constraint.maxBias;
	joint->bias = cpfclamp(-joint->constraint.biasCoef*dt_inv*(pdist), -maxBias, maxBias);

	// compute max impulse
	joint->jnMax = J_MAX(joint, dt);

	// apply accumulated impulse
	if(!joint->bias) //{
		// if bias is 0, then the joint is not at a limit.
		joint->jnAcc = 0.0f;
//	} else {
		cpVect j = cpvmult(joint->n, joint->jnAcc);
		apply_impulses(a, b, joint->r1, joint->r2, j);
//	}
}

static void
applyImpulse(cpSlideJoint *joint)
{
	if(!joint->bias) return;  // early exit

	CONSTRAINT_BEGIN(joint, a, b);

	cpVect n = joint->n;
	cpVect r1 = joint->r1;
	cpVect r2 = joint->r2;

	// compute relative velocity
	cpVect vr = relative_velocity(a, b, r1, r2);
	cpFloat vrn = cpvdot(vr, n);

	// compute normal impulse
	cpFloat jn = (joint->bias - vrn)*joint->nMass;
	cpFloat jnOld = joint->jnAcc;
	joint->jnAcc = cpfclamp(jnOld + jn, -joint->jnMax, 0.0f);
	jn = joint->jnAcc - jnOld;

	// apply impulse
	apply_impulses(a, b, joint->r1, joint->r2, cpvmult(n, jn));
}

static cpFloat
getImpulse(cpConstraint *joint)
{
	return cpfabs(((cpSlideJoint *)joint)->jnAcc);
}

static const cpConstraintClass klass = {
	(cpConstraintPreStepFunction)preStep,
	(cpConstraintApplyImpulseFunction)applyImpulse,
	(cpConstraintGetImpulseFunction)getImpulse,
};
CP_DefineClassGetter(cpSlideJoint)

cpSlideJoint *
cpSlideJointAlloc(void)
{
	return (cpSlideJoint *)cpcalloc(1, sizeof(cpSlideJoint));
}

cpSlideJoint *
cpSlideJointInit(cpSlideJoint *joint, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max)
{
	cpConstraintInit((cpConstraint *)joint, &klass, a, b);

	joint->anchr1 = anchr1;
	joint->anchr2 = anchr2;
	joint->min = min;
	joint->max = max;

	joint->jnAcc = 0.0f;

	return joint;
}

cpConstraint *
cpSlideJointNew(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max)
{
	return (cpConstraint *)cpSlideJointInit(cpSlideJointAlloc(), a, b, anchr1, anchr2, min, max);
}


code:
/* Copyright (c) 2007 Scott Lembcke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>

#include "chipmunk_private.h"
#include "constraints/util.h"

cpFloat cpContactsEstimateCrushingImpulse(cpContact *contacts, int numContacts);
cpArbiter* cpArbiterAlloc(void);
cpArbiter* cpArbiterNew(cpShape *a, cpShape *b);
void cpArbiterDestroy(cpArbiter *arb);
void cpArbiterFree(cpArbiter *arb);

cpFloat cp_bias_coef = 0.1f;
cpFloat cp_collision_slop = 0.1f;

cpContact*
cpContactInit(cpContact *con, cpVect p, cpVect n, cpFloat dist, cpHashValue hash)
{
	con->p = p;
	con->n = n;
	con->dist = dist;

	con->jnAcc = 0.0f;
	con->jtAcc = 0.0f;
	con->jBias = 0.0f;

	con->hash = hash;

	return con;
}

cpVect
cpArbiterTotalImpulse(cpArbiter *arb)
{
	cpContact *contacts = arb->contacts;
	cpVect sum = cpvzero;

	for(int i=0, count=arb->numContacts; i<count; i++){
		cpContact *con = &contacts[i];
		sum = cpvadd(sum, cpvmult(con->n, con->jnAcc));
	}

	return sum;
}

cpVect
cpArbiterTotalImpulseWithFriction(cpArbiter *arb)
{
	cpContact *contacts = arb->contacts;
	cpVect sum = cpvzero;

	for(int i=0, count=arb->numContacts; i<count; i++){
		cpContact *con = &contacts[i];
		sum = cpvadd(sum, cpvrotate(con->n, cpv(con->jnAcc, con->jtAcc)));
	}

	return sum;
}

cpFloat
cpContactsEstimateCrushingImpulse(cpContact *contacts, int numContacts)
{
	cpFloat fsum = 0.0f;
	cpVect vsum = cpvzero;

	for(int i=0; i<numContacts; i++){
		cpContact *con = &contacts[i];
		cpVect j = cpvrotate(con->n, cpv(con->jnAcc, con->jtAcc));

		fsum += cpvlength(j);
		vsum = cpvadd(vsum, j);
	}

	cpFloat vmag = cpvlength(vsum);
	return (1.0f - vmag/fsum);
}

void
cpArbiterIgnore(cpArbiter *arb)
{
	arb->state = cpArbiterStateIgnore;
}

cpArbiter*
cpArbiterAlloc(void)
{
	return (cpArbiter *)cpcalloc(1, sizeof(cpArbiter));
}

cpArbiter*
cpArbiterInit(cpArbiter *arb, cpShape *a, cpShape *b)
{
	arb->handler = NULL;
	arb->swappedColl = cpFalse;

	arb->e = 0.0f;
	arb->u = 0.0f;
	arb->surface_vr = cpvzero;

	arb->numContacts = 0;
	arb->contacts = NULL;

	arb->a = a;
	arb->b = b;

	arb->stamp = 0;
	arb->state = cpArbiterStateFirstColl;

	return arb;
}

cpArbiter*
cpArbiterNew(cpShape *a, cpShape *b)
{
	return cpArbiterInit(cpArbiterAlloc(), a, b);
}

void
cpArbiterDestroy(cpArbiter *arb)
{
//	if(arb->contacts) cpfree(arb->contacts);
}

void
cpArbiterFree(cpArbiter *arb)
{
	if(arb){
		cpArbiterDestroy(arb);
		cpfree(arb);
	}
}

void
cpArbiterUpdate(cpArbiter *arb, cpContact *contacts, int numContacts, cpCollisionHandler *handler, cpShape *a, cpShape *b)
{
	// Arbiters without contact data may exist if a collision function rejected the collision.
	if(arb->contacts){
		// Iterate over the possible pairs to look for hash value matches.
		for(int i=0; i<arb->numContacts; i++){
			cpContact *old = &arb->contacts[i];

			for(int j=0; j<numContacts; j++){
				cpContact *new_contact = &contacts[j];

				// This could trigger false positives, but is fairly unlikely nor serious if it does.
				if(new_contact->hash == old->hash){
					// Copy the persistant contact information.
					new_contact->jnAcc = old->jnAcc;
					new_contact->jtAcc = old->jtAcc;
				}
			}
		}
	}

	arb->contacts = contacts;
	arb->numContacts = numContacts;

	arb->handler = handler;
	arb->swappedColl = (a->collision_type != handler->a);

	arb->e = a->e * b->e;
	arb->u = a->u * b->u;
	arb->surface_vr = cpvsub(a->surface_v, b->surface_v);

	// For collisions between two similar primitive types, the order could have been swapped.
	arb->a = a;
	arb->b = b;

	// mark it as new if it's been cached
	if(arb->state == cpArbiterStateCached) arb->state = cpArbiterStateFirstColl;
}

void
cpArbiterPreStep(cpArbiter *arb, cpFloat dt_inv)
{
	cpBody *a = arb->a->body;
	cpBody *b = arb->b->body;

	for(int i=0; i<arb->numContacts; i++){
		cpContact *con = &arb->contacts[i];

		// Calculate the offsets.
		con->r1 = cpvsub(con->p, a->p);
		con->r2 = cpvsub(con->p, b->p);

		// Calculate the mass normal and mass tangent.
		con->nMass = 1.0f/k_scalar(a, b, con->r1, con->r2, con->n);
		con->tMass = 1.0f/k_scalar(a, b, con->r1, con->r2, cpvperp(con->n));

		// Calculate the target bias velocity.
		con->bias = -cp_bias_coef*dt_inv*cpfmin(0.0f, con->dist + cp_collision_slop);
		con->jBias = 0.0f;

		// Calculate the target bounce velocity.
		con->bounce = normal_relative_velocity(a, b, con->r1, con->r2, con->n)*arb->e;//cpvdot(con->n, cpvsub(v2, v1))*e;
	}
}

void
cpArbiterApplyCachedImpulse(cpArbiter *arb)
{
	cpShape *shapea = arb->a;
	cpShape *shapeb = arb->b;

	arb->u = shapea->u * shapeb->u;
	arb->surface_vr = cpvsub(shapeb->surface_v, shapea->surface_v);

	cpBody *a = shapea->body;
	cpBody *b = shapeb->body;

	for(int i=0; i<arb->numContacts; i++){
		cpContact *con = &arb->contacts[i];
		apply_impulses(a, b, con->r1, con->r2, cpvrotate(con->n, cpv(con->jnAcc, con->jtAcc)));
	}
}

void
cpArbiterApplyImpulse(cpArbiter *arb, cpFloat eCoef)
{
	cpBody *a = arb->a->body;
	cpBody *b = arb->b->body;

	for(int i=0; i<arb->numContacts; i++){
		cpContact *con = &arb->contacts[i];
		cpVect n = con->n;
		cpVect r1 = con->r1;
		cpVect r2 = con->r2;

		// Calculate the relative bias velocities.
		cpVect vb1 = cpvadd(a->v_bias, cpvmult(cpvperp(r1), a->w_bias));
		cpVect vb2 = cpvadd(b->v_bias, cpvmult(cpvperp(r2), b->w_bias));
		cpFloat vbn = cpvdot(cpvsub(vb2, vb1), n);

		// Calculate and clamp the bias impulse.
		cpFloat jbn = (con->bias - vbn)*con->nMass;
		cpFloat jbnOld = con->jBias;
		con->jBias = cpfmax(jbnOld + jbn, 0.0f);
		jbn = con->jBias - jbnOld;

		// Apply the bias impulse.
		apply_bias_impulses(a, b, r1, r2, cpvmult(n, jbn));

		// Calculate the relative velocity.
		cpVect vr = relative_velocity(a, b, r1, r2);
		cpFloat vrn = cpvdot(vr, n);

		// Calculate and clamp the normal impulse.
		cpFloat jn = -(con->bounce*eCoef + vrn)*con->nMass;
		cpFloat jnOld = con->jnAcc;
		con->jnAcc = cpfmax(jnOld + jn, 0.0f);
		jn = con->jnAcc - jnOld;

		// Calculate the relative tangent velocity.
		cpFloat vrt = cpvdot(cpvadd(vr, arb->surface_vr), cpvperp(n));

		// Calculate and clamp the friction impulse.
		cpFloat jtMax = arb->u*con->jnAcc;
		cpFloat jt = -vrt*con->tMass;
		cpFloat jtOld = con->jtAcc;
		con->jtAcc = cpfclamp(jtOld + jt, -jtMax, jtMax);
		jt = con->jtAcc - jtOld;

		// Apply the final impulse.
		apply_impulses(a, b, r1, r2, cpvrotate(n, cpv(jn, jt)));
	}
}


code:
/* Copyright (c) 2007 Scott Lembcke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <stdlib.h>
#include <string.h>

#include "chipmunk_private.h"

//#define CP_ARRAY_INCREMENT 10

// NOTE: cpArray is rarely used and will probably go away.

cpArray*
cpArrayAlloc(void)
{
	return (cpArray *)cpcalloc(1, sizeof(cpArray));
}

cpArray*
cpArrayInit(cpArray *arr, int size)
{
	arr->num = 0;

	size = (size ? size : 4);
	arr->max = size;
	arr->arr = (void **)cpcalloc(size, sizeof(void**));

	return arr;
}

cpArray*
cpArrayNew(int size)
{
	return cpArrayInit(cpArrayAlloc(), size);
}

void
cpArrayDestroy(cpArray *arr)
{
	cpfree(arr->arr);
	arr->arr = NULL;
}

void
cpArrayFree(cpArray *arr)
{
	if(arr){
		cpArrayDestroy(arr);
		cpfree(arr);
	}
}

void
cpArrayPush(cpArray *arr, void *object)
{
	if(arr->num == arr->max){
		arr->max *= 2;
		arr->arr = (void **)cprealloc(arr->arr, arr->max*sizeof(void**));
	}

	arr->arr[arr->num] = object;
	arr->num++;
}

void *
cpArrayPop(cpArray *arr)
{
	arr->num--;

	void *value = arr->arr[arr->num];
	arr->arr[arr->num] = NULL;

	return value;
}

void
cpArrayDeleteIndex(cpArray *arr, int idx)
{
	arr->num--;

	arr->arr[idx] = arr->arr[arr->num];
	arr->arr[arr->num] = NULL;
}

void
cpArrayDeleteObj(cpArray *arr, void *obj)
{
	for(int i=0; i<arr->num; i++){
		if(arr->arr[i] == obj){
			cpArrayDeleteIndex(arr, i);
			return;
		}
	}
}

void
cpArrayAppend(cpArray *arr, cpArray *other)
{
	void *tail = &arr->arr[arr->num];

	arr->num += other->num;
	if(arr->num >= arr->max){
		arr->max = arr->num;
		arr->arr = (void **)cprealloc(arr->arr, arr->max*sizeof(void**));
	}

	memcpy(tail, other->arr, other->num*sizeof(void**));
}

void
cpArrayEach(cpArray *arr, cpArrayIter iterFunc, void *data)
{
	for(int i=0; i<arr->num; i++)
		iterFunc(arr->arr[i], data);
}

cpBool
cpArrayContains(cpArray *arr, void *ptr)
{
	for(int i=0; i<arr->num; i++)
		if(arr->arr[i] == ptr) return cpTrue;

	return cpFalse;
}


code:
/* Copyright (c) 2007 Scott Lembcke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <math.h>
#include <stdlib.h>

#include "chipmunk.h"

cpVect
cpBBClampVect(const cpBB bb, const cpVect v)
{
	cpFloat x = cpfmin(cpfmax(bb.l, v.x), bb.r);
	cpFloat y = cpfmin(cpfmax(bb.b, v.y), bb.t);
	return cpv(x, y);
}

cpVect
cpBBWrapVect(const cpBB bb, const cpVect v)
{
	cpFloat ix = cpfabs(bb.r - bb.l);
	cpFloat modx = cpfmod(v.x - bb.l, ix);
	cpFloat x = (modx > 0.0f) ? modx : modx + ix;

	cpFloat iy = cpfabs(bb.t - bb.b);
	cpFloat mody = cpfmod(v.y - bb.b, iy);
	cpFloat y = (mody > 0.0f) ? mody : mody + iy;

	return cpv(x + bb.l, y + bb.b);
}