From 0bb64820af40cfdb7cc776c4ce424725a69ccaf6 Mon Sep 17 00:00:00 2001 From: oakes Date: Sun, 11 May 2014 15:38:14 -0400 Subject: [PATCH] Convert between radians and degrees and update the origin x/y --- src/play_clj/g2d_physics.clj | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/play_clj/g2d_physics.clj b/src/play_clj/g2d_physics.clj index 62632e3..c2b0cfb 100644 --- a/src/play_clj/g2d_physics.clj +++ b/src/play_clj/g2d_physics.clj @@ -2,7 +2,7 @@ (:require [play-clj.core :as c] [play-clj.math :as m] [play-clj.utils :as u]) - (:import [com.badlogic.gdx.math Vector2] + (:import [com.badlogic.gdx.math MathUtils Vector2] [com.badlogic.gdx.physics.box2d Body BodyDef ChainShape CircleShape Contact ContactListener EdgeShape Fixture FixtureDef Joint JointDef PolygonShape Transform])) @@ -75,12 +75,20 @@ (defn ^:private body-angle [entity] - (.getRotation ^Transform (body! entity :get-transform))) + (* (body! entity :get-angle) MathUtils/radiansToDegrees)) + +(defn ^:private body-origin-x + [entity] + (. ^Vector2 (body! entity :get-local-center) x)) + +(defn ^:private body-origin-y + [entity] + (. ^Vector2 (body! entity :get-local-center) y)) (defn body-position! - "Changes the position of the body in `entity`." + "Changes the position of the body in `entity`. The angle is in degrees." [entity x y angle] - (body! entity :set-transform x y angle)) + (body! entity :set-transform x y (* angle MathUtils/degreesToRadians))) (defn body-x! "Changes the `x` of the body in `entity`." @@ -93,7 +101,7 @@ (body-position! entity (body-x entity) y (body-angle entity))) (defn body-angle! - "Changes the `angle` of the body in `entity`." + "Changes the `angle` (degrees) of the body in `entity`." [entity angle] (body-position! entity (body-x entity) (body-y entity) angle)) @@ -264,6 +272,8 @@ such as :on-begin-contact." (assoc e :x (body-x e) :y (body-y e) - :angle (body-angle e)) + :angle (body-angle e) + :origin-x (body-origin-x e) + :origin-y (body-origin-y e)) e)) entities)))