Box2D Java

Discuss issues specific the Java port of Box2D
Villane
Posts: 101
Joined: Mon Sep 01, 2008 6:32 am

Re: Box2D Java

Postby Villane » Sun Jun 14, 2009 6:12 am

ewjordan wrote:Villane, do you use an IDE to do Scala? If so, which one? I've had major problems with each of the plugins (Eclipse, Netbeans, IntelliJ), have you found that any of them accurately identify errors and give you the syntax help that you'd expect from a Java IDE?


I am using Eclipse mostly because I'm an Eclipse fan :) But the matter is complicated. You will get different answers depending on the person you ask. The fact is that each of the IDE-s have problems right now. I expect that for Scala 2.8, the Eclipse IDE is going to be pretty good. Miles Sabin has been improving the IDE a lot and there are going to be big changes with 2.8.
But I think we are a couple of years short from having the same level of basic support we expect from any Java IDE :(
(by basic I mean not including complex refactorings, static analysis and other non-essential features)

ewjordan wrote:These tests have graphics turned off, I assume?

Yep.

ewjordan
Posts: 803
Joined: Sun Sep 23, 2007 2:35 pm

Re: Box2D Java

Postby ewjordan » Sun Jun 14, 2009 4:16 pm

toucansam wrote:Also, ewjordan, is there a reason why the last domino on the second row of the domino tower isn't created? I went ahead and commented the if statement (line 125)

Code: Select all

if (j != 1)
out so now it doesn't start collapsing. But if it wasn't supposed to be there for a reason then........whoops.

Heh, no reason in particular, just that the example I was copying (from Chipmunk, I think) started collapsing from the edge like that, and that the tower doesn't actually stand up under its own weight and I never had a chance to tune everything to the point where it would (not sure if it's even possible in real time with a tower of that size, to be honest - I don't think Chipmunk did it, either, their real time tower was a lot smaller if I'm remembering correctly).

toucansam
Posts: 356
Joined: Mon Jun 08, 2009 12:21 pm
Contact:

Re: Box2D Java

Postby toucansam » Mon Jun 15, 2009 1:07 am

Also, I noticed something strange with the blob joint demos. When you turn on aabb drawing, the boxes that fall have strange bounds. it happens for all the blog joint demos.

ewjordan
Posts: 803
Joined: Sun Sep 23, 2007 2:35 pm

Re: Box2D Java

Postby ewjordan » Mon Jun 15, 2009 11:05 am

toucansam wrote:Also, I noticed something strange with the blob joint demos. When you turn on aabb drawing, the boxes that fall have strange bounds. it happens for all the blog joint demos.

Hmm, that appears to have shown up at some point during the optimizations, I'm not sure exactly when. Probably just a line or two during the box creation where something was reused that should have been copied instead, it looks like the OBB that the AABB is computed from is too big (might have something to do with the fact that the box is created both with non-zero PolygonDef setAsBox center and non-zero BodyDef position); I'll see if I can track it down.

toucansam
Posts: 356
Joined: Mon Jun 08, 2009 12:21 pm
Contact:

Re: Box2D Java

Postby toucansam » Mon Jun 15, 2009 11:08 am

They were there at rev 142, so I'm pretty sure my optimizations didn't cause it.

Villane
Posts: 101
Joined: Mon Sep 01, 2008 6:32 am

Re: Box2D Java

Postby Villane » Mon Jun 15, 2009 11:43 am

I'm wondering if this code (the else part) in contact creation is correct/necessary:

Code: Select all

            if (register.primary) {
                return register.createFcn.create(shape1, shape2);
            } else {
                Contact c = register.createFcn.create(shape2, shape1);
                for (int i = 0; i < c.getManifoldCount(); ++i) {
                    Manifold m = c.getManifolds().get(i);
                    m.normal.negateLocal();
                }
                return c;
            }


Wouldn't the normal need to be negated after contact evaluation, not contact creation? Contact evaluation will overwrite the normal as far as I know. Is it important for the normal to be in the right direction? Also, I just looked and this has been removed from the C++ version, but the Manifolds in C++ are different now also.

weevil
Posts: 2
Joined: Mon Jun 15, 2009 11:35 am

Re: Box2D Java

Postby weevil » Mon Jun 15, 2009 11:48 am

I'm a beginning processing user and I'm hoping to be able to skin some box2d models. Unfortunately the only demo code for doing this on the box2d site is in actionscript, which would probably be trivial to convert to processing for an advanced user, but I am still pretty green, and I don't have any knowledge of actionscript at all.

