www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: luispablo on September 04, 2006, 04:39:30 am

Title: How to draw a rectangle
Post by: luispablo on September 04, 2006, 04:39:30 am
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
Title: How to draw a rectangle
Post by: Melssj5 on September 04, 2006, 06:49:57 pm
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.
Title: How to draw a rectangle
Post by: luispablo on September 04, 2006, 06:59:42 pm
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?
Title: How to draw a rectangle
Post by: Melssj5 on September 04, 2006, 07:02:12 pm
If you want to build a 3d scence you better use a 3d modeling software like 3ds max and load it into jpct.
Title: How to draw a rectangle
Post by: luispablo on September 04, 2006, 07:05:59 pm
Thanks a lot. I'll take your advice and try to use a modeling soft.
But, anyway, can I draw a rectangle somehow?
Title: How to draw a rectangle
Post by: EgonOlsen on September 04, 2006, 08:16:55 pm
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:

 
Code: [Select]

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;
   }
Title: How to draw a rectangle
Post by: EgonOlsen on September 04, 2006, 08:18:31 pm
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.
Title: How to draw a rectangle
Post by: Melssj5 on September 04, 2006, 08:49:53 pm
:wink:   8)
Title: Re: How to draw a rectangle
Post by: hantu on March 13, 2012, 03:12:07 pm
mark~