# www.jpct.net

## General => Feedback => Topic started by: LeoMaheo on March 22, 2009, 10:21:41 pm

Title: A call for cuboids (a.k.a. rectangles)
Post by: LeoMaheo on March 22, 2009, 10:21:41 pm
Hi!

I use JBullet to simulate walking ragdolls. Their body parts are cuboids.

I wish jPCT provided "native" cuboid support.
(Axis aligned cuboids I'd suggest :-))

(To some people: Some people refer to cuboids as rectangles.
Rectangles are however 2 dimensional and cuboids 3 dimensional.)

Kind regards,
Magnus
Title: Re: A call for cuboids (a.k.a. rectangles)
Post by: EgonOlsen on March 22, 2009, 10:24:09 pm
Doesn't this work: http://www.jpct.net/doc/com/threed/jpct/Primitives.html#getBox(float,%20float) (http://www.jpct.net/doc/com/threed/jpct/Primitives.html#getBox(float,%20float))?
Title: Re: A call for cuboids (a.k.a. rectangles)
Post by: LeoMaheo on March 22, 2009, 10:28:34 pm
But isn't then width = depth? I don't want that.
(Perhaps I can modify the rotation matrix so it stretches the box?)
Title: Re: A call for cuboids (a.k.a. rectangles)
Post by: EgonOlsen on March 22, 2009, 11:09:18 pm
But isn't then width = depth? I don't want that.
(Perhaps I can modify the rotation matrix so it stretches the box?)
Yes, that's true. You can modify the rotation matrix on your own to flatten the box, apply a rotateMesh() and reset the matrix. That should give you the desired 3d-rectangle.

Edit: Or just write your own cuboid-method...it shouldn't be too hard and it ensures that the cubs are really axis-aligned (i'm not sure that jPCT's lathe boxes are...).

Edit_2: Don't get me wrong. I'm not against adding this or something, but i'm busy right now with other things. So if you don't want to wait, you may be better off writing your own method. If you want to post it and it fits, i would be more than happy to add it to jPCT.
Title: Re: A call for cuboids (a.k.a. rectangles)
Post by: LeoMaheo on March 23, 2009, 04:40:10 am
Now I've modified the rotation matrix to scale a cube into a cuboid. Below code works for me.

(I currently use no textures though;
perhaps texture coordinates are affected in some (inappropriate) manner. (?))

`box = Primitives.getCube(1f);box.rotateY(Util.PI / 4); // cancel jPCT's default rotation around YMatrix scaler = new Matrix();scaler.setDump(new float[]{ halfExtents.x, 0, 0, 0, 0, halfExtents.y, 0, 0, 0, 0, halfExtents.z, 0, 0, 0, 0, 1 });box.getRotationMatrix().matMul(scaler);box.rotateMesh();box.build();// Reset rotation matrix so above scaling is not applied twice:box.getRotationMatrix().setIdentity();`