I have a problem with my setup. My custom DebugDraw class is not drawing anything and the circle object I create continues to fall, without hitting the ground and stopping.
Here is the code-
And for the DebugDraw class -
And some logs-
Please help me I am so lost.
Here is the code-
Code:
package chill.states;
import java.awt.Color;
import org.jbox2d.collision.*;
import org.jbox2d.collision.shapes.CircleShape;
import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.OBBViewportTransform;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.*;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Circle;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import chill.util.Slick2dDebugDraw;
public class NoState extends BasicGameState {
int stateID;
public int targetFPS = 40;
public int timeStep = (1000 / targetFPS);
public int iterations = 5;
Body ba;
static OBBViewportTransform v = new OBBViewportTransform();
private AABB worldAABB;
private World world;
int i = 0;
public NoState(int id)
{
this.stateID = id;
}
@Override
public void init(GameContainer arg0, StateBasedGame arg1)
throws SlickException {
v.setExtents(arg0.getWidth()/2, arg0.getHeight()/2);
// Step 1: Create Physics World Boundaries
worldAABB = new AABB();
Vec2 screenlower = new Vec2(arg0.getHeight(),arg0.getHeight());
Vec2 screenupper = new Vec2(arg0.getHeight(),arg0.getHeight());
Vec2 worldlower = new Vec2();
Vec2 worldupper = new Vec2();
v.getScreenToWorld(screenlower,worldlower );
v.getScreenToWorld(screenupper,worldupper );
//worldAABB.lowerBound.set(new Vec2((float) -100.0, (float) -100.0));
//worldAABB.upperBound.set(new Vec2((float) 100.0, (float) 100.0));
worldAABB.lowerBound.set(worldlower);
worldAABB.upperBound.set(worldupper);
// Step 2: Create Physics World with Gravity
Vec2 gravity = new Vec2((float) 0.0, (float) -10.0);
boolean doSleep = true;
world = new World(gravity, doSleep);
// Step 3: Create Ground Box
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.position.set(0.0f, 10.0f);
Body groundBody = world.createBody(groundBodyDef);
PolygonShape groundBox = new PolygonShape();
groundBox.setAsBox(50.0f, 10.0f);
groundBody.createFixture(groundBox,100);
// Create Dynamic Body
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set((float) 200.0, (float) 200.0);
ba = world.createBody(bodyDef);
// Create Shape with Properties
CircleShape circle = new CircleShape();
circle.m_radius = (float) 50.0;
FixtureDef f = new FixtureDef();
f.shape = circle;
f.density = 2.0f;
f.friction = 1.0f;
f.shape.m_radius = 5;
// Assign shape to Body
//ba.createFixture(circle,1);
ba.createFixture(f);
Slick2dDebugDraw sDD = new Slick2dDebugDraw(arg0.getGraphics(), arg0);
world.setDebugDraw(sDD);
}
/*
* private void bindSpriteToBody(Sprite sprite, final Body body) {
sprite.setAnchor(0.5, 0.5);
sprite.x.bindTo(new BindFunction() {
public Number f() {
return body.getPosition().x * WORLD_TO_STAGE_SCALE;
}
});
sprite.y.bindTo(new BindFunction() {
public Number f() {
return body.getPosition().y * WORLD_TO_STAGE_SCALE;
}
});
sprite.angle.bindTo(new BindFunction() {
public Number f() {
return body.getAngle();
}
});
}
private void addSpriteForBody(String imageName, Body body) {
Sprite sprite = new ImageSprite(imageName, 0, 0);
bindSpriteToBody(sprite, body);
add(sprite);
}
*/
public void addBall() {
// Create Dynamic Body
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set((float) 200.0, (float) 200.0);
ba = world.createBody(bodyDef);
// Create Shape with Properties
CircleShape circle = new CircleShape();
circle.m_radius = (float) 50.0;
FixtureDef f = new FixtureDef();
f.shape = circle;
f.density = 2.0f;
f.friction = 1.0f;
f.shape.m_radius = 5;
// Assign shape to Body
//ba.createFixture(circle,1);
ba.createFixture(f);
}
@Override
public void render(GameContainer gc, StateBasedGame arg1, Graphics g)
throws SlickException {
world.drawDebugData();
//Vec2 c = new Vec2();
//v.getWorldVectorToScreen(ba.getPosition(), c);
}
@Override
public void update(GameContainer gc, StateBasedGame arg1, int arg2)
throws SlickException {
// Update Physics World
world.step(timeStep, iterations, iterations);
Input input = gc.getInput();
int mouseX = input.getMouseX();
int mouseY = input.getMouseY();
if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ){
addBall();
}
System.out.println("X:"+ba.getPosition().x+" Y:"+ba.getPosition().y);
}
@Override
public int getID() {
// TODO Auto-generated method stub
return 0;
}
}
import java.awt.Color;
import org.jbox2d.collision.*;
import org.jbox2d.collision.shapes.CircleShape;
import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.OBBViewportTransform;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.*;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Circle;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import chill.util.Slick2dDebugDraw;
public class NoState extends BasicGameState {
int stateID;
public int targetFPS = 40;
public int timeStep = (1000 / targetFPS);
public int iterations = 5;
Body ba;
static OBBViewportTransform v = new OBBViewportTransform();
private AABB worldAABB;
private World world;
int i = 0;
public NoState(int id)
{
this.stateID = id;
}
@Override
public void init(GameContainer arg0, StateBasedGame arg1)
throws SlickException {
v.setExtents(arg0.getWidth()/2, arg0.getHeight()/2);
// Step 1: Create Physics World Boundaries
worldAABB = new AABB();
Vec2 screenlower = new Vec2(arg0.getHeight(),arg0.getHeight());
Vec2 screenupper = new Vec2(arg0.getHeight(),arg0.getHeight());
Vec2 worldlower = new Vec2();
Vec2 worldupper = new Vec2();
v.getScreenToWorld(screenlower,worldlower );
v.getScreenToWorld(screenupper,worldupper );
//worldAABB.lowerBound.set(new Vec2((float) -100.0, (float) -100.0));
//worldAABB.upperBound.set(new Vec2((float) 100.0, (float) 100.0));
worldAABB.lowerBound.set(worldlower);
worldAABB.upperBound.set(worldupper);
// Step 2: Create Physics World with Gravity
Vec2 gravity = new Vec2((float) 0.0, (float) -10.0);
boolean doSleep = true;
world = new World(gravity, doSleep);
// Step 3: Create Ground Box
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.position.set(0.0f, 10.0f);
Body groundBody = world.createBody(groundBodyDef);
PolygonShape groundBox = new PolygonShape();
groundBox.setAsBox(50.0f, 10.0f);
groundBody.createFixture(groundBox,100);
// Create Dynamic Body
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set((float) 200.0, (float) 200.0);
ba = world.createBody(bodyDef);
// Create Shape with Properties
CircleShape circle = new CircleShape();
circle.m_radius = (float) 50.0;
FixtureDef f = new FixtureDef();
f.shape = circle;
f.density = 2.0f;
f.friction = 1.0f;
f.shape.m_radius = 5;
// Assign shape to Body
//ba.createFixture(circle,1);
ba.createFixture(f);
Slick2dDebugDraw sDD = new Slick2dDebugDraw(arg0.getGraphics(), arg0);
world.setDebugDraw(sDD);
}
/*
* private void bindSpriteToBody(Sprite sprite, final Body body) {
sprite.setAnchor(0.5, 0.5);
sprite.x.bindTo(new BindFunction() {
public Number f() {
return body.getPosition().x * WORLD_TO_STAGE_SCALE;
}
});
sprite.y.bindTo(new BindFunction() {
public Number f() {
return body.getPosition().y * WORLD_TO_STAGE_SCALE;
}
});
sprite.angle.bindTo(new BindFunction() {
public Number f() {
return body.getAngle();
}
});
}
private void addSpriteForBody(String imageName, Body body) {
Sprite sprite = new ImageSprite(imageName, 0, 0);
bindSpriteToBody(sprite, body);
add(sprite);
}
*/
public void addBall() {
// Create Dynamic Body
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set((float) 200.0, (float) 200.0);
ba = world.createBody(bodyDef);
// Create Shape with Properties
CircleShape circle = new CircleShape();
circle.m_radius = (float) 50.0;
FixtureDef f = new FixtureDef();
f.shape = circle;
f.density = 2.0f;
f.friction = 1.0f;
f.shape.m_radius = 5;
// Assign shape to Body
//ba.createFixture(circle,1);
ba.createFixture(f);
}
@Override
public void render(GameContainer gc, StateBasedGame arg1, Graphics g)
throws SlickException {
world.drawDebugData();
//Vec2 c = new Vec2();
//v.getWorldVectorToScreen(ba.getPosition(), c);
}
@Override
public void update(GameContainer gc, StateBasedGame arg1, int arg2)
throws SlickException {
// Update Physics World
world.step(timeStep, iterations, iterations);
Input input = gc.getInput();
int mouseX = input.getMouseX();
int mouseY = input.getMouseY();
if ( input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ){
addBall();
}
System.out.println("X:"+ba.getPosition().x+" Y:"+ba.getPosition().y);
}
@Override
public int getID() {
// TODO Auto-generated method stub
return 0;
}
}
And for the DebugDraw class -
Code:
/*
Implementation of JBox2d's DebugDraw using Slick2d
@version 1.0.0
@author liamzebedee
Created by Liam Edwards-Playne
Cryptum Technologies - http://cryptum.net
Licensed under the MIT license
Copyright (C) 2011 by Liam Edwards-Playne
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.
*/
package chill.util;
import org.jbox2d.callbacks.DebugDraw;
import org.jbox2d.collision.AABB;
import org.jbox2d.common.*;
import org.jbox2d.pooling.arrays.IntArray;
import org.jbox2d.pooling.arrays.Vec2Array;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.ShapeFill;
import org.newdawn.slick.geom.Polygon;
public class Slick2dDebugDraw extends DebugDraw{
public static int circlePoints = 20;
Graphics g;
GameContainer gc;
//private final TestPanel panel;
//private final ColorPool cpool = new ColorPool();
/**
* @param viewport
*/
public Slick2dDebugDraw(Graphics g,GameContainer gc) {
super(new OBBViewportTransform());
viewportTransform.setYFlip(true);
viewportTransform.setExtents(gc.getWidth()/2, gc.getHeight()/2);
this.g = g;
this.gc = gc;
System.out.println("Slick2dDebugDraw initialised!");
}
private final Vec2Array vec2Array = new Vec2Array();
/**
* @see org.jbox2d.callbacks.DebugDraw#drawCircle1(org.jbox2d.common.Vec2, float, org.jbox2d.common.Color3f)
*/
@Override
public void drawCircle(Vec2 center, float radius, Color3f color) {
Vec2[] vecs = vec2Array.get(circlePoints );
generateCirle(center, radius, vecs, circlePoints);
drawPolygon(vecs, circlePoints, color);
}
@Override
public void drawPoint(Vec2 argPoint, float argRadiusOnScreen, Color3f argColor) {
getWorldToScreenToOut(argPoint, sp1);
g.setColor(new Color(argColor.x,argColor.y,argColor.z));
sp1.x -= argRadiusOnScreen;
sp1.y -= argRadiusOnScreen;
g.fillOval((int)sp1.x, (int)sp1.y, (int)argRadiusOnScreen*2, (int)argRadiusOnScreen*2);
}
private final Vec2 sp1 = new Vec2();
private final Vec2 sp2 = new Vec2();
/**
* @see org.jbox2d.callbacks.DebugDraw#drawSegment(org.jbox2d.common.Vec2, org.jbox2d.common.Vec2, org.jbox2d.common.Color3f)
*/
@Override
public void drawSegment(Vec2 p1, Vec2 p2, Color3f color) {
getWorldToScreenToOut(p1, sp1);
getWorldToScreenToOut(p2, sp2);
g.setColor(new Color(color.x,color.y,color.z));
g.drawLine((int)sp1.x, (int)sp1.y, (int)sp2.x, (int)sp2.y);
}
public void drawAABB(AABB argAABB, Color3f color){
g.setColor(new Color(color.x,color.y,color.z));
Vec2 vecs[] = vec2Array.get(4);
argAABB.getVertices(vecs);
drawPolygon(vecs, 4, color);
}
private final Vec2 saxis = new Vec2();
/**
* @see org.jbox2d.callbacks.DebugDraw#drawSolidCircle(org.jbox2d.common.Vec2, float, org.jbox2d.common.Vec2, org.jbox2d.common.Color3f)
*/
@Override
public void drawSolidCircle(Vec2 center, float radius, Vec2 axis, Color3f color) {
Vec2[] vecs = vec2Array.get(circlePoints );
generateCirle(center, radius, vecs, circlePoints);
drawSolidPolygon(vecs, circlePoints, color);
if(axis != null){
saxis.set(axis).mulLocal(radius).addLocal(center);
drawSegment(center, saxis, color);
}
}
// TODO change IntegerArray to a specific class for int[] arrays
private final Vec2 temp = new Vec2();
private final static IntArray xIntsPool = new IntArray();
private final static IntArray yIntsPool = new IntArray();
/**
* @see org.jbox2d.callbacks.DebugDraw#drawSolidPolygon(org.jbox2d.common.Vec2[], int, org.jbox2d.common.Color3f)
*/
@Override
public void drawSolidPolygon(Vec2[] vertices, int vertexCount, Color3f color) {
int[] xInts = xIntsPool.get(vertexCount);
int[] yInts = yIntsPool.get(vertexCount);
Polygon p = new Polygon();
for(int i=0; i<vertexCount; i++){
getWorldToScreenToOut(vertices[i], temp);
xInts[i] = (int)temp.x;
yInts[i] = (int)temp.y;
p.addPoint(xInts[i], yInts[i]);
}
g.setColor(new Color(color.x,color.y,color.z));
g.fill(p); //Draws shape filled with colour
//drawPolygon(vertices, vertexCount, color);
}
/**
* @see org.jbox2d.callbacks.DebugDraw#drawString(float, float, java.lang.String, org.jbox2d.common.Color3f)
*/
@Override
public void drawString(float x, float y, String s, Color3f color) {
g.setColor(new Color(color.x,color.y,color.z));
g.drawString(s, x, y);
}
private final Vec2 temp2 = new Vec2();
/**
* @see org.jbox2d.callbacks.DebugDraw#drawTransform(org.jbox2d.common.Transform)
*/
@Override
public void drawTransform(Transform xf) {
getWorldToScreenToOut(xf.position, temp);
temp2.setZero();
float k_axisScale = 0.4f;
g.setColor(new Color(1,0,0));
temp2.x = xf.position.x + k_axisScale * xf.R.col1.x;
temp2.y = xf.position.y + k_axisScale * xf.R.col1.y;
getWorldToScreenToOut(temp2, temp2);
g.drawLine((int)temp.x, (int)temp.y, (int)temp2.x, (int)temp2.y);
g.setColor(new Color(0,1,0));
temp2.x = xf.position.x + k_axisScale * xf.R.col2.x;
temp2.y = xf.position.y + k_axisScale * xf.R.col2.y;
getWorldToScreenToOut(temp2, temp2);
g.drawLine((int)temp.x, (int)temp.y, (int)temp2.x, (int)temp2.y);
}
// CIRCLE GENERATOR
private void generateCirle(Vec2 argCenter, float argRadius, Vec2[] argPoints, int argNumPoints){
float inc = MathUtils.TWOPI/argNumPoints;
for(int i=0; i<argNumPoints; i++){
argPoints[i].x = (argCenter.x + MathUtils.cos(i*inc)*argRadius);
argPoints[i].y = (argCenter.y + MathUtils.sin(i*inc)*argRadius);
}
}
}
Implementation of JBox2d's DebugDraw using Slick2d
@version 1.0.0
@author liamzebedee
Created by Liam Edwards-Playne
Cryptum Technologies - http://cryptum.net
Licensed under the MIT license
Copyright (C) 2011 by Liam Edwards-Playne
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.
*/
package chill.util;
import org.jbox2d.callbacks.DebugDraw;
import org.jbox2d.collision.AABB;
import org.jbox2d.common.*;
import org.jbox2d.pooling.arrays.IntArray;
import org.jbox2d.pooling.arrays.Vec2Array;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.ShapeFill;
import org.newdawn.slick.geom.Polygon;
public class Slick2dDebugDraw extends DebugDraw{
public static int circlePoints = 20;
Graphics g;
GameContainer gc;
//private final TestPanel panel;
//private final ColorPool cpool = new ColorPool();
/**
* @param viewport
*/
public Slick2dDebugDraw(Graphics g,GameContainer gc) {
super(new OBBViewportTransform());
viewportTransform.setYFlip(true);
viewportTransform.setExtents(gc.getWidth()/2, gc.getHeight()/2);
this.g = g;
this.gc = gc;
System.out.println("Slick2dDebugDraw initialised!");
}
private final Vec2Array vec2Array = new Vec2Array();
/**
* @see org.jbox2d.callbacks.DebugDraw#drawCircle1(org.jbox2d.common.Vec2, float, org.jbox2d.common.Color3f)
*/
@Override
public void drawCircle(Vec2 center, float radius, Color3f color) {
Vec2[] vecs = vec2Array.get(circlePoints );
generateCirle(center, radius, vecs, circlePoints);
drawPolygon(vecs, circlePoints, color);
}
@Override
public void drawPoint(Vec2 argPoint, float argRadiusOnScreen, Color3f argColor) {
getWorldToScreenToOut(argPoint, sp1);
g.setColor(new Color(argColor.x,argColor.y,argColor.z));
sp1.x -= argRadiusOnScreen;
sp1.y -= argRadiusOnScreen;
g.fillOval((int)sp1.x, (int)sp1.y, (int)argRadiusOnScreen*2, (int)argRadiusOnScreen*2);
}
private final Vec2 sp1 = new Vec2();
private final Vec2 sp2 = new Vec2();
/**
* @see org.jbox2d.callbacks.DebugDraw#drawSegment(org.jbox2d.common.Vec2, org.jbox2d.common.Vec2, org.jbox2d.common.Color3f)
*/
@Override
public void drawSegment(Vec2 p1, Vec2 p2, Color3f color) {
getWorldToScreenToOut(p1, sp1);
getWorldToScreenToOut(p2, sp2);
g.setColor(new Color(color.x,color.y,color.z));
g.drawLine((int)sp1.x, (int)sp1.y, (int)sp2.x, (int)sp2.y);
}
public void drawAABB(AABB argAABB, Color3f color){
g.setColor(new Color(color.x,color.y,color.z));
Vec2 vecs[] = vec2Array.get(4);
argAABB.getVertices(vecs);
drawPolygon(vecs, 4, color);
}
private final Vec2 saxis = new Vec2();
/**
* @see org.jbox2d.callbacks.DebugDraw#drawSolidCircle(org.jbox2d.common.Vec2, float, org.jbox2d.common.Vec2, org.jbox2d.common.Color3f)
*/
@Override
public void drawSolidCircle(Vec2 center, float radius, Vec2 axis, Color3f color) {
Vec2[] vecs = vec2Array.get(circlePoints );
generateCirle(center, radius, vecs, circlePoints);
drawSolidPolygon(vecs, circlePoints, color);
if(axis != null){
saxis.set(axis).mulLocal(radius).addLocal(center);
drawSegment(center, saxis, color);
}
}
// TODO change IntegerArray to a specific class for int[] arrays
private final Vec2 temp = new Vec2();
private final static IntArray xIntsPool = new IntArray();
private final static IntArray yIntsPool = new IntArray();
/**
* @see org.jbox2d.callbacks.DebugDraw#drawSolidPolygon(org.jbox2d.common.Vec2[], int, org.jbox2d.common.Color3f)
*/
@Override
public void drawSolidPolygon(Vec2[] vertices, int vertexCount, Color3f color) {
int[] xInts = xIntsPool.get(vertexCount);
int[] yInts = yIntsPool.get(vertexCount);
Polygon p = new Polygon();
for(int i=0; i<vertexCount; i++){
getWorldToScreenToOut(vertices[i], temp);
xInts[i] = (int)temp.x;
yInts[i] = (int)temp.y;
p.addPoint(xInts[i], yInts[i]);
}
g.setColor(new Color(color.x,color.y,color.z));
g.fill(p); //Draws shape filled with colour
//drawPolygon(vertices, vertexCount, color);
}
/**
* @see org.jbox2d.callbacks.DebugDraw#drawString(float, float, java.lang.String, org.jbox2d.common.Color3f)
*/
@Override
public void drawString(float x, float y, String s, Color3f color) {
g.setColor(new Color(color.x,color.y,color.z));
g.drawString(s, x, y);
}
private final Vec2 temp2 = new Vec2();
/**
* @see org.jbox2d.callbacks.DebugDraw#drawTransform(org.jbox2d.common.Transform)
*/
@Override
public void drawTransform(Transform xf) {
getWorldToScreenToOut(xf.position, temp);
temp2.setZero();
float k_axisScale = 0.4f;
g.setColor(new Color(1,0,0));
temp2.x = xf.position.x + k_axisScale * xf.R.col1.x;
temp2.y = xf.position.y + k_axisScale * xf.R.col1.y;
getWorldToScreenToOut(temp2, temp2);
g.drawLine((int)temp.x, (int)temp.y, (int)temp2.x, (int)temp2.y);
g.setColor(new Color(0,1,0));
temp2.x = xf.position.x + k_axisScale * xf.R.col2.x;
temp2.y = xf.position.y + k_axisScale * xf.R.col2.y;
getWorldToScreenToOut(temp2, temp2);
g.drawLine((int)temp.x, (int)temp.y, (int)temp2.x, (int)temp2.y);
}
// CIRCLE GENERATOR
private void generateCirle(Vec2 argCenter, float argRadius, Vec2[] argPoints, int argNumPoints){
float inc = MathUtils.TWOPI/argNumPoints;
for(int i=0; i<argNumPoints; i++){
argPoints[i].x = (argCenter.x + MathUtils.cos(i*inc)*argRadius);
argPoints[i].y = (argCenter.y + MathUtils.sin(i*inc)*argRadius);
}
}
}
And some logs-
Code:
X:200.0 Y:-10830.641
X:200.0 Y:-10832.625
X:200.0 Y:-10834.608
X:200.0 Y:-10836.592
X:200.0 Y:-10838.576
X:200.0 Y:-10840.56
X:200.0 Y:-10842.543
X:200.0 Y:-10844.527
X:200.0 Y:-10846.511
X:200.0 Y:-10848.494
X:200.0 Y:-10832.625
X:200.0 Y:-10834.608
X:200.0 Y:-10836.592
X:200.0 Y:-10838.576
X:200.0 Y:-10840.56
X:200.0 Y:-10842.543
X:200.0 Y:-10844.527
X:200.0 Y:-10846.511
X:200.0 Y:-10848.494
Please help me I am so lost.