Code: Select all

//Initialize an array that will hold all actors.
var allActors:Array = new Array();
 
//Create a new actor for our body
var myActor:Actor = new Actor(myBody, myGraphic);
myBody.m_userData = myActor;
 
//Add our body to the stack.
allActors.push(myActor);
 
//This function can now be called each frame, and it will update the position of all graphics but it still need to work with step.
function on_enter_frame(e:Event) {
    for each (var a:Actor in allActors) {
 
        // World state position
        var bodyPosition:b2Vec2=a.body.GetPosition();
        var bodyRotation:Number=a.body.GetAngle();
 
        // Sprite rotation based (0,0) correct for size by moving sprite before rotation.
        // ie. rotation about the center of the sprite.
        a.graphic.rotation=0;// If not, matrix starts wrong.
        var m:Matrix=a.graphic.transform.matrix;
 
        m.tx=- a.graphic.width/2;
        m.ty=- a.graphic.height/2;
        m.rotate(bodyRotation);// Already in radians
 
        // Now set the position to the world position
        m.tx+=bodyPosition.x*physScale;
        m.ty+=bodyPosition.y*physScale;
 
        // ...and set the whole thing at once via the matrix.
        // ie. Update the sprite.
        a.graphic.transform.matrix=m;
   }
}

public class Actor {
    public var body:b2Body;
    public var graphic:DisplayObject;
 
    function Actor(b:b2Body, g:DisplayObject){
        body = b;
        graphic = g;
    }
}


Are there any users who are up to speed with both actionscript and processing on here?

toucansam
Posts: 356
Joined: Mon Jun 08, 2009 12:21 pm
Contact:

Re: Box2D Java

Postby toucansam » Mon Jun 15, 2009 12:14 pm

weevil wrote:I'm a beginning processing user and I'm hoping to be able to skin some box2d models. Unfortunately the only demo code for doing this on the box2d site is in actionscript, which would probably be trivial to convert to processing for an advanced user, but I am still pretty green, and I don't have any knowledge of actionscript at all.

Code: Select all

(snip)


Are there any users who are up to speed with both actionscript and processing on here?


Me! yay! although I was never fond of actionscript. ok so, this code basically wraps the bullet bodies in an "Actor" class, which has the Flash DisplayObject (used for displaying in flash). For Processing, you would want to do the same thing, but with PImage (which you can load from an image, look in the docs). In this example code, every frame it goes through all the actors and basically sets the transform of the bullet body (the position, rotation, etc) to the flash DisplayObject. What you would do is have that same array of actors, and probably have this code in the actor:

Code: Select all

void draw(){
  XForm x = body.getXForm();
  applyMatrix( put the matrix from the xform here, and fill out the rest with the identity matrix);
  draw(thepimage);
}


which you would call every draw method
Last edited by toucansam on Wed Jun 17, 2009 12:20 pm, edited 1 time in total.

weevil
Posts: 2
Joined: Mon Jun 15, 2009 11:35 am

Re: Box2D Java

Postby weevil » Mon Jun 15, 2009 12:27 pm

Awesome, I'll give that a try. I was able to convert most of the var stuff in actionscript to processing variables, but I was stuck on actionscripts weird myWhatever conventions.

ewjordan
Posts: 803
Joined: Sun Sep 23, 2007 2:35 pm

Re: Box2D Java

Postby ewjordan » Mon Jun 15, 2009 1:44 pm

toucansam wrote:They were there at rev 142, so I'm pretty sure my optimizations didn't cause it.

Ah, okay, there was another round of optimizations before that which are probably at fault then (the pre-optimization version I've got loaded at the moment goes back pretty far). That gives me an idea where to look, thanks.

Villane wrote:I'm wondering if this code (the else part) in contact creation is correct/necessary:

Code: Select all

(snip)


Wouldn't the normal need to be negated after contact evaluation, not contact creation? Contact evaluation will overwrite the normal as far as I know. Is it important for the normal to be in the right direction? Also, I just looked and this has been removed from the C++ version, but the Manifolds in C++ are different now also.

Hmm, good question - haven't ever really looked at that bit of code in detail since the original port, so I'm not sure off the top of my head. I'll look into it and try to figure out what's going on.


Return to “Java”



Who is online

Users browsing this forum: No registered users and 2 guests