Author Topic: Manipulation of the Box primitive  (Read 2725 times)

Offline Zothicus

  • byte
  • *
  • Posts: 2
    • View Profile
Manipulation of the Box primitive
« on: September 09, 2011, 07:24:46 pm »
Hi all,

I am just looking into JPCT-AE and it looks great, though I am no expert in 3D. I have played with jMonkeyEngine, but for my android app, JPCT-AE seems best.

To create a 3D rectangle, I usually use a Box class with 3 parameters (width, height, depth). How can I do the same using JPCT-AE ?

I see : Primitive.getBox(float scale, float scaleHeight), but it lacks parameters, like depth, no ?

Thanks !

Zothicus

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Manipulation of the Box primitive
« Reply #1 on: September 09, 2011, 07:52:19 pm »
Yes, it lacks this, because all objects created by Primitives (except for the plane) are lathe objects. You can't scale these objects in three dimension due to the way they are created. If you want to create the box in code and not in an editor, take this code and modify it, so that dimensions in x/y/z directions actually differ:

Code: [Select]
    Object3D box=new Object3D(12);
   
    SimpleVector upperLeftFront=new SimpleVector(-1,-1,-1);
    SimpleVector upperRightFront=new SimpleVector(1,-1,-1);
    SimpleVector lowerLeftFront=new SimpleVector(-1,1,-1);
    SimpleVector lowerRightFront=new SimpleVector(1,1,-1);
   
    SimpleVector upperLeftBack = new SimpleVector( -1, -1, 1);
    SimpleVector upperRightBack = new SimpleVector(1, -1, 1);
    SimpleVector lowerLeftBack = new SimpleVector( -1, 1, 1);
    SimpleVector lowerRightBack = new SimpleVector(1, 1, 1);
   
    // Front
    box.addTriangle(upperLeftFront,0,0, lowerLeftFront,0,1, upperRightFront,1,0);
    box.addTriangle(upperRightFront,1,0, lowerLeftFront,0,1, lowerRightFront,1,1);
   
    // Back
    box.addTriangle(upperLeftBack,0,0, upperRightBack,1,0, lowerLeftBack,0,1);
    box.addTriangle(upperRightBack,1,0, lowerRightBack,1,1, lowerLeftBack,0,1);
   
    // Upper
    box.addTriangle(upperLeftBack,0,0, upperLeftFront,0,1, upperRightBack,1,0);
    box.addTriangle(upperRightBack,1,0, upperLeftFront,0,1, upperRightFront,1,1);
   
    // Lower
    box.addTriangle(lowerLeftBack,0,0, lowerRightBack,1,0, lowerLeftFront,0,1);
    box.addTriangle(lowerRightBack,1,0, lowerRightFront,1,1, lowerLeftFront,0,1);
   
    // Left
    box.addTriangle(upperLeftFront,0,0, upperLeftBack,1,0, lowerLeftFront,0,1);
    box.addTriangle(upperLeftBack,1,0, lowerLeftBack,1,1, lowerLeftFront,0,1);
   
    // Right
    box.addTriangle(upperRightFront,0,0, lowerRightFront,0,1, upperRightBack,1,0);
    box.addTriangle(upperRightBack,1,0, lowerRightFront, 0,1, lowerRightBack,1,1);

    box.setTexture("base");


Offline Zothicus

  • byte
  • *
  • Posts: 2
    • View Profile
Re: Manipulation of the Box primitive
« Reply #2 on: September 09, 2011, 07:56:58 pm »
Excellent, I'll try it !

Thanks for the quick answer Egon