How to draw a rectangle

Started by luispablo, September 04, 2006, 04:39:30 AM

Previous topic - Next topic

luispablo

Hi,
 I know this is a VERY newie question :oops:, but I can't draw a rectangle with, for example, one side with 10 and another one with 3. I'm only able to draw squares, with all side with the same length!   :roll:
 Thanks in advance

Melssj5

Hi, jpct is not a 2d engine so you  can draw only the 3d primitives pre defined, as I remember there is not a rectangular prism, only cubes, if you need it you bay think on drawing a cube and extruding it by some methid that  I dont know or even draw many cubes until get thye desired rectangles and merge all of them into a higher whole shape.
Nada por ahora

luispablo

I know it's 3D, but I'm trying to build a corridor, and it must have its walls, floor and ceiling in the form of rectangles.
I'm using Primitives.getPlane(), but this method only creates squares. How can I transform them to set its mesures?

Melssj5

If you want to build a 3d scence you better use a 3d modeling software like 3ds max and load it into jpct.
Nada por ahora

luispablo

Thanks a lot. I'll take your advice and try to use a modeling soft.
But, anyway, can I draw a rectangle somehow?

EgonOlsen

Yes, but only by building it yourself. This can either be done by using Object3D.addTriangle() or by merging multiple planes as returned by getPlane() into a rectangle. But that one may not have the texture properties you want. I may add a method to create a rectangle. I can give you the code of Primitves.getPlane(). It should be easy for you to change it in a way that it creates rectangles instead:


public static Object3D getPlane(int quads, float scale) {
     float startx=-scale*(float) quads/2f;
     float starty=startx;
     float tx=0f;
     float ty=0f;
     float dtex=(1f/(float) quads);
     Object3D obj=new Object3D(quads*quads*2+8);
     for (int i=0; i<quads; i++) {
        for (int p=0; p<quads; p++) {
           float dtx=tx+dtex;
           float dty=ty+dtex;
           if (dtx>1f) {
              dtx=1f;
           }
           if (dty>1f) {
              dty=1f;
           }
           obj.addTriangle(startx, starty, 0, tx, ty, startx, starty+scale, 0, tx, dty, startx+scale, starty, 0,
                           dtx, ty);
           obj.addTriangle(startx, starty+scale, 0, tx, dty, startx+scale, starty+scale, 0, dtx, dty, startx+scale,
                           starty, 0, dtx, ty);
           startx+=scale;
           tx+=dtex;
        }
        starty+=scale;
        startx=-scale*quads/2;
        tx=0;
        ty+=dtex;
     }
     return obj;
  }

EgonOlsen

BTW: Melssj5 is right when he suggests to use a modelling software instead because building a level out of primitives is very inefficient rendering wise.

Melssj5

Nada por ahora