Author Topic: A call for cuboids (a.k.a. rectangles)  (Read 3916 times)

Offline LeoMaheo

  • byte
  • *
  • Posts: 10
    • View Profile
A call for cuboids (a.k.a. rectangles)
« 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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11770
    • View Profile
    • http://www.jpct.net

Offline LeoMaheo

  • byte
  • *
  • Posts: 10
    • View Profile
Re: A call for cuboids (a.k.a. rectangles)
« Reply #2 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?)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11770
    • View Profile
    • http://www.jpct.net
Re: A call for cuboids (a.k.a. rectangles)
« Reply #3 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.
« Last Edit: March 22, 2009, 11:54:36 pm by EgonOlsen »

Offline LeoMaheo

  • byte
  • *
  • Posts: 10
    • View Profile
Re: A call for cuboids (a.k.a. rectangles)
« Reply #4 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. (?))

Thanks Egon for your quick reply :-)

Code: [Select]
box = Primitives.getCube(1f);
box.rotateY(Util.PI / 4); // cancel jPCT's default rotation around Y
Matrix 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();

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11770
    • View Profile
    • http://www.jpct.net
Re: A call for cuboids (a.k.a. rectangles)
« Reply #5 on: March 23, 2009, 04:23:09 pm »
(I currently use no textures though;
perhaps texture coordinates are affected in some (inappropriate) manner. (?))
The lathe objects that Primitives creates (except for the plane...) have no texture coordinates anyway... ;)